2011-10-23 17:52:20 +00:00
|
|
|
/*
|
|
|
|
* Simulation for obstacle avoidance behavior
|
|
|
|
* (based on Cane Project - http://code.google.com/p/cane by Mikko Mononen (c) 2009)
|
|
|
|
*
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2011-11-29 10:54:47 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2011-10-23 17:52:20 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
2010-06-04 23:29:49 +00:00
|
|
|
|
2012-02-23 10:41:31 +00:00
|
|
|
#ifndef __KX_OBSTACLESIMULATION_H__
|
|
|
|
#define __KX_OBSTACLESIMULATION_H__
|
2010-06-04 23:29:49 +00:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include "MT_Point2.h"
|
|
|
|
#include "MT_Point3.h"
|
|
|
|
|
|
|
|
class KX_GameObject;
|
2010-06-07 23:09:50 +00:00
|
|
|
class KX_NavMeshObject;
|
|
|
|
|
|
|
|
enum KX_OBSTACLE_TYPE
|
2012-09-16 04:58:18 +00:00
|
|
|
{
|
2010-06-07 23:09:50 +00:00
|
|
|
KX_OBSTACLE_OBJ,
|
|
|
|
KX_OBSTACLE_NAV_MESH,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum KX_OBSTACLE_SHAPE
|
2012-09-16 04:58:18 +00:00
|
|
|
{
|
2010-06-07 23:09:50 +00:00
|
|
|
KX_OBSTACLE_CIRCLE,
|
|
|
|
KX_OBSTACLE_SEGMENT,
|
|
|
|
};
|
2010-06-04 23:29:49 +00:00
|
|
|
|
2010-08-04 19:32:37 +00:00
|
|
|
#define VEL_HIST_SIZE 6
|
2010-06-04 23:29:49 +00:00
|
|
|
struct KX_Obstacle
|
|
|
|
{
|
2010-06-07 23:09:50 +00:00
|
|
|
KX_OBSTACLE_TYPE m_type;
|
|
|
|
KX_OBSTACLE_SHAPE m_shape;
|
2010-06-04 23:29:49 +00:00
|
|
|
MT_Point3 m_pos;
|
2010-06-07 23:09:50 +00:00
|
|
|
MT_Point3 m_pos2;
|
2010-06-04 23:29:49 +00:00
|
|
|
MT_Scalar m_rad;
|
2010-08-04 19:32:37 +00:00
|
|
|
|
|
|
|
float vel[2];
|
|
|
|
float pvel[2];
|
|
|
|
float dvel[2];
|
|
|
|
float nvel[2];
|
|
|
|
float hvel[VEL_HIST_SIZE*2];
|
|
|
|
int hhead;
|
|
|
|
|
2010-06-07 23:09:50 +00:00
|
|
|
|
2010-06-04 23:29:49 +00:00
|
|
|
KX_GameObject* m_gameObj;
|
|
|
|
};
|
2010-08-04 19:32:37 +00:00
|
|
|
typedef std::vector<KX_Obstacle*> KX_Obstacles;
|
2010-06-04 23:29:49 +00:00
|
|
|
|
|
|
|
class KX_ObstacleSimulation
|
|
|
|
{
|
|
|
|
protected:
|
2010-08-04 19:32:37 +00:00
|
|
|
KX_Obstacles m_obstacles;
|
2010-06-07 23:09:50 +00:00
|
|
|
|
2010-06-18 23:48:52 +00:00
|
|
|
MT_Scalar m_levelHeight;
|
2010-07-15 18:41:29 +00:00
|
|
|
bool m_enableVisualization;
|
2010-06-18 23:48:52 +00:00
|
|
|
|
2010-08-10 20:48:28 +00:00
|
|
|
KX_Obstacle* CreateObstacle(KX_GameObject* gameobj);
|
2010-06-04 23:29:49 +00:00
|
|
|
public:
|
2010-07-15 18:41:29 +00:00
|
|
|
KX_ObstacleSimulation(MT_Scalar levelHeight, bool enableVisualization);
|
2010-06-04 23:29:49 +00:00
|
|
|
virtual ~KX_ObstacleSimulation();
|
|
|
|
|
2010-06-07 23:09:50 +00:00
|
|
|
void DrawObstacles();
|
2010-08-04 19:32:37 +00:00
|
|
|
//void DebugDraw();
|
2010-06-07 23:09:50 +00:00
|
|
|
|
|
|
|
void AddObstacleForObj(KX_GameObject* gameobj);
|
2010-07-09 22:22:51 +00:00
|
|
|
void DestroyObstacleForObj(KX_GameObject* gameobj);
|
2010-06-07 23:09:50 +00:00
|
|
|
void AddObstaclesForNavMesh(KX_NavMeshObject* navmesh);
|
2010-06-04 23:29:49 +00:00
|
|
|
KX_Obstacle* GetObstacle(KX_GameObject* gameobj);
|
2012-09-16 04:58:18 +00:00
|
|
|
void UpdateObstacles();
|
2010-06-07 23:09:50 +00:00
|
|
|
virtual void AdjustObstacleVelocity(KX_Obstacle* activeObst, KX_NavMeshObject* activeNavMeshObj,
|
2012-09-16 04:58:18 +00:00
|
|
|
MT_Vector3& velocity, MT_Scalar maxDeltaSpeed,MT_Scalar maxDeltaAngle);
|
2010-06-04 23:29:49 +00:00
|
|
|
|
2012-04-21 13:37:26 +00:00
|
|
|
};
|
2010-06-04 23:29:49 +00:00
|
|
|
class KX_ObstacleSimulationTOI: public KX_ObstacleSimulation
|
|
|
|
{
|
|
|
|
protected:
|
2010-08-10 20:48:28 +00:00
|
|
|
int m_maxSamples; // Number of sample steps
|
2010-06-04 23:29:49 +00:00
|
|
|
float m_minToi; // Min TOI
|
|
|
|
float m_maxToi; // Max TOI
|
2010-08-10 20:48:28 +00:00
|
|
|
float m_velWeight; // Sample selection angle weight
|
|
|
|
float m_curVelWeight; // Sample selection current velocity weight
|
2010-06-04 23:29:49 +00:00
|
|
|
float m_toiWeight; // Sample selection TOI weight
|
|
|
|
float m_collisionWeight; // Sample selection collision weight
|
|
|
|
|
2010-08-10 20:48:28 +00:00
|
|
|
virtual void sampleRVO(KX_Obstacle* activeObst, KX_NavMeshObject* activeNavMeshObj,
|
|
|
|
const float maxDeltaAngle) = 0;
|
2010-06-04 23:29:49 +00:00
|
|
|
public:
|
2010-07-15 18:41:29 +00:00
|
|
|
KX_ObstacleSimulationTOI(MT_Scalar levelHeight, bool enableVisualization);
|
2010-06-07 23:09:50 +00:00
|
|
|
virtual void AdjustObstacleVelocity(KX_Obstacle* activeObst, KX_NavMeshObject* activeNavMeshObj,
|
2010-08-10 20:48:28 +00:00
|
|
|
MT_Vector3& velocity, MT_Scalar maxDeltaSpeed,MT_Scalar maxDeltaAngle);
|
|
|
|
};
|
|
|
|
|
|
|
|
class KX_ObstacleSimulationTOI_rays: public KX_ObstacleSimulationTOI
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
virtual void sampleRVO(KX_Obstacle* activeObst, KX_NavMeshObject* activeNavMeshObj,
|
|
|
|
const float maxDeltaAngle);
|
|
|
|
public:
|
|
|
|
KX_ObstacleSimulationTOI_rays(MT_Scalar levelHeight, bool enableVisualization);
|
|
|
|
};
|
|
|
|
|
|
|
|
class KX_ObstacleSimulationTOI_cells: public KX_ObstacleSimulationTOI
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
float m_bias;
|
|
|
|
bool m_adaptive;
|
|
|
|
int m_sampleRadius;
|
|
|
|
virtual void sampleRVO(KX_Obstacle* activeObst, KX_NavMeshObject* activeNavMeshObj,
|
|
|
|
const float maxDeltaAngle);
|
|
|
|
public:
|
|
|
|
KX_ObstacleSimulationTOI_cells(MT_Scalar levelHeight, bool enableVisualization);
|
2010-06-04 23:29:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|