content/hifi-public/cellscience/Scripts/billboard.js
Dale Glass 0d14e5a379 Initial data.
Needs a lot of cleanup. Data has been de-duplicated, and where identical copies existed, one of them
has been replaced with a symlink.

Some files have been excluded, such as binaries, installers and debug dumps. Some of that may still
be present.
2022-02-13 18:59:11 +01:00

58 lines
1.8 KiB
JavaScript

var spriteURL = "http://dynamoidapps.com/HighFidelity/Cosm/Sprites/nucleosomes_sprite.fbx";
var spriteDimensions = {
x: 10,
y: 10,
z: 10
};
var sprite;
var isMouseDown = false;
var RAD_TO_DEG = 180.0 / Math.PI;
var Y_AXIS = { x: 0, y: 1, z: 0 };
var X_AXIS = { x: 1, y: 0, z: 0 };
function MakeSprite () {
sprite = Entities.addEntity({
type: "Model",
name: "sprite",
modelURL: spriteURL,
dimensions: spriteDimensions,
position: Vec3.sum(MyAvatar.position, Quat.getFront(MyAvatar.orientation)),
rotation: Quat.inverse(Quat.getFront(MyAvatar.orientation))
});
}
function UpdateOrientation (event) {
if (isMouseDown && event.isRightButton) {
var direction,
yaw,
pitch,
rot;
direction = Vec3.normalize(Vec3.subtract(MyAvatar.position, Entities.getEntityProperties(sprite).position));
yaw = Quat.angleAxis(Math.atan2(direction.x, direction.z) * RAD_TO_DEG, Y_AXIS);
pitch = Quat.angleAxis(Math.asin(-direction.y) * RAD_TO_DEG, X_AXIS);
rot = Quat.multiply(yaw, pitch);
var avatar = Quat.safeEulerAngles(MyAvatar.orientation);
var printRot = Quat.safeEulerAngles(rot);
print("avatar = (" + avatar.x + ", " + avatar.y + ", " + avatar.z + ")");
print("sprite = (" + printRot.x + ", " + printRot.y + ", " + printRot.z + ")");
Entities.editEntity(sprite, {
rotation: rot
});
}
}
function OnMouseDown(event) {
isMouseDown = true;
}
function OnMouseUp(event) {
isMouseDown = false;
}
MakeSprite();
Controller.mouseMoveEvent.connect(UpdateOrientation);
Controller.mousePressEvent.connect(OnMouseDown);
Controller.mouseReleaseEvent.connect(OnMouseUp);