Hi guys,
I have been experimenting with a free mouse look function.
There is the problem when the mouse reaches the edge of the screen, so I tried to center the mouse position at each frame.
Unfortunately, this only works when I move the mouse VERY slowly. As soon as I move the mouse faster, it gets jerky, no matter how high the sync rate is.
Am I missing something?
I understand that there is a GetRawMouseWheelDelta(), so why is there no GetRawMouseDeltaX() and GetRawMouseYDeltaY() which would return the vertical and horizontal mouse movement?
// Project: FreelookMouse
// Created: 23-05-20
#option_explicit
SetErrorMode ( 2 )
#CONSTANT WIDTH GetMaxDeviceWidth()
#CONSTANT HEIGHT GetMaxDeviceHeight()
#CONSTANT cam 1
SetWindowSize ( WIDTH, HEIGHT , 1 )
SetVirtualResolution ( WIDTH, HEIGHT )
SetSyncRate ( 144, 1 )
UseNewDefaultFonts ( 1 )
SetRandomSeed ( 13374711 )
dim cube[1000] as integer
global plane as integer
local i as integer
global last_mx# as float
global last_my# as float
SetCameraPosition ( cam, 0, 10, 0 )
SetCameraLookAt ( cam, 0, 10, 1000, 0 )
SetShadowMappingMode ( 3 )
SetShadowSmoothing ( 2 )
SetShadowRange ( 100 )
SetShadowMapSize ( 2048, 2048 )
SetFogMode ( 1 )
SetFogColor ( 5, 5, 55 )
SetFogRange ( 65, 100 )
SetRawMouseVisible ( 0 )
SetRawMousePosition ( WIDTH / 2.0, HEIGHT / 2.0 )
plane = CreateObjectbox ( 150, .1, 150 )
SetObjectPosition ( plane, 0, 0, 0 )
SetObjectColor ( plane, 255, 255, 255, 255 )
SetObjectLightMode ( plane, 1 )
SetObjectReceiveShadow ( plane, 1 )
for i=1 to 1000
cube[i] = CreateObjectBox ( random ( 5, 15 ) / 10.0, random ( 5, 15 ) / 10.0, random ( 5, 15 ) / 10.0 )
SetObjectPosition ( cube[i], random ( 0, 150 ) - 75, random ( 0, 10 ), random ( 0, 150 ) - 75 )
SetObjectColor ( cube[i], random ( 0, 255 ), random ( 0, 255 ), random ( 0, 255 ), 255 )
SetObjectLightMode ( cube[i], 1 )
SetObjectReceiveShadow ( cube[i], 1 )
SetObjectCastShadow ( cube[i], 1 )
next i
repeat
FreeLook()
Sync()
until GetRawKeyPressed ( 27 )
END
function FreeLook()
local deltaX# as float
local deltaY# as float
local newX# as float
local angleX# as float
local angleY# as float
angleX# = GetCameraAngleX ( cam )
angleY# = GetCameraAngleY ( cam )
deltaX# = -( GetRawMouseX() - last_mx# ) / 50.0 // * GetFrameTime()
deltaY# = -( GetRawMouseY() - last_my# ) / 50.0 // * GetFrameTime()
newX# = angleX# - deltaY#
if ( newX# > 89 ) then newX# = 89
if ( newX# < -89 ) then newX# = -89
SetCameraRotation ( cam, newX#, angleY# - deltaX#, 0 )
SetRawMousePosition ( WIDTH / 2.0, HEIGHT / 2.0 )
last_mx# = GetRawMouseX()
last_my# = GetRawMouseY()
endfunction
Cheers,
PSY