All pastes #743936 Raw Edit

Someone

public text v1 · immutable
·published 2007-10-20 22:46 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	'Translate from localspace to worldspace
		fromspace.getWorldTransforms(matrix) 
		vector:TVector3 = matrix.mulWithVector3(vector) 
		If tospace = Null Then Return vector 'If this is allwe need to do, then return the vector.
	EndIf
	
	If tospace <> Null Then	'If we need to convert to global, then this is where we do so.
	
		tospace.getWorldTransforms(matrix) 
		Return matrix.inverse().mulWithVector3(vector) 

	EndIf
	
End Function