Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
    
You CreateOrthographic and CreateOrthographicOffCenter calls are equivalent, but the rotations applied aren't the same. –  r2d2rigo Dec 21 '11 at 15:46
    
@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. –  oddy Dec 21 '11 at 15:56

1 Answer 1

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);
share|improve this answer

Your Answer

 
discard

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.