[no bug] matrix4.getScale() just after matrix4.setScale()

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

[no bug] matrix4.getScale() just after matrix4.setScale()

Post by greenya »

Hi!

Bug #1: I've noticed that setting rotation via setRotationDegrees() causes scale to be changed too.
Bug #2: Also the order of what you do fist: set rotation or set scale - does matter.

Next test case shows this problem:

Code: Select all

	core::matrix4 m;
	m.setTranslation(core::vector3df(-5210, -582, -9738));
	m.setRotationDegrees(core::vector3df(124, 352, 8));
	m.setScale(1.1f);
	// NOW: m[0] == m[5] == m[10] == 1.1f
	core::vector3df v = m.getScale();
	// NOW: v == X=1.1173017 Y=1.3730689 Z=1.3796232
Now, all the same, we've only interchanged order of rotation and scale calls:

Code: Select all

	core::matrix4 m;
	m.setTranslation(core::vector3df(-5210, -582, -9738));
	m.setScale(1.1f);
	// NOW: m[0] == m[5] == m[10] == 1.1f
	m.setRotationDegrees(core::vector3df(124, 352, 8));
	// NOW: m[0] == 0.98063082, m[5] == -0.56980854, m[10] == -0.55375081
	core::vector3df v = m.getScale();
	// NOW: v == X=0.99999994 Y=0.99999994 Z=0.99999994 // this is 1.0 (but not 1.1)
P.S.: if i don't set rotation at all, i get back correct scale.
Last edited by greenya on Thu May 26, 2011 7:09 pm, edited 3 times in total.
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post by Radikalizm »

To me this is pretty much expected behavior, those matrix operations are not commutative so the order of executed operations matters
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

To me it seems incorrect at all. To me all 3 attributes of the object (scene node) are completly independent, so if i set position and rotation - scale must not be changed. I do not do projection using projective camera matrix or somthing like that, i just translate, rotate and scale - a simple operations on the object. So to me - matrix is a container for translation, rotation and scale vectors only.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

This is (almost) not possible, at least not efficient. You need to multiply matrices which define rotation and scale. These operations (only in this combination) are commutative, so no problem which order you do. Otherwise we'd need to check for each call, whether rotation or scale is set, and decompose the matrix in case it is. This takes a few hundred cycles each, and would kill all update performance. But it should be documented in the API.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Actually it's correctly done for SceneNodes. As SceneNodes keep internally a vector for scale - so it works for those as you expect. It's just a problem when working with matrices.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

Ah, now i see. If SceneNode keeps dedicated vector for scale then everything is OK. Then this is not a bug ofcause.
Thank you for explanation!
Post Reply