mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 13:30:33 +02:00
end of day
This commit is contained in:
parent
6e8d505726
commit
29de3581dd
3 changed files with 105 additions and 110 deletions
|
@ -38,9 +38,21 @@ var TRIGGER_OFF_VALUE = 0.15;
|
|||
var DISTANCE_HOLDING_RADIUS_FACTOR = 5; // multiplied by distance between hand and object
|
||||
var DISTANCE_HOLDING_ACTION_TIMEFRAME = 0.1; // how quickly objects move to their new position
|
||||
var DISTANCE_HOLDING_ROTATION_EXAGGERATION_FACTOR = 2.0; // object rotates this much more than hand did
|
||||
var NO_INTERSECT_COLOR = { red: 10, green: 10, blue: 255}; // line color when pick misses
|
||||
var INTERSECT_COLOR = { red: 250, green: 10, blue: 10}; // line color when pick hits
|
||||
var LINE_ENTITY_DIMENSIONS = { x: 1000, y: 1000,z: 1000};
|
||||
var NO_INTERSECT_COLOR = {
|
||||
red: 10,
|
||||
green: 10,
|
||||
blue: 255
|
||||
}; // line color when pick misses
|
||||
var INTERSECT_COLOR = {
|
||||
red: 250,
|
||||
green: 10,
|
||||
blue: 10
|
||||
}; // line color when pick hits
|
||||
var LINE_ENTITY_DIMENSIONS = {
|
||||
x: 1000,
|
||||
y: 1000,
|
||||
z: 1000
|
||||
};
|
||||
var LINE_LENGTH = 500;
|
||||
var PICK_MAX_DISTANCE = 500; // max length of pick-ray
|
||||
|
||||
|
@ -100,7 +112,7 @@ var DEFAULT_GRABBABLE_DATA = {
|
|||
invertSolidWhileHeld: false
|
||||
};
|
||||
|
||||
var disabledHand ='none';
|
||||
var disabledHand = 'none';
|
||||
|
||||
function getTag() {
|
||||
return "grab-" + MyAvatar.sessionUUID;
|
||||
|
@ -200,7 +212,7 @@ function MyController(hand, triggerAction) {
|
|||
this.state = newState;
|
||||
}
|
||||
|
||||
this.debugLine = function(closePoint, farPoint, color){
|
||||
this.debugLine = function(closePoint, farPoint, color) {
|
||||
Entities.addEntity({
|
||||
type: "Line",
|
||||
name: "Debug Line",
|
||||
|
@ -301,7 +313,7 @@ function MyController(hand, triggerAction) {
|
|||
this.lastPickTime = now;
|
||||
}
|
||||
|
||||
for (var index=0; index < pickRays.length; ++index) {
|
||||
for (var index = 0; index < pickRays.length; ++index) {
|
||||
var pickRay = pickRays[index];
|
||||
var directionNormalized = Vec3.normalize(pickRay.direction);
|
||||
var directionBacked = Vec3.multiply(directionNormalized, PICK_BACKOFF_DISTANCE);
|
||||
|
@ -376,6 +388,15 @@ function MyController(hand, triggerAction) {
|
|||
for (i = 0; i < nearbyEntities.length; i++) {
|
||||
var grabbableDataForCandidate =
|
||||
getEntityCustomData(GRABBABLE_DATA_KEY, nearbyEntities[i], DEFAULT_GRABBABLE_DATA);
|
||||
if (grabbableDataForCandidate["turnOffOppositeBeam"] === true) {
|
||||
if (this.hand === RIGHT_HAND) {
|
||||
disabledHand = LEFT_HAND;
|
||||
} else {
|
||||
disabledHand = RIGHT_HAND;
|
||||
}
|
||||
} else {
|
||||
disabledHand = 'none';
|
||||
}
|
||||
if (grabbableDataForCandidate.grabbable === false) {
|
||||
continue;
|
||||
}
|
||||
|
@ -405,7 +426,8 @@ function MyController(hand, triggerAction) {
|
|||
var handControllerPosition = Controller.getSpatialControlPosition(this.palm);
|
||||
var handRotation = Quat.multiply(MyAvatar.orientation, Controller.getSpatialControlRawRotation(this.palm));
|
||||
var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, ["position", "rotation",
|
||||
"gravity", "ignoreForCollisions"]);
|
||||
"gravity", "ignoreForCollisions"
|
||||
]);
|
||||
var now = Date.now();
|
||||
|
||||
// add the action and initialize some variables
|
||||
|
@ -460,7 +482,7 @@ function MyController(hand, triggerAction) {
|
|||
|
||||
// the action was set up on a previous call. update the targets.
|
||||
var radius = Math.max(Vec3.distance(this.currentObjectPosition, handControllerPosition) *
|
||||
DISTANCE_HOLDING_RADIUS_FACTOR, DISTANCE_HOLDING_RADIUS_FACTOR);
|
||||
DISTANCE_HOLDING_RADIUS_FACTOR, DISTANCE_HOLDING_RADIUS_FACTOR);
|
||||
// how far did avatar move this timestep?
|
||||
var currentPosition = MyAvatar.position;
|
||||
var avatarDeltaPosition = Vec3.subtract(currentPosition, this.currentAvatarPosition);
|
||||
|
@ -511,9 +533,9 @@ function MyController(hand, triggerAction) {
|
|||
|
||||
// this doubles hand rotation
|
||||
var handChange = Quat.multiply(Quat.slerp(this.handPreviousRotation,
|
||||
handRotation,
|
||||
DISTANCE_HOLDING_ROTATION_EXAGGERATION_FACTOR),
|
||||
Quat.inverse(this.handPreviousRotation));
|
||||
handRotation,
|
||||
DISTANCE_HOLDING_ROTATION_EXAGGERATION_FACTOR),
|
||||
Quat.inverse(this.handPreviousRotation));
|
||||
this.handPreviousRotation = handRotation;
|
||||
this.currentObjectRotation = Quat.multiply(handChange, this.currentObjectRotation);
|
||||
|
||||
|
@ -548,8 +570,7 @@ function MyController(hand, triggerAction) {
|
|||
|
||||
this.lineOff();
|
||||
|
||||
var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity,
|
||||
["position", "rotation", "gravity", "ignoreForCollisions"]);
|
||||
var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, ["position", "rotation", "gravity", "ignoreForCollisions"]);
|
||||
this.activateEntity(this.grabbedEntity, grabbedProperties);
|
||||
|
||||
var handRotation = this.getHandRotation();
|
||||
|
@ -787,7 +808,7 @@ function MyController(hand, triggerAction) {
|
|||
|
||||
this.release = function() {
|
||||
|
||||
if(this.hand !== disabledHand){
|
||||
if (this.hand !== disabledHand) {
|
||||
//release the disabled hand when we let go with the main one
|
||||
disabledHand = 'none';
|
||||
}
|
||||
|
@ -828,9 +849,15 @@ function MyController(hand, triggerAction) {
|
|||
if (data["refCount"] == 1) {
|
||||
data["gravity"] = grabbedProperties.gravity;
|
||||
data["ignoreForCollisions"] = grabbedProperties.ignoreForCollisions;
|
||||
var whileHeldProperties = {gravity: {x:0, y:0, z:0}};
|
||||
var whileHeldProperties = {
|
||||
gravity: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
}
|
||||
};
|
||||
if (invertSolidWhileHeld) {
|
||||
whileHeldProperties["ignoreForCollisions"] = ! grabbedProperties.ignoreForCollisions;
|
||||
whileHeldProperties["ignoreForCollisions"] = !grabbedProperties.ignoreForCollisions;
|
||||
}
|
||||
Entities.editEntity(entityID, whileHeldProperties);
|
||||
}
|
||||
|
@ -870,4 +897,4 @@ function cleanup() {
|
|||
}
|
||||
|
||||
Script.scriptEnding.connect(cleanup);
|
||||
Script.update.connect(update);
|
||||
Script.update.connect(update);
|
|
@ -2,7 +2,7 @@
|
|||
// arrow.js
|
||||
//
|
||||
// This script attaches to an arrow to make it stop and stick when it hits something. Could use this to make it a fire arrow or really give any kind of property to itself or the entity it hits.
|
||||
//
|
||||
//
|
||||
// Created by James B. Pollack @imgntn on 10/19/2015
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
|
@ -20,9 +20,44 @@
|
|||
}
|
||||
|
||||
Arrow.prototype = {
|
||||
glowBox: null,
|
||||
preload: function(entityID) {
|
||||
this.entityID = entityID;
|
||||
if (this.glowBox === null) {
|
||||
this.createGlowBox();
|
||||
Script.update.connect(this.updateGlowBoxPosition);
|
||||
}
|
||||
},
|
||||
unload: function() {
|
||||
Script.update.disconnect(this.updateGlowBoxPosition);
|
||||
Entities.deleteEntity(this.glowBox);
|
||||
},
|
||||
createGlowBox: function() {
|
||||
var glowBowProperties = {
|
||||
name: 'Arrow Glow Box',
|
||||
type: 'Box',
|
||||
dimensions: {
|
||||
x: 0.02,
|
||||
y: 0.02,
|
||||
z: 0.64
|
||||
},
|
||||
color: {
|
||||
red: 255,
|
||||
green: 0,
|
||||
blue: 255
|
||||
},
|
||||
}
|
||||
_this.glowBow = Entities.addEntity(glowBowProperties);
|
||||
},
|
||||
updateGlowBoxPosition: function() {
|
||||
var arrowProperties = Entities.getEntityProperties(_this.entityID, ["position", "rotation"]);
|
||||
//once parenting is available, just attach the glowbow to the arrow
|
||||
Entities.editEntity(_this.entityID, {
|
||||
position: arrowProperties.position,
|
||||
rotation: arrowProperties.rotation
|
||||
})
|
||||
},
|
||||
|
||||
collisionWithEntity: function(me, otherEntity, collision) {
|
||||
|
||||
Vec3.print('penetration = ', collision.penetration);
|
||||
|
|
|
@ -10,6 +10,16 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
// TODO:
|
||||
// make it so you can shoot without blocking your view with your hand
|
||||
// make arrows more visible
|
||||
// make arrow rotate toward ground as it flies
|
||||
// different model? compound bow will look better in the HMD, and be easier to aim. this is what HTC uses in the longbow demo: http://www.turbosquid.com/3d-models/3d-model-bow-arrow/773106
|
||||
// add noise when you release arrow -> add the sound to the arrow and keep it with position so you hear it whizz by
|
||||
// add noise when you draw string
|
||||
// re-enable arrows sticking when they hit
|
||||
// prepare for haptics
|
||||
|
||||
(function() {
|
||||
|
||||
var ZERO_VEC = {
|
||||
|
@ -17,6 +27,7 @@
|
|||
y: 0,
|
||||
z: 0
|
||||
};
|
||||
|
||||
var LINE_ENTITY_DIMENSIONS = {
|
||||
x: 1000,
|
||||
y: 1000,
|
||||
|
@ -27,12 +38,12 @@
|
|||
var ARROW_MODEL_URL = "https://hifi-public.s3.amazonaws.com/models/bow/arrow_good.fbx";
|
||||
var ARROW_COLLISION_HULL_URL = "https://hifi-public.s3.amazonaws.com/models/bow/arrow_good_collision_hull.obj";
|
||||
var ARROW_SCRIPT_URL = Script.resolvePath('arrow.js');
|
||||
var ARROW_OFFSET = 0.25;
|
||||
var ARROW_OFFSET = 0.32;
|
||||
var ARROW_FORCE = 1.25;
|
||||
var ARROW_DIMENSIONS = {
|
||||
x: 0.02,
|
||||
y: 0.02,
|
||||
z: 0.16
|
||||
z: 0.64
|
||||
};
|
||||
|
||||
var ARROW_GRAVITY = {
|
||||
|
@ -54,6 +65,9 @@
|
|||
|
||||
var TARGET_LINE_LENGTH = 1;
|
||||
|
||||
var LEFT_TIP = 1;
|
||||
var RIGHT_TIP = 3;
|
||||
|
||||
var _this;
|
||||
|
||||
function Bow() {
|
||||
|
@ -189,7 +203,7 @@
|
|||
grabbableKey: {
|
||||
turnOffOtherHand: true,
|
||||
turnOffOppositeBeam: true,
|
||||
invertSolidWhileHeld: true,
|
||||
invertSolidWhileHeld: true
|
||||
}
|
||||
})
|
||||
});
|
||||
|
@ -207,12 +221,13 @@
|
|||
this.stringDrawn = false;
|
||||
this.deleteStrings();
|
||||
this.hasArrow = false;
|
||||
Entities.deleteEntity(this.arrow);
|
||||
Entities.editEntity(this.entityID, {
|
||||
userData: JSON.stringify({
|
||||
grabbableKey: {
|
||||
turnOffOtherHand: false,
|
||||
turnOffOppositeBeam: true,
|
||||
invertSolidWhileHeld: true,
|
||||
invertSolidWhileHeld: true
|
||||
}
|
||||
})
|
||||
});
|
||||
|
@ -246,20 +261,21 @@
|
|||
} else if (this.triggerValue >= DRAW_STRING_THRESHOLD && this.stringDrawn === true) {
|
||||
this.stringData.handPosition = this.getStringHandPosition();
|
||||
this.stringData.handRotation = this.getStringHandRotation();
|
||||
this.stringData.grabHandPosition = this.getGrabHandPosition();
|
||||
this.initialHand === 'right' ? this.stringData.grabHandPosition = Controller.getSpatialControlPosition(RIGHT_TIP) : this.stringData.grabHandPosition = Controller.getSpatialControlPosition(LEFT_TIP);
|
||||
// this.stringData.grabHandPosition = this.getGrabHandPosition();
|
||||
this.stringData.grabHandRotation = this.getGrabHandRotation();
|
||||
|
||||
|
||||
this.drawStrings();
|
||||
this.updateArrowPosition();
|
||||
this.createTargetLine();
|
||||
|
||||
} else if (this.triggerValue >= DRAW_STRING_THRESHOLD && this.stringDrawn === false) {
|
||||
this.stringDrawn = true;
|
||||
this.createStrings();
|
||||
this.stringData.handPosition = this.getStringHandPosition();
|
||||
this.stringData.handRotation = this.getStringHandRotation();
|
||||
this.stringData.grabHandPosition = this.getGrabHandPosition();
|
||||
// this.stringData.grabHandPosition = this.getGrabHandPosition();
|
||||
this.initialHand === 'right' ? this.stringData.grabHandPosition = Controller.getSpatialControlPosition(RIGHT_TIP) : this.stringData.grabHandPosition = Controller.getSpatialControlPosition(LEFT_TIP);
|
||||
this.stringData.grabHandRotation = this.getGrabHandRotation();
|
||||
if (this.hasArrow === false) {
|
||||
this.createArrow();
|
||||
|
@ -268,17 +284,15 @@
|
|||
|
||||
this.drawStrings();
|
||||
this.updateArrowPosition();
|
||||
this.createTargetLine();
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
getArrowPosition: function() {
|
||||
|
||||
var arrowVector = Vec3.subtract(this.bowProperties.position, this.stringData.handPosition);
|
||||
var arrowVector = Vec3.subtract(this.stringData.handPosition, this.stringData.grabHandPosition);
|
||||
arrowVector = Vec3.normalize(arrowVector);
|
||||
arrowVector = Vec3.multiply(arrowVector, ARROW_OFFSET);
|
||||
var arrowPosition = Vec3.sum(this.stringData.handPosition, arrowVector);
|
||||
var arrowPosition = Vec3.sum(this.stringData.grabHandPosition, arrowVector);
|
||||
return arrowPosition;
|
||||
},
|
||||
orientationOf: function(vector) {
|
||||
|
@ -373,87 +387,6 @@
|
|||
}, 100)
|
||||
|
||||
},
|
||||
createTargetLine: function() {
|
||||
var handToHand = Vec3.subtract(this.stringData.handPosition, this.stringData.grabHandPosition);
|
||||
|
||||
var arrowRotation = this.orientationOf(handToHand);
|
||||
|
||||
// Entities.addEntity({
|
||||
// type: "Line",
|
||||
// name: "Debug Line",
|
||||
// dimensions: LINE_ENTITY_DIMENSIONS,
|
||||
// visible: true,
|
||||
// rotation: arrowRotation,
|
||||
// position: this.stringData.handPosition,
|
||||
// linePoints: [ZERO_VEC, Vec3.multiply(-TARGET_LINE_LENGTH, handToHand)],
|
||||
// color: {
|
||||
// red: 255,
|
||||
// green: 0,
|
||||
// blue: 255
|
||||
// },
|
||||
// lifetime: 0.1
|
||||
// });
|
||||
|
||||
// Entities.addEntity({
|
||||
// type: "Line",
|
||||
// name: "Debug Line",
|
||||
// dimensions: LINE_ENTITY_DIMENSIONS,
|
||||
// visible: true,
|
||||
// // rotation: bowRotation,
|
||||
// position: this.bowProperties.position,
|
||||
// linePoints: [ZERO_VEC, Vec3.multiply(TARGET_LINE_LENGTH, {
|
||||
// x: 1,
|
||||
// y: 0,
|
||||
// z: 0
|
||||
// })],
|
||||
// color: {
|
||||
// red: 255,
|
||||
// green: 0,
|
||||
// blue: 0
|
||||
// },
|
||||
// lifetime: 0.1
|
||||
// });
|
||||
|
||||
// Entities.addEntity({
|
||||
// type: "Line",
|
||||
// name: "Debug Line",
|
||||
// dimensions: LINE_ENTITY_DIMENSIONS,
|
||||
// visible: true,
|
||||
// // rotation: bowRotation,
|
||||
// position: this.bowProperties.position,
|
||||
// linePoints: [ZERO_VEC, Vec3.multiply(TARGET_LINE_LENGTH, {
|
||||
// x: 0,
|
||||
// y: 1,
|
||||
// z: 0
|
||||
// })],
|
||||
// color: {
|
||||
// red: 0,
|
||||
// green: 255,
|
||||
// blue: 0
|
||||
// },
|
||||
// lifetime: 0.1
|
||||
// });
|
||||
|
||||
// Entities.addEntity({
|
||||
// type: "Line",
|
||||
// name: "Debug Line",
|
||||
// dimensions: LINE_ENTITY_DIMENSIONS,
|
||||
// visible: true,
|
||||
// // rotation:bowRotation,
|
||||
// position: this.bowProperties.position,
|
||||
// linePoints: [ZERO_VEC, Vec3.multiply(TARGET_LINE_LENGTH, {
|
||||
// x: 0,
|
||||
// y: 0,
|
||||
// z: 1
|
||||
// })],
|
||||
// color: {
|
||||
// red: 0,
|
||||
// green: 0,
|
||||
// blue: 255
|
||||
// },
|
||||
// lifetime: 0.1
|
||||
// });
|
||||
},
|
||||
getLocalLineVectors: function() {
|
||||
var topVector = Vec3.subtract(this.stringData.handPosition, this.topStringPosition);
|
||||
var bottomVector = Vec3.subtract(this.stringData.handPosition, this.bottomStringPosition);
|
||||
|
|
Loading…
Reference in a new issue