x
Solved

# 3d polygon sorting and clipping..

Posted on 2000-04-03
Medium Priority
443 Views
Hi,

I'm writing a 3d engine as a special project in school.
Therefore it is not very fast but rather easy to understand,
everything is class based and most of the stuff are done
automatacally. BUT.. I have two problems.. polygon sorting
and clipping. What I think I would need is a function that
converts a point from the standard plane to the camera
plane so I can calculate where the point is related to what
position the camera is. But, I have no idea how so currently
I'm sorting polygons by z and I have no clipping. So if you
could help me it would really be appreciated.

/ eaz
0
Question by:eaz
• 6
• 3

LVL 2

Expert Comment

ID: 2680528
Sorting polygons by z axis is quite smart since you can start drawing polygons from back to fron that way you dont get the overlap, also you need to calculate the normals you know which surface are visible to the camera.

there are so many documents about 3D engines that you could spend days and days reading about them

check out http://www.cfxweb.net/ for further links

i could post some code for it as well. but first you read :D

Good luck on you

T. Rizos.
0

LVL 1

Expert Comment

ID: 2681742
first what are you using to write your prog ???
like in OpenGL you don't have this problem it doing it automaticlly

about sorting there are to algorithms :

1)"object sacn" when you are drawing an object go allover the object's and check if there is an object that you will draw and this point and check which one is nearer and that for each point of the object you are about to draw

2)"screen scan" when you are drawing make a matrix that will be the nearest z coordinate displayed on the screen
and then when you are drawing you have to check if the point you are about to draw is nearer then the nearest point if it is draw it if not don't

but for that you"ll have to write your own drawing func's

or just use OpenGL which as i know use one of this algorithms

0

Author Comment

ID: 2681917
I'm coding it from the ground up.. using DJGPP in mode 13h. So far I can draw and rotate some objects right in front of the camera in grayscale and do some antialiasing (terribly slow..). But I can not rotate the camera around the object or build move it around a scene since that would make objects end up behind the camera.

In another forum I got an answer that stated I could multiply my CameraMatrix with a PolygonMatrix to get a ResultMatrix which I then should multiply with something to get a final PolygonCameraMatrix. Help with that last part? Anyone?

/ eaz
0

LVL 1

Expert Comment

ID: 2683023
tell me how you make the camera

as i see it it a matrix of rotation and translation
that will rotate and translate the scene
to the right position
and you should have a matrix that is the rotation and tranlation ,... of the object's for each object there is a matrix
and then you mult the two matrix's
the difrence it that the camera matrix is for all the objects and the other one is matrix per object
0

LVL 1

Expert Comment

ID: 2683027
tell me how you make the camera

as i see it it a matrix of rotation and translation
that will rotate and translate the scene
to the right position
and you should have a matrix that is the rotation and tranlation ,... of the object's for each object there is a matrix
and then you mult the two matrix's
the difrence it that the camera matrix is for all the objects and the other one is matrix per object
0

LVL 1

Expert Comment

ID: 2683030
tell me how you make the camera

as i see it it a matrix of rotation and translation
that will rotate and translate the scene
to the right position
and you should have a matrix that is the rotation and tranlation ,... of the object's for each object there is a matrix
and then you mult the two matrix's
the difrence it that the camera matrix is for all the objects and the other one is matrix per object
0

Author Comment

ID: 2684509
My camera is a struct with two double arrays (position and rotation) and one 4x4 viewmatrix.

typedef struct Camera3D
{
Point3D position;
Point3D rotation;
MATRIX_4x4 viewmatrix;
};

Ntdragon, there is a lot of errors in your text, it makes it hard to read and understand.. is it because of sloppy writing? No offence.. I'm just wondering. I'm also quite new to 3d programming so I don't understand everything about matrixes yet, so the easier you explain the faster I will learn. And my math book stops right where this begins.. quite annoying acctually.
0

LVL 1

Accepted Solution

ntdragon earned 200 total points
ID: 2691320

let's start with matrix you have to learn the basic operation with them
(+) and (*)
if you don't know how to do that tell me i"ll explain it to you
now about translation matrix there are some matrix for translation one for rotating one for translating and one for scaling you can find them in any graphic book
if you didn't manage to do so tell me and i"ll send them to you
now about your code you made a camera struct except it you have to make the same struct for each object or to make one global for all the object it will be for transfering the objects (rotate,translate,scale)
except that you have to make a func that mult to matrix's <i mean your struct's>
then when you draw the object you have to mult the camera matrix with the object matrix and the point you are about to draw and then draw<for that you have to write a func that mult matrix with vector>

0

Author Comment

ID: 2700412
Thank you for taking your time. I have solved the problem. Now all I have to implement is clipping.. and texturing and.... and.. and... =)
0

LVL 1

Expert Comment

ID: 2707788
0

## Featured Post

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.