mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 17:14:59 +02:00
First-pass finger motion trails
This commit is contained in:
parent
7ceb549416
commit
cb6f542b9f
4 changed files with 108 additions and 0 deletions
|
@ -95,6 +95,7 @@ void Hand::render(bool lookingInMirror) {
|
|||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_RESCALE_NORMAL);
|
||||
|
||||
renderFingerTrails();
|
||||
renderHandSpheres();
|
||||
}
|
||||
|
||||
|
@ -173,6 +174,35 @@ void Hand::renderHandSpheres() {
|
|||
glPopMatrix();
|
||||
}
|
||||
|
||||
void Hand::renderFingerTrails() {
|
||||
// Draw the finger root cones
|
||||
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];
|
||||
int numPositions = finger.getTrailNumPositions();
|
||||
if (numPositions > 0) {
|
||||
glBegin(GL_TRIANGLE_STRIP);
|
||||
for (int t = 0; t < numPositions; ++t)
|
||||
{
|
||||
const glm::vec3& center = finger.getTrailPosition(t);
|
||||
const float halfWidth = 0.001f;
|
||||
const glm::vec3 edgeDirection(1.0f, 0.0f, 0.0f);
|
||||
glm::vec3 edge0 = center + edgeDirection * halfWidth;
|
||||
glm::vec3 edge1 = center - edgeDirection * halfWidth;
|
||||
float alpha = 1.0f - ((float)t / (float)(numPositions - 1));
|
||||
glColor4f(1.0f, 0.0f, 0.0f, alpha);
|
||||
glVertex3fv((float*)&edge0);
|
||||
glVertex3fv((float*)&edge1);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Hand::setLeapFingers(const std::vector<glm::vec3>& fingerTips,
|
||||
const std::vector<glm::vec3>& fingerRoots) {
|
||||
// TODO: add id-checking here to increase finger stability
|
||||
|
@ -193,6 +223,7 @@ void Hand::setLeapFingers(const std::vector<glm::vec3>& fingerTips,
|
|||
}
|
||||
}
|
||||
}
|
||||
updateFingerTrails();
|
||||
}
|
||||
|
||||
void Hand::setLeapHands(const std::vector<glm::vec3>& handPositions,
|
||||
|
|
|
@ -74,6 +74,7 @@ private:
|
|||
// private methods
|
||||
void renderRaveGloveStage();
|
||||
void renderHandSpheres();
|
||||
void renderFingerTrails();
|
||||
void calculateGeometry();
|
||||
};
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@ HandData::HandData(AvatarData* owningAvatar) :
|
|||
for (int i = 0; i < 2; ++i) {
|
||||
_palms.push_back(PalmData(this));
|
||||
}
|
||||
const int standardTrailLength = 30;
|
||||
setFingerTrailLength(standardTrailLength);
|
||||
}
|
||||
|
||||
PalmData::PalmData(HandData* owningHandData) :
|
||||
|
@ -80,3 +82,66 @@ void HandData::decodeRemoteData(const std::vector<glm::vec3>& fingerVectors) {
|
|||
}
|
||||
}
|
||||
|
||||
void HandData::setFingerTrailLength(unsigned int length) {
|
||||
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];
|
||||
finger.setTrailLength(length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HandData::updateFingerTrails() {
|
||||
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];
|
||||
finger.updateTrail();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FingerData::setTrailLength(unsigned int length) {
|
||||
_tipTrailPositions.resize(length);
|
||||
_tipTrailCurrentStartIndex = 0;
|
||||
_tipTrailCurrentValidLength = 0;
|
||||
}
|
||||
|
||||
void FingerData::updateTrail() {
|
||||
if (_tipTrailPositions.size() == 0)
|
||||
return;
|
||||
|
||||
if (_isActive) {
|
||||
// Add the next point in the trail.
|
||||
_tipTrailCurrentStartIndex--;
|
||||
if (_tipTrailCurrentStartIndex < 0)
|
||||
_tipTrailCurrentStartIndex = _tipTrailPositions.size() - 1;
|
||||
|
||||
_tipTrailPositions[_tipTrailCurrentStartIndex] = getTipPosition();
|
||||
|
||||
if (_tipTrailCurrentValidLength < _tipTrailPositions.size())
|
||||
_tipTrailCurrentValidLength++;
|
||||
}
|
||||
else {
|
||||
// It's not active, so just shorten the trail.
|
||||
if (_tipTrailCurrentValidLength > 0)
|
||||
_tipTrailCurrentValidLength--;
|
||||
}
|
||||
}
|
||||
|
||||
int FingerData::getTrailNumPositions() {
|
||||
return _tipTrailCurrentValidLength;
|
||||
}
|
||||
|
||||
const glm::vec3& FingerData::getTrailPosition(int index) {
|
||||
if (index >= _tipTrailCurrentValidLength) {
|
||||
static glm::vec3 zero(0,0,0);
|
||||
return zero;
|
||||
}
|
||||
int posIndex = (index + _tipTrailCurrentStartIndex) % _tipTrailCurrentValidLength;
|
||||
return _tipTrailPositions[posIndex];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -40,6 +40,9 @@ public:
|
|||
std::vector<PalmData>& getPalms() { return _palms; }
|
||||
size_t getNumPalms() { return _palms.size(); }
|
||||
|
||||
void setFingerTrailLength(unsigned int length);
|
||||
void updateFingerTrails();
|
||||
|
||||
// Use these for sending and receiving hand data
|
||||
void encodeRemoteData(std::vector<glm::vec3>& fingerVectors);
|
||||
void decodeRemoteData(const std::vector<glm::vec3>& fingerVectors);
|
||||
|
@ -69,11 +72,19 @@ public:
|
|||
void setActive(bool active) { _isActive = active; }
|
||||
void setRawTipPosition(const glm::vec3& pos) { _tipRawPosition = pos; }
|
||||
void setRawRootPosition(const glm::vec3& pos) { _rootRawPosition = pos; }
|
||||
void setTrailLength(unsigned int length);
|
||||
void updateTrail();
|
||||
|
||||
int getTrailNumPositions();
|
||||
const glm::vec3& getTrailPosition(int index);
|
||||
|
||||
private:
|
||||
glm::vec3 _tipRawPosition;
|
||||
glm::vec3 _rootRawPosition;
|
||||
bool _isActive; // This has current valid data
|
||||
std::vector<glm::vec3> _tipTrailPositions;
|
||||
int _tipTrailCurrentStartIndex;
|
||||
int _tipTrailCurrentValidLength;
|
||||
PalmData* _owningPalmData;
|
||||
HandData* _owningHandData;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue