mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:24:00 +02:00
dice don't go away unless 'X' key is clicked, added harmonicOscillator test script
This commit is contained in:
parent
7e7500eaad
commit
5fb79df4c9
2 changed files with 69 additions and 4 deletions
|
@ -13,7 +13,8 @@
|
|||
//
|
||||
|
||||
var isDice = false;
|
||||
var NUMBER_OF_DICE = 2;
|
||||
var NUMBER_OF_DICE = 4;
|
||||
var LIFETIME = 10000; // Dice will live for about 3 hours
|
||||
var dice = [];
|
||||
var DIE_SIZE = 0.20;
|
||||
|
||||
|
@ -50,7 +51,7 @@ var diceButton = Overlays.addOverlay("image", {
|
|||
});
|
||||
|
||||
var GRAVITY = -3.5;
|
||||
var LIFETIME = 300;
|
||||
|
||||
// NOTE: angularVelocity is in radians/sec
|
||||
var MAX_ANGULAR_SPEED = Math.PI;
|
||||
|
||||
|
@ -105,6 +106,7 @@ function mousePressEvent(event) {
|
|||
var clickedText = false;
|
||||
var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y});
|
||||
if (clickedOverlay == offButton) {
|
||||
deleteDice();
|
||||
Script.stop();
|
||||
} else if (clickedOverlay == diceButton) {
|
||||
var HOW_HARD = 2.0;
|
||||
|
@ -116,10 +118,8 @@ function mousePressEvent(event) {
|
|||
}
|
||||
|
||||
function scriptEnding() {
|
||||
deleteDice();
|
||||
Overlays.deleteOverlay(offButton);
|
||||
Overlays.deleteOverlay(diceButton);
|
||||
|
||||
}
|
||||
|
||||
Entities.entityCollisionWithEntity.connect(entityCollisionWithEntity);
|
||||
|
|
65
examples/harmonicOscillator.js
Normal file
65
examples/harmonicOscillator.js
Normal file
|
@ -0,0 +1,65 @@
|
|||
// harmonicOscillator.js
|
||||
//
|
||||
// Created by Philip Rosedale on May 5, 2015
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// An object moves around the edge of a disc while
|
||||
// changing color. The script is continuously updating
|
||||
// position, velocity, rotation, and color. The movement
|
||||
// should appear perfectly smooth to someone else,
|
||||
// provided their network connection is good.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
var ball, disc;
|
||||
var time = 0.0;
|
||||
var range = 1.0;
|
||||
var speed = 0.5;
|
||||
|
||||
|
||||
var basePosition = Vec3.sum(Camera.getPosition(), Quat.getFront(Camera.getOrientation()));
|
||||
|
||||
ball = Entities.addEntity(
|
||||
{ type: "Box",
|
||||
position: basePosition,
|
||||
dimensions: { x: 0.1, y: 0.1, z: 0.1 },
|
||||
color: { red: 255, green: 0, blue: 255 }
|
||||
});
|
||||
|
||||
disc = Entities.addEntity(
|
||||
{ type: "Sphere",
|
||||
position: basePosition,
|
||||
dimensions: { x: range, y: range / 20.0, z: range },
|
||||
color: { red: 128, green: 128, blue: 128 }
|
||||
});
|
||||
|
||||
function update(deltaTime) {
|
||||
time += deltaTime * speed;
|
||||
if (!ball.isKnownID) {
|
||||
ball = Entities.identifyEntity(ball);
|
||||
}
|
||||
rotation = Quat.angleAxis(time/Math.PI * 180.0, { x: 0, y: 1, z: 0 });
|
||||
Entities.editEntity(ball,
|
||||
{
|
||||
color: { red: 255 * (Math.sin(time)/2.0 + 0.5),
|
||||
green: 255 - 255 * (Math.sin(time)/2.0 + 0.5),
|
||||
blue: 0 },
|
||||
position: { x: basePosition.x + Math.sin(time) / 2.0 * range,
|
||||
y: basePosition.y,
|
||||
z: basePosition.z + Math.cos(time) / 2.0 * range },
|
||||
velocity: { x: Math.cos(time)/2.0 * range,
|
||||
y: 0.0,
|
||||
z: -Math.sin(time)/2.0 * range },
|
||||
rotation: rotation
|
||||
});
|
||||
}
|
||||
|
||||
function scriptEnding() {
|
||||
Entities.deleteEntity(ball);
|
||||
Entities.deleteEntity(disc);
|
||||
}
|
||||
|
||||
Script.scriptEnding.connect(scriptEnding);
|
||||
Script.update.connect(update);
|
Loading…
Reference in a new issue