Quaternion lerping

Hi,

I’m new to the engine and I’m exploring a little bit the math API. I want to do a simple quaternion lerp but unfortunately I get something wrong when playing, it’s not lerping but rather directly going to the “To” quat. Also I think it’s really strange to call the lerp directly on the transform’s rot because of the redundancy of the from argument. A static function in the Quat class would have been great but I couldn’t find it, maybe I’ve missed something ? I know that Quat.lerp is inlined so it’s more efficient but why not having an override that only takes a “to” quat and the t ?

Here is my code:

class PlayerController extends iron.Trait {

var toRot:Quat;
var start:Bool;

public function new() {
    super();

    notifyOnInit(function() {
        var initEuler = object.transform.rot.getEuler();
        toRot = object.transform.rot.fromEuler(initEuler.x, -100.0, initEuler.z);
    });

    notifyOnUpdate(function() {

        if(Input.getKeyboard().down("space"))
        {
            start = true;
        }

        if(start)
        {
            object.transform.rot = object.transform.rot.lerp(object.transform.rot, toRot, Time.delta * 0.1);
            object.transform.buildMatrix();
        }
    });

    // notifyOnRemove(function() {
    // });
}

}

Thanks !

Hi
this:

toRot = object.transform.rot.fromEuler(initEuler.x, -100.0, initEuler.z);

change to:

toRot = new Quat().fromEuler(initEuler.x, -100.0, initEuler.z);

Full code:

package arm;

import iron.system.Time;
import iron.system.Input;
import iron.math.Quat;

class MyTrait extends iron.Trait {
	var toRot:Quat;
	var start:Bool;

	public function new() {
		super();

		notifyOnInit(function() {
			var initEuler = object.transform.rot.getEuler();
			toRot = new Quat().fromEuler(initEuler.x, -100.0, initEuler.z);
		});

		notifyOnUpdate(function() {
			if (Input.getKeyboard().down("space")) {
				start = true;
			}
			else { start = false; }

			if (start) {
				object.transform.rot.lerp(object.transform.rot, toRot, Time.delta * 0.1);
				object.transform.buildMatrix();
			}
		});
	}
}
1 Like

Thx, it works but I still don’t understand why the previous line doesn’t work.

This method object.transform.rot.fromEuler already turns the object. It turning the object during initialization, before pressing Space.

1 Like

Yes, makes sense, thanks !