Ok, done it. This uses camerapick() to get the 3d location of the mouse, as if it was projected onto the plane working surface. It then positions the pivot (visualised as a white sphere), at the mouse co-ords.
Now, because when you zoom in, the mouse co-ords remain the same, this causes a problem. The zoom will constantly try and centre the screen. So you have to adjust the mouse pointer too. So, i'm using cameraproject directly after my zoom code, in the "zoom_in" function.
What this does it take an entity in the 3d world, and return it's 2d co-ords on screen. So after the zoom, the pivot moves closer to the centre of the camera. I project it's co-ords into 2d, and move the mouse to that location.
The first part of that function moves the camera so the pivot is closer to the centre of the camera. It cuts off if it is within 0.1 blitz units, to stop it moving for so long.
The second part of the function is the same, except it moves the camera in more, actually zooming.
The third part of the function is the camera project stuff i explained above.
Full code:
Now, because when you zoom in, the mouse co-ords remain the same, this causes a problem. The zoom will constantly try and centre the screen. So you have to adjust the mouse pointer too. So, i'm using cameraproject directly after my zoom code, in the "zoom_in" function.
What this does it take an entity in the 3d world, and return it's 2d co-ords on screen. So after the zoom, the pivot moves closer to the centre of the camera. I project it's co-ords into 2d, and move the mouse to that location.
Function zoom_in() PositionEntity zoom_piv,EntityX(zoom_piv,True),EntityY(zoom_piv,True),EntityZ(camera) If EntityDistance(camera,zoom_piv) > 0.1 Then PointEntity camera,zoom_piv MoveEntity camera,0,0,EntityDistance#(zoom_piv,camera)/15 End If PositionEntity zoom_piv,EntityX(zoom_piv,True),EntityY(zoom_piv,True),0 PointEntity camera,zoom_piv If EntityZ(camera)<-1.9 Then MoveEntity camera,0,0,EntityDistance#(zoom_piv,camera)/20 If EntityZ(camera)>-1.9 Then PositionEntity camera,EntityX(camera,True),EntityY(camera,True),-1.9 End If End If RotateEntity camera,0,0,0 CameraProject(camera,EntityX(zoom_piv,True),EntityY(zoom_piv,True),EntityZ(zoom_piv)) MoveMouse ProjectedX#(),ProjectedY#() End Function
The first part of that function moves the camera so the pivot is closer to the centre of the camera. It cuts off if it is within 0.1 blitz units, to stop it moving for so long.
The second part of the function is the same, except it moves the camera in more, actually zooming.
The third part of the function is the camera project stuff i explained above.
Full code:
Graphics3D 800,600 SetBuffer BackBuffer() Global camera = CreateCamera() PositionEntity camera,0,0,-10 Global light = CreateLight() Global zoom_piv = CreateSphere() ScaleEntity zoom_piv,0.3,0.3,0.3 Global plane = CreatePlane() TurnEntity plane,-90,0,0 EntityPickMode plane,2 Global plane_texture = CreateTexture(64,64) SetBuffer TextureBuffer(plane_texture) Color 128,128,255 Rect 0,0,64,64 Color 64,64,255 Rect 1,1,62,62 SetBuffer BackBuffer() EntityTexture plane,plane_texture While Not KeyHit(1) If KeyDown(203) Then MoveEntity zoom_piv,-0.1,0,0 If KeyDown(205) Then MoveEntity zoom_piv,0.1,0,0 If KeyDown(200) Then MoveEntity zoom_piv,0,0.1,0 If KeyDown(208) Then MoveEntity zoom_piv,0,-0.1,0 If KeyDown(2) Then zoom_in() ElseIf KeyDown(3) Then zoom_out() End If CameraPick camera,MouseX(),MouseY() PositionEntity zoom_piv,PickedX(),PickedY(),0 UpdateWorld RenderWorld Flip Delay 20 Wend Function zoom_in() PositionEntity zoom_piv,EntityX(zoom_piv,True),EntityY(zoom_piv,True),EntityZ(camera) If EntityDistance(camera,zoom_piv) > 0.1 Then PointEntity camera,zoom_piv MoveEntity camera,0,0,EntityDistance#(zoom_piv,camera)/15 End If PositionEntity zoom_piv,EntityX(zoom_piv,True),EntityY(zoom_piv,True),0 PointEntity camera,zoom_piv If EntityZ(camera)<-1.9 Then MoveEntity camera,0,0,EntityDistance#(zoom_piv,camera)/20 If EntityZ(camera)>-1.9 Then PositionEntity camera,EntityX(camera,True),EntityY(camera,True),-1.9 End If End If RotateEntity camera,0,0,0 CameraProject(camera,EntityX(zoom_piv,True),EntityY(zoom_piv,True),EntityZ(zoom_piv)) MoveMouse ProjectedX#(),ProjectedY#() End Function Function zoom_out() If EntityZ(camera)>-10 Then MoveEntity camera,0,0,-EntityDistance#(zoom_piv,camera)/20.0 If EntityZ(camera)<-10 Then PositionEntity camera,EntityX(camera,True),EntityY(camera,True),-10 End If End If RotateEntity camera,0,0,0 End Function