Archived

This topic is now archived and is closed to further replies.

rotating a 2d image with directdraw 7

This topic is 5886 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 fellow programmers, I''m programming in VC++ and I''m using DirectX 7.0 (or 8.0). I want to know how I could rotate a square image with DirectDraw in real-time. I''ve already created some code to lock the 16 bpp DirectDrawSurface. However, I don''t know the algorithm for rotation. To get the best results, I need a for-loop that walks through each x and y coordinate of the target surface. For each point, the ''real'' x and y must be calculated (that is, the coordinate of the pixel before rotation) and that pixel must then be copied to the new x and y position. Doing it the other way would give poor results, so I''ve heard. I''m not very handy with cosine function and those rotation formulas, so maybe you can help me. Also, for performance issues, it would be nice if the algorithms is DWORD aligned, that is 2 x-coordinates at once. Thanks, QTheBrain

Share this post


Link to post
Share on other sites
Dont quote me on this but im pretty sure there is a
DDBLT_ROTATIONANGLE that use the dwRotationAngle member of the DDBLTFX structure as the rotation angle (specified in hundreths of a degree) for the surface.

Used possibly like this:

DDBLTFX ddbltfx;
ZeroMemory( &ddbltfx, sizeof(ddbltfx) );
ddbltfx.dwSize = sizeof(ddbltfx);
ddbltfx.dwRotationAngle=(DWORD)//rotation angle goes here

lpddsBack->Blt(NULL,lpddsThingy,NULL,DDBLT_ROTATIONANGLE | DDBLT_WAIT,&ddbltfx);

Dont know if this is what you are lookin for but good luck anyways.

Share this post


Link to post
Share on other sites
DrySlime is right, but it only works if your video card supports hardware 2D rotation by an arbitrary angle... i only know this because mine doesn''t

--- krez (krezisback@aol.com)

Share this post


Link to post
Share on other sites
Most of the 2D rotations are done with pre-calculated tables. The pixels are repositioned in real time, but all of the math was already done before blitting it.

Edited by - GoofProg on November 1, 2001 1:19:59 AM

Share this post


Link to post
Share on other sites
I think the best way is using Direct3D8 for 2D rendering (forget about DirectDraw if you still didn''t dig a big hole on it!), just transform 4 vertices and set texture, fast, nice and easy.

See this:
http://www.gamedev.net/reference/programming/features/2ddx8/

Share this post


Link to post
Share on other sites
My hardware doesn''t support the ddbltfx_rotation thingie, so i cannot use them. However, i''m quite interested in the direct3d way. The question i have now is: now directdraw is gone in dx8, what are the surfaces to blit to? I can''t find any blitters or offscreen surfaces - it''s all vertices and stuff. I understand you have to create a plane that equals your window size and make the camera look at it. But how do i blit some sprites like a game character on that flat plane without using any more planes and polygones?

Thanx,

QTheBrain

Share this post


Link to post
Share on other sites
hey, the website that I had posed above did explain how to do 2d by direct3d. You are right, please forget about any blit kind function, they are dead.

the idea of how to render in 2d is approximately like this:
- define a struct of vertex, at least should have x, y, color, u, v.
- create 4 vertices from vertex buffer, lock them and assign the values appropriately.
- set texture(s), finally render.

Sure it is more complex when you are going to face it, good luck buddy.

PS. if you are new to Direct3D, I suggest you take a look at the tutorial lessons first, the project "C:\mssdk\samples\Multimedia\Direct3D\Tutorials\Tut02_Vertices" should be easy enough for a beginner.

Share this post


Link to post
Share on other sites
I made a software rotation. It not perfect, but it works and it's kinda fast. It uses DirectDraw...

Here it is:
http://hemohes.4t.com/rotation.zip

/MindWipe

"If it doesn't fit, force it; if it breaks, it needed replacement anyway."

[EDIT] You rotate with the arrow keys [/EDIT]

Edited by - MindWipe on November 4, 2001 8:11:36 AM

Share this post


Link to post
Share on other sites