We get it. We use ad blockers too. But GameDev.net displays them so we can continue to be a great platform for you.
Please whitelist GameDev.net and our advertisers.
Also consider a GDNet+ Pro subscription to remove all ads from GameDev.net.
OpenGL API Specifications
Documents and Learning ResourcesSupport Libraries and FrameworksFunction Libraries and GeneratorsThis list contains some basic resources for getting started with, and developing for, OpenGL 3.0 and onwards. Contact your forum moderator if you want to contribute to the list or have any comments.Subscribe to GameDev.net's newsletters to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 23 April 2011 - 01:40 PM
Posted 23 April 2011 - 01:56 PM
I'm not very skilled with math, but i'm wondering what does glRotatef do internally?
I have some legacy code which does some math i don't really understand and sends values to glRotatef. I am implementing a physics engine to go with this legacy code and i need a 4x4 matrix instead of that output, i don't really understand how the rotation along a vector glrotatef thing works, but i just need a resulting matrix - which if i multiplied with glMultMatrixf instead of glrotatef would result in same working output.
Thanks.
Posted 23 April 2011 - 01:57 PM
| x^2*(1-c)+c x*y*(1-c)-z*s x*z*(1-c)+y*s 0 | R = | y*x*(1-c)+z*s y^2*(1-c)+c y*z*(1-c)-x*s 0 | | x*z*(1-c)-y*s y*z*(1-c)+x*s z^2*(1-c)+c 0 | | 0 0 0 1 |
Posted 23 April 2011 - 02:15 PM
Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.
Posted 23 April 2011 - 02:19 PM
function CreateGlRotateMatrix(angle, x, y, z: single) : TMatrix; var axis: TVector3f; b, c, ac, s: single; begin result:= IdentityHmgMatrix; c:= cos(angle); s:= sin(angle); result[0,0] := (x*x) * (1-c)+c; result[1,0] := x*y * (1-c)-z*s; result[2,0] := x*z * (1-c)+y*s; result[0,1] := y*x * (1-c)+z*s; result[1,1] := (y*y) * (1-c)+c; result[2,1] := y*z * (1-c)-x*s; result[0,2] := x*z * (1-c)-y*s; result[1,2] := y*z * (1-c)+x*s; result[2,2] := (z*z) * (1-c)+c; end;
Posted 23 April 2011 - 02:20 PM
A normalized vector. I guess you knew that already, but just making sure everyone knows it as well .[x, y, z] - a vector about which the rotation should be done
Posted 23 April 2011 - 02:57 PM
A normalized vector. I guess you knew that already, but just making sure everyone knows it as well .
Posted 23 April 2011 - 03:08 PM
function CreateGlRotateMatrix(angle, x, y, z: single) : TMatrix; var axis: TVector3f; b, c, ac, s: single; invLen : Single; begin invLen:= RSqrt(x * x + y * y + z * z); x:= x * invLen; y:= y * invLen; z:= z * invLen; result:= IdentityHmgMatrix; c:= cos(angle); s:= sin(angle); result[0,0] := (x*x) * (1-c)+c; result[1,0] := x*y * (1-c)-z*s; result[2,0] := x*z * (1-c)+y*s; result[0,1] := y*x * (1-c)+z*s; result[1,1] := (y*y) * (1-c)+c; result[2,1] := y*z * (1-c)-x*s; result[0,2] := x*z * (1-c)-y*s; result[1,2] := y*z * (1-c)+x*s; result[2,2] := (z*z) * (1-c)+c; // vectorgeometry.TransposeMatrix(result); end;
Posted 23 April 2011 - 03:10 PM
c:= cos(angle); s:= sin(angle);
The results aren't what it's supposed to be:
I replaced: glRotatef(Angle * 180 / Pi, Axis[0], Axis[1], Axis[2]);
With:
rotang:= CreateGlRotateMatrix( Angle * 180 / Pi, Axis[0], Axis[1], Axis[2]);
glMultMatrixf(@rotang[0,0]);
The results make a total mess when objects are rendered, none of rotations look correctly, did i get the matrix array addressing right? in delphi the matrix order are row-col based.
Posted 23 April 2011 - 03:22 PM
Hey, I just noticed the way you pass angles... glRotatef() takes angle in degrees not in radians!!!The results aren't what it's supposed to be:
I replaced: glRotatef(Angle * 180 / Pi, Axis[0], Axis[1], Axis[2]);
With:
rotang:= CreateGlRotateMatrix( Angle * 180 / Pi, Axis[0], Axis[1], Axis[2]);
Posted 23 April 2011 - 03:50 PM
function CreateGlRotateMatrix(angle, x, y, z: single) : TMatrix; var axis: TVector3f; b, c, ac, s: single; invLen : Single; begin angle:= vectorgeometry.degtorad(angle); invLen:= RSqrt(x * x + y * y + z * z); x:= x * invLen; y:= y * invLen; z:= z * invLen; result:= IdentityHmgMatrix; c:= cos(angle); s:= sin(angle); result[0,0] := (x*x) * (1-c)+c; result[1,0] := x*y * (1-c)-z*s; result[2,0] := x*z * (1-c)+y*s; result[0,1] := y*x * (1-c)+z*s; result[1,1] := (y*y) * (1-c)+c; result[2,1] := y*z * (1-c)-x*s; result[0,2] := x*z * (1-c)-y*s; result[1,2] := y*z * (1-c)+x*s; result[2,2] := (z*z) * (1-c)+c; end;
// preprocess quarternion rotations X := rx; Y := ry; Z := rz; W := -rw; S := Sqrt(1.0 - W * W); // divide by zero if not (S = 0) then begin Axis[0] := X / S; Axis[1] := Y / S; Axis[2] := Z / S; Angle := 2 * geometry.ArcCos(W); if not (Angle = 0) then begin rotang:= CreateGlRotateMatrix( Angle * 180 / Pi, Axis[0], Axis[1], Axis[2]); glMultMatrixf(@rotang[0,0]); //glRotatef(Angle * 180 / Pi, Axis[0], Axis[1], Axis[2]); end; end;
Edited by Delfi, 23 April 2011 - 03:53 PM.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.