B3D's Entity Rotation

Blitz3D Forums/Blitz3D Programming/B3D's Entity Rotation

xmlspy(Posted 2006) [#1]
It is annoying the heck out of me how the rotation does not go from 0 to 359. My program is trying to get the entity's yaw and it bothers the heck out of me how the yaw can be 180 or -180.

Anyone have some functions to return rotation values from 0 to 359?


xmlspy(Posted 2006) [#2]
This seems to work...
Graphics3D 640, 480, 0, 2

cam = CreateCamera()
MoveEntity cam, 0, 0, -5

c = CreateCube()

Repeat
	cr =cr+1
	RotateEntity c, 0, cr, 0
	
	RenderWorld
	Text 0, 20, EntityYaw(c)
	Text 0, 0, TEntityYaw(c)
	Flip
Until KeyHit(1)
End

Function TEntityYaw#(entity)
	ey# = EntityYaw(entity)
	If ey>=-180 And ey <=0
		ey = (360+ey)
		DebugLog ey
		Return ey
	ElseIf ey >= 0 And ey <=180
		Return ey
	EndIf
End Function



(tu) sinu(Posted 2006) [#3]
use:

if ey<0
ey = ey+360
return ey
else
return ey
endif

ey will always be>=-180 :)


xmlspy(Posted 2006) [#4]
Got it before you did... ja! :p


Stevie G(Posted 2006) [#5]
How about this one ..

Ey = Ey + 360.0 * ( EntityYaw( Entity ) < 0 )

;)


Damien Sturdy(Posted 2006) [#6]
B3D's way of doing it is actually pretty nice, since you can use the yaw directly in a calculation for AI purposes. it saves alot of confusion; Turntonorm=-Entityyaw(mahmama)/10.0 slowly turns the entity back to 0.
It's useful to avoid alot of AI coding and because of this allows faster AI code. (Thats how I use it ;) )


Stevie G(Posted 2006) [#7]
Agree with Cyg. It's far more logical and useful in 3d when you get used to it.

Stevie


(tu) sinu(Posted 2006) [#8]
It's just when you want to use it to turn the entity in relation to the camera ie mario64 that the -180 rotation system gets tricky.


Stevie G(Posted 2006) [#9]
@ sinu ...

Completely disagree. Try this short example ... A + S to rotate the camera, cursors to move. No need to worry about the rotation system ;)


Graphics3D 640,480,16,1

Global LIGHT = CreateLight()
Global PLANE = CreatePlane() 
EntityColor PLANE, 200,100,100
texture = CreateTexture( 32, 32 )
SetBuffer TextureBuffer( texture )
For y = 0 To 1
	For x = 0 To 1
		Color 100, 150+25*( ( x+y) Mod 2 ) , 100
		Rect x*16,y*16,16,16,1
	Next
Next
SetBuffer BackBuffer()
ScaleTexture texture, 50,50
EntityTexture PLANE, texture
FreeTexture texture

Global CUBE = CreateCube() : FitMesh CUBE, -2,0,-2,4,10,4
Global CAMERApivot = CreatePivot()
Global CAMERA = CreateCamera( CAMERApivot )
PositionEntity CAMERA, 0,50,-50
PointEntity CAMERA , CAMERApivot

While Not KeyDown(1)

	PositionEntity CAMERApivot , EntityX( cube ) , 0, EntityZ( cube )
	TurnEntity CAMERApivot, 0 , KeyDown(31) - KeyDown(30) , 0
	Mx# = KeyDown(205) - KeyDown(203)
	Mz# = KeyDown(200) - KeyDown(208 )
	TFormVector Mx, 0, Mz , CAMERApivot , 0
	TranslateEntity CUBE, TFormedX(), 0, TFormedZ()

	RenderWorld()
	Flip

Wend


Stevie


(tu) sinu(Posted 2006) [#10]
@Stevie G

Am i missing something, all that demo shows is how to translate the entity correctly when turning a camera around it, not actually turning the entity to face the right direction too?


Stevie G(Posted 2006) [#11]
Sorry mate .. is this what you mean?



Stevie


(tu) sinu(Posted 2006) [#12]
Yep, i only discovered the coolness of the Delta commands recently and didn't think of using in this way, cheers :)