Code archives/3D Graphics - Misc/EntityScaleX(), EntityScaleY(), EntityScaleZ()

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

Download source code

EntityScaleX(), EntityScaleY(), EntityScaleZ() by sswift2002
These funtions return the scale you have set for each axis of an entity with ScaleEntity().

They do so by accessing and interpreting the data in the entity's transformation matrix using an undocumented Blitz command.

These commands are great to have any time you need to know how an entity has been scaled but that information isn't actualyl stored anyhwere. Like if you're writing a library for other folks to use which needs to take an entity's scale into account.
; -------------------------------------------------------------------------------------------------------------------
; This function returns the X axis scale of an entity, as set by ScaleEntity().
; -------------------------------------------------------------------------------------------------------------------
Function EntityScaleX#(Entity)

        Local Vx#, Vy#, Vz#, Scale#

	Vx# = GetMatElement(Entity, 0, 0)
	Vy# = GetMatElement(Entity, 0, 1)
	Vz# = GetMatElement(Entity, 0, 2)	
	
	Scale# = Sqr(Vx#*Vx# + Vy#*Vy# + Vz#*Vz#)
	
	Return Scale#

End Function


; -------------------------------------------------------------------------------------------------------------------
; This function returns the Y axis scale of an entity, as set by ScaleEntity().
; -------------------------------------------------------------------------------------------------------------------
Function EntityScaleY#(Entity)

        Local Vx#, Vy#, Vz#, Scale#

	Vx# = GetMatElement(Entity, 1, 0)
	Vy# = GetMatElement(Entity, 1, 1)
	Vz# = GetMatElement(Entity, 1, 2)	
	
	Scale# = Sqr(Vx#*Vx# + Vy#*Vy# + Vz#*Vz#)
	
	Return Scale#

End Function


; -------------------------------------------------------------------------------------------------------------------
; This function returns the Z axis scale of an entity, as set by ScaleEntity().
; -------------------------------------------------------------------------------------------------------------------
Function EntityScaleZ#(Entity)

        Local Vx#, Vy#, Vz#, Scale#

	Vx# = GetMatElement(Entity, 2, 0)
	Vy# = GetMatElement(Entity, 2, 1)
	Vz# = GetMatElement(Entity, 2, 2)	
	
	Scale# = Sqr(Vx#*Vx# + Vy#*Vy# + Vz#*Vz#)
	
	Return Scale#

End Function

Comments

Ross C2006
Excellent stuff man!


Fuller2006
useful in editors and stuff


Code Archives Forum