PDA

View Full Version : Moving an Object



sumeet
07-16-2008, 10:51 PM
Hi,

I am very new to OpenGL......
and am currently using JOGL.

Creating an object is OK....but i just cant get the object to move.......
eg:- I create a simple 2D triangle
I want to rotate it around a vertice A.......

|\
| \
|_ _ \ pos 1

_ _
| /
| /
|/ pos 2

and so on....

could someone tell me what commands do i use to make this happen.........

I tried creating four different triangles,around a vertice...
sequentially.....but i dont know how to clear the previous drawn triangle...so that the next triangle appears alone.....i mean the triangle appears to be moving......

I follow the approach below....
1. I draw a triangle with a begin and end section.......
2. I issue the glClear command...
3. I draw the triangle again in a new position...
....

Is the above approach incorrect?????
Please suggest a solution............

satan
07-17-2008, 03:26 AM
First of all you need to draw just one triangle and issue glRotate/glTranslate calls to move it. It is not necessary to create other triangles.
For animation you should make sure that you use a double buffered context and call the corresponding 'swapbuffers' command after each frame (glxSwapBuffers in Linux, most likely wglSwapBuffers in Windows and something similar for jogl, I think).
Take a look here (http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=04www.headwize.com), lesson 4 should help.

sumeet
07-17-2008, 09:32 PM
Thanks a lot...........

But now i have another problem.......
The object rotates....thats fine.......but how do i make it move
in 2D context......
for eg gl.glRotatef(angle/16, 0, 0, 1);(angle starts from 1..)
would rotate the object about the Z-axis.....

i need to move the object in 2D view about a certain vertex of the object in the XY plane only.......

what should i do?????

satan
07-18-2008, 04:07 AM
glTranslate (http://www.opengl.org/sdk/docs/man/xhtml/glTranslate.xml)?