mmakrzem
06-05-2007, 04:08 AM
I was testing my game engine on different computers yesterday and I found that on certain computers, when I run my FPS game at 800x600 resolution in fullscreen mode, my camera (player) ends up spinning like crazy. The way that I handle the player's view is I take the position of the mouse and I place it at the centre of the screen. Then each frame, when the users moves the mouse, I measure the difference in the current mouse position wrt the centre to get a direction vector for the motion in X and Y. Using this information I can then rotate the view about the X axis or Y axis in OpenGL.
The strange thing is that under any other resolution (1024x768, 1280x1024) I don't get any crazy spinning action. Everything works fine. Also, when I run the game at 800x600 in windowed mode, it also works. No crazy spinning. Additionally, the crazy spinning only happens on a laptop computer that I was using for testing. On a desktop machine everything works fine.
Any idea's what could be wrong?
Pyabo
06-05-2007, 12:19 PM
Possibly a math error somewhere... if the calculations are as simple as you say, spit out the values in a readable form on the screen and make sure you are getting the sorts of data from the mouse you expect. Old school debugging at its best.
Chroma
06-08-2007, 05:56 AM
Hi mmakrzem. I'm assuming you're using a variant of C but here's some mouselook code I wrote for Blitz3D awhile back. Maybe you'll see some technique in here that will joggle something.
;MouseLook Code
;by Chroma
Global sw = 1024, sh = 768
Graphics3D sw,sh,0,2
SetBuffer BackBuffer()
;delta time vars
Global dt#,NewTime%,OldTime%,TotalTime%
NewTime = MilliSecs()
OldTime = NewTime
;fps calc
Global framecounter_counter
Global framecounter_time
Global framecounter_framerate
Global FPS$
Function FPS$()
Framecounter_counter=Framecounter_counter+1
If Framecounter_time=0 Then Framecounter_time=MilliSecs()
If Framecounter_time+1001<MilliSecs() Then
Framecounter_framerate=Framecounter_counter
Framecounter_counter=0
Framecounter_time=MilliSecs()
EndIf
zsemi$="FPS: "+Framecounter_framerate
Return zsemi$
End Function
Global cam_piv = CreatePivot()
Global cam = CreateCamera(cam_piv)
CameraRange cam,0.2,10000
PositionEntity cam,0,1.6,0
; mouse sensitivity
Local mlook_spd# = 12.0 ;speed
Local mlook_dmp# = 20.0 ;damper
;Make some cubes to look at
Dim cube(200)
For n=1 To 200
cube(n) = CreateCube()
ScaleEntity cube(n), Rand(1,50),Rand(1,50),Rand(1,50)
PositionEntity cube(n), Rand(-1000,1000),Rand(-1000,1000),Rand(-1000,1000)
Next
Local flp = True
Local cam_zoom = 1
; Reset Mouse
HidePointer
MoveMouse sw/2,sh/2
While Not KeyHit(1)
Cls
Delta_Time()
If MouseHit(2)
zoom = 1 - zoom
Select zoom
Case 0
cam_zoom = 1
mlook_spd = 12.0
Case 1
cam_zoom = 3
mlook_spd = 12.0 * 5
End Select
CameraZoom cam,cam_zoom
EndIf
;Hit the "=" key to toggle Flip True/False
If KeyHit(13) Then flp = 1 - flp
; ---FPS Code---
;mouselook
mxspd# = MouseXSpeed() / mlook_spd
myspd# = MouseYSpeed() / mlook_spd
If mxspd <> 0 Or myspd <> 0 Then MoveMouse sw/2,sh/2
mlook_yaw# = mlook_yaw - mxspd
mlook_pitch# = mlook_pitch + myspd
If mlook_pitch => 89 Then mlook_pitch = 89
If mlook_pitch =< -89 Then mlook_pitch = -89
mlook_yaw2# = mlook_yaw2# + ((mlook_yaw# - mlook_yaw2#) * mlook_dmp#) * dt
mlook_pitch2# = mlook_pitch2# + ((mlook_pitch# - mlook_pitch2#) * mlook_dmp#) * dt
RotateEntity cam,mlook_pitch2,mlook_yaw2,0
UpdateWorld
RenderWorld
Text 5,5,"Press '=' to toggle Flip state."
Text 5,25,FPS()
Text 5,65,"RMB to toggle sniper scope."
Text 5,85,"Magnification: "+cam_zoom+"x"
;2D Crosshair
Color 0,255,0
Line sw/2-5,sh/2,sw/2-9,sh/2
Line sw/2+5,sh/2,sw/2+9,sh/2
Line sw/2,sh/2-5,sw/2,sh/2-9
Line sw/2,sh/2+5,sw/2,sh/2+9
Color 255,255,255
Flip flp
Wend
End
Function Delta_Time()
NewTime = MilliSecs()
dt = Float (NewTime - OldTime)/1000
OldTime = NewTime
TotalTime = TotalTime + dt
End Function
mmakrzem
06-08-2007, 10:31 AM
Thanks for the help. I started spitting values out of my game engine into a text file and I was able to find my bug. Basically I forgot to set the screen size AFTER I swiched to full screen mode. This meant that if I had the screen resolution set to something like 1680x1050 and then ran my game in 800x600 full screen mode, my mouse cursor was told to go to 840,525 rather than 400,300.
vBulletin v3.6.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.