Solved

3d polygon sorting and clipping..

Posted on 2000-04-03
10
432 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

746 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

12 Experts available now in Live!

Get 1:1 Help Now