SetTransform impact

BlitzMax Forums/BlitzMax Beginners Area/SetTransform impact

Adam Novagen(Posted 2012) [#1]
Just wondering how much of a footprint the SetScale() command has. Being introduced to polymorphism, I'm naturally thinking of things like universal sprite systems, for instance:

Type sprite
    Field x:Float,y:Float
    Field w:Float,h:Float ' Width, Height
    Field r:Float ' Rotation
    Field a:Float ' Alpha
    Field image:Int,f:Int ' Image, Frame
    
    Method draw()
        SetTransform r,w,h
        DrawImage image,x,y,f
    End Method
End Type

Type ball Extends sprite
    Field r:Int,g:Int,b:Int
    Field bounce:Float
End Type

The idea here is of course that every image on the screen is ultimately a sprite, so there can be a "root class" that all the individual classes - players, projectiles, enemies etc - extend.

My question is that, as you can see, the SetTransform() command is called every time that a sprite is drawn. This allows a clean, easy way to have the width, height and rotation of each sprite controlled individually. However, I remember many times when methods like this could trip one up; for instance, the need for single-surface particle systems in Blitz3D, because draw calls are more time-intensive than polygons. So, I'm wondering: is it a viable, speedy method to use SetTransform() before every image drawing? Or am I setting myself up for a performance hammer?


matibee(Posted 2012) [#2]
IIRC, and if you dig through the relevant brl mods, values like rotation and scalex, scaley are simply stored by the graphics driver as floating point variables. So a setscale() call simply sets the two internal floats, nothing else. Then, when you make a draw call, the screen positions are calculated on the fly using the current rotation, scalex & scaley values, regardless if they are 1.0 or anything else.


Adam Novagen(Posted 2012) [#3]
Oh good, I was hoping it would be something like that but wanted to make sure. I shall proceed as planned, then!