Quote: "The whole point of AppGameKit is code that works on Windows should work on Mac and Linux. For the most part it does which is brilliant but for some strange reason the mouse side on Mac acts completely different than on Windows. I've tried multiple versions of mouse look code which work fine on Windows but always stick on Mac."
I'd have to agree. I've done some testing tonight and there seems to be 2 main issues:
SetRawMousePosition to recenter the mouse each frame only works if the mouse cursor is hidden. If the mouse ever leaves the bounds of the window it becomes visible and this doesn't recenter it properly. When visible, it can hit the edge of the screen problems. This seems to affect both mac and windows though and can be resolved by setting it to hidden again each frame.
More importantly for mac, if SetRawMousePosition is called every frame, it prevents all mouse movement entirely. On windows it allows you to capture the amount that the mouse moved from the center during the frame.
detection of movement can be forced by adding a minimal delay to the positioning, but this then creates a pause which prevents smooth mouse looking and isn't really a solution.
// Project: 3D FPS
// Created: 2019-02-16
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "3D FPS" )
SetWindowSize( 1280, 720, 0 )
//SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
//SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 60, 0 ) // 30fps instead of 60 to save battery
SetVSync( 1 )
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
//grass = LoadImage( "grass.png" )
//SetImageMinFilter( grass, 0 )
//SetImageMagFilter( grass, 0 )
ground = CreateObjectPlane( 128, 128 )
RotateObjectGlobalX( ground, 90 )
//SetObjectImage( ground, grass, 0 )
player = CreateObjectCapsule( 2, 6, 1 )
SetObjectPosition( player, 0, 6, 0 )
SetCameraRotation( 1, 0, 0, 0 )
spdPlay = 1
SetRawMouseVisible( 0 )
SetResolutionMode(1)
screenWidth = GetDeviceWidth()
screenHeight = GetDeviceHeight()
SetWindowAllowResize(0)
SetWindowSize( screenWidth, screenHeight, 0, 1 )
SetVirtualResolution ( screenWidth, screenHeight )
screenCenterX = screenWidth * 0.5
screenCenterY = screenHeight * 0.5
moveX as float
moveY as float
tilt as float
pan as float
//=====================
invert = -1 // should mouse Y tilt the camera up or down? 1 inverted -1 regular
//=====================
do
if GetRawKeyState( 87 ) = 1
MoveObjectLocalZ( player, spdPlay )
endif
if GetRawKeyState( 83 ) = 1
MoveObjectLocalZ( player, -spdPlay )
endif
if GetRawKeyState( 65 ) = 1
MoveObjectLocalX( player, -spdPlay )
endif
if GetRawKeyState( 68 ) = 1
MoveObjectLocalX( player, spdPlay )
endif
if GetRawKeyState( 48 ) = 1 // 0 (zero)key
end
endif
if GetRawKeyState(27) then end // escape key
moveX = GetRawMouseX() - screenCenterX
moveY = (screenCenterY - GetRawMouseY()) * invert
inc tilt, (moveY * 0.02)
inc pan, (moveX * 0.02)
if tilt > 85.0 and tilt < 180.0
tilt = 85.0
endif
if tilt < 270.0 and tilt > 180.0
tilt = 270.0
endif
SetCameraPosition( 1, GetObjectX( player ), GetObjectY( player ), GetObjectZ(player) )
SetCameraRotation(1, tilt, pan, 0.0)
SetObjectRotation( player, GetObjectAngleX( player ), GetCameraAngleY( 1 ), GetObjectAngleZ( player ) )
SetRawMouseVisible(0)
if timer() - oldTimer > 1
SetRawMousePosition(screenCenterX, ScreenCenterY)
oldTimer = timer()
endif
Print( ScreenFPS() )
print(str(screenCenterX) + "," + str(screenCenterY))
print(str(GetRawMouseX()) + "," + str(GetRawMouseY()))
print(str(moveX) + "," + str(moveY))
Sync()
loop
after some further testing, looks like you need at least 200ms between calls to set the mouse position in order to detect any mouse movement from that position, at least on my machine, which is terrible for camera handling.
http://games.joshkirklin.com/sulium
A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.