# could some one have a look at this. local roation to real world

This topic is 3013 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

// this is only for the Y rotation float matrix[16]; Item->Model->GetMatrix( matrix );// this is an engine that gets the matrix float matrixSinMinus = matrix[2]; float matrixSin = matrix[8]; float matrixCos = matrix[10]; // rotate local corners to there real world position float realWorldX,realWorldZ; struct p { float x,y;} point; realWorldX = (matrixCos * point.x) + (matrixSinMinus * point.z); realWorldZ = (matrixSin * point.x) + (matrixCos * point.z);

##### Share on other sites
Okay. I've looked at it.

##### Share on other sites
If there's something wrong with it, what's wrong?
If there's not, why post it?
Is there any particular reason why you're inlining parts of matrix multiplication instead of just multiplying your matrix with a vector?

##### Share on other sites
Quote:
 Original post by ZaoIf there's something wrong with it, what's wrong?If there's not, why post it?Is there any particular reason why you're inlining parts of matrix multiplication instead of just multiplying your matrix with a vector?

i just want to make sure if this is right , its the first time that i have tryed to impliment it .

its done this way cause its 3d engine that get taught in first year off uni

##### Share on other sites
It looks like what you are doing is taking a matrix assumed to be of the following form

$\left[\begin{array}{cccc}\cos\left(\theta\right)&0&-\sin\left(\theta\right)&0\\0&0&0&0\\\sin\left(\theta\right)&0&\cos\left(\theta\right)&0\\0&0&0&1\end{array}\right]$

Ripping out the sin and cos peices, and using them to rotate a vector in the x-z plane. This solution does work, but it only works if you are rotating around the y axis. If this is a special case where you are always going to rotate around the y axis, why not use a 2x2 matrix instead of a 4x4.

If you are looking for a more general solution, why not just do this?

$\left[\begin{array}{c}x'\\0\\z'\\1\end{array}\right]=\left[\begin{array}{cccc}\cos\left(\theta\right)&0&-\sin\left(\theta\right)&0\\0&0&0&0\\\sin\left(\theta\right)&0&\cos\left(\theta\right)&0\\0&0&0&1\end{array}\right]\left[\begin{array}{c}x\\0\\z\\1\end{array}\right]$

• 33
• 12
• 10
• 9
• 9
• ### Forum Statistics

• Total Topics
631354
• Total Posts
2999489
×