Easier rotation?

BlitzMax Forums/BlitzMax Beginners Area/Easier rotation?

chwaga(Posted 2008) [#1]
Hi, I'm new (like, last night new) to blitzmax, transferring from c++/blitz3d, and I'm wondering if there's an easier way to rotate images than setrotation, draw, setrotation, draw, etc.

(forgive me if I have no idea what I'm talking about)
is it possible to extend the TImage type to hold a rotation attribute, so whenever drawimage() is called, by default it rotates the image?

any help is appreciated!


GfK(Posted 2008) [#2]
Wouldn't you have something like (typed straight into reply box so untested, but you get the idea):
Aliens:tAliens = new tAliens

Aliens.Add()
Aliens.Draw()

Type tAliens
  Field list:TList = New TList

  Method add()
    local alien:tAlien = new tAlien
    'set alien attributes here
    Self.list.AddLast alien
  End Method

  Method draw()
    Local alien:tAlien
    For alien = EachIn Self.list
      SetRotation alien.angle
      DrawImage alien.image, alien.x, alien.y
    Next
    SetRotation 0
  End Method

End Type

Type tAlien
  Field x:Float
  Field y:Float
  Field angle:Float
  Field image:TImage
End Type



chwaga(Posted 2008) [#3]
yeah, that would work, except it seems kind of needless to do that for every project you make, wouldn't it just be more efficient to add an attribute to TImage??


Bremer(Posted 2008) [#4]
If it was added to TImage, then it would needlessly set the rotation angle on all images not rotated at all, so that is probably never going to happen. If you want more control, then you will have to code your own sprite handling functions/types to deal with things like this automatically.


GfK(Posted 2008) [#5]
Its not needless, its the beginnings of a self-contained class. Every class I write code for usually has three methods; Add(), Update() and Draw().

Keeps everything nice and simple.


Bremer(Posted 2008) [#6]
Perhaps it was not the right way to write it. What I ment was, that it would not be something that would be added into the base code of bmax since you would not always need images rotated, it is better to leave it out of the basic draw code.


Htbaa(Posted 2008) [#7]
Easier? How easy do you want it to have? The way BlitzMax handles it is great, and fast. Try rotating with C/C++ and SDL and do this real time :-). Not impossible and not as fast as BlitzMax, but it requires more than 2 lines of code.

Nice to see a new user aboard. I just got BlitzMax last week as well.


chwaga(Posted 2008) [#8]
but how much of a slowdown does rotating 0 degrees take? You could just add to the rotation component of rendering the image to check if rotation = 0 then skip the rotation algorithm.


GfK(Posted 2008) [#9]
but how much of a slowdown does rotating 0 degrees take?
Exactly the same as rotating to any other angle.

You could just add to the rotation component of rendering the image to check if rotation = 0 then skip the rotation algorithm.
I'd wager that its faster to simply force the rotation rather than doing a comparison first.


Grey Alien(Posted 2008) [#10]
GfK: You are probably right but it would be interesting to test that.


Who was John Galt?(Posted 2008) [#11]
Nooooo!!! Please I don't want my projects to run slower in future releases to cater for something that saves someone else a couple of lines of code. If all these kinds of requests were catered for, BlitzMax would be bloated and slow as a snail in treacle.


GfK(Posted 2008) [#12]
Yeah, and what if you want to draw 50 aliens all at different rotations, using the same image?

You can't, because the rotation would be set per-image and you'd need to manually change the rotation 50 times anyway.

I think that the way it currently works, is the best way. You need to use custom types anyway to store the position/speed of aliens, so another field for the rotation is no big deal.


Grey Alien(Posted 2008) [#13]
Yeah make a custom type with tons of other useful fields too.