Jan 12, 2011 at 1:30 PM
Edited Jan 12, 2011 at 2:30 PM
just found out about your new HelloWorld Sample which should get some of the confusion out of my code. Which was to that point indeed Trial & Error regarding the Transformation and Scaling.
I also just realized the Radius vs. Diameter thingy in the Constructor. Actually I wanted to have the Screen at a fixed size so that a higher Resolution means you can see more of the World Space. I guess my approach was wrong.
I will rewrite the Physics integration using your new HelloWorld Sample which looked pretty understandable to me.
ok, I managed to replicate the Behavior from the new HelloWorld Sample.
I am currently doing the following:
Fixtures for Sprites are created like this:
float width = s.Asset.Width / TwengineGame.MeterInPx;
float height = s.Asset.Height / TwengineGame.MeterInPx;
if (collisionShape == CollisionShape.Circle)
f = FixtureFactory.CreateCircle(this.pw, width/2, 1f);
else if (collisionShape == CollisionShape.Rectangle)
f = FixtureFactory.CreateRectangle(this.pw, width, height, 1.0f);
The Camera Class defines this Projection Matrix:
Projection = Matrix.CreateOrthographicOffCenter(0f, _graphics.Viewport.Width / TwengineGame.MeterInPx, _graphics.Viewport.Height / TwengineGame.MeterInPx, 0f, 0f, 1f);
Sprites are Drawn like this then:
Vector2 screenCoords = this.Fixture.Body.Position * TwengineGame.MeterInPx;
Vector2 origin = new Vector2(this.Asset.Width / 2, this.Asset.Height / 2);
sb.Draw(this.Asset, screenCoords, null, this.Color, this.Fixture.Body.Rotation, origin, 1f, SpriteEffects.None, this.LayerDepth);
Passing no View Matrix to the RenderDebugView() and SpriteBatch.Begin() calls this works flawless.
I now tried to use the View Matrix for Camera Control, since that's the common usage as I understand it. So I defined the following View Matrix for the Camera and passed it to RenderDebugView() and SpriteBatch.Begin():
View = Matrix.CreateRotationZ(_rotation) * Matrix.CreateTranslation(-_position.X, -_position.Y, 0) * Matrix.CreateScale(_zoom);
Zooming works fine, but the Translation part seems wrong. As soon as introduce the Translationmatrix and try moving the Camera the DebugView and the Sprites get Offset again. I guess it's because of the Scaling Factor MeterInPx missing somewhere in the Equation.
But then again I thought the view Matrix would get applied to both the DebugView Rendering and the SpriteBatch rendering and should thus have the same Effect on both?!
I am a bit confused here, if you could give me a nod in the right direction I would appreciate it.