1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-25 06:35:30 +00:00

49 lines
1.9 KiB
C++
Raw Normal View History

2012-03-19 19:38:44 -04:00
#include "trace.h"
#include <map>
2013-02-08 13:12:34 -08:00
#include <btBulletDynamicsCommon.h>
#include <btBulletCollisionCommon.h>
2013-02-06 21:47:09 -08:00
#include "physic.hpp"
2012-03-19 19:38:44 -04:00
2013-02-08 13:12:34 -08:00
enum traceWorldType
2012-03-19 19:38:44 -04:00
{
2013-02-08 13:12:34 -08:00
collisionWorldTrace = 1,
pickWorldTrace = 2,
bothWorldTrace = collisionWorldTrace | pickWorldTrace
};
2012-03-19 19:38:44 -04:00
void newtrace(traceResults *results, const Ogre::Quaternion& orient, const Ogre::Vector3& start, const Ogre::Vector3& end, const Ogre::Vector3& BBHalfExtents, bool isInterior, OEngine::Physic::PhysicEngine *enginePass) //Traceobj was a Aedra Object
2012-03-19 19:38:44 -04:00
{
2013-02-08 13:12:34 -08:00
const btVector3 btstart(start.x, start.y, start.z + BBHalfExtents.z);
const btVector3 btend(end.x, end.y, end.z + BBHalfExtents.z);
const btQuaternion btorient (orient.x, orient.y, orient.z, orient.w);
2012-03-19 19:38:44 -04:00
2012-08-14 18:04:58 -04:00
const btBoxShape newshape(btVector3(BBHalfExtents.x, BBHalfExtents.y, BBHalfExtents.z));
2013-02-08 13:12:34 -08:00
//const btCapsuleShapeZ newshape(BBHalfExtents.x, BBHalfExtents.z * 2 - BBHalfExtents.x * 2);
const btTransform from(btorient, btstart);
const btTransform to(btorient, btend);
2013-02-08 13:12:34 -08:00
btCollisionWorld::ClosestConvexResultCallback newTraceCallback(btstart, btend);
2013-05-09 11:12:55 +01:00
newTraceCallback.m_collisionFilterMask = OEngine::Physic::CollisionType_World|OEngine::Physic::CollisionType_HeightMap|OEngine::Physic::CollisionType_Actor;
2013-02-08 13:12:34 -08:00
enginePass->dynamicsWorld->convexSweepTest(&newshape, from, to, newTraceCallback);
// Copy the hit data over to our trace results struct:
2013-02-20 04:14:52 -08:00
if(newTraceCallback.hasHit())
2013-02-08 13:12:34 -08:00
{
2013-02-20 04:14:52 -08:00
const btVector3& tracehitnormal = newTraceCallback.m_hitNormalWorld;
results->fraction = newTraceCallback.m_closestHitFraction;
results->planenormal = Ogre::Vector3(tracehitnormal.x(), tracehitnormal.y(), tracehitnormal.z());
results->endpos = (end-start)*results->fraction + start;
2013-02-08 13:12:34 -08:00
}
else
{
2013-02-20 04:14:52 -08:00
results->endpos = end;
results->planenormal = Ogre::Vector3(0.0f, 0.0f, 1.0f);
results->fraction = 1.0f;
2013-02-08 13:12:34 -08:00
}
2012-03-19 19:38:44 -04:00
}