Sign in to follow this  
Chumad

Help with 3d math for showing a star

Recommended Posts

I'm trying to solicit some help for calculating the x,y pixel loc of where to put a star that is defined in a 3d space. For 2d, I've found this is pretty simple. I setup an x,y for the star and an x,y for the camera. I subtract the camera's x,y from the star's x,y and plop a graphic out and the resulting x,y. How do I do this for 3d? Assuming I already have my star's xyz defined, how do I go about adding the camera to the equation? What math do I use to calculate the pixel x,y? What about the size of the star's radius if the camera happens to be zoomed in close/far? Thanks for any tips. Chu

Share this post


Link to post
Share on other sites
This is not a particularly easy thing to do compared to the 2d case. Before you start writing transformations from scratch, ask yourself if you wouldn't be better off learning the basics of a graphics API - for example, DirectX provides a pretty well-established and simple mechanism for doing this and hides most of the gory details from you.

The basic process involves three transformation matrices, generally called the world, view and projection matrices. In order, these do the following:

World matrix: Place the object in the world, dependent on the object's position, orientation and scale.
View matrix: Place the world in front of the virtual camera, dependent on the camera's position and orientation.
Projection matrix: Determine the screen coordinates of the objects (including the depth, to determine which objects should appear in front of others) dependent on the camera's field of view angle, aspect ratio, minimum and maximum view distance. This last step is probably the trickiest mathematically.

Understanding exactly how the transforms do what they do will require some linear algebra and trigonometry. But like I say, 3D graphics APIs can simplify this a great deal by creating the matrices for you based on a simplified set of variables (i.e. they provide functions for creating matrices to perform common transforms like translations, rotations etc. given your xyz coordinates)

This stuff is fundamental to 3D rendering so it's generally covered early in any tutorials, so have a browse around the web or bookshops. I like Frank Luna's "3D Game Programming" book, and it doesn't shy away too much from the mathematical details of this stage in the rendering process.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this