mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 19:57:11 +02:00
Added angular velocity and angular movement to hand, changed hand to block.
This commit is contained in:
parent
d272a7de31
commit
a22cd3680a
2 changed files with 52 additions and 9 deletions
|
@ -24,14 +24,24 @@ Hand::Hand(glm::vec3 initcolor)
|
||||||
scale.z = scale.y * 1.0;
|
scale.z = scale.y * 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Hand::addAngularVelocity (float pRate, float yRate, float rRate) {
|
||||||
|
pitchRate += pRate;
|
||||||
|
yawRate += yRate;
|
||||||
|
rollRate += rRate;
|
||||||
|
}
|
||||||
|
|
||||||
void Hand::render()
|
void Hand::render()
|
||||||
{
|
{
|
||||||
// glPushMatrix();
|
glPushMatrix();
|
||||||
// glTranslatef(position.x, position.y, position.z);
|
glTranslatef(position.x, position.y, position.z);
|
||||||
// glColor3f(color.x, color.y, color.z);
|
glRotatef(yaw, 0, 1, 0);
|
||||||
// glScalef(scale.x, scale.y, scale.z);
|
glRotatef(pitch, 1, 0, 0);
|
||||||
// glutSolidSphere(1.5, 20, 20);
|
glRotatef(roll, 0, 0, 1);
|
||||||
// glPopMatrix();
|
glColor3f(color.x, color.y, color.z);
|
||||||
|
glScalef(scale.x, scale.y, scale.z);
|
||||||
|
//glutSolidSphere(1.5, 20, 20);
|
||||||
|
glutSolidCube(1.0);
|
||||||
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hand::reset()
|
void Hand::reset()
|
||||||
|
@ -39,17 +49,48 @@ void Hand::reset()
|
||||||
position.x = DEFAULT_X;
|
position.x = DEFAULT_X;
|
||||||
position.y = DEFAULT_Y;
|
position.y = DEFAULT_Y;
|
||||||
position.z = DEFAULT_Z;
|
position.z = DEFAULT_Z;
|
||||||
|
pitch = yaw = roll = 0;
|
||||||
|
pitchRate = yawRate = rollRate = 0;
|
||||||
setTarget(position);
|
setTarget(position);
|
||||||
velocity.x = velocity.y = velocity.z = 0;
|
velocity.x = velocity.y = velocity.z = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hand::simulate(float deltaTime)
|
void Hand::simulate(float deltaTime)
|
||||||
{
|
{
|
||||||
// If noise, add wandering movement
|
const float VNOISE = 0.1;
|
||||||
|
const float RSPRING = 0.01;
|
||||||
|
const float RNOISE = 0.1;
|
||||||
|
|
||||||
|
// If noise, add a bit of random velocity
|
||||||
if (noise) {
|
if (noise) {
|
||||||
position += noise * 0.1f * glm::vec3(randFloat() - 0.5, randFloat() - 0.5, randFloat() - 0.5);
|
glm::vec3 nVel(randFloat() - 0.5f, randFloat() - 0.5f, randFloat() - 0.5f);
|
||||||
|
nVel *= VNOISE;
|
||||||
|
addVelocity(nVel);
|
||||||
|
|
||||||
|
addAngularVelocity(RNOISE*(randFloat() - 0.5f),
|
||||||
|
RNOISE*(randFloat() - 0.5f),
|
||||||
|
RNOISE*(randFloat() - 0.5f));
|
||||||
}
|
}
|
||||||
|
position += velocity*deltaTime;
|
||||||
|
|
||||||
|
pitch += pitchRate;
|
||||||
|
yaw += yawRate;
|
||||||
|
roll += rollRate;
|
||||||
|
|
||||||
// Decay position of hand toward target
|
// Decay position of hand toward target
|
||||||
position -= deltaTime*(position - target);
|
position -= deltaTime*(position - target);
|
||||||
|
|
||||||
|
// Decay velocity
|
||||||
|
velocity *= 1.0 - deltaTime;
|
||||||
|
|
||||||
|
// Decay Angular Velocity
|
||||||
|
pitchRate *= 1.0 - deltaTime;
|
||||||
|
yawRate *= 1.0 - deltaTime;
|
||||||
|
rollRate *= 1.0 - deltaTime;
|
||||||
|
|
||||||
|
// Add spring effect to return hand rotation to zero
|
||||||
|
pitchRate -= pitch * RSPRING;
|
||||||
|
yawRate -= yaw * RSPRING;
|
||||||
|
rollRate -= roll * RSPRING;
|
||||||
|
|
||||||
}
|
}
|
|
@ -23,12 +23,14 @@ public:
|
||||||
void render ();
|
void render ();
|
||||||
void reset ();
|
void reset ();
|
||||||
void setNoise (float mag) { noise = mag; };
|
void setNoise (float mag) { noise = mag; };
|
||||||
void addVel (glm::vec3 v) { velocity += v; };
|
void addVelocity (glm::vec3 v) { velocity += v; };
|
||||||
|
void addAngularVelocity (float pRate, float yRate, float rRate);
|
||||||
glm::vec3 getPos() { return position; };
|
glm::vec3 getPos() { return position; };
|
||||||
void setPos(glm::vec3 p) { position = p; };
|
void setPos(glm::vec3 p) { position = p; };
|
||||||
void setTarget(glm::vec3 t) { target = t; };
|
void setTarget(glm::vec3 t) { target = t; };
|
||||||
private:
|
private:
|
||||||
glm::vec3 position, target, velocity, color, scale;
|
glm::vec3 position, target, velocity, color, scale;
|
||||||
|
float pitch, yaw, roll, pitchRate, yawRate, rollRate;
|
||||||
float noise;
|
float noise;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue