forked from teamnwah/openmw-tes3coop
Separate adjustRigidBody function
This commit is contained in:
parent
e7329d5f8b
commit
1f5bc229e0
7 changed files with 43 additions and 30 deletions
|
@ -193,7 +193,7 @@ namespace MWWorld
|
|||
Ogre::Quaternion pitchQuat = pitchNode->getOrientation();
|
||||
|
||||
|
||||
|
||||
//playerphysics->ps.snappingImplemented = false;
|
||||
|
||||
|
||||
playerphysics->ps.viewangles.x = pitchQuat.getPitch().valueDegrees();
|
||||
|
@ -280,19 +280,20 @@ namespace MWWorld
|
|||
mEngine->deleteRigidBody(handle);
|
||||
}
|
||||
|
||||
void PhysicsSystem::moveObject (const std::string& handle, const Ogre::Vector3& position)
|
||||
void PhysicsSystem::moveObject (const std::string& handle, Ogre::SceneNode* node)
|
||||
{
|
||||
if (OEngine::Physic::RigidBody* body = mEngine->getRigidBody(handle))
|
||||
{
|
||||
// TODO very dirty hack to avoid crash during setup -> needs cleaning up to allow
|
||||
// start positions others than 0, 0, 0
|
||||
btTransform tr = body->getWorldTransform();
|
||||
Ogre::Vector3 position = node->getPosition();
|
||||
tr.setOrigin(btVector3(position.x,position.y,position.z));
|
||||
body->setWorldTransform(tr);
|
||||
}
|
||||
if (OEngine::Physic::PhysicActor* act = mEngine->getCharacter(handle))
|
||||
{
|
||||
// TODO very dirty hack to avoid crash during setup -> needs cleaning up to allow
|
||||
/*// TODO very dirty hack to avoid crash during setup -> needs cleaning up to allow
|
||||
// start positions others than 0, 0, 0
|
||||
if (handle == "player")
|
||||
{
|
||||
|
@ -301,31 +302,32 @@ namespace MWWorld
|
|||
else
|
||||
{
|
||||
act->setPosition(btVector3(position.x,position.y,position.z));
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsSystem::rotateObject (const std::string& handle, const Ogre::Quaternion& rotation)
|
||||
void PhysicsSystem::rotateObject (const std::string& handle, Ogre::SceneNode* node)
|
||||
{
|
||||
if (OEngine::Physic::PhysicActor* act = mEngine->getCharacter(handle))
|
||||
/*if (OEngine::Physic::PhysicActor* act = mEngine->getCharacter(handle))
|
||||
{
|
||||
act->setRotation(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w));
|
||||
}
|
||||
}*/
|
||||
if (OEngine::Physic::RigidBody* body = mEngine->getRigidBody(handle))
|
||||
{
|
||||
Ogre::Quaternion rotation = node->getOrientation();
|
||||
body->getWorldTransform().setRotation(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w));
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsSystem::scaleObject (const std::string& handle, float scale)
|
||||
void PhysicsSystem::scaleObject (const std::string& handle, Ogre::SceneNode* node)
|
||||
{
|
||||
if(handleToMesh.find(handle) != handleToMesh.end())
|
||||
{
|
||||
btTransform transform = mEngine->getRigidBody(handle)->getWorldTransform();
|
||||
removeObject(handle);
|
||||
|
||||
Ogre::Quaternion quat = Ogre::Quaternion(transform.getRotation().getW(), transform.getRotation().getX(), transform.getRotation().getY(), transform.getRotation().getZ());
|
||||
Ogre::Vector3 vec = Ogre::Vector3(transform.getOrigin().getX(), transform.getOrigin().getY(), transform.getOrigin().getZ());
|
||||
float scale = node->getScale().x;
|
||||
Ogre::Quaternion quat = node->getOrientation();
|
||||
Ogre::Vector3 vec = node->getPosition();
|
||||
addObject(handle, handleToMesh[handle], quat, scale, vec);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,11 +34,11 @@ namespace MWWorld
|
|||
|
||||
void removeObject (const std::string& handle);
|
||||
|
||||
void moveObject (const std::string& handle, const Ogre::Vector3& position);
|
||||
void moveObject (const std::string& handle, Ogre::SceneNode* node);
|
||||
|
||||
void rotateObject (const std::string& handle, const Ogre::Quaternion& rotation);
|
||||
void rotateObject (const std::string& handle, Ogre::SceneNode* node);
|
||||
|
||||
void scaleObject (const std::string& handle, float scale);
|
||||
void scaleObject (const std::string& handle, Ogre::SceneNode* node);
|
||||
|
||||
bool toggleCollisionMode();
|
||||
|
||||
|
|
|
@ -585,7 +585,7 @@ namespace MWWorld
|
|||
{
|
||||
moveObjectImp(ptr, x, y, z);
|
||||
|
||||
mPhysics->moveObject (ptr.getRefData().getHandle(), Ogre::Vector3 (x, y, z));
|
||||
mPhysics->moveObject (ptr.getRefData().getHandle(), ptr.getRefData().getBaseNode());
|
||||
}
|
||||
|
||||
void World::scaleObject (const Ptr& ptr, float scale)
|
||||
|
@ -595,7 +595,7 @@ namespace MWWorld
|
|||
ptr.getCellRef().scale = scale;
|
||||
//scale = scale/ptr.getRefData().getBaseNode()->getScale().x;
|
||||
ptr.getRefData().getBaseNode()->setScale(scale,scale,scale);
|
||||
mPhysics->scaleObject( ptr.getRefData().getHandle(), scale );
|
||||
mPhysics->scaleObject( ptr.getRefData().getHandle(), ptr.getRefData().getBaseNode());
|
||||
}
|
||||
|
||||
void World::rotateObject (const Ptr& ptr,float x,float y,float z)
|
||||
|
@ -610,7 +610,7 @@ namespace MWWorld
|
|||
Ogre::Quaternion roty(Ogre::Degree(-y),Ogre::Vector3::UNIT_Y);
|
||||
Ogre::Quaternion rotz(Ogre::Degree(-z),Ogre::Vector3::UNIT_Z);
|
||||
ptr.getRefData().getBaseNode()->setOrientation(rotx*roty*rotz);
|
||||
mPhysics->rotateObject(ptr.getRefData().getHandle(),ptr.getRefData().getBaseNode()->getOrientation());
|
||||
mPhysics->rotateObject(ptr.getRefData().getHandle(),ptr.getRefData().getBaseNode());
|
||||
}
|
||||
|
||||
void World::indexToPosition (int cellX, int cellY, float &x, float &y, bool centre) const
|
||||
|
|
|
@ -129,7 +129,7 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource)
|
|||
};
|
||||
cShape->boxTranslation = boxTranslation;
|
||||
if(mBoundingBox != NULL)
|
||||
cShape->Shape = mBoundingBox;
|
||||
cShape->Shape = mBoundingBox;
|
||||
|
||||
else
|
||||
{
|
||||
|
|
|
@ -332,6 +332,20 @@ namespace Physic
|
|||
mHeightFieldMap.erase(name);
|
||||
}
|
||||
|
||||
void PhysicEngine::adjustRigidBody(BulletShapePtr shape, RigidBody* body, float scale, Ogre::Vector3 position, Ogre::Quaternion rotation){
|
||||
btTransform tr;
|
||||
btBoxShape* box = dynamic_cast<btBoxShape*>(body->getCollisionShape());
|
||||
if(box != NULL){
|
||||
Ogre::Vector3 transrot = rotation * (shape->boxTranslation * scale);
|
||||
Ogre::Vector3 newPosition = transrot + position;
|
||||
tr.setOrigin(btVector3(newPosition.x, newPosition.y, newPosition.z));
|
||||
}
|
||||
else
|
||||
tr.setOrigin(btVector3(position.x,position.y,position.z));
|
||||
tr.setRotation(btQuaternion(rotation.x,rotation.y,rotation.z,rotation.w));
|
||||
body->setWorldTransform(tr);
|
||||
}
|
||||
|
||||
RigidBody* PhysicEngine::createAndAdjustRigidBody(std::string mesh,std::string name,float scale, Ogre::Vector3 position, Ogre::Quaternion rotation)
|
||||
{
|
||||
std::string sid = (boost::format("%07.3f") % scale).str();
|
||||
|
@ -355,17 +369,9 @@ namespace Physic
|
|||
RigidBody* body = new RigidBody(CI,name);
|
||||
body->collide = shape->collide;
|
||||
|
||||
btTransform tr;
|
||||
btBoxShape* box = dynamic_cast<btBoxShape*>(body->getCollisionShape());
|
||||
if(box != NULL){
|
||||
Ogre::Vector3 transrot = rotation * (shape->boxTranslation * scale);
|
||||
Ogre::Vector3 newPosition = transrot + position;
|
||||
tr.setOrigin(btVector3(newPosition.x, newPosition.y, newPosition.z));
|
||||
}
|
||||
else
|
||||
tr.setOrigin(btVector3(position.x,position.y,position.z));
|
||||
tr.setRotation(btQuaternion(rotation.x,rotation.y,rotation.z,rotation.w));
|
||||
body->setWorldTransform(tr);
|
||||
//Pass in BulletShape, RigidBody, scale, position, rotation
|
||||
|
||||
adjustRigidBody(shape, body, scale, position, rotation);
|
||||
|
||||
return body;
|
||||
|
||||
|
|
|
@ -148,6 +148,8 @@ namespace Physic
|
|||
*/
|
||||
RigidBody* createAndAdjustRigidBody(std::string mesh,std::string name,float scale, Ogre::Vector3 position, Ogre::Quaternion rotation);
|
||||
|
||||
void adjustRigidBody(BulletShapePtr shape, RigidBody* body, float scale, Ogre::Vector3 position, Ogre::Quaternion rotation);
|
||||
|
||||
/**
|
||||
* Add a HeightField to the simulation
|
||||
*/
|
||||
|
|
|
@ -21,6 +21,7 @@ void newtrace(traceResults* const results, const Ogre::Vector3& start, const Ogr
|
|||
//if (!traceobj->incellptr)
|
||||
// return;
|
||||
|
||||
|
||||
const Ogre::Vector3 rayDir = end - start;
|
||||
|
||||
|
||||
|
@ -35,6 +36,7 @@ void newtrace(traceResults* const results, const Ogre::Vector3& start, const Ogr
|
|||
//Ogre::Vector3 endReplace = startReplace;
|
||||
//endReplace.z -= .25;
|
||||
|
||||
|
||||
const bool hasHit = NewPhysicsTrace<collisionWorldTrace>(&out, start, end, BBHalfExtents, Ogre::Vector3(0.0f, 0.0f,0.0f), isInterior, enginePass);
|
||||
|
||||
if (out.fraction < 0.001f)
|
||||
|
@ -104,7 +106,8 @@ const bool NewPhysicsTrace(NewPhysTraceResults* const out, const Ogre::Vector3&
|
|||
const btVector3 btend(end.x, end.y, end.z);
|
||||
const btQuaternion btrot(rotation.y, rotation.x, rotation.z); //y, x, z
|
||||
|
||||
const btBoxShape newshape(btVector3(BBHalfExtents.x, BBHalfExtents.y, BBHalfExtents.z));
|
||||
const btBoxShape newshape(btVector3(BBHalfExtents.x, BBHalfExtents.y, BBHalfExtents.z));
|
||||
//const btCapsuleShapeZ newshape(BBHalfExtents.x, BBHalfExtents.z * 2 - BBHalfExtents.x * 2);
|
||||
const btTransform from(btrot, btstart);
|
||||
const btTransform to(btrot, btend);
|
||||
|
||||
|
|
Loading…
Reference in a new issue