mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-03 23:13:12 +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");
|
||||
|
||||
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
|
||||
if (MOVE_WITH_HEAD) {
|
||||
var objDistance = Vec3.length(objectToAvatar);
|
||||
|
@ -826,8 +839,21 @@ function MyController(hand) {
|
|||
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, {
|
||||
targetPosition: this.currentObjectPosition,
|
||||
targetPosition: targetPosition,
|
||||
linearTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME,
|
||||
targetRotation: this.currentObjectRotation,
|
||||
angularTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME,
|
||||
|
@ -836,6 +862,34 @@ function MyController(hand) {
|
|||
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() {
|
||||
var now = Date.now();
|
||||
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, this.grabbedEntity, DEFAULT_GRABBABLE_DATA);
|
||||
|
|
|
@ -14,51 +14,64 @@
|
|||
preload: function(entityID) {
|
||||
this.entityID = entityID;
|
||||
var entityProperties = Entities.getEntityProperties(this.entityID, "userData");
|
||||
print('USER DATA:::' + 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() {
|
||||
this.setInitialProperties();
|
||||
},
|
||||
startDistantGrab: function() {
|
||||
// Entities.editEntity(this.entityID, {
|
||||
// parentID: MyAvatar.sessionUUID,
|
||||
// parentJointIndex: MyAvatar.getJointIndex("LeftHand")
|
||||
// });
|
||||
this.setInitialProperties();
|
||||
},
|
||||
setInitialProperties: function() {
|
||||
this.initialProperties = Entities.getEntityProperties(this.entityID);
|
||||
},
|
||||
getClampedPosition: function() {
|
||||
var dPosition;
|
||||
// dPosition = Vec3.subtract(MyAvatar.position, this.previousPosition);
|
||||
//convert to localFrame
|
||||
// dPosition = Vec3.multiplyQbyV(Quat.inverse(MyAvatar.orientation), dPosition);
|
||||
clampPosition: function() {
|
||||
|
||||
var currentProperties = Entities.getEntityProperties(this.entityID);
|
||||
|
||||
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() {
|
||||
var currentPosition = this.getClampedPosition();
|
||||
var distance = Vec3.distance(this.initialProperties.position, currentPosition);
|
||||
// this.clampPosition();
|
||||
print('distant grab')
|
||||
var currentPosition = Entities.getEntityProperties(this.entityID, "position").position;
|
||||
|
||||
if (userData.sliderType === 'color_red' || userData.sliderType === 'color_green' || userData.sliderType === 'color_blue') {
|
||||
this.sliderValue = scaleValueBasedOnDistanceFromStart(distance, COLOR_MAX);
|
||||
var distance = Vec3.distance(this.axisBasePosition, this.currentProjection);
|
||||
|
||||
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') {
|
||||
this.sliderValue = scaleValueBasedOnDistanceFromStart(distance, INTENSITY_MAX);
|
||||
if (this.userData.sliderType === 'intensity') {
|
||||
this.sliderValue = this.scaleValueBasedOnDistanceFromStart(distance, INTENSITY_MAX);
|
||||
}
|
||||
if (userData.sliderType === 'cutoff') {
|
||||
this.sliderValue = scaleValueBasedOnDistanceFromStart(distance, CUTOFF_MAX);
|
||||
if (this.userData.sliderType === 'cutoff') {
|
||||
this.sliderValue = this.scaleValueBasedOnDistanceFromStart(distance, CUTOFF_MAX);
|
||||
}
|
||||
if (userData.sliderType === 'exponent') {
|
||||
this.sliderValue = scaleValueBasedOnDistanceFromStart(distance, EXPONENT_MAX);
|
||||
if (this.userData.sliderType === 'exponent') {
|
||||
this.sliderValue = this.scaleValueBasedOnDistanceFromStart(distance, EXPONENT_MAX);
|
||||
};
|
||||
|
||||
Entities.editEntity(this.entityID, {
|
||||
position: currentPosition,
|
||||
// rotation: this.getClampedRotation()
|
||||
});
|
||||
|
||||
},
|
||||
releaseGrab: function() {
|
||||
Entities.editEntity(this.entityID, {
|
||||
|
@ -66,7 +79,8 @@
|
|||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
}
|
||||
},
|
||||
parentID: null
|
||||
})
|
||||
|
||||
this.sendValueToSlider();
|
||||
|
@ -79,10 +93,11 @@
|
|||
return min2 + (max2 - min2) * ((value - min1) / (max1 - min1));
|
||||
},
|
||||
sendValueToSlider: function() {
|
||||
var _t = this;
|
||||
var message = {
|
||||
lightID: userData.lightID,
|
||||
sliderType: userData.sliderType,
|
||||
sliderValue: this.sliderValue
|
||||
lightID: _t.userData.lightID,
|
||||
sliderType: _t.userData.sliderType,
|
||||
sliderValue: _t.sliderValue
|
||||
}
|
||||
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 = {
|
||||
r: 255,
|
||||
g: 0,
|
||||
b: 0
|
||||
red: 255,
|
||||
green: 0,
|
||||
blue: 0
|
||||
};
|
||||
|
||||
var GREEN = {
|
||||
r: 0,
|
||||
g: 255,
|
||||
b: 0
|
||||
red: 0,
|
||||
green: 255,
|
||||
blue: 0
|
||||
};
|
||||
|
||||
var BLUE = {
|
||||
r: 0,
|
||||
g: 0,
|
||||
b: 255
|
||||
red: 0,
|
||||
green: 0,
|
||||
blue: 255
|
||||
};
|
||||
|
||||
var PURPLE = {
|
||||
r: 255,
|
||||
g: 0,
|
||||
b: 255
|
||||
red: 255,
|
||||
green: 0,
|
||||
blue: 255
|
||||
};
|
||||
|
||||
var WHITE = {
|
||||
r: 255,
|
||||
g: 255,
|
||||
b: 255
|
||||
red: 255,
|
||||
green: 255,
|
||||
blue: 255
|
||||
};
|
||||
|
||||
var AXIS_SCALE = 1;
|
||||
|
@ -44,7 +44,7 @@ var BOX_DIMENSIONS = {
|
|||
};
|
||||
var PER_ROW_OFFSET = {
|
||||
x: 0,
|
||||
y: 0.2,
|
||||
y: -0.2,
|
||||
z: 0
|
||||
};
|
||||
|
||||
|
@ -55,6 +55,7 @@ function entitySlider(light, color, sliderType, row) {
|
|||
this.color = color;
|
||||
this.sliderType = sliderType;
|
||||
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.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 extension = Vec3.multiply(AXIS_SCALE, rightVector);
|
||||
var endOfAxis = Vec3.sum(position, extension);
|
||||
|
||||
var endOfAxis;
|
||||
this.endOfAxis = endOfAxis;
|
||||
print('endOfAxis:::' + JSON.stringify(endOfAxis))
|
||||
var properties = {
|
||||
type: 'Line',
|
||||
name: 'Hifi-Slider-Axis::'+this.sliderType,
|
||||
name: 'Hifi-Slider-Axis::' + this.sliderType,
|
||||
color: this.color,
|
||||
collisionsWillMove: false,
|
||||
ignoreForCollisions: true,
|
||||
|
@ -129,14 +130,14 @@ entitySlider.prototype = {
|
|||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
}, endOfAxis],
|
||||
}, extension],
|
||||
lineWidth: 5,
|
||||
};
|
||||
|
||||
this.axis = Entities.addEntity(properties);
|
||||
},
|
||||
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);
|
||||
|
||||
//line starts on left and goes to right
|
||||
|
@ -162,18 +163,26 @@ entitySlider.prototype = {
|
|||
initialDistance = this.distanceExponent;
|
||||
}
|
||||
var extension = Vec3.multiply(initialDistance, rightVector);
|
||||
var endOfAxis = Vec3.sum(position, extension);
|
||||
var sliderPosition = Vec3.sum(position, extension);
|
||||
var properties = {
|
||||
type: 'Box',
|
||||
name: 'Hifi-Slider::'+this.sliderType,
|
||||
name: 'Hifi-Slider::' + this.sliderType,
|
||||
dimensions: BOX_DIMENSIONS,
|
||||
collisionsWillMove: true,
|
||||
color: this.color,
|
||||
position: endOfAxis,
|
||||
position: sliderPosition,
|
||||
script: BOX_SCRIPT_URL,
|
||||
userData: JSON.stringify({
|
||||
lightModifierKey: {
|
||||
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)));
|
||||
|
||||
var ground = Entities.addEntity({
|
||||
name:'Hifi-Light-Mod-Floor',
|
||||
type: "Model",
|
||||
modelURL: "https://hifi-public.s3.amazonaws.com/eric/models/woodFloor.fbx",
|
||||
dimensions: {
|
||||
|
|
Loading…
Reference in a new issue