MilGra
milgra
about
articles
projects

blogroll
bit-101
coding horror
blameit
failblog
beszeljukmac
sghu

navigation
posts
docs
admin

Projection Plane Based Real 3D


All children, from the age of 6 dreams of an own 3D engine. Even I did that. That's why i have written this tutorial, to make those people`s work easier who couldn't succeeded in doing so.

PART 1. THE THEORY

What is it about? We have a point in the 3 dimensional space, and we would like to project it perpendicularly to an arbitrary plane, and we have to determine the projected points position relative to a given point on the plane. We can define a plane in many ways, but in this case the best way is to define it by a normal vector and a base point, so it will be much more easier to move it. In addition, we can at once use the normal vector as the position vector of the line going through the chosen point in the 3D space.



We can define the intersection point by using the parametric equations of the line (normal to the plane, going through the point P) and the plane. However, we can't determine a relative position directly yet, because we only know one point related to the plane. We need two more points related to the plane with which we will be able to determine the position of S.



The simplest way is to rotate the plane's normal onto the plane to such a position where it is parallel to xz plane thus providing a fix axis. The other vector can be calculated by the vectorial multiplication of the normal and the previously created vector. If we have all this, then we only need to calculate the relative position of S.



We only need to determine the angles between SA vector, and the directional vectors, and we have to change into the planes A origined, 2 dimensional coordinate system.



PART 2. ALL THIS IN PRACTICE

Everything has been good and easy so far, but how the hell can we implement this? So, it's no easy matter, i suffered for 3 weeks, until i managed to structure the code in a simple and clean form.
We need two classes, the first - and the most important - is the Vector class, since we only use vectors during the projection, and the second is the Plane class, in which we can carry out other, plane-related functions.
But let's see the Vector class first. It must have all the used vector operations.

Vector Class Source Code
Plane Class Source Code

And thats all folks! I've further tuned the final version to make things more spectacular, download it and examine it to your hearts content.







Source files

Article on gotoandplay.it

MilGra


powered by kure