# Why are the vertices from a mesh not transforming using a camera?

I am able to use a camera class to change the view and rotation of a simple quad, so I know it works, but when I move on to a more advanced geometry, such as a mesh, I am unable to affect the transform of the object at all. The WVP matrix does change in the mesh example (using print statements), but no movement or rotation is observed.

My camera first calls

camera.SetLens(0.33f * (float)Math.PI, Width / Height, 0.5f, 1000.0f)


on initialization, where width and height is the width and height of the window, SetLens is defined here:

public void SetLens(float fovY, float aspect, float zn, float zf)
{
FovY = fovY;
Aspect = aspect;
NearZ = zn;
FarZ = zf;

NearWindowHeight = 2.0f * NearZ * (float)Math.Tan(0.5f * FovY);
FarWindowHeight = 2.0f * FarZ * (float)Math.Tan(0.5f * FovY);

Proj = Matrix.PerspectiveFovLH(FovY, Aspect, NearZ, FarZ);
}


Every frame I call Draw, and it updates the view matrix of the camera. (Draw is on the bottom of this code snippet)

public void UpdateViewMatrix()
{
var r = Right;
var u = Up;
var l = Look;
var p = Position;

l = Vector3.Normalize(l);
u = Vector3.Normalize(Vector3.Cross(l, r));

r = Vector3.Cross(u, l);

var x = -Vector3.Dot(p, r);
var y = -Vector3.Dot(p, u);
var z = -Vector3.Dot(p, l);

Right = r;
Up = u;
Look = l;

var v = new Matrix();
v[0, 0] = Right.X;
v[1, 0] = Right.Y;
v[2, 0] = Right.Z;
v[3, 0] = x;

v[0, 1] = Up.X;
v[1, 1] = Up.Y;
v[2, 1] = Up.Z;
v[3, 1] = y;

v[0, 2] = Look.X;
v[1, 2] = Look.Y;
v[2, 2] = Look.Z;
v[3, 2] = z;

v[0, 3] = v[1, 3] = v[2, 3] = 0;
v[3, 3] = 1;

View = v;
}

private void Draw()
{
camera.UpdateViewMatrix();
Matrix view = camera.View;
Matrix proj = camera.Proj;
Matrix world = Matrix.Identity;
Matrix WVP = world * view * proj;
...
}


For the camera to make changes, I call the following functions on keypress/mouse movement

public void Strafe(float d)
{
Position += Right * d;
}

public void Walk(float d)
{
Position += Look * d;
}

public void Pitch(float angle)
{
var r = Matrix.RotationAxis(Right, angle);
Up = Vector3.TransformNormal(Up, r);
Look = Vector3.TransformNormal(Look, r);
}

public void Yaw(float angle)
{
var r = Matrix.RotationY(angle);
Right = Vector3.TransformNormal(Right, r);
Up = Vector3.TransformNormal(Up, r);
Look = Vector3.TransformNormal(Look, r);
}


In my vertex shader I just set the position of the vertex like this:

output.position = mul(worldViewProj, position);


So again, I can get it working with a simple triangle or quad, but I need to load triangles and their connectivity from a TIN and I am able to draw the mesh on the screen but my camera operations are not translating the mesh at all. Any clues on what I might be doing wrong? For clarification, the whole mesh should be considered one object.

First of all, I haven't looked through all that code, but my first guess would be this line in the shader:

output.position = mul(worldViewProj, position);


If your position.w is 0, then no translation (movement) from the camera will affect the output.position. Can you try to force set the w component to 1 like this:

output.position = mul(worldViewProj, float4(position.xyz, 1));


Otherwise, you may have to debug the cpu code. For GPU debugging, you can try graphics/GPU debugger tools, which can step through shader code like it was cpu code (but chances are that it won't work for your GPU).

Good Luck!