Advertisement

[XNA] Matrix.CreateRotationX

Started by November 07, 2015 02:37 PM
4 comments, last by montify 9 years, 3 months ago

Hello,

I have a question:

When i create a Rotation Matrix like:


result = Matrix.CreateFromAxisAngle(new Vector3(0, 1, 0), MathHelper.ToRadians(90.0f));

Why i have on M11 and M33 a pretty high Value?:

E in a value means Exponent ?

rota.PNG

When i transform this Matrix with a Vector:


nw = new Vector3(-1, 0, 1); 
ne = new Vector3(1, 0, 1); 
sw = new Vector3(-1, 0, -1); 
se = new Vector3(1, 0, -1); 

nw = Vector3.Transform(nw, world);
ne = Vector3.Transform(ne, world);
sw = Vector3.Transform(sw, world);
se = Vector3.Transform(se, world);

i get:


{X:-1 Y:-1 Z:-4,371139E-08}
{X:1 Y:-1 Z:-4,371139E-08}
{X:-1 Y:1 Z:4,371139E-08}
{X:1 Y:1 Z:4,371139E-08}

Is the Y-Value correct?

Those values are really small.

-4.371139E-08 =

-4.371139 * 10^(-8) =

-4.371139 / 10*8 =

-0.00000004371139

Hello to all my stalkers.

Advertisement

Thank you for Reply

the thing is: is have 6 flat grids (33x33 Vertices) i would translate each grid to a Cube. Should the number not -1 or 1 ? Why is it so tiny?

No, main axis rotation with angles of multiples of 90° will yield 1, -1 or 0. Those small values are practically 0 so you're (usually) fine.

Rotation matrices are calculated using trigonometric functions and due to limited precision this small bias can happen. If that poses a problem (e.g. cracks in your cube mesh), hardcode those matrix values or the whole cube mesh.

Here an implementation of rotation on the X-axis to show you what happens :


void CMatrix4::SetRotationX( const float Angle )
{
  const float Cos = CMath::Cos( Angle );
  const float Sin = CMath::Sin( Angle );
  m44[ 0 ][ 0 ] = 1.0f; m44[ 0 ][ 1 ] = 0.0f; m44[ 0 ][ 2 ] = 0.0f; m44[ 0 ][ 3 ] = 0.0f;
  m44[ 1 ][ 0 ] = 0.0f; m44[ 1 ][ 1 ] = Cos;  m44[ 1 ][ 2 ] = -Sin; m44[ 1 ][ 3 ] = 0.0f;
  m44[ 2 ][ 0 ] = 0.0f; m44[ 2 ][ 1 ] = Sin;  m44[ 2 ][ 2 ] = Cos;  m44[ 2 ][ 3 ] = 0.0f;
  m44[ 3 ][ 0 ] = 0.0f; m44[ 3 ][ 1 ] = 0.0f; m44[ 3 ][ 2 ] = 0.0f; m44[ 3 ][ 3 ] = 1.0f;
}

Thank you guys for answer, i hardcoded the Matrix.

But i have another issue.

My Planet is normalized Cube with six side.

I create the Noise Value like here described:

https://britonia.wordpress.com/2009/12/23/noise-part-iii-gpu/

The Noise generated for each patch, so the PixelShader needs the Coordinate of the patch (xNW, xNE, xSW).

For the root Patch ( without subedived the quadtree it´s):



 nw = new Vector3(-1,0, 1);
 ne = new Vector3(1, 0, 1);
 sw = new Vector3(-1, 0, -1);

Assume this is for the TopSide of the Cube.

How i get the noise for the Front side of the Cube?

It´s a 3d noise Funtion in the Shader so how i can translate the nw, se, sw Vector to match the front side (when i pass the right Value i have no seams on the Cube Faces like:)

seams.PNG

This topic is closed to new replies.

Advertisement