bool Line::isInBetween( Vector2D pos, Vector2D point1, Vector2D point2){ pos = getPointOnLineClosestTo( pos ); // get closest point float dDist = point1.distanceTo( point2 ); // get distance between 2 pos // if the distance from both points to the projection is smaller than this // dist, the pos lies in between. return pos.distanceTo( point1 ) <= dDist && pos.distanceTo( point2 ) <= dDist; }
double SurfaceToImplicit2::signedDistanceLocal( const Vector2D& otherPoint) const { Vector2D x = _surface->closestPoint(otherPoint); Vector2D n = _surface->closestNormal(otherPoint); n = (isNormalFlipped) ? -n : n; if (n.dot(otherPoint - x) < 0.0) { return -x.distanceTo(otherPoint); } else { return x.distanceTo(otherPoint); } }
bool Cone::isInside( Vector2D pos ) const { float dist = pos.distanceTo( peak ); float angle = (pos - peak).getDirection(); return ( ( minDistance <= dist && dist <= maxDistance && isAngInInterval( angle, fstAngle, sndAngle ) ) || ( dist == 0 && minDistance == 0) ); }
void Animal::handleStimulus(Environment *environment, double dt) { voiceInterval -= dt; if (this == environment->getPlayer()) { Vector2D movement = environment->getMovement(); movement = movement.mult(dt); translate(movement); handleCollisions(environment); environment->updateObjectScreen(this); if (movement.distanceTo(Vector2D()) > 1.0e-5) { addEnergy(-dt); } for (int i = 0; i < sensors.size(); i++) { sensors[i]->handleStimulus(this, environment, dt); } } else { RandomNumberGenerator *rng = RandomNumberGenerator::getInstance(); if (curAIStateDuration > 0.0) { curAIStateDuration -= dt; } else { curAIStateDuration = ((double) rng->getInt(500, 3000)) / 1000.0; curAIDirection = Vector2D(rng->getInt(-1, 1), rng->getInt(-1, 1)); curAIDirection = curAIDirection.mult(speed); } Vector2D movement = curAIDirection; movement = movement.mult(dt); translate(movement); handleCollisions(environment); environment->updateObjectScreen(this); } }
Vector2D SphSystemData2::gradientAt( size_t i, const ConstArrayAccessor1<double>& values) const { Vector2D sum; auto p = positions(); auto d = densities(); const auto& neighbors = neighborLists()[i]; Vector2D origin = p[i]; SphSpikyKernel2 kernel(_kernelRadius); const double m = mass(); for (size_t j : neighbors) { Vector2D neighborPosition = p[j]; double dist = origin.distanceTo(neighborPosition); if (dist > 0.0) { Vector2D dir = (neighborPosition - origin) / dist; sum += d[i] * m * (values[i] / square(d[i]) + values[j] / square(d[j])) * kernel.gradient(dist, dir); } } return sum; }
double SphSystemData2::sumOfKernelNearby(const Vector2D& origin) const { double sum = 0.0; SphStdKernel2 kernel(_kernelRadius); neighborSearcher()->forEachNearbyPoint( origin, _kernelRadius, [&] (size_t, const Vector2D& neighborPosition) { double dist = origin.distanceTo(neighborPosition); sum += kernel(dist); }); return sum; }
Vector2D SphSystemData2::interpolate( const Vector2D& origin, const ConstArrayAccessor1<Vector2D>& values) const { Vector2D sum; auto d = densities(); SphStdKernel2 kernel(_kernelRadius); const double m = mass(); neighborSearcher()->forEachNearbyPoint( origin, _kernelRadius, [&] (size_t i, const Vector2D& neighborPosition) { double dist = origin.distanceTo(neighborPosition); double weight = m / d[i] * kernel(dist); sum += weight * values[i]; }); return sum; }
Vector2D SphSystemData2::laplacianAt( size_t i, const ConstArrayAccessor1<Vector2D>& values) const { Vector2D sum; auto p = positions(); auto d = densities(); const auto& neighbors = neighborLists()[i]; Vector2D origin = p[i]; SphSpikyKernel2 kernel(_kernelRadius); const double m = mass(); for (size_t j : neighbors) { Vector2D neighborPosition = p[j]; double dist = origin.distanceTo(neighborPosition); sum += m * (values[j] - values[i]) / d[j] * kernel.secondDerivative(dist); } return sum; }
void MultiDirectionalEar::renderFeedback(Object *object, Environment *environment) { if (object == environment->getPlayer()) { Vector2D windowPos = environment->getWindowPos(object->getPosition()); for (int i = 0; i < nearestObjects.size(); i++) { Object *nearestObject = nearestObjects[i]; if (nearestObject->getVoice() && nearestObject->getVoiceInterval() <= 0.0) { nearestObject->resetVoiceInterval(); Vector2D objectWindowPos = environment->getWindowPos(nearestObject->getPosition()); Vector2D relativePos = objectWindowPos.add(windowPos.mult(-1.0)); relativePos = relativePos.normalize(); double pan = relativePos.getX(); double nearestObjectDistance = windowPos.distanceTo(objectWindowPos); double gain = 1.0 - (nearestObjectDistance / 1000.0); if (gain < 0.0) { gain = 0.0; } al_play_sample(nearestObject->getVoice(), gain, pan, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL); } } } }
double Surface2::closestDistanceLocal(const Vector2D& otherPointLocal) const { return otherPointLocal.distanceTo(closestPointLocal(otherPointLocal)); }
float Line::distanceToPoint( Vector2D pos ){ return pos.distanceTo( getPointOnLineClosestTo( pos ) ); }