mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:44:02 +02:00
handControlledHead.js added
This commit is contained in:
parent
726d111827
commit
f40e46957b
1 changed files with 65 additions and 0 deletions
65
examples/example/avatarcontrol/handControlledHead.js
Normal file
65
examples/example/avatarcontrol/handControlledHead.js
Normal file
|
@ -0,0 +1,65 @@
|
|||
// handControlledHead.js
|
||||
|
||||
//This script allows you to look around, driving the rotation of the avatar's head by the right hand orientation.
|
||||
|
||||
const YAW_MULTIPLIER = 20000;
|
||||
const PITCH_MULTIPLIER = 15000;
|
||||
const EPSILON = 0.001;
|
||||
var firstPress = true;
|
||||
var handPreviousVerticalRotation = 0.0;
|
||||
var handCurrentVerticalRotation = 0.0;
|
||||
var handPreviousHorizontalRotation = 0.0;
|
||||
var handCurrentHorizontalRotation = 0.0;
|
||||
var rotatedHandPosition;
|
||||
var rotatedTipPosition;
|
||||
|
||||
function update(deltaTime) {
|
||||
if(Controller.getValue(Controller.Standard.RightPrimaryThumb)){
|
||||
pitchManager(deltaTime);
|
||||
}else if(!firstPress){
|
||||
firstPress = true;
|
||||
}
|
||||
if(firstPress && MyAvatar.headYaw){
|
||||
MyAvatar.headYaw -= MyAvatar.headYaw/10;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function pitchManager(deltaTime){
|
||||
|
||||
rotatedHandPosition = Vec3.multiplyQbyV(Quat.fromPitchYawRollDegrees(0, -MyAvatar.bodyYaw, 0), MyAvatar.getRightHandPosition());
|
||||
rotatedTipPosition = Vec3.multiplyQbyV(Quat.fromPitchYawRollDegrees(0, -MyAvatar.bodyYaw, 0), MyAvatar.getRightHandTipPosition());
|
||||
|
||||
handCurrentVerticalRotation = Vec3.subtract(rotatedTipPosition, rotatedHandPosition).y;
|
||||
handCurrentHorizontalRotation = Vec3.subtract(rotatedTipPosition, rotatedHandPosition).x;
|
||||
|
||||
var handCurrentHorizontalRotationFiltered = handCurrentHorizontalRotation;
|
||||
|
||||
//to avoid yaw drift
|
||||
if((handCurrentHorizontalRotation - handPreviousHorizontalRotation) < EPSILON && (handCurrentHorizontalRotation - handPreviousHorizontalRotation) > -EPSILON){
|
||||
handCurrentHorizontalRotationFiltered = handPreviousHorizontalRotation;
|
||||
}
|
||||
|
||||
if(firstPress){
|
||||
handPreviousVerticalRotation = handCurrentVerticalRotation;
|
||||
handPreviousHorizontalRotation = handCurrentHorizontalRotation;
|
||||
firstPress = false;
|
||||
}
|
||||
|
||||
MyAvatar.headPitch += (handCurrentVerticalRotation - handPreviousVerticalRotation)*PITCH_MULTIPLIER*deltaTime;
|
||||
MyAvatar.headYaw -= (handCurrentHorizontalRotationFiltered - handPreviousHorizontalRotation)*YAW_MULTIPLIER*deltaTime;
|
||||
|
||||
|
||||
handPreviousVerticalRotation = handCurrentVerticalRotation;
|
||||
handPreviousHorizontalRotation = handCurrentHorizontalRotationFiltered;
|
||||
|
||||
|
||||
}
|
||||
|
||||
function clean(){
|
||||
MyAvatar.headYaw = 0.0;
|
||||
}
|
||||
|
||||
|
||||
Script.update.connect(update);
|
||||
Script.scriptEnding.connect(clean);
|
Loading…
Reference in a new issue