1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-25 11:52:40 +01:00

Fix Dynamic objects not visually moving

This commit is contained in:
Daniel Evans 2015-04-27 04:12:58 +01:00
parent 85b1ab120f
commit 0507bfdae6
4 changed files with 44 additions and 24 deletions

View File

@ -30,6 +30,9 @@ public:
void changeModel(std::shared_ptr<ObjectData> incoming);
virtual glm::vec3 getPosition() const;
virtual glm::quat getRotation() const;
virtual void setRotation(const glm::quat& r);
virtual bool takeDamage(const DamageInfo& damage);

View File

@ -47,6 +47,10 @@ void InstanceObject::tick(float dt)
engine->dynamicsWorld->addRigidBody(body->body);
}
}
else
{
_updateLastTransform();
}
auto _bws = body->body->getWorldTransform().getOrigin();
glm::vec3 ws(_bws.x(), _bws.y(), _bws.z());
@ -115,20 +119,40 @@ void InstanceObject::changeModel(std::shared_ptr<ObjectData> incoming)
{
if( body ) {
delete body;
body = nullptr;
}
object = incoming;
if( incoming ) {
body = new CollisionInstance;
auto bod = new CollisionInstance;
if( body->createPhysicsBody(this, object->modelName, dynamics.get()) )
if( bod->createPhysicsBody(this, object->modelName, dynamics.get()) )
{
body->body->setActivationState(ISLAND_SLEEPING);
bod->body->setActivationState(ISLAND_SLEEPING);
body = bod;
}
}
}
glm::vec3 InstanceObject::getPosition() const
{
if( body ) {
btVector3 Pos = body->body->getWorldTransform().getOrigin();
return glm::vec3(Pos.x(), Pos.y(), Pos.z());
}
return position;
}
glm::quat InstanceObject::getRotation() const
{
if( body ) {
btQuaternion rot = body->body->getWorldTransform().getRotation();
return glm::quat(rot.w(), rot.x(), rot.y(), rot.z());
}
return rotation;
}
void InstanceObject::setRotation(const glm::quat &r)
{
if( body ) {

View File

@ -27,7 +27,7 @@ StdOutReciever logPrinter;
RWGame::RWGame(const std::string& gamepath, int argc, char* argv[])
: state(nullptr), engine(nullptr), renderer(nullptr), script(nullptr), inFocus(true),
showDebugStats(false), showDebugPaths(false),
showDebugStats(false), showDebugPaths(false), showDebugPhysics(false),
accum(0.f), timescale(1.f)
{
size_t w = GAME_WINDOW_WIDTH, h = GAME_WINDOW_HEIGHT;
@ -434,26 +434,6 @@ void RWGame::render(float alpha, float time)
auto rendertime = renderer->getRenderer()->popDebugGroup();
#if 0
debug->setShaderProgram(engine->renderer.worldProg);
if( engine->state.player )
{
if( engine->state.player->getCharacter()->getCurrentVehicle() )
{
auto v = engine->state.player->getCharacter()->getCurrentVehicle();
for( auto& p : v->dynamicParts )
{
if( p.second.body )
{
engine->dynamicsWorld->debugDrawObject(p.second.body->getWorldTransform(), p.second.body->getCollisionShape(), btVector3(1.f, 0.f, 0.f));
engine->dynamicsWorld->debugDrawConstraint(p.second.constraint);
}
}
}
}
debug->flush(&engine->renderer);
#endif
if( showDebugPaths )
{
renderDebugPaths(time);
@ -463,6 +443,15 @@ void RWGame::render(float alpha, float time)
{
renderDebugStats(time, rendertime);
}
if( showDebugPhysics )
{
if( engine )
{
engine->dynamicsWorld->debugDrawWorld();
debug->flush(renderer);
}
}
drawOnScreenText(engine, renderer);
}
@ -612,6 +601,9 @@ void RWGame::globalKeyEvent(const sf::Event& event)
case sf::Keyboard::F2:
showDebugPaths = ! showDebugPaths;
break;
case sf::Keyboard::F3:
showDebugPhysics = ! showDebugPhysics;
break;
default: break;
}
}

View File

@ -27,6 +27,7 @@ class RWGame
ViewCamera lastCam, nextCam;
bool showDebugStats;
bool showDebugPaths;
bool showDebugPhysics;
int lastDraws; /// Number of draws issued for the last frame.
float accum;