public
Created

Rotates the cube in the PlayCanvas demo...

  • Download Gist
PlayCanvas Cube Demo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
pc.script.create("spinner", function (context) {
var Spinner = function (entity) {
// Cache the entity that this script instance affects
this.entity = entity;
};
Spinner.prototype.update = function (dt) {
// Retrieve the transformation matrix of the entity
var transform = this.entity.getLocalTransform();
// Create rotation matrix of 1 degree around the y axis
var angle = Math.PI / 180.0;
var axis = pc.math.vec3.create(0, 1, 0);
var rotate = pc.math.mat4.makeRotate(angle, axis);
// Pre-multiply the rotation against the entity xform
pc.math.mat4.multiply(transform, rotate, transform);
};
return Spinner;
});

After the API update, this now becomes:

pc.script.create("spinner", function (context) {

    var Spinner = function (entity) {
        // Cache the entity that this script instance affects
        this.entity = entity;
    };

    Spinner.prototype.update = function (dt) {
        // Rotate 1 degree around the y axis
        this.entity.rotate(0, 1, 0);
    };

    return Spinner;
});

Much simpler! :)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.