View Full Version : Matrix question

KurtCob

09-28-2000, 01:19 AM

Hello people, I'm here again http://www.opengl.org/discussion_boards/ubb/smile.gif,

I'm sorry but I don't know how to multiply a point (X, Y, Z) to a matrix (may be a rotating matrix) can someone give me some help, I also don't know the rotating matrix, if I'm not making a mistake, there is a special one for each axis(I mean one for the X axis, one for the Y axis and another one for the Z axis), please can some one help me ?

Thank you for the moment

Best regards

Kurt

edotorpedo

09-28-2000, 09:55 AM

Hi,

maybe this function in pseudocode will help. In this function point b is rotated around point a using matrix calcs. Here you can only specify xangle and yangle. Mail me for any questions: fredo@studenten.net

----------------------------------

Public Function rotatePoint(a As PointType, b As PointType, xangle As GLfloat, yangle As GLfloat) As PointType

Dim X As GLfloat, Y As GLfloat, z As GLfloat

'These are the matrices for rotating any point in R3 around the axes

'R(y) = | cos(a) 0 -sin(a) |

' | 0 1 0 |

' | sin(a) 0 cos(a) |

'

'R(z) = | cos(b) sin(b) 0 |

' | -sin(b) cos(b) 0 |

' | 0 0 1 |

'

'R(x) = | 1 0 0 |

' | 0 cos(c) sin(c) |

' | 0 -sin(c) cos(c) |

'

'In this sub I multiply (R(y) with b=yangle) with (R(x) with a=xangle)..

'The matrix that is created is multiplied with x,y,z to create a point

X = a.X - b.X 'substracting b to rotate around origin, otherwise matrix won't

Y = a.Y - b.Y 'work

z = a.z - b.z

a.X = Cos(yangle) * X + Sin(yangle) * Sin(xangle) * Y - Sin(yangle) * Cos(xangle) * z

a.Y = 0 + Cos(xangle) * Y + Sin(xangle) * z

a.z = Sin(yangle) * X + Cos(yangle) * -Sin(xangle) * Y + Cos(yangle) * Cos(xangle) * z

a.X = a.X + b.X 'adding b again to achieve original rotated point

a.Y = a.Y + b.Y

a.z = a.z + b.z

rotatePoint = a

End Function

---------------------------------------------

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.