updates
This commit is contained in:
17
Game.cpp
17
Game.cpp
@@ -244,7 +244,7 @@ public:
|
||||
float panel_width;
|
||||
void initGui();
|
||||
};
|
||||
#undef WATER
|
||||
#define WATER
|
||||
class App : public OgreBites::ApplicationContext {
|
||||
std::unique_ptr<Ogre::Bullet::DynamicsWorld> mDynWorld;
|
||||
std::unique_ptr<Ogre::Bullet::DebugDrawer> mDbgDraw;
|
||||
@@ -262,6 +262,7 @@ class App : public OgreBites::ApplicationContext {
|
||||
#ifdef WATER
|
||||
Water m_water;
|
||||
#endif
|
||||
bool mTerrainReady;
|
||||
class KeyboardListener : public OgreBites::InputListener,
|
||||
public Ogre::FrameListener {
|
||||
App *mApp;
|
||||
@@ -366,8 +367,10 @@ class App : public OgreBites::ApplicationContext {
|
||||
update(evt.timeSinceLastFrame);
|
||||
if (mApp->getCharacterController() && gui_active)
|
||||
mApp->getCharacterController()->disableUpdates();
|
||||
else if (mApp->getCharacterController() && !gui_active)
|
||||
else if (mApp->getCharacterController() && !gui_active && mApp->isTerrainReady()) {
|
||||
OgreAssert(mApp->isTerrainReady(), "terrain is not ready");
|
||||
mApp->getCharacterController()->enableUpdates();
|
||||
}
|
||||
if (!gui_active) {
|
||||
mApp->updateSun(evt.timeSinceLastFrame);
|
||||
mApp->updateTerrain(evt.timeSinceLastFrame);
|
||||
@@ -387,6 +390,7 @@ public:
|
||||
Ogre::Vector3(0, -9.8, 0)))
|
||||
, m_terrain(mDynWorld->getBtWorld())
|
||||
, mCharacterController(nullptr)
|
||||
, mTerrainReady(false)
|
||||
{
|
||||
}
|
||||
virtual ~App()
|
||||
@@ -550,6 +554,15 @@ public:
|
||||
Ogre::Timer mTerrainUpd;
|
||||
void updateTerrain(float delta)
|
||||
{
|
||||
Ogre::Vector3 pos = mCharacterController->getPosition();
|
||||
if (!mTerrainReady && m_terrain.isLoadedAt(pos) && mCharacterController->checkGround()) {
|
||||
std::cout << "terrain ready\n";
|
||||
mTerrainReady = true;
|
||||
}
|
||||
}
|
||||
bool isTerrainReady()
|
||||
{
|
||||
return mTerrainReady;
|
||||
}
|
||||
// TODO: implement rough water level calculation
|
||||
float getWaterLevel(const Ogre::Vector3 &position)
|
||||
|
||||
Reference in New Issue
Block a user