Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-07-05
3
Medium Priority
?
1,924 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 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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

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…
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
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…
Suggested Courses

704 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