DeltaPitch problem

Blitz3D Forums/Blitz3D Programming/DeltaPitch problem

Ken Lynch(Posted 2003) [#1]
I'm not sure whether there's a bug with DeltaPitch or I'm doing something wrong but to me it only seems to half work. The following code works fine if the spot is on the left but has problems when it is on the right.

Graphics3D 800, 600
SetBuffer BackBuffer()

camera=CreateCamera()

; Position and rotate camera so we have overhead (top-down) view
PositionEntity camera,0,0,-10

; Create red cone (the arrow)
arrow=CreateCone()
RotateMesh arrow,90,0,0
TurnEntity arrow,0,90,0
EntityColor arrow,255,0,0

; Create blue sphere (the spot)
spot=CreateSphere()
EntityColor spot,0,0,255
PositionEntity spot,-5,0,0

While Not KeyDown(1)

	; If w,a,s,d pressed then move spot
	If KeyDown(17)=True Then MoveEntity spot,0,0.1,0 ; w - up
	If KeyDown(30)=True Then MoveEntity spot,-0.1,0,0 ; a - left
	If KeyDown(31)=True Then MoveEntity spot,0,-0.1,0 ; s - down
	If KeyDown(32)=True Then MoveEntity spot,0.1,0,0 ; d - right

	; Rotate arrow using delta yaw value. Arrow will point at spot.
	TurnEntity arrow,DeltaPitch(arrow, spot),0,0
	
	RenderWorld

	Text 0,0,"Note: Camera view is overhead. The arrow will x-rotate using DeltaPitch value."
	Text 0,20,"Use w,a,s,d to move spot."

	Flip
	Wend

End 


I've done the same code using DeltaYaw and that works perfectly. Does DeltaPitch work slightly differently or is it a bug?


DJWoodgate(Posted 2003) [#2]
Its not a bug. Pitch values only range from -90 to 90. So you need to incorporate Yaw to get a proper direction vector. However this gets a bit iffy in this context because as pitch approaches -90 or 90 yaw ceases to have a lot of meaning.


Jeppe Nielsen(Posted 2003) [#3]
Why not use Atan2() to turn your arrow?


Floyd(Posted 2003) [#4]
Yaw and Pitch cover ranges of 360 and 180 degrees.
They are similar to Longitude and Latitude on the Earth.

If Pitch (Latitude) spanned 360 degrees then every
orientation (point on the Earth) would be covered twice.

The result is that DeltaPitch by itself is not a useful concept.

You can see how Yaw and Pitch interact with this slight
variation on your example.
Graphics3D 800, 600
SetBuffer BackBuffer()

camera=CreateCamera()

; Position and rotate camera so we have overhead (top-down) view
PositionEntity camera,0,0,-10

; Create red cone (the arrow)
arrow=CreateCone()
RotateMesh arrow,90,0,0
TurnEntity arrow,0,90,0
EntityColor arrow,255,0,0

; Create blue sphere (the spot)
spot=CreateSphere()
EntityColor spot,0,0,255
PositionEntity spot,-5,0,0

While Not KeyDown(1)

	; If w,a,s,d pressed then move spot
	If KeyDown(17)=True Then MoveEntity spot,0,0.1,0 ; w - up
	If KeyDown(30)=True Then MoveEntity spot,-0.1,0,0 ; a - left
	If KeyDown(31)=True Then MoveEntity spot,0,-0.1,0 ; s - down
	If KeyDown(32)=True Then MoveEntity spot,0.1,0,0 ; d - right

	; Rotate arrow using delta yaw value. Arrow will point at spot.
	
	dp# = DeltaPitch(arrow, spot)
	dy# = DeltaYaw(arrow,spot)

	;TurnEntity arrow, d,0,0
	
	RenderWorld

	Text 0,0,"Note: Camera view is overhead. The arrow will x-rotate using DeltaPitch value."
	Text 0,20,"Use w,a,s,d to move spot."
	Text 0,60,"DeltaPitch = " + Int(1000*dp)/1000.0
	Text 0,80,"  DeltaYaw = " + Int(1000*dy)/1000.0
	Flip
Wend

The same thing happens on Earth when you cross over the North or South Pole.
Longitude suddenly jumps by 180 degrees.


Ken Lynch(Posted 2003) [#5]
Thanks for the replies. I think the online help needs changing as it says for DeltaPitch:


Returns the pitch angle, that src_entity should be rotated by in order to face dest_entity.



The command name is confusing, while you are all correct in saying you only need pitch values from -90 to 90, Delta in maths is a 'difference' so it is possible to have a DeltaPitch from -180 to 180 and this is what I'd assume from the command name and its description.