mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 12:38:27 +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();
|
palmRotation = myAvatar->getLeftPalmRotation();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto rotation = myAvatar->getWorldAlignedOrientation();
|
auto rotation = palmRotation * _relativeRotation;
|
||||||
auto offset = rotation * _relativePosition;
|
auto offset = rotation * _relativePosition;
|
||||||
auto position = palmPosition + offset;
|
auto position = palmPosition + offset;
|
||||||
rotation *= palmRotation;
|
|
||||||
rotation *= _relativeRotation;
|
|
||||||
unlock();
|
unlock();
|
||||||
|
|
||||||
if (!tryLockForWrite()) {
|
if (!tryLockForWrite()) {
|
||||||
|
|
|
@ -372,16 +372,9 @@ glm::vec3 MyAvatar::getLeftPalmPosition() {
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::quat MyAvatar::getLeftPalmRotation() {
|
glm::quat MyAvatar::getLeftPalmRotation() {
|
||||||
unsigned int leftIndex = 0;
|
glm::quat leftRotation;
|
||||||
if (getHand()->getNumPalms() > leftIndex) {
|
getSkeletonModel().getJointRotationInWorldFrame(getSkeletonModel().getLeftHandJointIndex(), leftRotation);
|
||||||
PalmData& palm = getHand()->getPalms()[leftIndex];
|
return leftRotation;
|
||||||
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::vec3 MyAvatar::getRightPalmPosition() {
|
glm::vec3 MyAvatar::getRightPalmPosition() {
|
||||||
|
@ -394,16 +387,9 @@ glm::vec3 MyAvatar::getRightPalmPosition() {
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::quat MyAvatar::getRightPalmRotation() {
|
glm::quat MyAvatar::getRightPalmRotation() {
|
||||||
unsigned int rightIndex = 1;
|
glm::quat rightRotation;
|
||||||
if (getHand()->getNumPalms() > rightIndex) {
|
getSkeletonModel().getJointRotationInWorldFrame(getSkeletonModel().getRightHandJointIndex(), rightRotation);
|
||||||
PalmData& palm = getHand()->getPalms()[rightIndex];
|
return rightRotation;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyAvatar::clearReferential() {
|
void MyAvatar::clearReferential() {
|
||||||
|
|
Loading…
Reference in a new issue