Please help me align this :)

Blitz3D Forums/Blitz3D Programming/Please help me align this :)

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.

No need to use sin/cos maths - use a couple of pivots ..

Graphics3D 800,600,32,2
Global frameTimer = CreateTimer(60)
Global camera=CreateCamera()
CameraZoom camera,1
CameraRange camera, 0.1, 1000
MoveEntity camera,0,0,-3
Color 255,255,0
light=CreateLight(1)

Type part
	Field sprite
	Field vx#
	Field vy#
	Field vz#
	Field deathtime
End Type

Global pAlive

Global emDirX#
Global emDirY#
Global emDirZ#
Global emDirYaw#
Global emDirPitch#=90
Global emissionCone#=10
Global partSpeed#=.1

;SG
Global emPivot = CreatePivot() 
Global emPivotRnd = CreatePivot( emPivot )

Global sphere=CreateSphere(2)
ScaleEntity sphere,.08,.08,.08
HideEntity sphere

Global arrow=CreateCone()
ScaleEntity arrow,.08,.08,.08
RotateMesh arrow,90,0,0
EntityColor arrow,255,255,0

Global pole=CreateCube()
ScaleEntity pole,.03,.03,.45
EntityColor pole,255,255,0

Function emissionTest()

	a.part=New part
	pAlive=pAlive+1
	a\sprite=CopyEntity (sphere)
	EntityAlpha a\sprite,.3
	a\deathtime=MilliSecs()+2000
	
	rndEmCone#=Rnd(-emissionCone,emissionCone)
	
	;SG
	RotateEntity emPivotRnd, rndEmCone, -rndEMCone, 0
	TFormVector 0,0,1, emPivotRnd, 0
	a\vx# = TFormedX() * partSpeed#
	a\vy# = TFormedY() * partSpeed#
	a\vz# = TFormedZ() * partSpeed#						

	moveParticles()

End Function

Function moveParticles()
	For a.part=Each part
		MoveEntity a\sprite,a\vx*partSpeed,a\vy*partSpeed,a\vz*partSpeed
		If MilliSecs()>=a\deathtime Then
			FreeEntity a\sprite
			Delete a
			pAlive=pAlive-1
		EndIf
	Next
End Function

Function drawEmDir()

	;SG
	TFormVector 0,0,1,emPivot, 0
	emDirX# = TFormedX() 
	emDirY# = TFormedY() 
	emDirZ# = TFormedZ() 
	
	AlignToVector arrow,emDirX,emDirY,emDirZ,3
	PositionEntity arrow,emDirX#*1.02,emDirY#*1.02,emDirZ#*1.02
	
	AlignToVector pole,emDirX,emDirY,emDirZ,3
	PositionEntity pole,emDirX#*.5,emDirY#*.5,emDirZ#*.5
End Function

;----------------------------------------------------------------------------------------------------
; MAIN LOOP -----------------------------------------------------------------------------------------
;----------------------------------------------------------------------------------------------------
While Not KeyHit(1)
	WaitTimer(frameTimer)	;rispetta il limite di fps
	
	If KeyDown(205) Then emDirYaw=emDirYaw+2
	If KeyDown(203) Then emDirYaw=emDirYaw-2
	If KeyDown(200) Then emDirPitch=emDirPitch+2
	If KeyDown(208) Then emDirPitch=emDirPitch-2
	If KeyDown(78) And emissionCone<360 Then emissionCone=emissionCone+1
	If KeyDown(74) And emissionCone>0 Then emissionCone=emissionCone-1
	
	;SG
	RotateEntity emPivot, emDirPitch, emDirYaw, 0
	
	emissionTest()
	UpdateWorld()
	RenderWorld()
	drawEmDir()
	tc=0
	tc=tc+1 Text (26-FontWidth()),FontHeight()*tc,"emDirPitch : "+emDirPitch
	tc=tc+1 Text (26-FontWidth()),FontHeight()*tc,"emDirYaw : "+emDirYaw
	tc=tc+1 Text (26-FontWidth()),FontHeight()*tc,"emDirX : "+emDirX
	tc=tc+1 Text (26-FontWidth()),FontHeight()*tc,"emDirY : "+emDirY
	tc=tc+1 Text (26-FontWidth()),FontHeight()*tc,"emDirZ : "+emDirZ
	tc=tc+1 Text (26-FontWidth()),FontHeight()*tc,"emissionCone : "+emissionCone
	tc=tc+1 Text (26-FontWidth()),FontHeight()*tc,"Parts  Alive : "+pAlive
	Flip()
Wend
End