mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 20:17:01 +02:00
make balls for both hands, allow you to change color, remove red wire simulation
This commit is contained in:
parent
7a4f9cf722
commit
38d928fa4e
3 changed files with 60 additions and 63 deletions
|
@ -24,11 +24,20 @@ const int TOY_BALL_HAND = 1;
|
||||||
const float TOY_BALL_RADIUS = 0.05f;
|
const float TOY_BALL_RADIUS = 0.05f;
|
||||||
const float TOY_BALL_DAMPING = 0.99f;
|
const float TOY_BALL_DAMPING = 0.99f;
|
||||||
const glm::vec3 NO_GRAVITY = glm::vec3(0,0,0);
|
const glm::vec3 NO_GRAVITY = glm::vec3(0,0,0);
|
||||||
|
const glm::vec3 NO_VELOCITY = glm::vec3(0,0,0);
|
||||||
const glm::vec3 TOY_BALL_GRAVITY = glm::vec3(0,-1,0);
|
const glm::vec3 TOY_BALL_GRAVITY = glm::vec3(0,-1,0);
|
||||||
const QString TOY_BALL_UPDATE_SCRIPT("");
|
const QString TOY_BALL_UPDATE_SCRIPT("");
|
||||||
const QString TOY_BALL_DONT_DIE_SCRIPT("Particle.setShouldDie(false);");
|
const QString TOY_BALL_DONT_DIE_SCRIPT("Particle.setShouldDie(false);");
|
||||||
const float PALM_COLLISION_RADIUS = 0.03f;
|
const float PALM_COLLISION_RADIUS = 0.03f;
|
||||||
const xColor TOY_BALL_ON_SERVER_COLOR = { 255, 255, 0 };
|
const xColor TOY_BALL_ON_SERVER_COLOR[] =
|
||||||
|
{
|
||||||
|
{ 255, 0, 0 },
|
||||||
|
{ 0, 255, 0 },
|
||||||
|
{ 0, 0, 255 },
|
||||||
|
{ 255, 255, 0 },
|
||||||
|
{ 0, 255, 255 },
|
||||||
|
{ 255, 0, 255 },
|
||||||
|
};
|
||||||
|
|
||||||
Hand::Hand(Avatar* owningAvatar) :
|
Hand::Hand(Avatar* owningAvatar) :
|
||||||
HandData((AvatarData*)owningAvatar),
|
HandData((AvatarData*)owningAvatar),
|
||||||
|
@ -39,13 +48,14 @@ Hand::Hand(Avatar* owningAvatar) :
|
||||||
_collisionCenter(0,0,0),
|
_collisionCenter(0,0,0),
|
||||||
_collisionAge(0),
|
_collisionAge(0),
|
||||||
_collisionDuration(0),
|
_collisionDuration(0),
|
||||||
_toyBallPosition(0),
|
|
||||||
_toyBallVelocity(0),
|
|
||||||
_toyBallInHand(false),
|
|
||||||
_hasToyBall(false),
|
|
||||||
_ballParticleEditHandle(NULL),
|
|
||||||
_pitchUpdate(0)
|
_pitchUpdate(0)
|
||||||
{
|
{
|
||||||
|
for (int i = 0; i < MAX_HANDS; i++) {
|
||||||
|
_toyBallInHand[i] = false;
|
||||||
|
_ballParticleEditHandles[i] = NULL;
|
||||||
|
_whichBallColor[i] = 0;
|
||||||
|
}
|
||||||
|
_lastControllerButtons = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hand::init() {
|
void Hand::init() {
|
||||||
|
@ -77,13 +87,25 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
|
||||||
// but make sure you clean it up, when you're done
|
// but make sure you clean it up, when you're done
|
||||||
delete caughtParticle;
|
delete caughtParticle;
|
||||||
}
|
}
|
||||||
|
int handID = palm.getSixenseID();
|
||||||
|
|
||||||
|
// If there's a ball in hand, and the user presses the skinny button, then change the color of the ball
|
||||||
|
int currentControllerButtons = palm.getControllerButtons();
|
||||||
|
printf("currentControllerButtons=%d\n",currentControllerButtons);
|
||||||
|
|
||||||
|
if (currentControllerButtons != _lastControllerButtons && (currentControllerButtons & BUTTON_0)) {
|
||||||
|
_whichBallColor[handID]++;
|
||||||
|
if (_whichBallColor[handID] >= sizeof(TOY_BALL_ON_SERVER_COLOR)/sizeof(TOY_BALL_ON_SERVER_COLOR[0])) {
|
||||||
|
_whichBallColor[handID] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Is the controller button being held down....
|
// Is the controller button being held down....
|
||||||
if (palm.getControllerButtons() & BUTTON_FWD) {
|
if (palm.getControllerButtons() & BUTTON_FWD) {
|
||||||
// If grabbing toy ball, add forces to it.
|
// If grabbing toy ball, add forces to it.
|
||||||
|
|
||||||
// If we don't currently have a ball in hand, then create it...
|
// If we don't currently have a ball in hand, then create it...
|
||||||
if (!_toyBallInHand) {
|
if (!_toyBallInHand[handID]) {
|
||||||
// Test for whether close enough to catch and catch....
|
// Test for whether close enough to catch and catch....
|
||||||
|
|
||||||
// isCaught is also used as "creating" a new ball... for now, this section is the
|
// isCaught is also used as "creating" a new ball... for now, this section is the
|
||||||
|
@ -92,75 +114,60 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
|
||||||
|
|
||||||
// If we didn't catch something, then create a new ball....
|
// If we didn't catch something, then create a new ball....
|
||||||
if (!isCaught) {
|
if (!isCaught) {
|
||||||
_toyBallInHand = true;
|
_toyBallInHand[handID] = true;
|
||||||
_hasToyBall = true;
|
|
||||||
|
|
||||||
// create the ball, call MakeParticle, and use the resulting ParticleEditHandle to
|
// create the ball, call MakeParticle, and use the resulting ParticleEditHandle to
|
||||||
// manage the newly created particle.
|
// manage the newly created particle.
|
||||||
// Create a particle on the particle server
|
// Create a particle on the particle server
|
||||||
_ballParticleEditHandle = Application::getInstance()->makeParticle(fingerTipPosition / (float)TREE_SCALE,
|
_ballParticleEditHandles[handID] = Application::getInstance()->makeParticle(
|
||||||
TOY_BALL_RADIUS / (float) TREE_SCALE,
|
fingerTipPosition / (float)TREE_SCALE,
|
||||||
TOY_BALL_ON_SERVER_COLOR,
|
TOY_BALL_RADIUS / (float) TREE_SCALE,
|
||||||
_toyBallVelocity / (float)TREE_SCALE,
|
TOY_BALL_ON_SERVER_COLOR[_whichBallColor[handID]],
|
||||||
NO_GRAVITY / (float) TREE_SCALE,
|
NO_VELOCITY / (float)TREE_SCALE,
|
||||||
TOY_BALL_DAMPING,
|
NO_GRAVITY / (float) TREE_SCALE,
|
||||||
TOY_BALL_DONT_DIE_SCRIPT);
|
TOY_BALL_DAMPING,
|
||||||
|
TOY_BALL_DONT_DIE_SCRIPT);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
if (_toyBallInHand) {
|
|
||||||
// Ball is in hand
|
// Ball is in hand
|
||||||
_toyBallPosition = fingerTipPosition;
|
_ballParticleEditHandles[handID]->updateParticle(fingerTipPosition / (float)TREE_SCALE,
|
||||||
_toyBallVelocity = glm::vec3(0);
|
|
||||||
|
|
||||||
_ballParticleEditHandle->updateParticle(fingerTipPosition / (float)TREE_SCALE,
|
|
||||||
TOY_BALL_RADIUS / (float) TREE_SCALE,
|
TOY_BALL_RADIUS / (float) TREE_SCALE,
|
||||||
TOY_BALL_ON_SERVER_COLOR,
|
TOY_BALL_ON_SERVER_COLOR[_whichBallColor[handID]],
|
||||||
_toyBallVelocity / (float)TREE_SCALE,
|
NO_VELOCITY / (float)TREE_SCALE,
|
||||||
NO_GRAVITY / (float) TREE_SCALE,
|
NO_GRAVITY / (float) TREE_SCALE,
|
||||||
TOY_BALL_DAMPING,
|
TOY_BALL_DAMPING,
|
||||||
TOY_BALL_DONT_DIE_SCRIPT);
|
TOY_BALL_DONT_DIE_SCRIPT);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If toy ball just released, add velocity to it!
|
// If toy ball just released, add velocity to it!
|
||||||
if (_toyBallInHand) {
|
if (_toyBallInHand[handID]) {
|
||||||
|
|
||||||
_toyBallInHand = false;
|
_toyBallInHand[handID] = false;
|
||||||
glm::vec3 handVelocity = palm.getRawVelocity();
|
glm::vec3 handVelocity = palm.getRawVelocity();
|
||||||
glm::vec3 fingerTipVelocity = palm.getTipVelocity();
|
glm::vec3 fingerTipVelocity = palm.getTipVelocity();
|
||||||
glm::quat avatarRotation = _owningAvatar->getOrientation();
|
glm::quat avatarRotation = _owningAvatar->getOrientation();
|
||||||
//printVector(avatarRotation * handVelocity);
|
glm::vec3 toyBallVelocity = avatarRotation * fingerTipVelocity;
|
||||||
_toyBallVelocity += avatarRotation * fingerTipVelocity;
|
|
||||||
|
|
||||||
// ball is no longer in hand...
|
// ball is no longer in hand...
|
||||||
_ballParticleEditHandle->updateParticle(fingerTipPosition / (float)TREE_SCALE,
|
_ballParticleEditHandles[handID]->updateParticle(fingerTipPosition / (float)TREE_SCALE,
|
||||||
TOY_BALL_RADIUS / (float) TREE_SCALE,
|
TOY_BALL_RADIUS / (float) TREE_SCALE,
|
||||||
TOY_BALL_ON_SERVER_COLOR,
|
TOY_BALL_ON_SERVER_COLOR[_whichBallColor[handID]],
|
||||||
_toyBallVelocity / (float)TREE_SCALE,
|
toyBallVelocity / (float)TREE_SCALE,
|
||||||
TOY_BALL_GRAVITY / (float) TREE_SCALE,
|
TOY_BALL_GRAVITY / (float) TREE_SCALE,
|
||||||
TOY_BALL_DAMPING,
|
TOY_BALL_DAMPING,
|
||||||
TOY_BALL_UPDATE_SCRIPT);
|
TOY_BALL_UPDATE_SCRIPT);
|
||||||
|
|
||||||
// after releasing the ball, we free our ParticleEditHandle so we can't edit it further
|
// after releasing the ball, we free our ParticleEditHandle so we can't edit it further
|
||||||
// note: deleting the edit handle doesn't effect the actual particle
|
// note: deleting the edit handle doesn't effect the actual particle
|
||||||
delete _ballParticleEditHandle;
|
delete _ballParticleEditHandles[handID];
|
||||||
_ballParticleEditHandle = NULL;
|
_ballParticleEditHandles[handID] = NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Simulate toy ball
|
|
||||||
_toyBallPosition += _toyBallVelocity * deltaTime;
|
|
||||||
|
|
||||||
if (!_toyBallInHand) {
|
// remember the last pressed button state
|
||||||
_toyBallVelocity += TOY_BALL_GRAVITY * deltaTime;
|
if (currentControllerButtons != 0) {
|
||||||
}
|
_lastControllerButtons = currentControllerButtons;
|
||||||
if (_toyBallPosition.y < 0.f) {
|
|
||||||
_toyBallPosition.y = 0.f;
|
|
||||||
_toyBallVelocity.y *= -1.f;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_hasToyBall) {
|
|
||||||
_toyBallVelocity -= (_toyBallVelocity * TOY_BALL_DAMPING) * deltaTime;
|
|
||||||
//printf("applying damping to TOY_BALL deltaTime=%f\n",deltaTime);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,9 +199,7 @@ void Hand::simulate(float deltaTime, bool isMine) {
|
||||||
FingerData& finger = palm.getFingers()[0]; // Sixense has only one finger
|
FingerData& finger = palm.getFingers()[0]; // Sixense has only one finger
|
||||||
glm::vec3 fingerTipPosition = finger.getTipPosition();
|
glm::vec3 fingerTipPosition = finger.getTipPosition();
|
||||||
|
|
||||||
if (palm.getSixenseID() == TOY_BALL_HAND) {
|
simulateToyBall(palm, fingerTipPosition, deltaTime);
|
||||||
simulateToyBall(palm, fingerTipPosition, deltaTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (palm.getControllerButtons() & BUTTON_1) {
|
if (palm.getControllerButtons() & BUTTON_1) {
|
||||||
if (glm::length(fingerTipPosition - _lastFingerAddVoxel) > (FINGERTIP_VOXEL_SIZE / 2.f)) {
|
if (glm::length(fingerTipPosition - _lastFingerAddVoxel) > (FINGERTIP_VOXEL_SIZE / 2.f)) {
|
||||||
|
@ -376,15 +381,6 @@ void Hand::render( bool isMine) {
|
||||||
renderLeapHands();
|
renderLeapHands();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render toy ball
|
|
||||||
if (isMine && _hasToyBall) {
|
|
||||||
glPushMatrix();
|
|
||||||
glColor3f(1, 0, 0);
|
|
||||||
glTranslatef(_toyBallPosition.x, _toyBallPosition.y, _toyBallPosition.z);
|
|
||||||
glutWireSphere(TOY_BALL_RADIUS, 10, 10);
|
|
||||||
glPopMatrix();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isMine) {
|
if (isMine) {
|
||||||
// If hand/voxel collision has happened, render a little expanding sphere
|
// If hand/voxel collision has happened, render a little expanding sphere
|
||||||
if (_collisionAge > 0.f) {
|
if (_collisionAge > 0.f) {
|
||||||
|
|
|
@ -96,11 +96,11 @@ private:
|
||||||
|
|
||||||
void simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, float deltaTime);
|
void simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, float deltaTime);
|
||||||
|
|
||||||
glm::vec3 _toyBallPosition;
|
#define MAX_HANDS 2
|
||||||
glm::vec3 _toyBallVelocity;
|
bool _toyBallInHand[MAX_HANDS];
|
||||||
bool _toyBallInHand;
|
int _whichBallColor[MAX_HANDS];
|
||||||
bool _hasToyBall;
|
ParticleEditHandle* _ballParticleEditHandles[MAX_HANDS];
|
||||||
ParticleEditHandle* _ballParticleEditHandle;
|
int _lastControllerButtons;
|
||||||
|
|
||||||
float _pitchUpdate;
|
float _pitchUpdate;
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ const int NUM_FINGERS = NUM_HANDS * NUM_FINGERS_PER_HAND;
|
||||||
const int LEAPID_INVALID = -1;
|
const int LEAPID_INVALID = -1;
|
||||||
const int SIXENSEID_INVALID = -1;
|
const int SIXENSEID_INVALID = -1;
|
||||||
|
|
||||||
|
const int BUTTON_0 = 1; // the skinny button between 1 and 2
|
||||||
const int BUTTON_1 = 32;
|
const int BUTTON_1 = 32;
|
||||||
const int BUTTON_2 = 64;
|
const int BUTTON_2 = 64;
|
||||||
const int BUTTON_3 = 8;
|
const int BUTTON_3 = 8;
|
||||||
|
|
Loading…
Reference in a new issue