Mojo2 - rotate image like Max2D?

Started by wombats, November 29, 2019, 03:31:51

Previous topic - Next topic

wombats

Hi,

How can I rotate an image in Mojo2 like Max2D?

Sprite is from: https://opengameart.org/content/sassy-guards

Max2D:


Graphics 640, 480

Local image:TImage = LoadImage("")

While Not KeyDown(KEY_ESCAPE)

  Cls
  SetRotation(45)
  DrawImage(image, 100, 100)
  Flip

Wend


Mojo2:

SuperStrict

Framework mky.mojo2
?Not opengles
Import brl.GLGraphics
?opengles
Import sdl.sdlgraphics
?
Import brl.pngloader

Function Radian:Float(degree:Float)
  Return degree * Pi / 180
EndFunction

Graphics 640, 480, 0

Local canvas:TCanvas = New TCanvas.CreateCanvas()

Local image:TImage=TImage.Load("")

While Not KeyDown(KEY_ESCAPE)
  canvas.Clear(0, 0, 0)
  canvas.PushMatrix
  canvas.Rotate(Radian(45))
  canvas.DrawImage(image, 100, 100)
  canvas.PopMatrix
  canvas.Flush()
Flip 1
Wend

Henri

Hi,

I haven't used Mojo, but judging by the information found here https://regal-internet-brothers.github.io/monkey/docs/Modules_mojo.graphics.html
I would guess that rotate function rotates the whole canvas, and DrawImage function seems to have rotate parameter for rotating single image locally.

-Henri
- Got 01100011 problems, but the bit ain't 00000001

wombats

In the Mojo2 module, the DrawImage function just calls the same functions I've used in my code, so I get the same results.

Brucey

#3
Hallo :)

You can use DrawImageXYZ(image:TImage,tx:Float,ty:Float,rz:Float), where tx and ty translates, and rz rotates.
There's also a DrawImageXYZS(), which adds scaling to the operation.

Check out the "examples" folder in the mojo2.mod folder.

wombats

Hi Brucey,

Thanks for your reply. I can't see that DrawImageXYZ does anything different to what I was doing. I need to use DrawRectImage, ideally, and there isn't a form of it that includes rotation.

It does expect angles in radians, correct? Is there something wrong with my Radian function?

Derron

If you need to draw a part of the image instead of the whole you might try to set the handle of the image to the center of the "part of the image". So any rotation will be around this then - instead of the "0,0" of the whole image.


bye
Ron

wombats

Quote from: Derron on November 29, 2019, 18:00:07
If you need to draw a part of the image instead of the whole you might try to set the handle of the image to the center of the "part of the image". So any rotation will be around this then - instead of the "0,0" of the whole image.


bye
Ron
That's something I hadn't thought about, but right now I use DrawRectImage just to draw the image at a different size. In Mojo2, the docs say the handle is ignored for that function.

Derron

If you use it just to scale it ... then maybe use the appropriate function for it (as Brucey suggested). And in the next step - use the one which scales _and_ rotates.


bye
Ron

wombats

#8
It seems to expect angles in negative degrees, so I have it rotated the right way. I can draw it at the correct location with DrawImageXYZ, but not DrawRectImage. I need to use that function as I draw images at different pixel sizes, but I can't get it to work with the rotation. I looked in graphics.bmx in mojo2.mod and I think I'm doing the same things as the DrawImageXYZ function.

wombats

#9
I've managed to get it to rotate and draw as I want by translating and then translating back. Thank you for all the suggestions.