Update
This commit is contained in:
38
Game.cpp
38
Game.cpp
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "src/terrain/terrain.h"
|
||||
#include "water/water.h"
|
||||
#include "src/characters/controller.h"
|
||||
class App;
|
||||
class SkyRenderer : public Ogre::SceneManager::Listener {
|
||||
protected:
|
||||
@@ -248,6 +249,7 @@ class App : public OgreBites::ApplicationContext {
|
||||
std::unique_ptr<Ogre::Bullet::DebugDrawer> mDbgDraw;
|
||||
Ogre::SceneNode *mCameraNode, *mCameraPivot, *mCameraGoal;
|
||||
Ogre::Camera *mCamera;
|
||||
CharacterController *mCharacterController;
|
||||
Ogre::Real mPivotPitch;
|
||||
Ogre::SceneManager *mScnMgr;
|
||||
OgreBites::InputListenerChain mInput;
|
||||
@@ -284,9 +286,12 @@ class App : public OgreBites::ApplicationContext {
|
||||
// std::cout << "Escape!\n";
|
||||
// Ogre::Root::getSingleton().queueEndRendering();
|
||||
mApp->setWindowGrab(false);
|
||||
return true;
|
||||
}
|
||||
if (evt.keysym.sym == OgreBites::SDLK_SPACE)
|
||||
return false;
|
||||
if (evt.keysym.sym == OgreBites::SDLK_SPACE) {
|
||||
mApp->dump_water();
|
||||
}
|
||||
if (evt.keysym.sym == 'w')
|
||||
motion.z = -1.0f;
|
||||
if (evt.keysym.sym == 's')
|
||||
@@ -304,6 +309,7 @@ class App : public OgreBites::ApplicationContext {
|
||||
{
|
||||
if (gui_active)
|
||||
return false;
|
||||
return false;
|
||||
if (evt.keysym.sym == 'w' && motion.z < 0.0f)
|
||||
motion.z = 0.0f;
|
||||
if (evt.keysym.sym == 's' && motion.z > 0.0f)
|
||||
@@ -320,6 +326,7 @@ class App : public OgreBites::ApplicationContext {
|
||||
{
|
||||
if (gui_active)
|
||||
return false;
|
||||
return false;
|
||||
// update camera goal based on mouse movement
|
||||
mApp->updateCameraGoal(-0.18f * evt.xrel,
|
||||
-0.12f * evt.yrel, 0);
|
||||
@@ -329,6 +336,7 @@ class App : public OgreBites::ApplicationContext {
|
||||
{
|
||||
if (gui_active)
|
||||
return false;
|
||||
return false;
|
||||
// update camera goal based on mouse movement
|
||||
mApp->updateCameraGoal(0, 0, -0.15f * evt.y);
|
||||
return true;
|
||||
@@ -380,6 +388,7 @@ public:
|
||||
, mDynWorld(new Ogre::Bullet::DynamicsWorld(
|
||||
Ogre::Vector3(0, -9.8, 0)))
|
||||
, m_terrain(mDynWorld->getBtWorld())
|
||||
, mCharacterController(nullptr)
|
||||
{
|
||||
}
|
||||
virtual ~App()
|
||||
@@ -459,18 +468,30 @@ public:
|
||||
std::cout << "Set up water" << "\n";
|
||||
m_water.createWater(getRenderWindow(), mCamera);
|
||||
std::cout << "Set up cursor" << "\n";
|
||||
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
|
||||
Ogre::ResourceGroupManager::getSingleton()
|
||||
.initialiseAllResourceGroups();
|
||||
// OgreBites::ApplicationContext::loadResources();
|
||||
setupCursor();
|
||||
// setupCursor();
|
||||
setupPlayer();
|
||||
std::cout << "Create content" << "\n";
|
||||
createContent();
|
||||
std::cout << "Setup terrain" << "\n";
|
||||
setupTerrain();
|
||||
m_water.init();
|
||||
}
|
||||
void setupPlayer()
|
||||
{
|
||||
mCharacterController = new CharacterController(
|
||||
mCameraNode, mCamera, mScnMgr, mDynWorld.get());
|
||||
#if 0
|
||||
/* FIXME: make proper player setup */
|
||||
Ogre::Entity *ent =
|
||||
mScnMgr->createEntity("PlayerBoat", "boat.glb");
|
||||
mCameraPivot->attachObject(ent);
|
||||
#endif
|
||||
}
|
||||
void setupCursor()
|
||||
{
|
||||
|
||||
// mKeyDirection = Ogre::Vector3::ZERO;
|
||||
// mVerticalVelocity = 0;
|
||||
Ogre::ManualObject *mobj =
|
||||
@@ -515,6 +536,7 @@ public:
|
||||
{
|
||||
if (delta == 0.0f)
|
||||
return;
|
||||
#if 0
|
||||
Ogre::Vector3 move(mCameraNode->getOrientation().zAxis() *
|
||||
mKbd.motion.z);
|
||||
move += Ogre::Vector3(mCameraNode->getOrientation().xAxis() *
|
||||
@@ -535,11 +557,13 @@ public:
|
||||
// mKbd.motion = Ogre::Vector3(0, 0, 0);
|
||||
// if (move.squaredLength() > 0)
|
||||
// std::cout << move << "\n";
|
||||
#endif
|
||||
}
|
||||
void updateCamera(Ogre::Real delta)
|
||||
{
|
||||
if (delta == 0.0f)
|
||||
return;
|
||||
#if 0
|
||||
// place the camera pivot roughly at the character's shoulder
|
||||
// mCameraPivot->setPosition(mBodyNode->getPosition() +
|
||||
// Ogre::Vector3::UNIT_Y * CAM_HEIGHT);
|
||||
@@ -555,10 +579,12 @@ public:
|
||||
// always look at the pivot
|
||||
mCameraNode->lookAt(mCameraPivot->_getDerivedPosition(),
|
||||
Ogre::Node::TS_PARENT);
|
||||
#endif
|
||||
}
|
||||
void updateCameraGoal(Ogre::Real deltaYaw, Ogre::Real deltaPitch,
|
||||
Ogre::Real deltaZoom)
|
||||
{
|
||||
#if 0
|
||||
mCameraPivot->yaw(Ogre::Degree(deltaYaw),
|
||||
Ogre::Node::TS_PARENT);
|
||||
if (!(mPivotPitch + deltaPitch > 25 && deltaPitch > 0) &&
|
||||
@@ -585,6 +611,7 @@ public:
|
||||
if (h + 10 > mh.y)
|
||||
mCameraGoal->translate(0, 10.0f * deltaZoom, distChange,
|
||||
Ogre::Node::TS_LOCAL);
|
||||
#endif
|
||||
}
|
||||
Ogre::SceneNode *mSunGoal;
|
||||
Ogre::SceneNode *mSunNode;
|
||||
@@ -659,7 +686,8 @@ public:
|
||||
m_edit_ui.initGui();
|
||||
createSun();
|
||||
mInput = OgreBites::InputListenerChain(
|
||||
{ getImGuiInputListener(), &mKbd });
|
||||
{ getImGuiInputListener(), &mKbd,
|
||||
mCharacterController });
|
||||
addInputListener(&mInput);
|
||||
getRoot()->addFrameListener(&mKbd);
|
||||
// mTrayMgr->showCursor();
|
||||
|
||||
Reference in New Issue
Block a user