How would I get a unit direction vector from a Quaternion representing an orientation?
1 Like
Try something like:
var Quat = pc.createScript('quat');
// initialize code called once per entity
Quat.prototype.initialize = function() {
this.dir = new pc.Vec3();
this.end = new pc.Vec3();
this.red = new pc.Color(1, 0, 0);
};
// update code called every frame
Quat.prototype.update = function(dt) {
// Rotate 0, 0, 1 to match rotation of entity. Note you could use
// any other axis here...
var q = this.entity.getRotation();
q.transformVector(pc.Vec3.BACK, this.dir);
// Draw the vector
var start = this.entity.getPosition();
this.end.add2(start, this.dir);
this.app.renderLine(start, this.end, this.red);
};
3 Likes
Exactly what I needed. Ended up using pc.Vec3.FORWARD. Thank you.
1 Like