Mouse Wheel Camera

Blitz3D Forums/Blitz3D Programming/Mouse Wheel Camera

Joey(Posted 2005) [#1]
Ok I am trying to make it so when I roll the mouse wheel forward it moves the camera forward and backward the camera goes backward. For some reason it dont work properly. First of all when the app loads and I try to move the camera nothing happens til after I have rotated the camera somewhere with the mouse (its set up to press and hold right click to pivot the mouse around). The second thing it does is if I roll the mouse wheel to go forward sometimes the camera starts going the wrong direction. Whats wrong with this. Here is the code I got.

mzs = mousezspeed()
if mzs = 1
moveentity camera,0,0,100
endif

Heres the code for the right mouse button deal.
if mousedown(2)
mxs=MouseXSpeed()
mys=MouseYSpeed()
dest_cam_yaw#=dest_cam_yaw#-mxs
dest_cam_pitch#=dest_cam_pitch#+mys
cam_yaw=cam_yaw+((dest_cam_yaw-cam_yaw)/5)
cam_pitch=cam_pitch+((dest_cam_pitch-cam_pitch)/5)
RotateEntity camera,cam_pitch#,cam_yaw#,0
MoveMouse Width/2,Height/2
endif


Picklesworth(Posted 2005) [#2]
if mzs = 1

Should be:
if mzs > 0

Or better even (two-directional):
moveentity camera,0,0,mzs ;may want to divide by something

and mzs = mousezspeed()
should be mzs# = mousezspeed()
An integer won't do :D


Joey(Posted 2005) [#3]
uhmm that didn't work. Still same problem.


Joey(Posted 2005) [#4]
thats weird when I set it to move 10 units it seems to work fine but with 100 it messes up.


RiverRatt(Posted 2005) [#5]
I did something like this. Hope it helps.

If MouseZSpeed()<>0 Then
speed#=(MouseZ()+MouseZSpeed())*.1
EndIf




Joey(Posted 2005) [#6]
ok since it worked perfect with moveentity entity,0,0,10 I put that in a for loop and loop it depending on how fast I want it to move. works perfect lol. Just gotta impravize.


Rook Zimbabwe(Posted 2005) [#7]
Did you try
 CameraZoom camera,{ZOOMFACTOR}
Where ZOOMFACTOR is a number up to 2 (I think.) It seems much simpler than moving the camera.

This is in your CODE section in Blitz.
I used MouseZ() instead of MouseZSpeed() so the Zoom would work correctly.
-RZ


RiverRatt(Posted 2005) [#8]
Joey; Did my code not work for you?


Joey(Posted 2005) [#9]
well the zoom wont work becuz I want to just move the camera around the world. And River I havn't gotten to try it yet I been at school. But what part of your code actually moves the camera?


Rook Zimbabwe(Posted 2005) [#10]
With my code you can move the camera around... If you wanted to use the mouse to turn the camera there are lots of tutorials out there. My point is "Don't reinvent the wheel!" If you want to move the camera around the world use the arrow keys or WADX like everyone else.
-RZ


Joey(Posted 2005) [#11]
I am using the mouse for camera control. And the idea I thought worked didn't so I have to figure out another way. Im not re-inventing the wheel just using a method of interface differently and IMO easier than using the arrow keys. Please explain your code RiverRatt. I will look it over when I get home but I couldn't find where you were actually moving the camera.


AdrianT(Posted 2005) [#12]
I did this for my vertical scrolling shooter, but cheated since I used a animated camera in b3d pipeline and the mouse wheel to move through the keyframes


Joey(Posted 2005) [#13]
hmm well I made a function that is broke somehow. Anyone got any Ideas?

code/
Function moveobject#(entity, speed)
yaw# = Entityyaw#(entity)
curpitch# = EntityPitch#(entity)
pitch# = 90 - Abs(curpitch#)
If Abs(yaw#) <= 90
beta_angle# = Abs(yaw#)
Endif
If Abs(yaw#) > 90
beta_angle# = 180 - Abs(yaw#)
Endif
If yaw# => 0 And yaw# <= 90
quadx = 1
quadz = 1
Endif
If yaw# => 90 And yaw# <= 180
quadx = -1
quadz = 1
Endif
If yaw# => 180 And yaw# <= 270
quadx = -1
quadz = -1
Endif
If yaw# => 270 And yaw# <= 360
quadx = 1
quadz = -1
Endif
If curpitch# => 0
quady = 1
Endif
If curpitch# < 0
quady = -1
Endif
x0 = entityx#(entity)
y0 = entityy#(entity)
z0 = entityz#(entity)
xz# = Sin#(pitch#) * speed
y1# = (cos#(pitch#) * speed) * quady
z1# = (sin#(beta_angle#) * xz#) * quadz
x1# = (cos#(beta_angle#) * xz#) * quadx

PositionEntity entity, x0-x1, y0-y1, z0-z1

End Function
code*/


RiverRatt(Posted 2005) [#14]
Joey;In my code the camera is attatched to the box pivot called p_pivot (short for player pivot) in the line p_cam=CreateCamera(p_pivot).
Then its z position is updated right before the cls command.

If MouseZSpeed()<>0 Then
speed#=(MouseZ()+MouseZSpeed())*.1
EndIf

MoveEntity p_pivot,0,0,speed# ;HERE
cls

In this line
If MouseZSpeed()<>0 Then
Is the z mouse button being turned? MouseZSpeed() will return a value greater that 0 for forword movement and less than 0 for backward movement.
and then this line,
speed#=(MouseZ()+MouseZSpeed())*.1
sets the float variable speed# to how far the mouse z button has bin rotated.
MouseZ() the mouses initial starting position.
MouseZSpeed() can be + or - infinity. Now because leaving it speed#=(MouseZ()+MouseZSpeed()) (without the *.1) results in a moving to fast I multiply it by .1 so the camera will move only 1/10
the value of Mousezspeed().


Joey(Posted 2005) [#15]
ok I looked at ur code and its not exactly what I was looking for. I want the camera to move only when the wheel is being turned. I would like to control the camera like they do in TerraEd. This is really making me angry because I can't seem to get this and yet it seems so easy. Why would the camera only do this at higher speeds. And if I increment the speed it seems to not do this at all. Idk what to think/do.


Rook Zimbabwe(Posted 2005) [#16]
Maybe you should rethink it a bit... use MouseZ() to control the SPEED of the movement then you simply have to call this:

If MouseZ() > 0 Then Movementz = MouseZ()
If MouseZ() < 0 then movementz = MouseZ()

You know... use it like an accelerator pedal.

But then again I really can't see what you are doing... It might be brilliant... Good luck.
-RZ


Joey(Posted 2005) [#17]
u know what. ill compile an exe and show you what I got so far. maybe you can help a lil better then.


RiverRatt(Posted 2005) [#18]
Do you meen something more like this?



Joey(Posted 2005) [#19]
Alright thats pretty close but my camera has to be able to rotate around and and idk how to explain it. Here is the link to what I have so far and you will notice the bug in the camera. Got any ideas how to fix this.


http://users.orofino-id.com/joey_gentry/mapbuilder.exe


RiverRatt(Posted 2005) [#20]
It has a memory access violation on startup.

The code I posted was moving the sprite, I fixed it to move the camera.


Joey(Posted 2005) [#21]
Here then compile this. It does the same thing but with less pretties. Also how I post code on the forums.

width = 1024
height = 768
Graphics3d width, height, 0, 1
Setbuffer Backbuffer()
Global dest_cam_x#,dest_cam_z#,dest_cam_pitch#,dest_cam_yaw#

;Load Camera
camera = Createcamera()
Camerarange Camera,1,5000
Positionentity Camera,0,1000,0

gridtex = Loadtexture("media\grid.bmp")
Scaletexture gridtex,100,100

;load Grid
groundplane = Createplane()
Entitytexture groundplane, gridtex

While Not Keyhit(1)

Gosub mouseLook

Renderworld
Flip
Wend
End

;Sets Up MouseLook For The Main Camera
.mouselook
If Mousedown(2)
mxs=Mousexspeed()
mys=Mouseyspeed()
dest_cam_yaw#=dest_cam_yaw#-mxs
dest_cam_pitch#=dest_cam_pitch#+mys
cam_yaw=cam_yaw+((dest_cam_yaw-cam_yaw)/5)
cam_pitch=cam_pitch+((dest_cam_pitch-cam_pitch)/5)
Rotateentity camera,cam_pitch,cam_yaw,0
Movemouse Width/2,Height/2
Endif

Select Mousezspeed()
Case -1
Moveentity camera,0,0,-100
Case 1
Moveentity camera,0,0,100
End Select
Return


Joey(Posted 2005) [#22]
anyone?? I asked terraed and they kindly replied but for some reason it still didn't work.

Can someone translate this for me. Its french.
"Permet de deplacer un objet en Y grace au mouse wheel"


Rook Zimbabwe(Posted 2005) [#23]
Joey you are still trying to reinvent the wheel here... Lets take your question backwards...

To place code on the forums you can either use {code} {/code} (the {} is really the [] but to make the example...) this is used for SHORT bits of code.

Long bits of code are used in {codebox} {/codebox} (again {} are really []...)

second... aside from remaking your code (I had to substitute a texture for one of my own) I find no problem in making it work... Push RIGHT mouse and turn and rotate WHEEL to move forward...??? What else do you want to do???
The WHEEL to move forward works IF you have pressed the RIGHT mouse previously... That can be fixed by cut and paste.

All I get with your program is MEMORY ACCESS VIOLATION which means you made calls to folders or images that aren't there in my directory. Lets face it this is your first project isn't it! : )

Oh yeah... the French... Keeping in mind my French was HS French about 20+ years ago... "permission to move the object in Y using the mouse wheel"

You can also write it this way:
: )
Now if you want it to move forward like it is walking on its own WHEN YOU PRESS the RIGHT mouse button that would be a simple modification.
-RZ


Joey(Posted 2005) [#24]
hey man i thank all of you for your help. Yea this is my first but its going well til now but I got it sorted out. All my code worked fine before. It was an optical illusion when going at high speeds and I not having any other objects could not see this. I apologize for the inconvenience and I understand what your saying now lol. Thanks for you help! Hey also I did notice it would not work unless I press the right mouse button previously but what part of the code fixes that so I know for future refrence.


Rook Zimbabwe(Posted 2005) [#25]
Great! Good luck... ;)
-RZ