João Serra
João Serra

Reputation: 399

XNA setting isometric camera view or world?

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.

Upvotes: 1

Views: 2393

Answers (2)

Andrew Russell
Andrew Russell

Reputation: 27225

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.

Upvotes: 2

Blau
Blau

Reputation: 5762

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);

Upvotes: 0

Related Questions