#### Archived

This topic is now archived and is closed to further replies.

# Face To Face With a Cube

This topic is 6151 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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) --------------------------

##### Share on other sites
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..

##### Share on other sites
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)
--------------------------

##### Share on other sites
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;
}
}

1. 1
2. 2
Rutin
21
3. 3
4. 4
frob
17
5. 5

• 9
• 12
• 9
• 33
• 13
• ### Forum Statistics

• Total Topics
632595
• Total Posts
3007267

×