From cc82acc18cbd2ed1c8f5a09e625c14791dee5544 Mon Sep 17 00:00:00 2001 From: Sergey Lapin Date: Mon, 10 Nov 2025 07:14:45 +0300 Subject: [PATCH] Initial commit --- CMakeLists.txt | 51 ++++++++++++++++++++ main.cpp | 124 +++++++++++++++++++++++++++++++++++++++++++++++++ main.h | 3 ++ 3 files changed, 178 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 main.cpp create mode 100644 main.h diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..0ee98a6 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,51 @@ +cmake_minimum_required(VERSION 3.13.0) +project(jolt-physics) + +set(CMAKE_CXX_STANDARD 14) +# The COMPONENTS part checks that OGRE was built the way we need it +# The CONFIG flag makes sure we get OGRE instead of OGRE-next +find_package(OGRE REQUIRED COMPONENTS Bites Paging Terrain CONFIG) +find_package(ZLIB) +find_package(SDL2) +find_package(assimp REQUIRED CONFIG) +find_package(OgreProcedural REQUIRED CONFIG) +find_package(pugixml REQUIRED CONFIG) +find_package(flecs REQUIRED CONFIG) + +add_library(fix::assimp INTERFACE IMPORTED) +set_target_properties(fix::assimp PROPERTIES + INTERFACE_LINK_LIBRARIES "${ASSIMP_LIBRARIES};pugixml" + INTERFACE_LINK_DIRECTORIES "${ASSIMP_LIBRARY_DIRS}" +) + +add_library(fix::OgreProcedural INTERFACE IMPORTED) +set_target_properties(fix::OgreProcedural PROPERTIES + INTERFACE_LINK_LIBRARIES "OgreProcedural" + INTERFACE_LINK_DIRECTORIES "${CMAKE_PREFIX_PATH}/lib" +) + +if(OGRE_STATIC) +add_library(OgreGLSupportStatic INTERFACE IMPORTED) +set_target_properties(OgreGLSupportStatic PROPERTIES + INTERFACE_LINK_LIBRARIES "OgreGLSupportStatic" + INTERFACE_LINK_DIRECTORIES "${CMAKE_PREFIX_PATH}/lib" +) +endif() + +add_library(fix::pugixml INTERFACE IMPORTED) +set_target_properties(fix::pugixml PROPERTIES + INTERFACE_LINK_LIBRARIES "pugixml" + INTERFACE_LINK_DIRECTORIES "${CMAKE_PREFIX_PATH}/lib" +) +# add the source files as usual +add_executable(jolt-demo main.cpp) + +# this also sets the includes and pulls third party dependencies +target_link_libraries(jolt-demo OgreBites OgrePaging ${ASSIMP_LIBRARIES} + -Wl,--as-needed + ) +if(OGRE_STATIC) +target_link_options(jolt-demo PRIVATE -static-libstdc++ -static-libgcc) +endif() +#add_dependencies(0_Bootstrap stage_files import_vrm) + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..ec13b4f --- /dev/null +++ b/main.cpp @@ -0,0 +1,124 @@ +#include + +#include +#include +#include +#include "main.h" + +class App : public OgreBites::ApplicationContext { + Ogre::SceneNode *mCameraNode; + Ogre::SceneManager *mScnMgr; + std::unique_ptr mCharacter; + KeyHandler mKeyHandler; + MainWorld mWorld; + +public: + App(); + virtual ~App(); + + void setup(); + void locateResources(); + void initCamera(); + Ogre::SceneManager *getSceneManager() + { + return mScnMgr; + } + void createContent(); + void createCharacter(); + void setupWorld(); +}; + +App::App() + : OgreBites::ApplicationContext("App") +{ +} +void App::setup() +{ + OgreBites::ApplicationContext::setup(); + Ogre::Root *root = getRoot(); + Ogre::SceneManager *scnMgr = root->createSceneManager(); + mScnMgr = scnMgr; +} +void App::locateResources() +{ + OgreBites::ApplicationContext::locateResources(); +} +App::~App() +{ +} +void App::initCamera() +{ + // also need to tell where we are + mCameraNode = mScnMgr->getRootSceneNode()->createChildSceneNode(); + mCameraNode->setPosition(0, 2, 3); + mCameraNode->lookAt(Ogre::Vector3(0, 1, -1), Ogre::Node::TS_PARENT); + + // create the camera + Ogre::Camera *cam = mScnMgr->createCamera("tps_camera"); + cam->setNearClipDistance(0.1f); // specific to this sample + cam->setAutoAspectRatio(true); + mCameraNode->attachObject(cam); + + // and tell it to render into the main window + getRenderWindow()->addViewport(cam); +} +void App::setupWorld() +{ + addInputListener(&mKeyHandler); + mWorld.setup(); + getRoot()->addFrameListener(&mWorld); +} +void App::createCharacter() +{ + Ogre::Camera *cam = static_cast( + mCameraNode->getAttachedObject("tps_camera")); + mCharacter = std::make_unique(mCameraNode, cam, + mScnMgr, &mWorld); + // mInputListenerChain = TouchAgnosticInputListenerChain(getRenderWindow(), {&mKeyHandler, mCharacter.get()}); + addInputListener(mCharacter.get()); + WorldData::get_singleton()->initPagedWorld(cam); +} +void App::createContent() +{ + // without light we would just get a black screen + Ogre::Light *light = mScnMgr->createLight("MainLight"); + Ogre::SceneNode *lightNode = + mScnMgr->getRootSceneNode()->createChildSceneNode(); + // lightNode->setPosition(0, 10, 15); + lightNode->setDirection( + Ogre::Vector3(0.55, -0.3, 0.75).normalisedCopy()); + lightNode->attachObject(light); + light->setType(Ogre::Light::LT_DIRECTIONAL); + light->setDiffuseColour(Ogre::ColourValue::White); + light->setSpecularColour(Ogre::ColourValue(0.4, 0.4, 0.4)); + mScnMgr->setSkyBox(true, "Skybox", 490); +} +int main(int argc, char *argv[]) +{ + App ctx; + ctx.initApp(); + // get a pointer to the already created root + Ogre::Root *root = ctx.getRoot(); + Ogre::SceneManager *scnMgr = ctx.getSceneManager(); + + // register our scene with the RTSS + Ogre::RTShader::ShaderGenerator *shadergen = + Ogre::RTShader::ShaderGenerator::getSingletonPtr(); + shadergen->addSceneManager(scnMgr); + WorldData::init(root, scnMgr); + ctx.setWindowGrab(true); + ctx.createContent(); + ctx.initCamera(); + ctx.setupWorld(); + ctx.createCharacter(); + // register for input events + // KeyHandler keyHandler; + // ctx.addInputListener(&keyHandler); + + ctx.getRoot()->startRendering(); + ctx.setWindowGrab(false); + ctx.closeApp(); + WorldData::cleanup(); + return 0; +} + diff --git a/main.h b/main.h new file mode 100644 index 0000000..0d6ad44 --- /dev/null +++ b/main.h @@ -0,0 +1,3 @@ +#ifndef __MAIN_H_ +#define __MAIN_H_ +#endif