Elp, Entity yaw.

Blitz3D Forums/Blitz3D Programming/Elp, Entity yaw.

Paul "Taiphoz"(Posted 2004) [#1]
hay all, I know this is gona be something really really daft, but its buggin me so i thought id ask.

If you need the media I will provide it as well just let me know.

ok, What im trying to do is have this target moved by the mouse, the ship will face the target at all times, I'm using the Delta Yaw method to do this(found on a forum search) ..

The Problem is that as I move the target from left to right, as I pass over the ship and go into its right hand side the ship flips over.

Any Ideas ?

;
;
;	Asteroids Remake.
;
;	This mini project has been started as a test bed for some of the things
;	I plan to implement into the SolarShatter code base.
;
;

Graphics3D 800,600,32,2
SetBuffer BackBuffer()
Cls

HidePointer()



Global cam=CreateCamera()
PositionEntity cam,0,0,-20
Global light=CreateLight()


Global background=CreatePlane()
Global texture_background=LoadTexture("img/bg1.jpg")

RotateEntity background,-90,0,0
ScaleTexture texture_background,40,30
PositionTexture texture_background,.50,.50

EntityTexture background,texture_background


Global line_vert=LoadImage("img/vert.jpg")
Global line_hor=LoadImage("img/hor.jpg")
Global Target=LoadImage("img/target.bmp"):MidHandle target:MaskImage target,255,0,255


Global mouse_pivot=CreateSphere(3)




Global PLayer_Ship=LoadMesh("models/ship.3ds")
ScaleEntity player_ship,.02,.02,.02
HideEntity PLayer_Ship


Type player

	Field x#
	Field y#
	Field z#
	
	Field turn_rate#
	Field turn_amount#
	
	Field sight_pivot
	Field model

End Type


Global player.player = New player
	player\x=0
	player\y=0
	player\turn_rate=1.5
	
	player\model=CopyEntity(player_ship)
	PositionEntity player\model,0,0,-2			
	HideEntity background

	
	t=CreateSphere(3)
	PositionEntity t,0,20,-2
	
	player\sight_pivot=CreatePivot()
	PositionEntity player\sight_pivot,0,0,-2
	
	EntityParent player\model,player\sight_pivot
	
	RotateEntity player\model,0,0,90
	


;Play out the game intro

Intro()

Function Intro()

	GUI()
	
End Function

End













Function GUI()
	Local ENDGUI=False
	
	Repeat
		Cls
		
			GUI_Update()
			GUI_Render()
			
			UpdateWorld()
			RenderWorld()
			
			GUI_Render_2D()
			
			If KeyHit(57)=1 Then Game()
			
		Flip False
	Until KeyHit(1) Or ENDGUI=True
	
End Function


Function GUI_Update()
	
	
End Function


Function GUI_Render()
	
	

End Function

Function GUI_render_2D()

End Function













Function GAME()
	Local ENDGAME=False
	
	Repeat
		Cls
		
			GAME_Update()
			GAME_Render()
			
			UpdateWorld()
			RenderWorld()
			
			GAME_render_2d()
		Flip 
	Until KeyHit(1) Or ENDGAME=True
		
End Function

Function GAME_update()
		
	PositionEntity mouse_pivot,-19.1+(MouseX()/20.99),-(-14.2+(MouseY()/20.99)),-2
	PointEntity player\sight_pivot,mouse_pivot
	game_align(player\model,mouse_pivot,1)

End Function

Global switch=False

Function game_align( Entity, Target, Smooth# )

	dp# = GAME_LIMIT ( DeltaPitch( Entity , Target ) , -Smooth , Smooth )
	dy# = GAME_LIMIT ( DeltaYaw( Entity , Target ), -Smooth , Smooth )
	TurnEntity Entity, 0 , dy , 0
		 
End Function


Function GAME_LIMIT#( q# , low# , hi# )

	If q < low q = low
	If q > hi q = hi

	Return q
	
End Function

Function GAME_render()
	PositionEntity player\model,player\x,player\y,-2,1
End Function




Function GAME_render_2D()
	DrawImage line_hor,0,MouseY(),0
	DrawImage line_vert,MouseX(),0,0
	DrawImage target,MouseX(),1+MouseY(),0
	
	
	Text 1,1,"Yaw :"+EntityYaw(player\model,1)
	Text 1,20,"pit :"+EntityPitch(player\model,1)
	Text 1,30,"rol :"+EntityRoll(player\model,1)
End Function




Paul "Taiphoz"(Posted 2004) [#2]
Here is the full source with models and art.

http://yavin.binary-people.com/source/Roidz.zip


AntonyWells(Posted 2004) [#3]
Not tested, but this is a sound method.

function betterPointEntity(Entity1,entity2,axis=1)
       xd#=entityX(entity2)-entityX(entity1)
       yd#=entityY(entity2)-entityY(entity1)
       zd#=entityZ(entity2)-entityZ(entity1)
       td#=sqr(xd*xd+yd*yd+zd*zd)
       alignToVector Entity1,xd/td,yd/td,zd/td,axis
end function


Depending on your model's orientation you may want to change axis to 0 or 2.


Paul "Taiphoz"(Posted 2004) [#4]
Yeah that function is ok, but it allows for the ship to turn on all axis..

So Still need some help here.

All I want is for the ship to turn left or right to face the target, it should not turn on any other axis.


ckob(Posted 2004) [#5]
what i did was parent the model to a pivot and rotated the pivot instead on only yaw.


Paul "Taiphoz"(Posted 2004) [#6]
I tried that cKob it didnt work though.


ckob(Posted 2004) [#7]
hmm maybe detect if the mouse pointer is near the model and tell it not to allow any rotations. Thought this would work but I just noticed it does still rotate pitch :/


AntonyWells(Posted 2004) [#8]
function betterPointEntity(Entity1,entity2,axis=1)
       xd#=entityX(entity2)-entityX(entity1)
       yd#=entityY(entity2)-entityY(entity1)
       zd#=entityZ(entity2)-entityZ(entity1)
       td#=sqr(xd*xd+yd*yd+zd*zd)
       alignToVector Entity1,xd/td,0,zd/td,axis
end function


If you cancel out the Y part of the vector, it'll only point along the flat x/z plane(I.e only affect yaw)..
again not tested..but it should work, maybe with axis 0 or 2.


martonic(Posted 2004) [#9]
How about:
Create a pivot.
After moving the target, position the pivot at x,z of the target and y of the ship. Then, use "PointEntity ship, pivot". If necessary, add "EntityRotate ship,0,entityYaw(ship),0,1" (last 1 = global). That should keep it pinned down to the original orientation except for compass point.
If all of this does not fit your situation, then still, apply the principle: "the simpler the better". Good luck!


Stevie G(Posted 2004) [#10]
Try this Yavin, you're axis were all wrong so I've changes a couple of things. I've positioned camera directly above - it works.


;
;
;	Asteroids Remake.
;
;	This mini project has been started as a test bed for some of the things
;	I plan to implement into the SolarShatter code base.
;
;

Graphics3D 800,600,32,2
SetBuffer BackBuffer()
Cls

HidePointer()



Global cam=CreateCamera()
PositionEntity cam,0,20,0
RotateEntity cam,90,0,0
Global light=CreateLight()
Global switch=False
Global background=CreatePlane()
Global texture_background=LoadTexture("img/bg1.jpg")
ScaleTexture texture_background,40,30
PositionTexture texture_background,.50,.50
EntityTexture background,texture_background

Global line_vert=LoadImage("img/vert.jpg")
Global line_hor=LoadImage("img/hor.jpg")
Global Target=LoadImage("img/target.bmp"):MidHandle target:MaskImage target,255,0,255
Global PLayer_Ship=LoadMesh("models/ship.3ds")
ScaleEntity player_ship,.02,.02,.02
HideEntity PLayer_Ship

Type player
	Field x#
	Field y#
	Field z#
	Field turn_rate#
	Field turn_amount#
	Field sight_pivot
	Field model
End Type

Global player.player = New player
	player\x=0
	player\y=0
	player\z=0
	player\turn_rate=1.5
	
	player\model=CopyEntity(player_ship)
	PositionEntity player\model,0,0,0			
	player\sight_pivot=CreatePivot( player\model)
	PositionEntity player\sight_pivot,0,0,-2
	t=CreateSphere(3, player\sight_pivot):ScaleEntity t, 30, 30, 30

;Play out the game intro

Intro()

Function Intro()

	GUI()
	
End Function

End

;========================
;========================
;========================

Function GUI()
	Local ENDGUI=False
	
	Repeat
		Cls
		
			GUI_Update()
			GUI_Render()
			
			UpdateWorld()
			RenderWorld()
			
			GUI_Render_2D()
			
			If KeyHit(57)=1 Then Game()
			
		Flip False
	Until KeyHit(1) Or ENDGUI=True
	
End Function

;========================
;========================
;========================

Function GUI_Update()
	
	
End Function

;========================
;========================
;========================

Function GUI_Render()

End Function

;========================
;========================
;========================

Function GUI_render_2D()

End Function

;========================
;========================
;========================

Function GAME()
	Local ENDGAME=False
	
	Repeat
		Cls
		
			GAME_Update()
			GAME_Render()
			
			UpdateWorld()
			RenderWorld()
			
			GAME_render_2d()
		Flip 
	Until KeyHit(1) Or ENDGAME=True
		
End Function

Function GAME_update()
		
	PositionEntity player\sight_pivot,-19.1+(MouseX()/20.99),0, -(-14.2+(MouseY()/20.99)), 1
	game_align(player\model, player\sight_pivot,1)

End Function

;========================
;========================
;========================

Function game_align( Entity, Target, Smooth# )

	dp# = GAME_LIMIT ( DeltaPitch( Entity , Target ) , -Smooth , Smooth )
	dy# = GAME_LIMIT ( DeltaYaw( Entity , Target ), -Smooth , Smooth )
	TurnEntity Entity, 0 , dy , 0, 1
		 
End Function

;========================
;========================
;========================

Function GAME_LIMIT#( q# , low# , hi# )

	If q < low q = low
	If q > hi q = hi

	Return q
	
End Function

;========================
;========================
;========================


Function GAME_render()
	PositionEntity player\model, player\x,0,player\z
End Function




Function GAME_render_2D()

	DrawImage line_hor,0,MouseY(),0
	DrawImage line_vert,MouseX(),0,0
	DrawImage target,MouseX(),1+MouseY(),0
	Text 1,1,"Yaw :"+EntityYaw(player\model,1)
	Text 1,20,"pit :"+EntityPitch(player\model,1)
	Text 1,30,"rol :"+EntityRoll(player\model,1)

End Function





Paul "Taiphoz"(Posted 2004) [#11]
That did the trick m8, I knew it was something daft like that.

thanks m8.