Code archives/3D Graphics - Misc/xForm

This code has been declared by its author to be Public Domain code.

Download source code

xForm by Klaas2002
This function resets the scale of an entity and all of its children to scale 1. The entitys still hold there position and the meshes where scaled to the initale scale.

Its somewhat like 3dMax xForm
Function xForm(entity,sxp#=1,syp#=1,szp#=1)
	Vx# = GetMatElement(Entity, 0, 0)
	Vy# = GetMatElement(Entity, 0, 1)
	Vz# = GetMatElement(Entity, 0, 2)	

	sx#=Sqr(Vx#*Vx# + Vy#*Vy# + Vz#*Vz#)
	sy#=Sqr(Vx#*Vx# + Vy#*Vy# + Vz#*Vz#)
	sz#=Sqr(Vx#*Vx# + Vy#*Vy# + Vz#*Vz#)
	
	px#=EntityX(entity) * sxp
	py#=EntityY(entity) * syp
	pz#=EntityZ(entity) * szp

	For i=1 To CountChildren(entity)
		child=GetChild(entity,i)
		xForm(child,sx,sy,sz)
	Next

	ScaleEntity entity,1,1,1
	ScaleMesh entity,sx,sy,sz
	PositionEntity entity,px,py,pz
End Function

Comments

None.

Code Archives Forum