DeltaYaw

Blitz3D Forums/Blitz3D Programming/DeltaYaw

I have searched the forums for a way to get the deltayaw between an entity and a coordinate without the need to create a temporary pivot and such without a success.
So i have tried on my own, here's the result so far:

; vector defintion
Type vec3d
 Field x#
 Field y#
 Field z#
End Type

Function VectorDot#(v1.vec3d,v2.vec3d)
 Return (v1\x*v2\x)+(v1\y*v2\y)+(v1\z*v2\z)
End Function

v1.vec3d = New vec3d
v2.vec3d = New vec3d

; some geometry
Graphics3D 800,600,0,2
SetBuffer BackBuffer()
cam = CreateCamera()
CameraZoom cam,1.6
obj1 = CreateCone()
ScaleEntity obj1,2,4,2
obj2 = CreateCube()
EntityColor obj1,255,0,0
EntityColor obj2,0,255,0
plane = CreatePlane()
EntityPickMode plane,2
PositionEntity plane,0,-1,0
RotateEntity obj1,90,0,0
PositionEntity cam,0,50,0
PointEntity cam,plane

;PositionEntity obj1,-10,0,-5

While Not KeyHit(1)

 If CameraPick (cam,MouseX(),MouseY())
	
  PositionEntity obj2,PickedX(),0,PickedZ()
		
  TFormNormal 0,0,1,obj1,0
  v1\x = TFormedX()
  v1\y = TFormedY()
  v1\z = TFormedZ()
				
  TFormNormal PickedX()-EntityX(obj1,1),PickedY()-EntityY(obj1,1),PickedZ()-EntityZ(obj1,1),0,obj1
			
  v2\x = TFormedX()
  v2\y = TFormedY()
  v2\z = TFormedZ()
		
  If v2\x < 0
   dir = 1
  Else
   dir = -1
  EndIf

  dot# = VectorDot#(v2,v1)
  angle# = ACos(-dot)
					
  TurnEntity obj1,0,angle*dir*0.1,0,1
			
 EndIf

 UpdateWorld()
 RenderWorld()
 Text 10,10,"X: " + EntityX(obj2)
 Text 10,30,"Y: " + EntityY(obj2)
 Text 10,50,"Z: " + EntityZ(obj2)
 Text 10,70,"ANGLE: " + angle
 Flip
 
 Wend

Delete Each vec3d
ClearWorld()
EndGraphics()
End

Although it spits out results that will fit my needs, i am not absolutely sure, if the transformations used are correct. Beside of this you will notice that the dot product is negated, i believe this is not correct since a negative dot product will show something that is behind the center object. Maybe someone has a deeper understanding of vectormath and may improve the above.

Why overcomplicate it for the sake of creating a global pivot which is re-used. I'd imagine it's also quicker than what you have.

That said - this is less code ..

;; some geometry
Graphics3D 800,600,0,2
SetBuffer BackBuffer()
cam = CreateCamera()
CameraZoom cam,1.6
obj1 = CreateCone()
RotateMesh obj1, 90,0,0
ScaleMesh obj1,2,2,4
obj2 = CreateCube()
EntityColor obj1,255,0,0
EntityColor obj2,0,255,0
plane = CreatePlane()
EntityPickMode plane,2
PositionEntity plane, 0, -1, 0
PositionEntity cam,0,50,0
PointEntity cam,plane


While Not KeyHit(1)

 If CameraPick (cam,MouseX(),MouseY())
	
  PositionEntity obj2,PickedX(),PickedY(),PickedZ()

	TFormPoint PickedX() , 0 , PickedZ()  , 0 , obj1
	angle# = ATan2( TFormedZ() , TFormedX() ) - 90
	TurnEntity obj1,0, angle * .1,0, 1
			
 EndIf

 UpdateWorld()
 RenderWorld()
 Text 10,10,"X: " + EntityX(obj2)
 Text 10,30,"Y: " + EntityY(obj2)
 Text 10,50,"Z: " + EntityZ(obj2)
 Text 10,70,"ANGLE: " + angle
Text 10,80,"TX : "+TFormedX()
Text 10,90,"Tz : "+TFormedZ()

 Flip
 
 Wend

ClearWorld()
EndGraphics()
End


Stevie

Ah, thank you ! This is indeed quite simple. I have found the corresponding function in the blitz-help now.

Cheers.