mirror of
https://github.com/lubosz/overte.git
synced 2025-08-12 18:45:09 +02:00
Merge branch 'master' of https://github.com/highfidelity/hifi into metavoxels
This commit is contained in:
commit
ee084d1afd
3 changed files with 97 additions and 2 deletions
|
@ -21,3 +21,10 @@ Script.update.connect(function(deltaTime) {
|
||||||
MyAvatar.setJointData("joint_L_knee", Quat.fromPitchYawRollDegrees(0.0, 0.0,
|
MyAvatar.setJointData("joint_L_knee", Quat.fromPitchYawRollDegrees(0.0, 0.0,
|
||||||
AMPLITUDE * (1.0 - Math.sin(cumulativeTime * FREQUENCY))));
|
AMPLITUDE * (1.0 - Math.sin(cumulativeTime * FREQUENCY))));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Script.scriptEnding.connect(function() {
|
||||||
|
MyAvatar.clearJointData("joint_R_hip");
|
||||||
|
MyAvatar.clearJointData("joint_L_hip");
|
||||||
|
MyAvatar.clearJointData("joint_R_knee");
|
||||||
|
MyAvatar.clearJointData("joint_L_knee");
|
||||||
|
});
|
||||||
|
|
|
@ -19,11 +19,14 @@ var pitchFromMouse = 0;
|
||||||
var isMouseDown = false;
|
var isMouseDown = false;
|
||||||
|
|
||||||
var BULLET_VELOCITY = 5.0;
|
var BULLET_VELOCITY = 5.0;
|
||||||
|
var LEFT_BUTTON_3 = 3;
|
||||||
|
|
||||||
// Load some sound to use for loading and firing
|
// Load some sound to use for loading and firing
|
||||||
var fireSound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guns/GUN-SHOT2.raw");
|
var fireSound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guns/GUN-SHOT2.raw");
|
||||||
var loadSound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guns/Gun_Reload_Weapon22.raw");
|
var loadSound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guns/Gun_Reload_Weapon22.raw");
|
||||||
var impactSound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guns/BulletImpact2.raw");
|
var impactSound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guns/BulletImpact2.raw");
|
||||||
|
var targetLaunchSound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guns/GUN-SHOT2.raw");
|
||||||
|
|
||||||
var audioOptions = new AudioInjectionOptions();
|
var audioOptions = new AudioInjectionOptions();
|
||||||
audioOptions.volume = 0.9;
|
audioOptions.volume = 0.9;
|
||||||
|
|
||||||
|
@ -34,6 +37,10 @@ for (t = 0; t < numberOfTriggers; t++) {
|
||||||
triggerPulled[t] = false;
|
triggerPulled[t] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isLaunchButtonPressed = false;
|
||||||
|
|
||||||
|
var score = 0;
|
||||||
|
|
||||||
// Create a reticle image in center of screen
|
// Create a reticle image in center of screen
|
||||||
var screenSize = Controller.getViewportDimensions();
|
var screenSize = Controller.getViewportDimensions();
|
||||||
var reticle = Overlays.addOverlay("image", {
|
var reticle = Overlays.addOverlay("image", {
|
||||||
|
@ -46,14 +53,32 @@ var reticle = Overlays.addOverlay("image", {
|
||||||
alpha: 1
|
alpha: 1
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var text = Overlays.addOverlay("text", {
|
||||||
|
x: screenSize.x / 2 - 100,
|
||||||
|
y: screenSize.y / 2 - 50,
|
||||||
|
width: 150,
|
||||||
|
height: 50,
|
||||||
|
color: { red: 0, green: 0, blue: 0},
|
||||||
|
textColor: { red: 255, green: 0, blue: 0},
|
||||||
|
topMargin: 4,
|
||||||
|
leftMargin: 4,
|
||||||
|
text: "Score: " + score
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
function printVector(string, vector) {
|
||||||
|
print(string + " " + vector.x + ", " + vector.y + ", " + vector.z);
|
||||||
|
}
|
||||||
|
|
||||||
function shootBullet(position, velocity) {
|
function shootBullet(position, velocity) {
|
||||||
var BULLET_SIZE = 0.02;
|
var BULLET_SIZE = 0.02;
|
||||||
|
var BULLET_GRAVITY = -0.02;
|
||||||
Particles.addParticle(
|
Particles.addParticle(
|
||||||
{ position: position,
|
{ position: position,
|
||||||
radius: BULLET_SIZE,
|
radius: BULLET_SIZE,
|
||||||
color: { red: 200, green: 0, blue: 0 },
|
color: { red: 200, green: 0, blue: 0 },
|
||||||
velocity: velocity,
|
velocity: velocity,
|
||||||
gravity: { x: 0, y: -0.1, z: 0 },
|
gravity: { x: 0, y: BULLET_GRAVITY, z: 0 },
|
||||||
damping: 0 });
|
damping: 0 });
|
||||||
|
|
||||||
// Play firing sounds
|
// Play firing sounds
|
||||||
|
@ -61,8 +86,41 @@ function shootBullet(position, velocity) {
|
||||||
Audio.playSound(fireSound, audioOptions);
|
Audio.playSound(fireSound, audioOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function shootTarget() {
|
||||||
|
var TARGET_SIZE = 0.25;
|
||||||
|
var TARGET_GRAVITY = -0.6;
|
||||||
|
var TARGET_UP_VELOCITY = 3.0;
|
||||||
|
var TARGET_FWD_VELOCITY = 5.0;
|
||||||
|
var DISTANCE_TO_LAUNCH_FROM = 3.0;
|
||||||
|
var camera = Camera.getPosition();
|
||||||
|
//printVector("camera", camera);
|
||||||
|
var forwardVector = Quat.getFront(Camera.getOrientation());
|
||||||
|
//printVector("forwardVector", forwardVector);
|
||||||
|
var newPosition = Vec3.sum(camera, Vec3.multiply(forwardVector, DISTANCE_TO_LAUNCH_FROM));
|
||||||
|
//printVector("newPosition", newPosition);
|
||||||
|
var velocity = Vec3.multiply(forwardVector, TARGET_FWD_VELOCITY);
|
||||||
|
velocity.y += TARGET_UP_VELOCITY;
|
||||||
|
//printVector("velocity", velocity);
|
||||||
|
|
||||||
|
Particles.addParticle(
|
||||||
|
{ position: newPosition,
|
||||||
|
radius: TARGET_SIZE,
|
||||||
|
color: { red: 0, green: 200, blue: 200 },
|
||||||
|
velocity: velocity,
|
||||||
|
gravity: { x: 0, y: TARGET_GRAVITY, z: 0 },
|
||||||
|
lifetime: 1000.0,
|
||||||
|
damping: 0.99 });
|
||||||
|
|
||||||
|
// Play target shoot sound
|
||||||
|
audioOptions.position = newPosition;
|
||||||
|
Audio.playSound(targetLaunchSound, audioOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function particleCollisionWithVoxel(particle, voxel, penetration) {
|
function particleCollisionWithVoxel(particle, voxel, penetration) {
|
||||||
Vec3.print('particleCollisionWithVoxel() ... penetration=', penetration);
|
Vec3.print('particleCollisionWithVoxel() ... penetration=', penetration);
|
||||||
|
|
||||||
var HOLE_SIZE = 0.125;
|
var HOLE_SIZE = 0.125;
|
||||||
var particleProperties = Particles.getParticleProperties(particle);
|
var particleProperties = Particles.getParticleProperties(particle);
|
||||||
var position = particleProperties.position;
|
var position = particleProperties.position;
|
||||||
|
@ -74,8 +132,24 @@ function particleCollisionWithVoxel(particle, voxel, penetration) {
|
||||||
Audio.playSound(impactSound, audioOptions);
|
Audio.playSound(impactSound, audioOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function particleCollisionWithParticle(particle1, particle2) {
|
||||||
|
print("Particle/Particle!");
|
||||||
|
score++;
|
||||||
|
Overlays.editOverlay(text, { text: "Score: " + score } );
|
||||||
|
Particles.deleteParticle(particle1);
|
||||||
|
Particles.deleteParticle(particle2);
|
||||||
|
}
|
||||||
|
|
||||||
|
function keyPressEvent(event) {
|
||||||
|
// if our tools are off, then don't do anything
|
||||||
|
if (event.text == "t") {
|
||||||
|
shootTarget();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function update(deltaTime) {
|
function update(deltaTime) {
|
||||||
|
|
||||||
|
|
||||||
// Check for mouseLook movement, update rotation
|
// Check for mouseLook movement, update rotation
|
||||||
// rotate body yaw for yaw received from mouse
|
// rotate body yaw for yaw received from mouse
|
||||||
var newOrientation = Quat.multiply(MyAvatar.orientation, Quat.fromVec3Radians( { x: 0, y: yawFromMouse, z: 0 } ));
|
var newOrientation = Quat.multiply(MyAvatar.orientation, Quat.fromVec3Radians( { x: 0, y: yawFromMouse, z: 0 } ));
|
||||||
|
@ -87,6 +161,15 @@ function update(deltaTime) {
|
||||||
MyAvatar.headPitch = newPitch;
|
MyAvatar.headPitch = newPitch;
|
||||||
pitchFromMouse = 0;
|
pitchFromMouse = 0;
|
||||||
|
|
||||||
|
// Check hydra controller for launch button press
|
||||||
|
if (!isLaunchButtonPressed && Controller.isButtonPressed(LEFT_BUTTON_3)) {
|
||||||
|
isLaunchButtonPressed = true;
|
||||||
|
shootTarget();
|
||||||
|
} else if (isLaunchButtonPressed && !Controller.isButtonPressed(LEFT_BUTTON_3)) {
|
||||||
|
isLaunchButtonPressed = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Check hydra controller for trigger press
|
// Check hydra controller for trigger press
|
||||||
|
|
||||||
var numberOfTriggers = Controller.getNumberOfTriggers();
|
var numberOfTriggers = Controller.getNumberOfTriggers();
|
||||||
|
@ -175,14 +258,17 @@ function mouseMoveEvent(event) {
|
||||||
|
|
||||||
function scriptEnding() {
|
function scriptEnding() {
|
||||||
Overlays.deleteOverlay(reticle);
|
Overlays.deleteOverlay(reticle);
|
||||||
|
Overlays.deleteOverlay(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
Particles.particleCollisionWithVoxel.connect(particleCollisionWithVoxel);
|
Particles.particleCollisionWithVoxel.connect(particleCollisionWithVoxel);
|
||||||
|
Particles.particleCollisionWithParticle.connect(particleCollisionWithParticle);
|
||||||
Script.scriptEnding.connect(scriptEnding);
|
Script.scriptEnding.connect(scriptEnding);
|
||||||
Script.update.connect(update);
|
Script.update.connect(update);
|
||||||
Controller.mousePressEvent.connect(mousePressEvent);
|
Controller.mousePressEvent.connect(mousePressEvent);
|
||||||
Controller.mouseReleaseEvent.connect(mouseReleaseEvent);
|
Controller.mouseReleaseEvent.connect(mouseReleaseEvent);
|
||||||
Controller.mouseMoveEvent.connect(mouseMoveEvent);
|
Controller.mouseMoveEvent.connect(mouseMoveEvent);
|
||||||
|
Controller.keyPressEvent.connect(keyPressEvent);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,9 +13,11 @@
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
|
||||||
|
const int MSECS_PER_FRAME_WHEN_THROTTLED = 66;
|
||||||
|
|
||||||
GLCanvas::GLCanvas() : QGLWidget(QGLFormat(QGL::NoDepthBuffer)),
|
GLCanvas::GLCanvas() : QGLWidget(QGLFormat(QGL::NoDepthBuffer)),
|
||||||
_throttleRendering(false),
|
_throttleRendering(false),
|
||||||
_idleRenderInterval(64)
|
_idleRenderInterval(MSECS_PER_FRAME_WHEN_THROTTLED)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue