├── .gitignore ├── Additional ├── solarinfoloader.cpp └── solarinfoloader.h ├── CMakeLists.txt ├── Core ├── Render │ ├── solardiffuseeffect.cpp │ ├── solardiffuseeffect.h │ ├── solarforwardframegraph.cpp │ ├── solarforwardframegraph.h │ ├── solarframegraph.cpp │ ├── solarframegraph.h │ ├── solarlight.cpp │ ├── solarlight.h │ ├── solarmaterial.cpp │ ├── solarmaterial.h │ ├── solarobjecteffect.cpp │ ├── solarobjecteffect.h │ ├── solarshadoweffect.cpp │ ├── solarshadoweffect.h │ ├── solarstandardframegraph.cpp │ └── solarstandardframegraph.h ├── SolarObjects │ ├── abstractsolarobject.cpp │ ├── abstractsolarobject.h │ ├── solarobjects.cpp │ └── solarobjects.h ├── animator.cpp ├── animator.h ├── cameracontroller.cpp ├── cameracontroller.h ├── mathcore.cpp ├── mathcore.h ├── object3dbuilder.h ├── object3dcontainer.cpp ├── object3dcontainer.h ├── solarobjectscontainer.cpp ├── solarobjectscontainer.h ├── solarobjectsfactory.h ├── utils.cpp └── utils.h ├── Interface └── iframegraph.h ├── LICENSE ├── Parser ├── solarparser.cpp └── solarparser.h ├── QML ├── Controls.qml ├── DatabaseLabel.qml ├── DateText.qml ├── FpsLabel.qml ├── Info.qml ├── PlanetButton.qml ├── PlanetList.qml ├── SolarEntityMain.qml ├── SolarFrame.qml ├── SolarSystemMain.qml ├── SpeedSlider.qml ├── TransparentButton.qml └── UserOptions.qml ├── README.md ├── Resources ├── Database │ └── SolarDB.db ├── Images │ ├── calendar_icon.png │ ├── earth.png │ ├── earthcloudmapcolortrans.png │ ├── earthcloudmapcolortransnormal.png │ ├── earthcloudmapspec.jpg │ ├── earthmap1k.jpg │ ├── earthnormal1k.jpg │ ├── earthspec1k.jpg │ ├── exit_icon.png │ ├── info_icon.png │ ├── jupiter.png │ ├── jupitermap.jpg │ ├── jupiternormal.jpg │ ├── mars.png │ ├── marsmap1k.jpg │ ├── marsnormal1k.jpg │ ├── mercury.png │ ├── mercurymap.jpg │ ├── mercurynormal.jpg │ ├── moonmap1k.jpg │ ├── moonnormal1k.jpg │ ├── neptune.png │ ├── neptunemap.jpg │ ├── neptunenormal.jpg │ ├── options_icon.png │ ├── planet_icon.png │ ├── pluto.png │ ├── plutomap.jpg │ ├── plutonormal.jpg │ ├── saturn.png │ ├── saturn_rings.png │ ├── saturnmap.jpg │ ├── saturnnormal.jpg │ ├── saturnringcolortrans.png │ ├── saturnringcolortransnormal.png │ ├── screen_icon.png │ ├── solar_system.jpg │ ├── solarsystem.png │ ├── solarsystem_icon.ico │ ├── solarsystem_icon.png │ ├── sun.png │ ├── sun_map.jpg │ ├── sun_normal.jpg │ ├── sunmap.jpg │ ├── uranus.png │ ├── uranusmap.jpg │ ├── uranusnormal.jpg │ ├── uranusringcolortrans.png │ ├── uranusringcolortransnormal.png │ ├── venus.png │ ├── venus_atmo.jpg │ ├── venus_atmonormal.jpg │ ├── venus_map.jpg │ ├── venusmap.jpg │ └── venusnormal.jpg ├── Info.txt ├── Meshes │ ├── planetRing.obj │ └── ring.obj ├── Shaders │ ├── diffuse.frag │ ├── diffuse.vert │ ├── diffusenormal.frag │ ├── diffusenormal.vert │ ├── diffuseshadow.frag │ ├── diffuseshadow.vert │ ├── shadowmap.frag │ ├── shadowmap.vert │ ├── skybox.frag │ └── skybox.vert └── Skybox │ ├── stars_negx.webp │ ├── stars_negy.webp │ ├── stars_negz.webp │ ├── stars_posx.webp │ ├── stars_posy.webp │ └── stars_posz.webp ├── Scene ├── MaterialObjects │ ├── diffuseobject.cpp │ ├── diffuseobject.h │ ├── normaldiffusealphaobject.cpp │ ├── normaldiffusealphaobject.h │ ├── normaldiffuseobject.cpp │ ├── normaldiffuseobject.h │ ├── unlitobject.cpp │ └── unlitobject.h ├── SceneObjects │ ├── earthcloud.cpp │ ├── earthcloud.h │ ├── emptysolarobject.cpp │ ├── emptysolarobject.h │ ├── planet.cpp │ ├── planet.h │ ├── planetring.cpp │ ├── planetring.h │ ├── solarskybox.cpp │ ├── solarskybox.h │ ├── sun.cpp │ └── sun.h ├── fpscounter.cpp ├── fpscounter.h ├── object3d.cpp ├── object3d.h ├── solarentity.cpp └── solarentity.h ├── UI ├── quickui.cpp └── quickui.h ├── android ├── AndroidManifest.xml └── res │ └── drawable-ldpi │ └── icon.png ├── dbconnector.cpp ├── dbconnector.h ├── main.cpp ├── object.cpp ├── object.h ├── res.qrc ├── solarsystemcore.cpp └── solarsystemcore.h /.gitignore: -------------------------------------------------------------------------------- 1 | /release 2 | /.qmake.stash 3 | /object_script.SolarSystem.Release 4 | /res_qmlcache.qrc 5 | /SolarSystem.pro.user 6 | /SolarSystem_resource.rc 7 | /Makefile 8 | /Makefile.Debug 9 | /Makefile.Release 10 | /object_script.SolarSystem.Debug 11 | /debug 12 | /SolarSystem.pro.user.4.10-pre1 13 | /CMakeLists.txt.user 14 | -------------------------------------------------------------------------------- /Additional/solarinfoloader.cpp: -------------------------------------------------------------------------------- 1 | #include "solarinfoloader.h" 2 | #include 3 | #include 4 | 5 | SolarSystem::SolarInfoLoader::SolarInfoLoader(QObject* parent): 6 | QObject(parent) 7 | { 8 | } 9 | 10 | QString SolarSystem::SolarInfoLoader::loadInfo() const 11 | { 12 | QFile infoFile(QStringLiteral(":/Resources/Info.txt")); 13 | 14 | if (!infoFile.open(QIODevice::ReadOnly)) 15 | qDebug() << "Can not open Info file"; 16 | 17 | return static_cast(infoFile.readAll()); 18 | } 19 | 20 | QString SolarSystem::SolarInfoLoader::loadInfo(const QString& insertVersion) const 21 | { 22 | return loadInfo().replace("%%", insertVersion); 23 | } 24 | 25 | QObject* SolarSystem::infoLoaderProvider(QQmlEngine* engine, QJSEngine* scriptEngine) 26 | { 27 | Q_UNUSED(engine) 28 | Q_UNUSED(scriptEngine) 29 | 30 | return new SolarSystem::SolarInfoLoader(); 31 | } 32 | -------------------------------------------------------------------------------- /Additional/solarinfoloader.h: -------------------------------------------------------------------------------- 1 | #ifndef SOLARINFOLOADER_H 2 | #define SOLARINFOLOADER_H 3 | 4 | #include 5 | #include 6 | 7 | class QQmlEngine; 8 | class QJSEngine; 9 | 10 | namespace SolarSystem 11 | { 12 | /// loads info from file to QML 13 | class SolarInfoLoader final : public QObject 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | explicit SolarInfoLoader(QObject* parent = nullptr); 19 | 20 | // loads info 21 | Q_INVOKABLE QString loadInfo() const; 22 | 23 | // loads info and inserts version to it 24 | Q_INVOKABLE QString loadInfo(const QString& insertVersion) const; 25 | }; 26 | 27 | QObject* infoLoaderProvider(QQmlEngine* engine, QJSEngine* scriptEngine); 28 | } 29 | 30 | #endif // SOLARINFOLOADER_H 31 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16) 2 | project(SolarSystem VERSION 1.0 LANGUAGES CXX) 3 | 4 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 5 | 6 | if (MSVC) 7 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17") 8 | else() 9 | set(CMAKE_CXX_STANDARD 17) 10 | endif() 11 | 12 | find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core) 13 | find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS 3DCore 3DExtras 3DInput 3DQuickExtras 3DRender Gui Qml Quick Sql) 14 | 15 | qt_standard_project_setup() 16 | 17 | qt_add_executable(SolarSystem WIN32 MACOSX_BUNDLE 18 | Additional/solarinfoloader.cpp Additional/solarinfoloader.h 19 | Core/Render/solardiffuseeffect.cpp Core/Render/solardiffuseeffect.h 20 | Core/Render/solarforwardframegraph.cpp Core/Render/solarforwardframegraph.h 21 | Core/Render/solarframegraph.cpp Core/Render/solarframegraph.h 22 | Core/Render/solarlight.cpp Core/Render/solarlight.h 23 | Core/Render/solarmaterial.cpp Core/Render/solarmaterial.h 24 | Core/Render/solarobjecteffect.cpp Core/Render/solarobjecteffect.h 25 | Core/Render/solarshadoweffect.cpp Core/Render/solarshadoweffect.h 26 | Core/Render/solarstandardframegraph.cpp Core/Render/solarstandardframegraph.h 27 | Core/SolarObjects/abstractsolarobject.cpp Core/SolarObjects/abstractsolarobject.h 28 | Core/SolarObjects/solarobjects.cpp Core/SolarObjects/solarobjects.h 29 | Core/animator.cpp Core/animator.h 30 | Core/cameracontroller.cpp Core/cameracontroller.h 31 | Core/mathcore.cpp Core/mathcore.h 32 | Core/object3dbuilder.h 33 | Core/object3dcontainer.cpp Core/object3dcontainer.h 34 | Core/solarobjectscontainer.cpp Core/solarobjectscontainer.h 35 | Core/solarobjectsfactory.h 36 | Core/utils.cpp Core/utils.h 37 | Interface/iframegraph.h 38 | Parser/solarparser.cpp Parser/solarparser.h 39 | Scene/MaterialObjects/diffuseobject.cpp Scene/MaterialObjects/diffuseobject.h 40 | Scene/MaterialObjects/normaldiffusealphaobject.cpp Scene/MaterialObjects/normaldiffusealphaobject.h 41 | Scene/MaterialObjects/normaldiffuseobject.cpp Scene/MaterialObjects/normaldiffuseobject.h 42 | Scene/MaterialObjects/unlitobject.cpp Scene/MaterialObjects/unlitobject.h 43 | Scene/SceneObjects/earthcloud.cpp Scene/SceneObjects/earthcloud.h 44 | Scene/SceneObjects/emptysolarobject.cpp Scene/SceneObjects/emptysolarobject.h 45 | Scene/SceneObjects/planet.cpp Scene/SceneObjects/planet.h 46 | Scene/SceneObjects/planetring.cpp Scene/SceneObjects/planetring.h 47 | Scene/SceneObjects/solarskybox.cpp Scene/SceneObjects/solarskybox.h 48 | Scene/SceneObjects/sun.cpp Scene/SceneObjects/sun.h 49 | Scene/fpscounter.cpp Scene/fpscounter.h 50 | Scene/object3d.cpp Scene/object3d.h 51 | Scene/solarentity.cpp Scene/solarentity.h 52 | UI/quickui.cpp UI/quickui.h 53 | dbconnector.cpp dbconnector.h 54 | main.cpp 55 | object.cpp object.h 56 | solarsystemcore.cpp solarsystemcore.h 57 | android/AndroidManifest.xml 58 | ) 59 | 60 | qt_add_qml_module(SolarSystem 61 | URI SolarSystemQml 62 | VERSION ${PROJECT_VERSION} 63 | QML_FILES 64 | QML/SolarEntityMain.qml 65 | QML/SolarSystemMain.qml 66 | QML/DateText.qml 67 | QML/TransparentButton.qml 68 | QML/Controls.qml 69 | QML/SolarFrame.qml 70 | QML/PlanetList.qml 71 | QML/PlanetButton.qml 72 | QML/Info.qml 73 | QML/FpsLabel.qml 74 | QML/SpeedSlider.qml 75 | QML/DatabaseLabel.qml 76 | QML/UserOptions.qml 77 | RESOURCES 78 | Resources/Skybox/stars_negx.webp 79 | Resources/Skybox/stars_negy.webp 80 | Resources/Skybox/stars_negz.webp 81 | Resources/Skybox/stars_posx.webp 82 | Resources/Skybox/stars_posy.webp 83 | Resources/Skybox/stars_posz.webp 84 | Resources/Images/earth.png 85 | Resources/Images/earthcloudmapcolortrans.png 86 | Resources/Images/earthcloudmapspec.jpg 87 | Resources/Images/earthmap1k.jpg 88 | Resources/Images/earthnormal1k.jpg 89 | Resources/Images/earthspec1k.jpg 90 | Resources/Images/jupiter.png 91 | Resources/Images/jupitermap.jpg 92 | Resources/Images/mars.png 93 | Resources/Images/marsmap1k.jpg 94 | Resources/Images/marsnormal1k.jpg 95 | Resources/Images/mercury.png 96 | Resources/Images/mercurymap.jpg 97 | Resources/Images/mercurynormal.jpg 98 | Resources/Images/moonmap1k.jpg 99 | Resources/Images/moonnormal1k.jpg 100 | Resources/Images/neptune.png 101 | Resources/Images/neptunemap.jpg 102 | Resources/Images/saturn.png 103 | Resources/Images/saturnmap.jpg 104 | Resources/Images/saturnringcolortrans.png 105 | Resources/Images/sun.png 106 | Resources/Images/sunmap.jpg 107 | Resources/Images/uranus.png 108 | Resources/Images/uranusmap.jpg 109 | Resources/Images/uranusringcolortrans.png 110 | Resources/Images/venus.png 111 | Resources/Meshes/ring.obj 112 | Resources/Images/sun_map.jpg 113 | Resources/Images/jupiternormal.jpg 114 | Resources/Images/saturnnormal.jpg 115 | Resources/Images/uranusnormal.jpg 116 | Resources/Images/neptunenormal.jpg 117 | Resources/Images/saturnringcolortransnormal.png 118 | Resources/Images/uranusringcolortransnormal.png 119 | Resources/Images/planet_icon.png 120 | Resources/Images/options_icon.png 121 | Resources/Images/calendar_icon.png 122 | Resources/Images/info_icon.png 123 | Resources/Images/venus_atmo.jpg 124 | Resources/Images/venus_atmonormal.jpg 125 | Resources/Images/earthcloudmapcolortransnormal.png 126 | Resources/Images/solarsystem.png 127 | Resources/Images/solarsystem_icon.png 128 | Resources/Images/exit_icon.png 129 | Resources/Images/solarsystem_icon.ico 130 | Resources/Images/pluto.png 131 | Resources/Images/plutomap.jpg 132 | Resources/Images/plutonormal.jpg 133 | Resources/Images/saturn_rings.png 134 | Resources/Images/screen_icon.png 135 | Resources/Meshes/planetRing.obj 136 | Resources/Shaders/shadowmap.vert 137 | Resources/Shaders/diffusenormal.frag 138 | Resources/Shaders/diffusenormal.vert 139 | Resources/Shaders/diffuseshadow.vert 140 | Resources/Shaders/shadowmap.frag 141 | Resources/Shaders/diffuseshadow.frag 142 | Resources/Images/sun_normal.jpg 143 | Resources/Shaders/diffuse.frag 144 | Resources/Shaders/diffuse.vert 145 | Resources/Shaders/skybox.frag 146 | Resources/Shaders/skybox.vert 147 | Resources/Database/SolarDB.db 148 | Resources/Info.txt 149 | NO_RESOURCE_TARGET_PATH 150 | ) 151 | 152 | set(ANDROID_PACKAGE_SOURCE_DIR ${PROJECT_SOURCE_DIR}/android CACHE INTERNAL "") 153 | 154 | target_link_libraries(SolarSystem PRIVATE 155 | Qt::3DCore 156 | Qt::3DExtras 157 | Qt::3DInput 158 | Qt::3DQuickExtras 159 | Qt::3DRender 160 | Qt::Core 161 | Qt::Gui 162 | Qt::Qml 163 | Qt::Quick 164 | Qt::Sql 165 | ) 166 | 167 | install(TARGETS SolarSystem 168 | BUNDLE DESTINATION . 169 | LIBRARY DESTINATION ${CMAKE_INSTALL_BINDIR} 170 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} 171 | ) 172 | 173 | qt_generate_deploy_qml_app_script( 174 | TARGET SolarSystem 175 | FILENAME_VARIABLE deploy_script 176 | NO_UNSUPPORTED_PLATFORM_ERROR 177 | DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM 178 | MACOS_BUNDLE_POST_BUILD 179 | ) 180 | 181 | install(SCRIPT ${deploy_script}) 182 | -------------------------------------------------------------------------------- /Core/Render/solardiffuseeffect.cpp: -------------------------------------------------------------------------------- 1 | #include "solardiffuseeffect.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | SolarSystem::SolarDiffuseEffect::SolarDiffuseEffect(Qt3DCore::QNode* parent): 12 | QEffect(parent) 13 | { 14 | // create filter keys 15 | auto* desktopKey = new Qt3DRender::QFilterKey(this); 16 | desktopKey->setName("name"); 17 | desktopKey->setValue("Desktop"); 18 | 19 | auto* forwardKey = new Qt3DRender::QFilterKey(this); 20 | forwardKey->setName("pass"); 21 | forwardKey->setValue("forward"); 22 | 23 | // create standard gl pass 24 | Qt3DRender::QRenderPass* glPass = new Qt3DRender::QRenderPass(this); 25 | glPass->setObjectName("glPass"); 26 | glPass->addFilterKey(forwardKey); 27 | 28 | // standard gl pass shader program 29 | Qt3DRender::QShaderProgram* glPassProgram = new Qt3DRender::QShaderProgram(glPass); 30 | glPassProgram->setVertexShaderCode(Qt3DRender::QShaderProgram::loadSource(QUrl::fromLocalFile(":/Resources/Shaders/diffuse.vert"))); 31 | glPassProgram->setFragmentShaderCode(Qt3DRender::QShaderProgram::loadSource(QUrl::fromLocalFile(":/Resources/Shaders/diffuse.frag"))); 32 | 33 | // add gl pass program 34 | glPass->setShaderProgram(glPassProgram); 35 | 36 | //************************** 37 | // tecnique 38 | //************************** 39 | 40 | // create tecniques 41 | Qt3DRender::QTechnique* openglTechnique = new Qt3DRender::QTechnique(this); 42 | 43 | // setup api 44 | auto* api = openglTechnique->graphicsApiFilter(); 45 | api->setApi(Qt3DRender::QGraphicsApiFilter::OpenGL); 46 | api->setProfile(Qt3DRender::QGraphicsApiFilter::CoreProfile); 47 | api->setMajorVersion(3); 48 | api->setMinorVersion(2); 49 | 50 | openglTechnique->addFilterKey(desktopKey); 51 | openglTechnique->addRenderPass(glPass); 52 | 53 | addTechnique(openglTechnique); 54 | } 55 | -------------------------------------------------------------------------------- /Core/Render/solardiffuseeffect.h: -------------------------------------------------------------------------------- 1 | #ifndef SOLARDIFFUSEEFFECT_H 2 | #define SOLARDIFFUSEEFFECT_H 3 | 4 | #include 5 | 6 | namespace SolarSystem 7 | { 8 | // diffuse without light 9 | class SolarDiffuseEffect : public Qt3DRender::QEffect 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | explicit SolarDiffuseEffect(Qt3DCore::QNode* parent = nullptr); 15 | }; 16 | } 17 | 18 | #endif // SOLARDIFFUSEEFFECT_H 19 | -------------------------------------------------------------------------------- /Core/Render/solarforwardframegraph.cpp: -------------------------------------------------------------------------------- 1 | #include "solarforwardframegraph.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | SolarSystem::SolarForwardFrameGraph::SolarForwardFrameGraph(Qt3DCore::QNode* parent): 14 | IFrameGraph(parent) 15 | { 16 | // render 17 | m_filter = new Qt3DRender::QTechniqueFilter(); 18 | 19 | auto* key = new Qt3DRender::QFilterKey(); 20 | key->setName("renderingStyle"); 21 | key->setValue("forward"); 22 | 23 | m_filter->addMatch(key); 24 | 25 | m_surfaceSelector = new Qt3DRender::QRenderSurfaceSelector(m_filter); 26 | 27 | m_viewPort = new Qt3DRender::QViewport(m_surfaceSelector); 28 | m_viewPort->setNormalizedRect(QRectF(0.0, 0.0, 1.0, 1.0)); 29 | 30 | m_cameraSelector = new Qt3DRender::QCameraSelector(m_viewPort); 31 | 32 | m_clearBuffers = new Qt3DRender::QClearBuffers(m_cameraSelector); 33 | m_clearBuffers->setBuffers(Qt3DRender::QClearBuffers::ColorDepthBuffer); 34 | m_clearBuffers->setClearColor(QColor(Qt::black)); 35 | 36 | m_frustum = new Qt3DRender::QFrustumCulling(m_clearBuffers); 37 | 38 | m_sortPolicy = new Qt3DRender::QSortPolicy(m_clearBuffers); 39 | 40 | QVector sortedVector; 41 | sortedVector.push_back(Qt3DRender::QSortPolicy::BackToFront); 42 | sortedVector.push_back(Qt3DRender::QSortPolicy::StateChangeCost); 43 | sortedVector.push_back(Qt3DRender::QSortPolicy::Material); 44 | 45 | m_sortPolicy->setSortTypes(sortedVector); 46 | 47 | setActiveFrameGraph(m_filter); 48 | setRenderPolicy(QRenderSettings::RenderPolicy::Always); 49 | } 50 | 51 | void SolarSystem::SolarForwardFrameGraph::setCamera(Qt3DCore::QEntity* camera) 52 | { 53 | m_cameraSelector->setCamera(camera); 54 | } 55 | -------------------------------------------------------------------------------- /Core/Render/solarforwardframegraph.h: -------------------------------------------------------------------------------- 1 | #ifndef SOLARFORWARDFRAMEGRAPH_H 2 | #define SOLARFORWARDFRAMEGRAPH_H 3 | 4 | #include 5 | 6 | namespace Qt3DRender 7 | { 8 | class QCamera; 9 | class QSortPolicy; 10 | class QClearBuffers; 11 | class QCameraSelector; 12 | class QViewport; 13 | class QRenderSurfaceSelector; 14 | class QTechniqueFilter; 15 | class QFrustumCulling; 16 | } 17 | 18 | namespace SolarSystem 19 | { 20 | // represents simple forward frame graph 21 | class SolarForwardFrameGraph : public IFrameGraph 22 | { 23 | Q_OBJECT 24 | 25 | public: 26 | explicit SolarForwardFrameGraph(Qt3DCore::QNode* parent = nullptr); 27 | virtual void setCamera(Qt3DCore::QEntity* camera) override; 28 | 29 | private: 30 | 31 | // render frame graph elements 32 | Qt3DRender::QSortPolicy* m_sortPolicy; 33 | Qt3DRender::QClearBuffers* m_clearBuffers; 34 | Qt3DRender::QCameraSelector* m_cameraSelector; 35 | Qt3DRender::QViewport* m_viewPort; 36 | Qt3DRender::QRenderSurfaceSelector* m_surfaceSelector; 37 | Qt3DRender::QTechniqueFilter* m_filter; 38 | Qt3DRender::QFrustumCulling* m_frustum; 39 | }; 40 | } 41 | 42 | #endif // SOLARFORWARDFRAMEGRAPH_H 43 | -------------------------------------------------------------------------------- /Core/Render/solarframegraph.cpp: -------------------------------------------------------------------------------- 1 | #include "solarframegraph.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | SolarSystem::SolarFrameGraph::SolarFrameGraph(Qt3DCore::QNode* parent): 16 | QRenderSettings(parent) 17 | { 18 | m_viewPort = new Qt3DRender::QViewport(this); 19 | m_viewPort->setNormalizedRect(QRectF(0, 0, 1.0, 1.0)); 20 | 21 | m_selector = new Qt3DRender::QRenderSurfaceSelector(m_viewPort); 22 | 23 | m_techniqueFilter = new Qt3DRender::QTechniqueFilter(m_selector); 24 | 25 | auto* desktopFilter = new Qt3DRender::QFilterKey(m_techniqueFilter); 26 | desktopFilter->setName("name"); 27 | desktopFilter->setValue("Desktop"); 28 | 29 | m_techniqueFilter->addMatch(desktopFilter); 30 | 31 | // create render pass filter 32 | m_renderPassShadowFilter = new Qt3DRender::QRenderPassFilter(m_techniqueFilter); 33 | 34 | auto* shadowMapFilter = new Qt3DRender::QFilterKey(m_renderPassShadowFilter); 35 | shadowMapFilter->setName("pass"); 36 | shadowMapFilter->setValue("shadowmap"); 37 | 38 | m_renderPassShadowFilter->addMatch(shadowMapFilter); 39 | 40 | // create target selector 41 | m_targetSelector = new Qt3DRender::QRenderTargetSelector(m_renderPassShadowFilter); 42 | 43 | // render target 44 | auto* renderTarget = new Qt3DRender::QRenderTarget(m_targetSelector); 45 | auto* targetOutput = new Qt3DRender::QRenderTargetOutput(renderTarget); 46 | targetOutput->setObjectName("depth"); 47 | targetOutput->setAttachmentPoint(Qt3DRender::QRenderTargetOutput::Depth); 48 | 49 | // create shadow texture 50 | m_texture = new Qt3DRender::QTexture2D; 51 | m_texture->setFormat(Qt3DRender::QAbstractTexture::D24); 52 | m_texture->setGenerateMipMaps(false); 53 | m_texture->setMagnificationFilter(Qt3DRender::QAbstractTexture::Linear); 54 | m_texture->setMinificationFilter(Qt3DRender::QAbstractTexture::Linear); 55 | m_texture->wrapMode()->setX(Qt3DRender::QTextureWrapMode::ClampToEdge); 56 | m_texture->wrapMode()->setY(Qt3DRender::QTextureWrapMode::ClampToEdge); 57 | m_texture->setComparisonFunction(Qt3DRender::QAbstractTexture::CompareLessEqual); 58 | m_texture->setComparisonMode(Qt3DRender::QAbstractTexture::CompareRefToTexture); 59 | 60 | targetOutput->setTexture(m_texture); 61 | renderTarget->addOutput(targetOutput); 62 | 63 | // buffer 64 | auto* clearBuffer = new Qt3DRender::QClearBuffers(m_targetSelector); 65 | clearBuffer->setBuffers(Qt3DRender::QClearBuffers::DepthBuffer); 66 | m_lightCameraSelector = new Qt3DRender::QCameraSelector(clearBuffer); 67 | 68 | // forward render pass fitler 69 | m_renderPassForwardFilter = new Qt3DRender::QRenderPassFilter(m_selector); 70 | 71 | auto* forwardFilter = new Qt3DRender::QFilterKey(m_renderPassForwardFilter); 72 | forwardFilter->setName("pass"); 73 | forwardFilter->setValue("forward"); 74 | 75 | m_renderPassForwardFilter->addMatch(forwardFilter); 76 | 77 | // buffer 78 | auto* forwardClearBuffer = new Qt3DRender::QClearBuffers(m_renderPassForwardFilter); 79 | forwardClearBuffer->setBuffers(Qt3DRender::QClearBuffers::ColorDepthBuffer); 80 | 81 | m_viewCameraSelector = new Qt3DRender::QCameraSelector(forwardClearBuffer); 82 | 83 | setActiveFrameGraph(m_viewPort); 84 | } 85 | 86 | void SolarSystem::SolarFrameGraph::setViewCamera(Qt3DRender::QCamera* viewCamera) 87 | { 88 | m_viewCameraSelector->setCamera(viewCamera); 89 | } 90 | 91 | void SolarSystem::SolarFrameGraph::setLightCamera(Qt3DRender::QCamera* lightCamera) 92 | { 93 | m_lightCameraSelector->setCamera(lightCamera); 94 | } 95 | 96 | Qt3DRender::QCamera* SolarSystem::SolarFrameGraph::viewCamera() const 97 | { 98 | return qobject_cast(m_viewCameraSelector->camera()); 99 | } 100 | 101 | Qt3DRender::QCamera* SolarSystem::SolarFrameGraph::lightCamera() const 102 | { 103 | return qobject_cast(m_lightCameraSelector->camera()); 104 | } 105 | 106 | Qt3DRender::QTexture2D* SolarSystem::SolarFrameGraph::shadowTexture() const 107 | { 108 | return m_texture; 109 | } 110 | -------------------------------------------------------------------------------- /Core/Render/solarframegraph.h: -------------------------------------------------------------------------------- 1 | #ifndef SOLARFRAMEGRAPH_H 2 | #define SOLARFRAMEGRAPH_H 3 | 4 | #include 5 | 6 | namespace Qt3DRender 7 | { 8 | class QCamera; 9 | class QViewport; 10 | class QTexture2D; 11 | class QRenderSurfaceSelector; 12 | class QTechniqueFilter; 13 | class QRenderPassFilter; 14 | class QRenderTargetSelector; 15 | class QCameraSelector; 16 | } 17 | 18 | namespace SolarSystem 19 | { 20 | // represents base active frame graph 21 | class SolarFrameGraph : public Qt3DRender::QRenderSettings 22 | { 23 | Q_OBJECT 24 | 25 | public: 26 | explicit SolarFrameGraph(Qt3DCore::QNode* parent = nullptr); 27 | 28 | // cameras 29 | void setViewCamera(Qt3DRender::QCamera* viewCamera); 30 | Qt3DRender::QCamera* viewCamera() const; 31 | 32 | void setLightCamera(Qt3DRender::QCamera* lightCamera); 33 | Qt3DRender::QCamera* lightCamera() const; 34 | 35 | // shadow texture 36 | Qt3DRender::QTexture2D* shadowTexture() const; 37 | 38 | private: 39 | 40 | // view port 41 | Qt3DRender::QViewport* m_viewPort; 42 | 43 | // texture 44 | Qt3DRender::QTexture2D* m_texture; 45 | 46 | // selector 47 | Qt3DRender::QRenderSurfaceSelector* m_selector; 48 | 49 | // filter 50 | Qt3DRender::QTechniqueFilter* m_techniqueFilter; 51 | 52 | // pass 53 | Qt3DRender::QRenderPassFilter* m_renderPassShadowFilter; 54 | Qt3DRender::QRenderPassFilter* m_renderPassForwardFilter; 55 | 56 | // target selector 57 | Qt3DRender::QRenderTargetSelector* m_targetSelector; 58 | 59 | // camera selectors 60 | Qt3DRender::QCameraSelector* m_lightCameraSelector; 61 | Qt3DRender::QCameraSelector* m_viewCameraSelector; 62 | }; 63 | } 64 | 65 | #endif // SOLARFRAMEGRAPH_H 66 | -------------------------------------------------------------------------------- /Core/Render/solarlight.cpp: -------------------------------------------------------------------------------- 1 | #include "solarlight.h" 2 | #include 3 | #include 4 | 5 | SolarSystem::SolarLight::SolarLight(Qt3DCore::QNode* parent): 6 | Qt3DCore::QEntity(parent), 7 | m_lightCamera(new Qt3DRender::QCamera(this)), 8 | m_intensity(1.0f, 1.0f, 1.0f) 9 | { 10 | m_lightCamera->setObjectName("lightCameraLens"); 11 | m_lightCamera->setProjectionType(Qt3DRender::QCameraLens::ProjectionType::PerspectiveProjection); 12 | m_lightCamera->setFieldOfView(30); 13 | m_lightCamera->setNearPlane(CameraSettings::nearPlane * 0.0001f); 14 | m_lightCamera->setFarPlane(10000000.0f); 15 | m_lightCamera->setPosition(QVector3D(0, 0, 0)); 16 | m_lightCamera->setViewCenter(QVector3D(0, 0, 0)); 17 | m_lightCamera->setUpVector(CameraSettings::defaultUp); 18 | } 19 | 20 | Qt3DRender::QCamera* SolarSystem::SolarLight::camera() const 21 | { 22 | return m_lightCamera; 23 | } 24 | 25 | QMatrix4x4 SolarSystem::SolarLight::lightViewProjection() const 26 | { 27 | return m_lightCamera->projectionMatrix() * m_lightCamera->viewMatrix(); 28 | } 29 | 30 | QVector3D SolarSystem::SolarLight::intensity() const 31 | { 32 | return m_intensity; 33 | } 34 | 35 | void SolarSystem::SolarLight::setIntensity(const QVector3D &intensity) 36 | { 37 | m_intensity = intensity; 38 | } 39 | -------------------------------------------------------------------------------- /Core/Render/solarlight.h: -------------------------------------------------------------------------------- 1 | #ifndef SOLARLIGHT_H 2 | #define SOLARLIGHT_H 3 | 4 | #include 5 | #include 6 | 7 | namespace Qt3DRender 8 | { 9 | class QCamera; 10 | } 11 | 12 | namespace SolarSystem 13 | { 14 | // represents point light 15 | class SolarLight : public Qt3DCore::QEntity 16 | { 17 | Q_OBJECT 18 | 19 | public: 20 | explicit SolarLight(Qt3DCore::QNode* parent = nullptr); 21 | 22 | // returns camera 23 | Qt3DRender::QCamera* camera() const; 24 | 25 | // PV matrix 26 | QMatrix4x4 lightViewProjection() const; 27 | 28 | // returns intensity 29 | QVector3D intensity() const; 30 | 31 | // set intensity 32 | void setIntensity(const QVector3D& intensity); 33 | 34 | private: 35 | Qt3DRender::QCamera* m_lightCamera; 36 | QVector3D m_intensity; 37 | }; 38 | } 39 | 40 | #endif // SOLARLIGHT_H 41 | -------------------------------------------------------------------------------- /Core/Render/solarmaterial.cpp: -------------------------------------------------------------------------------- 1 | #include "solarmaterial.h" 2 | 3 | SolarSystem::SolarMaterial::SolarMaterial(Qt3DCore::QNode* parent): 4 | QMaterial(parent) 5 | { 6 | // main params 7 | m_ambientColorParam = new Qt3DRender::QParameter(this); 8 | m_ambientColorParam->setName("ambient"); 9 | m_ambientColorParam->setValue(QVector3D(m_ambientColor.redF(), m_ambientColor.blueF(), m_ambientColor.greenF())); 10 | 11 | m_specularColorParam = new Qt3DRender::QParameter(this); 12 | m_specularColorParam->setName("specular"); 13 | m_specularColorParam->setValue(QVector3D(m_specularColor.redF(), m_specularColor.blueF(), m_specularColor.greenF())); 14 | 15 | m_shininessParam = new Qt3DRender::QParameter(this); 16 | m_shininessParam->setName("shininess"); 17 | m_shininessParam->setValue(m_shininess); 18 | 19 | m_textureScaleParam = new Qt3DRender::QParameter(this); 20 | m_textureScaleParam->setName("texCoordScale"); 21 | m_textureScaleParam->setValue(m_textureScale); 22 | 23 | m_opacityParam = new Qt3DRender::QParameter(this); 24 | m_opacityParam->setName("opacity"); 25 | m_opacityParam->setValue(m_opacity); 26 | 27 | // create diffuse texture 28 | m_diffuseTexture2D = new Qt3DRender::QTexture2D(); 29 | m_diffuseTexture2D->setMinificationFilter(Qt3DRender::QAbstractTexture::LinearMipMapLinear); 30 | m_diffuseTexture2D->setMagnificationFilter(Qt3DRender::QAbstractTexture::Linear); 31 | m_diffuseTexture2D->wrapMode()->setX(Qt3DRender::QTextureWrapMode::Repeat); 32 | m_diffuseTexture2D->wrapMode()->setY(Qt3DRender::QTextureWrapMode::Repeat); 33 | m_diffuseTexture2D->setGenerateMipMaps(true); 34 | m_diffuseTexture2D->setMaximumAnisotropy(16.0f); 35 | 36 | // create diffuse image 37 | m_diffuseImage = new Qt3DRender::QTextureImage(m_diffuseTexture2D); 38 | m_diffuseImage->setSource(m_diffuseTextureSource); 39 | 40 | // create texture parameter 41 | m_diffuseTexture2D->addTextureImage(m_diffuseImage); 42 | m_diffuseTextureParam = new Qt3DRender::QParameter("diffuseTexture", m_diffuseTexture2D, this); 43 | 44 | m_normalTexture2D = new Qt3DRender::QTexture2D(); 45 | m_normalTexture2D->setMinificationFilter(Qt3DRender::QAbstractTexture::Linear); 46 | m_normalTexture2D->setMagnificationFilter(Qt3DRender::QAbstractTexture::Linear); 47 | m_normalTexture2D->wrapMode()->setX(Qt3DRender::QTextureWrapMode::Repeat); 48 | m_normalTexture2D->wrapMode()->setY(Qt3DRender::QTextureWrapMode::Repeat); 49 | m_normalTexture2D->setMaximumAnisotropy(16.0f); 50 | 51 | // create normal image 52 | m_normalImage = new Qt3DRender::QTextureImage(m_normalTexture2D); 53 | m_normalImage->setSource(m_normalTextureSource); 54 | 55 | // create normal parameter 56 | m_normalTexture2D->addTextureImage(m_normalImage); 57 | m_normalTextureParam = new Qt3DRender::QParameter("normalTexture", m_normalTexture2D, this); 58 | 59 | addParameter(m_ambientColorParam); 60 | addParameter(m_specularColorParam); 61 | addParameter(m_shininessParam); 62 | addParameter(m_textureScaleParam); 63 | addParameter(m_opacityParam); 64 | addParameter(m_diffuseTextureParam); 65 | addParameter(m_normalTextureParam); 66 | } 67 | 68 | QColor SolarSystem::SolarMaterial::ambientColor() const 69 | { 70 | return m_ambientColor; 71 | } 72 | 73 | QColor SolarSystem::SolarMaterial::specularColor() const 74 | { 75 | return m_specularColor; 76 | } 77 | 78 | QString SolarSystem::SolarMaterial::diffuseTextureSource() const 79 | { 80 | return m_diffuseTextureSource; 81 | } 82 | 83 | QString SolarSystem::SolarMaterial::normalTextureSource() const 84 | { 85 | return m_normalTextureSource; 86 | } 87 | 88 | float SolarSystem::SolarMaterial::shininess() const 89 | { 90 | return m_shininess; 91 | } 92 | 93 | float SolarSystem::SolarMaterial::textureScale() const 94 | { 95 | return m_textureScale; 96 | } 97 | 98 | float SolarSystem::SolarMaterial::opacity() const 99 | { 100 | return m_opacity; 101 | } 102 | 103 | void SolarSystem::SolarMaterial::setAmbient(QColor color) 104 | { 105 | m_ambientColor = color; 106 | m_ambientColorParam->setValue(QVector3D(color.redF(), color.blueF(), color.greenF())); 107 | } 108 | 109 | void SolarSystem::SolarMaterial::setSpecular(QColor color) 110 | { 111 | m_specularColor = color; 112 | m_specularColorParam->setValue(QVector3D(color.redF(), color.blueF(), color.greenF())); 113 | } 114 | 115 | void SolarSystem::SolarMaterial::setDiffuseTextureSource(const QString& source) 116 | { 117 | m_diffuseTextureSource = source; 118 | m_diffuseImage->setSource(QUrl::fromLocalFile(source)); 119 | } 120 | 121 | void SolarSystem::SolarMaterial::setNormalTextureSource(const QString &source) 122 | { 123 | m_normalTextureSource = source; 124 | m_normalImage->setSource(QUrl::fromLocalFile(source)); 125 | } 126 | 127 | void SolarSystem::SolarMaterial::setSnininess(float value) 128 | { 129 | m_shininess = value; 130 | m_shininessParam->setValue(value); 131 | } 132 | 133 | void SolarSystem::SolarMaterial::setTextureScale(float scale) 134 | { 135 | m_textureScale = scale; 136 | m_textureScaleParam->setValue(scale); 137 | } 138 | 139 | void SolarSystem::SolarMaterial::setOpacity(float opacity) 140 | { 141 | m_opacity = opacity; 142 | m_opacityParam->setValue(opacity); 143 | } 144 | -------------------------------------------------------------------------------- /Core/Render/solarmaterial.h: -------------------------------------------------------------------------------- 1 | #ifndef SOLARMATERIAL_H 2 | #define SOLARMATERIAL_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace SolarSystem 13 | { 14 | // represents base solar material 15 | class SolarMaterial : public Qt3DRender::QMaterial 16 | { 17 | Q_OBJECT 18 | 19 | public: 20 | explicit SolarMaterial(Qt3DCore::QNode* parent = nullptr); 21 | 22 | QColor ambientColor() const; 23 | QColor specularColor() const; 24 | QString diffuseTextureSource() const; 25 | QString normalTextureSource() const; 26 | float shininess() const; 27 | float textureScale() const; 28 | float opacity() const; 29 | 30 | void setAmbient(QColor color); 31 | void setSpecular(QColor color); 32 | void setDiffuseTextureSource(const QString& source); 33 | void setNormalTextureSource(const QString& source); 34 | void setSnininess(float value); 35 | void setTextureScale(float scale); 36 | void setOpacity(float opacity); 37 | 38 | private: 39 | Qt3DRender::QParameter* m_ambientColorParam; 40 | Qt3DRender::QParameter* m_specularColorParam; 41 | Qt3DRender::QParameter* m_shininessParam; 42 | Qt3DRender::QParameter* m_diffuseTextureParam; 43 | Qt3DRender::QParameter* m_normalTextureParam; 44 | Qt3DRender::QParameter* m_textureScaleParam; 45 | Qt3DRender::QParameter* m_opacityParam; 46 | 47 | QColor m_ambientColor = QColor::fromRgbF(0.1f, 0.1f, 0.1f, 1.0f); 48 | QColor m_specularColor = QColor::fromRgbF(0.5f, 0.5f, 0.5f, 1.0f); 49 | float m_shininess = 150.0f; 50 | QString m_diffuseTextureSource; 51 | QString m_normalTextureSource; 52 | float m_textureScale = 1.0f; 53 | float m_opacity = 1.0f; 54 | 55 | // textures 56 | Qt3DRender::QTexture2D* m_diffuseTexture2D; 57 | Qt3DRender::QTexture2D* m_normalTexture2D; 58 | Qt3DRender::QTextureImage* m_diffuseImage; 59 | Qt3DRender::QTextureImage* m_normalImage; 60 | 61 | }; 62 | } 63 | 64 | #endif // SOLARMATERIAL_H 65 | -------------------------------------------------------------------------------- /Core/Render/solarobjecteffect.cpp: -------------------------------------------------------------------------------- 1 | #include "solarobjecteffect.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | SolarSystem::SolarObjectEffect::SolarObjectEffect(Qt3DCore::QNode* parent): 11 | Qt3DRender::QEffect(parent) 12 | { 13 | m_vertexShaderGL = ":/Resources/Shaders/diffusenormal.vert"; 14 | m_fragShaderGL = ":/Resources/Shaders/diffusenormal.frag"; 15 | } 16 | 17 | SolarSystem::SolarLight* SolarSystem::SolarObjectEffect::light() const 18 | { 19 | return m_lightObject; 20 | } 21 | 22 | void SolarSystem::SolarObjectEffect::setLight(SolarSystem::SolarLight* light) 23 | { 24 | m_lightObject = light; 25 | } 26 | 27 | void SolarSystem::SolarObjectEffect::initialization() 28 | { 29 | if (m_lightObject != nullptr) 30 | { 31 | // create params 32 | auto* lightViewParam = new Qt3DRender::QParameter(this); 33 | lightViewParam->setName("lightViewProjection"); 34 | lightViewParam->setValue(m_lightObject->lightViewProjection()); 35 | 36 | auto* lightPos = new Qt3DRender::QParameter(this); 37 | lightPos->setName("lightPosition"); 38 | lightPos->setValue(m_lightObject->camera()->position()); 39 | 40 | auto* lightInt = new Qt3DRender::QParameter(this); 41 | lightInt->setName("lightIntensity"); 42 | lightInt->setValue(m_lightObject->intensity()); 43 | 44 | // add params 45 | addParameter(lightViewParam); 46 | addParameter(lightPos); 47 | addParameter(lightInt); 48 | 49 | // create filter keys 50 | auto* desktopKey = new Qt3DRender::QFilterKey(this); 51 | desktopKey->setName("name"); 52 | desktopKey->setValue("Desktop"); 53 | 54 | auto* forwardKey = new Qt3DRender::QFilterKey(this); 55 | forwardKey->setName("pass"); 56 | forwardKey->setValue("forward"); 57 | 58 | // create standard gl pass 59 | m_glPass = new Qt3DRender::QRenderPass(this); 60 | m_glPass->setObjectName("glPass"); 61 | m_glPass->addFilterKey(forwardKey); 62 | 63 | // standard gl pass shader program 64 | Qt3DRender::QShaderProgram* glPassProgram = new Qt3DRender::QShaderProgram(m_glPass); 65 | glPassProgram->setVertexShaderCode(Qt3DRender::QShaderProgram::loadSource(QUrl::fromLocalFile(m_vertexShaderGL))); 66 | glPassProgram->setFragmentShaderCode(Qt3DRender::QShaderProgram::loadSource(QUrl::fromLocalFile(m_fragShaderGL))); 67 | 68 | // add gl pass program 69 | m_glPass->setShaderProgram(glPassProgram); 70 | 71 | //************************** 72 | // tecnique 73 | //************************** 74 | 75 | // create tecniques 76 | Qt3DRender::QTechnique* openglTechnique = new Qt3DRender::QTechnique(this); 77 | 78 | // setup api 79 | auto* api = openglTechnique->graphicsApiFilter(); 80 | api->setApi(Qt3DRender::QGraphicsApiFilter::OpenGL); 81 | api->setProfile(Qt3DRender::QGraphicsApiFilter::CoreProfile); 82 | api->setMajorVersion(3); 83 | api->setMinorVersion(2); 84 | 85 | openglTechnique->addFilterKey(desktopKey); 86 | openglTechnique->addRenderPass(m_glPass); 87 | 88 | addTechnique(openglTechnique); 89 | } 90 | } 91 | 92 | QString SolarSystem::SolarObjectEffect::vertexShaderSource() const 93 | { 94 | return m_vertexShaderGL; 95 | } 96 | 97 | QString SolarSystem::SolarObjectEffect::fragmentShaderSource() const 98 | { 99 | return m_fragShaderGL; 100 | } 101 | 102 | void SolarSystem::SolarObjectEffect::setVertexShaderSource(const QString& source) 103 | { 104 | m_vertexShaderGL = source; 105 | } 106 | 107 | void SolarSystem::SolarObjectEffect::setFragmentShaderSource(const QString& source) 108 | { 109 | m_fragShaderGL = source; 110 | } 111 | -------------------------------------------------------------------------------- /Core/Render/solarobjecteffect.h: -------------------------------------------------------------------------------- 1 | #ifndef SOLAROBJECTEFFECT_H 2 | #define SOLAROBJECTEFFECT_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace SolarSystem 10 | { 11 | // represents any solid solar system body effect 12 | class SolarObjectEffect : public Qt3DRender::QEffect 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | explicit SolarObjectEffect(Qt3DCore::QNode* parent = nullptr); 18 | 19 | SolarLight* light() const; 20 | void setLight(SolarLight* light); 21 | 22 | QString vertexShaderSource() const; 23 | QString fragmentShaderSource() const; 24 | 25 | void setVertexShaderSource(const QString& source); 26 | void setFragmentShaderSource(const QString& source); 27 | 28 | // init effect 29 | void initialization(); 30 | 31 | private: 32 | 33 | // standard gl pass 34 | Qt3DRender::QRenderPass* m_glPass; 35 | 36 | // light 37 | SolarLight* m_lightObject = nullptr; 38 | 39 | // shaders source 40 | QString m_vertexShaderGL; 41 | QString m_fragShaderGL; 42 | }; 43 | } 44 | 45 | #endif // SOLAROBJECTEFFECT_H 46 | -------------------------------------------------------------------------------- /Core/Render/solarshadoweffect.cpp: -------------------------------------------------------------------------------- 1 | #include "solarshadoweffect.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | SolarSystem::SolarShadowEffect::SolarShadowEffect(Qt3DCore::QNode* parent): 12 | Qt3DRender::QEffect(parent) 13 | { 14 | } 15 | 16 | SolarSystem::SolarLight* SolarSystem::SolarShadowEffect::light() const 17 | { 18 | return m_lightObject; 19 | } 20 | 21 | void SolarSystem::SolarShadowEffect::setLight(SolarSystem::SolarLight* light) 22 | { 23 | m_lightObject = light; 24 | } 25 | 26 | Qt3DRender::QTexture2D* SolarSystem::SolarShadowEffect::shadowTexture() const 27 | { 28 | return m_shadowTexture; 29 | } 30 | 31 | void SolarSystem::SolarShadowEffect::setShadowTexture(Qt3DRender::QTexture2D* texture) 32 | { 33 | m_shadowTexture = texture; 34 | } 35 | 36 | void SolarSystem::SolarShadowEffect::initialization() 37 | { 38 | if (m_lightObject != nullptr && m_shadowTexture != nullptr) 39 | { 40 | // create params 41 | auto* lightViewParam = new Qt3DRender::QParameter(this); 42 | lightViewParam->setName("lightViewProjection"); 43 | lightViewParam->setValue(m_lightObject->lightViewProjection()); 44 | 45 | auto* lightPos = new Qt3DRender::QParameter(this); 46 | lightPos->setName("lightPosition"); 47 | lightPos->setValue(m_lightObject->camera()->position()); 48 | 49 | auto* lightInt = new Qt3DRender::QParameter(this); 50 | lightInt->setName("lightIntensity"); 51 | lightInt->setValue(m_lightObject->intensity()); 52 | 53 | auto* shadowMap = new Qt3DRender::QParameter("shadowMapTexture", m_shadowTexture, this); 54 | 55 | // add params 56 | addParameter(lightViewParam); 57 | addParameter(lightPos); 58 | addParameter(lightInt); 59 | addParameter(shadowMap); 60 | 61 | // create filter keys 62 | auto* desktopKey = new Qt3DRender::QFilterKey(this); 63 | desktopKey->setName("name"); 64 | desktopKey->setValue("Desktop"); 65 | 66 | auto* shadowKey = new Qt3DRender::QFilterKey(this); 67 | shadowKey->setName("pass"); 68 | shadowKey->setValue("shadowmap"); 69 | 70 | auto* forwardKey = new Qt3DRender::QFilterKey(this); 71 | forwardKey->setName("pass"); 72 | forwardKey->setValue("forward"); 73 | 74 | // first render pass 75 | 76 | // create shadow render pass 77 | m_shadowPass = new Qt3DRender::QRenderPass(this); 78 | m_shadowPass->setObjectName("shadowPass"); 79 | m_shadowPass->addFilterKey(shadowKey); 80 | 81 | // shadow map shader program 82 | Qt3DRender::QShaderProgram* shadowProgram = new Qt3DRender::QShaderProgram(m_shadowPass); 83 | shadowProgram->setVertexShaderCode(Qt3DRender::QShaderProgram::loadSource(QUrl::fromLocalFile(":/Resources/Shaders/shadowmap.vert"))); 84 | shadowProgram->setFragmentShaderCode(Qt3DRender::QShaderProgram::loadSource(QUrl::fromLocalFile(":/Resources/Shaders/shadowmap.frag"))); 85 | 86 | // add shadow program 87 | m_shadowPass->setShaderProgram(shadowProgram); 88 | 89 | // create render states 90 | auto* shadowPolygonOffset = new Qt3DRender::QPolygonOffset(m_shadowPass); 91 | shadowPolygonOffset->setScaleFactor(4.0f); 92 | shadowPolygonOffset->setDepthSteps(4.0f); 93 | 94 | auto* shadowDepthTest = new Qt3DRender::QDepthTest(m_shadowPass); 95 | shadowDepthTest->setDepthFunction(Qt3DRender::QDepthTest::Less); 96 | 97 | // add shadow render states to shadow render pass 98 | m_shadowPass->addRenderState(shadowPolygonOffset); 99 | m_shadowPass->addRenderState(shadowDepthTest); 100 | 101 | // second render pass 102 | 103 | // create standard gl pass 104 | m_glPass = new Qt3DRender::QRenderPass(this); 105 | m_glPass->setObjectName("glPass"); 106 | m_glPass->addFilterKey(forwardKey); 107 | 108 | // standard gl pass shader program 109 | Qt3DRender::QShaderProgram* glPassProgram = new Qt3DRender::QShaderProgram(m_glPass); 110 | glPassProgram->setVertexShaderCode(Qt3DRender::QShaderProgram::loadSource(QUrl::fromLocalFile(":/Resources/Shaders/diffuseshadow.vert"))); 111 | glPassProgram->setFragmentShaderCode(Qt3DRender::QShaderProgram::loadSource(QUrl::fromLocalFile(":/Resources/Shaders/diffuseshadow.frag"))); 112 | 113 | // add gl pass program 114 | m_glPass->setShaderProgram(glPassProgram); 115 | 116 | //************************** 117 | // tecnique 118 | //************************** 119 | 120 | // create tecniques 121 | Qt3DRender::QTechnique* openglTechnique = new Qt3DRender::QTechnique(this); 122 | 123 | auto* api = openglTechnique->graphicsApiFilter(); 124 | api->setApi(Qt3DRender::QGraphicsApiFilter::OpenGL); 125 | api->setProfile(Qt3DRender::QGraphicsApiFilter::CoreProfile); 126 | api->setMajorVersion(3); 127 | api->setMinorVersion(2); 128 | 129 | openglTechnique->addFilterKey(desktopKey); 130 | openglTechnique->addRenderPass(m_shadowPass); 131 | openglTechnique->addRenderPass(m_glPass); 132 | 133 | addTechnique(openglTechnique); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /Core/Render/solarshadoweffect.h: -------------------------------------------------------------------------------- 1 | #ifndef SOLARSHADOWEFFECT_H 2 | #define SOLARSHADOWEFFECT_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace SolarSystem 10 | { 11 | // repsents shadow map effect 12 | class SolarShadowEffect : public Qt3DRender::QEffect 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | explicit SolarShadowEffect(Qt3DCore::QNode* parent = nullptr); 18 | 19 | SolarLight* light() const; 20 | void setLight(SolarLight* light); 21 | 22 | Qt3DRender::QTexture2D* shadowTexture() const; 23 | void setShadowTexture(Qt3DRender::QTexture2D* texture); 24 | 25 | // init effect 26 | void initialization(); 27 | 28 | private: 29 | 30 | // 1t shadow pass 31 | Qt3DRender::QRenderPass* m_shadowPass; 32 | 33 | // 2d standard gl pass 34 | Qt3DRender::QRenderPass* m_glPass; 35 | 36 | // light 37 | SolarLight* m_lightObject = nullptr; 38 | 39 | // texture 40 | Qt3DRender::QTexture2D* m_shadowTexture = nullptr; 41 | }; 42 | } 43 | 44 | #endif // SOLARSHADOWEFFECT_H 45 | -------------------------------------------------------------------------------- /Core/Render/solarstandardframegraph.cpp: -------------------------------------------------------------------------------- 1 | #include "solarstandardframegraph.h" 2 | #include 3 | 4 | SolarSystem::SolarStandardFrameGraph::SolarStandardFrameGraph(Qt3DCore::QNode* parent): 5 | IFrameGraph(parent), 6 | m_renderer(new Qt3DExtras::QForwardRenderer(parent)) 7 | { 8 | setRenderPolicy(QRenderSettings::RenderPolicy::Always); 9 | setActiveFrameGraph(m_renderer); 10 | 11 | m_renderer->setFrustumCullingEnabled(false); 12 | m_renderer->setClearColor(QColor(Qt::black)); 13 | } 14 | 15 | void SolarSystem::SolarStandardFrameGraph::setCamera(Qt3DCore::QEntity* camera) 16 | { 17 | m_renderer->setCamera(camera); 18 | } 19 | -------------------------------------------------------------------------------- /Core/Render/solarstandardframegraph.h: -------------------------------------------------------------------------------- 1 | #ifndef SOLARSTANDARDFRAMEGRAPH_H 2 | #define SOLARSTANDARDFRAMEGRAPH_H 3 | 4 | #include 5 | 6 | namespace Qt3DExtras 7 | { 8 | class QForwardRenderer; 9 | } 10 | 11 | namespace SolarSystem 12 | { 13 | // represents standard forward frame graph 14 | class SolarStandardFrameGraph : public IFrameGraph 15 | { 16 | Q_OBJECT 17 | 18 | public: 19 | explicit SolarStandardFrameGraph(Qt3DCore::QNode* parent = nullptr); 20 | 21 | // sets camera to forward renderer 22 | virtual void setCamera(Qt3DCore::QEntity* camera) override; 23 | 24 | private: 25 | Qt3DExtras::QForwardRenderer* m_renderer; 26 | }; 27 | } 28 | 29 | #endif // SOLARSTANDARDFRAMEGRAPH_H 30 | -------------------------------------------------------------------------------- /Core/SolarObjects/abstractsolarobject.cpp: -------------------------------------------------------------------------------- 1 | #include "abstractsolarobject.h" 2 | 3 | SolarSystem::AbstractSolarObject::AbstractSolarObject(QObject* parent): 4 | QObject(parent) 5 | { 6 | } 7 | 8 | SolarSystem::AbstractSolarObject::~AbstractSolarObject() 9 | { 10 | } 11 | 12 | double SolarSystem::AbstractSolarObject::radius() const 13 | { 14 | return m_radius; 15 | } 16 | 17 | void SolarSystem::AbstractSolarObject::setRadius(double radius) 18 | { 19 | m_radius = radius; 20 | } 21 | 22 | double SolarSystem::AbstractSolarObject::tilt() const 23 | { 24 | return m_tilt; 25 | } 26 | 27 | void SolarSystem::AbstractSolarObject::setTilt(double tilt) 28 | { 29 | m_tilt = tilt; 30 | } 31 | 32 | double SolarSystem::AbstractSolarObject::roll() const 33 | { 34 | return m_roll; 35 | } 36 | 37 | void SolarSystem::AbstractSolarObject::setRoll(double roll) 38 | { 39 | m_roll = roll; 40 | } 41 | 42 | double SolarSystem::AbstractSolarObject::x() const 43 | { 44 | return m_x; 45 | } 46 | 47 | void SolarSystem::AbstractSolarObject::setX(double x) 48 | { 49 | m_x = x; 50 | } 51 | 52 | double SolarSystem::AbstractSolarObject::y() const 53 | { 54 | return m_y; 55 | } 56 | 57 | void SolarSystem::AbstractSolarObject::setY(double y) 58 | { 59 | m_y = y; 60 | } 61 | 62 | double SolarSystem::AbstractSolarObject::z() const 63 | { 64 | return m_z; 65 | } 66 | 67 | void SolarSystem::AbstractSolarObject::setZ(double z) 68 | { 69 | m_z = z; 70 | } 71 | 72 | double SolarSystem::AbstractSolarObject::N1() const 73 | { 74 | return m_n1; 75 | } 76 | 77 | double SolarSystem::AbstractSolarObject::N2() const 78 | { 79 | return m_n2; 80 | } 81 | 82 | double SolarSystem::AbstractSolarObject::i1() const 83 | { 84 | return m_i1; 85 | } 86 | 87 | double SolarSystem::AbstractSolarObject::i2() const 88 | { 89 | return m_i2; 90 | } 91 | 92 | double SolarSystem::AbstractSolarObject::w1() const 93 | { 94 | return m_w1; 95 | } 96 | 97 | double SolarSystem::AbstractSolarObject::w2() const 98 | { 99 | return m_w2; 100 | } 101 | 102 | double SolarSystem::AbstractSolarObject::a1() const 103 | { 104 | return m_a1; 105 | } 106 | 107 | double SolarSystem::AbstractSolarObject::a2() const 108 | { 109 | return m_a2; 110 | } 111 | 112 | double SolarSystem::AbstractSolarObject::e1() const 113 | { 114 | return m_e1; 115 | } 116 | 117 | double SolarSystem::AbstractSolarObject::e2() const 118 | { 119 | return m_e2; 120 | } 121 | 122 | double SolarSystem::AbstractSolarObject::M1() const 123 | { 124 | return m_m1; 125 | } 126 | 127 | double SolarSystem::AbstractSolarObject::M2() const 128 | { 129 | return m_m2; 130 | } 131 | 132 | double SolarSystem::AbstractSolarObject::period() const 133 | { 134 | return m_period; 135 | } 136 | 137 | SolarSystem::SolarObjects SolarSystem::AbstractSolarObject::centerOfOrbit() const 138 | { 139 | return m_centerOfOrbit; 140 | } 141 | 142 | SolarSystem::SolarObjects SolarSystem::AbstractSolarObject::object() const 143 | { 144 | return m_objectType; 145 | } 146 | -------------------------------------------------------------------------------- /Core/SolarObjects/abstractsolarobject.h: -------------------------------------------------------------------------------- 1 | #ifndef ABSTRACTSOLAROBJECT_H 2 | #define ABSTRACTSOLAROBJECT_H 3 | 4 | #include 5 | #include "solarsystemcore.h" 6 | #include 7 | #include 8 | 9 | namespace SolarSystem 10 | { 11 | // simple presentation of math solar object 12 | class AbstractSolarObject : public QObject 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | explicit AbstractSolarObject(QObject* parent = nullptr); 18 | virtual ~AbstractSolarObject(); 19 | 20 | double radius() const; 21 | void setRadius(double radius); 22 | 23 | double tilt() const; 24 | void setTilt(double tilt); 25 | 26 | double roll() const; 27 | void setRoll(double roll); 28 | 29 | double x() const; 30 | void setX(double x); 31 | 32 | double y() const; 33 | void setY(double y); 34 | 35 | double z() const; 36 | void setZ(double z); 37 | 38 | //only getters 39 | double N1() const; 40 | double N2() const; 41 | double i1() const; 42 | double i2() const; 43 | double w1() const; 44 | double w2() const; 45 | double a1() const; 46 | double a2() const; 47 | double e1() const; 48 | double e2() const; 49 | double M1() const; 50 | double M2() const; 51 | double period() const; 52 | SolarObjects centerOfOrbit() const; 53 | SolarObjects object() const; 54 | 55 | protected: 56 | double m_radius = 0; 57 | double m_tilt = 0; 58 | double m_n1 = 0; 59 | double m_n2 = 0; 60 | double m_i1 = 0; 61 | double m_i2 = 0; 62 | double m_w1 = 0; 63 | double m_w2 = 0; 64 | double m_a1 = 0; 65 | double m_a2 = 0; 66 | double m_e1 = 0; 67 | double m_e2 = 0; 68 | double m_m1 = 0; 69 | double m_m2 = 0; 70 | double m_period = 0; 71 | double m_x = 0; 72 | double m_y = 0; 73 | double m_z = 0; 74 | double m_roll = 0; 75 | SolarObjects m_centerOfOrbit; 76 | SolarObjects m_objectType; 77 | 78 | // derived class should override and call this at constructor 79 | virtual void initialize() = 0; 80 | }; 81 | 82 | // solar objects type 83 | using SolarObjectPtr = std::shared_ptr; 84 | using SolarObjectsArray = std::vector; 85 | using SolarObjectsMap = std::unordered_map; 86 | } 87 | 88 | #endif // ABSTRACTSOLAROBJECT_H 89 | -------------------------------------------------------------------------------- /Core/SolarObjects/solarobjects.h: -------------------------------------------------------------------------------- 1 | #ifndef SOLAROBJECTS_H 2 | #define SOLAROBJECTS_H 3 | 4 | #include "Core/SolarObjects/abstractsolarobject.h" 5 | 6 | namespace SolarSystem 7 | { 8 | namespace Stars 9 | { 10 | // Sun the center of solar sytem 11 | class Sun final : public AbstractSolarObject 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit Sun(QObject* parent = nullptr); 17 | 18 | protected: 19 | virtual void initialize() override; 20 | }; 21 | } 22 | 23 | namespace Planets 24 | { 25 | class Mercury final : public AbstractSolarObject 26 | { 27 | Q_OBJECT 28 | 29 | public: 30 | explicit Mercury(QObject* parent = nullptr); 31 | 32 | protected: 33 | virtual void initialize() override; 34 | }; 35 | 36 | class Venus final : public AbstractSolarObject 37 | { 38 | Q_OBJECT 39 | 40 | public: 41 | explicit Venus(QObject* parent = nullptr); 42 | 43 | protected: 44 | virtual void initialize() override; 45 | }; 46 | 47 | class Earth final : public AbstractSolarObject 48 | { 49 | Q_OBJECT 50 | 51 | public: 52 | explicit Earth(QObject* parent = nullptr); 53 | 54 | protected: 55 | virtual void initialize() override; 56 | }; 57 | 58 | class Mars final : public AbstractSolarObject 59 | { 60 | Q_OBJECT 61 | 62 | public: 63 | explicit Mars(QObject* parent = nullptr); 64 | 65 | protected: 66 | virtual void initialize() override; 67 | }; 68 | 69 | class Jupiter final : public AbstractSolarObject 70 | { 71 | Q_OBJECT 72 | 73 | public: 74 | explicit Jupiter(QObject* parent = nullptr); 75 | 76 | protected: 77 | virtual void initialize() override; 78 | }; 79 | 80 | class Saturn final : public AbstractSolarObject 81 | { 82 | Q_OBJECT 83 | 84 | public: 85 | explicit Saturn(QObject* parent = nullptr); 86 | 87 | protected: 88 | virtual void initialize() override; 89 | }; 90 | 91 | class Uranus final : public AbstractSolarObject 92 | { 93 | Q_OBJECT 94 | 95 | public: 96 | explicit Uranus(QObject* parent = nullptr); 97 | 98 | protected: 99 | virtual void initialize() override; 100 | }; 101 | 102 | class Neptune final : public AbstractSolarObject 103 | { 104 | Q_OBJECT 105 | 106 | public: 107 | explicit Neptune(QObject* parent = nullptr); 108 | 109 | protected: 110 | virtual void initialize() override; 111 | }; 112 | 113 | class Pluto final : public AbstractSolarObject 114 | { 115 | Q_OBJECT 116 | 117 | public: 118 | explicit Pluto(QObject* parent = nullptr); 119 | 120 | protected: 121 | virtual void initialize() override; 122 | }; 123 | 124 | } 125 | 126 | namespace Moons 127 | { 128 | class Moon final : public AbstractSolarObject 129 | { 130 | Q_OBJECT 131 | 132 | public: 133 | explicit Moon(QObject* parent = nullptr); 134 | 135 | protected: 136 | virtual void initialize() override; 137 | 138 | }; 139 | } 140 | } 141 | 142 | 143 | #endif // SOLAROBJECTS_H 144 | -------------------------------------------------------------------------------- /Core/animator.cpp: -------------------------------------------------------------------------------- 1 | #include "animator.h" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | SolarSystem::Animator::Animator(QObject* parent): 12 | QObject(parent) 13 | { 14 | } 15 | 16 | SolarSystem::SolarObjects SolarSystem::Animator::currentObject() const 17 | { 18 | return m_currentSolarObject; 19 | } 20 | 21 | bool SolarSystem::Animator::isAnimated() const 22 | { 23 | return m_animated; 24 | } 25 | 26 | void SolarSystem::Animator::enableAnimation() 27 | { 28 | MathCore::instance()->cameraController()->setEnabled(false); 29 | m_animated = true; 30 | } 31 | 32 | void SolarSystem::Animator::disableAnimation() 33 | { 34 | MathCore::instance()->cameraController()->setEnabled(true); 35 | m_animated = false; 36 | } 37 | 38 | void SolarSystem::Animator::animate(float deltaTime) 39 | { 40 | if (m_animated) 41 | { 42 | checkAnimation(); 43 | animation(deltaTime); 44 | } 45 | 46 | MathCore::instance()->calculate(deltaTime, m_currentSolarObject); 47 | } 48 | 49 | void SolarSystem::Animator::animateCamera(SolarObjects object) 50 | { 51 | if (object != m_currentSolarObject) 52 | { 53 | m_currentSolarObject = object; 54 | 55 | // object for animation changed 56 | emit currentObjectChanged(m_currentSolarObject); 57 | 58 | MathCore::instance()->updateSolarViewZoomLimit(m_currentSolarObject); 59 | 60 | enableAnimation(); 61 | } 62 | } 63 | 64 | void SolarSystem::Animator::animation(float deltaTime) 65 | { 66 | static constexpr float positionSpeed = 1.25f; 67 | static constexpr float viewSpeed = 1.35f; 68 | 69 | static constexpr float defaultCameraRoll = 0.0f; 70 | static constexpr float cameraAngleThreshold = 30.0f; 71 | 72 | auto camera = MathCore::instance()->camera(); 73 | auto object = m_currentSolarObject != SolarObjects::SolarSystemView ? m_currentSolarObject : SolarObjects::Sun; 74 | 75 | // animate view 76 | auto center = MathCore::instance()->objectPosition(m_currentSolarObject); 77 | camera->setViewCenter(Utils::lerp(camera->viewCenter(), center, deltaTime * viewSpeed)); 78 | 79 | // correct roll 80 | const auto roll = camera->transform()->rotationZ(); 81 | camera->rollAboutViewCenter(defaultCameraRoll - roll); 82 | 83 | if (m_currentSolarObject != SolarObjects::SolarSystemView) 84 | { 85 | if (!MathCore::instance()->checkAngleThreshold(object, cameraAngleThreshold)) 86 | return; 87 | } 88 | 89 | // animate position 90 | auto position = MathCore::instance()->viewPositionOfObject(m_currentSolarObject); 91 | camera->setPosition(Utils::lerp(camera->position(), position, deltaTime * positionSpeed)); 92 | } 93 | 94 | void SolarSystem::Animator::checkAnimation() 95 | { 96 | static constexpr float cameraAngleThreshold = 3.5f; 97 | 98 | const bool result = m_currentSolarObject == SolarObjects::SolarSystemView || m_currentSolarObject == SolarObjects::Sun; 99 | const float coeff = !result ? 1.05f : 1.15f; 100 | 101 | auto camera = MathCore::instance()->camera(); 102 | auto position = (m_currentSolarObject != SolarObjects::SolarSystemView) ? 103 | MathCore::instance()->objectPosition(m_currentSolarObject) : CameraSettings::defaultCameraPosition; 104 | 105 | auto needDistance = (MathCore::instance()->viewPositionOfObject(m_currentSolarObject) - position).length(); 106 | auto currentDistance = (camera->position() - position).length(); 107 | 108 | auto object = m_currentSolarObject != SolarObjects::SolarSystemView ? m_currentSolarObject : SolarObjects::Sun; 109 | auto angleResult = MathCore::instance()->checkAngleThreshold(object, cameraAngleThreshold); 110 | 111 | if (m_currentSolarObject == SolarObjects::SolarSystemView) 112 | needDistance += coeff + 2.0f; 113 | 114 | if (currentDistance/coeff <= needDistance && angleResult) 115 | disableAnimation(); 116 | } 117 | -------------------------------------------------------------------------------- /Core/animator.h: -------------------------------------------------------------------------------- 1 | #ifndef ANIMATOR_H 2 | #define ANIMATOR_H 3 | 4 | #include 5 | 6 | #include 7 | 8 | namespace SolarSystem 9 | { 10 | // animates and controlls mathcore 11 | class Animator : public QObject 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit Animator(QObject* parent = nullptr); 17 | ~Animator() = default; 18 | 19 | // returns current animated solar object 20 | SolarObjects currentObject() const; 21 | bool isAnimated() const; 22 | 23 | protected: 24 | void enableAnimation(); 25 | void disableAnimation(); 26 | 27 | public slots: 28 | 29 | // main call for solar system animation 30 | void animate(float deltaTime); 31 | 32 | // sets camera view center to solar object and animates it 33 | void animateCamera(SolarObjects object); 34 | 35 | signals: 36 | void currentObjectChanged(SolarObjects); 37 | 38 | private: 39 | void animation(float deltaTime); 40 | void checkAnimation(); 41 | 42 | // selected solar object 43 | SolarObjects m_currentSolarObject = SolarObjects::SolarSystemView; 44 | bool m_animated = false; 45 | }; 46 | } 47 | 48 | #endif // ANIMATOR_H 49 | -------------------------------------------------------------------------------- /Core/cameracontroller.cpp: -------------------------------------------------------------------------------- 1 | #include "cameracontroller.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | #include 15 | 16 | SolarSystem::CameraController::CameraController(Qt3DCore::QNode* parent): 17 | Qt3DCore::QEntity(parent), 18 | m_logicalDevice(new Qt3DInput::QLogicalDevice(this)), 19 | m_mouseDevice(new Qt3DInput::QMouseDevice(this)), 20 | m_mouseButtonAction(new Qt3DInput::QAction(this)), 21 | m_mouseButtonInput(new Qt3DInput::QActionInput(this)), 22 | m_mouseXAxis(new Qt3DInput::QAxis(this)), 23 | m_mouseYAxis(new Qt3DInput::QAxis(this)), 24 | m_mouseXInput(new Qt3DInput::QAnalogAxisInput(this)), 25 | m_mouseYInput(new Qt3DInput::QAnalogAxisInput(this)), 26 | m_mouseWheelXInput(new Qt3DInput::QAnalogAxisInput(this)), 27 | mouseWheelYInput(new Qt3DInput::QAnalogAxisInput(this)), 28 | m_mouseWheelXAxis(new Qt3DInput::QAxis(this)), 29 | m_mouseWheelYAxis(new Qt3DInput::QAxis(this)) 30 | { 31 | #ifdef Q_OS_ANDROID 32 | m_mouseButtonInput->setButtons(QVector({Qt::LeftButton})); 33 | #else 34 | m_mouseButtonInput->setButtons(QVector({Qt::RightButton})); 35 | #endif 36 | 37 | m_mouseButtonInput->setSourceDevice(m_mouseDevice); 38 | m_mouseButtonAction->addInput(m_mouseButtonInput); 39 | 40 | // axes 41 | 42 | // mouse X 43 | m_mouseXInput->setAxis(Qt3DInput::QMouseDevice::X); 44 | m_mouseXInput->setSourceDevice(m_mouseDevice); 45 | m_mouseXAxis->addInput(m_mouseXInput); 46 | 47 | // mouse Y 48 | m_mouseYInput->setAxis(Qt3DInput::QMouseDevice::Y); 49 | m_mouseYInput->setSourceDevice(m_mouseDevice); 50 | m_mouseYAxis->addInput(m_mouseYInput); 51 | 52 | // mouse wheel X 53 | m_mouseWheelXInput->setAxis(Qt3DInput::QMouseDevice::WheelX); 54 | m_mouseWheelXInput->setSourceDevice(m_mouseDevice); 55 | m_mouseWheelXAxis->addInput(m_mouseWheelXInput); 56 | 57 | // mouse wheel Y 58 | mouseWheelYInput->setAxis(Qt3DInput::QMouseDevice::WheelY); 59 | mouseWheelYInput->setSourceDevice(m_mouseDevice); 60 | m_mouseWheelYAxis->addInput(mouseWheelYInput); 61 | 62 | // logical device init 63 | m_logicalDevice->addAction(m_mouseButtonAction); 64 | m_logicalDevice->addAxis(m_mouseXAxis); 65 | m_logicalDevice->addAxis(m_mouseYAxis); 66 | m_logicalDevice->addAxis(m_mouseWheelXAxis); 67 | m_logicalDevice->addAxis(m_mouseWheelYAxis); 68 | 69 | // tick component 70 | m_frameAction = new Qt3DLogic::QFrameAction(this); 71 | 72 | QObject::connect(m_frameAction, &Qt3DLogic::QFrameAction::triggered, this, &CameraController::onFrameAction); 73 | QObject::connect(this, &CameraController::enabledChanged, this, &CameraController::onEnabled); 74 | 75 | addComponent(m_logicalDevice); 76 | addComponent(m_frameAction); 77 | } 78 | 79 | void SolarSystem::CameraController::setCamera(Qt3DRender::QCamera* camera) 80 | { 81 | m_viewCamera = camera; 82 | } 83 | 84 | Qt3DRender::QCamera* SolarSystem::CameraController::camera() const 85 | { 86 | return m_viewCamera; 87 | } 88 | 89 | void SolarSystem::CameraController::setLookSpeed(float lookSpeed) 90 | { 91 | m_lookSpeedValue = lookSpeed; 92 | } 93 | 94 | float SolarSystem::CameraController::lookSpeed() const 95 | { 96 | return m_lookSpeedValue; 97 | } 98 | 99 | void SolarSystem::CameraController::setZoomLimit(float limit) 100 | { 101 | m_zoomLimitValue = limit; 102 | } 103 | 104 | float SolarSystem::CameraController::zoomLimit() const 105 | { 106 | return m_zoomLimitValue; 107 | } 108 | 109 | void SolarSystem::CameraController::setZoomSpeed(float zoomSpeed) 110 | { 111 | m_zoomSpeedValue = zoomSpeed; 112 | } 113 | 114 | float SolarSystem::CameraController::zoomSpeed() const 115 | { 116 | return m_zoomSpeedValue; 117 | } 118 | 119 | void SolarSystem::CameraController::setDefaultZoomLimit() 120 | { 121 | m_zoomLimitValue = m_defaultZoomLimitValue; 122 | } 123 | 124 | float SolarSystem::CameraController::defaultZoomLimit() const 125 | { 126 | return m_defaultZoomLimitValue; 127 | } 128 | 129 | void SolarSystem::CameraController::setDefaultZoomSpeed() 130 | { 131 | m_zoomSpeedValue = m_defaultZoomSpeedValue; 132 | } 133 | 134 | float SolarSystem::CameraController::defaultZoomSpeed() const 135 | { 136 | return m_defaultZoomSpeedValue; 137 | } 138 | 139 | void SolarSystem::CameraController::setLookAtObject(SolarSystem::Object3D* object) 140 | { 141 | m_lookAtObject = object; 142 | } 143 | 144 | SolarSystem::Object3D* SolarSystem::CameraController::lookAtObject() const 145 | { 146 | return m_lookAtObject; 147 | } 148 | 149 | void SolarSystem::CameraController::touchZoom(float value) 150 | { 151 | if (isEnabled()) 152 | return; 153 | 154 | // inverse value of touch 155 | ZoomData data { m_deltaTime, Zoom::ByTouch, value }; 156 | value > 0 ? zoomIn(data) : zoomOut(data); 157 | } 158 | 159 | void SolarSystem::CameraController::updateCameraViewCenter(float deltaTime) 160 | { 161 | auto viewCenter = m_lookAtObject != nullptr ? m_lookAtObject->position() : QVector3D(0, 0, 0); 162 | m_viewCamera->setViewCenter(Utils::lerp(m_viewCamera->viewCenter(), viewCenter, deltaTime)); 163 | } 164 | 165 | void SolarSystem::CameraController::zoom(const ZoomData& data) 166 | { 167 | auto translationValue = data.type != Zoom::ByTouch ? m_mouseWheelYAxis->value() : data.value; 168 | m_viewCamera->translate(QVector3D(0, 0, translationValue * data.deltaTime * m_zoomSpeedValue), 169 | Qt3DRender::QCamera::CameraTranslationOption::DontTranslateViewCenter); 170 | } 171 | 172 | void SolarSystem::CameraController::zoomIn(const ZoomData& data) 173 | { 174 | if ((m_viewCamera->viewCenter() - m_viewCamera->position()).lengthSquared() > (m_zoomLimitValue * m_zoomLimitValue)) 175 | zoom(data); 176 | } 177 | 178 | void SolarSystem::CameraController::zoomOut(const ZoomData& data) 179 | { 180 | if ((m_viewCamera->viewCenter() - m_viewCamera->position()).lengthSquared() < (m_zoomOutLimitValue * m_zoomOutLimitValue * 1000.0f)) 181 | zoom(data); 182 | } 183 | 184 | void SolarSystem::CameraController::onEnabled(bool enabled) 185 | { 186 | m_logicalDevice->setEnabled(enabled); 187 | } 188 | 189 | void SolarSystem::CameraController::onFrameAction(float deltaTime) 190 | { 191 | if (!isEnabled()) 192 | { 193 | m_deltaTime = deltaTime; 194 | return; 195 | } 196 | 197 | updateCameraViewCenter(deltaTime); 198 | 199 | // right mouse button is pressed/ or touch on mobile 200 | if (m_mouseButtonAction->isActive()) 201 | { 202 | m_viewCamera->panAboutViewCenter(m_mouseXAxis->value() * m_lookSpeedValue * deltaTime, m_cameraUp); 203 | m_viewCamera->tiltAboutViewCenter(m_mouseYAxis->value() * m_lookSpeedValue * deltaTime); 204 | } 205 | 206 | // zoom check in 207 | if (m_mouseWheelYAxis->value() > 0) 208 | { 209 | zoomIn(ZoomData { deltaTime, Zoom::ByWheel }); 210 | } 211 | 212 | // zoom check out 213 | if (m_mouseWheelYAxis->value() < 0) 214 | { 215 | zoomOut(ZoomData { deltaTime, Zoom::ByWheel }); 216 | } 217 | } 218 | -------------------------------------------------------------------------------- /Core/cameracontroller.h: -------------------------------------------------------------------------------- 1 | #ifndef CAMERACONTROLLER_H 2 | #define CAMERACONTROLLER_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace Qt3DRender 10 | { 11 | class QCamera; 12 | } 13 | 14 | namespace Qt3DInput 15 | { 16 | class QLogicalDevice; 17 | class QMouseDevice; 18 | class QAction; 19 | class QActionInput; 20 | class QAxis; 21 | class QAnalogAxisInput; 22 | } 23 | 24 | namespace Qt3DLogic 25 | { 26 | class QFrameAction; 27 | } 28 | 29 | namespace SolarSystem 30 | { 31 | class Object3D; 32 | 33 | // view controll 34 | class CameraController : public Qt3DCore::QEntity 35 | { 36 | Q_OBJECT 37 | 38 | enum class Zoom 39 | { 40 | ByWheel, 41 | ByTouch 42 | }; 43 | 44 | struct ZoomData 45 | { 46 | float deltaTime; 47 | Zoom type; 48 | float value = 0; 49 | }; 50 | 51 | public: 52 | explicit CameraController(Qt3DCore::QNode* parent = nullptr); 53 | 54 | void setCamera(Qt3DRender::QCamera* camera); 55 | Qt3DRender::QCamera* camera() const; 56 | 57 | void setLookSpeed(float lookSpeed); 58 | float lookSpeed() const; 59 | 60 | void setZoomLimit(float limit); 61 | float zoomLimit() const; 62 | 63 | void setZoomSpeed(float zoomSpeed); 64 | float zoomSpeed() const; 65 | 66 | void setDefaultZoomLimit(); 67 | float defaultZoomLimit() const; 68 | 69 | void setDefaultZoomSpeed(); 70 | float defaultZoomSpeed() const; 71 | 72 | void setLookAtObject(Object3D* object); 73 | Object3D* lookAtObject() const; 74 | 75 | // use from qml only 76 | void touchZoom(float value); 77 | 78 | private: 79 | Qt3DRender::QCamera* m_viewCamera = nullptr; 80 | Qt3DInput::QLogicalDevice* m_logicalDevice = nullptr; 81 | Qt3DLogic::QFrameAction* m_frameAction = nullptr; 82 | 83 | // mouse device 84 | Qt3DInput::QMouseDevice* m_mouseDevice; 85 | 86 | // input fields 87 | Qt3DInput::QAction* m_mouseButtonAction; 88 | Qt3DInput::QActionInput* m_mouseButtonInput; 89 | Qt3DInput::QAxis* m_mouseXAxis; 90 | Qt3DInput::QAxis* m_mouseYAxis; 91 | Qt3DInput::QAnalogAxisInput* m_mouseXInput; 92 | Qt3DInput::QAnalogAxisInput* m_mouseYInput; 93 | 94 | // wheel 95 | Qt3DInput::QAnalogAxisInput* m_mouseWheelXInput; 96 | Qt3DInput::QAnalogAxisInput* mouseWheelYInput; 97 | Qt3DInput::QAxis* m_mouseWheelXAxis; 98 | Qt3DInput::QAxis* m_mouseWheelYAxis; 99 | 100 | // values 101 | float m_lookSpeedValue = 180.0f; 102 | float m_defaultZoomLimitValue = modified(250000.0f); 103 | float m_defaultZoomSpeedValue = modified(5000000.0f); 104 | float m_zoomLimitValue = m_defaultZoomLimitValue; 105 | float m_zoomOutLimitValue = m_zoomLimitValue; 106 | float m_zoomSpeedValue = m_defaultZoomSpeedValue; 107 | 108 | float m_deltaTime = 0.0f; 109 | 110 | QVector3D m_cameraUp = QVector3D(0.0f, 1.0f, 0.0f); 111 | Object3D* m_lookAtObject = nullptr; 112 | 113 | protected: 114 | void updateCameraViewCenter(float deltaTime); 115 | 116 | void zoom(const ZoomData& data); 117 | void zoomIn(const ZoomData& data); 118 | void zoomOut(const ZoomData& data); 119 | 120 | private slots: 121 | void onEnabled(bool enabled); 122 | 123 | // update camera 124 | void onFrameAction(float deltaTime); 125 | }; 126 | } 127 | 128 | #endif // CAMERACONTROLLER_H 129 | -------------------------------------------------------------------------------- /Core/mathcore.h: -------------------------------------------------------------------------------- 1 | #ifndef MATHCORE_H 2 | #define MATHCORE_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | namespace Qt3DRender 12 | { 13 | class QCamera; 14 | } 15 | 16 | namespace SolarSystem 17 | { 18 | class Object3DContainer; 19 | class CameraController; 20 | class SolarObjectsContainer; 21 | 22 | // base solar math model 23 | // some realizations used from Qt QML Planets example 24 | class MathCore final : public QObject 25 | { 26 | Q_OBJECT 27 | 28 | Q_PROPERTY(float solarSystemSpeed READ solarSystemSpeed WRITE setSolarSystemSpeed NOTIFY solarSystemSpeedChanged) 29 | 30 | private: 31 | explicit MathCore(QObject* parent = nullptr); 32 | ~MathCore(); 33 | 34 | MathCore(const MathCore&) = delete; 35 | MathCore(MathCore&&) = delete; 36 | MathCore& operator=(const MathCore&) = delete; 37 | MathCore& operator=(MathCore&&) = delete; 38 | 39 | public: 40 | 41 | // creates solar math core only once 42 | static MathCore* instance(); 43 | 44 | void setCamera(Qt3DRender::QCamera* camera); 45 | Qt3DRender::QCamera* camera() const; 46 | 47 | // returns outer radius of solar object 48 | float getOuterRadius(SolarObjects object); 49 | 50 | // calcualtes current time 51 | void advanceTime(SolarObjects object); 52 | 53 | // checks and sets solar objects actual scale 54 | void setSolarObjectsScale(float scale, bool focused = false); 55 | 56 | // sets camera view center to solar object 57 | void updateSolarView(SolarObjects object); 58 | 59 | // sets days per frame scale speed 60 | void setSolarSystemSpeed(float speed); 61 | 62 | // sets planets container with Object3D 63 | void setObject3DContainer(Object3DContainer* planetsContainer); 64 | 65 | // recalculates all system objects scale 66 | void changeSolarSystemScale(float scale, bool focused = false); 67 | 68 | // sets to math core tick delta time 69 | void setDeltaTime(float dt); 70 | 71 | // returns current calculated solar time 72 | QDateTime getTime() const; 73 | 74 | // calculates solar system non-planet positions 75 | void additionalCalculation(); 76 | 77 | // sets camera controller 78 | void setCameraController(CameraController* controller); 79 | 80 | // returns camera controller 81 | CameraController* cameraController() const; 82 | 83 | // updates camera min zoom position 84 | void updateSolarViewZoomLimit(SolarObjects object); 85 | 86 | // returns solar object position 87 | QVector3D objectPosition(SolarObjects object); 88 | 89 | // returns position of solar view to solar object 90 | QVector3D viewPositionOfObject(SolarObjects object); 91 | 92 | // returns current solar system speed (days per frame) 93 | float solarSystemSpeed() const; 94 | 95 | // calcualtes next step of ultra speed 96 | void changeExtraSpeed() const; 97 | 98 | // returns utral speed 99 | double extraSpeed() const; 100 | 101 | // sets ultra speed to default value 102 | void resetExtraSpeed() const; 103 | 104 | // calculates all objects container solar objects position 105 | void calculateAllSolarObjectsPosiitons(); 106 | 107 | // performs main calculation of math core 108 | void calculate(float deltaTime, SolarObjects object); 109 | 110 | // returns result of angle threshold between camera and solar object 111 | Q_INVOKABLE bool checkAngleThreshold(SolarObjects object, float threshold); 112 | 113 | signals: 114 | void solarSystemSpeedChanged(float); 115 | void solarTimeChanged(const QDateTime&); 116 | 117 | private: 118 | struct Data; 119 | std::unique_ptr data; 120 | 121 | /// helper methods 122 | 123 | // calculates solar object current position 124 | void calculateObjectPosition(SolarObjects object); 125 | 126 | void setupPlanetRings(); 127 | void atmosphereCalculations(); 128 | 129 | float calculateZoomLimit(SolarObjects object, float limit); 130 | float calculateZoomLimit(SolarObjects object); 131 | }; 132 | } 133 | 134 | #endif // MATHCORE_H 135 | -------------------------------------------------------------------------------- /Core/object3dbuilder.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJECT3DBUILDER_H 2 | #define OBJECT3DBUILDER_H 3 | 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | namespace SolarSystem 12 | { 13 | template 14 | class Object3DBuilder 15 | { 16 | public: 17 | Object3DBuilder() {} 18 | Object3DBuilder(const QString& diffuse, const QString& normal = QString()): 19 | m_normalSource(normal), 20 | m_diffuseSource(diffuse) 21 | { 22 | } 23 | 24 | Object3DBuilder& setShiness(float shiness) 25 | { 26 | m_shiness = shiness; 27 | return *this; 28 | } 29 | 30 | Object3DBuilder& setNormalSource(const QString& normalSource) 31 | { 32 | m_normalSource = normalSource; 33 | return *this; 34 | } 35 | 36 | Object3DBuilder& setDiffuseSource(const QString& diffuseSource) 37 | { 38 | m_diffuseSource = diffuseSource; 39 | return *this; 40 | } 41 | 42 | Object3DBuilder& setTilt(double tilt) 43 | { 44 | m_tilt = tilt; 45 | return *this; 46 | } 47 | 48 | // create and setup planet 49 | Object* build(Qt3DCore::QNode* root = nullptr) 50 | { 51 | Object* object = new Object(root); 52 | 53 | auto material = qobject_cast(object->material()); 54 | 55 | // diffuse 56 | if (!m_diffuseSource.isEmpty()) 57 | { 58 | Qt3DRender::QTextureImage* diffuse = new Qt3DRender::QTextureImage(object); 59 | diffuse->setSource(QUrl::fromLocalFile(m_diffuseSource)); 60 | material->diffuse()->addTextureImage(diffuse); 61 | } 62 | 63 | // normal 64 | if (!m_normalSource.isEmpty()) 65 | { 66 | Qt3DRender::QTextureImage* normal = new Qt3DRender::QTextureImage(object); 67 | normal->setSource(QUrl::fromLocalFile(m_normalSource)); 68 | material->normal()->addTextureImage(normal); 69 | } 70 | 71 | if (m_shiness != 0.0f) 72 | material->setShininess(material->shininess() * m_shiness); 73 | 74 | if (m_tilt != 0.0) 75 | object->setTilt(m_tilt); 76 | 77 | return object; 78 | } 79 | 80 | private: 81 | QString m_normalSource; 82 | QString m_diffuseSource; 83 | float m_shiness = 0; 84 | double m_tilt = 0; 85 | }; 86 | 87 | using PlanetBuilder = Object3DBuilder; 88 | using PlanetRingBuilder = Object3DBuilder; 89 | } 90 | 91 | #endif // OBJECT3DBUILDER_H 92 | -------------------------------------------------------------------------------- /Core/object3dcontainer.cpp: -------------------------------------------------------------------------------- 1 | #include "object3dcontainer.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | SolarSystem::Object3DContainer::Object3DContainer(Qt3DCore::QNode* root, QObject* parent): 14 | QObject(parent) 15 | { 16 | initialize(root); 17 | } 18 | 19 | SolarSystem::Object3DContainer::~Object3DContainer() 20 | { 21 | if (m_rootNode == nullptr) 22 | { 23 | for (auto& elem : m_objectContainer) 24 | { 25 | delete elem.second; 26 | } 27 | } 28 | } 29 | 30 | void SolarSystem::Object3DContainer::initialize(Qt3DCore::QNode* root) 31 | { 32 | constexpr auto shiness = 10.0f; 33 | 34 | /// create planets and add to map 35 | 36 | m_objectContainer[SolarObjects::Sun] = new Sun(root); 37 | 38 | // mercury 39 | m_objectContainer[SolarObjects::Mercury] = PlanetBuilder{":/Resources/Images/mercurymap.jpg", ":/Resources/Images/mercurynormal.jpg"} 40 | .setShiness(shiness) 41 | .setTilt(SolarObjectsValues::Mercury::tilt) 42 | .build(root); 43 | 44 | // venus 45 | m_objectContainer[SolarObjects::Venus] = PlanetBuilder{":/Resources/Images/venus_atmo.jpg", ":/Resources/Images/venus_atmonormal.jpg"} 46 | .setShiness(shiness) 47 | .setTilt(SolarObjectsValues::Venus::tilt) 48 | .build(root); 49 | 50 | // earth 51 | m_objectContainer[SolarObjects::Earth] = PlanetBuilder{":/Resources/Images/earthmap1k.jpg", ":/Resources/Images/earthnormal1k.jpg"} 52 | .setShiness(shiness) 53 | .setTilt(SolarObjectsValues::Earth::tilt) 54 | .build(root); 55 | 56 | // moon 57 | m_objectContainer[SolarObjects::Moon] = PlanetBuilder{":/Resources/Images/moonmap1k.jpg", ":/Resources/Images/moonnormal1k.jpg"} 58 | .setShiness(shiness) 59 | .setTilt(SolarObjectsValues::Moon::tilt) 60 | .build(root); 61 | 62 | // mars 63 | m_objectContainer[SolarObjects::Mars] = PlanetBuilder{":/Resources/Images/marsmap1k.jpg", ":/Resources/Images/marsnormal1k.jpg"} 64 | .setShiness(shiness) 65 | .setTilt(SolarObjectsValues::Mars::tilt) 66 | .build(root); 67 | 68 | // jupiter 69 | m_objectContainer[SolarObjects::Jupiter] = PlanetBuilder{":/Resources/Images/jupitermap.jpg", ":/Resources/Images/jupiternormal.jpg"} 70 | .setShiness(shiness) 71 | .setTilt(SolarObjectsValues::Jupier::tilt) 72 | .build(root); 73 | 74 | // saturn 75 | m_objectContainer[SolarObjects::Saturn] = PlanetBuilder{":/Resources/Images/saturnmap.jpg", ":/Resources/Images/saturnnormal.jpg"} 76 | .setShiness(shiness) 77 | .setTilt(SolarObjectsValues::Saturn::tilt) 78 | .build(root); 79 | 80 | // uranus 81 | m_objectContainer[SolarObjects::Uranus] = PlanetBuilder{":/Resources/Images/uranusmap.jpg", ":/Resources/Images/uranusnormal.jpg"} 82 | .setShiness(shiness) 83 | .setTilt(SolarObjectsValues::Uranus::tilt) 84 | .build(root); 85 | 86 | // neptune 87 | m_objectContainer[SolarObjects::Neptune] = PlanetBuilder{":/Resources/Images/neptunemap.jpg", ":/Resources/Images/neptunenormal.jpg"} 88 | .setShiness(shiness) 89 | .setTilt(SolarObjectsValues::Neptune::tilt) 90 | .build(root); 91 | 92 | // pluto 93 | m_objectContainer[SolarObjects::Pluto] = PlanetBuilder{":/Resources/Images/plutomap.jpg", ":/Resources/Images/plutonormal.jpg"} 94 | .setShiness(shiness) 95 | .setTilt(SolarObjectsValues::Pluto::tilt) 96 | .build(root); 97 | 98 | m_calculatedSolarObjectNumber = static_cast(m_objectContainer.size()); 99 | 100 | // add additional solar objects 101 | m_objectContainer[SolarObjects::SaturnRing] = PlanetRingBuilder{":/Resources/Images/saturnringcolortrans.png", ":/Resources/Images/saturnringcolortransnormal.png"} 102 | .setTilt(SolarObjectsValues::SaturnRing::tilt) 103 | .build(root); 104 | 105 | m_objectContainer[SolarObjects::UranusRing] = PlanetRingBuilder{":/Resources/Images/uranusringcolortrans.png", ":/Resources/Images/uranusringcolortransnormal.png"} 106 | .setTilt(SolarObjectsValues::UranusRing::tilt) 107 | .build(root); 108 | 109 | m_objectContainer[SolarObjects::EarthCloud] = new EarthCloud(root); 110 | m_rootNode = root; 111 | } 112 | 113 | int SolarSystem::Object3DContainer::planetsNumber() const 114 | { 115 | return m_calculatedSolarObjectNumber; 116 | } 117 | 118 | SolarSystem::Object3DMap& SolarSystem::Object3DContainer::objects() const 119 | { 120 | return m_objectContainer; 121 | } 122 | 123 | SolarSystem::Object3D* SolarSystem::Object3DContainer::object(SolarSystem::SolarObjects type) const 124 | { 125 | auto iter = m_objectContainer.find(type); 126 | 127 | if (iter != m_objectContainer.end()) 128 | return iter->second; 129 | 130 | return nullptr; 131 | } 132 | -------------------------------------------------------------------------------- /Core/object3dcontainer.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJECT3DCONTAINER_H 2 | #define OBJECT3DCONTAINER_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace SolarSystem 10 | { 11 | using Object3DMap = std::map; 12 | 13 | // contains all 3D planets 14 | class Object3DContainer : public QObject 15 | { 16 | Q_OBJECT 17 | 18 | public: 19 | explicit Object3DContainer(Qt3DCore::QNode* root = nullptr, QObject* parent = nullptr); 20 | ~Object3DContainer(); 21 | 22 | // returns solar object count (planets + moons + start) 23 | int planetsNumber() const; 24 | 25 | // returns planet storage 26 | Object3DMap& objects() const; 27 | Object3D* object(SolarObjects type) const; 28 | 29 | private: 30 | 31 | // main planet storage 32 | mutable Object3DMap m_objectContainer; 33 | 34 | // root entity 35 | Qt3DCore::QNode* m_rootNode = nullptr; 36 | 37 | // number of calculated planets in the planet container 38 | int m_calculatedSolarObjectNumber = 0; 39 | 40 | // initialization helper 41 | void initialize(Qt3DCore::QNode* root); 42 | }; 43 | } 44 | 45 | #endif // OBJECT3DCONTAINER_H 46 | -------------------------------------------------------------------------------- /Core/solarobjectscontainer.cpp: -------------------------------------------------------------------------------- 1 | #include "solarobjectscontainer.h" 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | SolarSystem::SolarObjectsContainer::SolarObjectsContainer(QObject* parent): 11 | QObject(parent) 12 | { 13 | // create all maths solar system objects 14 | 15 | // stars 16 | m_solarObjects.emplace(std::make_pair(SolarObjects::Sun, SolarObjectsFactory::create())); 17 | 18 | // planets 19 | m_solarObjects.emplace(std::make_pair(SolarObjects::Mercury, SolarObjectsFactory::create())); 20 | m_solarObjects.emplace(std::make_pair(SolarObjects::Venus, SolarObjectsFactory::create())); 21 | m_solarObjects.emplace(std::make_pair(SolarObjects::Earth, SolarObjectsFactory::create())); 22 | m_solarObjects.emplace(std::make_pair(SolarObjects::Mars, SolarObjectsFactory::create())); 23 | m_solarObjects.emplace(std::make_pair(SolarObjects::Jupiter, SolarObjectsFactory::create())); 24 | m_solarObjects.emplace(std::make_pair(SolarObjects::Saturn, SolarObjectsFactory::create())); 25 | m_solarObjects.emplace(std::make_pair(SolarObjects::Neptune, SolarObjectsFactory::create())); 26 | m_solarObjects.emplace(std::make_pair(SolarObjects::Uranus, SolarObjectsFactory::create())); 27 | m_solarObjects.emplace(std::make_pair(SolarObjects::Pluto, SolarObjectsFactory::create())); 28 | 29 | // moons 30 | m_solarObjects.emplace(std::make_pair(SolarObjects::Moon, SolarObjectsFactory::create())); 31 | } 32 | 33 | SolarSystem::SolarObjectPtr SolarSystem::SolarObjectsContainer::solarObject(SolarSystem::SolarObjects object) const 34 | { 35 | auto iter = m_solarObjects.find(object); 36 | 37 | if (iter != m_solarObjects.end()) 38 | return iter->second; 39 | else 40 | qDebug() << "The object: " + SolarParser::parseSolarObjectToString(object) + " not in solar container"; 41 | 42 | return SolarObjectPtr(); 43 | } 44 | -------------------------------------------------------------------------------- /Core/solarobjectscontainer.h: -------------------------------------------------------------------------------- 1 | #ifndef SOLAROBJECTSCONTAINER_H 2 | #define SOLAROBJECTSCONTAINER_H 3 | 4 | #include 5 | 6 | namespace SolarSystem 7 | { 8 | // solar math objects storage 9 | class SolarObjectsContainer final : public QObject 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | explicit SolarObjectsContainer(QObject* parent = nullptr); 15 | 16 | // get math solar object 17 | SolarObjectPtr solarObject(SolarObjects object) const; 18 | 19 | private: 20 | SolarObjectsMap m_solarObjects; 21 | }; 22 | } 23 | 24 | #endif // SOLAROBJECTSCONTAINER_H 25 | -------------------------------------------------------------------------------- /Core/solarobjectsfactory.h: -------------------------------------------------------------------------------- 1 | #ifndef SOLAROBJECTSFACTORY_H 2 | #define SOLAROBJECTSFACTORY_H 3 | 4 | #include 5 | 6 | namespace SolarSystem 7 | { 8 | // all math solar objects factory 9 | class SolarObjectsFactory final 10 | { 11 | public: 12 | 13 | // creates any object inherited from AbstractSolarObject 14 | template< typename SolarObject, 15 | typename... Args, 16 | typename = std::enable_if_t< 17 | std::is_base_of>::value>> 19 | 20 | static std::shared_ptr create(Args&&... args) 21 | { 22 | using Type = typename std::remove_cv_t; 23 | return std::make_shared(std::forward(args)...); 24 | } 25 | }; 26 | } 27 | 28 | #endif // SOLAROBJECTSFACTORY_H 29 | -------------------------------------------------------------------------------- /Core/utils.cpp: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | 3 | SolarSystem::Utils::Utils(QObject* parent): 4 | QObject(parent) 5 | { 6 | } 7 | 8 | QObject* SolarSystem::utilsProvider(QQmlEngine*, QJSEngine*) 9 | { 10 | return new Utils(); 11 | } 12 | -------------------------------------------------------------------------------- /Core/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILS_H 2 | #define UTILS_H 3 | 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | class QQmlEngine; 13 | class QJSEngine; 14 | 15 | namespace SolarSystem 16 | { 17 | // Additional class with solar system common helper methods 18 | class Utils final : public QObject 19 | { 20 | Q_OBJECT 21 | 22 | explicit Utils(QObject* parent = nullptr); 23 | 24 | public: 25 | 26 | // days time scale calculation 27 | static float calculateUT(int h, int m = 0, float s = 0) 28 | { 29 | return (h + m/60.0f + s/3600.0f)/24.0f; 30 | } 31 | 32 | // time scale calculation 33 | static float calculateTimeScale(int year, int month, int day) 34 | { 35 | return 367 * year - 7 * (year + (month + 9) / 12) / 4 + 275 * month / 9 + day - 730530; 36 | } 37 | 38 | // linear interpolation, time range [0, 1] 39 | static QVector3D lerp(const QVector3D& start, const QVector3D& end, float time) 40 | { 41 | return (start + (end - start) * time); 42 | } 43 | 44 | // linear interpolation for primitive types, time range [0, 1] 45 | template>> 46 | static T lerp(T start, T end, float time) 47 | { 48 | return (1.0f - time) * start + time * end; 49 | } 50 | 51 | // spherical linear interpolation from https://en.wikipedia.org/wiki/Slerp 52 | static QVector3D slerp(const QVector3D& start, const QVector3D& end, float time) 53 | { 54 | auto dot = QVector3D::dotProduct(start, end); 55 | auto dotValue = std::clamp(dot, -1.0f, 1.0f); 56 | 57 | auto theta = std::acos(dotValue) * time; 58 | auto relativeVector = (end - start * dotValue).normalized(); 59 | 60 | return (start * std::cos(theta)) + (relativeVector * std::sin(theta)); 61 | } 62 | 63 | // calculates angle between two vectors 3d 64 | Q_INVOKABLE static float angle(const QVector3D& lhs, const QVector3D& rhs) 65 | { 66 | auto dot = QVector3D::dotProduct(lhs, rhs); 67 | auto dotValue = std::clamp(dot, -1.0f, 1.0f); 68 | auto cos = dotValue/(lhs.length() * rhs.length()); 69 | 70 | // radians to degree 71 | return std::acos(cos) * 180.0f/static_cast(M_PI); 72 | } 73 | 74 | // calculates angle between two vectors 2d 75 | Q_INVOKABLE static float angle(const QVector2D& lhs, const QVector2D& rhs) 76 | { 77 | return Utils::angle(lhs.toVector3D(), rhs.toVector3D()); 78 | } 79 | 80 | // helper to QML, calculates distance between two vectors 3d 81 | Q_INVOKABLE static float distance(const QVector3D& lhs, const QVector3D& rhs) 82 | { 83 | return (lhs - rhs).length(); 84 | } 85 | 86 | // helper to QML, calculates distance between two vectors 2d 87 | Q_INVOKABLE static float distance(const QVector2D& lhs, const QVector2D& rhs) 88 | { 89 | return distance(lhs.toVector3D(), rhs.toVector3D()); 90 | } 91 | 92 | // calculates the shortest difference between two given angles given in degrees, 93 | // https://stackoverflow.com/questions/1878907/the-smallest-difference-between-2-angles 94 | Q_INVOKABLE static float deltaAngle(float current, float target) 95 | { 96 | float result = current - target; 97 | return -(static_cast(result + 180) % 360 - 180); 98 | } 99 | 100 | Q_INVOKABLE static float specialAngle(const QVector2D& lhs, const QVector2D& rhs) 101 | { 102 | auto from = rhs - lhs; 103 | auto to = QVector2D(1, 0); 104 | 105 | auto result = Utils::angle(from, to); 106 | auto cross = QVector3D::crossProduct(from.toVector3D(), to.toVector3D()); 107 | 108 | if (cross.z() > 0) 109 | { 110 | result = 360.0f - result; 111 | } 112 | 113 | return result; 114 | } 115 | 116 | friend QObject* utilsProvider(QQmlEngine*, QJSEngine*); 117 | }; 118 | 119 | QObject* utilsProvider(QQmlEngine*, QJSEngine*); 120 | } 121 | 122 | #endif // UTILS_H 123 | -------------------------------------------------------------------------------- /Interface/iframegraph.h: -------------------------------------------------------------------------------- 1 | #ifndef IFRAMEGRAPH_H 2 | #define IFRAMEGRAPH_H 3 | 4 | #include 5 | 6 | namespace SolarSystem 7 | { 8 | // represents abstract frame graph class 9 | class IFrameGraph : public Qt3DRender::QRenderSettings 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | explicit IFrameGraph(Qt3DCore::QNode* parent = nullptr): 15 | QRenderSettings(parent) {} 16 | 17 | virtual void setCamera(Qt3DCore::QEntity* camera) = 0; 18 | }; 19 | } 20 | 21 | #endif // IFRAMEGRAPH_H 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Nikita Instand 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Parser/solarparser.cpp: -------------------------------------------------------------------------------- 1 | #include "solarparser.h" 2 | 3 | SolarSystem::ObjectType SolarSystem::SolarParser::parseString(const QString &str) 4 | { 5 | ObjectType objectType = ObjectType::SolarSystemBody; 6 | 7 | if (str == SolarStrings::planet) 8 | objectType = ObjectType::Planet; 9 | 10 | if (str == SolarStrings::dwarfPlanet) 11 | objectType = ObjectType::DwarfPlanet; 12 | 13 | if (str == SolarStrings::star) 14 | objectType = ObjectType::Star; 15 | 16 | if (str == SolarStrings::moon) 17 | objectType = ObjectType::Moon; 18 | 19 | if (str == SolarStrings::asteroid) 20 | objectType = ObjectType::Asteroid; 21 | 22 | if (str == SolarStrings::galaxy) 23 | objectType = ObjectType::Galaxy; 24 | 25 | if (str == SolarStrings::ring) 26 | objectType = ObjectType::Ring; 27 | 28 | return objectType; 29 | } 30 | 31 | QString SolarSystem::SolarParser::parseSolarObjectToString(SolarSystem::SolarObjects object) 32 | { 33 | QString str; 34 | 35 | switch (object) 36 | { 37 | case SolarObjects::SolarSystemView: 38 | str = SolarObjectsValues::SolarSystem::toString; 39 | break; 40 | 41 | case SolarObjects::Sun: 42 | str = SolarObjectsValues::Sun::toString; 43 | break; 44 | 45 | case SolarObjects::Mercury: 46 | str = SolarObjectsValues::Mercury::toString; 47 | break; 48 | 49 | case SolarObjects::Venus: 50 | str = SolarObjectsValues::Venus::toString; 51 | break; 52 | 53 | case SolarObjects::Earth: 54 | str = SolarObjectsValues::Earth::toString; 55 | break; 56 | 57 | case SolarObjects::Mars: 58 | str = SolarObjectsValues::Mars::toString; 59 | break; 60 | 61 | case SolarObjects::Jupiter: 62 | str = SolarObjectsValues::Jupier::toString; 63 | break; 64 | 65 | case SolarObjects::Saturn: 66 | str = SolarObjectsValues::Saturn::toString; 67 | break; 68 | 69 | case SolarObjects::Neptune: 70 | str = SolarObjectsValues::Neptune::toString; 71 | break; 72 | 73 | case SolarObjects::Uranus: 74 | str = SolarObjectsValues::Uranus::toString; 75 | break; 76 | 77 | case SolarObjects::Pluto: 78 | str = SolarObjectsValues::Pluto::toString; 79 | break; 80 | 81 | case SolarObjects::Moon: 82 | str = SolarObjectsValues::Moon::toString; 83 | break; 84 | 85 | default: 86 | str = "None"; 87 | break; 88 | } 89 | 90 | return str; 91 | } 92 | 93 | float SolarSystem::SolarParser::parseSolarObjectTilt(SolarSystem::SolarObjects object) 94 | { 95 | double tilt = 0; 96 | 97 | switch (object) 98 | { 99 | 100 | case SolarObjects::Sun: 101 | tilt = SolarObjectsValues::Sun::tilt; 102 | break; 103 | 104 | case SolarObjects::Mercury: 105 | tilt = SolarObjectsValues::Mercury::tilt; 106 | break; 107 | 108 | case SolarObjects::Venus: 109 | tilt = SolarObjectsValues::Venus::tilt; 110 | break; 111 | 112 | case SolarObjects::Earth: 113 | tilt = SolarObjectsValues::Earth::tilt; 114 | break; 115 | 116 | case SolarObjects::Mars: 117 | tilt = SolarObjectsValues::Mars::tilt; 118 | break; 119 | 120 | case SolarObjects::Jupiter: 121 | tilt = SolarObjectsValues::Jupier::tilt; 122 | break; 123 | 124 | case SolarObjects::Saturn: 125 | tilt = SolarObjectsValues::Saturn::tilt; 126 | break; 127 | 128 | case SolarObjects::Uranus: 129 | tilt = SolarObjectsValues::Uranus::tilt; 130 | break; 131 | 132 | case SolarObjects::Neptune: 133 | tilt = SolarObjectsValues::Neptune::tilt; 134 | break; 135 | 136 | case SolarObjects::Pluto: 137 | tilt = SolarObjectsValues::Pluto::tilt; 138 | break; 139 | 140 | case SolarObjects::Moon: 141 | tilt = SolarObjectsValues::Moon::tilt; 142 | break; 143 | 144 | default: 145 | break; 146 | } 147 | 148 | return static_cast(tilt); 149 | } 150 | 151 | double SolarSystem::SolarParser::parseSolarObjectRadius(SolarSystem::SolarObjects object) 152 | { 153 | double radius = 0; 154 | 155 | switch (object) 156 | { 157 | case SolarObjects::Sun: 158 | radius = SolarObjectsValues::Sun::radius; 159 | break; 160 | 161 | case SolarObjects::Mercury: 162 | radius = SolarObjectsValues::Mercury::radius; 163 | break; 164 | 165 | case SolarObjects::Venus: 166 | radius = SolarObjectsValues::Venus::radius; 167 | break; 168 | 169 | case SolarObjects::Earth: 170 | radius = SolarObjectsValues::Earth::radius; 171 | break; 172 | 173 | case SolarObjects::Mars: 174 | radius = SolarObjectsValues::Mars::radius; 175 | break; 176 | 177 | case SolarObjects::Jupiter: 178 | radius = SolarObjectsValues::Jupier::radius; 179 | break; 180 | 181 | case SolarObjects::Saturn: 182 | radius = SolarObjectsValues::Saturn::radius; 183 | break; 184 | 185 | case SolarObjects::Uranus: 186 | radius = SolarObjectsValues::Uranus::radius; 187 | break; 188 | 189 | case SolarObjects::Neptune: 190 | radius = SolarObjectsValues::Neptune::radius; 191 | break; 192 | 193 | case SolarObjects::Pluto: 194 | radius = SolarObjectsValues::Pluto::radius; 195 | break; 196 | 197 | case SolarObjects::Moon: 198 | radius = SolarObjectsValues::Moon::radius; 199 | break; 200 | 201 | default: 202 | break; 203 | } 204 | 205 | return radius; 206 | } 207 | 208 | SolarSystem::SolarObjects SolarSystem::SolarParser::parsePlanetListIndex(int index) 209 | { 210 | SolarObjects object = SolarObjects::SolarSystemView; 211 | 212 | switch (index) 213 | { 214 | case 0: 215 | object = SolarObjects::SolarSystemView; 216 | break; 217 | 218 | case 1: 219 | object = SolarObjects::Sun; 220 | break; 221 | 222 | case 2: 223 | object = SolarObjects::Mercury; 224 | break; 225 | 226 | case 3: 227 | object = SolarObjects::Venus; 228 | break; 229 | 230 | case 4: 231 | object = SolarObjects::Earth; 232 | break; 233 | 234 | case 5: 235 | object = SolarObjects::Mars; 236 | break; 237 | 238 | case 6: 239 | object = SolarObjects::Jupiter; 240 | break; 241 | 242 | case 7: 243 | object = SolarObjects::Saturn; 244 | break; 245 | 246 | case 8: 247 | object = SolarObjects::Uranus; 248 | break; 249 | 250 | case 9: 251 | object = SolarObjects::Neptune; 252 | break; 253 | 254 | case 10: 255 | object = SolarObjects::Pluto; 256 | break; 257 | 258 | default: 259 | break; 260 | } 261 | 262 | return object; 263 | } 264 | -------------------------------------------------------------------------------- /Parser/solarparser.h: -------------------------------------------------------------------------------- 1 | #ifndef SOLARPARSER_H 2 | #define SOLARPARSER_H 3 | 4 | #include 5 | #include 6 | 7 | namespace SolarSystem 8 | { 9 | // static realization of string solar object parser 10 | class SolarParser 11 | { 12 | public: 13 | 14 | // parse string to get solar object type 15 | static ObjectType parseString(const QString& str); 16 | 17 | // returns string from SolarObejcts type 18 | static QString parseSolarObjectToString(SolarObjects object); 19 | 20 | // returns tilt of solar object 21 | static float parseSolarObjectTilt(SolarObjects object); 22 | 23 | // returns radius of solar object 24 | static double parseSolarObjectRadius(SolarObjects object); 25 | 26 | // returns solar object from planet list index 27 | static SolarObjects parsePlanetListIndex(int index); 28 | }; 29 | } 30 | 31 | 32 | #endif // SOLARPARSER_H 33 | -------------------------------------------------------------------------------- /QML/Controls.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | 3 | Column { 4 | id: root 5 | spacing: 3 6 | 7 | // size of every element 8 | property int elementWidth: 10 9 | property int elementHeight: 20 10 | 11 | signal planetButtonClicked(string name) 12 | signal infoButtonClicked(string name) 13 | signal calendarButtonClicked(string name) 14 | signal optionButtonClicked(string name) 15 | 16 | // planet list button 17 | TransparentButton { 18 | id: planetButton 19 | width: root.elementWidth 20 | height: root.elementHeight 21 | radius: 4 22 | source: "qrc:/Resources/Images/planet_icon.png" 23 | objectName: "planetButton" 24 | 25 | onClicked: root.planetButtonClicked(planetButton.objectName) 26 | } 27 | 28 | // calendar button 29 | TransparentButton { 30 | id: calendarButton 31 | width: root.elementWidth 32 | height: root.elementHeight 33 | radius: 4 34 | source: "qrc:/Resources/Images/calendar_icon.png" 35 | objectName: "calendarButton" 36 | 37 | onClicked: root.calendarButtonClicked(calendarButton.objectName) 38 | } 39 | 40 | // options button 41 | TransparentButton { 42 | id: optionsButton 43 | width: root.elementWidth 44 | height: root.elementHeight 45 | radius: 4 46 | source: "qrc:/Resources/Images/options_icon.png" 47 | objectName: "optionsButton" 48 | 49 | onClicked: root.optionButtonClicked(optionsButton.objectName) 50 | } 51 | 52 | // info button 53 | TransparentButton { 54 | id: infoButton 55 | width: root.elementWidth 56 | height: root.elementHeight 57 | radius: 4 58 | source: "qrc:/Resources/Images/info_icon.png" 59 | objectName: "infoButton" 60 | 61 | onClicked: root.infoButtonClicked(infoButton.objectName) 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /QML/DatabaseLabel.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | 3 | Item { 4 | id: root 5 | property string text: "" 6 | 7 | Text { 8 | anchors.fill: parent 9 | color: "white" 10 | font.pixelSize: 22 11 | style: Text.Sunken 12 | styleColor: "black" 13 | text: " Database status: " + root.text 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /QML/DateText.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | 3 | Text { 4 | anchors.top: parent.top 5 | anchors.horizontalCenter: parent.horizontalCenter 6 | color: "white"; 7 | font.pixelSize: 20 8 | style: Text.Sunken; 9 | styleColor: "black" 10 | } 11 | -------------------------------------------------------------------------------- /QML/FpsLabel.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | 3 | Item { 4 | id: root 5 | property string text: "" 6 | 7 | Text { 8 | anchors.fill: parent 9 | color: "white" 10 | font.pixelSize: 22 11 | style: Text.Sunken 12 | styleColor: "black" 13 | text: " Fps: " + root.text 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /QML/Info.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | 3 | Text { 4 | id: root 5 | 6 | property alias showInfo: showInfoAnim 7 | property alias unshowInfo: unshowInfoAnim 8 | 9 | font.family: "Comic Sans MS" 10 | font.italic: true 11 | verticalAlignment: Text.AlignVCenter 12 | font.pixelSize: 18 13 | font.weight: Font.Light 14 | lineHeight: 1.625 * 16 15 | lineHeightMode: Text.FixedHeight 16 | color: "white" 17 | opacity: 0 18 | wrapMode: Text.Wrap 19 | style: Text.Sunken; 20 | styleColor: "black" 21 | visible: false 22 | 23 | PropertyAnimation { 24 | id: showInfoAnim 25 | target: root 26 | property: "opacity" 27 | to: 0.85 28 | duration: 1000 29 | onStarted: root.visible = true 30 | } 31 | 32 | PropertyAnimation { 33 | id: unshowInfoAnim 34 | target: root 35 | property: "opacity" 36 | to: 0 37 | duration: 1000 38 | onStopped: root.visible = false 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /QML/PlanetButton.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | 3 | Rectangle { 4 | id: planetButton 5 | 6 | property alias text: planetText.text 7 | property alias source: planetImage.source 8 | property alias focusPlanet: planetImage.focusPlanet 9 | property Item planetSelector: parent.parent 10 | property int buttonSize: 70 11 | property int fontSize: 16 12 | 13 | signal clicked; 14 | 15 | width: buttonSize 16 | height: buttonSize 17 | color: "transparent" 18 | 19 | Image { 20 | id: planetImage 21 | anchors.fill: parent 22 | property int focusPlanet 23 | 24 | MouseArea { 25 | anchors.fill: parent 26 | hoverEnabled: true 27 | 28 | onClicked: { 29 | planetSelector.focusedPlanet = focusPlanet; 30 | planetButton.clicked(); 31 | } 32 | 33 | onEntered: PropertyAnimation { 34 | target: planetText; 35 | property: "opacity"; 36 | to: 1 37 | } 38 | 39 | onExited: PropertyAnimation { 40 | target: planetText 41 | property: "opacity" 42 | to: 0 43 | } 44 | } 45 | } 46 | 47 | Text { 48 | id: planetText 49 | anchors.centerIn: parent 50 | font.family: "Helvetica" 51 | font.pixelSize: fontSize 52 | font.weight: Font.Light 53 | color: "white" 54 | opacity: 0 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /QML/PlanetList.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | 3 | Item { 4 | id: root 5 | 6 | property int buttonSize: 70 7 | property int fontSize: 14 8 | property int focusedPlanet: 0 9 | 10 | signal clicked; 11 | 12 | // planet view model 13 | ListModel { 14 | id: planetModel 15 | 16 | ListElement { 17 | name: "Solar System" 18 | planetImageSource: "qrc:/Resources/Images/solarsystem.png" 19 | planetNumber: 0 20 | } 21 | 22 | ListElement { 23 | name: "Sun" 24 | planetImageSource: "qrc:/Resources/Images/sun.png" 25 | planetNumber: 1 26 | } 27 | 28 | ListElement { 29 | name: "Mercury" 30 | planetImageSource: "qrc:/Resources/Images/mercury.png" 31 | planetNumber: 2 32 | } 33 | 34 | ListElement { 35 | name: "Venus" 36 | planetImageSource: "qrc:/Resources/Images/venus.png" 37 | planetNumber: 3 38 | } 39 | 40 | ListElement { 41 | name: "Earth" 42 | planetImageSource: "qrc:/Resources/Images/earth.png" 43 | planetNumber: 4 44 | } 45 | 46 | ListElement { 47 | name: "Mars" 48 | planetImageSource: "qrc:/Resources/Images/mars.png" 49 | planetNumber: 5 50 | } 51 | 52 | ListElement { 53 | name: "Jupiter" 54 | planetImageSource: "qrc:/Resources/Images/jupiter.png" 55 | planetNumber: 6 56 | } 57 | 58 | ListElement { 59 | name: "Saturn" 60 | planetImageSource: "qrc:/Resources/Images/saturn.png" 61 | planetNumber: 7 62 | } 63 | 64 | ListElement { 65 | name: "Uranus" 66 | planetImageSource: "qrc:/Resources/Images/uranus.png" 67 | planetNumber: 8 68 | } 69 | 70 | ListElement { 71 | name: "Neptune" 72 | planetImageSource: "qrc:/Resources/Images/neptune.png" 73 | planetNumber: 9 74 | } 75 | 76 | ListElement { 77 | name: "Pluto" 78 | planetImageSource: "qrc:/Resources/Images/pluto.png" 79 | planetNumber: 10 80 | } 81 | } 82 | 83 | // model delegate 84 | Component { 85 | id: modelDelegate 86 | 87 | //use button 88 | PlanetButton { 89 | source: planetImageSource 90 | text: name 91 | planetSelector: root 92 | buttonSize: root.buttonSize 93 | fontSize: root.fontSize 94 | focusPlanet: planetNumber 95 | 96 | onClicked: root.clicked() 97 | } 98 | } 99 | 100 | // view element 101 | ListView { 102 | id: planetButtonView 103 | anchors.fill: parent 104 | spacing: 10 105 | width: root.parent.width 106 | interactive: false 107 | model: planetModel 108 | delegate: modelDelegate 109 | orientation: Qt.Horizontal 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /QML/SolarEntityMain.qml: -------------------------------------------------------------------------------- 1 | import QtQml 2.2 2 | 3 | import Qt3D.Core 2.0 4 | import Qt3D.Extras 2.0 5 | 6 | import SolarSystem 1.0 7 | import SolarSystem.Utils 1.0 8 | 9 | // QML/C++ code connection 10 | Entity { 11 | id: rootEntity 12 | 13 | property alias entity: solarSystem 14 | property alias counter: solarSystem.counter 15 | 16 | SolarEntity { 17 | id: solarSystem 18 | } 19 | 20 | function dbState() { 21 | return solarSystem.databaseStatus ? "Ok" : "Failured"; 22 | } 23 | 24 | // calculates possibility to use zoom by QML 25 | function zoom(touch1, touch2) { 26 | const minPitchDistance = 0.05 27 | const pitchRatio = 0.25 28 | 29 | var touch1Start = Qt.vector2d(touch1.previousX, touch1.previousY) 30 | var touch2Start = Qt.vector2d(touch2.previousX, touch2.previousY) 31 | 32 | var touch1Position = Qt.vector2d(touch1.x, touch1.y) 33 | var touch2Position = Qt.vector2d(touch2.x, touch2.y) 34 | 35 | var touchDelta1 = touch1Position.minus(touch1Start) 36 | var touchDelta2 = touch2Position.minus(touch2Start) 37 | 38 | var pitchDistance = Utils.distance(touch1Position, touch2Position) 39 | var previousDistance = Utils.distance(touch1Position.minus(touchDelta1), touch2Position.minus(touchDelta2)) 40 | var pitchDistanceDelta = pitchDistance - previousDistance; 41 | 42 | if (Math.abs(pitchDistanceDelta) > minPitchDistance) { 43 | pitchDistanceDelta *= pitchRatio 44 | } 45 | else { 46 | pitchDistance = 0 47 | pitchDistanceDelta = 0 48 | } 49 | 50 | if (Math.abs(pitchDistanceDelta) > 0) { 51 | solarSystem.zoomCamera(pitchDistanceDelta) 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /QML/SolarFrame.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | 3 | // white frame 4 | Rectangle { 5 | color: "transparent" 6 | border.color: "white" 7 | 8 | Rectangle { 9 | anchors.fill: parent 10 | color: "white" 11 | opacity: 0.1 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /QML/SpeedSlider.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.10 2 | import QtQuick.Controls 2.2 3 | 4 | Slider { 5 | orientation: Qt.Vertical 6 | from: 0 7 | to: 100 8 | value: 50 9 | } 10 | -------------------------------------------------------------------------------- /QML/TransparentButton.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | import QtQuick.Controls 2.1 3 | 4 | Rectangle { 5 | id: root 6 | border.color: "white" 7 | color: "transparent" 8 | antialiasing: true 9 | 10 | // source ref 11 | property alias source: image.source 12 | 13 | signal clicked; 14 | 15 | property real lowOpacity: 0.1 16 | property real maxOpacity: 0.3 17 | 18 | // image on Rectangle surface 19 | Image { 20 | id: image 21 | anchors.verticalCenter: parent.verticalCenter 22 | anchors.horizontalCenter: parent.horizontalCenter 23 | width: parent.width/1.7 24 | height: parent.width/1.7 25 | smooth: true 26 | antialiasing: true 27 | } 28 | 29 | // opacity white rectangle 30 | Rectangle { 31 | id: coloredRECT 32 | anchors.fill: parent 33 | color: "white" 34 | opacity: lowOpacity 35 | 36 | MouseArea { 37 | id: area 38 | anchors.fill: parent 39 | hoverEnabled: true 40 | 41 | // click event 42 | onClicked: { 43 | root.clicked() 44 | } 45 | 46 | // press event 47 | onPressed: { 48 | coloredRECT.opacity = root.lowOpacity 49 | } 50 | 51 | // release event 52 | onReleased: { 53 | if (area.containsMouse) { 54 | coloredRECT.opacity = root.maxOpacity 55 | } 56 | } 57 | 58 | // enter event 59 | onEntered: { 60 | coloredRECT.opacity = root.maxOpacity 61 | } 62 | 63 | // exit event 64 | onExited: { 65 | coloredRECT.opacity = root.lowOpacity 66 | } 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /QML/UserOptions.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | import QtQuick.Controls 2.1 3 | 4 | Item { 5 | id: root 6 | 7 | signal fpsButtonClicked(bool state) 8 | signal dbButtonClicked(bool state) 9 | 10 | // title text 11 | Text { 12 | id: title 13 | anchors.top: root.top 14 | anchors.topMargin: 10 15 | width: parent.width 16 | height: 25 17 | color: "white" 18 | font.italic: true 19 | verticalAlignment: Text.AlignVCenter 20 | horizontalAlignment: Text.AlignHCenter 21 | wrapMode: Text.Wrap 22 | font.pixelSize: 24 23 | style: Text.Sunken; 24 | styleColor: "black" 25 | text: "Options" 26 | } 27 | 28 | Row { 29 | id: fpsRow 30 | anchors.left: root.left 31 | anchors.top: title.bottom 32 | anchors.topMargin: 30 33 | spacing: 15 34 | 35 | // fps title 36 | Text { 37 | wrapMode: Text.Wrap 38 | font.pixelSize: 18 39 | style: Text.Sunken; 40 | styleColor: "black" 41 | color: "white" 42 | text: "Show FPS: " 43 | width: 200 44 | height: fpsRow.height 45 | verticalAlignment: Text.AlignVCenter 46 | horizontalAlignment: Text.AlignRight 47 | } 48 | 49 | // fps button 50 | Button { 51 | id: fpsButton 52 | width: 170 53 | height: 50 54 | text: "On" 55 | font.pixelSize: 22 56 | property bool state: true 57 | 58 | onClicked: { 59 | state = !state 60 | root.fpsButtonClicked(state) 61 | fpsButton.text = state ? "On" : "Off" 62 | } 63 | } 64 | } 65 | 66 | Row { 67 | id: dbRow 68 | anchors.left: root.left 69 | anchors.top: fpsRow.bottom 70 | anchors.topMargin: 30 71 | spacing: 15 72 | 73 | // db title 74 | Text { 75 | wrapMode: Text.Wrap 76 | font.pixelSize: 18 77 | style: Text.Sunken; 78 | styleColor: "black" 79 | color: "white" 80 | text: "Show Database state: " 81 | width: 200 82 | height: dbRow.height 83 | verticalAlignment: Text.AlignVCenter 84 | horizontalAlignment: Text.AlignRight 85 | } 86 | 87 | // db button 88 | Button { 89 | id: dbButton 90 | width: 170 91 | height: 50 92 | text: "Off" 93 | font.pixelSize: 22 94 | property bool state: false 95 | 96 | onClicked: { 97 | state = !state 98 | root.dbButtonClicked(state) 99 | dbButton.text = state ? "On" : "Off" 100 | } 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SolarSystem 2 | Solar system model based on Qt3D framework.
3 | Some features used from Qt Planet QML example.
4 | Some textures used from:
5 | http://www.solarsystemscope.com
6 | 7 | Created in 2017
8 |
9 | Thanks to Qt Company.
10 |
11 | ![alt tag](http://ipic.su/img/img7/fs/SolarSystemScreen.1562931855.jpg)
12 |
13 | 14 |

Build for Windows/Linux/MacOS/Android

15 |

Build dependencies

16 |
    17 |
  • Qt6.0
  • 18 |
  • Compiler with C++17 support
  • 19 |
  • Cmake 3.16 or newest
  • 20 | 21 | On Windows:
    22 | 23 | It is necessary to run in the terminal, which sets the environment variables for building a Visual Studio project 24 | 25 | >```sh 26 | >git clone https://github.com/Instand/SolarSystem.git 27 | >cd SolarSystem 28 | >mkdir build 29 | >cd build 30 | >cmake -DCMAKE_BUILD_TYPE=Release -A x64 .. 31 | >cmake --build . --target ALL_BUILD --config Release 32 | On Linux/MacOS:
    33 | >```sh 34 | >git clone https://github.com/Instand/SolarSystem.git 35 | >cd SolarSystem 36 | >mkdir build 37 | >cd build 38 | >cmake -DCMAKE_BUILD_TYPE=Release .. 39 | >make -j4 40 | 41 |

    Binaries

    42 | 43 | Release binaries are available at https://github.com/Instand/SolarSystem/releases
    44 | -------------------------------------------------------------------------------- /Resources/Database/SolarDB.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Database/SolarDB.db -------------------------------------------------------------------------------- /Resources/Images/calendar_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/calendar_icon.png -------------------------------------------------------------------------------- /Resources/Images/earth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/earth.png -------------------------------------------------------------------------------- /Resources/Images/earthcloudmapcolortrans.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/earthcloudmapcolortrans.png -------------------------------------------------------------------------------- /Resources/Images/earthcloudmapcolortransnormal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/earthcloudmapcolortransnormal.png -------------------------------------------------------------------------------- /Resources/Images/earthcloudmapspec.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/earthcloudmapspec.jpg -------------------------------------------------------------------------------- /Resources/Images/earthmap1k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/earthmap1k.jpg -------------------------------------------------------------------------------- /Resources/Images/earthnormal1k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/earthnormal1k.jpg -------------------------------------------------------------------------------- /Resources/Images/earthspec1k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/earthspec1k.jpg -------------------------------------------------------------------------------- /Resources/Images/exit_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/exit_icon.png -------------------------------------------------------------------------------- /Resources/Images/info_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/info_icon.png -------------------------------------------------------------------------------- /Resources/Images/jupiter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/jupiter.png -------------------------------------------------------------------------------- /Resources/Images/jupitermap.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/jupitermap.jpg -------------------------------------------------------------------------------- /Resources/Images/jupiternormal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/jupiternormal.jpg -------------------------------------------------------------------------------- /Resources/Images/mars.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/mars.png -------------------------------------------------------------------------------- /Resources/Images/marsmap1k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/marsmap1k.jpg -------------------------------------------------------------------------------- /Resources/Images/marsnormal1k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/marsnormal1k.jpg -------------------------------------------------------------------------------- /Resources/Images/mercury.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/mercury.png -------------------------------------------------------------------------------- /Resources/Images/mercurymap.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/mercurymap.jpg -------------------------------------------------------------------------------- /Resources/Images/mercurynormal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/mercurynormal.jpg -------------------------------------------------------------------------------- /Resources/Images/moonmap1k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/moonmap1k.jpg -------------------------------------------------------------------------------- /Resources/Images/moonnormal1k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/moonnormal1k.jpg -------------------------------------------------------------------------------- /Resources/Images/neptune.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/neptune.png -------------------------------------------------------------------------------- /Resources/Images/neptunemap.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/neptunemap.jpg -------------------------------------------------------------------------------- /Resources/Images/neptunenormal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/neptunenormal.jpg -------------------------------------------------------------------------------- /Resources/Images/options_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/options_icon.png -------------------------------------------------------------------------------- /Resources/Images/planet_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/planet_icon.png -------------------------------------------------------------------------------- /Resources/Images/pluto.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/pluto.png -------------------------------------------------------------------------------- /Resources/Images/plutomap.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/plutomap.jpg -------------------------------------------------------------------------------- /Resources/Images/plutonormal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/plutonormal.jpg -------------------------------------------------------------------------------- /Resources/Images/saturn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/saturn.png -------------------------------------------------------------------------------- /Resources/Images/saturn_rings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/saturn_rings.png -------------------------------------------------------------------------------- /Resources/Images/saturnmap.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/saturnmap.jpg -------------------------------------------------------------------------------- /Resources/Images/saturnnormal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/saturnnormal.jpg -------------------------------------------------------------------------------- /Resources/Images/saturnringcolortrans.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/saturnringcolortrans.png -------------------------------------------------------------------------------- /Resources/Images/saturnringcolortransnormal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/saturnringcolortransnormal.png -------------------------------------------------------------------------------- /Resources/Images/screen_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/screen_icon.png -------------------------------------------------------------------------------- /Resources/Images/solar_system.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/solar_system.jpg -------------------------------------------------------------------------------- /Resources/Images/solarsystem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/solarsystem.png -------------------------------------------------------------------------------- /Resources/Images/solarsystem_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/solarsystem_icon.ico -------------------------------------------------------------------------------- /Resources/Images/solarsystem_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/solarsystem_icon.png -------------------------------------------------------------------------------- /Resources/Images/sun.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/sun.png -------------------------------------------------------------------------------- /Resources/Images/sun_map.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/sun_map.jpg -------------------------------------------------------------------------------- /Resources/Images/sun_normal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/sun_normal.jpg -------------------------------------------------------------------------------- /Resources/Images/sunmap.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/sunmap.jpg -------------------------------------------------------------------------------- /Resources/Images/uranus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/uranus.png -------------------------------------------------------------------------------- /Resources/Images/uranusmap.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/uranusmap.jpg -------------------------------------------------------------------------------- /Resources/Images/uranusnormal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/uranusnormal.jpg -------------------------------------------------------------------------------- /Resources/Images/uranusringcolortrans.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/uranusringcolortrans.png -------------------------------------------------------------------------------- /Resources/Images/uranusringcolortransnormal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/uranusringcolortransnormal.png -------------------------------------------------------------------------------- /Resources/Images/venus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/venus.png -------------------------------------------------------------------------------- /Resources/Images/venus_atmo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/venus_atmo.jpg -------------------------------------------------------------------------------- /Resources/Images/venus_atmonormal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/venus_atmonormal.jpg -------------------------------------------------------------------------------- /Resources/Images/venus_map.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/venus_map.jpg -------------------------------------------------------------------------------- /Resources/Images/venusmap.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/venusmap.jpg -------------------------------------------------------------------------------- /Resources/Images/venusnormal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Images/venusnormal.jpg -------------------------------------------------------------------------------- /Resources/Info.txt: -------------------------------------------------------------------------------- 1 | Solar System v. %% 2 | 3 | Based on Qt Framework with Qt3D technology. 4 | For education only. 5 | Some features used from 6 | Qt Planet QML example. 7 | 8 | Some textures used from: 9 | http://www.solarsystemscope.com. 10 | 11 | Created by Arew in 2017. 12 | 13 | Source code available at: 14 | https://github.com/Instand/SolarSystem 15 | 16 | Thanks to Emerald and Qt Company. 17 | -------------------------------------------------------------------------------- /Resources/Shaders/diffuse.frag: -------------------------------------------------------------------------------- 1 | #version 150 core 2 | 3 | uniform sampler2D diffuseTexture; 4 | 5 | in vec3 position; 6 | in vec2 texCoord; 7 | 8 | out vec4 fragColor; 9 | 10 | vec4 dModel(const in vec2 flipYTexCoord) 11 | { 12 | vec3 diffuseColor = texture2D(diffuseTexture, flipYTexCoord).rgb; 13 | return vec4(diffuseColor, 1.0); 14 | } 15 | 16 | void main() 17 | { 18 | vec2 flipYTexCoord = texCoord; 19 | flipYTexCoord.x = 1.0 - texCoord.x; 20 | 21 | vec4 result = dModel(flipYTexCoord); 22 | 23 | fragColor = result; 24 | } 25 | -------------------------------------------------------------------------------- /Resources/Shaders/diffuse.vert: -------------------------------------------------------------------------------- 1 | #version 150 core 2 | 3 | in vec3 vertexPosition; 4 | in vec2 vertexTexCoord; 5 | 6 | out vec3 position; 7 | out vec2 texCoord; 8 | 9 | uniform mat4 modelView; 10 | uniform mat4 mvp; 11 | 12 | uniform float texCoordScale; 13 | 14 | void main() 15 | { 16 | texCoord = vertexTexCoord * texCoordScale; 17 | position = vec3(modelView * vec4(vertexPosition, 1.0)); 18 | gl_Position = mvp * vec4(vertexPosition, 1.0); 19 | } 20 | -------------------------------------------------------------------------------- /Resources/Shaders/diffusenormal.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | //light 4 | uniform vec3 lightPosition; 5 | uniform vec3 lightIntensity; 6 | 7 | //material color data 8 | uniform vec3 ambient; 9 | uniform vec3 specular; 10 | uniform float shininess; 11 | uniform float opacity; 12 | 13 | //textures 14 | uniform sampler2D diffuseTexture; 15 | uniform sampler2D normalTexture; 16 | 17 | in vec3 lightDir; 18 | in vec3 viewDir; 19 | in vec2 texCoord; 20 | 21 | out vec4 fragColor; 22 | 23 | void dbModel(const in vec3 norm, const in vec2 flipYTexCoord, out vec3 ambientAndDiff, out vec3 spec) 24 | { 25 | vec3 r = reflect(-lightDir, norm); 26 | vec3 diffuseColor = texture2D(diffuseTexture, flipYTexCoord).rgb; 27 | vec3 kAmbient = lightIntensity * ambient * diffuseColor; 28 | float sDotN = max(dot(lightDir, norm), 0.0); 29 | vec3 diffuse = lightIntensity * diffuseColor * sDotN; 30 | 31 | ambientAndDiff = kAmbient + diffuse; 32 | 33 | spec = vec3(0.0); 34 | 35 | if (sDotN > 0.0) 36 | spec = (lightIntensity * specular) * pow(max(dot(r, viewDir), 0.0), shininess); 37 | } 38 | 39 | void main() 40 | { 41 | vec2 flipYTexCoord = texCoord; 42 | flipYTexCoord.x = 1.0 - texCoord.x; 43 | 44 | vec4 normal = 2.0 * texture2D(normalTexture, flipYTexCoord) - vec4(1.0); 45 | 46 | vec3 result = lightIntensity * ambient * texture2D(diffuseTexture, flipYTexCoord).rgb; 47 | 48 | vec3 ambientAndDiff, spec; 49 | dbModel(normalize(normal.xyz), flipYTexCoord, ambientAndDiff, spec); 50 | result = ambientAndDiff + spec; 51 | 52 | fragColor = vec4(result, opacity); 53 | } 54 | -------------------------------------------------------------------------------- /Resources/Shaders/diffusenormal.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | in vec3 vertexPosition; 4 | in vec3 vertexNormal; 5 | in vec2 vertexTexCoord; 6 | in vec4 vertexTangent; 7 | 8 | out vec3 lightDir; 9 | out vec3 viewDir; 10 | out vec2 texCoord; 11 | 12 | uniform mat4 viewMatrix; 13 | uniform mat4 modelMatrix; 14 | uniform mat4 modelView; 15 | uniform mat3 modelViewNormal; 16 | uniform mat4 mvp; 17 | uniform float texCoordScale; 18 | uniform vec3 lightPosition; 19 | 20 | void main() 21 | { 22 | texCoord = vertexTexCoord * texCoordScale; 23 | 24 | vec3 normal = normalize(modelViewNormal * vertexNormal); 25 | vec3 tangent = normalize(modelViewNormal * vertexTangent.xyz); 26 | vec3 position = vec3(modelView * vec4(vertexPosition, 1.0)); 27 | vec3 binormal = normalize(cross(normal, tangent)); 28 | 29 | mat3 tangentMatrix = mat3 ( 30 | tangent.x, binormal.x, normal.x, 31 | tangent.y, binormal.y, normal.y, 32 | tangent.z, binormal.z, normal.z); 33 | 34 | vec3 s = lightPosition - position; 35 | lightDir = normalize(tangentMatrix * vec3(viewMatrix * vec4(s, 1.0))); 36 | 37 | vec3 v = -position; 38 | viewDir = normalize(tangentMatrix * v); 39 | 40 | 41 | gl_Position = mvp * vec4(vertexPosition, 1.0); 42 | } 43 | -------------------------------------------------------------------------------- /Resources/Shaders/diffuseshadow.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | uniform mat4 viewMatrix; 4 | 5 | uniform vec3 lightPosition; 6 | uniform vec3 lightIntensity; 7 | 8 | //material data 9 | uniform vec3 ambient; 10 | uniform vec3 specular; 11 | uniform float shininess; 12 | uniform float opacity; 13 | 14 | uniform sampler2D diffuseTexture; 15 | uniform sampler2DShadow shadowMapTexture; 16 | 17 | in vec4 positionInLightSpace; 18 | 19 | in vec3 position; 20 | in vec3 normal; 21 | in vec2 texCoord; 22 | 23 | out vec4 fragColor; 24 | 25 | vec3 dModel(const in vec2 flipYTexCoord) 26 | { 27 | vec3 s = normalize(vec3(viewMatrix * vec4(lightPosition, 1.0)) - position); 28 | vec3 v = normalize(-position); 29 | vec3 r = reflect(-s, normal); 30 | float diffuse = max(dot(s, normal), 0.0); 31 | float specularValue = 0.0; 32 | 33 | if (dot(s, normal) > 0.0) 34 | specularValue = (shininess / (8.0 * 3.14)) * pow(max(dot(r, v), 0.0), shininess); 35 | 36 | vec3 diffuseColor = texture2D(diffuseTexture, flipYTexCoord).rgb; 37 | 38 | return lightIntensity * ((ambient + diffuse) * diffuseColor + specularValue * specular); 39 | } 40 | 41 | void main() 42 | { 43 | vec2 flipYTexCoord = texCoord; 44 | flipYTexCoord.y = 1.0 - texCoord.y; 45 | 46 | float shadowMapSample = textureProj(shadowMapTexture, positionInLightSpace); 47 | 48 | vec3 result = lightIntensity * ambient * texture2D(diffuseTexture, flipYTexCoord).rgb; 49 | if (shadowMapSample > 0) 50 | result += dModel(flipYTexCoord); 51 | 52 | float alpha = opacity * texture2D(diffuseTexture, flipYTexCoord).a; 53 | 54 | fragColor = vec4(result, alpha); 55 | } 56 | -------------------------------------------------------------------------------- /Resources/Shaders/diffuseshadow.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | in vec3 vertexPosition; 4 | in vec3 vertexNormal; 5 | in vec2 vertexTexCoord; 6 | 7 | out vec4 positionInLightSpace; 8 | out vec3 position; 9 | out vec3 normal; 10 | out vec2 texCoord; 11 | 12 | uniform mat4 lightViewProjection; 13 | uniform mat4 modelMatrix; 14 | uniform mat4 modelView; 15 | uniform mat3 modelViewNormal; 16 | uniform mat4 mvp; 17 | uniform float texCoordScale; 18 | 19 | void main() 20 | { 21 | const mat4 shadowMatrix = mat4(0.5, 0.0, 0.0, 0.0, 22 | 0.0, 0.5, 0.0, 0.0, 23 | 0.0, 0.0, 0.5, 0.0, 24 | 0.5, 0.5, 0.5, 1.0); 25 | 26 | positionInLightSpace = shadowMatrix * lightViewProjection * modelMatrix * vec4(vertexPosition, 1.0); 27 | 28 | texCoord = vertexTexCoord * texCoordScale; 29 | normal = normalize(modelViewNormal * vertexNormal); 30 | position = vec3(modelView * vec4(vertexPosition, 1.0)); 31 | 32 | gl_Position = mvp * vec4(vertexPosition, 1.0); 33 | } 34 | -------------------------------------------------------------------------------- /Resources/Shaders/shadowmap.frag: -------------------------------------------------------------------------------- 1 | #version 150 core 2 | 3 | out float fragmentdepth; 4 | 5 | void main() 6 | { 7 | fragmentdepth = gl_FragCoord.z; 8 | } 9 | -------------------------------------------------------------------------------- /Resources/Shaders/shadowmap.vert: -------------------------------------------------------------------------------- 1 | #version 150 core 2 | 3 | in vec3 vertex; 4 | uniform mat4 mvp; 5 | 6 | void main(void) 7 | { 8 | gl_Position = mvp * vec4(vertex, 1.0); 9 | } 10 | -------------------------------------------------------------------------------- /Resources/Shaders/skybox.frag: -------------------------------------------------------------------------------- 1 | #version 140 2 | 3 | in vec3 texCoord0; 4 | out vec4 fragColor; 5 | uniform samplerCube skyboxTexture; 6 | 7 | void main() 8 | { 9 | fragColor = texture(skyboxTexture, texCoord0); 10 | } 11 | -------------------------------------------------------------------------------- /Resources/Shaders/skybox.vert: -------------------------------------------------------------------------------- 1 | #version 140 2 | 3 | in vec3 vertexPosition; 4 | out vec3 texCoord0; 5 | 6 | uniform mat4 modelMatrix; 7 | uniform mat4 viewMatrix; 8 | uniform mat4 projectionMatrix; 9 | 10 | void main() 11 | { 12 | texCoord0 = vertexPosition.xyz; 13 | gl_Position = vec4(projectionMatrix * mat4(mat3(viewMatrix)) * modelMatrix * vec4(vertexPosition, 1.0)).xyww; 14 | } 15 | -------------------------------------------------------------------------------- /Resources/Skybox/stars_negx.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Skybox/stars_negx.webp -------------------------------------------------------------------------------- /Resources/Skybox/stars_negy.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Skybox/stars_negy.webp -------------------------------------------------------------------------------- /Resources/Skybox/stars_negz.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Skybox/stars_negz.webp -------------------------------------------------------------------------------- /Resources/Skybox/stars_posx.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Skybox/stars_posx.webp -------------------------------------------------------------------------------- /Resources/Skybox/stars_posy.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Skybox/stars_posy.webp -------------------------------------------------------------------------------- /Resources/Skybox/stars_posz.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/Resources/Skybox/stars_posz.webp -------------------------------------------------------------------------------- /Scene/MaterialObjects/diffuseobject.cpp: -------------------------------------------------------------------------------- 1 | #include "diffuseobject.h" 2 | #include 3 | #include 4 | 5 | SolarSystem::DiffuseObject::DiffuseObject(Qt3DCore::QNode* parent): 6 | Object3D(parent) 7 | { 8 | m_materialType = SolarMaterials::Diffuse; 9 | m_material = new Qt3DExtras::QDiffuseMapMaterial(); 10 | 11 | auto mat = qobject_cast(m_material); 12 | Qt3DRender::QTextureWrapMode wrapMode; 13 | 14 | wrapMode.setX(Qt3DRender::QTextureWrapMode::WrapMode::Repeat); 15 | wrapMode.setY(Qt3DRender::QTextureWrapMode::WrapMode::Repeat); 16 | wrapMode.setZ(Qt3DRender::QTextureWrapMode::WrapMode::Repeat); 17 | 18 | mat->diffuse()->setWrapMode(wrapMode); 19 | mat->diffuse()->setGenerateMipMaps(true); 20 | mat->diffuse()->setMagnificationFilter(Qt3DRender::QAbstractTexture::Linear); 21 | mat->diffuse()->setMinificationFilter(Qt3DRender::QAbstractTexture::LinearMipMapLinear); 22 | mat->diffuse()->setMaximumAnisotropy(16.0f); 23 | 24 | mat->setShininess(10000000); 25 | mat->setSpecular(QColor(qRgba(0,0,0,255))); 26 | mat->setAmbient(QColor(qRgba(10,10,10,255))); 27 | mat->setTextureScale(1.0f); 28 | 29 | addComponent(m_material); 30 | } 31 | -------------------------------------------------------------------------------- /Scene/MaterialObjects/diffuseobject.h: -------------------------------------------------------------------------------- 1 | #ifndef DIFFUSEOBJECT_H 2 | #define DIFFUSEOBJECT_H 3 | 4 | #include 5 | #include 6 | 7 | namespace SolarSystem 8 | { 9 | // represents solar3dobject with diffuse material 10 | class DiffuseObject : public Object3D 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit DiffuseObject(Qt3DCore::QNode* parent = nullptr); 16 | }; 17 | } 18 | 19 | #endif // DIFFUSEOBJECT_H 20 | -------------------------------------------------------------------------------- /Scene/MaterialObjects/normaldiffusealphaobject.cpp: -------------------------------------------------------------------------------- 1 | #include "normaldiffusealphaobject.h" 2 | #include 3 | #include 4 | #include 5 | 6 | SolarSystem::NormalDiffuseAlphaObject::NormalDiffuseAlphaObject(Qt3DCore::QNode* parent): 7 | Object3D(parent) 8 | { 9 | m_materialType = SolarMaterials::NormalDiffuseAplha; 10 | m_material = new Qt3DExtras::QNormalDiffuseMapAlphaMaterial(); 11 | 12 | auto mat = qobject_cast(m_material); 13 | Qt3DRender::QTextureWrapMode wrapMode; 14 | 15 | mat->diffuse()->setWrapMode(wrapMode); 16 | mat->diffuse()->setGenerateMipMaps(true); 17 | mat->diffuse()->setMagnificationFilter(Qt3DRender::QAbstractTexture::Linear); 18 | mat->diffuse()->setMinificationFilter(Qt3DRender::QAbstractTexture::LinearMipMapLinear); 19 | mat->diffuse()->setMaximumAnisotropy(16.0f); 20 | 21 | mat->normal()->setWrapMode(wrapMode); 22 | mat->normal()->setMagnificationFilter(Qt3DRender::QAbstractTexture::Linear); 23 | mat->normal()->setMinificationFilter(Qt3DRender::QAbstractTexture::Linear); 24 | mat->normal()->setMaximumAnisotropy(16.0f); 25 | 26 | mat->setShininess(0); 27 | mat->setSpecular(QColor(qRgba(0,0,0,255))); 28 | mat->setAmbient(QColor(qRgba(10,10,10,255))); 29 | mat->setTextureScale(1.0f); 30 | 31 | m_picker->setEnabled(false); 32 | 33 | addComponent(m_material); 34 | } 35 | -------------------------------------------------------------------------------- /Scene/MaterialObjects/normaldiffusealphaobject.h: -------------------------------------------------------------------------------- 1 | #ifndef NORMALDIFFUSEALPHAOBJECT_H 2 | #define NORMALDIFFUSEALPHAOBJECT_H 3 | 4 | #include 5 | #include 6 | 7 | namespace SolarSystem 8 | { 9 | // represents solar3dobject with normal diffuse alpha material 10 | class NormalDiffuseAlphaObject : public Object3D 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit NormalDiffuseAlphaObject(Qt3DCore::QNode* parent = nullptr); 16 | }; 17 | } 18 | 19 | #endif // NORMALDIFFUSEALPHAOBJECT_H 20 | -------------------------------------------------------------------------------- /Scene/MaterialObjects/normaldiffuseobject.cpp: -------------------------------------------------------------------------------- 1 | #include "normaldiffuseobject.h" 2 | #include 3 | #include 4 | 5 | SolarSystem::NormalDiffuseObject::NormalDiffuseObject(Qt3DCore::QNode* parent): 6 | Object3D(parent) 7 | { 8 | m_materialType = SolarMaterials::NormalDiffuse; 9 | m_material = new Qt3DExtras::QNormalDiffuseMapMaterial(); 10 | 11 | auto mat = qobject_cast(m_material); 12 | Qt3DRender::QTextureWrapMode wrapMode; 13 | 14 | mat->diffuse()->setWrapMode(wrapMode); 15 | mat->diffuse()->setGenerateMipMaps(true); 16 | mat->diffuse()->setMagnificationFilter(Qt3DRender::QAbstractTexture::Linear); 17 | mat->diffuse()->setMinificationFilter(Qt3DRender::QAbstractTexture::LinearMipMapLinear); 18 | mat->diffuse()->setMaximumAnisotropy(16.0f); 19 | 20 | mat->normal()->setWrapMode(wrapMode); 21 | mat->normal()->setMagnificationFilter(Qt3DRender::QAbstractTexture::Linear); 22 | mat->normal()->setMinificationFilter(Qt3DRender::QAbstractTexture::Linear); 23 | mat->normal()->setMaximumAnisotropy(16.0f); 24 | 25 | addComponent(m_material); 26 | } 27 | -------------------------------------------------------------------------------- /Scene/MaterialObjects/normaldiffuseobject.h: -------------------------------------------------------------------------------- 1 | #ifndef NORMALDIFFUSEOBJECT_H 2 | #define NORMALDIFFUSEOBJECT_H 3 | 4 | #include 5 | #include 6 | 7 | namespace SolarSystem 8 | { 9 | // solar 3d object with normal diffuse map material 10 | class NormalDiffuseObject : public Object3D 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit NormalDiffuseObject(Qt3DCore::QNode* parent = nullptr); 16 | }; 17 | } 18 | 19 | #endif // NORMALDIFFUSEOBJECT_H 20 | -------------------------------------------------------------------------------- /Scene/MaterialObjects/unlitobject.cpp: -------------------------------------------------------------------------------- 1 | #include "unlitobject.h" 2 | #include 3 | #include 4 | #include 5 | 6 | SolarSystem::UnlitObject::UnlitObject(Qt3DCore::QNode* parent): 7 | Object3D(parent) 8 | { 9 | m_materialType = SolarMaterials::Unlit; 10 | m_material = new Qt3DExtras::QTextureMaterial(); 11 | 12 | auto mat = qobject_cast(m_material); 13 | Qt3DRender::QTextureWrapMode wrapMode; 14 | 15 | wrapMode.setX(Qt3DRender::QTextureWrapMode::WrapMode::Repeat); 16 | wrapMode.setY(Qt3DRender::QTextureWrapMode::WrapMode::Repeat); 17 | wrapMode.setZ(Qt3DRender::QTextureWrapMode::WrapMode::Repeat); 18 | 19 | mat->texture()->setWrapMode(wrapMode); 20 | mat->texture()->setGenerateMipMaps(true); 21 | mat->texture()->setMagnificationFilter(Qt3DRender::QAbstractTexture::Linear); 22 | mat->texture()->setMinificationFilter(Qt3DRender::QAbstractTexture::LinearMipMapLinear); 23 | mat->texture()->setMaximumAnisotropy(16.0f); 24 | 25 | m_picker->setEnabled(false); 26 | 27 | addComponent(m_material); 28 | } 29 | -------------------------------------------------------------------------------- /Scene/MaterialObjects/unlitobject.h: -------------------------------------------------------------------------------- 1 | #ifndef UNLITOBJECT_H 2 | #define UNLITOBJECT_H 3 | 4 | #include 5 | #include 6 | 7 | namespace SolarSystem 8 | { 9 | // represents solar 3d object with unlit material 10 | class UnlitObject : public Object3D 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit UnlitObject(Qt3DCore::QNode* parent = nullptr); 16 | }; 17 | } 18 | 19 | #endif // UNLITOBJECT_H 20 | -------------------------------------------------------------------------------- /Scene/SceneObjects/earthcloud.cpp: -------------------------------------------------------------------------------- 1 | #include "earthcloud.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | SolarSystem::EarthCloud::EarthCloud(Qt3DCore::QNode* parent): 9 | NormalDiffuseAlphaObject(parent) 10 | { 11 | m_renderer = new Qt3DRender::QGeometryRenderer(this); 12 | addComponent(m_renderer); 13 | 14 | auto sphereGeometry = new Qt3DExtras::QSphereGeometry(); 15 | 16 | sphereGeometry->setRadius(PlanetSettings::radius); 17 | sphereGeometry->setGenerateTangents(PlanetSettings::generateTangents); 18 | sphereGeometry->setRings(PlanetSettings::rings); 19 | sphereGeometry->setSlices(PlanetSettings::slices); 20 | 21 | m_renderer->setGeometry(sphereGeometry); 22 | 23 | Qt3DExtras::QNormalDiffuseMapAlphaMaterial* mat = qobject_cast(m_material); 24 | 25 | Qt3DRender::QTextureImage* diffuseMap = new Qt3DRender::QTextureImage(); 26 | diffuseMap->setSource(QUrl::fromLocalFile(":/Resources/Images/earthcloudmapcolortrans.png")); 27 | mat->diffuse()->addTextureImage(diffuseMap); 28 | 29 | Qt3DRender::QTextureImage* normalMap = new Qt3DRender::QTextureImage(); 30 | normalMap->setSource(QUrl::fromLocalFile(":/Resources/Images/earthcloudmapcolortransnormal.png")); 31 | mat->normal()->addTextureImage(normalMap); 32 | 33 | mat->setShininess(100000.0f); 34 | } 35 | -------------------------------------------------------------------------------- /Scene/SceneObjects/earthcloud.h: -------------------------------------------------------------------------------- 1 | #ifndef EARTHCLOUD_H 2 | #define EARTHCLOUD_H 3 | 4 | #include 5 | #include 6 | 7 | namespace SolarSystem 8 | { 9 | // represents earth cloud mesh 10 | class EarthCloud : public NormalDiffuseAlphaObject 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit EarthCloud(Qt3DCore::QNode* parent = nullptr); 16 | }; 17 | } 18 | 19 | #endif // EARTHCLOUD_H 20 | -------------------------------------------------------------------------------- /Scene/SceneObjects/emptysolarobject.cpp: -------------------------------------------------------------------------------- 1 | #include "emptysolarobject.h" 2 | 3 | SolarSystem::EmptySolarObject::EmptySolarObject(Qt3DCore::QNode* parent): 4 | Object3D(parent) 5 | { 6 | } 7 | 8 | void SolarSystem::EmptySolarObject::update(float deltaTime) 9 | { 10 | Q_UNUSED(deltaTime) 11 | 12 | //do anything we want 13 | //... 14 | } 15 | -------------------------------------------------------------------------------- /Scene/SceneObjects/emptysolarobject.h: -------------------------------------------------------------------------------- 1 | #ifndef EMPTYSOLAROBJECT_H 2 | #define EMPTYSOLAROBJECT_H 3 | 4 | #include 5 | 6 | namespace SolarSystem 7 | { 8 | // empty object can be placed on the scene without any rendering, but with some interesting features 9 | class EmptySolarObject: public Object3D 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | explicit EmptySolarObject(Qt3DCore::QNode* parent = nullptr); 15 | 16 | protected: 17 | virtual void update(float deltaTime) override; 18 | }; 19 | } 20 | 21 | #endif // EMPTYSOLAROBJECT_H 22 | -------------------------------------------------------------------------------- /Scene/SceneObjects/planet.cpp: -------------------------------------------------------------------------------- 1 | #include "planet.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | SolarSystem::Planet::Planet(Qt3DCore::QNode *parent): 8 | NormalDiffuseObject(parent) 9 | { 10 | m_renderer = new Qt3DRender::QGeometryRenderer(this); 11 | addComponent(m_renderer); 12 | 13 | auto sphereGeometry = new Qt3DExtras::QSphereGeometry(this); 14 | 15 | //setup geometry 16 | sphereGeometry->setRadius(PlanetSettings::radius); 17 | sphereGeometry->setGenerateTangents(PlanetSettings::generateTangents); 18 | sphereGeometry->setRings(PlanetSettings::rings); 19 | sphereGeometry->setSlices(PlanetSettings::slices); 20 | 21 | m_renderer->setGeometry(sphereGeometry); 22 | } 23 | -------------------------------------------------------------------------------- /Scene/SceneObjects/planet.h: -------------------------------------------------------------------------------- 1 | #ifndef PLANET_H 2 | #define PLANET_H 3 | 4 | #include 5 | 6 | namespace SolarSystem 7 | { 8 | // base class for solar planets 9 | class Planet : public NormalDiffuseObject 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | explicit Planet(Qt3DCore::QNode* parent = nullptr); 15 | }; 16 | } 17 | 18 | #endif // PLANET_H 19 | -------------------------------------------------------------------------------- /Scene/SceneObjects/planetring.cpp: -------------------------------------------------------------------------------- 1 | #include "planetring.h" 2 | #include 3 | #include 4 | #include 5 | 6 | SolarSystem::PlanetRing::PlanetRing(Qt3DCore::QNode* parent): 7 | NormalDiffuseAlphaObject(parent) 8 | { 9 | auto mesh = new Qt3DRender::QMesh(this); 10 | m_renderer = mesh; 11 | addComponent(m_renderer); 12 | 13 | mesh->setSource(QUrl::fromLocalFile(":/Resources/Meshes/ring.obj")); 14 | } 15 | -------------------------------------------------------------------------------- /Scene/SceneObjects/planetring.h: -------------------------------------------------------------------------------- 1 | #ifndef PLANETRING_H 2 | #define PLANETRING_H 3 | 4 | #include 5 | 6 | namespace SolarSystem 7 | { 8 | // represents a planet ring, for example saturn and uranus rings 9 | class PlanetRing : public NormalDiffuseAlphaObject 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | explicit PlanetRing(Qt3DCore::QNode* parent = nullptr); 15 | }; 16 | } 17 | 18 | #endif // PLANETRING_H 19 | -------------------------------------------------------------------------------- /Scene/SceneObjects/solarskybox.cpp: -------------------------------------------------------------------------------- 1 | #include "solarskybox.h" 2 | 3 | SolarSystem::SolarSkyBox::SolarSkyBox(Qt3DCore::QNode* parent): 4 | QSkyboxEntity(parent) 5 | { 6 | //create skybox from file 7 | setBaseName(QStringLiteral("qrc:/Resources/Skybox/stars")); 8 | setExtension(QStringLiteral(".webp")); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /Scene/SceneObjects/solarskybox.h: -------------------------------------------------------------------------------- 1 | #ifndef SOLARSKYBOX_H 2 | #define SOLARSKYBOX_H 3 | 4 | #include 5 | #include 6 | 7 | namespace SolarSystem 8 | { 9 | // represents space 10 | class SolarSkyBox : public Qt3DExtras::QSkyboxEntity 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit SolarSkyBox(Qt3DCore::QNode* parent = nullptr); 16 | }; 17 | } 18 | 19 | #endif // SOLARSKYBOX_H 20 | -------------------------------------------------------------------------------- /Scene/SceneObjects/sun.cpp: -------------------------------------------------------------------------------- 1 | #include "sun.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | SolarSystem::Sun::Sun(Qt3DCore::QNode* parent): 10 | UnlitObject(parent) 11 | { 12 | m_renderer = new Qt3DRender::QGeometryRenderer(this); 13 | addComponent(m_renderer); 14 | 15 | auto sphereGeometry = new Qt3DExtras::QSphereGeometry(this); 16 | 17 | //setup geometry 18 | sphereGeometry->setRadius(PlanetSettings::radius); 19 | sphereGeometry->setGenerateTangents(PlanetSettings::generateTangents); 20 | sphereGeometry->setRings(PlanetSettings::rings); 21 | sphereGeometry->setSlices(PlanetSettings::slices); 22 | 23 | m_renderer->setGeometry(sphereGeometry); 24 | 25 | auto sunLight = new Qt3DRender::QPointLight(); 26 | sunLight->setIntensity(1.35f); 27 | 28 | addComponent(sunLight); 29 | setObjectName(SolarObjectsValues::Sun::toString); 30 | 31 | auto mat = qobject_cast(m_material); 32 | 33 | // sun diffuse 34 | Qt3DRender::QTextureImage* sunDiffuse = new Qt3DRender::QTextureImage(); 35 | sunDiffuse->setSource(QUrl::fromLocalFile(":/Resources/Images/sun_map.jpg")); 36 | mat->texture()->addTextureImage(sunDiffuse); 37 | 38 | setTilt(SolarObjectsValues::Sun::tilt); 39 | } 40 | -------------------------------------------------------------------------------- /Scene/SceneObjects/sun.h: -------------------------------------------------------------------------------- 1 | #ifndef SUN_H 2 | #define SUN_H 3 | 4 | #include 5 | 6 | namespace SolarSystem 7 | { 8 | // represents sun with diffuse material 9 | class Sun final : public UnlitObject 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | explicit Sun(Qt3DCore::QNode* parent = nullptr); 15 | }; 16 | } 17 | 18 | #endif // SUN_H 19 | -------------------------------------------------------------------------------- /Scene/fpscounter.cpp: -------------------------------------------------------------------------------- 1 | #include "fpscounter.h" 2 | #include 3 | 4 | struct SolarSystem::FpsCounter::FpsData 5 | { 6 | Qt3DLogic::QFrameAction* action = nullptr; 7 | 8 | int frameCount = 0; 9 | float dt = 0; 10 | float fps = 0; 11 | float updateRate = 1.0f; 12 | }; 13 | 14 | SolarSystem::FpsCounter::FpsCounter(Qt3DCore::QNode* parent): 15 | QEntity(parent), 16 | m_data(new FpsData()) 17 | { 18 | m_data->action = new Qt3DLogic::QFrameAction(this); 19 | addComponent(m_data->action); 20 | 21 | QObject::connect(m_data->action, &Qt3DLogic::QFrameAction::triggered, [&](float dt){ 22 | 23 | ++m_data->frameCount; 24 | m_data->dt += dt; 25 | 26 | if (m_data->dt > (1.0f / m_data->updateRate)) 27 | { 28 | m_data->fps = m_data->frameCount / m_data->dt; 29 | m_data->frameCount = 0; 30 | m_data->dt -= 1.0f/ m_data->updateRate; 31 | 32 | emit fpsChanged(static_cast(m_data->fps)); 33 | } 34 | }); 35 | } 36 | 37 | SolarSystem::FpsCounter::~FpsCounter() 38 | { 39 | delete m_data; 40 | } 41 | 42 | int SolarSystem::FpsCounter::fps() const 43 | { 44 | return static_cast(m_data->fps); 45 | } 46 | -------------------------------------------------------------------------------- /Scene/fpscounter.h: -------------------------------------------------------------------------------- 1 | #ifndef FPSCOUNTER_H 2 | #define FPSCOUNTER_H 3 | 4 | #include 5 | 6 | namespace SolarSystem 7 | { 8 | /// caclcualtes fps 9 | class FpsCounter : public Qt3DCore::QEntity 10 | { 11 | Q_OBJECT 12 | 13 | Q_PROPERTY(int fps READ fps NOTIFY fpsChanged) 14 | 15 | public: 16 | explicit FpsCounter(Qt3DCore::QNode* parent = nullptr); 17 | virtual ~FpsCounter(); 18 | 19 | /// returns fps value 20 | int fps() const; 21 | 22 | private: 23 | struct FpsData; 24 | FpsData* m_data; 25 | 26 | signals: 27 | 28 | /// fps can be read 29 | void fpsChanged(int fps); 30 | }; 31 | } 32 | 33 | #endif // FPSCOUNTER_H 34 | -------------------------------------------------------------------------------- /Scene/object3d.cpp: -------------------------------------------------------------------------------- 1 | #include "object3d.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | SolarSystem::Object3D::Object3D(Qt3DCore::QNode* parent): 10 | QEntity(parent) 11 | { 12 | m_frameAction = new Qt3DLogic::QFrameAction(this); 13 | m_transform = new Qt3DCore::QTransform(this); 14 | m_picker = new Qt3DRender::QObjectPicker(this); 15 | 16 | m_picker->setDragEnabled(false); 17 | m_picker->setEnabled(true); 18 | 19 | addComponent(m_frameAction); 20 | addComponent(m_transform); 21 | addComponent(m_picker); 22 | 23 | QObject::connect(m_frameAction, &Qt3DLogic::QFrameAction::triggered, this, [this](float deltaTime) { 24 | 25 | //additional actions 26 | for (const auto& elem : m_logic) 27 | elem(deltaTime); 28 | 29 | update(deltaTime); 30 | 31 | }); 32 | } 33 | 34 | void SolarSystem::Object3D::update(float deltaTime) 35 | { 36 | Q_UNUSED(deltaTime) 37 | baseBehaviour(); 38 | } 39 | 40 | void SolarSystem::Object3D::addLogic(SolarSystem::LogicPtr func) 41 | { 42 | m_logic.push_back(func); 43 | } 44 | 45 | void SolarSystem::Object3D::clearLogic() 46 | { 47 | m_logic.clear(); 48 | } 49 | 50 | Qt3DCore::QTransform* SolarSystem::Object3D::transform() const 51 | { 52 | return m_transform; 53 | } 54 | 55 | Qt3DRender::QGeometryRenderer* SolarSystem::Object3D::renderer() const 56 | { 57 | return m_renderer; 58 | } 59 | 60 | Qt3DRender::QObjectPicker* SolarSystem::Object3D::picker() const 61 | { 62 | return m_picker; 63 | } 64 | 65 | Qt3DRender::QMaterial* SolarSystem::Object3D::material() const 66 | { 67 | return m_material; 68 | } 69 | 70 | SolarSystem::SolarObjects SolarSystem::Object3D::solarType() const 71 | { 72 | return m_solarType; 73 | } 74 | 75 | void SolarSystem::Object3D::setSolarType(SolarSystem::SolarObjects type) 76 | { 77 | m_solarType = type; 78 | } 79 | 80 | SolarSystem::SolarMaterials SolarSystem::Object3D::materialType() const 81 | { 82 | return m_materialType; 83 | } 84 | 85 | double SolarSystem::Object3D::r() const 86 | { 87 | return m_r; 88 | } 89 | 90 | void SolarSystem::Object3D::setR(double r) 91 | { 92 | m_r = r; 93 | } 94 | 95 | double SolarSystem::Object3D::x() const 96 | { 97 | return m_x; 98 | } 99 | 100 | void SolarSystem::Object3D::setX(double x) 101 | { 102 | m_x = x; 103 | } 104 | 105 | double SolarSystem::Object3D::y() const 106 | { 107 | return m_y; 108 | } 109 | 110 | void SolarSystem::Object3D::setY(double y) 111 | { 112 | m_y = y; 113 | } 114 | 115 | double SolarSystem::Object3D::z() const 116 | { 117 | return m_z; 118 | } 119 | 120 | void SolarSystem::Object3D::setZ(double z) 121 | { 122 | m_z = z; 123 | } 124 | 125 | double SolarSystem::Object3D::roll() const 126 | { 127 | return m_roll; 128 | } 129 | 130 | void SolarSystem::Object3D::setRoll(double roll) 131 | { 132 | m_roll = roll; 133 | } 134 | 135 | double SolarSystem::Object3D::tilt() const 136 | { 137 | return m_tilt; 138 | } 139 | 140 | void SolarSystem::Object3D::setTilt(double tilt) 141 | { 142 | m_tilt = tilt; 143 | } 144 | 145 | QVector3D SolarSystem::Object3D::position() const 146 | { 147 | return QVector3D(static_cast(m_x), static_cast(m_y), static_cast(m_z)); 148 | } 149 | 150 | void SolarSystem::Object3D::baseBehaviour() 151 | { 152 | auto matrix = QMatrix4x4(); 153 | 154 | matrix.translate(position()); 155 | 156 | matrix.rotate(static_cast(m_tilt), SolarValues::tiltAxis); 157 | matrix.rotate(static_cast(m_roll), SolarValues::rollAxis); 158 | 159 | matrix.scale(static_cast(m_r)); 160 | 161 | m_transform->setMatrix(matrix); 162 | } 163 | -------------------------------------------------------------------------------- /Scene/object3d.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJECT3D_H 2 | #define OBJECT3D_H 3 | 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | 10 | namespace Qt3DCore 11 | { 12 | class QTransform; 13 | } 14 | 15 | namespace Qt3DLogic 16 | { 17 | class QFrameAction; 18 | } 19 | 20 | namespace Qt3DRender 21 | { 22 | class QGeometryRenderer; 23 | class QObjectPicker; 24 | class QMaterial; 25 | } 26 | 27 | namespace SolarSystem 28 | { 29 | using LogicPtr = std::function; 30 | using Logic = std::vector; 31 | 32 | /// base visual object on the scene 33 | class Object3D : public Qt3DCore::QEntity 34 | { 35 | Q_OBJECT 36 | 37 | public: 38 | explicit Object3D(Qt3DCore::QNode* parent = nullptr); 39 | 40 | protected: 41 | 42 | // frame tick for solar object logic programming 43 | virtual void update(float deltaTime); 44 | 45 | void setMaterialType(SolarMaterials material); 46 | 47 | public: 48 | 49 | // logic 50 | void addLogic(LogicPtr func); 51 | void clearLogic(); 52 | 53 | Qt3DCore::QTransform* transform() const; 54 | Qt3DRender::QGeometryRenderer* renderer() const; 55 | Qt3DRender::QObjectPicker* picker() const; 56 | Qt3DRender::QMaterial* material() const; 57 | 58 | // returns current object type 59 | SolarObjects solarType() const; 60 | void setSolarType(SolarObjects type); 61 | 62 | // returns object material type 63 | SolarMaterials materialType() const; 64 | 65 | double r() const; 66 | void setR(double r); 67 | 68 | double x() const; 69 | void setX(double x); 70 | 71 | double y() const; 72 | void setY(double y); 73 | 74 | double z() const; 75 | void setZ(double z); 76 | 77 | double roll() const; 78 | void setRoll(double roll); 79 | 80 | double tilt() const; 81 | void setTilt(double tilt); 82 | 83 | QVector3D position() const; 84 | 85 | protected: 86 | void baseBehaviour(); 87 | 88 | // logical 89 | SolarSystem::Logic m_logic; 90 | Qt3DLogic::QFrameAction* m_frameAction; 91 | Qt3DRender::QObjectPicker* m_picker; 92 | 93 | // Qt3D components 94 | Qt3DCore::QTransform* m_transform; 95 | Qt3DRender::QGeometryRenderer* m_renderer; 96 | Qt3DRender::QMaterial* m_material; 97 | 98 | // main data 99 | SolarSystem::SolarObjects m_solarType; 100 | SolarSystem::SolarMaterials m_materialType = SolarMaterials::None; 101 | 102 | double m_r = 0; 103 | double m_x = 0; 104 | double m_y = 0; 105 | double m_z = 0; 106 | double m_roll = 0; 107 | double m_tilt = 0; 108 | }; 109 | } 110 | 111 | #endif // OBJECT3D_H 112 | -------------------------------------------------------------------------------- /Scene/solarentity.cpp: -------------------------------------------------------------------------------- 1 | #include "solarentity.h" 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | SolarSystem::SolarEntity::SolarEntity(QNode* parent): 17 | Qt3DCore::QEntity(parent), 18 | m_rootAction(new Qt3DLogic::QFrameAction()), 19 | m_object3DContainer(new Object3DContainer(this)), 20 | m_fpsCounter(new FpsCounter(this)) 21 | { 22 | DBConnector::instance(); 23 | 24 | addComponent(m_rootAction); 25 | 26 | // scene camera setup 27 | m_camera = new Qt3DRender::QCamera(this); 28 | m_camera->setProjectionType(Qt3DRender::QCameraLens::PerspectiveProjection); 29 | m_camera->setViewCenter(QVector3D(0.0f, 3.5f, 0.0f)); 30 | 31 | m_camera->setFieldOfView(CameraSettings::fieldOfView); 32 | m_camera->setNearPlane(CameraSettings::nearPlane * 0.0001f); 33 | m_camera->setFarPlane(CameraSettings::farPlane); 34 | m_camera->setUpVector(CameraSettings::defaultUp); 35 | m_camera->setPosition(CameraSettings::defaultCameraPosition); 36 | 37 | // orbit camera controller 38 | auto controller = new SolarSystem::CameraController(this); 39 | controller->setCamera(m_camera); 40 | controller->setLookSpeed(controller->lookSpeed() * 1.2f); 41 | 42 | // owned by entity 43 | new SolarSkyBox(this); 44 | 45 | // frame graph 46 | m_frameGraph = new SolarStandardFrameGraph(this); 47 | m_frameGraph->setCamera(m_camera); 48 | 49 | m_inputSettings = new Qt3DInput::QInputSettings(); 50 | 51 | addComponent(m_frameGraph); 52 | addComponent(m_inputSettings); 53 | 54 | // math core control 55 | MathCore::instance()->setObject3DContainer(m_object3DContainer); 56 | MathCore::instance()->setCamera(m_camera); 57 | MathCore::instance()->setCameraController(controller); 58 | MathCore::instance()->setSolarSystemSpeed(SolarSystem::SolarValues::startSpeed); 59 | MathCore::instance()->changeSolarSystemScale(SolarSystem::SolarValues::startSize); 60 | 61 | m_animator = new Animator(this); 62 | 63 | QObject::connect(m_rootAction, &Qt3DLogic::QFrameAction::triggered, m_animator, &Animator::animate); 64 | QObject::connect(MathCore::instance(), &MathCore::solarTimeChanged, this, &SolarEntity::timeChanged); 65 | QObject::connect(m_animator, &Animator::currentObjectChanged, this, &SolarEntity::onAnimatedObjectChanged); 66 | } 67 | 68 | Qt3DRender::QCamera* SolarSystem::SolarEntity::camera() const 69 | { 70 | return m_camera; 71 | } 72 | 73 | SolarSystem::FpsCounter* SolarSystem::SolarEntity::counter() const 74 | { 75 | return m_fpsCounter; 76 | } 77 | 78 | bool SolarSystem::SolarEntity::databaseStatus() const 79 | { 80 | return DBConnector::instance().status() && DBConnector::instance().isOpen(); 81 | } 82 | 83 | QDateTime SolarSystem::SolarEntity::time() const 84 | { 85 | return MathCore::instance()->getTime(); 86 | } 87 | 88 | QString SolarSystem::SolarEntity::currentObjectString() const 89 | { 90 | return SolarParser::parseSolarObjectToString(m_animator->currentObject()); 91 | } 92 | 93 | QString SolarSystem::SolarEntity::info() const 94 | { 95 | auto columnNames = DBConnector::instance().columnNames(); 96 | auto objParameters = DBConnector::instance().info(m_animator->currentObject()); 97 | auto dbFieldsParamsCount = DbParams::paramList.size(); 98 | auto str = QString(); 99 | 100 | if (columnNames.size() != objParameters.size() || columnNames.size() != dbFieldsParamsCount 101 | || dbFieldsParamsCount != objParameters.size()) 102 | { 103 | qDebug() << "Something wrong in DB connector"; 104 | qDebug() << columnNames.size() << " != " << objParameters.size(); 105 | 106 | return str; 107 | } 108 | 109 | // fill info sheet 110 | for (int i = 0; i < columnNames.size(); ++i) 111 | str.append(columnNames[i] + ": " + objParameters[i] + " " + DbParams::paramList[i] + "\n\n"); 112 | 113 | return str; 114 | } 115 | 116 | double SolarSystem::SolarEntity::extraSpeed() const 117 | { 118 | return MathCore::instance()->extraSpeed(); 119 | } 120 | 121 | bool SolarSystem::SolarEntity::isAnimated() const 122 | { 123 | return m_animator->isAnimated(); 124 | } 125 | 126 | void SolarSystem::SolarEntity::setCameraControllerEnabled(bool state) 127 | { 128 | MathCore::instance()->cameraController()->setEnabled(state); 129 | } 130 | 131 | void SolarSystem::SolarEntity::zoomCamera(float value) 132 | { 133 | MathCore::instance()->cameraController()->touchZoom(value); 134 | } 135 | 136 | void SolarSystem::SolarEntity::setSolarSpeed(int value) 137 | { 138 | auto coeff = 0.02f * value; 139 | MathCore::instance()->setSolarSystemSpeed(SolarValues::startSpeed * coeff); 140 | } 141 | 142 | void SolarSystem::SolarEntity::setSolarSize(int value) 143 | { 144 | float coeff = value/50.0f; 145 | MathCore::instance()->changeSolarSystemScale(SolarValues::startSize * coeff); 146 | } 147 | 148 | void SolarSystem::SolarEntity::setViewCenter(int index) 149 | { 150 | auto object = SolarParser::parsePlanetListIndex(index); 151 | m_animator->animateCamera(object); 152 | } 153 | 154 | void SolarSystem::SolarEntity::setEventSource(QObject* object) 155 | { 156 | m_inputSettings->setEventSource(object); 157 | } 158 | 159 | void SolarSystem::SolarEntity::changeExtraSpeed() 160 | { 161 | MathCore::instance()->changeExtraSpeed(); 162 | emit extraSpeedChanged(MathCore::instance()->extraSpeed()); 163 | } 164 | 165 | void SolarSystem::SolarEntity::resetExtraSpeed() 166 | { 167 | MathCore::instance()->resetExtraSpeed(); 168 | emit extraSpeedChanged(MathCore::instance()->extraSpeed()); 169 | } 170 | 171 | void SolarSystem::SolarEntity::onAnimatedObjectChanged(SolarSystem::SolarObjects object) 172 | { 173 | emit currentObjectStringChanged(SolarParser::parseSolarObjectToString(object)); 174 | } 175 | -------------------------------------------------------------------------------- /Scene/solarentity.h: -------------------------------------------------------------------------------- 1 | #ifndef SOLARENTITY_H 2 | #define SOLARENTITY_H 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | #include 15 | 16 | #include 17 | 18 | namespace SolarSystem 19 | { 20 | class Object3DContainer; 21 | class Animator; 22 | class IFrameGraph; 23 | 24 | // represents chain of solar objects (root entity), 25 | // mediator for objects and QML/C++ code connector 26 | class SolarEntity : public Qt3DCore::QEntity 27 | { 28 | Q_OBJECT 29 | 30 | Q_PROPERTY(FpsCounter* counter READ counter) 31 | 32 | Q_PROPERTY(QString currentObjectString READ currentObjectString NOTIFY currentObjectStringChanged) 33 | Q_PROPERTY(double extraSpeed READ extraSpeed NOTIFY extraSpeedChanged) 34 | Q_PROPERTY(QDateTime time READ time NOTIFY timeChanged) 35 | Q_PROPERTY(bool databaseStatus READ databaseStatus) 36 | Q_PROPERTY(QString info READ info) 37 | 38 | public: 39 | explicit SolarEntity(QNode* parent = nullptr); 40 | ~SolarEntity() = default; 41 | 42 | Qt3DRender::QCamera* camera() const; 43 | FpsCounter* counter() const; 44 | bool databaseStatus() const; 45 | 46 | QDateTime time() const; 47 | QString currentObjectString() const; 48 | QString info() const; 49 | double extraSpeed() const; 50 | 51 | // mobile touch support by QML 52 | Q_INVOKABLE bool isAnimated() const; 53 | Q_INVOKABLE void setCameraControllerEnabled(bool state); 54 | Q_INVOKABLE void zoomCamera(float value); 55 | 56 | signals: 57 | void timeChanged(const QDateTime&); 58 | void currentObjectStringChanged(const QString&); 59 | void extraSpeedChanged(double); 60 | 61 | public slots: 62 | 63 | // sets current solar speed, in percents 64 | void setSolarSpeed(int value); 65 | 66 | // sets current planets size, in percents 67 | void setSolarSize(int value); 68 | 69 | // sets camera view center by ui planet index 70 | void setViewCenter(int index); 71 | 72 | // sets event source to qt3d input settings 73 | void setEventSource(QObject* object); 74 | 75 | void changeExtraSpeed(); 76 | void resetExtraSpeed(); 77 | 78 | private slots: 79 | void onAnimatedObjectChanged(SolarObjects object); 80 | 81 | private: 82 | Qt3DRender::QCamera* m_camera; 83 | Qt3DLogic::QFrameAction* m_rootAction; 84 | Qt3DInput::QInputSettings* m_inputSettings; 85 | 86 | Object3DContainer* m_object3DContainer; 87 | Animator* m_animator; 88 | FpsCounter* m_fpsCounter; 89 | IFrameGraph* m_frameGraph; 90 | }; 91 | } 92 | 93 | #endif // SOLARENTITY_H 94 | -------------------------------------------------------------------------------- /UI/quickui.cpp: -------------------------------------------------------------------------------- 1 | #include "quickui.h" 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | SolarSystem::QuickUi::QuickUi(QObject* parent): 10 | QObject(parent) 11 | { 12 | qmlRegisterType("SolarSystem", 1, 0, "SolarEntity"); 13 | 14 | qmlRegisterSingletonType("SolarSystem.Utils", 1, 0, "Utils", SolarSystem::utilsProvider); 15 | qmlRegisterSingletonType("SolarSystem.InfoLoader", 1, 0, "InfoLoader", SolarSystem::infoLoaderProvider); 16 | 17 | if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) 18 | { 19 | m_format.setVersion(4, 0); 20 | m_format.setProfile(QSurfaceFormat::CoreProfile); 21 | } 22 | 23 | m_format.setDepthBufferSize(24); 24 | m_format.setStencilBufferSize(8); 25 | m_format.setSamples(4); 26 | 27 | m_view.setFormat(m_format); 28 | m_view.setResizeMode(QQuickView::SizeRootObjectToView); 29 | m_view.setSource(QUrl("qrc:/QML/SolarSystemMain.qml")); 30 | m_view.setColor("#000000"); 31 | 32 | m_view.setMinimumWidth(1280); 33 | m_view.setMinimumHeight(700); 34 | 35 | m_view.setIcon(QIcon(QStringLiteral(":/Resources/Images/solarsystem_icon.png"))); 36 | 37 | QObject::connect(m_view.engine(), SIGNAL(quit()), this, SLOT(quit())); 38 | } 39 | 40 | void SolarSystem::QuickUi::show() 41 | { 42 | #ifdef QT_NO_DEBUG 43 | m_view.showFullScreen(); 44 | #else 45 | m_view.show(); 46 | #endif 47 | } 48 | 49 | void SolarSystem::QuickUi::quit() 50 | { 51 | qApp->exit(); 52 | } 53 | -------------------------------------------------------------------------------- /UI/quickui.h: -------------------------------------------------------------------------------- 1 | #ifndef QUICKUI_H 2 | #define QUICKUI_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace SolarSystem 9 | { 10 | // user interface based on qt quick 11 | class QuickUi : public QObject 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit QuickUi(QObject* parent = nullptr); 17 | 18 | Q_INVOKABLE void show(); 19 | 20 | private: 21 | QSurfaceFormat m_format; 22 | QQuickView m_view; 23 | 24 | private slots: 25 | void quit(); 26 | }; 27 | } 28 | 29 | #endif // QUICKUI_H 30 | -------------------------------------------------------------------------------- /android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /android/res/drawable-ldpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Instand/SolarSystem/f1abe57dff59f7ae7a80a2e86e00c9112d3d2b22/android/res/drawable-ldpi/icon.png -------------------------------------------------------------------------------- /dbconnector.cpp: -------------------------------------------------------------------------------- 1 | #include "dbconnector.h" 2 | #include 3 | #include 4 | 5 | using SolarS = SolarSystem::SolarStrings; 6 | using SolarV = SolarSystem::SolarValues; 7 | using Types = SolarSystem::SolarFields; 8 | 9 | #ifdef Q_OS_ANDROID 10 | static void assetsSetup(const QString& path) 11 | { 12 | QFile assetsFile("assets:/" + SolarS::dbFileName); 13 | 14 | if (assetsFile.exists()) 15 | { 16 | if (!assetsFile.copy(path)) 17 | qDebug() << "Copy database from assets failed"; 18 | } 19 | } 20 | #endif 21 | 22 | SolarSystem::DBConnector::DBConnector(QObject* parent): 23 | QObject(parent), 24 | m_dataBase(QSqlDatabase::addDatabase(SolarS::qSqlLite)) 25 | { 26 | #ifndef Q_OS_ANDROID 27 | m_dbPath = QGuiApplication::applicationDirPath() + SolarS::dbFolder + SolarS::dbFileName; 28 | 29 | if (!QFile::exists(m_dbPath)) 30 | { 31 | QDir dir; 32 | dir.mkdir(QGuiApplication::applicationDirPath() + SolarS::dbFolder); 33 | 34 | QFile file(":/Resources" + SolarS::dbFolder + SolarS::dbFileName); 35 | file.copy(m_dbPath); 36 | } 37 | #endif 38 | 39 | #ifdef Q_OS_ANDROID 40 | m_dbPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + SolarS::dbFileName; 41 | 42 | if (!QFile::setPermissions(m_dbPath, QFile::WriteOwner | QFile::ReadOwner)) 43 | qDebug() << "Database permissions failed"; 44 | 45 | QFileInfo file(m_dbPath); 46 | 47 | if (!file.exists()) 48 | { 49 | QFile resourceFile(":/Resources" + SolarS::dbFolder + SolarS::dbFileName); 50 | 51 | if (resourceFile.exists()) 52 | { 53 | if (!resourceFile.copy(m_dbPath)) 54 | { 55 | qDebug() << "Copy database from resources failed, try to copy from assets"; 56 | assetsSetup(m_dbPath); 57 | } 58 | } 59 | else 60 | assetsSetup(m_dbPath); 61 | } 62 | #endif 63 | QFileInfo info(m_dbPath); 64 | 65 | if (info.isFile() && info.exists()) 66 | { 67 | m_dataBase.setDatabaseName(m_dbPath); 68 | 69 | if (!m_dataBase.open()) 70 | qDebug() << "Database opening failed"; 71 | } 72 | } 73 | 74 | SolarSystem::DBConnector::~DBConnector() 75 | { 76 | if (m_dataBase.isOpen()) 77 | m_dataBase.close(); 78 | 79 | if (QFile::exists(m_dbPath)) 80 | QFile::remove(m_dbPath); 81 | } 82 | 83 | SolarSystem::DBConnector& SolarSystem::DBConnector::instance() 84 | { 85 | static DBConnector connector; 86 | return connector; 87 | } 88 | 89 | bool SolarSystem::DBConnector::isOpen() 90 | { 91 | return m_dataBase.isOpen(); 92 | } 93 | 94 | int SolarSystem::DBConnector::elementsCount() 95 | { 96 | QStringList list; 97 | 98 | if (m_dataBase.isOpen()) 99 | { 100 | QSqlQuery query(SolarS::select + SolarS::nameField + SolarS::from + SolarS::dbName); 101 | 102 | while (query.next()) { 103 | list << query.value(SolarV::zero).toString(); 104 | } 105 | } 106 | 107 | return list.size(); 108 | } 109 | 110 | bool SolarSystem::DBConnector::status() const 111 | { 112 | return m_dataBase.isValid(); 113 | } 114 | 115 | const SolarSystem::ObjectPtr SolarSystem::DBConnector::info(const QString& objectName) const 116 | { 117 | SolarSystem::ObjectPtr object = std::make_shared(); 118 | 119 | if (m_dataBase.isOpen()) 120 | { 121 | QSqlQuery query(SolarS::select + SolarS::all + SolarS::from + SolarS::dbName + SolarS::where + SolarS::nameField + 122 | SolarS::like + SolarS::likeObject(objectName)); 123 | 124 | // collecting query data to local object 125 | if (query.first()) 126 | createObjectFromQuery(query, object); 127 | } 128 | 129 | return object; 130 | } 131 | 132 | QStringList SolarSystem::DBConnector::allSolarObjects() const 133 | { 134 | QStringList objectList; 135 | 136 | if (m_dataBase.isOpen()) 137 | { 138 | QSqlQuery query(SolarS::select + SolarS::nameField + SolarS::from + SolarS::dbName); 139 | 140 | while (query.next()) { 141 | objectList << query.value(SolarV::zero).toString(); 142 | } 143 | } 144 | 145 | return objectList; 146 | } 147 | 148 | QStringList SolarSystem::DBConnector::allPlanetsNames() const 149 | { 150 | QStringList list; 151 | 152 | if (m_dataBase.isOpen()) 153 | { 154 | QSqlQuery query(SolarS::select + SolarS::nameField + SolarS::from + SolarS::dbName + SolarS::where + SolarS::type + 155 | SolarS::like + SolarS::likeObject(SolarStrings::planet)); 156 | 157 | while (query.next()) { 158 | list << query.value(SolarV::zero).toString(); 159 | } 160 | } 161 | 162 | return list; 163 | } 164 | 165 | QStringList SolarSystem::DBConnector::columnNames() const 166 | { 167 | QStringList list; 168 | 169 | if (m_dataBase.isOpen()) 170 | { 171 | QSqlQuery query("PRAGMA table_info('SolarSystem')"); 172 | 173 | while (query.next()) 174 | list << query.value(1).toString(); 175 | } 176 | 177 | return list; 178 | } 179 | 180 | QStringList SolarSystem::DBConnector::info(SolarSystem::SolarObjects object) const 181 | { 182 | auto objStr = SolarParser::parseSolarObjectToString(object); 183 | QStringList list; 184 | 185 | if (m_dataBase.isOpen()) 186 | { 187 | QSqlQuery query("SELECT * FROM SolarSystem WHERE Name =" + SolarS::likeObject(objStr)); 188 | 189 | // columns count 190 | auto size = query.record().count(); 191 | 192 | while (query.next()) 193 | { 194 | for (int i = 0; i < size; ++i) 195 | list << query.value(i).toString(); 196 | } 197 | } 198 | 199 | return list; 200 | } 201 | 202 | void SolarSystem::DBConnector::createObjectFromQuery(QSqlQuery& query, ObjectPtr& object) const 203 | { 204 | object->setStringType(query.value(Types::SolarType).toString()); 205 | object->setSolarObjectName(query.value(Types::Name).toString()); 206 | object->setOrbitalSpeed(query.value(Types::OrbitalSpeed).toFloat()); 207 | object->setMass(query.value(Types::Mass).toDouble()); 208 | object->setMeanRadius(query.value(Types::MeanRadius).toFloat()); 209 | object->setSurfaceTemperature(query.value(Types::Temperature).toInt()); 210 | object->setSurfaceGravity(query.value(Types::Gravity).toFloat()); 211 | object->setVolume(query.value(Types::Volume).toDouble()); 212 | object->setSiderealPeriod(query.value(Types::SiderealPeriod).toDouble()); 213 | object->setOrbitalPeriod(query.value(Types::OrbitalPeriod).toDouble()); 214 | object->setDescription(query.value(Types::Description).toString()); 215 | 216 | // programming type 217 | object->setSolarType(SolarParser::parseString(object->stringType())); 218 | } 219 | -------------------------------------------------------------------------------- /dbconnector.h: -------------------------------------------------------------------------------- 1 | #ifndef DBCONNECTOR_H 2 | #define DBCONNECTOR_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | namespace SolarSystem 12 | { 13 | // connection and receive data from database (default SQLite 3) Singleton 14 | class DBConnector final : public QObject 15 | { 16 | Q_OBJECT 17 | 18 | private: 19 | explicit DBConnector(QObject* parent = nullptr); 20 | ~DBConnector(); 21 | 22 | DBConnector(const DBConnector& dbc) = delete; 23 | DBConnector(DBConnector&& dbc) = delete; 24 | DBConnector& operator= (const DBConnector& dbc) = delete; 25 | 26 | public: 27 | static DBConnector& instance(); 28 | 29 | // checks db state 30 | bool isOpen(); 31 | 32 | // checks db elements count 33 | int elementsCount(); 34 | 35 | // returns database status 36 | bool status() const; 37 | 38 | // returns a full info about object 39 | const ObjectPtr info(const QString& objectName) const; 40 | 41 | // returns all solar object names 42 | QStringList allSolarObjects() const; 43 | 44 | // returns names of all planets 45 | QStringList allPlanetsNames() const; 46 | 47 | // returns names of all columns 48 | QStringList columnNames() const; 49 | 50 | // returns a full info about solar object from solarObject type 51 | QStringList info(SolarObjects object) const; 52 | 53 | private: 54 | QSqlDatabase m_dataBase; 55 | QString m_dbPath; 56 | 57 | // creates object 58 | void createObjectFromQuery(QSqlQuery& query, ObjectPtr& object) const; 59 | }; 60 | } 61 | 62 | #endif // DBCONNECTOR_H 63 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QGuiApplication a(argc, argv); 7 | 8 | // show our beautiful solar system to us 9 | SolarSystem::QuickUi ui; 10 | ui.show(); 11 | 12 | return a.exec(); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /object.cpp: -------------------------------------------------------------------------------- 1 | #include "object.h" 2 | 3 | struct SolarSystem::Object::ObjectData 4 | { 5 | // base parameters 6 | QString stringType; // solar object type: Planet, Sattelite (Moon), Ring, Dwarf Planet, Solar System Body, Star, Asteroid, Galaxy 7 | QString name; // base name 8 | float orbitalSpeed; // base orbital speed, km/s 9 | double mass; // base mass, kg 10 | float meanRadius; // base radius, km 11 | int surfaceTemp; // base surface temperature, K 12 | float surfaceGRavity; // base surface gravity, m/s^2 13 | double volume; // base volume, km^3 14 | 15 | // programming type 16 | SolarSystem::ObjectType solarType; 17 | 18 | // periods 19 | double siderealPeriod; // sidereal rotation period (around of axis) 20 | double orbitalPeriod; // orbital rotation period (around of sun) 21 | 22 | // solar system object description 23 | QString description; 24 | }; 25 | 26 | SolarSystem::Object::Object(QObject* parent): 27 | QObject(parent), solarObjectData(new ObjectData) 28 | { 29 | solarObjectData->solarType = ObjectType::SolarSystemBody; 30 | } 31 | 32 | SolarSystem::Object::~Object() 33 | { 34 | delete solarObjectData; 35 | } 36 | 37 | SolarSystem::Object::Object(const SolarSystem::Object& obj): 38 | Object(obj.parent()) 39 | { 40 | solarObjectData = new SolarSystem::Object::ObjectData(*(obj.solarObjectData)); 41 | } 42 | 43 | SolarSystem::Object& SolarSystem::Object::operator=(SolarSystem::Object obj) 44 | { 45 | // temp object swap 46 | SolarSystem::swap(*this, obj); 47 | return *this; 48 | } 49 | 50 | // interface 51 | void SolarSystem::Object::setDescription(const QString& description) 52 | { 53 | solarObjectData->description = description; 54 | } 55 | 56 | QString SolarSystem::Object::description() const 57 | { 58 | return solarObjectData->description; 59 | } 60 | 61 | void SolarSystem::Object::setStringType(const QString& type) 62 | { 63 | solarObjectData->stringType = type; 64 | } 65 | 66 | QString SolarSystem::Object::stringType() const 67 | { 68 | return solarObjectData->stringType; 69 | } 70 | 71 | void SolarSystem::Object::setSolarObjectName(const QString& name) 72 | { 73 | solarObjectData->name = name; 74 | } 75 | 76 | QString SolarSystem::Object::solarObjectName() const 77 | { 78 | return solarObjectData->name; 79 | } 80 | 81 | void SolarSystem::Object::setOrbitalSpeed(float speed) 82 | { 83 | solarObjectData->orbitalSpeed = speed; 84 | } 85 | 86 | float SolarSystem::Object::orbitalSpeed() const 87 | { 88 | return solarObjectData->orbitalSpeed; 89 | } 90 | 91 | void SolarSystem::Object::setMass(double mass) 92 | { 93 | solarObjectData->mass = mass; 94 | } 95 | 96 | double SolarSystem::Object::mass() const 97 | { 98 | return solarObjectData->mass; 99 | } 100 | 101 | void SolarSystem::Object::setMeanRadius(float radius) 102 | { 103 | solarObjectData->meanRadius = radius; 104 | } 105 | 106 | float SolarSystem::Object::meanRadius() const 107 | { 108 | return solarObjectData->meanRadius; 109 | } 110 | 111 | void SolarSystem::Object::setSurfaceTemperature(int temperature) 112 | { 113 | solarObjectData->surfaceTemp = temperature; 114 | } 115 | 116 | int SolarSystem::Object::surfaceTemperature() const 117 | { 118 | return solarObjectData->surfaceTemp; 119 | } 120 | 121 | void SolarSystem::Object::setSurfaceGravity(float gravity) 122 | { 123 | solarObjectData->surfaceGRavity = gravity; 124 | } 125 | 126 | float SolarSystem::Object::surfaceGravity() const 127 | { 128 | return solarObjectData->surfaceGRavity; 129 | } 130 | 131 | void SolarSystem::Object::setVolume(double volume) 132 | { 133 | solarObjectData->volume = volume; 134 | } 135 | 136 | double SolarSystem::Object::volume() const 137 | { 138 | return solarObjectData->volume; 139 | } 140 | 141 | void SolarSystem::Object::setSolarType(ObjectType type) 142 | { 143 | solarObjectData->solarType = type; 144 | } 145 | 146 | SolarSystem::ObjectType SolarSystem::Object::solarType() const 147 | { 148 | return solarObjectData->solarType; 149 | } 150 | 151 | void SolarSystem::Object::setSiderealPeriod(double period) 152 | { 153 | solarObjectData->siderealPeriod = period; 154 | } 155 | 156 | double SolarSystem::Object::siderealPeriod() const 157 | { 158 | return solarObjectData->siderealPeriod; 159 | } 160 | 161 | void SolarSystem::Object::setOrbitalPeriod(double period) 162 | { 163 | solarObjectData->orbitalPeriod = period; 164 | } 165 | 166 | double SolarSystem::Object::orbitalPeriod() const 167 | { 168 | return solarObjectData->orbitalPeriod; 169 | } 170 | 171 | void SolarSystem::swap(SolarSystem::Object& lhs, SolarSystem::Object& rhs) 172 | { 173 | std::swap(lhs.solarObjectData, rhs.solarObjectData); 174 | } 175 | -------------------------------------------------------------------------------- /object.h: -------------------------------------------------------------------------------- 1 | #ifndef SOLARSYSTEMOBJECT_H 2 | #define SOLARSYSTEMOBJECT_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | namespace SolarSystem 12 | { 13 | // base object of solar system for storing info from database 14 | class Object : public QObject 15 | { 16 | Q_OBJECT 17 | 18 | public: 19 | explicit Object(QObject* parent = nullptr); 20 | ~Object(); 21 | 22 | Object(const Object& obj); 23 | Object& operator=(Object obj); 24 | 25 | private: 26 | struct ObjectData; 27 | ObjectData* solarObjectData; 28 | 29 | friend void swap(Object&, Object&); 30 | 31 | public: 32 | 33 | // interface 34 | void setDescription(const QString& description); 35 | QString description() const; 36 | 37 | void setStringType(const QString& type); 38 | QString stringType() const; 39 | 40 | void setSolarObjectName(const QString& name); 41 | QString solarObjectName() const; 42 | 43 | void setOrbitalSpeed(float speed); 44 | float orbitalSpeed() const; 45 | 46 | void setMass(double mass); 47 | double mass() const; 48 | 49 | void setMeanRadius(float radius); 50 | float meanRadius() const; 51 | 52 | void setSurfaceTemperature(int temperature); 53 | int surfaceTemperature() const; 54 | 55 | void setSurfaceGravity(float gravity); 56 | float surfaceGravity() const; 57 | 58 | void setVolume(double volume); 59 | double volume() const; 60 | 61 | void setSolarType(ObjectType type); 62 | ObjectType solarType() const; 63 | 64 | void setSiderealPeriod(double period); 65 | double siderealPeriod() const; 66 | 67 | void setOrbitalPeriod(double period); 68 | double orbitalPeriod() const; 69 | }; 70 | 71 | void swap(Object& lhs, Object& rhs); 72 | 73 | using ObjectPtr = std::shared_ptr; 74 | } 75 | 76 | #endif // SOLARSYSTEMOBJECT_H 77 | -------------------------------------------------------------------------------- /res.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | Resources/Skybox/stars_negx.webp 4 | Resources/Skybox/stars_negy.webp 5 | Resources/Skybox/stars_negz.webp 6 | Resources/Skybox/stars_posx.webp 7 | Resources/Skybox/stars_posy.webp 8 | Resources/Skybox/stars_posz.webp 9 | Resources/Images/earth.png 10 | Resources/Images/earthcloudmapcolortrans.png 11 | Resources/Images/earthcloudmapspec.jpg 12 | Resources/Images/earthmap1k.jpg 13 | Resources/Images/earthnormal1k.jpg 14 | Resources/Images/earthspec1k.jpg 15 | Resources/Images/jupiter.png 16 | Resources/Images/jupitermap.jpg 17 | Resources/Images/mars.png 18 | Resources/Images/marsmap1k.jpg 19 | Resources/Images/marsnormal1k.jpg 20 | Resources/Images/mercury.png 21 | Resources/Images/mercurymap.jpg 22 | Resources/Images/mercurynormal.jpg 23 | Resources/Images/moonmap1k.jpg 24 | Resources/Images/moonnormal1k.jpg 25 | Resources/Images/neptune.png 26 | Resources/Images/neptunemap.jpg 27 | Resources/Images/saturn.png 28 | Resources/Images/saturnmap.jpg 29 | Resources/Images/saturnringcolortrans.png 30 | Resources/Images/sun.png 31 | Resources/Images/sunmap.jpg 32 | Resources/Images/uranus.png 33 | Resources/Images/uranusmap.jpg 34 | Resources/Images/uranusringcolortrans.png 35 | Resources/Images/venus.png 36 | QML/SolarEntityMain.qml 37 | QML/SolarSystemMain.qml 38 | QML/DateText.qml 39 | Resources/Meshes/ring.obj 40 | Resources/Images/sun_map.jpg 41 | Resources/Images/jupiternormal.jpg 42 | Resources/Images/saturnnormal.jpg 43 | Resources/Images/uranusnormal.jpg 44 | Resources/Images/neptunenormal.jpg 45 | Resources/Images/saturnringcolortransnormal.png 46 | Resources/Images/uranusringcolortransnormal.png 47 | QML/TransparentButton.qml 48 | Resources/Images/planet_icon.png 49 | QML/Controls.qml 50 | Resources/Images/options_icon.png 51 | Resources/Images/calendar_icon.png 52 | Resources/Images/info_icon.png 53 | QML/SolarFrame.qml 54 | QML/PlanetList.qml 55 | QML/PlanetButton.qml 56 | Resources/Images/venus_atmo.jpg 57 | Resources/Images/venus_atmonormal.jpg 58 | Resources/Images/earthcloudmapcolortransnormal.png 59 | Resources/Images/solarsystem.png 60 | Resources/Images/solarsystem_icon.png 61 | Resources/Images/exit_icon.png 62 | Resources/Images/solarsystem_icon.ico 63 | Resources/Images/pluto.png 64 | Resources/Images/plutomap.jpg 65 | Resources/Images/plutonormal.jpg 66 | Resources/Images/saturn_rings.png 67 | QML/Info.qml 68 | Resources/Images/screen_icon.png 69 | Resources/Meshes/planetRing.obj 70 | Resources/Shaders/shadowmap.vert 71 | Resources/Shaders/diffusenormal.frag 72 | Resources/Shaders/diffusenormal.vert 73 | Resources/Shaders/diffuseshadow.vert 74 | Resources/Shaders/shadowmap.frag 75 | Resources/Shaders/diffuseshadow.frag 76 | Resources/Images/sun_normal.jpg 77 | Resources/Shaders/diffuse.frag 78 | Resources/Shaders/diffuse.vert 79 | Resources/Shaders/skybox.frag 80 | Resources/Shaders/skybox.vert 81 | Resources/Database/SolarDB.db 82 | Resources/Info.txt 83 | QML/FpsLabel.qml 84 | QML/SpeedSlider.qml 85 | QML/DatabaseLabel.qml 86 | QML/UserOptions.qml 87 | 88 | 89 | -------------------------------------------------------------------------------- /solarsystemcore.cpp: -------------------------------------------------------------------------------- 1 | #include "solarsystemcore.h" 2 | 3 | const QString SolarSystem::SolarStrings::qSqlLite = "QSQLITE"; 4 | 5 | // db fields 6 | const QString SolarSystem::SolarStrings::dbName = "SolarSystem"; 7 | const QString SolarSystem::SolarStrings::dbFileName = "SolarDB.db"; 8 | const QString SolarSystem::SolarStrings::dbFolder = "/Database/"; 9 | const QString SolarSystem::SolarStrings::nameField = "Name"; 10 | const QString SolarSystem::SolarStrings::type = "Solar type"; 11 | const QString SolarSystem::SolarStrings::orbitalSpeed = "Orbital speed"; 12 | const QString SolarSystem::SolarStrings::mass = "Mass"; 13 | const QString SolarSystem::SolarStrings::meanRadius = "Mean radius"; 14 | const QString SolarSystem::SolarStrings::surfaceTemp = "Temperature"; 15 | const QString SolarSystem::SolarStrings::surfaceGravity = "Gravity"; 16 | const QString SolarSystem::SolarStrings::volume = "Volume"; 17 | const QString SolarSystem::SolarStrings::siderealPeriod = "Sidereal period"; 18 | const QString SolarSystem::SolarStrings::orbitalPeriod = "Orbital period"; 19 | const QString SolarSystem::SolarStrings::description = "Description"; 20 | 21 | // Sql query 22 | const QString SolarSystem::SolarStrings::select = "SELECT "; 23 | const QString SolarSystem::SolarStrings::from = " FROM "; 24 | const QString SolarSystem::SolarStrings::where = " WHERE "; 25 | const QString SolarSystem::SolarStrings::like = " LIKE"; 26 | const QString SolarSystem::SolarStrings::all = "*"; 27 | 28 | // types 29 | const QString SolarSystem::SolarStrings::planet = "Planet"; 30 | const QString SolarSystem::SolarStrings::dwarfPlanet = "Dwarf planet"; 31 | const QString SolarSystem::SolarStrings::star = "Star"; 32 | const QString SolarSystem::SolarStrings::moon = "Moon"; 33 | const QString SolarSystem::SolarStrings::ring = "Ring"; 34 | const QString SolarSystem::SolarStrings::solarSystemBody = "Solar system body"; 35 | const QString SolarSystem::SolarStrings::galaxy = "Galaxy"; 36 | const QString SolarSystem::SolarStrings::asteroid = "Asteroid"; 37 | 38 | // values 39 | const float SolarSystem::SolarValues::solarSystemModifier = 10000.0f; 40 | 41 | const int SolarSystem::SolarValues::zero = 0; 42 | const int SolarSystem::SolarValues::solarDistance = modified(2600000); 43 | const float SolarSystem::SolarValues::auScale = modified(149597.870700f); 44 | 45 | const float SolarSystem::SolarValues::saturnOuterRadius = 120.700f; 46 | const float SolarSystem::SolarValues::uranusOuterRadius = 40.0f; 47 | const float SolarSystem::SolarValues::sunOuterRadiusDelimiter = 100.0f; 48 | const double SolarSystem::SolarValues::sunRadiusDelimeter = 80.0; 49 | 50 | const float SolarSystem::SolarValues::startSize = modified(1800.0f); 51 | const float SolarSystem::SolarValues::startSpeed = 1000000.0f; 52 | 53 | const int SolarSystem::SolarValues::year = 2000; 54 | const int SolarSystem::SolarValues::month = 1; 55 | const int SolarSystem::SolarValues::day = 1; 56 | 57 | const QVector3D SolarSystem::SolarValues::rollAxis = QVector3D(0, 1, 0); 58 | const QVector3D SolarSystem::SolarValues::tiltAxis = QVector3D(0, 0, 1); 59 | 60 | QString SolarSystem::SolarStrings::likeObject(const QString& object) 61 | { 62 | return "'" + object + "'"; 63 | } 64 | --------------------------------------------------------------------------------