Rotation Help - Spinning around a model

Blitz3D Forums/Blitz3D Programming/Rotation Help - Spinning around a model

Slider(Posted 2003) [#1]
I'm still getting to grips with Blitz 3d and I'm having trouble with what seems a simple problem. I have a model that I would like to rotate the camera around, and have the camera always face the model.

My model is located at 10,10,10

The following tries to rotate around the y-axis, but seems to flip around 90 and 270 degrees:
PositionEntity camera, (cos(degs)*3) + 10, 10, (sin(degs)*3) + 10
point_entity(camera, 10, 10, 10)


point_entity is from the code archives:
Function Point_Entity(entity,x#,y#,z#)
	xdiff# = EntityX(entity)-x#
	ydiff# = EntityY(entity)-y#
	zdiff# = EntityZ(entity)-z#

        dist#=Sqr#((xdiff#*xdiff#)+(zdiff#*zdiff#))
	
	pitch# = ATan2(ydiff#,dist#)
	yaw#   = ATan2(xdiff#,-zdiff#)

	RotateEntity entity,pitch#,yaw#,0
End Function


Eventually I would like to control the movement via the cursor keys. Does anyone have advice/code to do this?


Slider(Posted 2003) [#2]
Effectively the camera would always be the same distance from the model, so I guess it would have a 'spherical' movement.

Even when I get it moving on one axis, adding another seems very difficult! Help!!!


Rob(Posted 2003) [#3]
by far the easiest way is the humble pivot.

centerpivot = createpivot()
positionentity centerpivot at target object to rotate about
position camera exactly at distance away from target
PointEntity Camera,centerpivot
EntityParent Camera,centerpivot

All you do now is RotateEntity centerpivot or TurnEntity centerpivot. And the camera will roll effortlessly around. EntityParent camera,0 will break the attachment if you're wondering.


Rob Farley(Posted 2003) [#4]
What Rob said!

Example:

Graphics3D 640,480

c=CreateCube()
p=CreatePivot()

l1=CreateLight(2):PositionEntity l1,1000,0,0:LightColor l1,255,100,100
l2=CreateLight(2):PositionEntity l2,-1000,0,0:LightColor l2,100,100,255
AmbientLight 0,0,0

For n=1 To 100
s=CreateSphere(2)
PositionEntity s,Rand(-10,10),Rand(-10,10),Rand(-10,10)
Next

cam=CreateCamera()

MoveEntity cam,0,0,-10
EntityParent cam,p

Repeat
TurnEntity p,0,1,0

UpdateWorld
RenderWorld
Flip

Until KeyHit(1)



Slider(Posted 2003) [#5]
Thanks guys!