Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

3d polygon sorting and clipping..

Posted on 2000-04-03
10
Medium Priority
?
440 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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
 
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 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

688 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