really need help with 3D objects in openGL

Started by
4 comments, last by Zakwayda 12 years, 11 months ago
<div>I am trying to get 3D objects to move and interact with each other. They will collide and move in other directions when such a collusion occurs. How would I go about doing this?</div><div><br></div>
Advertisement
Step 1 - familiarise yourself with some basic 3D maths. For your particular case, look up 3D Vectors - find out what they are, how to add them together, how to use them to represent a position in 3D space

Step 2 - make a basic structure to represent your Vector3. In C++, this would look something like:


class Vector3
{
public:
Vector3() { x = y = z = 0.0f; }

float x;
float y;
float z;
};


Step 2 - figure out how to apply a desired translation before rendering your 3D object :

- Create a Vector3 to represent your object's position
- Add/subtract to/from your vector depending on keyboard input
- Use OpenGL's glTranslatef() function to apply the translation before your render you object

In its very basic form, your rendering loop will need to look something like:


//Push an identity matrix to the stack
//(any glTranslate operation you do operates on the current matrix - you'll need a blank slate to work with. Look up 'world space' and 'object space' to see what we're doing here)
glPushMatrix();

//Apply the desired translation
glTranslatef(myVector.x, myVector.y, myVector.z);

//Render your object, as you're already doing

//Pop the matrix stack
glPopMatrix();



Once you've grasped the basics, I recommend reading up on 3D Matrix - what they are, how to use them to represent a position and rotation in 3D space, how to add/multiply them together, and how they apply to OpenGL.

"The right, man, in the wrong, place, can make all the dif-fer-rence in the world..." - GMan, Half-Life 2

A blog of my SEGA Megadrive development adventures: http://www.bigevilcorporation.co.uk

okay...but is there any tutorials i can find on this? i really don tknow much about openG. just how to draw some cubes etc from the nehe tutorials.

if there is a tutorial with code examples that would be great!
Swiftless has some cool tutorials, in my opinion:

http://www.swiftless.com/opengltuts.html
thanks i will have a look at that. so basically i just want to have some 3d objects that interact with each other. but they interact with each other differently, depending on the type of object. eg if you a cube hits a sphere, it bounces off. if the cube hits a cube, it goes through it. how would i do this?<div><br></div><div><span class="Apple-style-span" style="color: rgb(28, 40, 55); font-size: 11px; line-height: 16px; ">do u think this will be a very hard task for someone who has only really read up on basic stuff on openGL? (such as just chapters 1-3 on the redbook, and just nehe lessons 1-5)?&nbsp;</span></div>
I assume this is a homework assignment of some sort?

do u think this will be a very hard task for someone who has only really read up on basic stuff on openGL? (such as just chapters 1-3 on the redbook, and just nehe lessons 1-5)?[/quote]
The things you're asking about actually have very little to do with OpenGL specifically, so the Red Book won't help you much here. I think the NeHe tutorials include some examples of moving about and so forth, but I'm not sure if they cover the kinds of things you're asking about. (You could always skim through the tutorial descriptions and see though.)

The assignment you've been given sounds a little involved to me (especially if you don't already have a background in the required subjects), but what I'd recommend is to break it down and tackle one problem at a time.

For example, a good first step might be just to get the movement part working, without worrying about the terrain or the collision detection. Just getting the ball moving continually in a forward direction and turning left or right in response to user input will be a good step towards finishing the assignment. (deadstar laid out the basics of how to do this above.)
its actually a project and i have been very unwell so i need some help to get it done

This topic is closed to new replies.

Advertisement