1   2   3
Ім'я файлу: Курсова (3) (1).docx
Розширення: docx
Розмір: 2331кб.
Дата: 27.01.2023
скачати
Пов'язані файли:
Кишеньковий довыдник.doc

Результати роботи проекту

Кінцевий вигляд проекту на С++ та .QML:



Рисунок 24,25

Результат проекту (оскільки для двох мов результат ідентичний показано буде лише кілька рисунків):



Рисунок 26



Рисунок 27

Висновок

У даній курсовій роботі був розроблений крос-платформенний проект для демонстрації основ 3D графіки. Для досягнення поставленої цілі були розкриті наступні етапи:

  • Аналіз та опис програмного середовища

  • Проект програми, який включає розробку діаграми об'єктів та наслідування, розробку алгоритмів.

  • Програмування проекту на двох мовах, з акцентуванням уваги на різницях за схожості розробки.

  • Аналіз та демонстрація результатів

Дану програму можна використовувати для вивчення основ програмування 3D графіки на фрейворку Qt. Програма не вимоглива до характеристик вашого ПК та добре структурована для кращого розуміння.

При оформленні курсового проекту були одержані навики написання програмного забезпечення, а також великий практичний досвід роботи з мовою програмування C++ у середовищі Qt Creator, а також QML, з використанням Qt Quick.

Теоретичні відомості були закріплені практичними заняттями.

Список літератури

  1. Qt Documentation: Signals & slots https://doc.qt.io/qt-6/signalsandslots

  2. 2. Qt Documentation: MetaObjects

  3. https://doc.qt.io/qt-6/metaobjects

  4. Qt Wiki: https://wiki.qt.io/About_Qt


Додаток

Повний код програми на С++:

Основний скрипт main.cpp

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include "cameracontroller.h"
Qt3DCore::QEntity *createScene();

int main(int argc, char *argv[])

{

QGuiApplication app(argc, argv);
Qt3DExtras::Qt3DWindow view;
Qt3DCore::QEntity *rootEntity = createScene();
Qt3DRender::QCamera *camera =view.camera();

camera->lens()->setPerspectiveProjection(60,(float)view.width()/view.height(),0.1f,1000.0f);

camera->setPosition(QVector3D(0.0f,0.0f,40.0f));

camera->setViewCenter(QVector3D(0.0f,0.0f,0.0f));

CameraController *cameraController = new CameraController(rootEntity);

cameraController->setCamera(camera);

cameraController->setLookSpeed(100.0f);

cameraController->setLinearSpeed(50.0f);

view.setRootEntity(rootEntity);

view.show();

return app.exec();

}
Qt3DCore::QEntity *createScene()

{
Qt3DCore::QEntity *resultEntity = new Qt3DCore::QEntity;

Qt3DExtras::QSkyboxEntity *skyboxEntity = new Qt3DExtras::QSkyboxEntity(resultEntity);

skyboxEntity->setBaseName("qrc:/res/skybox");

skyboxEntity->setExtension(".tga");
const float baseScale = 0.1f;
Qt3DCore::QTransform *skyTransform = new Qt3DCore::QTransform(skyboxEntity);

skyTransform->setTranslation(QVector3D(0.0f, baseScale / 8.0f - 0.001f, 0.0f ));

skyTransform->setScale3D(QVector3D(1, 1, 1));
skyboxEntity->addComponent(skyTransform);
Qt3DCore::QEntity *torusEntity = new Qt3DCore::QEntity(resultEntity);
Qt3DExtras::QTorusMesh *torusMesh = new Qt3DExtras::QTorusMesh(torusEntity);

torusMesh->setRadius(15.0f);

torusMesh->setMinorRadius(6.0f);

torusMesh->setSlices(16);

torusMesh->setRings(32);
Qt3DExtras::QPhongMaterial *torusMaterial = new Qt3DExtras::QPhongMaterial(torusEntity);

torusMaterial->setDiffuse(QColor(255,0,255));

torusMaterial->setSpecular(QColor(0,255,255));

Qt3DCore::QTransform *torusTransform = new Qt3DCore::QTransform(torusEntity);

torusTransform->setTranslation(QVector3D(-30.0f,0.0f,0.0f));
torusEntity->addComponent(torusMesh);

torusEntity->addComponent(torusMaterial);

torusEntity->addComponent(torusTransform);
Qt3DCore::QEntity *cuboidEntity = new Qt3DCore::QEntity(resultEntity);
Qt3DExtras::QCuboidMesh *cuboidMesh = new Qt3DExtras::QCuboidMesh(cuboidEntity);

cuboidMesh->setXExtent(12);

cuboidMesh->setYExtent(12);

cuboidMesh->setZExtent(12);
Qt3DExtras::QPhongMaterial *cuboidMaterial = new Qt3DExtras::QPhongMaterial(cuboidEntity);

cuboidMaterial->setDiffuse(QColor(0,0,255));

cuboidMaterial->setSpecular(QColor(255,255,255));
Qt3DCore::QTransform *cuboidTransform = new Qt3DCore::QTransform(cuboidEntity);

cuboidTransform->setTranslation(QVector3D(-30.0f,0.0f,0.0f));

cuboidTransform->setRotationX(55);

cuboidTransform->setRotationZ(45);
cuboidEntity->addComponent(cuboidMesh);

cuboidEntity->addComponent(cuboidMaterial);

cuboidEntity->addComponent(cuboidTransform);
Qt3DCore::QEntity *planeEntity = new Qt3DCore::QEntity(resultEntity);
Qt3DExtras::QPlaneMesh *planeMesh = new Qt3DExtras::QPlaneMesh(planeEntity);

planeMesh->setWidth(1000);

planeMesh->setHeight(1000);
Qt3DExtras::QPhongMaterial *planeMaterial = new Qt3DExtras::QPhongMaterial(planeEntity);

planeMaterial->setDiffuse(QColor(0,255,50));
Qt3DCore::QTransform *planeTransform = new Qt3DCore::QTransform(planeEntity);

planeTransform->setTranslation(QVector3D(0,-20,0));
planeEntity->addComponent(planeMesh);

planeEntity->addComponent(planeMaterial);

planeEntity->addComponent(planeTransform);
Qt3DCore::QEntity *coneEntity = new Qt3DCore::QEntity(resultEntity);
Qt3DExtras::QConeMesh *coneMesh = new Qt3DExtras::QConeMesh(coneEntity);

coneMesh->setBottomRadius(15);

coneMesh->setRings(32);

coneMesh->setSlices(16);

coneMesh->setTopRadius(3);

coneMesh->setLength(40);
Qt3DExtras::QPhongMaterial *coneMaterial = new Qt3DExtras::QPhongMaterial(coneEntity);

coneMaterial->setDiffuse(QColor(255,212,111));
Qt3DCore::QTransform *coneTransform = new Qt3DCore::QTransform(coneEntity);

coneTransform->setTranslation(QVector3D(30,0,0));

coneTransform->setRotationZ(180);
coneEntity->addComponent(coneMesh);

coneEntity->addComponent(coneMaterial);

coneEntity->addComponent(coneTransform);
Qt3DCore::QEntity *sphereEntity1 = new Qt3DCore::QEntity(resultEntity);
Qt3DExtras::QSphereMesh *sphereMesh1 = new Qt3DExtras::QSphereMesh(sphereEntity1);

sphereMesh1->setRadius(8.5);

sphereMesh1->setRings(32);

sphereMesh1->setSlices(32);
Qt3DExtras::QPhongMaterial *sphereMaterial1 = new Qt3DExtras::QPhongMaterial(sphereEntity1);

sphereMaterial1->setDiffuse(QColor(101,71,0));
Qt3DCore::QTransform *sphereTransform1 = new Qt3DCore::QTransform(sphereEntity1);

sphereTransform1->setTranslation(QVector3D(25,20,-3));
sphereEntity1->addComponent(sphereMesh1);

sphereEntity1->addComponent(sphereMaterial1);

sphereEntity1->addComponent(sphereTransform1);
Qt3DCore::QEntity *sphereEntity2 = new Qt3DCore::QEntity(resultEntity);
Qt3DExtras::QSphereMesh *sphereMesh2 = new Qt3DExtras::QSphereMesh(sphereEntity2);

sphereMesh2->setRadius(9);

sphereMesh2->setRings(32);

sphereMesh2->setSlices(32);
Qt3DExtras::QPhongMaterial *sphereMaterial2 = new Qt3DExtras::QPhongMaterial(sphereEntity2);

sphereMaterial2->setDiffuse(QColor(247,189,249));
Qt3DCore::QTransform *sphereTransform2 = new Qt3DCore::QTransform(sphereEntity2);

sphereTransform2->setTranslation(QVector3D(35,20,-3));
sphereEntity2->addComponent(sphereMesh2);

sphereEntity2->addComponent(sphereMaterial2);

sphereEntity2->addComponent(sphereTransform2);
Qt3DCore::QEntity *sphereEntity3 = new Qt3DCore::QEntity(resultEntity);
Qt3DExtras::QSphereMesh *sphereMesh3 = new Qt3DExtras::QSphereMesh(sphereEntity3);

sphereMesh3->setRadius(9);

sphereMesh3->setRings(32);

sphereMesh3->setSlices(32);
Qt3DExtras::QPhongMaterial *sphereMaterial3 = new Qt3DExtras::QPhongMaterial(sphereEntity3);

sphereMaterial3->setDiffuse(QColor(198,255,159));
Qt3DCore::QTransform *sphereTransform3 = new Qt3DCore::QTransform(sphereEntity3);

sphereTransform3->setTranslation(QVector3D(30,20,5));
sphereEntity3->addComponent(sphereMesh3);

sphereEntity3->addComponent(sphereMaterial3);

sphereEntity3->addComponent(sphereTransform3);
Qt3DCore::QEntity *lightEntity1 = new Qt3DCore::QEntity(resultEntity);
Qt3DRender::QPointLight *pointLight1 = new Qt3DRender::QPointLight(lightEntity1);
Qt3DCore::QTransform *lightTransform1 = new Qt3DCore::QTransform(lightEntity1);

lightTransform1->setTranslation(QVector3D(-20.0f,0.0f,20.0f));
lightEntity1->addComponent(pointLight1);

lightEntity1->addComponent(lightTransform1);
Qt3DCore::QEntity *lightEntity2 = new Qt3DCore::QEntity(resultEntity);
Qt3DRender::QPointLight *pointLight2 = new Qt3DRender::QPointLight(lightEntity2);
Qt3DCore::QTransform *lightTransform2 = new Qt3DCore::QTransform(lightEntity2);

lightTransform2->setTranslation(QVector3D(0.0f,50.0f,0.0f));
lightEntity2->addComponent(pointLight2);

lightEntity2->addComponent(lightTransform2);
Qt3DCore::QEntity *lightEntity3 = new Qt3DCore::QEntity(resultEntity);
Qt3DRender::QPointLight *pointLight3 = new Qt3DRender::QPointLight(lightEntity3);
Qt3DCore::QTransform *lightTransform3 = new Qt3DCore::QTransform(lightEntity3);

lightTransform3->setTranslation(QVector3D(30.0f,50.0f,0.0f));
lightEntity3->addComponent(pointLight3);

lightEntity3->addComponent(lightTransform3);
return resultEntity;

}

Скрипт cameracontroller.cpp

#include "cameracontroller.h"
CameraController::CameraController(Qt3DCore::QNode *parent):

Qt3DCore::QEntity(parent)

{

m_keyUpPressed = false;

m_keyDownPressed = false;

m_keyLeftPressed = false;

m_keyRightPressed = false;

m_dx = 0;

m_dy = 0;

m_lookSpeed = 180.0;

m_linearSpeed = 0;

m_camera = 0;

m_foV = 30;
m_mouseDevice = new Qt3DInput::QMouseDevice(this);

m_keyboardDevice = new Qt3DInput::QKeyboardDevice(this);

m_logicalDevice = new Qt3DInput::QLogicalDevice(this);
m_keyUpAction = new Qt3DInput::QAction(this);

m_keyDownAction = new Qt3DInput::QAction(this);

m_keyLeftAction = new Qt3DInput::QAction(this);

m_keyRightAction = new Qt3DInput::QAction(this);

m_keySpaceAction = new Qt3DInput::QAction(this);

m_keyLeftShiftAction = new Qt3DInput::QAction(this);

m_keyUpInput = new Qt3DInput::QActionInput(this);

m_keyDownInput = new Qt3DInput::QActionInput(this);

m_keyLeftInput = new Qt3DInput::QActionInput(this);

m_keyRightInput = new Qt3DInput::QActionInput(this);

m_keySpaceInput = new Qt3DInput::QActionInput(this);

m_keyLeftShiftInput = new Qt3DInput::QActionInput(this);

m_xAxis = new Qt3DInput::QAxis(this);

m_yAxis = new Qt3DInput::QAxis(this);

m_mouseXInput = new Qt3DInput::QAnalogAxisInput(this);

m_mouseYInput = new Qt3DInput::QAnalogAxisInput(this);

m_frameAction = new Qt3DLogic::QFrameAction(this);
m_keyUpInput->setButtons(QVector() << Qt::Key_Up << Qt::Key_W);

m_keyUpInput->setSourceDevice(m_keyboardDevice);

m_keyUpAction->addInput(m_keyUpInput);

m_keyUpAction->setObjectName("Key_Up");
m_keyDownInput->setButtons(QVector() << Qt::Key_Down << Qt::Key_S);

m_keyDownInput->setSourceDevice(m_keyboardDevice);

m_keyDownAction->addInput(m_keyDownInput);

m_keyDownAction->setObjectName("Key_Down");
m_keyLeftInput->setButtons(QVector() << Qt::Key_Left << Qt::Key_A);

m_keyLeftInput->setSourceDevice(m_keyboardDevice);

m_keyLeftAction->addInput(m_keyLeftInput);

m_keyLeftAction->setObjectName("Key_Left");
m_keyRightInput->setButtons(QVector() << Qt::Key_Right << Qt::Key_D);

m_keyRightInput->setSourceDevice(m_keyboardDevice);

m_keyRightAction->addInput(m_keyRightInput);

m_keyRightAction->setObjectName("Key_Right");
m_keySpaceInput->setButtons(QVector() << Qt::Key_Space);

m_keySpaceInput->setSourceDevice(m_keyboardDevice);

m_keySpaceAction->addInput(m_keySpaceInput);

m_keySpaceAction->setObjectName("Key_Space");
m_keyLeftShiftInput->setButtons(QVector() << Qt::Key_Shift);

m_keyLeftShiftInput->setSourceDevice(m_keyboardDevice);

m_keyLeftShiftAction->addInput(m_keyLeftShiftInput);

m_keyLeftShiftAction->setObjectName("Key_Shift");

m_mouseXInput->setAxis(Qt3DInput::QMouseDevice::X);

m_mouseXInput->setSourceDevice(m_mouseDevice);

m_xAxis->addInput(m_mouseXInput);

m_xAxis->setObjectName("X_Axis");
m_mouseYInput->setAxis(Qt3DInput::QMouseDevice::Y);

m_mouseYInput->setSourceDevice(m_mouseDevice);

m_yAxis->addInput(m_mouseYInput);

m_yAxis->setObjectName("Y_Axis");
m_logicalDevice->addAction(m_keyUpAction);

m_logicalDevice->addAction(m_keyDownAction);

m_logicalDevice->addAction(m_keyLeftAction);

m_logicalDevice->addAction(m_keyRightAction);

m_logicalDevice->addAction(m_keySpaceAction);

m_logicalDevice->addAction(m_keyLeftShiftAction);

m_logicalDevice->addAxis(m_xAxis);

m_logicalDevice->addAxis(m_yAxis);
connect(m_keyUpAction,SIGNAL(activeChanged(bool)),this,SLOT(activeChanged(bool)));

connect(m_keyDownAction,SIGNAL(activeChanged(bool)),this,SLOT(activeChanged(bool)));

connect(m_keyRightAction,SIGNAL(activeChanged(bool)),this,SLOT(activeChanged(bool)));

connect(m_keyLeftAction,SIGNAL(activeChanged(bool)),this,SLOT(activeChanged(bool)));

connect(m_keySpaceAction,SIGNAL(activeChanged(bool)),this,SLOT(activeChanged(bool)));

connect(m_keyLeftShiftAction,SIGNAL(activeChanged(bool)),this,SLOT(activeChanged(bool)));

connect(m_xAxis, SIGNAL(valueChanged(float)),this,SLOT(valueChanged(float)));

connect(m_yAxis, SIGNAL(valueChanged(float)),this,SLOT(valueChanged(float)));

connect(m_frameAction,SIGNAL(triggered(float)),this,SLOT(frameActionTriggered(float)));

}
void CameraController::setCamera(Qt3DRender::QCamera *camera)

{

m_camera=camera;

}
float CameraController::lookSpeed() const

{

return m_lookSpeed;

}
void CameraController::setLookSpeed(float lookSpeed)

{

m_lookSpeed=lookSpeed;

}
float CameraController::linearSpeed() const

{

return m_linearSpeed;

}
void CameraController::setLinearSpeed(float linearSpeed)

{

m_linearSpeed=linearSpeed;

}
void CameraController::activeChanged(bool isActive)

{

if(sender()->objectName() == "Key_Up")

{

m_keyUpPressed = isActive;

}

else if(sender()->objectName() == "Key_Down")

{

m_keyDownPressed = isActive;

}

else if(sender()->objectName() == "Key_Left")

{

m_keyLeftPressed = isActive;

}

else if(sender()->objectName() == "Key_Right")

{

m_keyRightPressed = isActive;

}

else if(sender()->objectName() == "Key_Space")

{

m_keySpacePressed = isActive;

}

else if(sender()->objectName() == "Key_Shift")

{

m_keyLeftShiftPressed = isActive;

}

}
void CameraController::valueChanged(float value)

{

if(sender()->objectName() == "X_Axis")

{

m_dx = value;

}

else if (sender()->objectName() == "Y_Axis")

{

m_dy = value;

}

}
void CameraController::frameActionTriggered(float dt)

{

if(m_camera != 0)

{

m_camera->pan(m_dx*m_lookSpeed*dt);

m_camera->tilt(m_dy*m_lookSpeed*dt);
if(m_keyUpPressed == true)

{

m_camera->translate(QVector3D(0,0,2),Qt3DRender::QCamera::TranslateViewCenter);

}

if(m_keyDownPressed == true)

{

m_camera->translate(QVector3D(0,0,-2),Qt3DRender::QCamera::TranslateViewCenter);

}

if(m_keyLeftPressed == true)

{

m_camera->translate(QVector3D(-2,0,0),Qt3DRender::QCamera::TranslateViewCenter);

}

if(m_keyRightPressed == true)

{

m_camera->translate(QVector3D(2,0,0),Qt3DRender::QCamera::TranslateViewCenter);

}

if(m_keySpacePressed == true)

{

m_camera->translate(QVector3D(0,2,0),Qt3DRender::QCamera::TranslateViewCenter);

}

if(m_keyLeftShiftPressed == true)

{

m_camera->translate(QVector3D(0,-2,0),Qt3DRender::QCamera::TranslateViewCenter);

}

}

}

Скрипт resources.cpp





res/skybox_negx.tga

res/skybox_negy.tga

res/skybox_negz.tga

res/skybox_posx.tga

res/skybox_posy.tga

res/skybox_posz.tga





Скрипт cameracontroller.h

#ifndef CAMERACONTROLLER_H

#define CAMERACONTROLLER_H
#include

#include

#include

#include

#include

#include

#include

#include

#include

#include
class CameraController : public Qt3DCore::QEntity

{

Q_OBJECT

public:

1   2   3

скачати

© Усі права захищені
написати до нас