Sign in to follow this  

Rotation?

This topic is 4665 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello.. I was wondering how you do rotation.. I managed to rotate the entire world, and I've managed to rotate a D3DXSPRITE, but not like a game char.. It's a 2d game, and I wanna rotate the arms of the player (like in Facewound).. I don't want to use those sprite functions as I had to enter coordinates in screen space.. So.. How is it done? What I want to do is rotate something round the Z axis.. All help appreciated.. Also, does anyone know of a nice and easy way to make a pixelshader work on the entire screen instead of each polygon?

Share this post


Link to post
Share on other sites
Quote:
Original post by DvDmanDT
Also, does anyone know of a nice and easy way to make a pixelshader work on the entire screen instead of each polygon?

Render your scene to a texture, then render a quad covering the whole screen using that texture and the pixel shader... I've never tried it, but I guess that is the principle.

Share this post


Link to post
Share on other sites
Quote:
Original post by staaf
Quote:
Original post by DvDmanDT
Also, does anyone know of a nice and easy way to make a pixelshader work on the entire screen instead of each polygon?

Render your scene to a texture, then render a quad covering the whole screen using that texture and the pixel shader... I've never tried it, but I guess that is the principle.


Yep, that is how one would go about doing it. Render to a texture in the first pass than use that texture as a sampler in the second pass. If you want to apply some sort of 2d filter in with your PS you can use a screen aligned quad as the geometry for your second pass, but you can use any geometry you want really. If you think that is going to be slow: try reading the back buffer.

You will have to explain your rotation problem better. Are you using sprites or not? If so specify the rotation in your call to draw or set the sprite's transform to a matrix that describes the transformation you desire (D3DXMatrixRotationZ?). If not set the world transform to the desired matrix .. unless you are using pretransformed verts, then just use sprite and save yourself the trouble.

Share this post


Link to post
Share on other sites
Ok.. Umm.. I have a tilebased sidescroller... All the tiles are drawn as quads, with z set to 0.. So basicly it's just a plane with lots of textures.. Now.. I want to draw my player the same way.. He will consist of two quads (legs and body or somethin), and he'll have arms.. Those arms should point towards the mouse.. So basicly, I only want to rotate the arms, and the gun he'll be holding.. The gun must be replaceable..

Also.. Does anyone have a tutorial or something on the render to texture?

Share this post


Link to post
Share on other sites
Ok, if your quads are all untransformed and centered at 0,0 you can use the world transform to position and rotate them. Basicaly set the world, draw the quad, repeat.
If the character is made up of several quads you can use a sort transformation tree to position the parts. For instance the matrix that represents the position of the character cam be multiplied by the matrix that represents the position of the arms relative to the character to get the position of the arms in the world space.

EX: (psudocode)
characterPosition = Translation(30,12,0);
armRotation = RotationZ(PI/6);

world = characterPosition
draw character position
world = armRotation * characterPosition;
draw arm

I believe that a number of the samples included with the SDK use render targets and multiple pass pixel shaders certianly the "PixelMotionBlur" sample does.

Share this post


Link to post
Share on other sites
If you just want to rotate an arm, from say the shoulder, then you take these steps.

1. Translate the arm to the origin. (Not centred on the origin, but have the joint for the rotation on the origin), make a note of this translation.

2. Apply this formula to each vertex in the arm:

x' = x * cos(theta) - y * sin(theta)
y' = x * sin(theta) + y * cos(theta)

Whereby theta is the angle in radians that you would like to rotate the arm counter-clockwise.

Note, to convert degrees to radians use this formula:

radians = (2 * pi * angle_in_degrees) / 360;

Then you translate the arm back to where it came from using the same translation as earlier, i.e before you subtracted the shoulder point, now you add it.

And thats about that, this may not be exactly what you need but this is what I use in my 2d app.

Also, you might want to use global lookup tables for sin and cos as this will be much much faster than using the standard math library function.

Kind regards.

Mark Coleman

Share this post


Link to post
Share on other sites

This topic is 4665 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this