XNA Track Pixel Rotation
I'm making an xna game where the tank has to move around the terrain. I need to find the bottom of the tank when rotated so that I can move it up and down as the player loops through the landscape.
for example, if I have a sprite with its top left corner at 400 to 300 and I rotate it around its center 45 degrees around its center how do I find the new locations of the bottom track.
thanks
Thanks for the answer Langaurd.
I've looked at the article link before, but didn't understand how it works.
I'm doing a 2d scrolling game. When the player moves left and right, the tank must also tilt to follow the contour of the terrain.
I have two vectors that hold the back of the track and one that holds the front bottom of the track.
I tried
Vector2 backBottom = new Vector2(5, 25); Vector2 frontBottom = new Vector2(5, 32); backBottom = Vector2.Transform(backBottom+position, Matrix.CreateRotationZ(angle)); frontBottom = Vector2.Transform(frontBottom+position, Matrix.CreateRotationZ(angle));
but it gave me some weird values
a source to share
It is not 100% clear what exactly you are trying to do. You mention a sprite that is 2D, but your description is in 3D. If you are taking a 2D side view, you cannot tell that the tank rotates 45 degrees. If you're doing a 2D top-down view, you don't have to worry about where the bottom of the tred is.
Anyway, two sentences. If you're keeping a close eye on rotating pixels, read this article: 2D Collision with Transformed Pixels from creators.xna.com. However, I would recommend tracking vectors. Use two vectors to represent the track locations and then use Vector2.Transform to rotate them with the tank. Then you can use vectors to check if the tracks hit, what angle they have, etc.
a source to share
You need to define a clearer orientation for the sprite. For tanks, I would use Front and Up Vector. Now you rotate both of them along with the angle of your discs depending on the terrain. Let's say these vectors are in the center of your sprite. and your sprite rotates just like your front and front vectors. Now just multiply your Half-Height by the -Up vector and you should have your local bottom center, add your tank position and you have your bottom track position in the world.
Important: Do not mix a point, which can be expressed as a vector, or a real vector, which has no position and only shows direction. For directions, it is important to normalize the vector.
Sorry for the vague answer, but you are a bit vague too.
a source to share