Jump to content
  • Advertisement
Sign in to follow this  
BennettSteele

Not drawing objects behind camera

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
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

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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: 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..

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!