• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 442
  • Last Modified:

3d polygon sorting and clipping..

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
eaz
Asked:
eaz
  • 6
  • 3
1 Solution
 
xLsCommented:
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
 
ntdragonCommented:
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
 
eazAuthor Commented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
ntdragonCommented:
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
 
ntdragonCommented:
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
 
ntdragonCommented:
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
 
eazAuthor Commented:
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
 
ntdragonCommented:
sorry about my sloppy writing

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
 
eazAuthor Commented:
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
 
ntdragonCommented:
always glad to help
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now