; VectorPitch Example ; ------------------- Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,4,-14 RotateEntity camera,8,0,0 light=CreateLight() RotateEntity light,45,45,0 ground=CreatePlane() EntityTexture ground,LoadTexture("media/MossyGround.BMP") ; A turret that has to tilt as well as turn turret=CreateCube() PositionEntity turret,0,1,0 barrel=CreateCylinder(12,True,turret) ScaleEntity barrel,0.3,1.2,0.3 RotateEntity barrel,90,0,0 PositionEntity barrel,0,0,1.2 ; The drone it is tracking, sweeping past and bobbing drone=CreateSphere(12) ScaleEntity drone,0.5,0.5,0.5 EntityColor drone,240,120,60 height#=4.0 While Not KeyDown(1) ; [ and ] fly the drone lower and higher If KeyDown(26) And height>-1 Then height=height-0.05 If KeyDown(27) And height<8 Then height=height+0.05 ; Sweep the drone left and right so the aim keeps changing PositionEntity drone,Sin(MilliSecs()/25.0)*7,height,7 ; The direction from the turret to the drone (both sit at the top level, ; so their local coordinates are already world coordinates) dx#=EntityX(drone)-EntityX(turret) dy#=EntityY(drone)-EntityY(turret) dz#=EntityZ(drone)-EntityZ(turret) ; VectorPitch is the up/down half of the aim, VectorYaw the left/right half pitch#=VectorPitch(dx,dy,dz) RotateEntity turret,pitch,VectorYaw(dx,dy,dz),0 ; Arrow keys move the camera If KeyDown(200) Then MoveEntity camera,0,0,0.1 If KeyDown(208) Then MoveEntity camera,0,0,-0.1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 RenderWorld Text 0,0,"[ / ]: fly the drone up and down Arrows: camera Esc: exit" Text 0,20,"VectorPitch("+dx+","+dy+","+dz+") = "+pitch Text 0,40,"RotateEntity turret,pitch,yaw,0 aims the barrel in one go" Text 0,60,"Up is NEGATIVE pitch: VectorPitch(0,1,0) = "+VectorPitch(0,1,0) Flip Wend End