mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:44:02 +02:00
use palm rotation data in hold action
This commit is contained in:
parent
08d63b7fd8
commit
d197bf2a85
3 changed files with 80 additions and 23 deletions
73
examples/stick-hydra.js
Normal file
73
examples/stick-hydra.js
Normal file
|
@ -0,0 +1,73 @@
|
|||
// stick.js
|
||||
// examples
|
||||
//
|
||||
// Created by Seth Alves on 2015-6-10
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Allow avatar to hold a stick
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
var hand = "left";
|
||||
var nullActionID = "00000000-0000-0000-0000-000000000000";
|
||||
var controllerID;
|
||||
var controllerActive;
|
||||
var stickID = null;
|
||||
var actionID = nullActionID;
|
||||
var makingNewStick = false;
|
||||
|
||||
function makeNewStick() {
|
||||
if (makingNewStick) {
|
||||
return;
|
||||
}
|
||||
makingNewStick = true;
|
||||
cleanUp();
|
||||
// sometimes if this is run immediately the stick doesn't get created? use a timer.
|
||||
Script.setTimeout(function() {
|
||||
stickID = Entities.addEntity({
|
||||
type: "Model",
|
||||
name: "stick",
|
||||
modelURL: "https://hifi-public.s3.amazonaws.com/eric/models/stick.fbx",
|
||||
compoundShapeURL: "https://hifi-public.s3.amazonaws.com/eric/models/stick.obj",
|
||||
dimensions: {x: .11, y: .11, z: 1.0},
|
||||
position: MyAvatar.getRightPalmPosition(), // initial position doesn't matter, as long as it's close
|
||||
rotation: MyAvatar.orientation,
|
||||
damping: .1,
|
||||
collisionSoundURL: "http://public.highfidelity.io/sounds/Collisions-hitsandslaps/67LCollision07.wav",
|
||||
restitution: 0.01,
|
||||
collisionsWillMove: true
|
||||
});
|
||||
actionID = Entities.addAction("hold", stickID,
|
||||
{relativePosition: {x: 0.0, y: 0.0, z: -0.5},
|
||||
relativeRotation: Quat.fromVec3Degrees({x: 0.0, y: 90.0, z: 0.0}),
|
||||
hand: hand,
|
||||
timeScale: 0.15});
|
||||
if (actionID == nullActionID) {
|
||||
cleanUp();
|
||||
}
|
||||
makingNewStick = false;
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
|
||||
function cleanUp() {
|
||||
if (stickID) {
|
||||
Entities.deleteEntity(stickID);
|
||||
stickID = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function initControls(){
|
||||
if (hand == "right") {
|
||||
controllerID = 3; // right handed
|
||||
} else {
|
||||
controllerID = 4; // left handed
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Script.scriptEnding.connect(cleanUp);
|
||||
makeNewStick();
|
|
@ -61,11 +61,9 @@ void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
|
|||
palmRotation = myAvatar->getLeftPalmRotation();
|
||||
}
|
||||
|
||||
auto rotation = myAvatar->getWorldAlignedOrientation();
|
||||
auto rotation = palmRotation * _relativeRotation;
|
||||
auto offset = rotation * _relativePosition;
|
||||
auto position = palmPosition + offset;
|
||||
rotation *= palmRotation;
|
||||
rotation *= _relativeRotation;
|
||||
unlock();
|
||||
|
||||
if (!tryLockForWrite()) {
|
||||
|
|
|
@ -372,16 +372,9 @@ glm::vec3 MyAvatar::getLeftPalmPosition() {
|
|||
}
|
||||
|
||||
glm::quat MyAvatar::getLeftPalmRotation() {
|
||||
unsigned int leftIndex = 0;
|
||||
if (getHand()->getNumPalms() > leftIndex) {
|
||||
PalmData& palm = getHand()->getPalms()[leftIndex];
|
||||
if (palm.isActive()) {
|
||||
glm::vec3 tipDirection = glm::normalize(palm.getTipPosition() - palm.getPosition());
|
||||
glm::vec3 avatarDirection = glm::vec3(0.0f, 0.0f, 1.0f) * getOrientation();
|
||||
return rotationBetween(avatarDirection, tipDirection);
|
||||
}
|
||||
}
|
||||
return glm::quat();
|
||||
glm::quat leftRotation;
|
||||
getSkeletonModel().getJointRotationInWorldFrame(getSkeletonModel().getLeftHandJointIndex(), leftRotation);
|
||||
return leftRotation;
|
||||
}
|
||||
|
||||
glm::vec3 MyAvatar::getRightPalmPosition() {
|
||||
|
@ -394,16 +387,9 @@ glm::vec3 MyAvatar::getRightPalmPosition() {
|
|||
}
|
||||
|
||||
glm::quat MyAvatar::getRightPalmRotation() {
|
||||
unsigned int rightIndex = 1;
|
||||
if (getHand()->getNumPalms() > rightIndex) {
|
||||
PalmData& palm = getHand()->getPalms()[rightIndex];
|
||||
if (palm.isActive()) {
|
||||
glm::vec3 tipDirection = glm::normalize(palm.getTipPosition() - palm.getPosition());
|
||||
glm::vec3 avatarDirection = glm::vec3(0.0f, 0.0f, 1.0f) * getOrientation();
|
||||
return rotationBetween(avatarDirection, tipDirection);
|
||||
}
|
||||
}
|
||||
return glm::quat();
|
||||
glm::quat rightRotation;
|
||||
getSkeletonModel().getJointRotationInWorldFrame(getSkeletonModel().getRightHandJointIndex(), rightRotation);
|
||||
return rightRotation;
|
||||
}
|
||||
|
||||
void MyAvatar::clearReferential() {
|
||||
|
|
Loading…
Reference in a new issue