Skip to content

Instantly share code, notes, and snippets.

@auz1111
Created July 23, 2012 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save auz1111/3162460 to your computer and use it in GitHub Desktop.
Save auz1111/3162460 to your computer and use it in GitHub Desktop.
Rotates the cube in the PlayCanvas demo...
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;
});
@willeastcott
Copy link

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! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment