Mouse stuff

Blitz3D Forums/Blitz3D Beginners Area/Mouse stuff

airborne(Posted 2012) [#1]
Ok, so I'm trying to make it so that camera/and sphere rotate together, but only when a certain button is depressed, right now I have them moving together, but how could i write this so that the mouse is free to do other things while not attempting to pan around all the time?




airborne(Posted 2012) [#2]
I've also been having another problem lately, for some reason my mouse cursor leaves the program window ever since I've inserted this pan code for sphere/camera/mouse, is there a way to keep the mouse cursor within the confines of the app window?


Midimaster(Posted 2012) [#3]
you have to set him to the center of the screen:
MoveMouse GraphicsWidth/2, GraphicsHeight/2


but be careful... you cannot use your mouse anymore f.e. to stop the app. So I would add this:

Global CenterMouse%=1

If KeyHit(1) Then End

If KeyHit(50) Then CenterMouse=0 ; press key "M"

If CenterMouse=1
     MoveMouse GraphicsWidth/2, GraphicsHeight/2
Endif



airborne(Posted 2012) [#4]
It isn't stopping the app i'm concerned about, esc key serves that function well enough, the problem that I encounter is that with center mouse the mouse is obviously confined to the center of the screen and cannot pan the camera/sphere, as well the mouse would be incapible of performing any interactive actions, such as pressing a button on a GUI


Midimaster(Posted 2012) [#5]
yes, but togehter with MouseSpeed() normaly they use to center the mouse.

How will you use the mouse for second interactions without driving the camera in wrong directions this moment? You could switch mode with a key. This was my idea of the key "M"

If KeyHit(50) Then CenterMouse=1-CenterMouse ; press key "M" to switch



Kiyoshi(Posted 2012) [#6]
Hello!

This seems like a problem I had a while ago, I was coding an RPG type game at the time. I wanted to be able to pan around my character from a 3rd-person viewpoint with my mouse, but I also had a GUI that would cast spells, open doors, etc.

What I did was add a flag variable that activated whenever the right mouse button was pressed down. This would run a bit of code that allowed the camera to pan around the player. However, when the button was released, the flag would lower, and normal gameplay could resume.

Implemented into your own code that you put up...

While Not KeyDown(1)
	If KeyDown(32)=True Then MoveEntity sphere,1,0,0
	If KeyDown(30)=True Then MoveEntity sphere,-1,0,0
	If KeyDown(31)=True Then MoveEntity sphere,0,0,-0.05
	If KeyDown(17)=True Then MoveEntity sphere,0,0,0.05
	If KeyDown(207)=True Then MoveEntity camera,0,0,1
	If KeyDown(199)=True Then MoveEntity camera,0,0,-1
	If KeyDown(29)=True Then MoveEntity sphere,0,10,0
	If KeyHit(57)=True Then MoveEntity sphere,0,10,0
	If MouseDown(1) Then MoveEntity sphere,0,0,5
	If MouseDown(3) Then MoveEntity sphere,0,0,0.5
	
	;This code below allows panning when the Right mouse button is pressed
	;---
	If MouseDown(2) And panstatus%=0 Then ;Check if right mouse button is pressed down
		panstatus%=1 ;Set the camera panning status to 1
		MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2) ;Reset the mouse to the center
	EndIf
	
	If panstatus%=1;When panstatus is 1, use the mouse to rotate the camera.
		mxs# = mxs# + MouseXSpeed()
		mys# = mys# + MouseYSpeed()
		MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);Keep the mouse centered...
		If MouseDown(2)=False Then panstatus%=0;If right mouse button is released, free the mouse and stop panning the camera
	EndIf
	;---
	
	If msx# > 90 Then mxs# = 0
	If msx# < 0 Then Msx# = 90
	If mys# > 45 Then mys# = 45
	If mys# < -45 Then mys# = -45
	
	RotateEntity camera,mys#,0,0
	RotateEntity sphere,0,-mxs#,0 


Of course, you can tweak the code to work specifically how you need it, but this is how I achieved a panning camera. There are probably better ways to go about this, but it worked for me. Maybe it could for you too!

Last edited 2012


_PJ_(Posted 2012) [#7]
You may consider some limiting code such as:

Local MX=MouseX()
Local MY=MouseY()
If ((MX<1) + (MX>GraphicsWidth()))
   MX=(GraphicsWidth()*(MX)>0)
End If
If ((MY<1) + (MY>GraphicsHeight()))
   MY=(GraphicsHeight()*(MY)>0)
End If
MoveMouse MX,MY


Last edited 2012


airborne(Posted 2012) [#8]
Thanks guys, sorry for the late response, I'm juggling this code in multiple spots lol, really appreciate all the advice