Camera Problem!
Blitz3D Forums/Blitz3D Programming/Camera Problem!
| ||
Sorry, I don't mean to be a pest by posting this in both the beginners area and here, but I thought I'd try anyway. If that's a breach of conduct, please let me know. I have a quick question regarding cameras in Blitz3D. My problem might have to do with the fact that I am misunderstanding the way AlignToVector and MoveEntity commands work. Here's a bit of code to illustrate my problem: Graphics3D 800,600 SetBuffer BackBuffer() Global mx,my,mz,mzspd,rotup,ticker,camera camera = CreateCamera() PositionEntity camera,0,-15,-5 TurnEntity camera,-90,0,0 light = CreateLight() cube = CreateCube() Function UpdateCamera() If mzspd > 0 rotup = 1 ElseIf mzspd < 0 rotup = -1 EndIf If rotup = 1 And ticker < 60 AlignToVector camera,0,.01,0,2,.01 MoveEntity camera,0,.1,.1 ticker = ticker + 1 ElseIf rotup = -1 And ticker < 60 AlignToVector camera,0,-.01,0,2,.01 MoveEntity camera,0,-.1,-.1 ticker = ticker + 1 EndIf If ticker = 60 rotup = 0 ticker = 0 EndIf End Function While Not KeyHit(1) mx = MouseX() my = MouseY() mz = MouseZ() UpdateWorld RenderWorld UpdateCamera() mxspd = MouseXSpeed() myspd = MouseYSpeed() mzspd = MouseZSpeed() If MilliSecs()<timer+1000 Then frame=frame+1 Else fps=frame frame=0 timer=MilliSecs() End If Flip Wend End I wanted it to work so that when I scroll up on the mouse button (just one click should do), it moves the camera up and tilts it down on the cube. When I scroll back (again, a single click should do), I want it to _perfectly reverse_ that motion. However, I find that when I scroll back, it doesn't bring the camera back to its starting point! What gives? If you could offer any help, I'd greatly appreciate it. Thanks, -- DJ3J, once again showing just how much of a beginner he really is. |
| ||
Hi DJ3J, I think what you want to do is to repeatedly point at the centre of the cube while moving around the arc of a circle. The PointEntity command takes care of looking at the cube, but the moving part will probably involve trig in calculating the distance to move in the y/z directions... If you just point at the cube and then move directly forward+up or backward+down you wont get the effect I think you are aiming for. I'll see if I can knock out some demo code later... |
| ||
how about positioning the camera at the same co-ordinates as the cube then zooming out? You can then rotate the camera around the cube a lot easier... Im not at home so i cant test this out though... |
| ||
I remember this being used in the dragon demo tho when i first downloaded the blitz3d demo... |
| ||
WHat you need to do, is each loop reset the pitch angle of the camera to zero, move the camera back or forward, depending on the mouseZ value, then point the camera at the cube. In that order. It should work fine :) |
| ||
Here's some code to do it. It's uses up and down arrow keys to move the camera :)Graphics3D 800,600 SetBuffer BackBuffer() Global camera=CreateCamera() Global light=CreateLight() Global cube=CreateCube() EntityParent camera,cube PositionEntity camera,0,2,-5 Global cube1=CreateCube(); cube so you can see movement EntityColor cube1,100,100,255 PositionEntity cube1,-1,0,5 While Not KeyHit(1) If KeyDown(200) Then movecamera(0.1) If KeyDown(208) Then movecamera(-0.1) UpdateWorld RenderWorld Text 0,0,"cam height="+EntityY(camera,True) Flip Wend Function movecamera(value#) RotateEntity camera,0,EntityYaw(camera),EntityRoll(camera) If Abs(EntityDistance(camera,cube))>0.5 And Abs(EntityDistance(camera,cube))<10 Then;ensure it's inside limits MoveEntity camera,0,0,value; move camera End If If Abs(EntityDistance(camera,cube))<3 Or Abs(EntityDistance(camera,cube))>10 Then; make sure camera stays within limits MoveEntity camera,0,0,-value; move camera back to previous location End If PointEntity camera,cube End Function |