clock works with arbitrary rotations

This commit is contained in:
ericrius1 2016-03-23 11:28:31 -07:00
parent cf9ef1078d
commit 1809c2971e
2 changed files with 38 additions and 28 deletions

View file

@ -85,8 +85,10 @@
var myDate = new Date(); var myDate = new Date();
var seconds = myDate.getSeconds(); var seconds = myDate.getSeconds();
secondRollDegrees = -seconds * DEGREES_FOR_SECOND; secondRollDegrees = -seconds * DEGREES_FOR_SECOND;
var localClockHandRotation = Quat.fromPitchYawRollDegrees(0, 0, secondRollDegrees);
var worldClockHandRotation = Quat.multiply(clockRotation, localClockHandRotation);
Entities.editEntity(_this.secondHand, { Entities.editEntity(_this.secondHand, {
rotation: Quat.fromPitchYawRollDegrees(0, 0, secondRollDegrees) rotation: worldClockHandRotation
}); });
}, },

View file

@ -82,19 +82,27 @@ MyCuckooClock = function(spawnPosition, spawnRotation) {
// ___________ // ___________
var myDate = new Date() var myDate = new Date()
// HOUR HAND *************************
var clockHandForwardOffset = -0.017;
// HOUR HAND *************************
var clockHandForwardOffset = -0.02;
var hourHandPosition = Vec3.sum(clockFacePosition, Vec3.multiply(Quat.getFront(clockRotation), clockHandForwardOffset)); var hourHandPosition = Vec3.sum(clockFacePosition, Vec3.multiply(Quat.getFront(clockRotation), clockHandForwardOffset));
var DEGREES_FOR_HOUR = 30 var DEGREES_FOR_HOUR = 30
var hours = myDate.getHours(); var hours = myDate.getHours();
var hourRollDegrees = -hours * DEGREES_FOR_HOUR; var hourRollDegrees = -hours * DEGREES_FOR_HOUR;
var worldClockRotation = Quat.fromPitchYawRollDegrees var localClockHandRotation = Quat.fromPitchYawRollDegrees(0, 0, hourRollDegrees);
var worldClockHandRotation = Quat.multiply(clockRotation, localClockHandRotation);
var ANGULAR_ROLL_SPEED_HOUR_RADIANS = 0.000029098833;
var localAngularVelocity = {
x: 0,
y: 0,
z: -ANGULAR_ROLL_SPEED_HOUR_RADIANS
};
var worldAngularVelocity = Vec3.multiplyQbyV(clockRotation, localAngularVelocity);
// var ANGULAR_ROLL_SPEED_HOUR_RADIANS = 0.000029098833;
clockHourHand = Entities.addEntity({ clockHourHand = Entities.addEntity({
type: "Model", type: "Model",
visible: false,
name: "hifi-home-model-clockHourHand", name: "hifi-home-model-clockHourHand",
parentID: clockFace, parentID: clockFace,
modelURL: CLOCK_HOUR_HAND_URL, modelURL: CLOCK_HOUR_HAND_URL,
@ -104,13 +112,9 @@ MyCuckooClock = function(spawnPosition, spawnRotation) {
y: 0.05, y: 0.05,
z: 0.5 z: 0.5
}, },
// rotation:hourHandRotation, rotation: worldClockHandRotation,
//angularDamping: 0, angularDamping: 0,
// angularVelocity: { angularVelocity: worldAngularVelocity,
// x: 0,
// y: 0,
// z: -ANGULAR_ROLL_SPEED_HOUR_RADIANS
// },
dimensions: { dimensions: {
x: 0.0263, x: 0.0263,
y: 0.0982, y: 0.0982,
@ -132,10 +136,10 @@ MyCuckooClock = function(spawnPosition, spawnRotation) {
var worldClockHandRotation = Quat.multiply(clockRotation, localClockHandRotation); var worldClockHandRotation = Quat.multiply(clockRotation, localClockHandRotation);
var ANGULAR_ROLL_SPEED_SECOND_RADIANS = 0.10472 var ANGULAR_ROLL_SPEED_SECOND_RADIANS = 0.10472
var localAngularVelocity = { var localAngularVelocity = {
x: 0, x: 0,
y: 0, y: 0,
z: -ANGULAR_ROLL_SPEED_SECOND_RADIANS z: -ANGULAR_ROLL_SPEED_SECOND_RADIANS
}; };
var worldAngularVelocity = Vec3.multiplyQbyV(clockRotation, localAngularVelocity); var worldAngularVelocity = Vec3.multiplyQbyV(clockRotation, localAngularVelocity);
clockSecondHand = Entities.addEntity({ clockSecondHand = Entities.addEntity({
type: "Model", type: "Model",
@ -158,9 +162,9 @@ MyCuckooClock = function(spawnPosition, spawnRotation) {
y: 0.05, y: 0.05,
z: 0.5 z: 0.5
}, },
rotation:worldClockHandRotation, rotation: worldClockHandRotation,
angularDamping: 0, angularDamping: 0,
angularVelocity: worldAngularVelocity , angularVelocity: worldAngularVelocity,
userData: JSON.stringify({ userData: JSON.stringify({
hifiHomeKey: { hifiHomeKey: {
reset: true reset: true
@ -173,33 +177,37 @@ MyCuckooClock = function(spawnPosition, spawnRotation) {
var DEGREES_FOR_MINUTE = 6; var DEGREES_FOR_MINUTE = 6;
var minutes = myDate.getMinutes(); var minutes = myDate.getMinutes();
var minuteRollDegrees = -minutes * DEGREES_FOR_MINUTE; var minuteRollDegrees = -minutes * DEGREES_FOR_MINUTE;
var localClockHandRotation = Quat.fromPitchYawRollDegrees(0, 0, minuteRollDegrees);
var worldClockHandRotation = Quat.multiply(clockRotation, localClockHandRotation);
var ANGULAR_ROLL_SPEED_MINUTE_RADIANS = 0.00174533; var ANGULAR_ROLL_SPEED_MINUTE_RADIANS = 0.00174533;
var localAngularVelocity = {
x: 0,
y: 0,
z: -ANGULAR_ROLL_SPEED_MINUTE_RADIANS
};
var worldAngularVelocity = Vec3.multiplyQbyV(clockRotation, localAngularVelocity);
clockMinuteHand = Entities.addEntity({ clockMinuteHand = Entities.addEntity({
type: "Model", type: "Model",
// visible: false,
modelURL: CLOCK_HOUR_HAND_URL, modelURL: CLOCK_HOUR_HAND_URL,
name: "hifi-home-model-clockMinuteHand", name: "hifi-home-model-clockMinuteHand",
parentID: clockFace, parentID: clockFace,
visible: false,
position: hourHandPosition, position: hourHandPosition,
registrationPoint: { registrationPoint: {
x: 0.5, x: 0.5,
y: 0.05, y: 0.05,
z: 0.5 z: 0.5
}, },
rotation: Quat.fromPitchYawRollDegrees(0, 0, minuteRollDegrees), rotation:worldClockHandRotation,
angularDamping: 0, angularDamping: 0,
angularVelocity: { angularVelocity: worldAngularVelocity,
x: 0,
y: 0,
z: -ANGULAR_ROLL_SPEED_MINUTE_RADIANS
},
dimensions: { dimensions: {
x: 0.0251, x: 0.0251,
y: 0.1179, y: 0.1179,
z: 0.0032 z: 0.0032
}, },
// script: MINUTE_HAND_CLOCK_SCRIPT_URL, script: MINUTE_HAND_CLOCK_SCRIPT_URL,
userData: JSON.stringify({ userData: JSON.stringify({
clockBody: clockBody, clockBody: clockBody,
secondHand: clockSecondHand, secondHand: clockSecondHand,