Not drawing objects behind camera

Started by
24 comments, last by L. Spiro 12 years, 6 months ago
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).
Advertisement
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
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?
dot product of two vectors
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..
XD im a math noob, what is dot product? the product of 2 dots?
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
So by multiplying the objects points (X',Y',Z') and the players vector (X,Y,Z), i can tell if the object is visible?

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: 61b787a32065fdf49cc7afe06fc27494.png 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..
Thanks! it makes sense now, but how would a stationary object have a vector? it makes sense if it just has points.

This topic is closed to new replies.

Advertisement