Public Group

# Help with 3d math for showing a star

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

## 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 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.

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5
khawk
11

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633677
• Total Posts
3013281
×