| |
 |
|
| Computers Forum Index » Computer - Graphics (Algorithms) » How to build a local matrix using Position/LookAt and Up |
|
Page 1 of 1 |
|
| Author |
Message |
| ben |
Posted: Sun Jun 05, 2005 7:03 pm |
|
|
|
Guest
|
Hi All,
I'm currently using OpenGL and was wanting to create a construct for my
Matrix4 class to simplify construction of a world matrix as follows:
/**
*Constructs a WORLD matrix using Position/LookAt and Up vectors
*/
Matrix4(const Vector3& vPos, const Vector3& vLookAt, const Vector3&
vUp);
Does anyone have any code they could share with me that does this?
Also, It would be a help if anyone knows how to extract the
Position/LookAt and Up vectors from a Matrix:
const Vector3& GetPosition()const;
const Vector3& GetLookAt()const;
const Vector3& GetUp()const;
Any help and or links would be much appreciated.
Thanks in advance,
Ben. |
|
|
| Back to top |
|
|
|
| Leo Spano |
Posted: Sun Jun 05, 2005 7:03 pm |
|
|
|
Guest
|
ben wrote:
Quote: Hi All,
I'm currently using OpenGL and was wanting to create a construct for my
Matrix4 class to simplify construction of a world matrix as follows:
/**
*Constructs a WORLD matrix using Position/LookAt and Up vectors
*/
Matrix4(const Vector3& vPos, const Vector3& vLookAt, const Vector3&
vUp);
Does anyone have any code they could share with me that does this?
Also, It would be a help if anyone knows how to extract the
Position/LookAt and Up vectors from a Matrix:
Let M a 4x4 matrix and let your vectors be normalised row vectors (the
point vPos must not be normalised).
Then
[ vRight , -vPos dot vRight ]
[ vUp, -vPos dot vUp ]
M = [ vLookAt, -vPos dot vLookAt ]
[ 0, 0, 0, 1 ]
where
vRight = vLookAt cross vUp.
Note that M * vPos = [0,0,0,1].
Hope it helps.
--
Leo |
|
|
| Back to top |
|
|
|
| ben |
Posted: Mon Jun 06, 2005 3:08 pm |
|
|
|
Guest
|
Cheers Leo.
Leo Spano wrote:
Quote: ben wrote:
Hi All,
I'm currently using OpenGL and was wanting to create a construct for my
Matrix4 class to simplify construction of a world matrix as follows:
/**
*Constructs a WORLD matrix using Position/LookAt and Up vectors
*/
Matrix4(const Vector3& vPos, const Vector3& vLookAt, const Vector3&
vUp);
Does anyone have any code they could share with me that does this?
Also, It would be a help if anyone knows how to extract the
Position/LookAt and Up vectors from a Matrix:
Let M a 4x4 matrix and let your vectors be normalised row vectors (the
point vPos must not be normalised).
Then
[ vRight , -vPos dot vRight ]
[ vUp, -vPos dot vUp ]
M = [ vLookAt, -vPos dot vLookAt ]
[ 0, 0, 0, 1 ]
where
vRight = vLookAt cross vUp.
Note that M * vPos = [0,0,0,1].
Hope it helps.
--
Leo |
|
|
| Back to top |
|
|
|
|
|
All times are GMT
The time now is Sun Nov 08, 2009 8:47 am
|
|