Solved

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

Posted on 2006-07-05
3
1,893 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 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:
JoseParrot 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:JoseParrot
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now