Skip to main content
gamedev.net
🔒 Locked

rotations

Started by parnell Sep 24, 2006 at 10:42 AM 5 replies 1.6k views
Original Post
parnell
parnell
Hi, I do MDX in c#, and i'm working on a sprite based game right now because my artists can't do 3d models, and i was just curious exactly how rotating sprites in the 3dX sprite drawer work. Do i just rotate my world matrix before drawing them? do i have to begin/end on Direct3d.SPrite with each individual sprite to get a different world matrix if using Draw(). Should i be using Draw2d instead? if so, why are there no overloads for float values? it uses system.drawing.point... I can't find anything with current Dx9.0 info using sprites, so any help rotating these things would be appreciated. Thanks. (some c# sample code on how to draw a sprite and rotate it around it's center would be appreciated. and c++ code won't be frowned upon either :) I figure this will also help me later on when i go to do a game and need a GUI using sprites might be good, or would it be better to use quads?
sirob
sirob
Per-Sprite rotations (and other transformations, such as scaling) are done using Sprite.Transform. You just set the matrix prior to calling Draw, and the sprite will be transformed by that matrix. There is no need to call Begin/End when changing the Transform matrix, unlike SetWorldViewLH (you can use both at the same time). The Sprite should be rotated around it center (if you define it correctly in the center parameter).

Quote:
I figure this will also help me later on when i go to do a game and need a GUI using sprites might be good, or would it be better to use quads?

I recommend Sprite for almost anything 2D. I only not use it when it doesn't provide the full functionality I need.

Hope this helps.
Sirob Yes.» - status: Work-O-Rama.
parnell
parnell
this is what i'm doing, but i know i need to offset the x,y somehow to scale from the center of the screen. i have screenheight and screenwidth 'globals'

device.Transform.View = Matrix.Scaling(zoomFactor, zoomFactor, 1.0f);
parnell
parnell
oh hey, in regards to the center parameter, is it the center of the sprite (based on the upper left of the sprite going down (positive y) and right(positive x) ..) OR is it based on the upper left of the screen? the documentation isn't very clear. I'm getting some strange results when trying to rotate.

Also, when i rotate a sprite, am i rotating around the Z axis like i would when looking at a model.
parnell
parnell
still needing a little help here, i'm trying to play around with it but every time i try to rotate a sprite by Transform property... it disappears off the screen.

I'm doing a Matrix.RotationZ... is that correct when dealing with sprites? since i'm rotating around the Z axis?

also, how do i rotate a view around a certain axis in space, rather than the origin?

If it's simpler, heres what i need to see some code for to understand:

i want to rotate a 128x128 sprite around it's object center and it will be located at 200,200,0. I want to then rotate the view around the center of the screen.. screenwidth/2, screenheight/2, 0.

Hope someone can help because the books i have are crap.

Thanks.
tont
tont
If you are trying to create a top/down effect in your game and you want to rotate along the Z axis, try this setting your world matrix = RotationMatrix * Translation Matrix. After you do that, then draw it.

If you dont set it properly and you rotate it, it will constantly rotate around the 'world matrix' center origin.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.