2
\$\begingroup\$

Pre. Having these matrix transformations:

var scale = Matrix.CreateScale(50f);
var eye = new Vector3(0, 0, 10.0f);
var view = Matrix.CreateLookAt(eye, Vector3.Zero, Vector3.Up);
var projection = scale * Matrix.CreateOrthographic(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 1.0f, 1000f);
var rotation = Matrix.CreateRotationX(-MathHelper.PiOver2)*Matrix.CreateRotationY(MathHelper.PiOver2);

and then for each mesh producing “world” like this:

var localWorld = transforms[mesh.ParentBone.Index] * rotation;

and then applying these parameters to the effect:

effect.Parameters["World"].SetValue(localWorld);
effect.Parameters["View"].SetValue(view);
effect.Parameters["Projection"].SetValue(projection);
effect.Parameters["Bones"].SetValue(boneTransforms);
effect.Parameters["WorldInverseTranspose"].SetValue(Matrix.Transpose(Matrix.Invert(localWorld)));

I’m getting nice model like this:

Kangaroo using CreateOrthographic

Post. But after I changed CreateOrthographic to CreateOrthographicOffCenter like this:

var projection = scale * Matrix.CreateOrthographicOffCenter(-GraphicsDevice.Viewport.Width / 2f, GraphicsDevice.Viewport.Width / 2f, GraphicsDevice.Viewport.Height / 2f, -GraphicsDevice.Viewport.Height / 2f, 1.0f, 1000f);
var rotation = Matrix.CreateRotationX(MathHelper.PiOver2) * Matrix.CreateRotationY(-MathHelper.PiOver2);

I’ve got this:

Kangaroo using CreateOrthographicOffCenter

Can someone give me a hint what am I doing wrong?

\$\endgroup\$
2
  • \$\begingroup\$ You CreateOrthographic and CreateOrthographicOffCenter calls are equivalent, but the rotations applied aren't the same. \$\endgroup\$
    – r2d2rigo
    Dec 21, 2011 at 15:46
  • \$\begingroup\$ @r2d2rigo I know. But that doesn’t change anything. Without rotation modification model will stay dark. But except for that, it will be also facing down. \$\endgroup\$
    – oddy
    Dec 21, 2011 at 15:56

1 Answer 1

1
\$\begingroup\$

Found an error.

Matrix.CreateOrthographicOffCenter(-GraphicsDevice.Viewport.Width / 2f, GraphicsDevice.Viewport.Width / 2f, GraphicsDevice.Viewport.Height / 2f, -GraphicsDevice.Viewport.Height / 2f, 1.0f, 1000f);

That’s not the same as

 Matrix.CreateOrthographic(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 1.0f, 1000f);

CreateOrthographicOffCenter sets M11 as 2f / (right - left) and so we’re getting value equal to GraphicsDevice.Viewport.Width, but M22 is set as 2f / (top - bottom) resulting in height equal to -GraphicsDevice.Viewport.Height

Thus, correct setup for the CreateOrthographicOffCenter is

Matrix.CreateOrthographicOffCenter(-GraphicsDevice.Viewport.Width / 2f, GraphicsDevice.Viewport.Width / 2f, -GraphicsDevice.Viewport.Height / 2f, GraphicsDevice.Viewport.Height / 2f, 1.0f, 1000f);
\$\endgroup\$

You must log in to answer this question.

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