Click to See Complete Forum and Search --> : wireframe 3d cube (problem)


LOGICO
November 2nd, 2006, 11:13 AM
Hello,
while trying to create a wireframe 3d cube the following problem appears: the cube doesn't show, some of the lines are drawn over the others.

The code only uses borland graphics. No DX or OpenGL.

First created a points array with 8 positions

Point3d CUBE[8] = {
{ -1, 1, 1 },
{ -1,- 1, 1 },
{ 1, 1, 1},
{ 1, -1, 1},
{ -1, 1, -1 },
{ 1, 1, -1 },
{ -1, -1, -1 },
{ 1,- 1, -1} };

Then I created a Matrix wich contains pairs of points. This is to know wich points connect to wich.

Then with a cycle all the positions in the CONNECTED matrix are checked.
The code gets X and Y for each connected point and a line is created.

The result doesn't show a cube. Used both parallel and perspective projections.

The code for the perspective projection is this

x1 = (int)60 * CUBE[origien].x / CUBE[origien].z + getmaxx() / 2;
y1 = (int)60 * -CUBE[origien].y / CUBE[origien].z + getmaxy () / 2;
x2 = (int)60 * CUBE[desteny].x / CUBE[desteny].z + getmaxx() / 2;
y2 = (int)60 * -CUBE[desteny].y / CUBE[desteny].z + getmaxy()/2;

line ( x1, y1, x2,y2);

origien and desteny are taken from the connected points matrix.

For example the perspective projection just shows a square with another line in the diagonal.

This happens because some of the points are getting overwritten by others, wich is strange since they should appear in perspective.

Thanks for your comments..