2d Sprite Rotation code

Advanced game related topics
Krylar
User
User
Posts: 88
Joined: Thu Apr 15, 2004 3:17 pm

2d Sprite Rotation code

Post by Krylar »

Hiya,

I've been messing with Sprite rotation from 3D back to 2D and I tossed together a bit of code that does the following:

1) Load a 2D sprite with 3D capability
2) Rotate the Sprite a user-defined amount
3) Display it in 3D
4) Grab it from the the buffer and stick it into an array for use with 2D

The idea is that you can have 1 2D image be automagically converted into a bunch of them, rotated at certain angle-intervals, and then placed in an array. But have them be accessible as 2D objects for speed.

If you're interested in the code, Get it Here

If someone knows of a faster way to do this using PB's code, please let me know! :D

EDIT...
I know there are many pieces of plugin code out there, but since I'm incorporating stuff into the book I'm somewhat tied by what I can use.
...EDIT

All the best!

-Krylar
Thanks!

-Krylar
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

you could do it without 3d hardware using the plgblt_ api
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Krylar
User
User
Posts: 88
Joined: Thu Apr 15, 2004 3:17 pm

Post by Krylar »

Heya,

Not familiar with that. I looked through the PB documentation and such but didn't find it.

If it's a library I suppose I can just have people look for it on their own from text in the book, but I'm supposed to be keeping to only actual PB commands and licensed libraries otherwise. :/

Thanks!

-Krylar
Codemonger
Enthusiast
Enthusiast
Posts: 384
Joined: Sat May 24, 2003 8:02 pm
Location: Canada
Contact:

Post by Codemonger »

You are right it's not an internal PB command. But any Win32 API function can be called from PB without any extra help by appending a underscore as a suffix... so :

win32function_(param1,param2,param3)

would call whatever win32 function. This makes PB very powerful because the easy access to Win32 API

@blueznl
plgblt does not do rotation, heres a quote from the ms docs:
Scaling, translation, and reflection transformations are allowed in the source device context; however, rotation and shear transformations are not.
anyway maybe i'm missing something as i quickly looked this up.
<br>"I deliver Justice, not Mercy"

    - Codemonger, 2004 A.D.
Krylar
User
User
Posts: 88
Joined: Thu Apr 15, 2004 3:17 pm

Post by Krylar »

Excellent information, Codemonger. :D

I just did a look up on MSDN as well:

http://msdn.microsoft.com/library/defau ... s_2dis.asp

Also seems that there's compatability problems with this command. From the Requirements section:

"Windows 95/98/Me: Unsupported."

I know most people are moving to XP or NT, but still may be some out there on the older ones.

Anyway, thanks to both you and blueznl for helping to guide me here. As you may imagine I'm in a bit of a crunch for getting up to speed on these things and so in a lot of cases I'm jumping forward and making assumptions on things. ;)

-Krylar
MadMax
Enthusiast
Enthusiast
Posts: 237
Joined: Mon Oct 06, 2003 11:56 am

Post by MadMax »

Krylar: For me while sprite3D rotation(1) is fast and OK for some things, it's quality is not so good for others. ATM I'm writing a small aplication, thet will rotate your sprite to the specified angles, and save them all in a single file (either contiguous or with a 1 pixel frame) Then with a small clipping procedure one will be able to use easily in games. (Code is working, just need to get the GUI stuff, I should have a working version soon)

Saddly I'm doing this with Blitz+, I'd love to do it with PB, but I don't have a good rotation routine (Anti-Alias) HINT HINT ! maybe someone would like to send me a good routine to use with PB 8)

(1) If you not too worried about the quality, why not use sprite3D directly? Contrary to popular belief sprite3D can be used for pixel perfect collisions, and can be animated too. If people are interested, tell me and I'll write a couple of small examples.



Well, I have a very primitive version that works, as soon as I write how to use it, I'll post a link, but right now a shower and of to drink a few beers :D
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

euh, codemonger, you're right about version / compatibility, it doesn't work on pre-win2k... but i think plgblt _ does do rotations (don't have a machine at hand to test it right now, installing new licenses etc.)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
Rings
Moderator
Moderator
Posts: 1427
Joined: Sat Apr 26, 2003 1:11 am

Post by Rings »

i think rotations are already done, see link here :
purearea.net site, a great lib from Mischa
SPAMINATOR NR.1
Post Reply