Hello,
this is my first post here so I hope I am writing in the right area.
I am currently writing my own simple 3D-Engine and everything is fine so far.
But I have a little problem: In order to draw pixels on the screen with my engine I have to use a simple DrawLine function that draws line between two two-dimensional points ( with x and y coordinates ). But I use three-dimensional coordinates ( with x, y and z coordinates ) in my engine.
Now I have to render or translate those three-dimensional coordinates with that additional depth coordinate z into simple two-dimensional coordinates.
I have tried to figure out the right algorhytm for days, but I just don't seem to make any progress at all.
I wrote two functions, that are supposed to do the whole rendering or translating process.
Here are the two functions:
function TranslateCoordinatesX ( int pointx, int pointz )
// translates three-dimensional points with x, y and z coordinates to two dimensional
// ones with only x and y coordinates
{
// define the new x-coordinate
int pointnewx;
// translate the coordinates
if ( pointx < 160 )
pointnewx = pointx + pointz;
else if ( pointx > 160 )
pointnewx = pointx - pointz;
else if ( pointx == 160 )
pointnewx = pointx;
// return the new x-coordinate
return pointnewx;
}
That is the function, that translates the x coordinate by adding the z coordinate to it and then returning it.
function TranslateCoordinatesY ( int pointy, int pointz )
// translates three-dimensional points with x, y and z coordinates to two dimensional
// ones with only x and y coordinates
{
// define the new y-coordinate
int pointnewy;
// translate the coordinates
if ( pointy < 100 )
pointnewy = pointy + pointz;
else if ( pointy > 100 )
pointnewy = pointy - pointz;
else if ( pointy == 100 )
pointnewy = pointy;
// return the new y-coordinate
return pointnewy;
}
THis function is supposed to do the same for the y coordinate.
I am aware of the fact that this algorythm I am using right now is wrong.
Right now the functions take the original x ( or y ) value and check if it is left of the middle of the screen. If it is left then they add the z value, if it is right, they substract the z value if it is right in the middle of the screen, the z value does not change anything at all.
Can anyone give me any hints or atleast push me in the right direction?
Thanks in advance,
Jan.