Problem about drawing

Jan 24, 2011 at 4:41 PM


Even though I am new to Farseer and XNA, I am quickly learning both of them. There is one thing I can't get working properly and even if there is some discussions about it, I can't make it work. I am using the Camera 2D that comes with the Demo.

I have read a few discussions but none of them seemed to solve my problem.

The problem is that when I draw on the screen, the position is not the same.

I do a BasicEffect to associate the View and the Projection


_Effect.View = pView; 
_Effect.Projection = pProjection; 
_Effect.Texture = Animation.Texture; 
_Effect.TextureEnabled = true; 
_Effect.VertexColorEnabled = true; 

//Begin my spritebatch with the effect to apply the view and projection.



//The position, rotation and origin all come from the body of my polygon. 

pSpriteBatch.Draw(Animation.Texture, pPosition, source, Color.White, pRotation, pOrigin, 0.06f, SpriteEffects.None, 0.0f);

I move the polygon with my mouse and when it draws, it's always around the polygon. The next thing I am thinking is to use my own Camera but I'm not sure if that's my problem.

Thanks for answering.


Jan 24, 2011 at 4:58 PM
Edited Jan 24, 2011 at 4:59 PM

It is quite hard to tell, what you mean by "The problem is that when I draw on the screen, the position is not the same." What do you draw... and not the same as what actually? Also you don't provide any values anywhere. It is impossible to answer your question without knowing what you view and projection matrices look like.

The Demo camera is pretty much hardcoded to work with an orthographic projection and units ranging from -25 to 25 on the y-axis. It is nothing that you can just throw into your project, when using a completely different coordinate system.

What most likely is also missing is some scaling factor somewhere, as Farseer units should be scaled to MKS (meters kilos seconds) system and your drawing is normally somewhat pixel and resolution dependent, e.g. you specify your sprites in pixels not meters.

For a simple example of how to draw things and using a basic camera, have a look at the updated HelloWorldXNA sample in the source control.

Jan 24, 2011 at 6:44 PM

Thanks for your answer.

I got some images to explain what I was talking about. , ,

As for the view and projection matrices , I have tried using the one that came with the Demo and the one on the latest source version.

        public void CreateProjection()
            // L/R/B/T
            Projection = Matrix.CreateOrthographicOffCenter(-25 * _graphics.Viewport.AspectRatio,
                                                            25 * _graphics.Viewport.AspectRatio, -25, 25, -1, 1);
            //Projection = Matrix.CreateOrthographicOffCenter(0f, _graphics.Viewport.Width / 64.0f,
            //                                                 _graphics.Viewport.Height / 64.0f, 0f, 0f, 1f);

            if (ProjectionUpdated != null)

        private void Resize()

            View = Matrix.CreateTranslation(new Vector3((Position - ScreenCenter) / 64.0f, 0f)) *
                     Matrix.CreateRotationZ(Rotation) *
                     Matrix.CreateTranslation(new Vector3(ScreenCenter / 64.0f, 0f)) *

            //View = Matrix.CreateRotationZ(_rotation) * Matrix.CreateTranslation(-_position.X, -_position.Y, 0) *
            //       Matrix.CreateScale(_zoom);

            if (ViewUpdated != null)

I understand that the units are hardcoded and I will modify it in my project.

For the conversion, I have a created a conversion class and I am using it at will right now.

Finally, I have looked at the code before asking a question and tried it without any success. Problem is still unsolved.