Update
This commit is contained in:
65
main.cpp
65
main.cpp
@@ -3,14 +3,28 @@
|
||||
#include <Ogre.h>
|
||||
#include <OgreApplicationContext.h>
|
||||
#include <OgrePageManager.h>
|
||||
#include "physics.h"
|
||||
#include "main.h"
|
||||
|
||||
class KeyHandler : public OgreBites::InputListener {
|
||||
bool keyPressed(const OgreBites::KeyboardEvent &evt) override
|
||||
{
|
||||
if (evt.keysym.sym == OgreBites::SDLK_ESCAPE) {
|
||||
Ogre::Root::getSingleton().queueEndRendering();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void frameRendered(const Ogre::FrameEvent &evt) override
|
||||
{
|
||||
JoltPhysicsWrapper::getSingleton().update(
|
||||
evt.timeSinceLastFrame);
|
||||
}
|
||||
};
|
||||
|
||||
class App : public OgreBites::ApplicationContext {
|
||||
Ogre::SceneNode *mCameraNode;
|
||||
Ogre::SceneManager *mScnMgr;
|
||||
std::unique_ptr<CharacterController> mCharacter;
|
||||
KeyHandler mKeyHandler;
|
||||
MainWorld mWorld;
|
||||
|
||||
public:
|
||||
App();
|
||||
@@ -29,7 +43,7 @@ public:
|
||||
};
|
||||
|
||||
App::App()
|
||||
: OgreBites::ApplicationContext("App")
|
||||
: OgreBites::ApplicationContext("JoltPhysics")
|
||||
{
|
||||
}
|
||||
void App::setup()
|
||||
@@ -65,18 +79,11 @@ void App::initCamera()
|
||||
void App::setupWorld()
|
||||
{
|
||||
addInputListener(&mKeyHandler);
|
||||
mWorld.setup();
|
||||
getRoot()->addFrameListener(&mWorld);
|
||||
}
|
||||
void App::createCharacter()
|
||||
{
|
||||
Ogre::Camera *cam = static_cast<Ogre::Camera *>(
|
||||
mCameraNode->getAttachedObject("tps_camera"));
|
||||
mCharacter = std::make_unique<CharacterController>(mCameraNode, cam,
|
||||
mScnMgr, &mWorld);
|
||||
// mInputListenerChain = TouchAgnosticInputListenerChain(getRenderWindow(), {&mKeyHandler, mCharacter.get()});
|
||||
addInputListener(mCharacter.get());
|
||||
WorldData::get_singleton()->initPagedWorld(cam);
|
||||
}
|
||||
void App::createContent()
|
||||
{
|
||||
@@ -92,6 +99,41 @@ void App::createContent()
|
||||
light->setDiffuseColour(Ogre::ColourValue::White);
|
||||
light->setSpecularColour(Ogre::ColourValue(0.4, 0.4, 0.4));
|
||||
mScnMgr->setSkyBox(true, "Skybox", 490);
|
||||
Ogre::MeshPtr mesh =
|
||||
Ogre::MeshManager::getSingleton().load("world.glb", "General");
|
||||
new JoltPhysicsWrapper(mScnMgr, mScnMgr->getRootSceneNode());
|
||||
JPH::ShapeRefC shape =
|
||||
JoltPhysicsWrapper::getSingleton().createMeshShape(mesh);
|
||||
JPH::ObjectLayer layer = Layers::NON_MOVING;
|
||||
JPH::ObjectLayer layerMoving = Layers::MOVING;
|
||||
JPH::ShapeRefC shapeBox1 =
|
||||
JoltPhysicsWrapper::getSingleton().createBoxShape(
|
||||
{ 0.5f, 1.7f, 0.5f });
|
||||
JPH::ShapeRefC shapeBox2 =
|
||||
JoltPhysicsWrapper::getSingleton().createBoxShape(
|
||||
{ 0.5f, 1.7f, 0.5f });
|
||||
JPH::ShapeRefC shapeBox3 =
|
||||
JoltPhysicsWrapper::getSingleton().createBoxShape(
|
||||
{ 0.5f, 1.7f, 0.5f });
|
||||
JoltPhysics::CompoundShapeBuilder builder;
|
||||
builder.addShape(shapeBox1, { -0.1f, 0.0f, 0.0f },
|
||||
Ogre::Quaternion::IDENTITY);
|
||||
builder.addShape(shapeBox2, { 0.0f, 0.0f, 0.0f },
|
||||
Ogre::Quaternion::IDENTITY);
|
||||
builder.addShape(shapeBox3, { 0.1f, 0.0f, 0.0f },
|
||||
Ogre::Quaternion::IDENTITY);
|
||||
JPH::ShapeRefC compound = builder.build();
|
||||
auto body = JoltPhysicsWrapper::getSingleton().createBody(
|
||||
shape.GetPtr(), 0, Ogre::Vector3::ZERO, Ogre::Quaternion::IDENTITY,
|
||||
JPH::EMotionType::Static, layer);
|
||||
auto compoundBody = JoltPhysicsWrapper::getSingleton().createBody(
|
||||
compound.GetPtr(), 0, Ogre::Vector3(0, 0, -3),
|
||||
Ogre::Quaternion::IDENTITY, JPH::EMotionType::Kinematic,
|
||||
layerMoving);
|
||||
JoltPhysicsWrapper::getSingleton().addBody(
|
||||
body, JPH::EActivation::DontActivate);
|
||||
JoltPhysicsWrapper::getSingleton().addBody(
|
||||
compoundBody, JPH::EActivation::DontActivate);
|
||||
}
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@@ -105,7 +147,6 @@ int main(int argc, char *argv[])
|
||||
Ogre::RTShader::ShaderGenerator *shadergen =
|
||||
Ogre::RTShader::ShaderGenerator::getSingletonPtr();
|
||||
shadergen->addSceneManager(scnMgr);
|
||||
WorldData::init(root, scnMgr);
|
||||
ctx.setWindowGrab(true);
|
||||
ctx.createContent();
|
||||
ctx.initCamera();
|
||||
@@ -118,7 +159,5 @@ int main(int argc, char *argv[])
|
||||
ctx.getRoot()->startRendering();
|
||||
ctx.setWindowGrab(false);
|
||||
ctx.closeApp();
|
||||
WorldData::cleanup();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user