Solved

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

Posted on 2006-07-05
3
1,917 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Assisted Solution

by:putaNerd
putaNerd earned 40 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 35 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

635 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