Editer camera rotation

Blitz3D Forums/Blitz3D Programming/Editer camera rotation

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

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



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