mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-29 19:22:57 +02:00
Hand now holds a ball a bit forward, which prevents the body from colliding with the ball on throw.
This commit is contained in:
parent
3750aa902a
commit
6c6a59b252
3 changed files with 23 additions and 10 deletions
|
@ -83,7 +83,6 @@ void Hand::reset() {
|
||||||
void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, float deltaTime) {
|
void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, float deltaTime) {
|
||||||
Application* app = Application::getInstance();
|
Application* app = Application::getInstance();
|
||||||
ParticleTree* particles = app->getParticles()->getTree();
|
ParticleTree* particles = app->getParticles()->getTree();
|
||||||
bool ballFromHand = Menu::getInstance()->isOptionChecked(MenuOption::BallFromHand);
|
|
||||||
int handID = palm.getSixenseID();
|
int handID = palm.getSixenseID();
|
||||||
|
|
||||||
const int NEW_BALL_BUTTON = BUTTON_3;
|
const int NEW_BALL_BUTTON = BUTTON_3;
|
||||||
|
@ -93,7 +92,8 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
|
||||||
|
|
||||||
bool ballAlreadyInHand = _toyBallInHand[handID];
|
bool ballAlreadyInHand = _toyBallInHand[handID];
|
||||||
|
|
||||||
glm::vec3 targetPosition = (ballFromHand ? palm.getPosition() : fingerTipPosition) / (float)TREE_SCALE;
|
glm::vec3 targetPosition;
|
||||||
|
palm.getBallHoldPosition(targetPosition);
|
||||||
float targetRadius = CATCH_RADIUS / (float)TREE_SCALE;
|
float targetRadius = CATCH_RADIUS / (float)TREE_SCALE;
|
||||||
|
|
||||||
// If I don't currently have a ball in my hand, then try to catch closest one
|
// If I don't currently have a ball in my hand, then try to catch closest one
|
||||||
|
@ -148,7 +148,8 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
|
||||||
if ((palm.getControllerButtons() & NEW_BALL_BUTTON) && (_toyBallInHand[handID] == false)) {
|
if ((palm.getControllerButtons() & NEW_BALL_BUTTON) && (_toyBallInHand[handID] == false)) {
|
||||||
_toyBallInHand[handID] = true;
|
_toyBallInHand[handID] = true;
|
||||||
// Create a particle on the particle server
|
// Create a particle on the particle server
|
||||||
glm::vec3 ballPosition = ballFromHand ? palm.getPosition() : fingerTipPosition;
|
glm::vec3 ballPosition;
|
||||||
|
palm.getBallHoldPosition(ballPosition);
|
||||||
_ballParticleEditHandles[handID] = app->makeParticle(
|
_ballParticleEditHandles[handID] = app->makeParticle(
|
||||||
ballPosition / (float)TREE_SCALE,
|
ballPosition / (float)TREE_SCALE,
|
||||||
TOY_BALL_RADIUS / (float) TREE_SCALE,
|
TOY_BALL_RADIUS / (float) TREE_SCALE,
|
||||||
|
@ -171,7 +172,8 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
|
||||||
xColor colorForParticleInHand = particleInHand ? particleInHand->getXColor()
|
xColor colorForParticleInHand = particleInHand ? particleInHand->getXColor()
|
||||||
: TOY_BALL_ON_SERVER_COLOR[_whichBallColor[handID]];
|
: TOY_BALL_ON_SERVER_COLOR[_whichBallColor[handID]];
|
||||||
|
|
||||||
glm::vec3 ballPosition = ballFromHand ? palm.getPosition() : fingerTipPosition;
|
glm::vec3 ballPosition;
|
||||||
|
palm.getBallHoldPosition(ballPosition);
|
||||||
_ballParticleEditHandles[handID]->updateParticle(ballPosition / (float)TREE_SCALE,
|
_ballParticleEditHandles[handID]->updateParticle(ballPosition / (float)TREE_SCALE,
|
||||||
TOY_BALL_RADIUS / (float) TREE_SCALE,
|
TOY_BALL_RADIUS / (float) TREE_SCALE,
|
||||||
colorForParticleInHand,
|
colorForParticleInHand,
|
||||||
|
@ -188,8 +190,9 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
|
||||||
const float THROWN_VELOCITY_SCALING = 1.5f;
|
const float THROWN_VELOCITY_SCALING = 1.5f;
|
||||||
_toyBallInHand[handID] = false;
|
_toyBallInHand[handID] = false;
|
||||||
palm.updateCollisionlessPaddleExpiry();
|
palm.updateCollisionlessPaddleExpiry();
|
||||||
glm::vec3 ballPosition = ballFromHand ? palm.getPosition() : fingerTipPosition;
|
glm::vec3 ballPosition;
|
||||||
glm::vec3 ballVelocity = ballFromHand ? palm.getRawVelocity() : palm.getTipVelocity();
|
palm.getBallHoldPosition(ballPosition);
|
||||||
|
glm::vec3 ballVelocity = palm.getTipVelocity();
|
||||||
glm::quat avatarRotation = _owningAvatar->getOrientation();
|
glm::quat avatarRotation = _owningAvatar->getOrientation();
|
||||||
ballVelocity = avatarRotation * ballVelocity;
|
ballVelocity = avatarRotation * ballVelocity;
|
||||||
ballVelocity *= THROWN_VELOCITY_SCALING;
|
ballVelocity *= THROWN_VELOCITY_SCALING;
|
||||||
|
@ -551,7 +554,6 @@ void Hand::renderLeapHands(bool isMine) {
|
||||||
|
|
||||||
//const glm::vec3 handColor = _ballColor;
|
//const glm::vec3 handColor = _ballColor;
|
||||||
const glm::vec3 handColor(1.0, 0.84, 0.66); // use the skin color
|
const glm::vec3 handColor(1.0, 0.84, 0.66); // use the skin color
|
||||||
bool ballFromHand = Menu::getInstance()->isOptionChecked(MenuOption::BallFromHand);
|
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glDepthMask(GL_TRUE);
|
glDepthMask(GL_TRUE);
|
||||||
|
@ -562,9 +564,8 @@ void Hand::renderLeapHands(bool isMine) {
|
||||||
if (!palm.isActive()) {
|
if (!palm.isActive()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
glm::vec3 targetPosition = ballFromHand ? palm.getPosition() : palm.getTipPosition();
|
glm::vec3 targetPosition;
|
||||||
const float BALL_FORWARD_OFFSET = 0.08f; // put the ball a bit forward of fingers
|
palm.getBallHoldPosition(targetPosition);
|
||||||
targetPosition += BALL_FORWARD_OFFSET * palm.getNormal();
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
ParticleTree* particles = Application::getInstance()->getParticles()->getTree();
|
ParticleTree* particles = Application::getInstance()->getParticles()->getTree();
|
||||||
|
|
|
@ -295,6 +295,15 @@ const glm::vec3& FingerData::getTrailPosition(int index) {
|
||||||
return _tipTrailPositions[posIndex];
|
return _tipTrailPositions[posIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PalmData::getBallHoldPosition(glm::vec3& position) const {
|
||||||
|
const float BALL_FORWARD_OFFSET = 0.08f; // put the ball a bit forward of fingers
|
||||||
|
position = BALL_FORWARD_OFFSET * getNormal();
|
||||||
|
if (_fingers.size() > 0) {
|
||||||
|
position += _fingers[0].getTipPosition();
|
||||||
|
} else {
|
||||||
|
position += getPosition();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -198,6 +198,9 @@ public:
|
||||||
bool hasPaddle() const { return _collisionlessPaddleExpiry < usecTimestampNow(); }
|
bool hasPaddle() const { return _collisionlessPaddleExpiry < usecTimestampNow(); }
|
||||||
void updateCollisionlessPaddleExpiry() { _collisionlessPaddleExpiry = usecTimestampNow() + USECS_PER_SECOND; }
|
void updateCollisionlessPaddleExpiry() { _collisionlessPaddleExpiry = usecTimestampNow() + USECS_PER_SECOND; }
|
||||||
|
|
||||||
|
/// Store position where the palm holds the ball.
|
||||||
|
void getBallHoldPosition(glm::vec3& position) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<FingerData> _fingers;
|
std::vector<FingerData> _fingers;
|
||||||
glm::quat _rawRotation;
|
glm::quat _rawRotation;
|
||||||
|
|
Loading…
Reference in a new issue