Thread: HOWTO: rotate sprites

  1. #1
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463

    HOWTO: rotate sprites

    Hi!

    Just started a DirectX project, it's a puzzle game, and got stucked right at the beginning

    I don't find a corresponding API to rotate the sprites - CSurface::Blt won't do that for me, and the BltBatch is not yet implemented (DirectX SDK 8.2).

    I don't want to mess up with Direct3D stuff, all I want is to rotate my 2D objects - thought it'll be easy, but I was wrong

    Any idea would be welcome.

    Thank you in advance!

    Have a nice code!

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    I thought Blt could rotate in whole 90 degrees (90, 180, 270)...?
    Never used it though!
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    http://msdn.microsoft.com/archive/de...ddref_4b7b.asp

    Blt has a DDBLT_DDFX flag. One of the operations are called dwRotationAngle. Could be worth checking out .
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    Thank you, Magos, I have also found IDirectDrawSurface7::Blt, the only problem is that I used CSurface, and a IDirectDrawSurface7 cast is not quite successful... :\

    I'll check that again today, what really scares me is
    "The IDirectDrawSurface7::Blt method performs a bit block transfer (blit). This method does not support z-buffering or alpha blending (see alpha channel) during blit operations".

    I m i g h t need some Z-buffering, as the sprites will "cover" each other.

    Bye!

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by Magos
    http://msdn.microsoft.com/archive/de...ddref_4b7b.asp

    Blt has a DDBLT_DDFX flag. One of the operations are called dwRotationAngle. Could be worth checking out .
    Not all video cards support this. Check the device caps and if it isn't supported then rotate them in software.

  6. #6
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    Originally posted by MrWizard
    Not all video cards support this. Check the device caps and if it isn't supported then rotate them in software.
    Yes, you're right, Blt will return in this case "DDERR_NOROTATIONHW
    No rotation hardware is present or available. "

    That's OK so far, but is there any DirectX API to rotate in software if HAL does not support it?

    Btw, yesterday I experimented with this Blt, my video card supports rotation, but still does not work.
    Actually, I use CSurface in my project, and the only way to obtain a pointer to IDirectDrawSurface7 is CSurface::GetDDSurface??? (sorry, can't remember the exact function name), which does not seem to work.

    That's my problem noe: how to get a IDirectDrawSurface7 from CSurface?

    ...maybe I'll have to redesign my class to use only IDirectDrawSurface7, and drop CSurface?

    Thank you!

  7. #7
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    I'm really dissappointed...there seem to be no API in DirectX which does the sprite rotation in software.

    IDirectDrawSurface7::Blt does the job only through HAL, so, if the video card does not support this, the program won't run.

    In my opinion, rotating DIBS in video-memory is a basic operation.
    DirectX 8.2(!) has no API for it. What are the guys at MS doing? Bug tracking? Debugging and fixing all day long?

    Take a closer look at those comments in the DirectX header files. They are EMPTY.
    Hmm,well...

    I guess I'll have this sprite rotation as homework

    Still, if you have some new idea, you're more then welcome!

    Have fun!
    Code clean and live long! (or vice-versa)

  8. #8
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    You could always write your own rotating function
    I did once for my (old DOS) drawing program.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  9. #9
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by Carlos
    I'm really dissappointed...there seem to be no API in DirectX which does the sprite rotation in software.

    IDirectDrawSurface7::Blt does the job only through HAL, so, if the video card does not support this, the program won't run.

    In my opinion, rotating DIBS in video-memory is a basic operation.
    DirectX 8.2(!) has no API for it. What are the guys at MS doing? Bug tracking? Debugging and fixing all day long?

    Take a closer look at those comments in the DirectX header files. They are EMPTY.
    Hmm,well...

    I guess I'll have this sprite rotation as homework

    Still, if you have some new idea, you're more then welcome!

    Have fun!
    Code clean and live long! (or vice-versa)
    You could always just used frame-based animation. Just use 36 different frames of the same ship ( rotated in 10 deg. intervals ). Keep track of the angle and blt the proper image. This will do fine , no?

  10. #10
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463

    Lightbulb

    My first idea was also frame-based animation, but game's design doesn't allow this.The base idea is that the user can freely load images, and these are splitted, randomly rotated and placed outside the "table" - the image is practically blowed up.

    You can drag the pieces while pressing the left mouse button and rotate the pieces with the right one.

    I try to make this game as realistic as possible, with the possibility to use the keyboard as well - thus allowing two ev. more people to play.

    When I'm ready with this project (you'll have to wait a little bit ) you, who helped me with ideas will receive it as a gift .

    So, keep in touch!

  11. #11
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by Carlos
    When I'm ready with this project (you'll have to wait a little bit ) you, who helped me with ideas will receive it as a gift .

    So, keep in touch!
    Sounds pretty cool. If you need some help getting started on software sprite rotation let me know.

  12. #12
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    Thank you, MrWizard!

    Math part of rotating is known for me, got some books and resources (rotating with 90 degrees is even easier).
    Just thought it'll be much easier using some DirectX API - now I see I was wrong.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. making sprites
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 02-20-2010, 07:00 AM
  2. Camera rotate to function
    By VirtualAce in forum Game Programming
    Replies: 0
    Last Post: 11-15-2008, 12:22 PM
  3. DirectX and Sprites
    By andyhunter in forum Game Programming
    Replies: 6
    Last Post: 12-24-2004, 06:40 PM
  4. I Found some nice sprites but need more...
    By BigCheese in forum C++ Programming
    Replies: 1
    Last Post: 03-23-2004, 06:03 PM
  5. Animating Multiple Sprites
    By Tommaso in forum Game Programming
    Replies: 2
    Last Post: 10-11-2002, 12:06 AM