mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 05:24:35 +02:00
working lsiders
This commit is contained in:
parent
109aa89619
commit
d4f55ed6d2
4 changed files with 135 additions and 56 deletions
|
@ -816,6 +816,19 @@ function MyController(hand) {
|
||||||
|
|
||||||
Entities.callEntityMethod(this.grabbedEntity, "continueDistantGrab");
|
Entities.callEntityMethod(this.grabbedEntity, "continueDistantGrab");
|
||||||
|
|
||||||
|
var defaultConstrainData = {
|
||||||
|
axisBasePosition:false,
|
||||||
|
endOfAxis: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
var constraintData = getEntityCustomData('lightModifierKey', this.grabbedEntity, defaultConstrainData);
|
||||||
|
|
||||||
|
// var constrainX = constraintData.constrain.x;
|
||||||
|
// var constrainY = constraintData.constrain.y;
|
||||||
|
// var constrainZ = constraintData.constrain.z;
|
||||||
|
|
||||||
|
// print('constrainY'+constrainY);
|
||||||
|
|
||||||
// mix in head motion
|
// mix in head motion
|
||||||
if (MOVE_WITH_HEAD) {
|
if (MOVE_WITH_HEAD) {
|
||||||
var objDistance = Vec3.length(objectToAvatar);
|
var objDistance = Vec3.length(objectToAvatar);
|
||||||
|
@ -826,8 +839,21 @@ function MyController(hand) {
|
||||||
this.currentObjectPosition = Vec3.sum(this.currentObjectPosition, change);
|
this.currentObjectPosition = Vec3.sum(this.currentObjectPosition, change);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var clampedVector;
|
||||||
|
var targetPosition;
|
||||||
|
if (constraintData.axisBasePosition !== false) {
|
||||||
|
clampedVector = this.projectVectorAlongAxis(this.currentObjectPosition, constraintData.axisBasePosition, constraintData.endOfAxis);
|
||||||
|
targetPosition = clampedVector;
|
||||||
|
} else {
|
||||||
|
targetPosition = {
|
||||||
|
x: this.currentObjectPosition.x,
|
||||||
|
y: this.currentObjectPosition.y,
|
||||||
|
z: this.currentObjectPosition.z
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Entities.updateAction(this.grabbedEntity, this.actionID, {
|
Entities.updateAction(this.grabbedEntity, this.actionID, {
|
||||||
targetPosition: this.currentObjectPosition,
|
targetPosition: targetPosition,
|
||||||
linearTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME,
|
linearTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME,
|
||||||
targetRotation: this.currentObjectRotation,
|
targetRotation: this.currentObjectRotation,
|
||||||
angularTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME,
|
angularTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME,
|
||||||
|
@ -836,6 +862,34 @@ function MyController(hand) {
|
||||||
this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC);
|
this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.projectVectorAlongAxis = function(position, axisStart, axisEnd) {
|
||||||
|
|
||||||
|
var aPrime = Vec3.subtract(position, axisStart);
|
||||||
|
|
||||||
|
var bPrime = Vec3.subtract(axisEnd, axisStart);
|
||||||
|
|
||||||
|
var bPrimeMagnitude = Vec3.length(bPrime);
|
||||||
|
|
||||||
|
var dotProduct = Vec3.dot(aPrime, bPrime);
|
||||||
|
|
||||||
|
var scalar = dotProduct / bPrimeMagnitude;
|
||||||
|
|
||||||
|
print('SCALAR:::'+scalar);
|
||||||
|
|
||||||
|
if(scalar<0){
|
||||||
|
scalar = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(scalar>1){
|
||||||
|
scalar = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
var projection = Vec3.sum(axisStart, Vec3.multiply(scalar, Vec3.normalize(bPrime)));
|
||||||
|
|
||||||
|
return projection
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
this.nearGrabbing = function() {
|
this.nearGrabbing = function() {
|
||||||
var now = Date.now();
|
var now = Date.now();
|
||||||
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, this.grabbedEntity, DEFAULT_GRABBABLE_DATA);
|
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, this.grabbedEntity, DEFAULT_GRABBABLE_DATA);
|
||||||
|
|
|
@ -14,51 +14,64 @@
|
||||||
preload: function(entityID) {
|
preload: function(entityID) {
|
||||||
this.entityID = entityID;
|
this.entityID = entityID;
|
||||||
var entityProperties = Entities.getEntityProperties(this.entityID, "userData");
|
var entityProperties = Entities.getEntityProperties(this.entityID, "userData");
|
||||||
|
print('USER DATA:::' + entityProperties.userData)
|
||||||
var parsedUserData = JSON.parse(entityProperties.userData);
|
var parsedUserData = JSON.parse(entityProperties.userData);
|
||||||
var userData = parsedUserData.lightModifierKey;
|
this.userData = parsedUserData.lightModifierKey;
|
||||||
|
this.bPrime = Vec3.subtract(this.userData.endOfAxis, this.userData.axisBasePosition);
|
||||||
|
this.bPrimeMagnitude = Vec3.length(this.bPrime);
|
||||||
|
|
||||||
},
|
},
|
||||||
startNearGrab: function() {
|
startNearGrab: function() {
|
||||||
this.setInitialProperties();
|
this.setInitialProperties();
|
||||||
},
|
},
|
||||||
startDistantGrab: function() {
|
startDistantGrab: function() {
|
||||||
|
// Entities.editEntity(this.entityID, {
|
||||||
|
// parentID: MyAvatar.sessionUUID,
|
||||||
|
// parentJointIndex: MyAvatar.getJointIndex("LeftHand")
|
||||||
|
// });
|
||||||
this.setInitialProperties();
|
this.setInitialProperties();
|
||||||
},
|
},
|
||||||
setInitialProperties: function() {
|
setInitialProperties: function() {
|
||||||
this.initialProperties = Entities.getEntityProperties(this.entityID);
|
this.initialProperties = Entities.getEntityProperties(this.entityID);
|
||||||
},
|
},
|
||||||
getClampedPosition: function() {
|
clampPosition: function() {
|
||||||
var dPosition;
|
|
||||||
// dPosition = Vec3.subtract(MyAvatar.position, this.previousPosition);
|
var currentProperties = Entities.getEntityProperties(this.entityID);
|
||||||
//convert to localFrame
|
|
||||||
// dPosition = Vec3.multiplyQbyV(Quat.inverse(MyAvatar.orientation), dPosition);
|
var aPrime = Vec3.subtract(this.userData.axisBasePosition, currentProperties.position);
|
||||||
|
|
||||||
|
var dotProduct = Vec3.dot(aPrime, this.bPrime);
|
||||||
|
|
||||||
|
var scalar = dotProduct / this.bPrimeMagnitude;
|
||||||
|
|
||||||
|
print('SCALAR:::' + scalar);
|
||||||
|
|
||||||
|
var projection = Vec3.sum(this.userData.axisBasePosition, Vec3.multiply(scalar, Vec3.normalize(this.bPrime)));
|
||||||
|
|
||||||
|
this.currentProjection = projection;
|
||||||
|
|
||||||
return dPosition;
|
|
||||||
},
|
|
||||||
getClampedRotation: function() {
|
|
||||||
var rotation = initialProperties.rotation;
|
|
||||||
return rotation;
|
|
||||||
},
|
},
|
||||||
continueDistantGrab: function() {
|
continueDistantGrab: function() {
|
||||||
var currentPosition = this.getClampedPosition();
|
// this.clampPosition();
|
||||||
var distance = Vec3.distance(this.initialProperties.position, currentPosition);
|
print('distant grab')
|
||||||
|
var currentPosition = Entities.getEntityProperties(this.entityID, "position").position;
|
||||||
|
|
||||||
if (userData.sliderType === 'color_red' || userData.sliderType === 'color_green' || userData.sliderType === 'color_blue') {
|
var distance = Vec3.distance(this.axisBasePosition, this.currentProjection);
|
||||||
this.sliderValue = scaleValueBasedOnDistanceFromStart(distance, COLOR_MAX);
|
|
||||||
|
if (this.userData.sliderType === 'color_red' || this.userData.sliderType === 'color_green' || this.userData.sliderType === 'color_blue') {
|
||||||
|
this.sliderValue = this.scaleValueBasedOnDistanceFromStart(distance, COLOR_MAX);
|
||||||
}
|
}
|
||||||
if (userData.sliderType === 'intensity') {
|
if (this.userData.sliderType === 'intensity') {
|
||||||
this.sliderValue = scaleValueBasedOnDistanceFromStart(distance, INTENSITY_MAX);
|
this.sliderValue = this.scaleValueBasedOnDistanceFromStart(distance, INTENSITY_MAX);
|
||||||
}
|
}
|
||||||
if (userData.sliderType === 'cutoff') {
|
if (this.userData.sliderType === 'cutoff') {
|
||||||
this.sliderValue = scaleValueBasedOnDistanceFromStart(distance, CUTOFF_MAX);
|
this.sliderValue = this.scaleValueBasedOnDistanceFromStart(distance, CUTOFF_MAX);
|
||||||
}
|
}
|
||||||
if (userData.sliderType === 'exponent') {
|
if (this.userData.sliderType === 'exponent') {
|
||||||
this.sliderValue = scaleValueBasedOnDistanceFromStart(distance, EXPONENT_MAX);
|
this.sliderValue = this.scaleValueBasedOnDistanceFromStart(distance, EXPONENT_MAX);
|
||||||
};
|
};
|
||||||
|
|
||||||
Entities.editEntity(this.entityID, {
|
|
||||||
position: currentPosition,
|
|
||||||
// rotation: this.getClampedRotation()
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
releaseGrab: function() {
|
releaseGrab: function() {
|
||||||
Entities.editEntity(this.entityID, {
|
Entities.editEntity(this.entityID, {
|
||||||
|
@ -66,7 +79,8 @@
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
z: 0
|
z: 0
|
||||||
}
|
},
|
||||||
|
parentID: null
|
||||||
})
|
})
|
||||||
|
|
||||||
this.sendValueToSlider();
|
this.sendValueToSlider();
|
||||||
|
@ -79,10 +93,11 @@
|
||||||
return min2 + (max2 - min2) * ((value - min1) / (max1 - min1));
|
return min2 + (max2 - min2) * ((value - min1) / (max1 - min1));
|
||||||
},
|
},
|
||||||
sendValueToSlider: function() {
|
sendValueToSlider: function() {
|
||||||
|
var _t = this;
|
||||||
var message = {
|
var message = {
|
||||||
lightID: userData.lightID,
|
lightID: _t.userData.lightID,
|
||||||
sliderType: userData.sliderType,
|
sliderType: _t.userData.sliderType,
|
||||||
sliderValue: this.sliderValue
|
sliderValue: _t.sliderValue
|
||||||
}
|
}
|
||||||
Messages.sendMessage('Hifi-Slider-Value-Reciever', JSON.stringify(message));
|
Messages.sendMessage('Hifi-Slider-Value-Reciever', JSON.stringify(message));
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,36 +3,36 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var BOX_SCRIPT_URL = Script.resolvePath('box.js');
|
var BOX_SCRIPT_URL = Script.resolvePath('box.js?'+Math.random(0,100));
|
||||||
|
|
||||||
var RED = {
|
var RED = {
|
||||||
r: 255,
|
red: 255,
|
||||||
g: 0,
|
green: 0,
|
||||||
b: 0
|
blue: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
var GREEN = {
|
var GREEN = {
|
||||||
r: 0,
|
red: 0,
|
||||||
g: 255,
|
green: 255,
|
||||||
b: 0
|
blue: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
var BLUE = {
|
var BLUE = {
|
||||||
r: 0,
|
red: 0,
|
||||||
g: 0,
|
green: 0,
|
||||||
b: 255
|
blue: 255
|
||||||
};
|
};
|
||||||
|
|
||||||
var PURPLE = {
|
var PURPLE = {
|
||||||
r: 255,
|
red: 255,
|
||||||
g: 0,
|
green: 0,
|
||||||
b: 255
|
blue: 255
|
||||||
};
|
};
|
||||||
|
|
||||||
var WHITE = {
|
var WHITE = {
|
||||||
r: 255,
|
red: 255,
|
||||||
g: 255,
|
green: 255,
|
||||||
b: 255
|
blue: 255
|
||||||
};
|
};
|
||||||
|
|
||||||
var AXIS_SCALE = 1;
|
var AXIS_SCALE = 1;
|
||||||
|
@ -44,7 +44,7 @@ var BOX_DIMENSIONS = {
|
||||||
};
|
};
|
||||||
var PER_ROW_OFFSET = {
|
var PER_ROW_OFFSET = {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0.2,
|
y: -0.2,
|
||||||
z: 0
|
z: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ function entitySlider(light, color, sliderType, row) {
|
||||||
this.color = color;
|
this.color = color;
|
||||||
this.sliderType = sliderType;
|
this.sliderType = sliderType;
|
||||||
this.verticalOffset = Vec3.multiply(row, PER_ROW_OFFSET);
|
this.verticalOffset = Vec3.multiply(row, PER_ROW_OFFSET);
|
||||||
|
print('slider : ' + this.sliderType + "should have an offset of : " + this.verticalOffset);
|
||||||
|
|
||||||
this.avatarRot = Quat.fromPitchYawRollDegrees(0, MyAvatar.bodyYaw, 0.0);
|
this.avatarRot = Quat.fromPitchYawRollDegrees(0, MyAvatar.bodyYaw, 0.0);
|
||||||
this.basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getFront(this.avatarRot)));
|
this.basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getFront(this.avatarRot)));
|
||||||
|
@ -111,11 +112,11 @@ entitySlider.prototype = {
|
||||||
var rightVector = Quat.getRight(this.avatarRot);
|
var rightVector = Quat.getRight(this.avatarRot);
|
||||||
var extension = Vec3.multiply(AXIS_SCALE, rightVector);
|
var extension = Vec3.multiply(AXIS_SCALE, rightVector);
|
||||||
var endOfAxis = Vec3.sum(position, extension);
|
var endOfAxis = Vec3.sum(position, extension);
|
||||||
|
this.endOfAxis = endOfAxis;
|
||||||
var endOfAxis;
|
print('endOfAxis:::' + JSON.stringify(endOfAxis))
|
||||||
var properties = {
|
var properties = {
|
||||||
type: 'Line',
|
type: 'Line',
|
||||||
name: 'Hifi-Slider-Axis::'+this.sliderType,
|
name: 'Hifi-Slider-Axis::' + this.sliderType,
|
||||||
color: this.color,
|
color: this.color,
|
||||||
collisionsWillMove: false,
|
collisionsWillMove: false,
|
||||||
ignoreForCollisions: true,
|
ignoreForCollisions: true,
|
||||||
|
@ -129,14 +130,14 @@ entitySlider.prototype = {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
z: 0
|
z: 0
|
||||||
}, endOfAxis],
|
}, extension],
|
||||||
lineWidth: 5,
|
lineWidth: 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.axis = Entities.addEntity(properties);
|
this.axis = Entities.addEntity(properties);
|
||||||
},
|
},
|
||||||
createBoxIndicator: function() {
|
createBoxIndicator: function() {
|
||||||
print('BOX COLOR IS:::'+JSON.stringify(this.color));
|
print('BOX COLOR IS:::' + JSON.stringify(this.color));
|
||||||
var position = Vec3.sum(this.basePosition, this.verticalOffset);
|
var position = Vec3.sum(this.basePosition, this.verticalOffset);
|
||||||
|
|
||||||
//line starts on left and goes to right
|
//line starts on left and goes to right
|
||||||
|
@ -162,18 +163,26 @@ entitySlider.prototype = {
|
||||||
initialDistance = this.distanceExponent;
|
initialDistance = this.distanceExponent;
|
||||||
}
|
}
|
||||||
var extension = Vec3.multiply(initialDistance, rightVector);
|
var extension = Vec3.multiply(initialDistance, rightVector);
|
||||||
var endOfAxis = Vec3.sum(position, extension);
|
var sliderPosition = Vec3.sum(position, extension);
|
||||||
var properties = {
|
var properties = {
|
||||||
type: 'Box',
|
type: 'Box',
|
||||||
name: 'Hifi-Slider::'+this.sliderType,
|
name: 'Hifi-Slider::' + this.sliderType,
|
||||||
dimensions: BOX_DIMENSIONS,
|
dimensions: BOX_DIMENSIONS,
|
||||||
|
collisionsWillMove: true,
|
||||||
color: this.color,
|
color: this.color,
|
||||||
position: endOfAxis,
|
position: sliderPosition,
|
||||||
script: BOX_SCRIPT_URL,
|
script: BOX_SCRIPT_URL,
|
||||||
userData: JSON.stringify({
|
userData: JSON.stringify({
|
||||||
lightModifierKey: {
|
lightModifierKey: {
|
||||||
lightID: this.lightID,
|
lightID: this.lightID,
|
||||||
sliderType: this.sliderType
|
sliderType: this.sliderType,
|
||||||
|
axisBasePosition: position,
|
||||||
|
endOfAxis: this.endOfAxis,
|
||||||
|
},
|
||||||
|
constraintKey: {
|
||||||
|
constrain: {
|
||||||
|
y: position.y
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(-3, Quat.getUp(avatarRot)));
|
basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(-3, Quat.getUp(avatarRot)));
|
||||||
|
|
||||||
var ground = Entities.addEntity({
|
var ground = Entities.addEntity({
|
||||||
|
name:'Hifi-Light-Mod-Floor',
|
||||||
type: "Model",
|
type: "Model",
|
||||||
modelURL: "https://hifi-public.s3.amazonaws.com/eric/models/woodFloor.fbx",
|
modelURL: "https://hifi-public.s3.amazonaws.com/eric/models/woodFloor.fbx",
|
||||||
dimensions: {
|
dimensions: {
|
||||||
|
|
Loading…
Reference in a new issue