mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 12:37:51 +02:00
fix up grab.js to use line entity
This commit is contained in:
parent
38caed00ca
commit
7a85bfa0d1
2 changed files with 17 additions and 21 deletions
|
@ -61,8 +61,13 @@ function vectorIsZero(v) {
|
||||||
return v.x == 0 && v.y == 0 && v.z == 0;
|
return v.x == 0 && v.y == 0 && v.z == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function vectorToString(v) {
|
function nearLinePoint(targetPosition) {
|
||||||
return "(" + v.x + ", " + v.y + ", " + v.z + ")"
|
// var handPosition = Vec3.sum(MyAvatar.position, {x:0, y:0.2, z:0});
|
||||||
|
var handPosition = MyAvatar.getRightPalmPosition();
|
||||||
|
var along = Vec3.subtract(targetPosition, handPosition);
|
||||||
|
along = Vec3.normalize(along);
|
||||||
|
along = Vec3.multiply(along, 0.4);
|
||||||
|
return Vec3.sum(handPosition, along);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,7 +82,6 @@ function mousePressEvent(event) {
|
||||||
var props = Entities.getEntityProperties(grabbedEntity)
|
var props = Entities.getEntityProperties(grabbedEntity)
|
||||||
isGrabbing = true;
|
isGrabbing = true;
|
||||||
originalGravity = props.gravity;
|
originalGravity = props.gravity;
|
||||||
print("mouse-press setting originalGravity " + originalGravity + " " + vectorToString(originalGravity));
|
|
||||||
targetPosition = props.position;
|
targetPosition = props.position;
|
||||||
currentPosition = props.position;
|
currentPosition = props.position;
|
||||||
currentVelocity = props.velocity;
|
currentVelocity = props.velocity;
|
||||||
|
@ -87,17 +91,14 @@ function mousePressEvent(event) {
|
||||||
gravity: {x: 0, y: 0, z: 0}
|
gravity: {x: 0, y: 0, z: 0}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
lineEntityID = Entities.addEntity({
|
lineEntityID = Entities.addEntity({
|
||||||
type: "Line",
|
type: "Line",
|
||||||
position: MyAvatar.position,
|
position: nearLinePoint(targetPosition),
|
||||||
// dimensions: {x:5, y:5, z:5},
|
dimensions: Vec3.subtract(targetPosition, nearLinePoint(targetPosition)),
|
||||||
dimensions: Vec3.subtract(targetPosition, MyAvatar.position),
|
color: { red: 255, green: 255, blue: 255 },
|
||||||
color: { red: 0, green: 255, blue: 0 }
|
lifetime: 300 // if someone crashes while moving something, don't leave the line there forever.
|
||||||
// lifetime: 10
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
Audio.playSound(grabSound, {
|
Audio.playSound(grabSound, {
|
||||||
position: props.position,
|
position: props.position,
|
||||||
volume: 0.4
|
volume: 0.4
|
||||||
|
@ -133,12 +134,9 @@ function mouseReleaseEvent() {
|
||||||
// 4. interface A releases the entity and puts the original gravity back
|
// 4. interface A releases the entity and puts the original gravity back
|
||||||
// 5. interface B releases the entity and puts the original gravity back (to zero)
|
// 5. interface B releases the entity and puts the original gravity back (to zero)
|
||||||
if (!vectorIsZero(originalGravity)) {
|
if (!vectorIsZero(originalGravity)) {
|
||||||
print("mouse-release restoring originalGravity" + vectorToString(originalGravity));
|
|
||||||
Entities.editEntity(grabbedEntity, {
|
Entities.editEntity(grabbedEntity, {
|
||||||
gravity: originalGravity
|
gravity: originalGravity
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
print("mouse-release not restoring originalGravity of zero");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Overlays.editOverlay(dropLine, {
|
Overlays.editOverlay(dropLine, {
|
||||||
|
@ -162,7 +160,6 @@ function mouseMoveEvent(event) {
|
||||||
var props = Entities.getEntityProperties(grabbedEntity);
|
var props = Entities.getEntityProperties(grabbedEntity);
|
||||||
if (!vectorIsZero(props.gravity)) {
|
if (!vectorIsZero(props.gravity)) {
|
||||||
originalGravity = props.gravity;
|
originalGravity = props.gravity;
|
||||||
print("mouse-move adopting originalGravity" + vectorToString(originalGravity));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
deltaMouse.x = event.x - prevMouse.x;
|
deltaMouse.x = event.x - prevMouse.x;
|
||||||
|
@ -194,6 +191,11 @@ function mouseMoveEvent(event) {
|
||||||
axisAngle = Quat.axis(dQ);
|
axisAngle = Quat.axis(dQ);
|
||||||
angularVelocity = Vec3.multiply((theta / dT), axisAngle);
|
angularVelocity = Vec3.multiply((theta / dT), axisAngle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Entities.editEntity(lineEntityID, {
|
||||||
|
position: nearLinePoint(targetPosition),
|
||||||
|
dimensions: Vec3.subtract(targetPosition, nearLinePoint(targetPosition))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
prevMouse.x = event.x;
|
prevMouse.x = event.x;
|
||||||
prevMouse.y = event.y;
|
prevMouse.y = event.y;
|
||||||
|
|
|
@ -131,12 +131,6 @@ void DeferredLightingEffect::renderWireCube(float size, const glm::vec4& color)
|
||||||
|
|
||||||
void DeferredLightingEffect::renderLine(const glm::vec3& p1, const glm::vec3& p2,
|
void DeferredLightingEffect::renderLine(const glm::vec3& p1, const glm::vec3& p2,
|
||||||
const glm::vec4& color1, const glm::vec4& color2) {
|
const glm::vec4& color1, const glm::vec4& color2) {
|
||||||
|
|
||||||
qDebug() << "LINE -- "
|
|
||||||
<< p1[0] << p1[1] << p1[2]
|
|
||||||
<< ","
|
|
||||||
<< p2[0] << p2[1] << p2[2];
|
|
||||||
|
|
||||||
bindSimpleProgram();
|
bindSimpleProgram();
|
||||||
DependencyManager::get<GeometryCache>()->renderLine(p1, p2, color1, color2);
|
DependencyManager::get<GeometryCache>()->renderLine(p1, p2, color1, color2);
|
||||||
releaseSimpleProgram();
|
releaseSimpleProgram();
|
||||||
|
|
Loading…
Reference in a new issue