1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 03:12:36 +01:00

Merge branch 'rwng' of bitbucket.org:danharibo/openrw into rwng

Conflicts:
	rwgame/RWGame.cpp
This commit is contained in:
Daniel Evans 2015-04-03 03:17:14 +01:00
commit bc54fac53a
7 changed files with 70 additions and 19 deletions

View File

@ -45,7 +45,7 @@ public:
*/ */
float mHealth; float mHealth;
bool _inWater; bool inWater;
/** /**
* @brief stores the height of water at the last tick * @brief stores the height of water at the last tick
@ -60,7 +60,7 @@ public:
GameObject(GameWorld* engine, const glm::vec3& pos, const glm::quat& rot, ModelRef model) GameObject(GameWorld* engine, const glm::vec3& pos, const glm::quat& rot, ModelRef model)
: _lastPosition(pos), _lastRotation(rot), position(pos), rotation(rot), : _lastPosition(pos), _lastRotation(rot), position(pos), rotation(rot),
model(model), engine(engine), animator(nullptr), skeleton(nullptr), mHealth(0.f), model(model), engine(engine), animator(nullptr), skeleton(nullptr), mHealth(0.f),
_inWater(false), _lastHeight(std::numeric_limits<float>::max()), visible(true), inWater(false), _lastHeight(std::numeric_limits<float>::max()), visible(true),
lifetime(GameObject::UnknownLifetime) lifetime(GameObject::UnknownLifetime)
{} {}
@ -139,7 +139,7 @@ public:
virtual bool isAnimationFixed() const { return true; } virtual bool isAnimationFixed() const { return true; }
virtual bool isInWater() const { return _inWater; } virtual bool isInWater() const { return inWater; }
virtual void tick(float dt) = 0; virtual void tick(float dt) = 0;

View File

@ -230,7 +230,15 @@ void CharacterObject::updateCharacter(float dt)
float wh = engine->gameData.waterHeights[wi]; float wh = engine->gameData.waterHeights[wi];
auto ws = getPosition(); auto ws = getPosition();
wh += engine->gameData.getWaveHeightAt(ws); wh += engine->gameData.getWaveHeightAt(ws);
if( ws.z < wh ) {
// If Not in water before
// If last position was above water
// Now Underwater
// Else Not Underwater
// Else
// Underwater
if( ! inWater && ws.z < wh && _lastHeight > wh ) {
ws.z = wh; ws.z = wh;
btVector3 bpos(ws.x, ws.y, ws.z); btVector3 bpos(ws.x, ws.y, ws.z);
@ -240,13 +248,14 @@ void CharacterObject::updateCharacter(float dt)
physObject->setWorldTransform(wt); physObject->setWorldTransform(wt);
physCharacter->setGravity(0.f); physCharacter->setGravity(0.f);
_inWater = true; inWater = true;
} }
else { else {
physCharacter->setGravity(9.81f); physCharacter->setGravity(9.81f);
_inWater = false; inWater = false;
} }
} }
_lastHeight = getPosition().z;
} }
} }

View File

@ -65,19 +65,19 @@ void InstanceObject::tick(float dt)
wH = engine->gameData.waterHeights[hI]; wH = engine->gameData.waterHeights[hI];
wH += engine->gameData.getWaveHeightAt(ws); wH += engine->gameData.getWaveHeightAt(ws);
if( vH <= wH ) { if( vH <= wH ) {
_inWater = true; inWater = true;
} }
else { else {
_inWater = false; inWater = false;
} }
} }
else { else {
_inWater = false; inWater = false;
} }
} }
_lastHeight = ws.z; _lastHeight = ws.z;
if( _inWater ) { if( inWater ) {
float oZ = -(body->collisionHeight * (dynamics->bouancy/100.f)); float oZ = -(body->collisionHeight * (dynamics->bouancy/100.f));
body->body->activate(true); body->body->activate(true);
// Damper motion // Damper motion

View File

@ -245,24 +245,24 @@ void VehicleObject::tickPhysics(float dt)
// and was not underwater here in the last tick // and was not underwater here in the last tick
if( _lastHeight >= wH ) { if( _lastHeight >= wH ) {
// we are for real, underwater // we are for real, underwater
_inWater = true; inWater = true;
} }
else if( _inWater == false ) { else if( inWater == false ) {
// It's just a tunnel or something, we good. // It's just a tunnel or something, we good.
_inWater = false; inWater = false;
} }
} }
else { else {
// The water is beneath us // The water is beneath us
_inWater = false; inWater = false;
} }
} }
else { else {
_inWater = false; inWater = false;
} }
} }
if( _inWater ) { if( inWater ) {
// Ensure that vehicles don't fall asleep at the top of a wave. // Ensure that vehicles don't fall asleep at the top of a wave.
if(! physBody->isActive() ) if(! physBody->isActive() )
{ {

View File

@ -108,6 +108,8 @@ RWGame::RWGame(const std::string& gamepath, int argc, char* argv[])
std::string name = "radar" + num + std::to_string(m); std::string name = "radar" + num + std::to_string(m);
engine->gameData.loadTXD(name + ".txd"); engine->gameData.loadTXD(name + ".txd");
} }
getRenderer()->water.setWaterTable(engine->gameData.waterHeights, 48, engine->gameData.realWater, 128*128);
auto loading = new LoadingState(this); auto loading = new LoadingState(this);
if( newgame ) if( newgame )

View File

@ -117,6 +117,15 @@ void IngameState::tick(float dt)
_lookAngles.x += deltaMouse.x / 100.0; _lookAngles.x += deltaMouse.x / 100.0;
_lookAngles.y += deltaMouse.y / 100.0; _lookAngles.y += deltaMouse.y / 100.0;
while(_lookAngles.x > glm::pi<float>())
{
_lookAngles.x -= 2.f * glm::pi<float>();
}
while(_lookAngles.x < -glm::pi<float>())
{
_lookAngles.x += 2.f * glm::pi<float>();
}
if (_lookAngles.y > qpi) if (_lookAngles.y > qpi)
_lookAngles.y = qpi; _lookAngles.y = qpi;
@ -153,9 +162,38 @@ void IngameState::tick(float dt)
float speed = vehicle->physVehicle->getCurrentSpeedKmHour(); float speed = vehicle->physVehicle->getCurrentSpeedKmHour();
if( autolookTimer <= 0.f && std::abs(speed) > 1.f ) if( autolookTimer <= 0.f && std::abs(speed) > 1.f )
{ {
float d = glm::sign(speed) > 0.f ? 0.f : glm::radians(180.f); float b = glm::roll(vehicle->getRotation()) + glm::half_pi<float>();
auto atrophy = std::min(1.f * glm::sign(_lookAngles.x - d) * dt, _lookAngles.x - d); while( b > glm::pi<float>() )
_lookAngles.x -= atrophy; {
b -= 2.f * glm::pi<float>();
}
while( b < -glm::pi<float>() )
{
b += 2.f * glm::pi<float>();
}
if( speed < 0.f )
{
if( _lookAngles.x < 0.f )
{
b -= glm::pi<float>();
}
else
{
b += glm::pi<float>();
}
}
float aD = b - _lookAngles.x;
const float rotateSpeed = 1.f;
if( std::abs(aD) <= rotateSpeed * dt )
{
_lookAngles.x = b;
}
else
{
_lookAngles.x += glm::sign(aD) * rotateSpeed * dt;
}
angle = glm::angleAxis(_lookAngles.x, glm::vec3(0.f, 0.f, 1.f));
} }
} }

View File

@ -10,8 +10,10 @@ class IngameState : public State
bool started; bool started;
bool test; bool test;
ViewCamera _look; ViewCamera _look;
/** Player input */
glm::vec2 _lookAngles; glm::vec2 _lookAngles;
glm::vec3 _movement; glm::vec3 _movement;
/** Timer to reset _lookAngles to forward in vehicles */
float autolookTimer; float autolookTimer;
public: public:
IngameState(RWGame* game, bool test = false); IngameState(RWGame* game, bool test = false);