mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-29 22:22:54 +02:00
Rave Glove Demo: Restructuring palm and finger data structures
This commit is contained in:
parent
b30131520f
commit
f21d2a477d
4 changed files with 71 additions and 18 deletions
|
@ -21,9 +21,7 @@ Hand::Hand(Avatar* owningAvatar) :
|
||||||
_owningAvatar(owningAvatar),
|
_owningAvatar(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)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,23 +40,18 @@ void Hand::reset() {
|
||||||
void Hand::simulate(float deltaTime, bool isMine) {
|
void Hand::simulate(float deltaTime, bool isMine) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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 handOffset(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() * handOffset;
|
||||||
_orientation = head.getOrientation();
|
_baseOrientation = head.getOrientation();
|
||||||
|
|
||||||
int numLeapBalls = _fingerTips.size();
|
int numLeapBalls = _fingerTips.size();
|
||||||
_leapBalls.resize(numLeapBalls);
|
_leapBalls.resize(numLeapBalls);
|
||||||
|
|
||||||
for (int i = 0; i < _fingerTips.size(); ++i) {
|
for (int i = 0; i < _fingerTips.size(); ++i) {
|
||||||
_leapBalls[i].rotation = _orientation;
|
_leapBalls[i].rotation = _baseOrientation;
|
||||||
_leapBalls[i].position = leapPositionToWorldPosition(_fingerTips[i]);
|
_leapBalls[i].position = leapPositionToWorldPosition(_fingerTips[i]);
|
||||||
_leapBalls[i].radius = 0.01;
|
_leapBalls[i].radius = 0.01;
|
||||||
_leapBalls[i].touchForce = 0.0;
|
_leapBalls[i].touchForce = 0.0;
|
||||||
|
|
|
@ -52,9 +52,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&);
|
||||||
|
@ -65,8 +62,8 @@ private:
|
||||||
bool _lookingInMirror;
|
bool _lookingInMirror;
|
||||||
bool _isRaveGloveActive;
|
bool _isRaveGloveActive;
|
||||||
glm::vec3 _ballColor;
|
glm::vec3 _ballColor;
|
||||||
glm::vec3 _position;
|
// glm::vec3 _position;
|
||||||
glm::quat _orientation;
|
// glm::quat _orientation;
|
||||||
std::vector<HandBall> _leapBalls;
|
std::vector<HandBall> _leapBalls;
|
||||||
|
|
||||||
// private methods
|
// private methods
|
||||||
|
|
|
@ -9,7 +9,29 @@
|
||||||
#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 < 5; ++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)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,11 @@
|
||||||
#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;
|
||||||
|
|
||||||
class HandData {
|
class HandData {
|
||||||
public:
|
public:
|
||||||
|
@ -31,17 +34,55 @@ public:
|
||||||
void setHandPositions(const std::vector<glm::vec3>& handPositons) { _handPositions = handPositons; }
|
void setHandPositions(const std::vector<glm::vec3>& handPositons) { _handPositions = handPositons; }
|
||||||
void setHandNormals(const std::vector<glm::vec3>& handNormals) { _handNormals = handNormals; }
|
void setHandNormals(const std::vector<glm::vec3>& handNormals) { _handNormals = handNormals; }
|
||||||
|
|
||||||
|
// position conversion
|
||||||
|
glm::vec3 leapPositionToWorldPosition(const glm::vec3& leapPosition) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
friend class AvatarData;
|
friend class AvatarData;
|
||||||
protected:
|
protected:
|
||||||
std::vector<glm::vec3> _fingerTips;
|
std::vector<glm::vec3> _fingerTips;
|
||||||
std::vector<glm::vec3> _fingerRoots;
|
std::vector<glm::vec3> _fingerRoots;
|
||||||
std::vector<glm::vec3> _handPositions;
|
std::vector<glm::vec3> _handPositions;
|
||||||
std::vector<glm::vec3> _handNormals;
|
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;
|
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);
|
||||||
|
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; }
|
||||||
|
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__) */
|
||||||
|
|
Loading…
Reference in a new issue