mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 18:35:20 +00:00
Merge remote branch 'gus/collision' into collision
This commit is contained in:
commit
bd55cfdcf9
@ -72,7 +72,7 @@ std::pair<std::string, float> MWScene::getFacedHandle (MWWorld::World& world)
|
|||||||
//let's avoid the capsule shape of the player.
|
//let's avoid the capsule shape of the player.
|
||||||
centerRay.setOrigin(centerRay.getOrigin() + 20*centerRay.getDirection());
|
centerRay.setOrigin(centerRay.getOrigin() + 20*centerRay.getDirection());
|
||||||
btVector3 from(centerRay.getOrigin().x,-centerRay.getOrigin().z,centerRay.getOrigin().y);
|
btVector3 from(centerRay.getOrigin().x,-centerRay.getOrigin().z,centerRay.getOrigin().y);
|
||||||
btVector3 to(centerRay.getPoint(1000).x,-centerRay.getPoint(1000).z,centerRay.getPoint(1000).y);
|
btVector3 to(centerRay.getPoint(500).x,-centerRay.getPoint(500).z,centerRay.getPoint(500).y);
|
||||||
|
|
||||||
return eng->rayTest(from,to);
|
return eng->rayTest(from,to);
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ void MWScene::doPhysics (float duration, MWWorld::World& world,
|
|||||||
{
|
{
|
||||||
Ogre::Quaternion quat = yawNode->getOrientation();
|
Ogre::Quaternion quat = yawNode->getOrientation();
|
||||||
Ogre::Vector3 dir1(iter->second.x,iter->second.z,-iter->second.y);
|
Ogre::Vector3 dir1(iter->second.x,iter->second.z,-iter->second.y);
|
||||||
dir = 0.07*(quat*dir1);
|
dir = 0.025*(quat*dir1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//set the walk direction
|
//set the walk direction
|
||||||
@ -208,7 +208,7 @@ void MWScene::toggleCollisionMode()
|
|||||||
{
|
{
|
||||||
mFreeFly = false;
|
mFreeFly = false;
|
||||||
act->enableCollisions(true);
|
act->enableCollisions(true);
|
||||||
act->setGravity(10.);
|
act->setGravity(4.);
|
||||||
act->setVerticalVelocity(0);
|
act->setVerticalVelocity(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,18 +125,47 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool hasCollisionNode = hasRootCollisionNode(node);
|
||||||
|
|
||||||
//do a first pass
|
//do a first pass
|
||||||
handleNode(node,0,Ogre::Matrix3::IDENTITY,Ogre::Vector3::ZERO,1,false,false);
|
handleNode(node,0,Ogre::Matrix3::IDENTITY,Ogre::Vector3::ZERO,1,hasCollisionNode,false,false);
|
||||||
|
|
||||||
//if collide = false, then it does a second pass which create a shape for raycasting.
|
//if collide = false, then it does a second pass which create a shape for raycasting.
|
||||||
if(cShape->collide == false)
|
if(cShape->collide == false)
|
||||||
{
|
{
|
||||||
handleNode(node,0,Ogre::Matrix3::IDENTITY,Ogre::Vector3::ZERO,1,false,true);
|
std::cout << "collide = false "<<resourceName << std::endl;
|
||||||
|
handleNode(node,0,Ogre::Matrix3::IDENTITY,Ogre::Vector3::ZERO,1,hasCollisionNode,false,true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ManualBulletShapeLoader::hasRootCollisionNode(Nif::Node* node)
|
||||||
|
{
|
||||||
|
if (node->recType == Nif::RC_NiNode)
|
||||||
|
{
|
||||||
|
Nif::NodeList &list = ((Nif::NiNode*)node)->children;
|
||||||
|
int n = list.length();
|
||||||
|
for (int i=0; i<n; i++)
|
||||||
|
{
|
||||||
|
if (list.has(i))
|
||||||
|
{
|
||||||
|
if(hasRootCollisionNode(&list[i])) return true;;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (node->recType == Nif::RC_NiTriShape)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if(node->recType == Nif::RC_RootCollisionNode)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags,
|
void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags,
|
||||||
Ogre::Matrix3 parentRot,Ogre::Vector3 parentPos,float parentScale,bool isCollisionNode,bool raycastingOnly)
|
Ogre::Matrix3 parentRot,Ogre::Vector3 parentPos,float parentScale,bool hasCollisionNode,bool isCollisionNode,bool raycastingOnly)
|
||||||
{
|
{
|
||||||
// Accumulate the flags from all the child nodes. This works for all
|
// Accumulate the flags from all the child nodes. This works for all
|
||||||
// the flags we currently use, at least.
|
// the flags we currently use, at least.
|
||||||
@ -194,11 +223,11 @@ void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags,
|
|||||||
{
|
{
|
||||||
if (list.has(i))
|
if (list.has(i))
|
||||||
{
|
{
|
||||||
handleNode(&list[i], flags,finalRot,finalPos,finalScale,isCollisionNode,raycastingOnly);
|
handleNode(&list[i], flags,finalRot,finalPos,finalScale,hasCollisionNode,isCollisionNode,raycastingOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (node->recType == Nif::RC_NiTriShape && isCollisionNode)
|
else if (node->recType == Nif::RC_NiTriShape && (isCollisionNode || !hasCollisionNode))
|
||||||
{
|
{
|
||||||
cShape->collide = true;
|
cShape->collide = true;
|
||||||
handleNiTriShape(dynamic_cast<Nif::NiTriShape*>(node), flags,finalRot,finalPos,finalScale,raycastingOnly);
|
handleNiTriShape(dynamic_cast<Nif::NiTriShape*>(node), flags,finalRot,finalPos,finalScale,raycastingOnly);
|
||||||
@ -210,7 +239,7 @@ void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags,
|
|||||||
for (int i=0; i<n; i++)
|
for (int i=0; i<n; i++)
|
||||||
{
|
{
|
||||||
if (list.has(i))
|
if (list.has(i))
|
||||||
handleNode(&list[i], flags,finalRot,finalPos,finalScale,true,raycastingOnly);
|
handleNode(&list[i], flags,finalRot,finalPos,finalScale,hasCollisionNode,true,raycastingOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -277,6 +306,7 @@ void ManualBulletShapeLoader::handleNiTriShape(Nif::NiTriShape *shape, int flags
|
|||||||
}
|
}
|
||||||
NodeShape = new btBvhTriangleMeshShape(mTriMesh,true);
|
NodeShape = new btBvhTriangleMeshShape(mTriMesh,true);
|
||||||
currentShape->addChildShape(tr,NodeShape);
|
currentShape->addChildShape(tr,NodeShape);
|
||||||
|
std::cout << "tri";
|
||||||
}
|
}
|
||||||
|
|
||||||
void ManualBulletShapeLoader::load(const std::string &name,const std::string &group)
|
void ManualBulletShapeLoader::load(const std::string &name,const std::string &group)
|
||||||
|
@ -105,7 +105,12 @@ private:
|
|||||||
*Parse a node.
|
*Parse a node.
|
||||||
*/
|
*/
|
||||||
void handleNode(Nif::Node *node, int flags,
|
void handleNode(Nif::Node *node, int flags,
|
||||||
Ogre::Matrix3 parentRot,Ogre::Vector3 parentPos,float parentScale,bool isCollisionNode,bool raycastingOnly);
|
Ogre::Matrix3 parentRot,Ogre::Vector3 parentPos,float parentScale,bool hasCollisionNode,bool isCollisionNode,bool raycastingOnly);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Helpler function
|
||||||
|
*/
|
||||||
|
bool hasRootCollisionNode(Nif::Node* node);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*convert a NiTriShape to a bullet trishape.
|
*convert a NiTriShape to a bullet trishape.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user