Home Game Development xna – How ought to I calculate world and projection matrices on this situation?

xna – How ought to I calculate world and projection matrices on this situation?

0
xna – How ought to I calculate world and projection matrices on this situation?

[ad_1]

Well, if you wish to use it for 2D video games (assuming from the tags), you solely want a Transform matrix to use to the SpriteBatch, you do not want World and Projection matrices.

So, if you’re drawing an object that ought to be drawn inside your recreation world (e.g. the primary participant), you employ the next Begin technique from SpriteBatch (XNA 4.0, exchange the opposite parameters by what you want):

spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, null, impact, digital camera.Transform);
/*
Draw the world objects like partitions, gamers, weapons, and many others.
...
*/
spriteBatch.End();

This will apply the digital camera’s impact to the drawing, simulating a digital camera inside your world.

For different visible components that aren’t a part of the world (just like the HUD with participant well being, and many others.), you simply use the common Begin technique (with out the digital camera’s matrix as a parameter) to attract it, since you do not really need them to maneuver throughout the display when the digital camera strikes, you need them to be static.

The approach the digital camera works is that it applies a translation matrix getting into the other way of the place you need your digital camera to be (it explains the unfavorable indicators in Matrix.CreateTranslation(-Position.X, -Position.Y, 0) to simulate a digital camera transferring inside a world. In truth, what you are actually doing is that you just’re transferring the world round in order that the digital camera’s view is represented by the sport’s window.

So, say you need your digital camera to maneuver to the precise by 20 pixels, you wish to transfer your complete world to the left by 20 pixels to offer the consumer the feeling that they moved to the precise. This is achieved by making use of the digital camera’s matrix to all of the world objects, to type of transfer them round.

The identical goes for scaling and rotation, you progress the world round if you’re drawing them to offer a feeling of change.

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here