PDA

View Full Version : Working in 3D



Gold_Dragon
10-09-2003, 06:58 PM
Are there any tutorials that go in to more depth than just creating a cube? I tried to work in a 3D space and my brain almost imploded. Yes, it was that bad.

I have no problem with the x and y coordinates. At least I don't think. You can create a 3D image in 2D by using depth and so on. When working in 3D do you need to use the camera or can you use the default camera view.

Ok when working in 3D how do you use the z coordinate? It seemed to have no impact at all with the code. Err, is it better to actually use 3D objects or is POLYGON_STRIP ok. Would it make an impact when using a light source using flat surfaces?

When using the camera on flat surfaces if I turn the object to far I see nothing and when I use the camera I see nothing. It seems I looking to far up or down.

satan
10-10-2003, 01:08 AM
Maybe you want to take a look at these tutorials: http://www.gametutorials.com/Tutorials/opengl/OpenGL_Pg1.htm#Camera

hih

Gold_Dragon
10-10-2003, 07:08 AM
Sweet. It is just what I was looking for. Nehe has some great stuff and I'm looking in to it but I need to be able to learn the reason for the camera position being where it is and how to build the world around it. I think what Tutorial 10 does is just move the world around the user. Pretty wicked but it does the trick very nicely.

dorbie
10-13-2003, 08:43 AM
In OpenGL the issue of moving the world past the eye vs moving the object through the world is only conceptually different. In practice they are the same.

The MODELVIEW matrix stores the transformation from object space to eye space, in other words it transforms the objects in the world to the correct location around the eye, AND/OR transforms the eye to the correct location w.r.t. the objects.

Imagine a video camera inside a box, and you're watching the TV picture from this camera. There are various objects glued down inside the box. Suddenly you see box and all the objects move together on the TV picture. Did the box move or did the camera move? You cannot tell by watching the TV. In OpenGL you don't care because the effects are indistinguishable, and each accomplishes the desired visual result.

Infact for projection purposes the world is always moved around the eye mathematically, but you generally don't need to worry about this too much when implementing a simple application. Just when moving the eye you negate the transformations and reverse the order of the application of rotations, (building an inverse matrix for the viewing transform w.r.t. the equivalent model transform).

[This message has been edited by dorbie (edited 10-13-2003).]

dorbie
10-13-2003, 08:54 AM
P.S. Another way to think of this inverse viewing matrix, is to imagine drawing a room in OpenGL, with the eye at the origin. You draw a 3D camera where you intend to move the eye to and use the modelview matrix to position the camera.

Next repeat the drawing procedure with the camera but also apply the viewing transformation to the modelview before drawing the camera, and don't bother drawing anything in the room except the camera. The eye will be drawn inside the camera at the camera's origin, and the camera will be oriented inside the room viewing it.

Now think about what just happened on the MODELVIEW matrix. The model matrix transformation for the camera must have been the exact opposite of the viewing matrix transformation for the eye (the inverse matrix) for them to cancel each other out and leave the eye inside the camera as if you had just drawn the camera with an identity matrix on the modelview.

Gold_Dragon
10-13-2003, 09:25 AM
This is all great information but I really want to know how to work the z axis in the picture. One of the problems I had when drawing the 3D Image was drawing the world from the camera kind of like 2D. I had some points that I thought should be raised up have 10 for the z and others that I thought shouldn't have only 0. The floor went from all four grids but had a z axis of 0. The walls instead of having the same coordinate like
point1: x=-5.0, y=-5.0, z=0.0
point2: x=-5.0, y=5.0, z=0.0
point3: x=-5.0, y=-5.0, z= 3.0
point4: x=-5.0, y=5.0, z=0.0

instead had something like this
point1: x=-5.0, y=-5.0, z=0.0
point2: x=-5.0, y=5.0, z=0.0
point3: x=-2.0, y=-3.0, z= 3.0
point4: x=-2.0, y=3.0, z=0.0

I thought this would create a 3D and in a 2D world, it would but I don't really know how lighting would effect it, if it was 2D or if I would even want or need lighting. I did add in a camera view after the fact and I was only able to see one wall, I believe it was the left wall, it was sort of some ways over and to the top.

The z axis knows only up and down which would be negitive for the floor and positive for the ceiling. To walk you would only require that the z camera not change but you wouldn't want to be to close to the floor but not to high up to be close to the ceiling. Also in some of the tutorials, wouldn't you want to have some lights in effect to create sort of a high ceiling effect (EDIT: don't answer).

I would ask about lighting but that is a topic for another time, if I can't figure it out myself.

The point of the matter is that I need to position the camera (which I didn't do the first time) and build the world around the camera and not the other way around. The second point is cracking the x, y, z code in building 3D worlds. If I can't figure it out for building a 3D world then how will I build a model in 3D space?

nexusone
10-13-2003, 09:55 AM
A good book on 3D programming would help you since it would have pictures of the ideas of 3D programming.

OpenGL the camera does not move, but instead you move the world around the camera to make it look like it is moving.


In openGL XYZ have a diffrent perspective then how XYZ is preseted say in Math or physics or some other 3D software.

X is up/down +/-
Y is right/left +/-
Z is front and back +/-

Sometime people try to hard to understand 3D, the best way to start is to draw on a piece of paper the idea for your world. I use grid paper which works out good.

But the big thing is to look at world space as the top of a map, where everything is located. Just like when you use a map, you don't move yourself to look at it, but you pick up the map and move it to where your eye can see a place on it.
Sort of the same idea in 3D.

Treat each object as is own little world.



[This message has been edited by nexusone (edited 10-13-2003).]

[This message has been edited by nexusone (edited 10-13-2003).]

Gold_Dragon
10-13-2003, 10:10 AM
So if I get this right then, brain exploding god, ouch.

Ok, let me get this straight. (head hurts). Okay. Lets see. Hmm, yeah. I think I may just need a book.

What? The X is the up and down but isn't that way the z is for. Why? Hmm, it could kind of make sense in the bizarro world.

Okay, I think I understand now. The reason the z is set to zero is not because the camera is looking top down but because it is looking straight and the z creates sort of like layered effect if you off center the picture some and enable depth.

Okay, it did hurt at first while I thought about it but now it sort of makes more sense. I shouldn't think like in the terms of geometery. It still kind of hurts but I'm not completely in the dark. Thanks man. It is not the z that should be zero but the x that should be zero. I will have to remember that and try building the world again.

Gold_Dragon
10-13-2003, 10:17 AM
Originally posted by nexusone:
Treat each object as is own little world.

So what if I overlap the objects in the code. Would OpenGL automatically space the models out to where they should go?

This creates some interesting and complicated choices when creating worlds... err, not worlds but maps in 3D. If I wanted to keep the camera... world positioned to the camera so that it is always so many degrees from it then would I check the z of the ground to the z of the camera and just move the world up to the camera and do the opposite for going up stairs and such? Working in 3D is difficult but anything difficult just needs a little time. Slow learning is a bore through.

dorbie
10-13-2003, 03:37 PM
Overlapping objects are resolved by the z buffer at the pixel level. The nearest z value wins (with conventional settings). If you don't enable the zbuffer (depth buffer) then the last object is drawn over earlier objects (search "painter's algorithm").

nexusone
10-15-2003, 10:55 AM
No, openGL only draws the objects, it is up to you to track and keep stored the position of each object.

Also up to you to check if two object are in the same space.

I am sure you have played a 3D game and at some point the 3D charactor has went into the ground or part of an object and you see the inside area's that you normally don't see. This is where the program has failed to keep the camera from looking at a wrong place.


Here is something that can get tricky, your camera and your ground's XYZ can get rotated so that say the ground'Z is parallel to the camera's X.

In respect to our camera.
Rotating camera around the X axis, is like moving our head up and down.
Rotating camera around the Y axis, is like moving our head from right to left.
Rotating camera around the Z, is like titlting your head to one side, but in the case of our camera we could do it a full 360 rotation.

Here is a example who how one may think about objects and each having its own XYZ or space.

If you are in say the star ship enterprise, and you are standing on the deck.
No matter how the ship turns or moves, your position on the deck of the enterprise stays the same in relationship to the ship.

Let take two starships the Enterprise and the Defient.
Each ship has a front, back, top, bottom, right and left side as does all objects in 3D space.

Let's call the front of the ship -Z, the rear of the ship +Z, the top +Y, bottom -Y, right side +X and left side -X.

Now since each ship can move in any direction in space, at any givin moment the ships +Z could be moving along in any XYZ axis.

Example the ship moving from right to left across the screen, its +Z axis would be moving across the camera X axis.

I hope this helps a little.



[This message has been edited by nexusone (edited 10-15-2003).]