Face To Face With a Cube

Started by
2 comments, last by Reverse_Gecko 22 years, 4 months ago
How do you find whitch face of a cube is facing you given the xyz rotations? - Gecko - gecko@flatirons.org ------------------------- "A cow, now that cuold be useful" - Conker(Conkers BFD for N64) --------------------------
Jeff Bland (Reverse_Gecko)reversegecko@gmail.com
Advertisement
compute the face normal and the viewer''s direction , do the dot product and see if it is >90 actually check only for the numerator of the formula to be >0 ( this is a backfaceculling ) when you are done, check the vector''s direction if one is ''against'' another , you are facing that surface, do it for every cube''s surface , but you may also want to take a look at quaternions to check the direction is a little bit tricky you could divide the space in octants and retreive the spherical coordinates giving only the vector direction, ..good work..

Ok. Sounds Easy Enough. Ummm.... Do you know where i can find sample code?

- Gecko
- gecko@flatirons.org
-------------------------
"A cow, now that cuold be useful" - Conker(Conkers BFD for N64)
--------------------------
Jeff Bland (Reverse_Gecko)reversegecko@gmail.com
Unfortunately not because i have never had the need to do soemthing like that but computing a normal and doing a dot product is quite straighforward, the tricky part is calculating the vector directions, try to search for polar coordinates or spherical

try thi code

void GetAngles( fVect V,float *fPan, float *fPitch )
{
float dx, dy, dz;
dx = (float)V[0];
dy = (float)V[1];
dz = (float)V[2];
if(dz > 0.0001f)
{
*fPan = (float) -atan(dx/dz);
dz /= cos((float)(*fPan));
*fPitch = (float) atan(dy/dz);
} else if(dz < -EPSILON)
{
*fPan = (float) (__PI-atan(dx/dz));
dz /= cos((float)(*fPan)-__PI);
*fPitch = (float) -atan(dy/dz);
} else
{
*fPan = 0.0f;
*fPitch = (float)-__PI/2.0f;
}
}


This topic is closed to new replies.

Advertisement