View Full Version : glRotatef function

hayden

01-23-2013, 11:51 AM

I need some clarification about glRotatef function. I have a rectangular plane with normal ax + by + cz = 0;

I would like to rotate it along (0, 1, 0) i.e. Y-axis.

I can find the in-between angle by dot product. Suppose the angle is theta in degree. Now how can I use glRotatef function to rotate the plane so that the new normal to the plane is along (0, 1, 0) vector; Is the following ok?

glRotatef( - theta, a, b, c);

If not, what will be the correct version?

Aleksandar

01-24-2013, 02:01 PM

That is not correct. It is not quite clear what you want to achieve.

1. If you want to make plane's normal to be coincident with Y-axis, then you need to find axis around which you have to rotate a plane. The angle is correct. It can be calculated from the scalar product. The axis, or to be more precise, the vector of rotation can be calculated from vector product: (nx, ny, nz) = (a,b,c) x (0,1,0).

=> glRotatef(teta, nx, ny, nz)

2. If the rotation should be done around Y-axis => glRotatef(alpha, 0, 1, 0). But for which angle, it is not defined by the question. So, this assumption is probably wrong.

hayden

01-24-2013, 05:14 PM

Thank you. The first one is what I asked. But whether it would be glRotatef( -theta, nx, ny, nz) or glRotatef( +theta, nx, ny, nz) . Could you explain a bit?

jenny_wui

01-25-2013, 01:37 PM

Could you let me know how to find out the corrsponding rotation matrix in this case?

jenny_wui

01-25-2013, 02:53 PM

I found the following link helpful:

http://en.wikipedia.org/wiki/Rotation_matrix

Rotation matrix from axis and angleFor some applications, it is helpful to be able to make a rotation with a given axis. Given a unit vector (http://www.opengl.org/wiki/Unit_vector) u = (ux, uy, uz), where ux2 + uy2 + uz2 = 1, the matrix for a rotation by an angle of θ about an axis in the direction of u is

http://upload.wikimedia.org/math/f/b/a/fbaee547c3c65ad3d48112502363378a.png

Powered by vBulletin® Version 4.2.5 Copyright © 2018 vBulletin Solutions Inc. All rights reserved.