Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Are cloned java char[][] objects totally new? 3 100
scoresClump  challenge 31 123
bunnyEars challenge 6 98
Sheet music - indicating power chords in staff 10 70
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 …
Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

932 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

10 Experts available now in Live!

Get 1:1 Help Now