December 07, 2019, 12:49:16 PM

Author Topic: Mojo2 - rotate image like Max2D?  (Read 180 times)

Offline wombats

  • Jr. Member
  • **
  • Posts: 36
Mojo2 - rotate image like Max2D?
« on: November 29, 2019, 03:31:51 AM »
Hi,

How can I rotate an image in Mojo2 like Max2D?

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

Max2D:

Code: [Select]
Graphics 640, 480

Local image:TImage = LoadImage("")

While Not KeyDown(KEY_ESCAPE)

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

Wend

Mojo2:

Code: [Select]
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

Offline Henri

  • Full Member
  • ***
  • Posts: 215
Re: Mojo2 - rotate image like Max2D?
« Reply #1 on: November 29, 2019, 11:54:44 AM »
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

Offline wombats

  • Jr. Member
  • **
  • Posts: 36
Re: Mojo2 - rotate image like Max2D?
« Reply #2 on: November 29, 2019, 02:18:40 PM »
In the Mojo2 module, the DrawImage function just calls the same functions I've used in my code, so I get the same results.

Offline Brucey

  • Jr. Member
  • **
  • Posts: 92
Re: Mojo2 - rotate image like Max2D?
« Reply #3 on: November 29, 2019, 05:08:06 PM »
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.

Offline wombats

  • Jr. Member
  • **
  • Posts: 36
Re: Mojo2 - rotate image like Max2D?
« Reply #4 on: November 29, 2019, 05:18:57 PM »
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?

Offline Derron

  • Hero Member
  • *****
  • Posts: 2607
Re: Mojo2 - rotate image like Max2D?
« Reply #5 on: November 29, 2019, 06:00:07 PM »
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

Offline wombats

  • Jr. Member
  • **
  • Posts: 36
Re: Mojo2 - rotate image like Max2D?
« Reply #6 on: November 29, 2019, 06:27:37 PM »
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.

Offline Derron

  • Hero Member
  • *****
  • Posts: 2607
Re: Mojo2 - rotate image like Max2D?
« Reply #7 on: November 29, 2019, 07:27:34 PM »
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

Offline wombats

  • Jr. Member
  • **
  • Posts: 36
Re: Mojo2 - rotate image like Max2D?
« Reply #8 on: November 29, 2019, 08:19:32 PM »
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.

Offline wombats

  • Jr. Member
  • **
  • Posts: 36
Re: Mojo2 - rotate image like Max2D?
« Reply #9 on: November 30, 2019, 01:30:44 AM »
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.