• Create Account

# really need help with 3D objects in openGL

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

### #1glut_user  Members   -  Reputation: 100

Like
0Likes
Like

Posted 19 May 2011 - 05:28 AM

<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>

### #2Big Evil Corporation  Members   -  Reputation: 507

Like
1Likes
Like

Posted 19 May 2011 - 06:12 AM

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
- 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);

//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

### #3glut_user  Members   -  Reputation: 100

Like
0Likes
Like

Posted 19 May 2011 - 07:45 AM

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!

### #4ShadowKyuzo  Members   -  Reputation: 100

Like
0Likes
Like

Posted 19 May 2011 - 08:22 AM

Swiftless has some cool tutorials, in my opinion:

http://www.swiftless.com/opengltuts.html

### #5glut_user  Members   -  Reputation: 100

Like
0Likes
Like

Posted 19 May 2011 - 08:32 AM

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>

### #6scgames  Members   -  Reputation: 2078

Like
0Likes
Like

Posted 19 May 2011 - 11:13 AM

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)?

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.)

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS