#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# OpenGL rotation/translation tutorials/help

Member Posts: 557
Hi.

I'm having some trouble using the glRotate and glTranslate in the proper way. Are there any devent turorials?

My problem can be stated as follows:

I have a object that will have to be rotated around itself before being put somewhere in the "landscape", which is also translated and rotated.

The object is placed at location Xo,Yo,Zo and must be rotated with Thetao and Phio.
The landscape is also moved and rotated (or the camera is moved...) using X,Y,Z,Phi,and Theta...
I have tried:

- creating the object at 0,0,0, rotating, translating it, and then the landscape. Seemingly, the object is not rotated with the landscape at all.
- placing the object at Xo,Yo,Zo and all the same. Seemingly, the object is not only rotated around itself, but also some other point...

The main problem is probably that I haven't got a clue how to use the matrix functions - seemingly, no "Add" function for matrixes in OpenGL exists? Should I study some more 3D maths?? :-)

The code for rotation the landscape, and then the object:
[code]
glTranslatef(0.f,0.f,(float)-nZDist);
glRotated(dTheta,1.,0.,0.);
glRotated(dPhi,0.,0.,1.);
glTranslatef((float)nX,(float)nY,float(nZ));
glCallList(1);
// Object...
glTranslatef(fOX,fOY,fOZ);
glRotatef(Thetao,1.f,0.f,0.f);
glRotatef(Phio,0.f,0.f,1.f);
glTranslatef(-fOX,-fOY,-fOZ);
glTranslatef(0.f,0.f,(float)-nZDist); // Same as above
glRotated(dTheta,1.,0.,0.);
glRotated(dPhi,0.,0.,1.);
glTranslatef((float)nX,(float)nY,float(nZ));
glCallList(2);
[/code]

As said, I'd be more than happy if someone could just point me to a good turorial regarding this.

Rune

• Member Posts: 557
Once again, I was too fast for you... The code was right, but had to be called in the reversed order. Seems strange to me, but works )
[code]
glTranslatef(0.f,0.f,(float)-nZDist);
glRotated(dTheta,1.,0.,0.);
glRotated(dPhi,0.,0.,1.);
glTranslatef((float)nX,(float)nY,float(nZ));
glTranslatef(fX,fY,fZ); // Moved this to AFTER the other stuff..
glRotatef(pPlayers[nPlayer].GetTheta(),1.f,0.f,0.f);
glRotatef(pPlayers[nPlayer].GetPhi(),0.f,0.f,1.f);
glTranslatef(-fX,-fY,-fZ);
glCallList(2);
[/code]
• Member Posts: 642
Think in the terms local coordinate system.
The opengl red book points out this specific mistake while explaining about the coordinate system in opengl. Maybe you should look at the red books explanation.

: Once again, I was too fast for you... The code was right, but had to be called in the reversed order. Seems strange to me, but works )
: [code]
: glTranslatef(0.f,0.f,(float)-nZDist);
: glRotated(dTheta,1.,0.,0.);
: glRotated(dPhi,0.,0.,1.);
: glTranslatef((float)nX,(float)nY,float(nZ));
: glTranslatef(fX,fY,fZ); // Moved this to AFTER the other stuff..
: glRotatef(pPlayers[nPlayer].GetTheta(),1.f,0.f,0.f);
: glRotatef(pPlayers[nPlayer].GetPhi(),0.f,0.f,1.f);
: glTranslatef(-fX,-fY,-fZ);
: glCallList(2);
: [/code]
:

• USAMember Posts: 4,624 ✭✭

____ [ http://forcoder.org ] free ebooks and video tutorials about \ PHP, Objective-C, Perl, Assembly, C, JavaScript, C++, Scratch, Swift, C#, Delphi, Go, Visual Basic, PL/SQL, R, Visual Basic .NET, Python, Ruby, Java, MATLAB Apex, Transact-SQL, Scala, Erlang, Crystal, Ada, FoxPro, Julia, ML, LabVIEW, Kotlin, ABAP, Rust, Awk, Lisp, F#, Lua, VBScript, Clojure, Fortran, Dart, Hack, Bash, Alice, Scheme, Logo, D, SAS, Prolog, COBOL \ _