Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

glRotatef(), Setting the center of rotation...

Posted on 2006-07-05
3
Medium Priority
?
1,928 Views
Last Modified: 2013-12-26
Hi everybody,

I'd like to rotate this triangle :

glPushMatrix();
glRotatef(10.0,0,0.0, 1.0);

glBegin(GL_TRIANGLES);
      glVertex3f( x1 ,0.2,0.0);
      glVertex3f( x2 ,0.25,0.0);
      glVertex3f( x3 ,0.15,0.0);      
glEnd();

glPopMatrix();

but the rotation is made around the origin (0,0,0), how can I rotate around this point : [x1 ,0.2,0.0] ?

Thank you!

Vincent
0
Comment
Question by:vinceTrace
  • 2
3 Comments
 
LVL 1

Assisted Solution

by:putaNerd
putaNerd earned 160 total points
ID: 17048722
Vincent,
Off the top of my head I suggest you try two things, both should work but they are good to know.

this might distort things a little in some cases
glPushMatrix();
glRotatef(10.0,x1 ,0.2,0.0, 1.0);

/**********************/
//this way moves the rotation point back to the origin. then rotates.
glTranslate(-x1,-0.2f,0.0f);
glPushMatrix();
glRotatef(10.0,x1 ,0.2,0.0, 1.0);

//at the end you should translate back to put your triangle back at the point it was. before popmatrix
glTranslate(x1,0.2f,0.0f);

hope this helps
j.
0
 
LVL 18

Accepted Solution

by:
Jose Parrot earned 140 total points
ID: 17050485
Hi,

OpenGL uses matrix approach to transformations: rotation, translation and scaling.

The matrix for rotation is:
            |  cos(A)  0   sin(A)   0 |
            |  0         1   0          0 |
            | -sin(A)  0   cos(A)   0 |
            |  0         0   0          1 |
for a given angle A. This rotate the point around the origin. Actually when you call glRotatef(10.0,0,0.0, 1.0) that matrix is solved.

An important feature of matrix calculations for transforms is that you can do BOTH at same time:

[1,0,0,0]              [cos(a),0,-sin(a),0]    [1,0,0,0]
[0,1,0,0]              [0,1,0,0]                   [0,1, 0,0]
[0,0,1,0]              [sin(a),0,cos(a),0]     [0,0,1,0]
[-X1,-0.2,-Z,1]      [0,0,0,1]                  [X1,0.2,Z,1]

The above matrix executes, in one single pass, the three calls in the sequence translate->rotate->translate. As each call solves a matrix, the single pass has the advantage of speed the execution by a factor of 3.

Jose
0
 
LVL 18

Expert Comment

by:Jose Parrot
ID: 17050968
Complementing:
You may want take a look at Dustin Juliano's excellent comment at

http://www.experts-exchange.com/Programming/Game_Development/3D_Programming/Q_20627768.html?query=glrotate+matrix&clearTAFilter=true

The approach on quaternions is very interesting if you look for speed.

Jose
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Integration Management Part 2

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question