From: Ben S. <bs...@vr...> - 2002-03-26 06:53:13
|
First off, I suggest walking through the first 5 NeHe tutorials. (http://nehe.gamedev.net) They should give you a good start at doing 3D graphics using OpenGL ... unfortunately, he doesn't use GLUT, he does straight up Win32 programming. Once the window is created though, the rest of the code is just regular OpenGL commands. To answer your questions about the matrix modes and such, I should talk a bit about how the graphics pipeline works. Generally, you want to store the coordinates of your 3D objects relative to the object's center. Thus the coordinates of the back, upper right corner of a cube with edges of length 1 unit would be (0.5, 0.5, 0.5). This allows you to rotate the model around it's center by applying rotation matrices to it. This coordinate system with the object's center at the origin is called "model coordinates". You have a model coordinate system for each model/object in your game. This is rather boring since you usually want more than one object in your world. You want all these objects to be oriented relative to each other somehow in one coordinate system. Thus we bring about the concept of the "world coordinate" system. In this system, the origin is in the center of the world and each object has a position relative to that origin. At that position lies the origin of that particular model's model coordinate system. If our cube from earlier were at position (20, 15, -5) from the origin, the back, upper right corner would be at world coordinates (20.5, 25.5, -4.5). You generally use a matrix to transform the vertices in your model from model coordinates to world coordinates using the "ModelWorld" matrix. It is in this transformation matrix that you generally want to do most of your translations and rotations to position your objects in your world. Next up we have the "camera/view coordinate" system. In this coordinate system, the position of the camera (the player's view into the world) is always at the origin. This helps OpenGL determine which polygons are visible on the screen. This coordinate system is rather unintuitive since in order to map from world coordinates to view coordinates, you must apply the inverse of the tranformation used to place the camera in the world. For example, if the camera were at (5, 5, -3), you would want to translate every world coordinate by (-5, -5, 3) to convert to view coordinates. If this seems odd, just think that you want to move the world around so that the camera is at the origin. Finally, you need to get this 3D world into a 2D screen. This is done using the projection transformation matrix. There are 2 common methods of doing this. The first is orthographic projection. This means that when objects are drawn to the screen, the z-coord is dropped and the vertex is plotted at (x,y). This works well for 2D games, but really does not give a 3D feel. The other projection type is perspective projection. This gives that 3D look by modifying the (x,y) coords based on the z coord. This makes vertices with a smaller z value look further away. You can essentially think of the mapping as (x,y,z) -> (x/z, y/z). ------- In OpenGL, the ModelWorld and WorldView transformation matrices are concatenated into one matrix for speed and that's why you'll see references to ModelView matrix mode. The Projection matrix mode only modifies matrix used to do the projection from 3D to 2D. There is also a Texture matrix, but I wouldn't worry about that now. The basic idea with OpenGL and matrix modes is that all matrix operations such as glLoadIdentity(), glRotatef(), glTranslatef(), etc apply to the current matrix. You must specify at some point which matrix you are working with. For example, glMatrixMode( GL_PERSPECTIVE ); // we want to modify the persp. matrix glLoadIdentity(); // clear out the current matrix and replace with identity gluPerspective( 80.0, // horizontal angle of the field of view (what you can see) (double)width / (double)height, // the aspect ration of your window 0.01, // the near clipping plane. clips coords with Zs < 0.01 500.0, // far clip plane. clips coords with Zs > 500.0 ); glMatrixMode( GL_MODELVIEW ); // now start modifying the modelview matrix glLoadIdentity(); // again, fill with identity matrix // rotate then translate, the ordering IS important. Try it the // other way around and see what happens. :) glTranslatef( 50.0, 0, 0 ); // translate 50 units to the left glRotatef( 30, 1, 0, 0, ); // rotate 30 degrees about the X axis glBegin( .. ); // ... glEnd(); Hopefully my explanation and NeHe's tutorials can give you a good start. Please email the list again if you have any more questions or if I missed one of your questions. Good luck with the BMX game! You should work on it with your source in CVS so you can get your code backed up and others can see you work and learn from it as you work on it. cheers, ----- Ben Scott President ISU Game Developers Club Treasurer ISU Ballroom Dance Company bs...@ia... On Mon, 25 Mar 2002, Lou Herard wrote: > So, I've decided to take the quantum leap into the realm of 3D graphi= cs with OpenGL and glut. The only problem is that I HAVE NO FRIKKIN IDEA W= HAT I'M DOING!!!! So, I was wondering if any of you 3D gurus had any words= of wisdom for me. OK, now let me go into a little bit of detail about wha= t I need help with. > > I'm making a BMX game. My plan is to make it like Mat Hoffman's Pro = BMX, with better gameplay (I'll let Hoffman beat me in the graphics departm= ent for right now). I'm working on the bike model. Right now, all I have = is the wheel class, which stores the wheel's world coordinates. Ultimately= , the wheel's world coordinates will be determined by the bike (since the w= heel is connected to the bike), but for now it's just floating in space. A= nyway, I have the points that constitute the wheel stored in a couple GL_LI= NES structures (basically, to enhance the 3D look, I made two identical cir= cles, one on the positive side of the Z axis, and one on the negative side = of the Z axis). I was looking through the redbook and it confuses the hell= out of me. How do I set the program up for 3D viewing? All this glMatrix= Mode and other stuff is kinda strange to look at. And then, once I have th= at set up, how do I actually transform the points in the structure? I'll l= ook at some code, too, but anyone who helps me out gets $5. (ok, maybe not= , but if you have any suggestions, I'd really appreciate them.) > > - Lou > > P.S. Over break, I was cleaning out my old laptop and I found some of th= e stuff I made in QB45. If anyone wants to see it, I can bring it to the m= eeting on Thursday. I have some executables. > |