# Not drawing objects behind camera

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

## Recommended Posts

I have lets say, a 3d point, the player (at 1,1,1) and the objects being drawn (their positions being their center too), lets say (2,2,2) or (0,0,0), how would i check to see if that is behind them? my camera has a horisontal and verticle axis, in degrees (0-360).

##### Share on other sites
For simple, small objects you can use D3DXVec3Dot(vObjectDistanceToCamera, vCameraDirection) and compare the returned value - objects behind the camera will return a negative while objects in front of the camera a positive value (or it could be flipped, try it out..). For more complex situations with large objects, you have to use more advanced techniques like view frustum culling

##### Share on other sites
What library is that in? also, what if i just used a vector for for the camera, and then check the center point of the box to see if it some-what in the opposite direction of the point?

##### Share on other sites
dot product of two vectors

##### Share on other sites
What library is that in?[/quote]

Oh, sry, I assumed you use DirectX (thats the libary). However the function does nothing more than calculating the dot-product, every math libary should have such a function. If not, you can calculate it yourself, just google it.

also, what if i just used a vector for for the camera, and then check the center point of the box to see if it some-what in the opposite direction of the point? [/quote]

Thats exactly what I suggested you to do, and what dot-product can be used for. However, be aware that if a object is like 100 world units long in your game, the center of the object could be behind the camera while parts of the object are actually in front of it. This is where view-frustum culling comes into play, it is easy to implement, I spent about 30 minutes or less to do so from the link I posted you today..

##### Share on other sites
XD im a math noob, what is dot product? the product of 2 dots?

##### Share on other sites
No, dot product can mean many things.. when it comes to maths my english is usually on its limits so just have a read here: Wikipedia: Dot products

##### Share on other sites
So by multiplying the objects points (X',Y',Z') and the players vector (X,Y,Z), i can tell if the object is visible?

##### Share on other sites

So by multiplying the objects points (X',Y',Z') and the players vector (X,Y,Z), i can tell if the object is visible?

Almost. Precicely, its this: In code: float dot = acos( (v1.x*v2.x +v1.y*v2.y +v1.z*v2.z) / ( sqrt(v1.x^2+v1.y^2+v1.z^2) * sqrt(v2.x^2+v1.y^2+v1.z^2) . If dot <= 0, the vectors are pointing in opposite directions. Don't be afraid of the formula I supplied, actually its easier to use, but I don't know what type of maths libaries you are using. My formula can be used without having access to any functions like D3DXVec3Length() which you could use instead of the sqrt()-statement..

##### Share on other sites
Thanks! it makes sense now, but how would a stationary object have a vector? it makes sense if it just has points.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 11
• 23
• 42
• 75