views:

61

answers:

1

This is sort of a homework question, however no expectations for code or whatever just an idea or hint towards the following problem.

I have a set of cubes in 3D world coordinates and i have to display them using two projections in two separate areas, parallel and perspective. The parallel went fine, no problems there, however displaying the same scene using perspective projection is becoming a nuisance for me.

The world to screen coordinates seemed like a good idea, but i don't know on which coordinates to apply them to, the original real coordinates, the new coordinates.

Thank you for your time.

PS: we are only allowed Java2D Api.

A: 

To perform a perspective projection, you need two additional things: the perspective point (where the "eye" is) and the projection plane. With a parallel projection, the perspective point/eye and plane can be any arbitrary distance from the objects (e.g., the cubes). But it is a little more complex with perspective projection.

Once you establish your eye and projection plane, you will need to iterate over your cubes. Ideally, you would iterate over them from the farthest cube to the eye to the nearest - that way the nearer cubes will overwrite the farther ones.

For each cube, determine the distance from the eye for each point. Then for each face (again in order of decreasing distance), calculate the projected points for each vertex. You can skip those faces with occluded points (the farthest vertex for each cube).

To calculate the projected point for a particular vertex, you need to find the point on the projection plane. This point will be where the line from the eye to the vertex intersects the projection plane. This will require some math, but should not be too difficult.