Mouselook and general interpolation

Blitz3D Forums/Blitz3D Beginners Area/Mouselook and general interpolation

Hujiklo(Posted 2004) [#1]
Hi there everybody.
I've had Blitz3d for about a week now and am struggling to find my feet. I'm not a natural coder so pretty much everything is a strain on my poor brain, and so I need to ask a few questions!!
I've been trawling through lots of Blitz code this past week - in particular FPS stuff. So far I've seen that all the mouselook is handled in pretty much the same way using MouseSpeed x and y etc..I was wondering if anybody has any other code that does not rely on this 'speed' system. The problem for me is at particlularly slow speeds whilst gently nudging the mouse the camera does not rotate so well. It sort of sticks, and is a real pain whilst trying to aim far away and be accurate at the same time
(imagine you were sniping through a scope and just trying to gently bead in on the target) - it leaves you feeling sort of powerless as only a real tug on the mouse will get it moving again, and of course by then you're off target!!
I was wondering why the mouse's x and y coordinates are not used at all as the guide for rotations? Can anybody tell me how it can be done in blitz3d? I'm imagining that at very slow mouse speeds it will be a little more rigid - that's what I'm hoping for.

Also can anybody tell me how to interpolate values say from co-ords to degrees? I used to use 3drad and cannot see any command that might give me the same results.

Any help or pointers at all would be fantastic...and forgive me if what I've just said sounds stupid!

Thanks.


Ross C(Posted 2004) [#2]
What you can do is, set the mouse X and Y to the centre of the screen. Then, every loop do call this:

y_move = center_x - MouseX()
x_move = center_y - MouseY()

RotateEntity camera , EntityPitch(camera) + move_x , EntityYaw(camera) + move_y , EntityRoll(camera)

MoveMouse center_x , center_y


center_x and center_y are the co-ords of the center of the screen :) Basically half the width and half the height of the screen.


Hujiklo(Posted 2004) [#3]
Thanks for that Ross! I'm going to try that now - it's going to be a long, long night for me..


Ross C(Posted 2004) [#4]
Hey, i'm back. Got some code for you. Just adjust the smoothness value to get faster/slower moving :o)

Graphics3D 800,600
SetBuffer BackBuffer()
HidePointer()

Global camera = CreateCamera()
PositionEntity camera,0,0,-10


Global light = CreateLight()

Global sphere = CreateSphere()

Global center_x = 400
Global center_y = 300

Global smoothness# = 30.0

While Not KeyHit(1)


	update_camera()
	

	UpdateWorld
	RenderWorld
	Flip
Wend


Function update_camera()

	move_y# = (center_x - MouseX()) / smoothness
	move_x# = (center_y - MouseY()) / smoothness
	
	RotateEntity camera , EntityPitch(camera)+move_x , EntityYaw(camera)+move_y , EntityRoll(camera)
	
	MoveMouse center_x,center_y
	
End Function



Hujiklo(Posted 2004) [#5]
He-He! Did you plant those mixed up variables in there just to test me Ross? I was about to post it doesn't do anything, when I thought I'd better take a closer look - 'X_moves, Y_moves' etc. are back to front!!
Big thanks anyhow, it's certainly more direct. But that's was whyin my first post I asked my second question. It's a little too rigid and jittery now.

How would I apply smoothing to the mouse anybody?


Hujiklo(Posted 2004) [#6]
Ha! You beat me to it Ross...another big thanks!!


WolRon(Posted 2004) [#7]
'X_moves, Y_moves' etc. are back to front!!
Hmm, the grasshopper caught the Masters typo...


Ross C(Posted 2004) [#8]
:D oops :)

Anyway, updated again. This one uses acceleration on the mouse, so the faster you move it, the further it will go. Mess around with smoothness and acceleration variable :o)

Graphics3D 800,600
SetBuffer BackBuffer()
HidePointer()

Global camera = CreateCamera()
PositionEntity camera,0,0,-10


Global light = CreateLight()

Global sphere = CreateSphere()

Global center_x = 400
Global center_y = 300

Global smoothness# = 10.0 ; smoothness of the mouse
Global max_acceleration# = 3 ; maximum acceleration of the mouse

While Not KeyHit(1)


	update_camera()
	

	UpdateWorld
	RenderWorld
	Flip
Wend


Function update_camera()

	move_y# = (center_x - MouseX()) / smoothness
	move_x# = (center_y - MouseY()) / smoothness
	
	move_x = move_x * Abs(move_x)
	move_y = move_y * Abs(move_y)
	
	If move_x > max_acceleration Then move_x = max_acceleration
	If move_x < -max_acceleration Then move_x = -max_acceleration
	If move_y > max_acceleration Then move_y = max_acceleration
	If move_y < -max_acceleration Then move_y = -max_acceleration
	
	RotateEntity camera , EntityPitch(camera)+move_x , EntityYaw(camera)+move_y , EntityRoll(camera)
	
	MoveMouse center_x,center_y
	
End Function



Ross C(Posted 2004) [#9]
Oh, forgot to mention, don't let the X rotation go past 90 or -90. If that happens, the rotation basically flips and starts going the other way. I think it's called gimble lock or something. Basically, don't let that happen :)


puki(Posted 2004) [#10]
Isn't "Ross" great.


Zethrax(Posted 2004) [#11]
Here's some code I just posted to the code archives which may answer some of your questions.

http://www.blitzbasic.co.nz/codearcs/codearcs.php?code=1137


Ross C(Posted 2004) [#12]
Nice and smooth Axeman :)


Hujiklo(Posted 2004) [#13]
Great stuff Ross and Axeman! Thanks, you've helped me get under the bonnet straight a way here and solve my mouse issues.

Axeman - did you know that your code only runs at half frame rate in full screen mode?..I think it's to do with you the 'Delay' and 'Vwait' commands you have there...it all works swell in full screen without them. It really is the smoothest mouse code ever. Well done!


Zethrax(Posted 2004) [#14]
Glad you like it!

I couldn't duplicate the problem you described Hujiklo but I've shifted the delay in the code to after the 'Flip False' statement, which may fix the problem. I've also added a frames per second counter to the code.