/* * Agent.cpp * RVO2-3D Library * * Copyright 2008 University of North Carolina at Chapel Hill * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Please send all bug reports to <[email protected]>. * * The authors may be contacted via: * * Jur van den Berg, Stephen J. Guy, Jamie Snape, Ming C. Lin, Dinesh Manocha * Dept. of Computer Science * 201 S. Columbia St. * Frederick P. Brooks, Jr. Computer Science Bldg. * Chapel Hill, N.C. 27599-3175 * United States of America * * <https://gamma.cs.unc.edu/RVO2/> */ #include "Agent3d.h" #include <cmath> #include <algorithm> #include "Definitions.h" #include "KdTree3d.h" namespace RVO3D { /** * \brief A sufficiently small positive number. */ const float RVO3D_EPSILON = …; /** * \brief Defines a directed line. */ class Line3D { … }; /** * \brief Solves a one-dimensional linear program on a specified line subject to linear constraints defined by planes and a spherical constraint. * \param planes Planes defining the linear constraints. * \param planeNo The plane on which the line lies. * \param line The line on which the 1-d linear program is solved * \param radius The radius of the spherical constraint. * \param optVelocity The optimization velocity. * \param directionOpt True if the direction should be optimized. * \param result A reference to the result of the linear program. * \return True if successful. */ bool linearProgram1(const std::vector<Plane> &planes, size_t planeNo, const Line3D &line, float radius, const Vector3 &optVelocity, bool directionOpt, Vector3 &result); /** * \brief Solves a two-dimensional linear program on a specified plane subject to linear constraints defined by planes and a spherical constraint. * \param planes Planes defining the linear constraints. * \param planeNo The plane on which the 2-d linear program is solved * \param radius The radius of the spherical constraint. * \param optVelocity The optimization velocity. * \param directionOpt True if the direction should be optimized. * \param result A reference to the result of the linear program. * \return True if successful. */ bool linearProgram2(const std::vector<Plane> &planes, size_t planeNo, float radius, const Vector3 &optVelocity, bool directionOpt, Vector3 &result); /** * \brief Solves a three-dimensional linear program subject to linear constraints defined by planes and a spherical constraint. * \param planes Planes defining the linear constraints. * \param radius The radius of the spherical constraint. * \param optVelocity The optimization velocity. * \param directionOpt True if the direction should be optimized. * \param result A reference to the result of the linear program. * \return The number of the plane it fails on, and the number of planes if successful. */ size_t linearProgram3(const std::vector<Plane> &planes, float radius, const Vector3 &optVelocity, bool directionOpt, Vector3 &result); /** * \brief Solves a four-dimensional linear program subject to linear constraints defined by planes and a spherical constraint. * \param planes Planes defining the linear constraints. * \param beginPlane The plane on which the 3-d linear program failed. * \param radius The radius of the spherical constraint. * \param result A reference to the result of the linear program. */ void linearProgram4(const std::vector<Plane> &planes, size_t beginPlane, float radius, Vector3 &result); Agent3D::Agent3D() : … { … } void Agent3D::computeNeighbors(RVOSimulator3D *sim_) { … } void Agent3D::computeNewVelocity(RVOSimulator3D *sim_) { … } void Agent3D::insertAgentNeighbor(const Agent3D *agent, float &rangeSq) { … } void Agent3D::update(RVOSimulator3D *sim_) { … } bool linearProgram1(const std::vector<Plane> &planes, size_t planeNo, const Line3D &line, float radius, const Vector3 &optVelocity, bool directionOpt, Vector3 &result) { … } bool linearProgram2(const std::vector<Plane> &planes, size_t planeNo, float radius, const Vector3 &optVelocity, bool directionOpt, Vector3 &result) { … } size_t linearProgram3(const std::vector<Plane> &planes, float radius, const Vector3 &optVelocity, bool directionOpt, Vector3 &result) { … } void linearProgram4(const std::vector<Plane> &planes, size_t beginPlane, float radius, Vector3 &result) { … } }