1

I'm trying to create an isometric (35 degrees) view by using a camera.

I'm drawing a triangle which rotates around Z axis.

For some reason the triangle is being cut at a certain point of the rotation giving this result

http://img442.imageshack.us/img442/8987/imagezle.jpg

I calculate the camera position by angle and z distance using this site: http://www.easycalculation.com/trigonometry/triangle-angles.php

This is how I define the camera:

// isometric angle is 35.2º => for -14.1759f Y = 10 Z
Vector3 camPos = new Vector3(0, -14.1759f, 10f);
Vector3 lookAt = new Vector3(0, 0, 0);
viewMat = Matrix.CreateLookAt(camPos, lookAt, Vector3.Up);


//projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, Game.GraphicsDevice.Viewport.AspectRatio, 1, 100);
float width = GameInterface.vpMissionWindow.Width;
float height = GameInterface.vpMissionWindow.Height;
projMat = Matrix.CreateOrthographic(width, height, 1, 1000);

worldMat = Matrix.Identity;

This is how I recalculate the world matrix rotation:

worldMat = Matrix.CreateRotationZ(3* visionAngle);

// keep triangle arround this Center point
worldMat *= Matrix.CreateTranslation(center);

effect.Parameters["xWorld"].SetValue(worldMat);

// updating rotation angle
visionAngle += 0.005f;

Any idea what I might be doing wrong? This is my first time working on a 3D project.

1
  • What does "For some reason the is being cut at a certain point of the rotation giving this result" mean? I think you left out a word. Commented Aug 13, 2012 at 0:07

2 Answers 2

2

Your triangle is being clipped by the far-plane.

When your GPU renders stuff, it only renders pixels that fall within the range (-1, -1, 0) to (1, 1, 1). That is: between the bottom left of the viewport and the top right. But also between some "near" plane and some "far" plane on the Z axis. (As well as doing clipping, this also determines the range of values covered by the depth buffer.)

Your projection matrix takes vertices that are in world or view space, and transforms them so that they fit inside that raster space. You may have seen the standard image of a view frustum for a perspective projection matrix, that shows how the edges of that raster region appear when transformed back into world space. The same thing exists for orthographic projections, but the edges of the view region are parallel.

The simple answer is to increase the distance to your far plane so that all your geometry falls within the raster region. It is the fourth parameter to Matrix.CreateOrthographic.

Increasing the distance between your near and far plane will reduce the precision of your depth buffer - so avoid making it any bigger than you need it to be.

4
  • i was able to fix it by setting the near plane as -500, but it confuses me because i though we could only have positive values in the near plane Commented Aug 13, 2012 at 11:19
  • 1
    A negative near plane creates problems for a perspective camera. The perspective camera represents a view frustum. If the near plane is zero then the near face will be a single point, and if the near plane is negative the near face (and all the geometry behind the camera) will be inverted. This causes all kinds of weirdness. However, an orthographic camera creates a view prism, and so the near face is always the same size no matter where it is placed - negative locations are ok. Commented Aug 13, 2012 at 11:54
  • thanks you. If you don't mind I would like to ask 1 last question. I still don't totally understand how effects work but I might need to draw 3d objects/models which are not in isometric view. Should I rotate the camera to an isometric view or rotate the 3d objects? Each effect can have it's own camera right? You help me allot thank you Commented Aug 13, 2012 at 13:53
  • 1
    Probably best to ask these sort of things in a fresh question. But the mini-answer is: Use the world matrix to move models into the right position/orientation/scale in world space, use the view matrix to move the world around so that it's in the right place relative to the camera, and the projection matrix we have already discussed will take that transformed world and put it that raster box. When drawing models, they'll probably each have their own world matrix, but share view and projection matrices. Commented Aug 14, 2012 at 8:15
0

I think your far plane is cropping it, so you should make bigger the projection matrix far plane argument...

 projMat = Matrix.CreateOrthographic(width, height, 1, 10000);

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