Non-Uniform scale of an object?

Blitz3D Forums/Blitz3D Beginners Area/Non-Uniform scale of an object?

Guy Fawkes(Posted 2012) [#1]
Can someone please tell me the formula for how to get the NON-uniform scale of an object?


Guy Fawkes(Posted 2012) [#2]
Anyone? :(


Yasha(Posted 2012) [#3]
I for one don't understand this question. What's a non-uniform scale? For that matter, what's a uniform scale?


Guy Fawkes(Posted 2012) [#4]
http://en.wikipedia.org/wiki/Scaling_%28geometry%29


Yasha(Posted 2012) [#5]
That's what I figured, but was confused because they're not distinct concepts in B3D.

The most sensible way to get the scale of an entity is to store it somewhere when it's set, and retrieve the value from there when you later need it. Yes there are ways to get it out of an entity using GetMatElement, but I can't think of a single reason (or even excuse) for why you should do that when there's a blindingly-obvious and extremely fast solution to be had by simply writing the numbers down.


RemiD(Posted 2012) [#6]
Also the functions MeshWidth(), MeshHeight(), MeshDepth(), FitMesh() may be useful for what you want to do.


Floyd(Posted 2012) [#7]
Here's another possibility, using the TForm commands.
Function GetScale( e )		; TFormedX() returns X-scale etc.
	Local p#, y#, r#
	p# = EntityPitch( e )
	y# = EntityYaw( e )
	r# = EntityRoll( e )
	RotateEntity e, 0,0,0		; 'unrotate' the entity
	TFormVector 1,1,1, e, 0
	RotateEntity e, p,y,r,  True	; put it back where it was
End Function



Kryzon(Posted 2012) [#8]
That's a neat function you got there.

For those not understanding how to use it:
- It calculates the scale of an entity (good for entities you have no clue what the current scale is).
After calling it, the pivot-scale of the entity you supplied is gonna be stored in the TFormedX(), Y() and Z() components, containing the entity's scale values corresponding to each world-axis.

This only works for entities scaled with ScaleEntity - for meshes scaled with ScaleMesh you can use MeshWidth() etc.


Charrua(Posted 2012) [#9]
nice function!

i got the following functions some time ago (don't remember the source.. sorry):

; -------------------------------------------------------------------------------------------------------------------
; This function returns the X axis scale of an entity, as set by ScaleEntity().
; -------------------------------------------------------------------------------------------------------------------
Function EntityScaleX#(Entity)
	
	Local Scale#, X#, Y#, Z#

	X# = GetMatElement(Entity, 0, 0)
	Y# = GetMatElement(Entity, 0, 1)
	Z# = GetMatElement(Entity, 0, 2)	
	
	Scale# = Sqr(X#*X# + Y#*Y# + Z#*Z#)
	
	Return Scale#

End Function

; -------------------------------------------------------------------------------------------------------------------
; This function returns the Y axis scale of an entity, as set by ScaleEntity().
; -------------------------------------------------------------------------------------------------------------------
Function EntityScaleY#(Entity)
	
	Local Scale#, X#, Y#, Z#
	
	X# = GetMatElement(Entity, 1, 0)
	Y# = GetMatElement(Entity, 1, 1)
	Z# = GetMatElement(Entity, 1, 2)	
	
	Scale# = Sqr(X#*X# + Y#*Y# + Z#*Z#)
	
	Return Scale#

End Function

; -------------------------------------------------------------------------------------------------------------------
; This function returns the Z axis scale of an entity, as set by ScaleEntity().
; -------------------------------------------------------------------------------------------------------------------
Function EntityScaleZ#(Entity)
	
	Local Scale#, X#, Y#, Z#
	
	X# = GetMatElement(Entity, 2, 0)
	Y# = GetMatElement(Entity, 2, 1)
	Z# = GetMatElement(Entity, 2, 2)	
	
	Scale# = Sqr(X#*X# + Y#*Y# + Z#*Z#)
	
	Return Scale#

End Function


Juan