Welcome to mirror list, hosted at ThFree Co, Russian Federation.

KX_ObstacleSimulation.h « Ketsji « gameengine « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b084f54d3b8d454499b4cec44eae7aad7857a569 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/**
* Simulation for obstacle avoidance behavior 
* (based on Cane Project - http://code.google.com/p/cane  by Mikko Mononen (c) 2009)
*
*
* $Id$
*
* ***** 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
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License.  See http://www.blender.org/BL/ for information
* about this.
*
* 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.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/

#ifndef __KX_OBSTACLESIMULATION
#define __KX_OBSTACLESIMULATION

#include <vector>
#include "MT_Point2.h"
#include "MT_Point3.h"

class KX_GameObject;
class KX_NavMeshObject;

enum KX_OBSTACLE_TYPE
{	
	KX_OBSTACLE_OBJ, 
	KX_OBSTACLE_NAV_MESH,
};

enum KX_OBSTACLE_SHAPE
{	
	KX_OBSTACLE_CIRCLE, 
	KX_OBSTACLE_SEGMENT,
};

struct KX_Obstacle
{
	KX_OBSTACLE_TYPE m_type;
	KX_OBSTACLE_SHAPE m_shape;
	MT_Point3 m_pos;
	MT_Point3 m_pos2;
	MT_Scalar m_rad;
	MT_Vector2 m_vel;
	
	KX_GameObject* m_gameObj;
};

class KX_ObstacleSimulation
{
protected:
	std::vector<KX_Obstacle*>	m_obstacles;

	MT_Scalar m_levelHeight;
	bool m_enableVisualization;

	virtual KX_Obstacle* CreateObstacle(KX_GameObject* gameobj);
	bool FilterObstacle(KX_Obstacle* activeObstacle, KX_NavMeshObject* activeNavMeshObj, KX_Obstacle* otherObstacle);
public:
	KX_ObstacleSimulation(MT_Scalar levelHeight, bool enableVisualization);
	virtual ~KX_ObstacleSimulation();

	void DrawObstacles();

	void AddObstacleForObj(KX_GameObject* gameobj);
	void DestroyObstacleForObj(KX_GameObject* gameobj);
	void AddObstaclesForNavMesh(KX_NavMeshObject* navmesh);
	KX_Obstacle* GetObstacle(KX_GameObject* gameobj);
	void UpdateObstacles();	
	virtual void AdjustObstacleVelocity(KX_Obstacle* activeObst, KX_NavMeshObject* activeNavMeshObj, 
								MT_Vector3& velocity, MT_Scalar maxDeltaSpeed,MT_Scalar maxDeltaAngle);

}; /* end of class KX_ObstacleSimulation*/

static const int AVOID_MAX_STEPS = 128;
struct TOICircle
{
	TOICircle() : n(0), minToi(0), maxToi(1) {}
	float	toi[AVOID_MAX_STEPS];	// Time of impact (seconds)
	float	toie[AVOID_MAX_STEPS];	// Time of exit (seconds)
	float	dir[AVOID_MAX_STEPS];	// Direction (radians)
	int		n;						// Number of samples
	float	minToi, maxToi;			// Min/max TOI (seconds)
};

class KX_ObstacleSimulationTOI: public KX_ObstacleSimulation
{
protected:
	int m_avoidSteps;				// Number of sample steps
	float m_minToi;					// Min TOI
	float m_maxToi;					// Max TOI
	float m_angleWeight;			// Sample selection angle weight
	float m_toiWeight;				// Sample selection TOI weight
	float m_collisionWeight;		// Sample selection collision weight

	std::vector<TOICircle*>	m_toiCircles; // TOI circles (one per active agent)
	virtual KX_Obstacle* CreateObstacle(KX_GameObject* gameobj);
public:
	KX_ObstacleSimulationTOI(MT_Scalar levelHeight, bool enableVisualization);
	~KX_ObstacleSimulationTOI();
	virtual void AdjustObstacleVelocity(KX_Obstacle* activeObst, KX_NavMeshObject* activeNavMeshObj, 
									MT_Vector3& velocity, MT_Scalar maxDeltaSpeed,MT_Scalar maxDeltaAngle);
};

#endif