SSquared![]() Member Posts: 654 From: Pacific Northwest Registered: 03-22-2005 |
When creating a vertex [glVertex3f(0.0f, 1.0f, 1.0f)], you use values like 1.0, 2.0, 0.5, etc. Are these values in relation to something? You aren't really defining the length or position using strict x/y values. Is it some relation to the current viewport and perspective? Where is 0,0? Thanks. |
|
Briant![]() Member Posts: 742 From: Stony Plain, Alberta, Canada Registered: 01-20-2001 |
Vertex coordinates are local, with the local (0,0,0) being the current world position. For example:
If you wanted the triangle in a different place, you don't change the coordinates in the glVertex3f calls, you change the coordinates in the glTranslatef call. ------------------ Check out this webhost! Fantastic prices, features and support! |
|
Calin![]() Member Posts: 358 From: Moldova Registered: 12-04-2006 |
0,0,0 is the origin, the place from which all the calculations are made. The matrix at the very bottom on which every other matrices get piled. You should look up on matrices. Usually the initial, untransformed space is called the World Matrix. Then you have for i.e Camera Matrix , object matrices etc. So your [glVertex3f(0.0f, 1.0f, 1.0f)] can be anywhere depending on the matrix it gets multiplied with. [Edit] [This message has been edited by Calin (edited April 20, 2007).] |
|
SSquared![]() Member Posts: 654 From: Pacific Northwest Registered: 03-22-2005 |
Thanks. For reference, I am more familiar with GDI and dealing with specific pixel-level data. I just started working with OpenGL on Wednesday, so this is brand new to me. The other day I implemented a colorful triangle I can rotate using the left/right/up/down arrows. It was basically a test to figure out how to get OpenGL working in an MFC View window. OK. Then I guess my real question is, what is a unit? Obviously, 1.0 does not refer to one pixel. I am currently reading "OpenGL Programming for Windows 95 and Windows NT" by Ron Fosner. It has been a very good book, although the editing was not too good. I am about 7 pages away from reading about Matrix Transformations, so maybe that will help explain things as well. |
|
Nomad Member Posts: 63 From: Registered: 06-29-2004 |
I've done a little with OpenGL, but probably not as much as folks at www.gamedev.net or www.gamespp.com. I also found something called the "redbook", a massive .pdf download from www.opengl.org, to be very helpful. The "unit" is definitely a little odd for a while. One way to think about it is to start from the default world setting (after a load identity call). Here, the x (also y) coordinate runs from -1 to 1. This gives a sense for the "unit", basically being related to the default screen or viewing window size. As you make manipulations to the viewing matrix, the unit kind of carries along with it as the size of the original screen. More complicatedly, OpenGL uses that "homogenous coordinates" system, where all the vectors and matrices have a secret fourth component attached to them called w. Usually, the w is 1 for a point; in matrices, they use this component to cause translations (instead of needing to add matrices, it's a fun exercies to verify). Not terribly useful in the beginning, but it will become useful to be aware of it. [This message has been edited by Nomad (edited April 20, 2007).] |
|
Briant![]() Member Posts: 742 From: Stony Plain, Alberta, Canada Registered: 01-20-2001 |
I just think of a "unit" as the unit of measurement appropriate to the virtual size of project. If you're making a car-racing game, you might build your car models so that a "unit" is a foot (e.g. a car model may be 12 units long, 4 units high, etc.). If you're doing a galaxy simulation, a "unit" might be 1,000 miles. If you're rendering a chess board, maybe it makes sense for your units to be in centimeters. It's up to you, you just have to be consistent throughout the project or things appear to be the wrong sizes. ------------------ Check out this webhost! Fantastic prices, features and support! |
|
SSquared![]() Member Posts: 654 From: Pacific Northwest Registered: 03-22-2005 |
OK, I think I get it. The unit is really based on the current screen. The default being the X and Y running from -1.0 to 1.0. So, if I pull back and change 'z' by -5 (moving in the +z direction), then 1.0 will end up being less screen space. If I want to move an object in x, y, or z, I use glTranslatef, again, using values relative to the current screen. You have all helped a lot. Thanks. I will put this to use so I can see it all in action. I had family over and a birthday party for my daughter this weekend, so I just haven't had time to write any new code. |
|
Briant![]() Member Posts: 742 From: Stony Plain, Alberta, Canada Registered: 01-20-2001 |
Hey ssquared, I don't understand what Nomad was saying, so your response to him leaves me unsure as well. To set how the "world" is displayed on your screen, you need to first use the glViewport and gluPerspective. Maybe Nomad was meaning using -1.0f and 1.0f in the parameters to gluPerspective or something, to set the screen as those perspective dimensions or something. I use different values, but it doesn't really matter as long as you know what you're doing and how you're thinking about your view into the world space. Hopefully he'll clear up what he meant. Anyway, you'll probably find lessons 1 & 2 on http://nehe.gamedev.net VERY helpful. ------------------ Check out this webhost! Fantastic prices, features and support! |
|
SSquared![]() Member Posts: 654 From: Pacific Northwest Registered: 03-22-2005 |
Thanks BrianT. I really appreciate that last bit of info. And it was like just shortly after my previous post, too. :-) That helps clear things up as well and gets to the crux of my question. All of this is based on some specified world view parameters defined by the coder. I did most of my work based on the book I'm using. I started looking at the NeHe Tutorials and will spend more time with them after I'm done with the book. Most of my research and understanding is acutally going beyond what we will be using at work. Our product is mostly 2D and mainly required the transparency capability of OpenGL. But I enjoy going beyond and seeing what other potential things we can use. |
|
Nomad Member Posts: 63 From: Registered: 06-29-2004 |
Sorry my response earlier was a little vague, I was trying too hard to make it literally apply to ssquared's question. BrianT is right in that your units really correspond to whatever scale your game world uses. If you want a car to be "12.0" units long, make sure your camera is far enough away (say, "20.0"-"30.0" range) so that you can see it. The units are very natural, based on proportionality rather than anything concrete like the pixel-based lengths of normal 2D programming. For me, the transition from concrete pixel-based lengths to this more flexible system in OpenGL was a little strange at first. It was just helpful for me to think of basing the units on the screen size for the initial world configuration, so that I would have something more concrete and hardware-based than objects in my game world. |