0
\$\begingroup\$

I got a model, and a camera pointing at this model, I think my camera position is the problem. Its showing the front of the model, but I want it to show its back like in third person. My camera code is:

Vector3 thirdPersonReference = new Vector3(0, 100, -100);
public Camera(Vector3 landscapePosition, Player _player)
    {
        this.player = _player;
        rotationMatrix = Matrix.CreateRotationY(this.player.Rotation);
        Vector3 transformedReference = Vector3.Transform(thirdPersonReference, rotationMatrix);
        this.position = transformedReference + this.player.Position;
        viewMatrix = Matrix.CreateLookAt(this.position, this.player.Position, new Vector3(0.0f, 1.0f, 0.0f));
        projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, this.player.AspectRatio,
            1.0f, 1000.0f);
        terrainMatrix = Matrix.CreateTranslation(landscapePosition);
    }

What is that Im doing wrong???

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

If I understand right what you are trying to move the camera backwards and upwards relative to the player model. However, in the Z-axis direction XNA ago, that is, you need to set Z coord 100 instead of -100. Or you can do like that:

Vector3 thirdPersonReference = Vectro3.Up * 100 + Vector3.Backward * 100;

Vector3.Backward has value (0, 0, 1), abd accordingly Vector3.Forward has value (0, 0, -1).

Please, see link and pay special attention to Remarks section.

\$\endgroup\$
5
  • \$\begingroup\$ I tried that out, and printed screen so u can see what I mean, this is the model Im rendering (with camera in front of it): tinypic.com/r/oh1lox/8 and this is when I tested with ur values: tinypic.com/r/sbk4xt/8 its like the model is insideout, I dont know. \$\endgroup\$
    – Caio Keto
    Commented Jan 14, 2015 at 12:19
  • \$\begingroup\$ Seems like problem not in camera and in CullMode or DepthStencilState. Try set DepthStencilState to DepthStencilState.Default and CullMode to CullMode.CounterClockwise or CullMode.Clockwise (depending on how your model mesh is generated) for your GraphicsDevide before drawind model. \$\endgroup\$
    – user52551
    Commented Jan 14, 2015 at 12:31
  • \$\begingroup\$ It worked, it was the DepthStencilState, I changed it and it worked like a charm. Thanks man! Really thanks! \$\endgroup\$
    – Caio Keto
    Commented Jan 14, 2015 at 12:39
  • \$\begingroup\$ Just one more question, to rotate the camera (like arcball) can I just change the thirdPersonReference values? like add Vector3.Up * 100, etc? \$\endgroup\$
    – Caio Keto
    Commented Jan 14, 2015 at 12:47
  • \$\begingroup\$ If you need free rotate the camera around the character that you can specify the displacement vector as Vector3 cameraOffset = Vector3.Backward * cameraDistance, and apply rotations to this vector. It will be more convenient than to add the offset along the axes. \$\endgroup\$
    – user52551
    Commented Jan 14, 2015 at 13:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .