Solved

3d polygon sorting and clipping..

Posted on 2000-04-03
10
433 Views
Last Modified: 2010-04-10
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
Comment
Question by:eaz
  • 6
  • 3
10 Comments
 
LVL 2

Expert Comment

by:xLs
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

by:ntdragon
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

by:eaz
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

by:ntdragon
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

by:ntdragon
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:ntdragon
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

by:eaz
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

by:
ntdragon earned 100 total points
ID: 2691320
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
 

Author Comment

by:eaz
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

by:ntdragon
ID: 2707788
always glad to help
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now