updated Raytracer demo, to enable non-world ray test
disable USE_WORLD_RAYCAST to see low level method to do ray testing, using one of the convex casting methods (tracing a point against a convex)
This commit is contained in:
@@ -108,7 +108,7 @@ static const int numObjects = 1;
|
|||||||
/// simplex contains the vertices, and some extra code to draw and debug
|
/// simplex contains the vertices, and some extra code to draw and debug
|
||||||
static GL_Simplex1to4 simplex;
|
static GL_Simplex1to4 simplex;
|
||||||
|
|
||||||
static btCollisionShape* shapePtr[maxNumObjects];
|
static btConvexShape* shapePtr[maxNumObjects];
|
||||||
static btTransform transforms[maxNumObjects];
|
static btTransform transforms[maxNumObjects];
|
||||||
|
|
||||||
renderTexture* raytracePicture = 0;
|
renderTexture* raytracePicture = 0;
|
||||||
@@ -329,7 +329,11 @@ void Raytracer::displayCallback()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// btConvexCast::CastResult rayResult;
|
#define USE_WORLD_RAYCAST 1
|
||||||
|
#ifndef USE_WORLD_RAYCAST
|
||||||
|
btConvexCast::CastResult rayResult;
|
||||||
|
#endif
|
||||||
|
|
||||||
btTransform rayToTrans;
|
btTransform rayToTrans;
|
||||||
rayToTrans.setIdentity();
|
rayToTrans.setIdentity();
|
||||||
btVector3 rayTo;
|
btVector3 rayTo;
|
||||||
@@ -362,28 +366,38 @@ void Raytracer::displayCallback()
|
|||||||
if (btRayAabb(rayFrom,rayTo,aabbMin,aabbMax,hitLambda,hitNormal))
|
if (btRayAabb(rayFrom,rayTo,aabbMin,aabbMax,hitLambda,hitNormal))
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#ifdef USE_WORLD_RAYCAST
|
||||||
btCollisionWorld::rayTestSingle(rayFromTrans,rayToTrans,
|
btCollisionWorld::rayTestSingle(rayFromTrans,rayToTrans,
|
||||||
&tmpObj,
|
&tmpObj,
|
||||||
shapePtr[s],
|
shapePtr[s],
|
||||||
transforms[s],
|
transforms[s],
|
||||||
resultCallback);
|
resultCallback);
|
||||||
|
if (resultCallback.HasHit())
|
||||||
|
{
|
||||||
|
//float fog = 1.f - 0.1f * rayResult.m_fraction;
|
||||||
|
resultCallback.m_hitNormalWorld.normalize();//.m_normal.normalize();
|
||||||
|
btVector3 worldNormal = resultCallback.m_hitNormalWorld;
|
||||||
|
|
||||||
|
#else //use USE_WORLD_RAYCAST
|
||||||
|
//reset previous result
|
||||||
|
rayResult.m_fraction = 1.f;
|
||||||
|
|
||||||
//choose the continuous collision detection method
|
//choose the continuous collision detection method
|
||||||
//btSubsimplexConvexCast convexCaster(&pointShape,shapePtr[s],&simplexSolver);
|
|
||||||
//GjkConvexCast convexCaster(&pointShape,shapePtr[0],&simplexSolver);
|
|
||||||
//ContinuousConvexCollision convexCaster(&pointShape,shapePtr[0],&simplexSolver,0);
|
|
||||||
|
|
||||||
//reset previous result
|
btSubsimplexConvexCast convexCaster(&pointShape,shapePtr[s],&simplexSolver);
|
||||||
//rayResult.m_fraction = 1.f;
|
//btGjkConvexCast convexCaster(&pointShape,shapePtr[0],&simplexSolver);
|
||||||
if (resultCallback.HasHit())
|
//btContinuousConvexCollision convexCaster(&pointShape,shapePtr[0],&simplexSolver,0);
|
||||||
// if (convexCaster.calcTimeOfImpact(rayFromTrans,rayToTrans,transforms[s],transforms[s],rayResult))
|
|
||||||
{
|
if (convexCaster.calcTimeOfImpact(rayFromTrans,rayToTrans,transforms[s],transforms[s],rayResult))
|
||||||
//float fog = 1.f - 0.1f * rayResult.m_fraction;
|
{
|
||||||
resultCallback.m_hitNormalWorld.normalize();//.m_normal.normalize();
|
btVector3 worldNormal;
|
||||||
|
worldNormal = transforms[s].getBasis() *rayResult.m_normal;
|
||||||
|
worldNormal.normalize();
|
||||||
|
#endif // USE_WORLD_RAYCAST
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
btVector3 worldNormal = resultCallback.m_hitNormalWorld;
|
|
||||||
// worldNormal = transforms[s].getBasis() *rayResult.m_normal;
|
|
||||||
|
|
||||||
|
|
||||||
float lightVec0 = worldNormal.dot(btVector3(0,-1,-1));//0.4f,-1.f,-0.4f));
|
float lightVec0 = worldNormal.dot(btVector3(0,-1,-1));//0.4f,-1.f,-0.4f));
|
||||||
|
|||||||
Reference in New Issue
Block a user