• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

Fixed MouseZ is always zero on MacOS...

SimonVD

New member
Tutorial Author
Joined
Dec 22, 2019
Messages
39
MouseZ value is always zero on MacOS, Mojave 10.14.6

Tested on targets: GLFW, HTML5 (Firefox and Safari)


Code:
Import mojo

Class MyApp Extends App

    
    Method OnRender()
    
        DrawText(("X: " + MouseX() + "~nY: " + MouseY() + "~nZ: " + MouseZ()).Split("~n"), DeviceWidth()/2, DeviceHeight()/2)
    
    End
End

Function Main()
    New MyApp
End
 
It only works on glfw and the value is always the difference to the last update, so you have to track the values somehow.
Try this one:

Cerberus:
Import mojo

Class MyApp Extends App
    Field mouseRollCnt:Int = 0
   
    Method OnRender()
        Cls()
        mouseRollCnt +=MouseZ()
        DrawText(("X: " + MouseX() + "~nY: " + MouseY() + "~nZ: " + mouseRollCnt).Split("~n"), DeviceWidth()/2, DeviceHeight()/2)
   
    End
End

Function Main()
    New MyApp
End
 
Thanks.

So there's no way to get MouseZ value on HTML5 target?
 
I quickly tried something like this for HTML5 target and it works but I'm open to suggestions.


Code:
JS_MOUSE_Z = 0;

const trackWheel = function (e) {
    JS_MOUSE_Z = e.deltaY;
}

window.addEventListener("wheel", trackWheel);


Code:
Import mojo

Import "native/mousez_html5.js"

Extern

Global JS_MOUSE_Z:Int= "JS_MOUSE_Z"



Public


Class MyApp Extends App
 
    Method OnRender()
        Cls()
        DrawText(("X: " + MouseX() + "~nY: " + MouseY() + "~nZ: " + JS_MOUSE_Z).Split("~n"), DeviceWidth()/2, DeviceHeight()/2)
       
    End
End

Function Main()
    New MyApp
End
 
Last edited:
This works for me without having to do any extern/js stuff myself. Probably works for mojo1 as well?
Tested on GLFW, HTML5 (Chrome)

Key lines are:
- Import diddy
- MouseZInit() — somewhere in OnCreate
- diddy.externfunctions.MouseZ() — Difference in z since the last time you called this; should probably always cache it

Code:
Strict

Import mojo2
Import diddy

Class myApp Extends App

    Field myCanvas:Canvas
    field mouse_z:Float
    field scrolled:Int

    Method OnCreate:Int()   
        myCanvas = New Canvas()           

        MouseZInit()
       
        SetUpdateRate(0)
        Return 0
    End   
       
    Method OnUpdate:Int()
       
        mouse_z = diddy.externfunctions.MouseZ()
       
        scrolled += (20 * mouse_z)
       
        Return 0
    End

    Method OnRender:Int()
        myCanvas.Clear(0.2, 0.2, 0.2)
   
        myCanvas.SetColor(1,1,1)
        myCanvas.DrawText("X: " + MouseY() + "   Y: " + MouseX() + "   Z: " + mouse_z, 100,100)
        myCanvas.DrawText("Scrolled : " + scrolled, 100,200)
   
        myCanvas.SetColor(1,0,0)
        myCanvas.DrawRect(300, 300 - scrolled, 50,50)
       
        myCanvas.Flush()
        Return 0
    End

End


Function Main:Int()
    New myApp()
    Return 0
End
mousez.gif
 
Back
Top Bottom