mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 17:14:59 +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) {
|
||||
Application* app = Application::getInstance();
|
||||
ParticleTree* particles = app->getParticles()->getTree();
|
||||
bool ballFromHand = Menu::getInstance()->isOptionChecked(MenuOption::BallFromHand);
|
||||
int handID = palm.getSixenseID();
|
||||
|
||||
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];
|
||||
|
||||
glm::vec3 targetPosition = (ballFromHand ? palm.getPosition() : fingerTipPosition) / (float)TREE_SCALE;
|
||||
glm::vec3 targetPosition;
|
||||
palm.getBallHoldPosition(targetPosition);
|
||||
float targetRadius = CATCH_RADIUS / (float)TREE_SCALE;
|
||||
|
||||
// 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)) {
|
||||
_toyBallInHand[handID] = true;
|
||||
// Create a particle on the particle server
|
||||
glm::vec3 ballPosition = ballFromHand ? palm.getPosition() : fingerTipPosition;
|
||||
glm::vec3 ballPosition;
|
||||
palm.getBallHoldPosition(ballPosition);
|
||||
_ballParticleEditHandles[handID] = app->makeParticle(
|
||||
ballPosition / (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()
|
||||
: 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,
|
||||
TOY_BALL_RADIUS / (float) TREE_SCALE,
|
||||
colorForParticleInHand,
|
||||
|
@ -188,8 +190,9 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
|
|||
const float THROWN_VELOCITY_SCALING = 1.5f;
|
||||
_toyBallInHand[handID] = false;
|
||||
palm.updateCollisionlessPaddleExpiry();
|
||||
glm::vec3 ballPosition = ballFromHand ? palm.getPosition() : fingerTipPosition;
|
||||
glm::vec3 ballVelocity = ballFromHand ? palm.getRawVelocity() : palm.getTipVelocity();
|
||||
glm::vec3 ballPosition;
|
||||
palm.getBallHoldPosition(ballPosition);
|
||||
glm::vec3 ballVelocity = palm.getTipVelocity();
|
||||
glm::quat avatarRotation = _owningAvatar->getOrientation();
|
||||
ballVelocity = avatarRotation * ballVelocity;
|
||||
ballVelocity *= THROWN_VELOCITY_SCALING;
|
||||
|
@ -551,7 +554,6 @@ void Hand::renderLeapHands(bool isMine) {
|
|||
|
||||
//const glm::vec3 handColor = _ballColor;
|
||||
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);
|
||||
glDepthMask(GL_TRUE);
|
||||
|
@ -562,9 +564,8 @@ void Hand::renderLeapHands(bool isMine) {
|
|||
if (!palm.isActive()) {
|
||||
continue;
|
||||
}
|
||||
glm::vec3 targetPosition = ballFromHand ? palm.getPosition() : palm.getTipPosition();
|
||||
const float BALL_FORWARD_OFFSET = 0.08f; // put the ball a bit forward of fingers
|
||||
targetPosition += BALL_FORWARD_OFFSET * palm.getNormal();
|
||||
glm::vec3 targetPosition;
|
||||
palm.getBallHoldPosition(targetPosition);
|
||||
glPushMatrix();
|
||||
|
||||
ParticleTree* particles = Application::getInstance()->getParticles()->getTree();
|
||||
|
|
|
@ -295,6 +295,15 @@ const glm::vec3& FingerData::getTrailPosition(int index) {
|
|||
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(); }
|
||||
void updateCollisionlessPaddleExpiry() { _collisionlessPaddleExpiry = usecTimestampNow() + USECS_PER_SECOND; }
|
||||
|
||||
/// Store position where the palm holds the ball.
|
||||
void getBallHoldPosition(glm::vec3& position) const;
|
||||
|
||||
private:
|
||||
std::vector<FingerData> _fingers;
|
||||
glm::quat _rawRotation;
|
||||
|
|
Loading…
Reference in a new issue