mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 15:30:38 +02:00
Moving "play slaps" code into its own method.
Cleaning up hand collision code in prep for more correct collisions.
This commit is contained in:
parent
4b58d04c17
commit
490b9149fa
2 changed files with 43 additions and 34 deletions
|
@ -125,6 +125,41 @@ void Hand::simulate(float deltaTime, bool isMine) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Hand::playSlaps(PalmData& palm, Avatar* avatar)
|
||||||
|
{
|
||||||
|
// Check for palm collisions
|
||||||
|
glm::vec3 myPalmPosition = palm.getPosition();
|
||||||
|
float palmCollisionDistance = 0.1f;
|
||||||
|
bool wasColliding = palm.getIsCollidingWithPalm();
|
||||||
|
palm.setIsCollidingWithPalm(false);
|
||||||
|
// If 'Play Slaps' is enabled, look for palm-to-palm collisions and make sound
|
||||||
|
for (size_t j = 0; j < avatar->getHand().getNumPalms(); j++) {
|
||||||
|
PalmData& otherPalm = avatar->getHand().getPalms()[j];
|
||||||
|
if (!otherPalm.isActive()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
glm::vec3 otherPalmPosition = otherPalm.getPosition();
|
||||||
|
if (glm::length(otherPalmPosition - myPalmPosition) < palmCollisionDistance) {
|
||||||
|
palm.setIsCollidingWithPalm(true);
|
||||||
|
if (!wasColliding) {
|
||||||
|
const float PALM_COLLIDE_VOLUME = 1.f;
|
||||||
|
const float PALM_COLLIDE_FREQUENCY = 1000.f;
|
||||||
|
const float PALM_COLLIDE_DURATION_MAX = 0.75f;
|
||||||
|
const float PALM_COLLIDE_DECAY_PER_SAMPLE = 0.01f;
|
||||||
|
Application::getInstance()->getAudio()->startDrumSound(PALM_COLLIDE_VOLUME,
|
||||||
|
PALM_COLLIDE_FREQUENCY,
|
||||||
|
PALM_COLLIDE_DURATION_MAX,
|
||||||
|
PALM_COLLIDE_DECAY_PER_SAMPLE);
|
||||||
|
// If the other person's palm is in motion, move mine downward to show I was hit
|
||||||
|
const float MIN_VELOCITY_FOR_SLAP = 0.05f;
|
||||||
|
if (glm::length(otherPalm.getVelocity()) > MIN_VELOCITY_FOR_SLAP) {
|
||||||
|
// add slapback here
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// We create a static CollisionList that is recycled for each collision test.
|
// We create a static CollisionList that is recycled for each collision test.
|
||||||
const float MAX_COLLISIONS_PER_AVATAR = 32;
|
const float MAX_COLLISIONS_PER_AVATAR = 32;
|
||||||
static CollisionList handCollisions(MAX_COLLISIONS_PER_AVATAR);
|
static CollisionList handCollisions(MAX_COLLISIONS_PER_AVATAR);
|
||||||
|
@ -139,41 +174,12 @@ void Hand::collideAgainstAvatar(Avatar* avatar, bool isMyHand) {
|
||||||
PalmData& palm = getPalms()[i];
|
PalmData& palm = getPalms()[i];
|
||||||
if (!palm.isActive()) {
|
if (!palm.isActive()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
glm::vec3 totalPenetration;
|
|
||||||
if (isMyHand && Menu::getInstance()->isOptionChecked(MenuOption::PlaySlaps)) {
|
|
||||||
// Check for palm collisions
|
|
||||||
glm::vec3 myPalmPosition = palm.getPosition();
|
|
||||||
float palmCollisionDistance = 0.1f;
|
|
||||||
bool wasColliding = palm.getIsCollidingWithPalm();
|
|
||||||
palm.setIsCollidingWithPalm(false);
|
|
||||||
// If 'Play Slaps' is enabled, look for palm-to-palm collisions and make sound
|
|
||||||
for (size_t j = 0; j < avatar->getHand().getNumPalms(); j++) {
|
|
||||||
PalmData& otherPalm = avatar->getHand().getPalms()[j];
|
|
||||||
if (!otherPalm.isActive()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
glm::vec3 otherPalmPosition = otherPalm.getPosition();
|
|
||||||
if (glm::length(otherPalmPosition - myPalmPosition) < palmCollisionDistance) {
|
|
||||||
palm.setIsCollidingWithPalm(true);
|
|
||||||
if (!wasColliding) {
|
|
||||||
const float PALM_COLLIDE_VOLUME = 1.f;
|
|
||||||
const float PALM_COLLIDE_FREQUENCY = 1000.f;
|
|
||||||
const float PALM_COLLIDE_DURATION_MAX = 0.75f;
|
|
||||||
const float PALM_COLLIDE_DECAY_PER_SAMPLE = 0.01f;
|
|
||||||
Application::getInstance()->getAudio()->startDrumSound(PALM_COLLIDE_VOLUME,
|
|
||||||
PALM_COLLIDE_FREQUENCY,
|
|
||||||
PALM_COLLIDE_DURATION_MAX,
|
|
||||||
PALM_COLLIDE_DECAY_PER_SAMPLE);
|
|
||||||
// If the other person's palm is in motion, move mine downward to show I was hit
|
|
||||||
const float MIN_VELOCITY_FOR_SLAP = 0.05f;
|
|
||||||
if (glm::length(otherPalm.getVelocity()) > MIN_VELOCITY_FOR_SLAP) {
|
|
||||||
// add slapback here
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (isMyHand && Menu::getInstance()->isOptionChecked(MenuOption::PlaySlaps)) {
|
||||||
|
playSlaps(palm, avatar);
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::vec3 totalPenetration;
|
||||||
handCollisions.clear();
|
handCollisions.clear();
|
||||||
if (avatar->findSphereCollisions(palm.getPosition(), scaledPalmRadius, handCollisions)) {
|
if (avatar->findSphereCollisions(palm.getPosition(), scaledPalmRadius, handCollisions)) {
|
||||||
for (int j = 0; j < handCollisions.size(); ++j) {
|
for (int j = 0; j < handCollisions.size(); ++j) {
|
||||||
|
|
|
@ -61,6 +61,9 @@ public:
|
||||||
void collideAgainstAvatar(Avatar* avatar, bool isMyHand);
|
void collideAgainstAvatar(Avatar* avatar, bool isMyHand);
|
||||||
void collideAgainstOurself();
|
void collideAgainstOurself();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void playSlaps(PalmData& palm, Avatar* avatar);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// disallow copies of the Hand, copy of owning Avatar is disallowed too
|
// disallow copies of the Hand, copy of owning Avatar is disallowed too
|
||||||
Hand(const Hand&);
|
Hand(const Hand&);
|
||||||
|
|
Loading…
Reference in a new issue