Note that there are some explanatory texts on larger screens.

plurals
  1. PODirect3D 11 WorldViewProjection Matrix Transformation Not Working
    text
    copied!<p>I have a simple square I'm drawing in 3D space using Direct3D 11 and SlimDX, with the following coordinates (I know it renders)</p> <pre><code>0,0,0.5 0,0.5,0.5 0.5,0.5,0.5 0.5,0,0.5 </code></pre> <p>I have a camera class that handles camera movement by applying matrix transformations to the viewmatrix. e.g. Camera.MoveForward(float x) moves the camera forward by x. It also holds the View and Projection matrices. I instantiate them using the following code:</p> <pre><code>Matrix view = Matrix.LookAtLH( new Vector3(0f, 0f, -5f), new Vector3(0f, 0f, 0f), new Vector3(0f, 1f, 0f)); Matrix projection = Matrix.PerspectiveFovLH( (float)Math.PI/2, WINDOWWIDTH/WINDOWHEIGHT, 0.1f, 110f); </code></pre> <p>The world matrix is set to the identity matrix.</p> <p>In my shader code I transform my coordinates using the following code:</p> <pre><code>PS_IN VS(VS_IN input) { PS_IN output = (PS_IN)0; output.pos = mul( input.pos, WorldViewProjection ); output.col = float4(1,1,1,1); return output; } </code></pre> <p>Where WorldViewProjection is set in my code using the following:</p> <pre><code>Matrix worldview = Matrix.Multiply(world, camera.ViewMatrix); Matrix worldviewprojection = Matrix.Multiply(worldview, camera.ProjectionMatrix); </code></pre> <p>I know the camera class's transformations are working as it's old code I wrote for an MDX application which worked fine, however when this runs I see my square, and moving forwards and backwards works just fine, but moving left and right seems to rotate the square around the Y (up) axis instead of translating it, moving up and down has a similar effect, rotating instead about the X (horizontal) axis.</p> <p>For reference, the camera movement functions:</p> <pre><code>public void MoveRight(float distance) { position.Z += (float)(Math.Sin(-angle.Y) * -distance); position.X += (float)(Math.Cos(-angle.Y) * -distance); updateViewMatrix(); } public void MoveForward(float distance) { position.X += (float)(Math.Sin(-angle.Y) * -distance); position.Z += (float)(Math.Cos(-angle.Y) * -distance); updateViewMatrix(); } public void MoveUp(float distance) { position.Y -= distance; updateViewMatrix(); } private void updateViewMatrix() { ViewMatrix = Matrix.Translation(position.X, position.Y, position.Z) * Matrix.RotationY(angle.Y) * Matrix.RotationX(angle.X) * Matrix.RotationZ(angle.Z); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload