mirror of
https://github.com/overte-org/overte.git
synced 2025-07-23 06:07:54 +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) {
|
if (_myAvatar.getMode() == AVATAR_MODE_WALKING) {
|
||||||
_handControl.stop();
|
_handControl.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update from Touch
|
// Update from Touch
|
||||||
if (_isTouchPressed) {
|
if (_isTouchPressed) {
|
||||||
float TOUCH_YAW_SCALE = -50.0f;
|
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 there's a leap-interaction hand visible, use that as the endpoint
|
||||||
if (getHand().getHandPositions().size() > 0) {
|
for (size_t i = 0; i < getHand().getPalms().size(); ++i) {
|
||||||
_skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position =
|
PalmData& palm = getHand().getPalms()[i];
|
||||||
getHand().leapPositionToWorldPosition(getHand().getHandPositions()[0]);
|
if (palm.isActive()) {
|
||||||
|
_skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = palm.getPosition();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}//if (_isMine)
|
}//if (_isMine)
|
||||||
|
|
||||||
//constrain right arm length and re-adjust elbow position as it bends
|
//constrain right arm length and re-adjust elbow position as it bends
|
||||||
|
|
|
@ -22,16 +22,11 @@ Hand::Hand(Avatar* owningAvatar) :
|
||||||
_renderAlpha(1.0),
|
_renderAlpha(1.0),
|
||||||
_lookingInMirror(false),
|
_lookingInMirror(false),
|
||||||
_ballColor(0.0, 0.0, 0.4),
|
_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)
|
_particleSystemInitialized(false)
|
||||||
{
|
{
|
||||||
// initialize all finger particle emitters with an invalid id as default
|
// initialize all finger particle emitters with an invalid id as default
|
||||||
for (int f = 0; f< NUM_FINGERS_PER_HAND; f ++ ) {
|
for (int f = 0; f< NUM_FINGERS_PER_HAND; f ++ ) {
|
||||||
_fingerParticleEmitter[f] = -1;
|
_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) {
|
void Hand::simulate(float deltaTime, bool isMine) {
|
||||||
updateFingerParticles(deltaTime);
|
if (_isRaveGloveActive) {
|
||||||
}
|
updateFingerParticles(deltaTime);
|
||||||
|
}
|
||||||
glm::vec3 Hand::leapPositionToWorldPosition(const glm::vec3& leapPosition) {
|
|
||||||
float unitScale = 0.001; // convert mm to meters
|
|
||||||
return _position + _orientation * (leapPosition * unitScale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hand::calculateGeometry() {
|
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
|
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();
|
Head& head = _owningAvatar->getHead();
|
||||||
_position = head.getPosition() + head.getOrientation() * offset;
|
_basePosition = head.getPosition() + head.getOrientation() * offset;
|
||||||
_orientation = head.getOrientation();
|
_baseOrientation = head.getOrientation();
|
||||||
|
|
||||||
int numLeapBalls = _fingerTips.size();
|
_leapBalls.clear();
|
||||||
_leapBalls.resize(numLeapBalls);
|
for (size_t i = 0; i < getNumPalms(); ++i) {
|
||||||
|
PalmData& palm = getPalms()[i];
|
||||||
for (int i = 0; i < _fingerTips.size(); ++i) {
|
if (palm.isActive()) {
|
||||||
_leapBalls[i].rotation = _orientation;
|
for (size_t f = 0; f < palm.getNumFingers(); ++f) {
|
||||||
_leapBalls[i].position = leapPositionToWorldPosition(_fingerTips[i]);
|
FingerData& finger = palm.getFingers()[f];
|
||||||
_leapBalls[i].radius = 0.01;
|
if (finger.isActive()) {
|
||||||
_leapBalls[i].touchForce = 0.0;
|
const float standardBallRadius = 0.01f;
|
||||||
_leapBalls[i].isCollidable = true;
|
_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) {
|
void Hand::render(bool lookingInMirror) {
|
||||||
|
|
||||||
if (_particleSystemInitialized) {
|
|
||||||
_particleSystem.render();
|
|
||||||
}
|
|
||||||
|
|
||||||
_renderAlpha = 1.0;
|
_renderAlpha = 1.0;
|
||||||
_lookingInMirror = lookingInMirror;
|
_lookingInMirror = lookingInMirror;
|
||||||
|
|
||||||
calculateGeometry();
|
calculateGeometry();
|
||||||
|
|
||||||
if (_isRaveGloveActive)
|
if (_isRaveGloveActive) {
|
||||||
renderRaveGloveStage();
|
renderRaveGloveStage();
|
||||||
|
|
||||||
|
if (_particleSystemInitialized) {
|
||||||
|
_particleSystem.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glEnable(GL_RESCALE_NORMAL);
|
glEnable(GL_RESCALE_NORMAL);
|
||||||
|
|
||||||
|
@ -141,21 +143,29 @@ void Hand::renderHandSpheres() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw the finger root cones
|
// Draw the finger root cones
|
||||||
if (_fingerTips.size() == _fingerRoots.size()) {
|
for (size_t i = 0; i < getNumPalms(); ++i) {
|
||||||
for (size_t i = 0; i < _fingerTips.size(); ++i) {
|
PalmData& palm = getPalms()[i];
|
||||||
glColor4f(_ballColor.r, _ballColor.g, _ballColor.b, 0.5);
|
if (palm.isActive()) {
|
||||||
glm::vec3 tip = leapPositionToWorldPosition(_fingerTips[i]);
|
for (size_t f = 0; f < palm.getNumFingers(); ++f) {
|
||||||
glm::vec3 root = leapPositionToWorldPosition(_fingerRoots[i]);
|
FingerData& finger = palm.getFingers()[f];
|
||||||
Avatar::renderJointConnectingCone(root, tip, 0.001, 0.003);
|
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
|
// Draw the palms
|
||||||
if (_handPositions.size() == _handNormals.size()) {
|
for (size_t i = 0; i < getNumPalms(); ++i) {
|
||||||
for (size_t i = 0; i < _handPositions.size(); ++i) {
|
PalmData& palm = getPalms()[i];
|
||||||
|
if (palm.isActive()) {
|
||||||
|
const float palmThickness = 0.002f;
|
||||||
glColor4f(_ballColor.r, _ballColor.g, _ballColor.b, 0.25);
|
glColor4f(_ballColor.r, _ballColor.g, _ballColor.b, 0.25);
|
||||||
glm::vec3 tip = leapPositionToWorldPosition(_handPositions[i]);
|
glm::vec3 tip = palm.getPosition();
|
||||||
glm::vec3 root = leapPositionToWorldPosition(_handPositions[i] + (_handNormals[i] * 2.0f));
|
glm::vec3 root = palm.getPosition() + palm.getNormal() * palmThickness;
|
||||||
Avatar::renderJointConnectingCone(root, tip, 0.05, 0.03);
|
Avatar::renderJointConnectingCone(root, tip, 0.05, 0.03);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,14 +175,39 @@ void Hand::renderHandSpheres() {
|
||||||
|
|
||||||
void Hand::setLeapFingers(const std::vector<glm::vec3>& fingerTips,
|
void Hand::setLeapFingers(const std::vector<glm::vec3>& fingerTips,
|
||||||
const std::vector<glm::vec3>& fingerRoots) {
|
const std::vector<glm::vec3>& fingerRoots) {
|
||||||
_fingerTips = fingerTips;
|
// TODO: add id-checking here to increase finger stability
|
||||||
_fingerRoots = fingerRoots;
|
|
||||||
|
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,
|
void Hand::setLeapHands(const std::vector<glm::vec3>& handPositions,
|
||||||
const std::vector<glm::vec3>& handNormals) {
|
const std::vector<glm::vec3>& handNormals) {
|
||||||
_handPositions = handPositions;
|
for (size_t i = 0; i < getNumPalms(); ++i) {
|
||||||
_handNormals = handNormals;
|
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;
|
static float t = 0.0f;
|
||||||
t += deltaTime;
|
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) {
|
int fingerIndex = 0;
|
||||||
fingerDirection /= fingerLength;
|
for (size_t i = 0; i < getNumPalms(); ++i) {
|
||||||
} else {
|
PalmData& palm = getPalms()[i];
|
||||||
fingerDirection = IDENTITY_UP;
|
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));
|
_particleSystem.setUpDirection(glm::vec3(0.0f, 1.0f, 0.0f));
|
||||||
|
|
|
@ -19,8 +19,6 @@
|
||||||
#include <SharedUtil.h>
|
#include <SharedUtil.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
const int NUM_FINGERS_PER_HAND = 5;
|
|
||||||
|
|
||||||
class Avatar;
|
class Avatar;
|
||||||
class ProgramObject;
|
class ProgramObject;
|
||||||
|
|
||||||
|
@ -56,9 +54,6 @@ public:
|
||||||
const glm::vec3& getLeapBallPosition (int ball) const { return _leapBalls[ball].position;}
|
const glm::vec3& getLeapBallPosition (int ball) const { return _leapBalls[ball].position;}
|
||||||
bool isRaveGloveActive () const { return _isRaveGloveActive; }
|
bool isRaveGloveActive () const { return _isRaveGloveActive; }
|
||||||
|
|
||||||
// position conversion
|
|
||||||
glm::vec3 leapPositionToWorldPosition(const glm::vec3& leapPosition);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// disallow copies of the Hand, copy of owning Avatar is disallowed too
|
// disallow copies of the Hand, copy of owning Avatar is disallowed too
|
||||||
Hand(const Hand&);
|
Hand(const Hand&);
|
||||||
|
@ -71,8 +66,6 @@ private:
|
||||||
bool _lookingInMirror;
|
bool _lookingInMirror;
|
||||||
bool _isRaveGloveActive;
|
bool _isRaveGloveActive;
|
||||||
glm::vec3 _ballColor;
|
glm::vec3 _ballColor;
|
||||||
glm::vec3 _position;
|
|
||||||
glm::quat _orientation;
|
|
||||||
std::vector<HandBall> _leapBalls;
|
std::vector<HandBall> _leapBalls;
|
||||||
|
|
||||||
bool _particleSystemInitialized;
|
bool _particleSystemInitialized;
|
||||||
|
|
|
@ -396,7 +396,7 @@ void ParticleSystem::renderEmitter(int e, float size) {
|
||||||
glm::vec3 r = _emitter[e].right * size;
|
glm::vec3 r = _emitter[e].right * size;
|
||||||
glm::vec3 u = _emitter[e].up * size;
|
glm::vec3 u = _emitter[e].up * size;
|
||||||
glm::vec3 f = _emitter[e].front * size;
|
glm::vec3 f = _emitter[e].front * size;
|
||||||
|
|
||||||
glLineWidth(2.0f);
|
glLineWidth(2.0f);
|
||||||
|
|
||||||
glColor3f(0.8f, 0.4, 0.4);
|
glColor3f(0.8f, 0.4, 0.4);
|
||||||
|
|
|
@ -86,6 +86,7 @@ private:
|
||||||
void updateEmitter(int e, float deltaTime);
|
void updateEmitter(int e, float deltaTime);
|
||||||
void updateParticle(int index, 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 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 killParticle(int p);
|
||||||
void renderEmitter(int emitterIndex, float size);
|
void renderEmitter(int emitterIndex, float size);
|
||||||
void renderParticle(int p);
|
void renderParticle(int p);
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
static const float fingerVectorRadix = 4; // bits of precision when converting from float<->fixed
|
||||||
|
|
||||||
AvatarData::AvatarData(Node* owningNode) :
|
AvatarData::AvatarData(Node* owningNode) :
|
||||||
NodeData(owningNode),
|
NodeData(owningNode),
|
||||||
_handPosition(0,0,0),
|
_handPosition(0,0,0),
|
||||||
|
@ -127,36 +129,22 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) {
|
||||||
*destinationBuffer++ = bitItems;
|
*destinationBuffer++ = bitItems;
|
||||||
|
|
||||||
// leap hand data
|
// leap hand data
|
||||||
// In order to make the hand data version-robust, hand data packing is just a series of vec3's,
|
std::vector<glm::vec3> fingerVectors;
|
||||||
// with conventions. If a client doesn't know the conventions, they can just get the vec3's
|
_handData->encodeRemoteData(fingerVectors);
|
||||||
// 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.
|
|
||||||
|
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
// Temporarily disable Leap finger sending, as it's causing a crash whenever someone's got a Leap connected
|
// Temporarily disable Leap finger sending, as it's causing a crash whenever someone's got a Leap connected
|
||||||
numFingerVectors = 0;
|
fingerVectors.clear();
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
|
if (fingerVectors.size() > 255)
|
||||||
*destinationBuffer++ = (unsigned char)numFingerVectors;
|
fingerVectors.clear(); // safety. We shouldn't ever get over 255, so consider that invalid.
|
||||||
|
|
||||||
if (numFingerVectors > 0) {
|
*destinationBuffer++ = (unsigned char)fingerVectors.size();
|
||||||
for (size_t i = 0; i < fingerTips.size(); ++i) {
|
|
||||||
destinationBuffer += packFloatScalarToSignedTwoByteFixed(destinationBuffer, fingerTips[i].x, 4);
|
for (size_t i = 0; i < fingerVectors.size(); ++i) {
|
||||||
destinationBuffer += packFloatScalarToSignedTwoByteFixed(destinationBuffer, fingerTips[i].y, 4);
|
destinationBuffer += packFloatScalarToSignedTwoByteFixed(destinationBuffer, fingerVectors[i].x, fingerVectorRadix);
|
||||||
destinationBuffer += packFloatScalarToSignedTwoByteFixed(destinationBuffer, fingerTips[i].z, 4);
|
destinationBuffer += packFloatScalarToSignedTwoByteFixed(destinationBuffer, fingerVectors[i].y, fingerVectorRadix);
|
||||||
}
|
destinationBuffer += packFloatScalarToSignedTwoByteFixed(destinationBuffer, fingerVectors[i].z, fingerVectorRadix);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// skeleton joints
|
// skeleton joints
|
||||||
|
@ -263,25 +251,16 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
|
||||||
// leap hand data
|
// leap hand data
|
||||||
if (sourceBuffer - startPosition < numBytes) // safety check
|
if (sourceBuffer - startPosition < numBytes) // safety check
|
||||||
{
|
{
|
||||||
std::vector<glm::vec3> fingerTips;
|
|
||||||
std::vector<glm::vec3> fingerRoots;
|
|
||||||
unsigned int numFingerVectors = *sourceBuffer++;
|
unsigned int numFingerVectors = *sourceBuffer++;
|
||||||
unsigned int numFingerTips = numFingerVectors / 2;
|
if (numFingerVectors > 0) {
|
||||||
unsigned int numFingerRoots = numFingerVectors - numFingerTips;
|
std::vector<glm::vec3> fingerVectors(numFingerVectors);
|
||||||
fingerTips.resize(numFingerTips);
|
for (size_t i = 0; i < numFingerVectors; ++i) {
|
||||||
fingerRoots.resize(numFingerRoots);
|
sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerVectors[i].x), fingerVectorRadix);
|
||||||
for (size_t i = 0; i < numFingerTips; ++i) {
|
sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerVectors[i].y), fingerVectorRadix);
|
||||||
sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerTips[i].x), 4);
|
sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerVectors[i].z), fingerVectorRadix);
|
||||||
sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerTips[i].y), 4);
|
}
|
||||||
sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerTips[i].z), 4);
|
_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
|
// skeleton joints
|
||||||
|
|
|
@ -9,7 +9,74 @@
|
||||||
#include "HandData.h"
|
#include "HandData.h"
|
||||||
|
|
||||||
HandData::HandData(AvatarData* owningAvatar) :
|
HandData::HandData(AvatarData* owningAvatar) :
|
||||||
|
_basePosition(0.0f, 0.0f, 0.0f),
|
||||||
|
_baseOrientation(0.0f, 0.0f, 0.0f, 1.0f),
|
||||||
_owningAvatarData(owningAvatar)
|
_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 <vector>
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
#include <glm/gtx/quaternion.hpp>
|
||||||
|
|
||||||
class AvatarData;
|
class AvatarData;
|
||||||
|
class FingerData;
|
||||||
|
class PalmData;
|
||||||
|
|
||||||
|
const int NUM_FINGERS_PER_HAND = 5;
|
||||||
|
|
||||||
class HandData {
|
class HandData {
|
||||||
public:
|
public:
|
||||||
|
@ -22,26 +27,79 @@ public:
|
||||||
|
|
||||||
// These methods return the positions in Leap-relative space.
|
// These methods return the positions in Leap-relative space.
|
||||||
// To convert to world coordinates, use Hand::leapPositionToWorldPosition.
|
// 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; }
|
// position conversion
|
||||||
const std::vector<glm::vec3>& getHandPositions() const { return _handPositions; }
|
glm::vec3 leapPositionToWorldPosition(const glm::vec3& leapPosition) {
|
||||||
const std::vector<glm::vec3>& getHandNormals() const { return _handNormals; }
|
const float unitScale = 0.001; // convert mm to meters
|
||||||
void setFingerTips(const std::vector<glm::vec3>& fingerTips) { _fingerTips = fingerTips; }
|
return _basePosition + _baseOrientation * (leapPosition * unitScale);
|
||||||
void setFingerRoots(const std::vector<glm::vec3>& fingerRoots) { _fingerRoots = fingerRoots; }
|
}
|
||||||
void setHandPositions(const std::vector<glm::vec3>& handPositons) { _handPositions = handPositons; }
|
glm::vec3 leapDirectionToWorldDirection(const glm::vec3& leapDirection) {
|
||||||
void setHandNormals(const std::vector<glm::vec3>& handNormals) { _handNormals = handNormals; }
|
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;
|
friend class AvatarData;
|
||||||
protected:
|
protected:
|
||||||
std::vector<glm::vec3> _fingerTips;
|
glm::vec3 _basePosition; // Hands are placed relative to this
|
||||||
std::vector<glm::vec3> _fingerRoots;
|
glm::quat _baseOrientation; // Hands are placed relative to this
|
||||||
std::vector<glm::vec3> _handPositions;
|
|
||||||
std::vector<glm::vec3> _handNormals;
|
|
||||||
AvatarData* _owningAvatarData;
|
AvatarData* _owningAvatarData;
|
||||||
|
std::vector<PalmData> _palms;
|
||||||
private:
|
private:
|
||||||
// privatize copy ctor and assignment operator so copies of this object cannot be made
|
// privatize copy ctor and assignment operator so copies of this object cannot be made
|
||||||
HandData(const HandData&);
|
HandData(const HandData&);
|
||||||
HandData& operator= (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__) */
|
#endif /* defined(__hifi__HandData__) */
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
PACKET_VERSION versionForPacketType(PACKET_TYPE type) {
|
PACKET_VERSION versionForPacketType(PACKET_TYPE type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case PACKET_TYPE_HEAD_DATA:
|
case PACKET_TYPE_HEAD_DATA:
|
||||||
return 1;
|
return 2;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue