View Full Version : Using matrices instead of GL parameters
JimmyFo
09302004, 09:47 AM
Hi, I was wondering how I could create viewing windows and projection without using glMatrixMode(GL_MODELVIEW/GL_PROJECTION), gluLookAt(...), glRotate.. and so on. What I need to do is  using matrix/vector multiplication alone  manipulate a camera, change the viewing window, etc. I don't know where to start  I know the formulas for multiplying and how to change the variables, but how do I display it? Is there some opengl function that takes matrices and displays them? I need to take three dimensional objects and map them to the window as two dimensional. Thanks  and what exactly does perspective division do?
again, thanks :)
james
hey jimmy, have a peek inside the redbook:
http://www.parallab.uib.no/SGI_bookshelves/SGI_Developer/books/OpenGL_PG/sgi_html/apf.html
perspective division is just part of the process of mapping points in the world to points on the screen.
* y (point in world)
/
/ 
/ 
/ 
/ 
 / 
point on / 
near> * y' 
/ 
/  
/  
eye>*z'z> eye zaxis


 <near plane the goal is to find y'. using similar triangles, you can see that y / z = y' / z'. solving for y',
y' = y z' / z. hence you have a "perspective division", which, in opengl, basically amounts to a division by z (since the eye looks in the negative z direction).
btw, why do you want to avoid the opengl stuff?
JimmyFo
10012004, 07:29 PM
My teacher wants the class to program this:
a) Render the models using points, wireframe and solid representations.
b) Support translations and rotations of the virtual camera. Translations and rotations should be defined with respect to the coordinate system of the camera. Thus, for instance, a translation in Z should move the camera forward (backward).
c) Render the objects at the center of the windows.
d) Support changes in both the horizontal and vertical fields of view. (Bonus)
e) Support backface culling. (Bonus)
f) Support some simple clipping. (Bonus)
but without using gl  we have to create a "MyGL" file basically. The thing is, I have no idea how to even display it since we can't use any of the functions I'm used to  I can scale/translate/etc the OBJECT fine, but I can't use the camera. I figure once I know how to display the obj, then all it is is manipulating the variables in the matrices, but I don't know where to place the matrices, or what functions to use, to get them to display. That's it I guess  thanks for replying. Any more help is GREATLY appreciated :)
james
p.s.  oh, and right, he said that in the end, it will be like displaying a two dimensional object to the screen... I'm not sure how that works, that one whole dimension is cut. I'm sure it has something to do with an orthographic style of displaying, and I assume that's done with the matrix manipulation in there somehow.
sounds like you have your homework cut out for you :)
lol  yes, you're right  the problem is, I can't start it. I don't know how to display anything! I understand very well the theory behind, and the matrix/vector multiplications. What I am confused about is how to display them. Say here are my display and reshape functions for the second window (MyGL)
void reshape( height width)
{
}
void display()
{
}
What goes in there? Since I can't use the gl functions like lookat, loadidentity, and matrixmode, I don't know what to do to display the screen. My thoughts were to try something like:
setIdentity(new4x4matrix) //which would make a 4x4 identity
but then, that's it. I think that would go in the reshape function, but where to I place other functions, and what would they do? In other words, in the reshape function say, what do I need to do to get a window to show? How to I pass items, and how many steps do I need to do before I can display something? I don't know if this is clear, but any help is great  thanks
james
Hi, JimmyFo
It seems you are needed to create your own graphic library. Such exercises are given in most of university. Main thing you should build is pipeline architecture. You looked like you know matrix operations very well. That is the most important one of pipeline steps. You know, graphics pipeline has following steps:
Transformation
Clipping
Projection
Rasterization
So, you can do transformation very well. For the Clipping and Projection steps, you should deeply study related algorithms such as CohenSutherland. After all of those steps, you should rasterize all the vertices you found. For the simple objects, you can do it using traditional methods. For more complexity, you also needed to study algorithms such as zbuffer etc.,
I think i know exactly what you're going through, I had to do exactly that for my graphics class.
If you had a triangle in 3d space, and you apply your projection algorithms on the vertices of the triangle, the result will be a triangle in 2d space. So you would still draw a triangle in opengl, just useing the 2d functions rather than 3d. The only thing that changes is the locations of the vertices.
Good luck with those projections though, they're rough.
JimmyFo
10042004, 05:58 PM
A quick question on the perspective division. If I take the three dimensional points (x,y,z) and want to convert them to another vector of just (x,y) so that they can be projected to the screen via vertex2f, do I set them like this:
newx = oldx;
newy = oldy/oldz;
and then go about displaying them like normal 2d points? Thanks 
james
Here's what it looks like, so that can't be right: http://www.geocities.com/thekingjimmy/gl.html
Powered by vBulletin® Version 4.2.5 Copyright © 2018 vBulletin Solutions Inc. All rights reserved.