Trig troubles with camera.

Blitz3D Forums/Blitz3D Programming/Trig troubles with camera.

Shifty Geezer(Posted 2005) [#1]
I'm trying to lock my camera so it doesn't drop below 0 height. I use 2 pivots for controlling rotation. I'm using the Mouse_lib.bb for reading mouse. Here's my code...
rostrum_pan=CreatePivot()
rostrum_tilt=CreatePivot(rostrum_pan)
camera=CreateCamera(rostrum_tilt)
CameraZoom camera,CAMERA_ZOOM
PositionEntity camera,0,0,-300
RotateEntity rostrum_tilt,35,0,0
PositionEntity rostrum_pan,0,50,0

mouse_z=mouse\speedz*10*modifier
test=EntityZ(camera)+mouse_z
If Abs(test)<3500
	MoveEntity camera,0,0,mouse_z
EndIf

If mouse\br\down
	TurnEntity rostrum_pan,0,mouse\speedx / 5.0,0
	TurnEntity rostrum_tilt,mouse\speedy / 5.0,0,0
	mouse\x=mx
	mouse\y=my
	MoveMouse mx,my
EndIf	
If EntityY(camera,1)<0			; If camera under 0 y
	theta#=ACos(EntityY(rostrum_tilt,1)/Abs(EntityZ(camera)))
	RotateEntity rostrum_tilt,theta,0,0,1
EndIf

Trouble is, it don't work!


Shifty Geezer(Posted 2005) [#2]
Solved replacing ACos with ASin. This flies in the face of my A-level maths, but what the hey!


markcw(Posted 2005) [#3]
you did a-level maths and you need help
with that?! lazy git. :)


Shifty Geezer(Posted 2005) [#4]
Though I passed I'm hazy at maths. Like computing - got a degree in Computer Science and still fumble around witht he basics ;)

On paper, angle=cos(Adjacent/Hypotenuse), but that wasn't working. So I swapped out Cos with Sin (which you always try when it isn't working as they're pretty much the same thing offset slightly!) and it worked. But I still don't know why!


markcw(Posted 2005) [#5]
well that explains it then! :)

but yeah, cos is the other angle to sin
in a 90dg triangle.