Today, I'm not at home. This code seems to do the right thing, but I can only get it to work on 2 angles (it is one more allready!). Here is the source:
; Createcube Example
; ------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
camera=CreateCamera()
;CameraZoom camera, 2.4
light=CreateLight()
RotateEntity light,90,0,0
; Create cube
cube=CreateCube()
PositionEntity cube,0,0,5
While Not KeyDown( 1 )
If KeyDown(203) Then iMoveEntity cube, -0.1, 0, 0
If KeyDown(205) Then iMoveEntity cube, +0.1, 0, 0
If KeyDown(200) Then iMoveEntity cube, -0.0, 0, -0.1
If KeyDown(208) Then iMoveEntity cube, +0.0, 0, +0.1
If KeyDown(16) Then TurnEntity cube, 0, -1, 0
If KeyDown(17) Then TurnEntity cube, 0, +1, 0
If KeyDown(18) Then TurnEntity cube, -1, 0, 0
If KeyDown(19) Then TurnEntity cube, +1, 0, 0
If KeyDown(20) Then TurnEntity cube, 0, 0, -1
If KeyDown(21) Then TurnEntity cube, 0, 0, +1
If KeyHit(30) Then
PositionEntity cube, 0 ,0, 5
RotateEntity cube, 0, 0, 0
End If
RenderWorld
Text 0, 0, "Cursor keys to move"
Text 0, 20, "Q/W Rotate Yaw"
Text 0, 40, "E/R Rotate Pitch"
Text 0, 60, "A reset"
Flip
Wend
End
Function iMoveEntity(mesh, x#, y#, z#)
rx# = EntityX(mesh)
ry# = EntityY(mesh)
rz# = EntityZ(mesh)
;1
gamma# = EntityYaw(mesh)
beta# = -EntityPitch(mesh)
alpha# = EntityRoll(mesh)
xl1#=z#*Sin(gamma)+x#*Cos(gamma)
yl1#=y#
zl1#=z#*Cos(gamma)-x#*Sin(gamma)
xl2#=xl1
yl2#=yl1*Cos(beta)-zl1*Sin(beta)
zl2#=yl1*Sin(beta)+zl1*Cos(beta)
xl3#=(yl2*Sin(alpha)+xl2*Cos(alpha))
yl3#=(yl2*Cos(alpha)-xl2*Sin(alpha))
zl3#=(zl2)
rx = rx + xl3
ry = ry - yl3
rz = rz - zl3
PositionEntity mesh, rx, ry, rz
End Function
The third angle works, but it somehow goes in the wrong direction. This code applies each angle of rotation (pitch/yaw/roll) one by one, which is the right way to do it, at least, that is what I've read somewhere.