Most of the time it works, but for some reason every once in a while it intersects on the hit side between on a value -0.000015 to +0.000015 different of the point it should be hitting instead(x.000000 that is).
For instance let's say we hit the face of block 100,100,100 on the z-side from some arbitrary position around 100,100,110 that should yield an intersection at something like 100.934312, 100.232241, 100.000000 but sometimes instead I get values like 100.934312, 100.232241, 99.999985 or 100.934312, 100.232241, 100.000002.
I have absolutely no idea why this is happening, can someone shed some light on this issue for me? I'm using a triangle mesh shape for rigid body collision and this is the code to make it:
Code: Select all
if (Mesh->getMeshBuffer(0)->getIndexCount())
{
BulletMesh = new btTriangleMesh;
S3DVertex *Vertices = (S3DVertex*)Mesh->getMeshBuffer(0)->getVertices();
u16* Indices = Mesh->getMeshBuffer(0)->getIndices();
for (u32 i = 0; i < Mesh->getMeshBuffer(0)->getIndexCount(); i += 3)
{
vector3df Tri1Pos = Vertices[Indices[i]].Pos;
vector3df Tri2Pos = Vertices[Indices[i + 1]].Pos;
vector3df Tri3Pos = Vertices[Indices[i + 2]].Pos;
BulletMesh->addTriangle(btVector3(Tri1Pos.X, Tri1Pos.Y, Tri1Pos.Z), btVector3(Tri2Pos.X, Tri2Pos.Y, Tri2Pos.Z), btVector3(Tri3Pos.X, Tri3Pos.Y, Tri3Pos.Z));
}
btBvhTriangleMeshShape *Shape = new btBvhTriangleMeshShape(BulletMesh, true);
btScalar Mass = 0;
btVector3 FallInertia(0, 0, 0);
btDefaultMotionState *MotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 0, 0)));
btRigidBody::btRigidBodyConstructionInfo CI(Mass, MotionState, Shape, FallInertia);
RigidBody = new btRigidBody(CI);
DynamicsWorld->addRigidBody(RigidBody);
}
Code: Select all
line3d<f32> Ray;
Ray.start = IrrCam->getPosition();
Ray.end = Ray.start + (IrrCam->getTarget() - Ray.start).normalize() * 256.0f;
btVector3 RayStart(Ray.start.X, Ray.start.Y, Ray.start.Z);
btVector3 RayEnd(Ray.end.X, Ray.end.Y, Ray.end.Z);
btCollisionWorld::ClosestRayResultCallback RayCallback(RayStart, RayEnd);
DynamicsWorld->rayTest(RayStart, RayEnd, RayCallback);
Code: Select all
printf("Test: %f %f %f\n\n", RayCallback.m_hitPointWorld.x(), RayCallback.m_hitPointWorld.y(), RayCallback.m_hitPointWorld.z());
Also! An additional question... Is it possible to get the coordinates of each vertex of the triangle that you hit with a raycast? Irrlicht has that feature and it's very nifty.