Help with AlignToVector

Blitz3D Forums/Blitz3D Programming/Help with AlignToVector

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Would recommend aligning both x and z axis like so ....

Graphics3D 640,480,16,2
SetBuffer BackBuffer()
SeedRnd MilliSecs()

Global lx#
Global ly#
Global lz#

Global cam = CreateCamera()
PositionEntity cam,0,10,-20
Global l=CreateLight()
RotateEntity l,0,0,0

;primary object (source of rotation)
cyl = CreateCylinder()
ScaleEntity cyl,.2,4,.2
PositionEntity cyl,-10,4,0

;secondary object that we'll try to make match "cyl"
cyl2 = CreateCylinder()
ScaleEntity cyl2,.2,4,.2
PositionEntity cyl2,10,4,0
EntityColor cyl2,255,0,0


While Not KeyHit(1)

Delay 100

TurnEntity cyl,.1,.1,.1

;call function to transform object's rotation to vector
lightangle(cyl, 1, 0, 0 )
;align cyl2 to cyl's vector
AlignToVector cyl2,lx,ly,lz,1
lightangle( cyl, 0, 0, 1 )
AlignToVector cyl2,lx,ly,lz,3

UpdateWorld()

RenderWorld()

Text 0,0,EntityPitch(cyl)+" "+lx+" "+EntityPitch(cyl2)
Text 0,12,EntityYaw(cyl)+" "+ly+" "+EntityYaw(cyl2)
Text 0,24,EntityRoll(cyl)+" "+lz+" "+EntityRoll(cyl2)

Flip

Wend


Function lightangle(light , x#, y#, z#)
	TFormVector(x,y,z,light,0)
	lx = TFormedX()
	ly = TFormedY()
	lz = TFormedZ()
End Function