From 8762f4a47abfd873acc036e70f24859105d0a6f7 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Wed, 15 Aug 2012 16:47:26 -0400 Subject: [PATCH] boxrotation nif field; commented functions --- apps/openmw/mwworld/physicssystem.cpp | 2 +- components/nifbullet/bullet_nif_loader.cpp | 6 +++--- components/nifbullet/bullet_nif_loader.hpp | 2 +- libs/openengine/bullet/BulletShapeLoader.h | 1 + libs/openengine/bullet/physic.cpp | 3 ++- libs/openengine/bullet/physic.hpp | 9 +++++++++ libs/openengine/bullet/pmove.cpp | 5 ++++- 7 files changed, 21 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index 3d4a08c69..d1e39c8b7 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -194,7 +194,7 @@ namespace MWWorld //playerphysics->ps.snappingImplemented = false; - + //playerphysics->ps.speed = 240; playerphysics->ps.viewangles.x = pitchQuat.getPitch().valueDegrees(); diff --git a/components/nifbullet/bullet_nif_loader.cpp b/components/nifbullet/bullet_nif_loader.cpp index fc7fb5ec2..6fec6241f 100644 --- a/components/nifbullet/bullet_nif_loader.cpp +++ b/components/nifbullet/bullet_nif_loader.cpp @@ -73,7 +73,7 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource) resourceName = cShape->getName(); cShape->collide = false; mBoundingBox = NULL; - boxTranslation = Ogre::Vector3(0,0,0); + cShape->boxTranslation = Ogre::Vector3(0,0,0); mTriMesh = new btTriangleMesh(); @@ -127,7 +127,6 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource) delete m_meshInterface; } }; - cShape->boxTranslation = boxTranslation; if(mBoundingBox != NULL) cShape->Shape = mBoundingBox; @@ -226,7 +225,8 @@ void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags, btVector3 boxsize = getbtVector((node->boundXYZ)); - boxTranslation = node->boundPos; + cShape->boxTranslation = node->boundPos; + cShape->boxRotation = node->boundRot; mBoundingBox = new btBoxShape(boxsize); } diff --git a/components/nifbullet/bullet_nif_loader.hpp b/components/nifbullet/bullet_nif_loader.hpp index beb4274b0..82ac227a0 100644 --- a/components/nifbullet/bullet_nif_loader.hpp +++ b/components/nifbullet/bullet_nif_loader.hpp @@ -102,7 +102,7 @@ private: std::string resourceName; std::string resourceGroup; - Ogre::Vector3 boxTranslation; + BulletShape* cShape;//current shape btTriangleMesh *mTriMesh; diff --git a/libs/openengine/bullet/BulletShapeLoader.h b/libs/openengine/bullet/BulletShapeLoader.h index c09f0dc7e..8640fd54f 100644 --- a/libs/openengine/bullet/BulletShapeLoader.h +++ b/libs/openengine/bullet/BulletShapeLoader.h @@ -32,6 +32,7 @@ public: btCollisionShape* Shape; Ogre::Vector3 boxTranslation; + Ogre::Quaternion boxRotation; //this flag indicate if the shape is used for collision or if it's for raycasting only. bool collide; }; diff --git a/libs/openengine/bullet/physic.cpp b/libs/openengine/bullet/physic.cpp index 2f0624470..0845864ef 100644 --- a/libs/openengine/bullet/physic.cpp +++ b/libs/openengine/bullet/physic.cpp @@ -336,9 +336,10 @@ namespace Physic btTransform tr; btBoxShape* box = dynamic_cast(body->getCollisionShape()); if(box != NULL){ - Ogre::Vector3 transrot = rotation * (shape->boxTranslation * scale); + Ogre::Vector3 transrot = rotation * shape->boxRotation * (shape->boxTranslation * scale); Ogre::Vector3 newPosition = transrot + position; tr.setOrigin(btVector3(newPosition.x, newPosition.y, newPosition.z)); + rotation = rotation * shape->boxRotation; } else tr.setOrigin(btVector3(position.x,position.y,position.z)); diff --git a/libs/openengine/bullet/physic.hpp b/libs/openengine/bullet/physic.hpp index 088bbc465..403af6c6c 100644 --- a/libs/openengine/bullet/physic.hpp +++ b/libs/openengine/bullet/physic.hpp @@ -145,10 +145,19 @@ namespace Physic /** * Create a RigidBody.It does not add it to the simulation, but it does add it to the rigidBody Map, * so you can get it with the getRigidBody function. + + After created, the body is set to the correct rotation, position, and scale */ RigidBody* createAndAdjustRigidBody(std::string mesh,std::string name,float scale, Ogre::Vector3 position, Ogre::Quaternion rotation); + /** + * Adjusts a rigid body to the right position and rotation + */ + void adjustRigidBody(BulletShapePtr shape, RigidBody* body, float scale, Ogre::Vector3 position, Ogre::Quaternion rotation); + /** + Mainly used to (but not limited to) adjust rigid bodies based on box shapes to the right position and rotation. + */ void boxAdjustExternal(std::string mesh, RigidBody* body, float scale, Ogre::Vector3 position, Ogre::Quaternion rotation); /** * Add a HeightField to the simulation diff --git a/libs/openengine/bullet/pmove.cpp b/libs/openengine/bullet/pmove.cpp index 4c70971a3..32a11179f 100644 --- a/libs/openengine/bullet/pmove.cpp +++ b/libs/openengine/bullet/pmove.cpp @@ -657,10 +657,11 @@ static void PM_Accelerate( Ogre::Vector3& wishdir, float wishspeed, float accel // int i; float addspeed, accelspeed, currentspeed; + // currentspeed = pm->ps->velocity dot wishdir //currentspeed = DotProduct (pm->ps->velocity, wishdir); currentspeed = pm->ps.velocity.dotProduct(wishdir); - + addspeed = wishspeed - currentspeed; if (addspeed <= 0) return; @@ -675,6 +676,8 @@ static void PM_Accelerate( Ogre::Vector3& wishdir, float wishspeed, float accel //for (i=0 ; i<3 ; i++) //pm->ps->velocity[i] += accelspeed * wishdir[i]; pm->ps.velocity += (wishdir * accelspeed); + //pm->ps.velocity = wishdir * wishspeed; //New, for instant acceleration + } static bool PM_CheckJump(void)