All pastes #738140 Raw Edit

Untitled

public text v1 · immutable
·published 2007-10-16 01:24 UTC
rendered paste body

Function Tformpoint:TVector3(vector:TVector3, fromspace:tscenenode = Null, tospace:tscenenode = Null) 
	'This function will convert between cloordinate systems.
	'It will do so linearly- converting first from FROMSPACE to World space - If necesary!
	'and then from World space to Tospace. This will give us all three options
	'necesary to do the required conversions WOOP.
	Local returnvec:TVector3
	Local matrix:TMatrix4 = TMatrix4.createEmpty() 
	
	If fromspace <> Null Then 'Convert from FROMSPACE to World space.
		fromspace.getWorldTransforms(matrix) 
		Local inverse:TMatrix4 = matrix.inverse() 
		vector = inverse.mulWithVector3(vector) 
		If tospace = Null Then Return vector
	EndIf
	
	'TBC: 
	'This code translates from World space space to local space (from World space to TOSPACE)
	If tospace <> Null Then
		tospace.getWorldTransforms(matrix) 
		ReturnVec = matrix.mulWithVector3(vector)  'Vector needs to be the one returned in the World space conversion above if necesarry.
	EndIf
	
	Return returnvec
End Function