QT += 3dcore 3drender 3dlogic 3dextras
INCLUDEPATH += "E:\Libs\Bullet3-2.89\include"
LIBS += -L"E:\Libs\Bullet3-2.89\lib"
LIBS += -lBulletDynamics -lBulletCollision -lLinearMath
SOURCES += \
main.cpp
RESOURCES += \
Models.qrc
QT += 3dcore 3drender 3dlogic 3dextras
INCLUDEPATH += "E:\Libs\Bullet3-2.89\include"
LIBS += -L"E:\Libs\Bullet3-2.89\lib"
LIBS += -lBulletDynamics -lBulletCollision -lLinearMath
SOURCES += \
main.cpp
RESOURCES += \
Models.qrc
To copy to clipboard, switch view to plain text mode
#ifdef _WIN32
#include <windows.h>
extern "C" __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
extern "C" __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 0x00000001;
#endif
#include <QGuiApplication>
#include <QEntity>
#include <Qt3DWindow>
#include <btBulletDynamicsCommon.h>
#include <QCamera>
#include <QPointLight>
#include <QTransform>
#include <QSceneLoader>
#include <QOrbitCameraController>
#include <QPhongMaterial>
int main(int argc, char *argv[])
{
QGuiApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
QGuiApplication app(argc, argv);
Qt3DExtras::Qt3DWindow view;
view.setGeometry(500, 100, 270, 270);
Qt3DRender::QCamera *camera = view.camera();
camera->lens()->setPerspectiveProjection(60.0f, view.width()/(float)view.height(), 0.1f, 1000.0f);
camera->setPosition(QVector3D(0.0f, 0.0f, 30.0f));
camera->setViewCenter(QVector3D(0.0f, 0.0f, 0.0f));
Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity;
Qt3DCore::QEntity *lightEntity = new Qt3DCore::QEntity(rootEntity);
Qt3DRender::QPointLight *pointLight = new Qt3DRender::QPointLight(lightEntity);
Qt3DCore::QTransform *lightTransform = new Qt3DCore::QTransform(rootEntity);
lightTransform->setTranslation(QVector3D(10.0f, 20.0f, 30.0f));
lightEntity->addComponent(pointLight);
lightEntity->addComponent(lightTransform);
Qt3DCore::QEntity *cubeEntity = new Qt3DCore::QEntity(rootEntity);
Qt3DRender::QSceneLoader *sceneLoader = new Qt3DRender::QSceneLoader(cubeEntity);
sceneLoader
->setSource
(QUrl("qrc:/Models/Cube.obj"));
cubeEntity->addComponent(sceneLoader);
Qt3DCore::QTransform *cubeTransform = new Qt3DCore::QTransform(cubeEntity);
cubeTransform->setScale(7.0f);
cubeEntity->addComponent(cubeTransform);
Qt3DExtras::QPhongMaterial *material = new Qt3DExtras::QPhongMaterial(rootEntity);
rootEntity->addComponent(material);
Qt3DExtras::QOrbitCameraController *cameraController = new Qt3DExtras::QOrbitCameraController(rootEntity);
cameraController->setCamera(camera);
cameraController->setLookSpeed(180.0f);
cameraController->setLinearSpeed(50.0f);
view.setRootEntity(rootEntity);
view.show();
return app.exec();
}
#ifdef _WIN32
#include <windows.h>
extern "C" __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
extern "C" __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 0x00000001;
#endif
#include <QGuiApplication>
#include <QEntity>
#include <Qt3DWindow>
#include <btBulletDynamicsCommon.h>
#include <QCamera>
#include <QPointLight>
#include <QTransform>
#include <QSceneLoader>
#include <QOrbitCameraController>
#include <QPhongMaterial>
int main(int argc, char *argv[])
{
QGuiApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
QGuiApplication app(argc, argv);
Qt3DExtras::Qt3DWindow view;
view.setGeometry(500, 100, 270, 270);
Qt3DRender::QCamera *camera = view.camera();
camera->lens()->setPerspectiveProjection(60.0f, view.width()/(float)view.height(), 0.1f, 1000.0f);
camera->setPosition(QVector3D(0.0f, 0.0f, 30.0f));
camera->setViewCenter(QVector3D(0.0f, 0.0f, 0.0f));
Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity;
Qt3DCore::QEntity *lightEntity = new Qt3DCore::QEntity(rootEntity);
Qt3DRender::QPointLight *pointLight = new Qt3DRender::QPointLight(lightEntity);
Qt3DCore::QTransform *lightTransform = new Qt3DCore::QTransform(rootEntity);
lightTransform->setTranslation(QVector3D(10.0f, 20.0f, 30.0f));
lightEntity->addComponent(pointLight);
lightEntity->addComponent(lightTransform);
Qt3DCore::QEntity *cubeEntity = new Qt3DCore::QEntity(rootEntity);
Qt3DRender::QSceneLoader *sceneLoader = new Qt3DRender::QSceneLoader(cubeEntity);
sceneLoader->setSource(QUrl("qrc:/Models/Cube.obj"));
cubeEntity->addComponent(sceneLoader);
Qt3DCore::QTransform *cubeTransform = new Qt3DCore::QTransform(cubeEntity);
cubeTransform->setScale(7.0f);
cubeEntity->addComponent(cubeTransform);
QStringList list = sceneLoader->entityNames();
Qt3DExtras::QPhongMaterial *material = new Qt3DExtras::QPhongMaterial(rootEntity);
rootEntity->addComponent(material);
Qt3DExtras::QOrbitCameraController *cameraController = new Qt3DExtras::QOrbitCameraController(rootEntity);
cameraController->setCamera(camera);
cameraController->setLookSpeed(180.0f);
cameraController->setLinearSpeed(50.0f);
view.setRootEntity(rootEntity);
view.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks