Pointentity Problem

Blitz3D Forums/Blitz3D Programming/Pointentity Problem

This is some code I knocked up to display the values returned by the EntityPitch, EntityYaw, and EntityRoll functions. It illistrates a few points, which I wanted to get clear in my head:

1 - EntityPitch returns the same values in different quadrants.

2 - It's important to be clear on where the starting rotation (0.0 degrees) is, and which direction the rotation will turn the entity in relation to the axis you are viewing along, as well as where the 'flipover' points (plus to minus, etc) are in the rotation.

3 - I have way too much time on my hands.


Const C_CAM_TURN_RATE# = 1.0

Global timer = CreateTimer( 25 )

Graphics3D 800, 600, 0, 2
SetBuffer BackBuffer()

Global cam = CreateCamera()
CameraZoom cam, 1.6
PositionEntity cam, 15.0, 0.0, 0.0

Global light = CreateLight()

Global cone_x = CreateCone() ; Cone points to X+.
RotateMesh cone_x, 0.0, 0.0, -90.0
UpdateNormals cone_x
HideEntity  cone_x

Global cone_y = CreateCone() ; Cone points to Y+.
UpdateNormals cone_y
HideEntity  cone_y

Global cone_z = CreateCone() ; Cone points to Z+.
RotateMesh cone_z, 90.0, 0.0, 0.0
UpdateNormals cone_z
HideEntity  cone_z

Global cone = cone_z
ShowEntity cone

PointEntity cam, cone

Global axis = 1

While Not KeyHit( 1 )

	If KeyHit( 57 )
		axis = axis + 1
		If axis = 4 Then axis = 1
	
		RotateEntity cone, 0.0, 0.0, 0.0
	
		HideEntity cone
		
		If axis = 1 Then PositionEntity cam, 15.0, 0.0, 0.0 : cone = cone_z
		If axis = 2 Then PositionEntity cam, 0.0, 15.0, 0.0 : cone = cone_x
		If axis = 3 Then PositionEntity cam, 0.0, 0.0, 15.0 : cone = cone_y
	
		ShowEntity cone
	
		PointEntity cam, cone
	EndIf
	
	If axis = 1 Then TurnEntity cone, C_CAM_TURN_RATE#, 0.0, 0.0
	If axis = 2 Then TurnEntity cone, 0.0, C_CAM_TURN_RATE#, 0.0
	If axis = 3 Then TurnEntity cone, 0.0, 0.0, C_CAM_TURN_RATE#
	
	UpdateWorld
	RenderWorld
	
	Color 255, 255, 255
	
	Text 10, 10, "Press SPACE to switch to a new axis of rotation"
	
	If axis = 1
		Text 10, 40, "Pitch (X axis): " + EntityPitch( cone )
		Text 10, 60, "Viewing from X+"
		Text 10, 80, "Cone points to Z+"
	EndIf
	
	If axis = 2
		Text 10, 40, "Yaw (Y axis): " + EntityYaw( cone )
		Text 10, 60, "Viewing from Y+"
		Text 10, 80, "Cone points to X+"
	EndIf
	
	If axis = 3
		Text 10, 40, "Roll (Z axis): " + EntityRoll( cone )
		Text 10, 60, "Viewing from Z+"
		Text 10, 80, "Cone points to Y+"
	EndIf
	
	If axis <> 1
	
		Color 200, 0, 0
		
		; -- Draw X+ axis marker.
		CameraProject cam, 5.0, 0.0, 0.0
		Text ProjectedX# (), ProjectedY# (), "X+", True, True
		;^^^^^^
		
		; -- Draw X- axis marker.
		CameraProject cam, -5.0, 0.0, 0.0
		Text ProjectedX# (), ProjectedY# (), "X-", True, True
		;^^^^^^
	
	EndIf
	
	If axis <> 2
	
		Color 240, 240, 0
		
		; -- Draw Y+ axis marker.
		CameraProject cam, 0.0, 5.0, 0.0
		Text ProjectedX# (), ProjectedY# (), "Y+", True, True
		;^^^^^^
		
		; -- Draw Y- axis marker.
		CameraProject cam, 0.0, -5.0, 0.0
		Text ProjectedX# (), ProjectedY# (), "Y-", True, True
		;^^^^^^
	
	EndIf
	
	If axis <> 3
	
		Color 0, 240, 0
		
		; -- Draw Z+ axis marker.
		CameraProject cam, 0.0, 0.0, 5.0
		Text ProjectedX# (), ProjectedY# (), "Z+", True, True
		;^^^^^^
		
		; -- Draw Z- axis marker.
		CameraProject cam, 0.0, 0.0, -5.0
		Text ProjectedX# (), ProjectedY# (), "Z-", True, True
		;^^^^^^
	
	EndIf
	
	Flip
	
	WaitTimer( timer )
	
Wend

End