0

I have a problem getting ray testing working in bullet physics. The raytest only works for objects which have an identity transform. If there is any translation, then the ray test is calculated wrong. This is the code: [code]

            btTransform trans;
            trans.setIdentity();
            trans.setFromOpenGLMatrix(matrix.m);
            btDefaultMotionState* motionState = new btDefaultMotionState(trans);
            btRigidBody::btRigidBodyConstructionInfo rbInfo(
                0, motionState, m_pVertexBuffer->GetBulletShape(), btVector3(0,0,0));
            btRigidBody* body = new btRigidBody(rbInfo);      
            g_physics.GetWorld()->addRigidBody(body);
    ....
        g_physics.GetWorld()->updateAabbs();
        g_physics.GetWorld()->computeOverlappingPairs();
        btVector3 btStart(x1, y1, z1);
        btVector3 btEnd(x2, y2, z2);
        btCollisionWorld::ClosestRayResultCallback ray(btStart, btEnd);


// Perform raycast
    g_physics.GetWorld()->rayTest(btStart, btEnd, ray);
    if (ray.hasHit()) 
    {
        btEnd = ray.m_hitPointWorld;
    }

[/code] Now, my game is using the z-axis as up, but that shouldn't be a problem as the ray is also entered as z up.

weston
  • 54,145
  • 21
  • 145
  • 203
user3259383
  • 149
  • 1
  • 9

0 Answers0