Why is my scaling wrong?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By raould
:warning: Old Version Published before Godot 3 was released.

following on from
https://forum.godotengine.org/8486/what-is-a-transform-really
and
https://forum.godotengine.org/7469/matrix-vs-tranform-local-vs-global?show=7469#q7469

I scale first then do rotate, then do translate. Why does it only end up in the right place when my scaling vector is (1,1,1)?

extends Node
const Util = preload( "util.gd" )
const k_mother_sx = 20
const k_mother_sy = 5
const k_mother_sz = 10
var k_mother_s3 = Vector3( k_mother_sx, k_mother_sy, k_mother_sz )

func moveto( theta, radius, z ):
	var transform = Util.get_origin_transform()
	transform = transform.scaled( k_mother_s3 )
	transform = transform.rotated( Vector3(0,0,1), theta )
	transform = transform.translated( Vector3(0, 0, z) )
	transform = transform.translated( Vector3(0, radius, 0) )
	transform = transform.rotated( Vector3(1,0,0), PI/2 )
	set_transform( transform )

util.gd:

const k_origin_transform = Transform( Vector3(1,0,0), \
	Vector3(0,1,0), \
	Vector3(0,0,1), \
	Vector3(0,0,0) )

static func get_origin_transform():
	return k_origin_transform

Depends on what you call “the right place”. When you use scaled and rotated, modifications are done relative to (0,0,0) (notice there is no “origin” expected in their arguments).

A simpler example and a definition of “expected state” versus “obtained state” could be easier to understand.

Note: it’s not documented, but if you want an identity transform you can simply write var transfom = Transform(), no need for a helper :wink:

Zylann | 2016-10-09 02:41