[Irrlicht] Helper Function: IrrFaceTargetNode()
Posted: Wed Jan 09, 2008 1:05 am
Since its been asked before.
Here some basic Function that Aligns one Node to Another.
Just Aligns X Axis for now but you should be able to extend it yourself now - as you see its not too hard
This can also be very handy to align your node on for example your playfield. By simply using a CubeSceneNode() using the Visibility Flag to OFF its a very convenient way ( not to mention that thoose nodes can be placed in irrEdit ).
btw. If you find the node following your command sluggyish, then comment out the delay. Events are processed each loop from the CPU while the GPU Renderloop still may bring high FPS in a simple scene. In essence, the events are processed in the speed of your mainloop.
Screenshot:

Executable Example & Function Source:
>>>> DOWNLOAD
Function Source:
Thalius
Here some basic Function that Aligns one Node to Another.
Just Aligns X Axis for now but you should be able to extend it yourself now - as you see its not too hard

This can also be very handy to align your node on for example your playfield. By simply using a CubeSceneNode() using the Visibility Flag to OFF its a very convenient way ( not to mention that thoose nodes can be placed in irrEdit ).
btw. If you find the node following your command sluggyish, then comment out the delay. Events are processed each loop from the CPU while the GPU Renderloop still may bring high FPS in a simple scene. In essence, the events are processed in the speed of your mainloop.
Screenshot:

Executable Example & Function Source:
>>>> DOWNLOAD
Function Source:
Code: Select all
; IRRFace Target Node (Aligns Sourcenode to Look at Targetnode )
; Returns #True / #False (alignment / no alignment)
;
; Usage:
; If IrrFaceTargetNode( *source_node, *target_node )
; Debug "Aligned"
; EndIf
;
Procedure IrrFaceTargetNode( *src.irr_node, *target.irr_node )
Protected ndiff.IRR_VECTOR, targetPos.IRR_VECTOR, srcPos.IRR_VECTOR, degree.f
; Check Pointers
If *target And *src
; Get Source Position
IrrGetNodePosition(*src, @srcPos\x, @srcPos\y, @srcPos\z)
; Get Target Position
IrrGetNodePosition(*target, @targetPos\x, @targetPos\y, @targetPos\z)
; Calculate Diff
ndiff\x = targetPos\x - srcPos\x
ndiff\y = targetPos\y - srcPos\y
ndiff\z = targetPos\z - srcPos\z
; Check X
If ndiff\x = 0.0
ProcedureReturn #False
Else
; Calculate Degree
degree.f = (ATan(ndiff\z / ndiff\x) * (180.0 / #PI))
; Fix Delta
If srcPos\x - targetPos\x > 0
degree.f = 90 - degree.f
Else
degree.f = -90 - degree.f
EndIf
; Rotate
IrrSetNodeRotation(*src ,0.0, degree.f, 0.0)
ProcedureReturn #True
EndIf
Else
ProcedureReturn #False
EndIf
EndProcedure