Reputation: 612
I want to do kind of fish-eye culling in my game. So for each object listed to draw I wanna check if is in frustrum of camera. I do it this way:
D3DXVECTOR3 cameraPos;
D3DXVECTOR3 pos;
D3DXVECTOR3 cameraVector;//where camera is looking( camera->eye() - camera->pos() )
D3DXVECTOR3 direction = pos - cameraPos;
normalize( &direction );
normalize( &cameraVector );
float dot = cameraVector.x * direction.x + cameraVector.y * direction.y + cameraVector.z * direction.z;
//float cosvalue = cos( dot ); // i was calculatin cos of cos :)
float cosvalue = dot;
float angle = acos (cosvalue) * 180.0f / PI;
if( angle < 45.0f ) draw();
But I get weird results. For example ( angle < 50.0f) draws everywhere but no where I want so fish eye is empty. !(angle < 50.0f) draws what i want. But (angle < 40) draws nothing :( I am not shure if it's my angle calculation or it's floats problem :( Anyone?
Upvotes: 0
Views: 9576
Reputation: 24846
dot_product = a.x * b.x + a.y * b.y + a.z * b.z = a.len() * b.len * cos(angle)
thus:
cos(angle) = dot_product / (a.len * b.len)
Your code does a strange thing: you're actually calculating the cosine of the dot product instead!
Upvotes: 6