Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My technical english is a little rusty so to avoid misunderstands please be patient with me :)
I will try to be brief and clear

- I have a 2d sprite character on the screen
- I've just start learning how to draw 3d primitives and work with the cameras
- I'm working on a 2d isometric environment
- I made a 3d isometric triangle which I want to center in character
- I'm trying to do something similar to a flashlight

- The triangle is not centered on character (probably because of the scales between 2d and 3d workspace)
-the triangle speed does not match the character speed.


player vision

        playerVision = new VertexPositionColor[3];

        playerVision[0].Position = new Vector3(-15f, -30f, 0f);
        playerVision[0].Color = Color.Transparent;
        playerVision[1].Position = new Vector3(0f, 0f, 0f);
        playerVision[1].Color = new Color(70, 102, 25, 20);
        playerVision[2].Position = new Vector3(15f, -30f, 0f);
        playerVision[2].Color = Color.Transparent;


private void SetUpCamera()
    // isometric angle is 35º , for 50y = -107z
    viewMatrix = Matrix.CreateLookAt(new Vector3(0, -107, 50), new Vector3(0, 0, 0), new Vector3(0, 1, 0));

    // TODO: use viewport for whole window or just the draw area ?
    projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GameInterface.vpWholeWindow.AspectRatio, 1.0f, 300.0f);

private void drawPlayerVision(GameTime gameTime, SpriteBatch spriteBatch, Vector2 playerDrawPos)
    // 50 is related with the camera position in the axis
    // TODO: this probably is incorrect since it should be a module of the distance? btw points
    Vector2 playerPos = playerDrawPos / 50;

    effect.CurrentTechnique = effect.Techniques["ColoredNoShading"];


    // rotating like a radar
    Matrix worldMatrix = Matrix.CreateRotationZ(3 * visionAngle);

    // moving to the character
    worldMatrix *= Matrix.CreateTranslation(new Vector3(playerPos.X, playerPos.Y, 0));            


    foreach (EffectPass pass in effect.CurrentTechnique.Passes)
         Game.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, playerVision, 0, 1, VertexPositionColor.VertexDeclaration);

if you need more details please ask me I've been trying to figure out all by myself so its a little hard for me :)

Thank you for your assistance

share|improve this question
Look into Viewport.Project and Viewport.Unproject methods, they might help you – NDraskovic Aug 1 '12 at 9:17
thanks im looking into them now – Navy Seal Aug 1 '12 at 16:54
I've still not been able to implement unproject... seems the primitve isn't drawn and also the values Im getting from unproject are Nan (not a number), ive been searching for an example but all i could find was an old xna example which isnt working anymore on xna 4... this seems so easy to implement but its just not working :( – Navy Seal Aug 2 '12 at 14:37
Well the first thing I can tell you is that working with primitives can be very frustrating, so you might try to make a model of the object you are trying to make (there are free modeling programs like Blender, Wings3D...). Working with models is a much easier (the basic stuff) than working with primitives. As for your problems with 2D-3D coordinates, loock into the picking algorithm, it might not solve your problem, but it might point you in the right direction. – NDraskovic Aug 4 '12 at 8:43
up vote 0 down vote accepted

I found that the issue was related with the usage of viewports. When defining viewports for 3d we need to define 2 extra props minDepth and maxDepth.

If we forget to define these two... the viewport is still valid for 2d but using unproject in 3d will return the NaN issue

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.