I'm currently working on a small editer for tokamak rigid bodies, and have run into the problem of camera rotation. I want the camera to rotate around the object, based on user mouse input in a similar way to editers like max(I only have gmax :P) or truespace. I've tried creating a pivot on the object, and then turning this based on mouse speeds but this messes up after multiple turns. Taking this, I tried maintaining the camera's pitch and yaw, and setting roll to 0. this was better, however pretty wierd. Anyone have some helpful code snipbits or methods?
Editer camera rotation
Blitz3D Forums/Blitz3D Programming/Editer camera rotation Try this one ...
Global ML_cam_pivot = CreatePivot() Global ML_cam_pivot2 = CreatePivot(ML_cam_pivot) Global ML_camera = CreateCamera(ML_cam_pivot2) Global x_speed#,y_speed#,z_speed# Function mouselook() x_speed# = x_speed * 0.3 + MouseXSpeed() * 0.3 y_speed# = y_speed * 0.3 + MouseYSpeed() * 0.3 z_speed# = z_speed * 0.3 + MouseZSpeed() * 0.3 MoveMouse GraphicsWidth()/2,GraphicsHeight()/2 TurnEntity ML_cam_pivot,0,-x_speed,0 ;turn player left/right TurnEntity ML_cam_pivot2,y_speed,0,0 ;tilt camera MoveEntity ML_camera,0,0,z_speed ;zoom End Function
Rough and ready, but works pretty nice.
Edit: Updated with Pan
LMB click an entity to focus on it
Left ALT + LMB to Rotate
Left ALT + RMB to Zoom
Left CTRL + LMB to Pan
Cya!
Tom
Edit: Updated with Pan
LMB click an entity to focus on it
Left ALT + LMB to Rotate
Left ALT + RMB to Zoom
Left CTRL + LMB to Pan
Graphics3D 800,600,32,2 Global MOVECAMTARGET=0 Global camzoom#= -10.0 Global cam=CreateCamera() Global campiv=CreatePivot() EntityParent cam,campiv PositionEntity cam,0,0,camzoom CameraRange cam,.1,500 light=CreateLight() Dim ent(10) For i=1 To 10 t=Rand(1,4) Select t Case 1 ent(i)=CreateCube() ScaleEntity ent(i),.5,.5,.5 Case 2 ent(i)=CreateSphere() ScaleEntity ent(i),.5,.5,.5 Case 3 ent(i)=CreateCylinder() ScaleEntity ent(i),.5,.5,.5 Case 4 ent(i)=CreateCone() ScaleEntity ent(i),.5,.5,.5 Default End Select EntityPickMode ent(i),2 ; polygon pickable EntityColor ent(i),Rand(100,255),Rand(100,255),Rand(100,255) PositionEntity ent(i),Rnd(-10,10),Rnd(1.5,8),Rnd(-10,10) Next While Not KeyHit(1) If MouseHit(1) p=CameraPick(cam,MouseX(),MouseY()) If p MOVECAMTARGET=PickedEntity() End If End If If KeyDown(56) And MouseDown(1) mouse_rotation() If KeyDown(56) And MouseDown(2) mouse_zoom() If KeyDown(29) And MouseDown(1) mouse_pan() If MOVECAMTARGET Then MoveCamTo() UpdateWorld RenderWorld Flip Wend End Function MoveCamTo() x#=EntityX#(MOVECAMTARGET,1) - EntityX#(campiv,1) y#=EntityY#(MOVECAMTARGET,1) - EntityY#(campiv,1) z#=EntityZ#(MOVECAMTARGET,1) - EntityZ#(campiv,1) If Abs(x) > .01 Or Abs(y) > .01 Or Abs(z) > .01 PositionEntity campiv,EntityX#(campiv,1) + (x * .1),EntityY#(campiv,1) + (y * .1),EntityZ#(campiv,1) + (z * .1),1 Else MOVECAMTARGET=0 End If End Function Function mouse_rotation() oldx#=MouseX() oldy#=MouseY() currentyaw#=EntityYaw#(campiv,1) currentpitch#=EntityPitch#(campiv,1) While MouseDown(1) newx#= - (MouseX() - oldx) * .5 + currentyaw newy#= (MouseY() - oldy) * .5 + currentpitch If newy > 80 Then newy=80 If newy < -80 Then newy = -80 RotateEntity campiv,newy,newx,0,1 If MOVECAMTARGET Then MoveCamTo() UpdateWorld RenderWorld Flip Wend End Function Function mouse_zoom() oldy#=MouseY() oldcamzoom#=camzoom While MouseDown(2) camzoom= -(MouseY() - oldy) * .05 + oldcamzoom If camzoom < -30 Then camzoom = -30 If camzoom > .5 Then camzoom = .5 PositionEntity cam,0,0,camzoom If MOVECAMTARGET Then MoveCamTo() UpdateWorld RenderWorld Flip Wend End Function Function mouse_pan() oldx#=MouseX() oldy#=MouseY() temppiv=CreatePivot(campiv) EntityParent temppiv,0,1 While MouseDown(1) newx#= - (MouseX() - oldx) * .02 newy#= (MouseY() - oldy) * .02 TFormPoint newx,newy,0,temppiv,0 PositionEntity campiv,TFormedX(),TFormedY(),TFormedZ(),1 If MOVECAMTARGET Then MoveCamTo() UpdateWorld RenderWorld Flip Wend FreeEntity temppiv End Function
Cya!
Tom
cool. thanx :) nice demo btw, tom, some nice camera stuff in there.