🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Sprite rotation with DirectDraw

Started by
3 comments, last by Nutz4Linux 24 years, 6 months ago
Hello, I would like to rotate sprites that I''ve stored in surfaces in DirectDraw. I''ve got some (slow) trig rotation formulas, but I don''t want to spend time implementing and optimizing only to find a faster way. So I was wondering if anyone can offer me some suggestions... I did notice in the DirectX SDK documentation that the Blt() function has some kind of support for rotation but I can''t figure out how to implement this. I tried filling in the DDBLTFX with the rotation angle * 100, and specifying the flag for rotation in Blt(), but this didn''t work. Any help would be appreciated. Thanks in advance, -Jey Kottalam 14 Year Old Computer Programmer http://www.armageddongames.com
-Jey Kottalam14 Year Old Computer Programmerhttp://www.armageddongames.com
Advertisement
I would appreciate it if code samples were in C or C++.

Thanks,

-Jey Kottalam
14 Year Old Computer Programmer
http://www.armageddongames.com
-Jey Kottalam14 Year Old Computer Programmerhttp://www.armageddongames.com
The only way I''ve found around using the slow trig rotation is to make use of Direct3D. I know must people aren''t willing to figure out Direct3D simply to add rotation, but keep in mind that if you use Direct3D you can also take advantage of alpha blending and some other things.

I wrote some simple code that uses Direct3D to rotate an image. However, I found out (once I actually learned some Direct3D) that I was rotating the image by moving the world and not the image. I decided to fix this and in doing so I started to write a class. However, I found out that you cannot use Direct3D and 2D blits at the same time as far as I know so I never added the rotation code to the class.

If anyone knows how to use a Blt to draw most of the scene and then render the rest of the scene with Direct3D let me know. If you want to see the code I''ve writen just ask. I''ve also got some trig rotation code if you want it. It may be faster (or slower) than yours.
Would you mind posting your trig rotation algorithms? I''m relatively new to DirectDraw itself so I do not want to use Direct3D yet. I''m already planning on only calculating sin(theta) and cos(theta) once per rotation, and using a look up table for sin and theta.

-Jey Kottalam
14 Year Old Computer Programmer
http://www.armageddongames.com
-Jey Kottalam14 Year Old Computer Programmerhttp://www.armageddongames.com
Rotation with DirectDraw is a little hard mostly because its only supported if your video card does. There is no software emulation for it.

I don''t have any code to do it, because, Well, mine doesn''t support it. But I can tell you that you need to set up a DDBLTFX structure (same way do for DDSURFACEDESC etc..), set the DDBLTFX.dwRotationAngle, and then call blt with something like

Backbuffer->Blt(&DestRect, SrcImage, &SrcRect, DDBLT_WAIT / DDBLT_KEYSRC / DDBLT_ROTATIONANGLE, &DDBLTFX)

Oh, and if you are going to make look up tables for Sin, and Cos just do it once the entire program. Once per rotation is optimizing, but once per execution is even more, and it doesn''t take up much room.

Hope I could help.

This topic is closed to new replies.

Advertisement