mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 08:04:01 +02:00
Merge remote-tracking branch 'upstream/master' into particles
This commit is contained in:
commit
ea7e16660c
10 changed files with 280 additions and 136 deletions
|
@ -2022,7 +2022,7 @@ void Application::update(float deltaTime) {
|
|||
if (_myAvatar.getMode() == AVATAR_MODE_WALKING) {
|
||||
_handControl.stop();
|
||||
}
|
||||
|
||||
|
||||
// Update from Touch
|
||||
if (_isTouchPressed) {
|
||||
float TOUCH_YAW_SCALE = -50.0f;
|
||||
|
|
|
@ -822,10 +822,13 @@ void Avatar::updateHandMovementAndTouching(float deltaTime, bool enableHandMovem
|
|||
}
|
||||
|
||||
// If there's a leap-interaction hand visible, use that as the endpoint
|
||||
if (getHand().getHandPositions().size() > 0) {
|
||||
_skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position =
|
||||
getHand().leapPositionToWorldPosition(getHand().getHandPositions()[0]);
|
||||
for (size_t i = 0; i < getHand().getPalms().size(); ++i) {
|
||||
PalmData& palm = getHand().getPalms()[i];
|
||||
if (palm.isActive()) {
|
||||
_skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = palm.getPosition();
|
||||
}
|
||||
}
|
||||
|
||||
}//if (_isMine)
|
||||
|
||||
//constrain right arm length and re-adjust elbow position as it bends
|
||||
|
|
|
@ -22,16 +22,11 @@ Hand::Hand(Avatar* owningAvatar) :
|
|||
_renderAlpha(1.0),
|
||||
_lookingInMirror(false),
|
||||
_ballColor(0.0, 0.0, 0.4),
|
||||
_position(0.0, 0.4, 0.0),
|
||||
_orientation(0.0, 0.0, 0.0, 1.0),
|
||||
_particleSystemInitialized(false)
|
||||
{
|
||||
// initialize all finger particle emitters with an invalid id as default
|
||||
for (int f = 0; f< NUM_FINGERS_PER_HAND; f ++ ) {
|
||||
_fingerParticleEmitter[f] = -1;
|
||||
|
||||
//glm::vec4 color(1.0f, 0.6f, 0.0f, 0.5f);
|
||||
//_particleSystem.setEmitterBaseParticle(f, true, 0.012f, color);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,48 +43,55 @@ void Hand::reset() {
|
|||
}
|
||||
|
||||
void Hand::simulate(float deltaTime, bool isMine) {
|
||||
updateFingerParticles(deltaTime);
|
||||
}
|
||||
|
||||
glm::vec3 Hand::leapPositionToWorldPosition(const glm::vec3& leapPosition) {
|
||||
float unitScale = 0.001; // convert mm to meters
|
||||
return _position + _orientation * (leapPosition * unitScale);
|
||||
if (_isRaveGloveActive) {
|
||||
updateFingerParticles(deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
void Hand::calculateGeometry() {
|
||||
glm::vec3 offset(0.2, -0.2, -0.3); // place the hand in front of the face where we can see it
|
||||
|
||||
Head& head = _owningAvatar->getHead();
|
||||
_position = head.getPosition() + head.getOrientation() * offset;
|
||||
_orientation = head.getOrientation();
|
||||
_basePosition = head.getPosition() + head.getOrientation() * offset;
|
||||
_baseOrientation = head.getOrientation();
|
||||
|
||||
int numLeapBalls = _fingerTips.size();
|
||||
_leapBalls.resize(numLeapBalls);
|
||||
|
||||
for (int i = 0; i < _fingerTips.size(); ++i) {
|
||||
_leapBalls[i].rotation = _orientation;
|
||||
_leapBalls[i].position = leapPositionToWorldPosition(_fingerTips[i]);
|
||||
_leapBalls[i].radius = 0.01;
|
||||
_leapBalls[i].touchForce = 0.0;
|
||||
_leapBalls[i].isCollidable = true;
|
||||
_leapBalls.clear();
|
||||
for (size_t i = 0; i < getNumPalms(); ++i) {
|
||||
PalmData& palm = getPalms()[i];
|
||||
if (palm.isActive()) {
|
||||
for (size_t f = 0; f < palm.getNumFingers(); ++f) {
|
||||
FingerData& finger = palm.getFingers()[f];
|
||||
if (finger.isActive()) {
|
||||
const float standardBallRadius = 0.01f;
|
||||
_leapBalls.resize(_leapBalls.size() + 1);
|
||||
HandBall& ball = _leapBalls.back();
|
||||
ball.rotation = _baseOrientation;
|
||||
ball.position = finger.getTipPosition();
|
||||
ball.radius = standardBallRadius;
|
||||
ball.touchForce = 0.0;
|
||||
ball.isCollidable = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Hand::render(bool lookingInMirror) {
|
||||
|
||||
if (_particleSystemInitialized) {
|
||||
_particleSystem.render();
|
||||
}
|
||||
|
||||
|
||||
_renderAlpha = 1.0;
|
||||
_lookingInMirror = lookingInMirror;
|
||||
|
||||
calculateGeometry();
|
||||
|
||||
if (_isRaveGloveActive)
|
||||
if (_isRaveGloveActive) {
|
||||
renderRaveGloveStage();
|
||||
|
||||
if (_particleSystemInitialized) {
|
||||
_particleSystem.render();
|
||||
}
|
||||
}
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_RESCALE_NORMAL);
|
||||
|
||||
|
@ -141,21 +143,29 @@ void Hand::renderHandSpheres() {
|
|||
}
|
||||
|
||||
// Draw the finger root cones
|
||||
if (_fingerTips.size() == _fingerRoots.size()) {
|
||||
for (size_t i = 0; i < _fingerTips.size(); ++i) {
|
||||
glColor4f(_ballColor.r, _ballColor.g, _ballColor.b, 0.5);
|
||||
glm::vec3 tip = leapPositionToWorldPosition(_fingerTips[i]);
|
||||
glm::vec3 root = leapPositionToWorldPosition(_fingerRoots[i]);
|
||||
Avatar::renderJointConnectingCone(root, tip, 0.001, 0.003);
|
||||
for (size_t i = 0; i < getNumPalms(); ++i) {
|
||||
PalmData& palm = getPalms()[i];
|
||||
if (palm.isActive()) {
|
||||
for (size_t f = 0; f < palm.getNumFingers(); ++f) {
|
||||
FingerData& finger = palm.getFingers()[f];
|
||||
if (finger.isActive()) {
|
||||
glColor4f(_ballColor.r, _ballColor.g, _ballColor.b, 0.5);
|
||||
glm::vec3 tip = finger.getTipPosition();
|
||||
glm::vec3 root = finger.getRootPosition();
|
||||
Avatar::renderJointConnectingCone(root, tip, 0.001, 0.003);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw the palms
|
||||
if (_handPositions.size() == _handNormals.size()) {
|
||||
for (size_t i = 0; i < _handPositions.size(); ++i) {
|
||||
for (size_t i = 0; i < getNumPalms(); ++i) {
|
||||
PalmData& palm = getPalms()[i];
|
||||
if (palm.isActive()) {
|
||||
const float palmThickness = 0.002f;
|
||||
glColor4f(_ballColor.r, _ballColor.g, _ballColor.b, 0.25);
|
||||
glm::vec3 tip = leapPositionToWorldPosition(_handPositions[i]);
|
||||
glm::vec3 root = leapPositionToWorldPosition(_handPositions[i] + (_handNormals[i] * 2.0f));
|
||||
glm::vec3 tip = palm.getPosition();
|
||||
glm::vec3 root = palm.getPosition() + palm.getNormal() * palmThickness;
|
||||
Avatar::renderJointConnectingCone(root, tip, 0.05, 0.03);
|
||||
}
|
||||
}
|
||||
|
@ -165,14 +175,39 @@ void Hand::renderHandSpheres() {
|
|||
|
||||
void Hand::setLeapFingers(const std::vector<glm::vec3>& fingerTips,
|
||||
const std::vector<glm::vec3>& fingerRoots) {
|
||||
_fingerTips = fingerTips;
|
||||
_fingerRoots = fingerRoots;
|
||||
// TODO: add id-checking here to increase finger stability
|
||||
|
||||
size_t fingerIndex = 0;
|
||||
for (size_t i = 0; i < getNumPalms(); ++i) {
|
||||
PalmData& palm = getPalms()[i];
|
||||
for (size_t f = 0; f < palm.getNumFingers(); ++f) {
|
||||
FingerData& finger = palm.getFingers()[f];
|
||||
if (fingerIndex < fingerTips.size()) {
|
||||
finger.setActive(true);
|
||||
finger.setRawTipPosition(fingerTips[fingerIndex]);
|
||||
finger.setRawRootPosition(fingerRoots[fingerIndex]);
|
||||
fingerIndex++;
|
||||
}
|
||||
else {
|
||||
finger.setActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Hand::setLeapHands(const std::vector<glm::vec3>& handPositions,
|
||||
const std::vector<glm::vec3>& handNormals) {
|
||||
_handPositions = handPositions;
|
||||
_handNormals = handNormals;
|
||||
for (size_t i = 0; i < getNumPalms(); ++i) {
|
||||
PalmData& palm = getPalms()[i];
|
||||
if (i < handPositions.size()) {
|
||||
palm.setActive(true);
|
||||
palm.setRawPosition(handPositions[i]);
|
||||
palm.setRawNormal(handNormals[i]);
|
||||
}
|
||||
else {
|
||||
palm.setActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -222,33 +257,41 @@ void Hand::updateFingerParticles(float deltaTime) {
|
|||
|
||||
static float t = 0.0f;
|
||||
t += deltaTime;
|
||||
|
||||
for ( int f = 0; f< _fingerTips.size(); f ++ ) {
|
||||
|
||||
if (_fingerParticleEmitter[f] != -1) {
|
||||
|
||||
glm::vec3 particleEmitterPosition = leapPositionToWorldPosition(_fingerTips[f]);
|
||||
|
||||
glm::vec3 fingerDirection = particleEmitterPosition - leapPositionToWorldPosition(_fingerRoots[f]);
|
||||
float fingerLength = glm::length(fingerDirection);
|
||||
|
||||
if (fingerLength > 0.0f) {
|
||||
fingerDirection /= fingerLength;
|
||||
} else {
|
||||
fingerDirection = IDENTITY_UP;
|
||||
int fingerIndex = 0;
|
||||
for (size_t i = 0; i < getNumPalms(); ++i) {
|
||||
PalmData& palm = getPalms()[i];
|
||||
if (palm.isActive()) {
|
||||
for (size_t f = 0; f < palm.getNumFingers(); ++f) {
|
||||
FingerData& finger = palm.getFingers()[f];
|
||||
if (finger.isActive()) {
|
||||
if (_fingerParticleEmitter[fingerIndex] != -1) {
|
||||
|
||||
glm::vec3 particleEmitterPosition = finger.getTipPosition();
|
||||
|
||||
glm::vec3 fingerDirection = particleEmitterPosition - leapPositionToWorldPosition(finger.getRootPosition());
|
||||
float fingerLength = glm::length(fingerDirection);
|
||||
|
||||
if (fingerLength > 0.0f) {
|
||||
fingerDirection /= fingerLength;
|
||||
} else {
|
||||
fingerDirection = IDENTITY_UP;
|
||||
}
|
||||
|
||||
glm::quat particleEmitterRotation = rotationBetween(IDENTITY_UP, fingerDirection);
|
||||
|
||||
_particleSystem.setEmitterPosition(_fingerParticleEmitter[f], particleEmitterPosition);
|
||||
_particleSystem.setEmitterRotation(_fingerParticleEmitter[f], particleEmitterRotation);
|
||||
|
||||
float radius = 0.005f;
|
||||
const glm::vec4 color(1.0f, 0.6f, 0.0f, 0.5f);
|
||||
const glm::vec3 velocity = fingerDirection * 0.002f;
|
||||
const float lifespan = 1.0f;
|
||||
_particleSystem.emitParticlesNow(_fingerParticleEmitter[f], 1, radius, color, velocity, lifespan);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glm::quat particleEmitterRotation = rotationBetween(IDENTITY_UP, fingerDirection);
|
||||
|
||||
_particleSystem.setEmitterPosition(_fingerParticleEmitter[f], particleEmitterPosition);
|
||||
_particleSystem.setEmitterRotation(_fingerParticleEmitter[f], particleEmitterRotation);
|
||||
|
||||
float radius = 0.005f;
|
||||
glm::vec4 color(1.0f, 0.6f, 0.0f, 0.5f);
|
||||
glm::vec3 velocity = fingerDirection * 0.002f;
|
||||
float lifespan = 1.0f;
|
||||
_particleSystem.emitParticlesNow(_fingerParticleEmitter[f], 1, radius, color, velocity, lifespan);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_particleSystem.setUpDirection(glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
#include <SharedUtil.h>
|
||||
#include <vector>
|
||||
|
||||
const int NUM_FINGERS_PER_HAND = 5;
|
||||
|
||||
class Avatar;
|
||||
class ProgramObject;
|
||||
|
||||
|
@ -56,9 +54,6 @@ public:
|
|||
const glm::vec3& getLeapBallPosition (int ball) const { return _leapBalls[ball].position;}
|
||||
bool isRaveGloveActive () const { return _isRaveGloveActive; }
|
||||
|
||||
// position conversion
|
||||
glm::vec3 leapPositionToWorldPosition(const glm::vec3& leapPosition);
|
||||
|
||||
private:
|
||||
// disallow copies of the Hand, copy of owning Avatar is disallowed too
|
||||
Hand(const Hand&);
|
||||
|
@ -71,8 +66,6 @@ private:
|
|||
bool _lookingInMirror;
|
||||
bool _isRaveGloveActive;
|
||||
glm::vec3 _ballColor;
|
||||
glm::vec3 _position;
|
||||
glm::quat _orientation;
|
||||
std::vector<HandBall> _leapBalls;
|
||||
|
||||
bool _particleSystemInitialized;
|
||||
|
|
|
@ -396,7 +396,7 @@ void ParticleSystem::renderEmitter(int e, float size) {
|
|||
glm::vec3 r = _emitter[e].right * size;
|
||||
glm::vec3 u = _emitter[e].up * size;
|
||||
glm::vec3 f = _emitter[e].front * size;
|
||||
|
||||
|
||||
glLineWidth(2.0f);
|
||||
|
||||
glColor3f(0.8f, 0.4, 0.4);
|
||||
|
|
|
@ -86,6 +86,7 @@ private:
|
|||
void updateEmitter(int e, float deltaTime);
|
||||
void updateParticle(int index, float deltaTime);
|
||||
void createParticle(int e, glm::vec3 position, glm::vec3 velocity, float radius, glm::vec4 color, float lifespan);
|
||||
//void runSpecialEffectsTest(int e, float deltaTime); // for debugging and artistic exploration
|
||||
void killParticle(int p);
|
||||
void renderEmitter(int emitterIndex, float size);
|
||||
void renderParticle(int p);
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
static const float fingerVectorRadix = 4; // bits of precision when converting from float<->fixed
|
||||
|
||||
AvatarData::AvatarData(Node* owningNode) :
|
||||
NodeData(owningNode),
|
||||
_handPosition(0,0,0),
|
||||
|
@ -127,36 +129,22 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) {
|
|||
*destinationBuffer++ = bitItems;
|
||||
|
||||
// leap hand data
|
||||
// In order to make the hand data version-robust, hand data packing is just a series of vec3's,
|
||||
// with conventions. If a client doesn't know the conventions, they can just get the vec3's
|
||||
// and render them as balls, or ignore them, without crashing or disrupting anyone.
|
||||
// Current convention:
|
||||
// Zero or more fingetTip positions, followed by the same number of fingerRoot positions
|
||||
|
||||
const std::vector<glm::vec3>& fingerTips = _handData->getFingerTips();
|
||||
const std::vector<glm::vec3>& fingerRoots = _handData->getFingerRoots();
|
||||
size_t numFingerVectors = fingerTips.size() + fingerRoots.size();
|
||||
if (numFingerVectors > 255)
|
||||
numFingerVectors = 0; // safety. We shouldn't ever get over 255, so consider that invalid.
|
||||
std::vector<glm::vec3> fingerVectors;
|
||||
_handData->encodeRemoteData(fingerVectors);
|
||||
|
||||
/////////////////////////////////
|
||||
// Temporarily disable Leap finger sending, as it's causing a crash whenever someone's got a Leap connected
|
||||
numFingerVectors = 0;
|
||||
fingerVectors.clear();
|
||||
/////////////////////////////////
|
||||
|
||||
*destinationBuffer++ = (unsigned char)numFingerVectors;
|
||||
|
||||
if (numFingerVectors > 0) {
|
||||
for (size_t i = 0; i < fingerTips.size(); ++i) {
|
||||
destinationBuffer += packFloatScalarToSignedTwoByteFixed(destinationBuffer, fingerTips[i].x, 4);
|
||||
destinationBuffer += packFloatScalarToSignedTwoByteFixed(destinationBuffer, fingerTips[i].y, 4);
|
||||
destinationBuffer += packFloatScalarToSignedTwoByteFixed(destinationBuffer, fingerTips[i].z, 4);
|
||||
}
|
||||
for (size_t i = 0; i < fingerRoots.size(); ++i) {
|
||||
destinationBuffer += packFloatScalarToSignedTwoByteFixed(destinationBuffer, fingerRoots[i].x, 4);
|
||||
destinationBuffer += packFloatScalarToSignedTwoByteFixed(destinationBuffer, fingerRoots[i].y, 4);
|
||||
destinationBuffer += packFloatScalarToSignedTwoByteFixed(destinationBuffer, fingerRoots[i].z, 4);
|
||||
}
|
||||
if (fingerVectors.size() > 255)
|
||||
fingerVectors.clear(); // safety. We shouldn't ever get over 255, so consider that invalid.
|
||||
|
||||
*destinationBuffer++ = (unsigned char)fingerVectors.size();
|
||||
|
||||
for (size_t i = 0; i < fingerVectors.size(); ++i) {
|
||||
destinationBuffer += packFloatScalarToSignedTwoByteFixed(destinationBuffer, fingerVectors[i].x, fingerVectorRadix);
|
||||
destinationBuffer += packFloatScalarToSignedTwoByteFixed(destinationBuffer, fingerVectors[i].y, fingerVectorRadix);
|
||||
destinationBuffer += packFloatScalarToSignedTwoByteFixed(destinationBuffer, fingerVectors[i].z, fingerVectorRadix);
|
||||
}
|
||||
|
||||
// skeleton joints
|
||||
|
@ -263,25 +251,16 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
|
|||
// leap hand data
|
||||
if (sourceBuffer - startPosition < numBytes) // safety check
|
||||
{
|
||||
std::vector<glm::vec3> fingerTips;
|
||||
std::vector<glm::vec3> fingerRoots;
|
||||
unsigned int numFingerVectors = *sourceBuffer++;
|
||||
unsigned int numFingerTips = numFingerVectors / 2;
|
||||
unsigned int numFingerRoots = numFingerVectors - numFingerTips;
|
||||
fingerTips.resize(numFingerTips);
|
||||
fingerRoots.resize(numFingerRoots);
|
||||
for (size_t i = 0; i < numFingerTips; ++i) {
|
||||
sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerTips[i].x), 4);
|
||||
sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerTips[i].y), 4);
|
||||
sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerTips[i].z), 4);
|
||||
if (numFingerVectors > 0) {
|
||||
std::vector<glm::vec3> fingerVectors(numFingerVectors);
|
||||
for (size_t i = 0; i < numFingerVectors; ++i) {
|
||||
sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerVectors[i].x), fingerVectorRadix);
|
||||
sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerVectors[i].y), fingerVectorRadix);
|
||||
sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerVectors[i].z), fingerVectorRadix);
|
||||
}
|
||||
_handData->decodeRemoteData(fingerVectors);
|
||||
}
|
||||
for (size_t i = 0; i < numFingerRoots; ++i) {
|
||||
sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerRoots[i].x), 4);
|
||||
sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerRoots[i].y), 4);
|
||||
sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerRoots[i].z), 4);
|
||||
}
|
||||
_handData->setFingerTips(fingerTips);
|
||||
_handData->setFingerRoots(fingerRoots);
|
||||
}
|
||||
|
||||
// skeleton joints
|
||||
|
|
|
@ -9,7 +9,74 @@
|
|||
#include "HandData.h"
|
||||
|
||||
HandData::HandData(AvatarData* owningAvatar) :
|
||||
_basePosition(0.0f, 0.0f, 0.0f),
|
||||
_baseOrientation(0.0f, 0.0f, 0.0f, 1.0f),
|
||||
_owningAvatarData(owningAvatar)
|
||||
{
|
||||
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
_palms.push_back(PalmData(this));
|
||||
}
|
||||
}
|
||||
|
||||
PalmData::PalmData(HandData* owningHandData) :
|
||||
_rawPosition(0, 0, 0),
|
||||
_rawNormal(0, 1, 0),
|
||||
_isActive(false),
|
||||
_owningHandData(owningHandData)
|
||||
{
|
||||
for (int i = 0; i < NUM_FINGERS_PER_HAND; ++i) {
|
||||
_fingers.push_back(FingerData(this, owningHandData));
|
||||
}
|
||||
}
|
||||
|
||||
FingerData::FingerData(PalmData* owningPalmData, HandData* owningHandData) :
|
||||
_tipRawPosition(0, 0, 0),
|
||||
_rootRawPosition(0, 0, 0),
|
||||
_isActive(false),
|
||||
_owningPalmData(owningPalmData),
|
||||
_owningHandData(owningHandData)
|
||||
{
|
||||
}
|
||||
|
||||
void HandData::encodeRemoteData(std::vector<glm::vec3>& fingerVectors) {
|
||||
fingerVectors.clear();
|
||||
for (size_t i = 0; i < getNumPalms(); ++i) {
|
||||
PalmData& palm = getPalms()[i];
|
||||
fingerVectors.push_back(palm.getRawPosition());
|
||||
fingerVectors.push_back(palm.getRawNormal());
|
||||
for (size_t f = 0; f < palm.getNumFingers(); ++f) {
|
||||
FingerData& finger = palm.getFingers()[f];
|
||||
if (finger.isActive()) {
|
||||
fingerVectors.push_back(finger.getTipRawPosition());
|
||||
fingerVectors.push_back(finger.getRootRawPosition());
|
||||
}
|
||||
else {
|
||||
fingerVectors.push_back(glm::vec3(0,0,0));
|
||||
fingerVectors.push_back(glm::vec3(0,0,0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HandData::decodeRemoteData(const std::vector<glm::vec3>& fingerVectors) {
|
||||
size_t vectorIndex = 0;
|
||||
for (size_t i = 0; i < getNumPalms(); ++i) {
|
||||
PalmData& palm = getPalms()[i];
|
||||
// If a palm is active, there will be
|
||||
// 1 vector for its position
|
||||
// 1 vector for normal
|
||||
// 10 vectors for fingers (5 tip/root pairs)
|
||||
bool palmActive = fingerVectors.size() >= i * 12;
|
||||
palm.setActive(palmActive);
|
||||
if (palmActive) {
|
||||
palm.setRawPosition(fingerVectors[vectorIndex++]);
|
||||
palm.setRawNormal(fingerVectors[vectorIndex++]);
|
||||
for (size_t f = 0; f < NUM_FINGERS_PER_HAND; ++f) {
|
||||
FingerData& finger = palm.getFingers()[i];
|
||||
finger.setRawTipPosition(fingerVectors[vectorIndex++]);
|
||||
finger.setRawRootPosition(fingerVectors[vectorIndex++]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,8 +13,13 @@
|
|||
#include <vector>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
class AvatarData;
|
||||
class FingerData;
|
||||
class PalmData;
|
||||
|
||||
const int NUM_FINGERS_PER_HAND = 5;
|
||||
|
||||
class HandData {
|
||||
public:
|
||||
|
@ -22,26 +27,79 @@ public:
|
|||
|
||||
// These methods return the positions in Leap-relative space.
|
||||
// To convert to world coordinates, use Hand::leapPositionToWorldPosition.
|
||||
const std::vector<glm::vec3>& getFingerTips() const { return _fingerTips; }
|
||||
const std::vector<glm::vec3>& getFingerRoots() const { return _fingerRoots; }
|
||||
const std::vector<glm::vec3>& getHandPositions() const { return _handPositions; }
|
||||
const std::vector<glm::vec3>& getHandNormals() const { return _handNormals; }
|
||||
void setFingerTips(const std::vector<glm::vec3>& fingerTips) { _fingerTips = fingerTips; }
|
||||
void setFingerRoots(const std::vector<glm::vec3>& fingerRoots) { _fingerRoots = fingerRoots; }
|
||||
void setHandPositions(const std::vector<glm::vec3>& handPositons) { _handPositions = handPositons; }
|
||||
void setHandNormals(const std::vector<glm::vec3>& handNormals) { _handNormals = handNormals; }
|
||||
|
||||
// position conversion
|
||||
glm::vec3 leapPositionToWorldPosition(const glm::vec3& leapPosition) {
|
||||
const float unitScale = 0.001; // convert mm to meters
|
||||
return _basePosition + _baseOrientation * (leapPosition * unitScale);
|
||||
}
|
||||
glm::vec3 leapDirectionToWorldDirection(const glm::vec3& leapDirection) {
|
||||
return glm::normalize(_baseOrientation * leapDirection);
|
||||
}
|
||||
|
||||
std::vector<PalmData>& getPalms() { return _palms; }
|
||||
size_t getNumPalms() { return _palms.size(); }
|
||||
|
||||
// Use these for sending and receiving hand data
|
||||
void encodeRemoteData(std::vector<glm::vec3>& fingerVectors);
|
||||
void decodeRemoteData(const std::vector<glm::vec3>& fingerVectors);
|
||||
|
||||
friend class AvatarData;
|
||||
protected:
|
||||
std::vector<glm::vec3> _fingerTips;
|
||||
std::vector<glm::vec3> _fingerRoots;
|
||||
std::vector<glm::vec3> _handPositions;
|
||||
std::vector<glm::vec3> _handNormals;
|
||||
glm::vec3 _basePosition; // Hands are placed relative to this
|
||||
glm::quat _baseOrientation; // Hands are placed relative to this
|
||||
AvatarData* _owningAvatarData;
|
||||
std::vector<PalmData> _palms;
|
||||
private:
|
||||
// privatize copy ctor and assignment operator so copies of this object cannot be made
|
||||
HandData(const HandData&);
|
||||
HandData& operator= (const HandData&);
|
||||
};
|
||||
|
||||
class FingerData {
|
||||
public:
|
||||
FingerData(PalmData* owningPalmData, HandData* owningHandData);
|
||||
|
||||
glm::vec3 getTipPosition() const { return _owningHandData->leapPositionToWorldPosition(_tipRawPosition); }
|
||||
glm::vec3 getRootPosition() const { return _owningHandData->leapPositionToWorldPosition(_rootRawPosition); }
|
||||
const glm::vec3& getTipRawPosition() const { return _tipRawPosition; }
|
||||
const glm::vec3& getRootRawPosition() const { return _rootRawPosition; }
|
||||
bool isActive() const { return _isActive; }
|
||||
|
||||
void setActive(bool active) { _isActive = active; }
|
||||
void setRawTipPosition(const glm::vec3& pos) { _tipRawPosition = pos; }
|
||||
void setRawRootPosition(const glm::vec3& pos) { _rootRawPosition = pos; }
|
||||
|
||||
private:
|
||||
glm::vec3 _tipRawPosition;
|
||||
glm::vec3 _rootRawPosition;
|
||||
bool _isActive; // This has current valid data
|
||||
PalmData* _owningPalmData;
|
||||
HandData* _owningHandData;
|
||||
};
|
||||
|
||||
class PalmData {
|
||||
public:
|
||||
PalmData(HandData* owningHandData);
|
||||
glm::vec3 getPosition() const { return _owningHandData->leapPositionToWorldPosition(_rawPosition); }
|
||||
glm::vec3 getNormal() const { return _owningHandData->leapDirectionToWorldDirection(_rawNormal); }
|
||||
const glm::vec3& getRawPosition() const { return _rawPosition; }
|
||||
const glm::vec3& getRawNormal() const { return _rawNormal; }
|
||||
bool isActive() const { return _isActive; }
|
||||
|
||||
std::vector<FingerData>& getFingers() { return _fingers; }
|
||||
size_t getNumFingers() { return _fingers.size(); }
|
||||
|
||||
void setActive(bool active) { _isActive = active; }
|
||||
void setRawPosition(const glm::vec3& pos) { _rawPosition = pos; }
|
||||
void setRawNormal(const glm::vec3& normal) { _rawNormal = normal; }
|
||||
|
||||
private:
|
||||
std::vector<FingerData> _fingers;
|
||||
glm::vec3 _rawPosition;
|
||||
glm::vec3 _rawNormal;
|
||||
bool _isActive; // This has current valid data
|
||||
HandData* _owningHandData;
|
||||
};
|
||||
|
||||
#endif /* defined(__hifi__HandData__) */
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
PACKET_VERSION versionForPacketType(PACKET_TYPE type) {
|
||||
switch (type) {
|
||||
case PACKET_TYPE_HEAD_DATA:
|
||||
return 1;
|
||||
return 2;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue