- Joined
- Jan 2, 2020
- Messages
- 1,280
I have problems understanding matrix handling in Cerberus. I've tried to read the documentation for a few weeks and painstainkinlgy converted the mojo1 example. It's behaving very strange. Any help would be much appreciated!
This is the mojo1 example:
this is mojo2 version that I tried to create, the zoom seem to be stronger at the start and it behaves not the same for some reason
some commands have a very different syntax in mojo2 and this makes me very uncertain what is actually wrong, I tried to find every mojo2 command that does the same as the mojo1.
Everything seems to work fine except the coordinates seem to be x2 zoom, I don't knoe how to put it.
Have a look here what I've got so far:
This is the mojo1 example:
Code:
Import mojo
Function Main()
New TransformMapApp
End
Class TransformMapApp Extends App
Field mx#,my#
Field tmx#,tmy#
Field omx#,omy#
Field mapMatrix#[]
Method OnCreate()
' Vertical blanking
SetSwapInterval 1 ; SetUpdateRate 0
PushMatrix
Scale DeviceWidth()/400.0, DeviceHeight()/300.0
mapMatrix = GetMatrix()
PopMatrix
End
Method OnUpdate()
Local coords#[]
mx = MouseX() ; my = MouseY()
PushMatrix
Translate mx,my
Rotate (KeyDown(KEY_LEFT)-KeyDown(KEY_RIGHT))*1.5
Local s# = 1+(KeyDown(KEY_UP) - KeyDown(KEY_DOWN))*.01
Scale s,s
Translate -mx,-my
Transform mapMatrix[0],mapMatrix[1],mapMatrix[2],mapMatrix[3],mapMatrix[4],mapMatrix[5]
coords = InvTransform([mx,my])
tmx = coords[0] ; tmy = coords[1]
If TouchDown(0) Then Translate tmx-omx, tmy-omy
mapMatrix = GetMatrix()
coords = InvTransform([mx,my])
omx = coords[0] ; omy = coords[1]
PopMatrix
End
Method OnRender()
Cls
PushMatrix
Transform mapMatrix[0],mapMatrix[1],mapMatrix[2],mapMatrix[3],mapMatrix[4],mapMatrix[5]
drawMap
DrawText Int(omx)+","+Int(omy),omx,omy-TextHeight()
Local bits#[] = InvTransform([mx,my])
DrawText Int(bits[0])+","+Int(bits[1]),omx,omy-TextHeight()*2
PopMatrix
End
Method drawMap()
For Local x=0 To 400 Step 100
DrawLine x,0,x,300
Next
For Local y=0 To 300 Step 100
DrawLine 0,y,400,y
Next
For Local x=50 To 400 Step 100
For Local y=50 To 300 Step 100
DrawCircle x,y,2
DrawText x+","+y,x+2,y+2
Next
Next
End
End
this is mojo2 version that I tried to create, the zoom seem to be stronger at the start and it behaves not the same for some reason
some commands have a very different syntax in mojo2 and this makes me very uncertain what is actually wrong, I tried to find every mojo2 command that does the same as the mojo1.
Everything seems to work fine except the coordinates seem to be x2 zoom, I don't knoe how to put it.
Have a look here what I've got so far:
Code:
Import mojo2
Function Main()
New TransformMapApp
End
Class TransformMapApp Extends App
Field canvas:Canvas
Field mx#,my#
Field tmx#,tmy#
Field omx#,omy#
Field mapMatrix#[]
Field gesturing:Bool
Method OnCreate()
canvas = New Canvas()
SetUpdateRate 0
canvas.PushMatrix
canvas.Scale DeviceWidth()/400.0, DeviceHeight()/300.0
canvas.GetMatrix(mapMatrix)
canvas.PopMatrix
End
Method OnUpdate()
Local coords#[]
Local coordsin#[]
mx = TouchX(0) ; my = TouchY(0)
canvas.PushMatrix
canvas.Translate mx,my
canvas.Rotate (KeyDown(KEY_LEFT)-KeyDown(KEY_RIGHT))*1.5
Local s# = 1+(KeyDown(KEY_UP) - KeyDown(KEY_DOWN))*.01
canvas.Scale s,s
canvas.Translate -mx,-my
canvas.Transform mapMatrix[0],mapMatrix[1],mapMatrix[2],mapMatrix[3],mapMatrix[4],mapMatrix[5]
' coords = InvTransform([mx,my]) ' MOJO1
coordsin[0] = mx ; coordsin[1] = my ' MOJO2
canvas.TransformCoords(coordsin,coords) ' MOJO2
tmx = coords[0] ; tmy = coords[1]
If TouchDown(0) Then canvas.Translate tmx-omx, tmy-omy
canvas.GetMatrix(mapMatrix)
' coords = InvTransform([mx,my]) ' MOJO1
coordsin[0] = mx ; coordsin[1] = my ' MOJO2
canvas.TransformCoords(coordsin,coords) ' MOJO2
omx = coords[0] ; omy = coords[1]
canvas.PopMatrix
End
Method OnRender()
canvas.Clear
canvas.PushMatrix
canvas.Transform mapMatrix[0],mapMatrix[1],mapMatrix[2],mapMatrix[3],mapMatrix[4],mapMatrix[5]
drawMap
canvas.DrawText Int(omx)+","+Int(omy),omx,omy-16
Local bitsin#[]
Local bits#[]
' bits = InvTransform([mx,my]) ' MOJO1
bitsin[0] = mx ; bitsin[1] = my ' MOJO2
canvas.TransformCoords(bitsin,bits) ' MOJO2
canvas.DrawText Int(bits[0])+","+Int(bits[1]),omx,omy-16
canvas.PopMatrix
canvas.Flush
End
Method drawMap()
For Local x=0 To 400 Step 100
canvas.DrawLine x,0,x,300
Next
For Local y=0 To 300 Step 100
canvas.DrawLine 0,y,400,y
Next
For Local x=50 To 400 Step 100
For Local y=50 To 300 Step 100
canvas.DrawCircle x,y,2
canvas.DrawText x+","+y,x+2,y+2
Next
Next
End
End
Last edited: