RigsofRods
Soft-body Physics Simulation
PointColDetector.h
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2009 Lefteris Stamatogiannakis
4 
5  For more information, see http://www.rigsofrods.org/
6 
7  Rigs of Rods is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License version 3, as
9  published by the Free Software Foundation.
10 
11  Rigs of Rods is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include "Application.h"
23 
24 namespace RoR {
25 
28 
31 
33 {
34 public:
35 
36  struct pointid_t // use PointidID_t for indexing
37  {
40  };
41 
42  std::vector<PointidID_t> hit_list;
43  std::unordered_set<ActorInstanceID_t> hit_list_actorset;
44  std::vector<pointid_t> hit_pointid_list;
45 
47 
48  void UpdateIntraPoint(bool contactables = false);
49  void UpdateInterPoint(bool ignorestate = false);
50  void query(const Ogre::Vector3& vec1, const Ogre::Vector3& vec2, const Ogre::Vector3& vec3, const float enlargeBB);
51 
52 private:
53 
54  struct refelem_t // use RefelemID_t for indexing
55  {
57  std::array<float, 3> point; // cached node AbsPosition
58  void setPoint(const Ogre::Vector3 pos) { point[0] = pos.x; point[1] = pos.y; point[2] = pos.z; }
59  };
60 
61  struct kdnode_t
62  {
63  float min;
64  int end;
65  float max;
67  float middle;
68  int begin;
69  };
70 
72  std::vector<ActorInstanceID_t> m_collision_partners;
73  std::vector<refelem_t> m_ref_list;
74 
75  std::vector<kdnode_t> m_kdtree;
76  Ogre::Vector3 m_bbmin = Ogre::Vector3::ZERO;
77  Ogre::Vector3 m_bbmax = Ogre::Vector3::ZERO;
79 
80  void queryrec(int kdindex, int axis);
81  void build_kdtree_incr(int axis, int index);
82  void partintwo(const int start, const int median, const int end, const int axis, float& minex, float& maxex);
83  void update_structures_for_contacters(bool ignoreinternal);
85 };
86 
89 
90 } // namespace RoR
RoR::PointColDetector::kdnode_t::max
float max
Definition: PointColDetector.h:65
RoR::PointColDetector::hit_pointid_list
std::vector< pointid_t > hit_pointid_list
Definition: PointColDetector.h:44
RoR::PointColDetector::m_bbmax
Ogre::Vector3 m_bbmax
Definition: PointColDetector.h:77
RoR::RefelemID_t
int RefelemID_t
index to PointColDetector::m_ref_list, use RoR::REFELEMID_INVALID as empty value.
Definition: ForwardDeclarations.h:46
RoR::NODENUM_INVALID
static const NodeNum_t NODENUM_INVALID
Definition: ForwardDeclarations.h:53
RoR::PointidID_t
int PointidID_t
index to PointColDetector::hit_pointid_list, use RoR::POINTIDID_INVALID as empty value.
Definition: ForwardDeclarations.h:43
RoR::PointColDetector::m_kdtree
std::vector< kdnode_t > m_kdtree
Definition: PointColDetector.h:75
RoR::PointColDetector::PointColDetector
PointColDetector(ActorPtr actor)
Definition: PointColDetector.h:46
RefCountingObjectPtr< Actor >
RoR::PointColDetector::UpdateInterPoint
void UpdateInterPoint(bool ignorestate=false)
Definition: PointColDetector.cpp:51
RoR::PointColDetector::m_bbmin
Ogre::Vector3 m_bbmin
Definition: PointColDetector.h:76
RoR::PointColDetector::kdnode_t::min
float min
Definition: PointColDetector.h:63
RoR::PointColDetector::m_ref_list
std::vector< refelem_t > m_ref_list
Definition: PointColDetector.h:73
RoR::ActorInstanceID_t
int ActorInstanceID_t
Unique sequentially generated ID of an actor in session. Use ActorManager::GetActorById()
Definition: ForwardDeclarations.h:37
RoR::NodeNum_t
uint16_t NodeNum_t
Node position within Actor::ar_nodes; use RoR::NODENUM_INVALID as empty value.
Definition: ForwardDeclarations.h:52
RoR::PointColDetector::pointid_t::actorid
ActorInstanceID_t actorid
Definition: PointColDetector.h:38
RoR::POINTIDID_INVALID
static const PointidID_t POINTIDID_INVALID
Definition: ForwardDeclarations.h:44
RoR::ACTORINSTANCEID_INVALID
static const ActorInstanceID_t ACTORINSTANCEID_INVALID
Definition: ForwardDeclarations.h:38
RoR::PointColDetector::kdnode_t::end
int end
Definition: PointColDetector.h:64
RoR::PointColDetector::m_object_list_size
int m_object_list_size
Definition: PointColDetector.h:78
RoR::PointColDetector::refelem_t::pidrefid
PointidID_t pidrefid
Definition: PointColDetector.h:56
RoR::PointColDetector::refelem_t::setPoint
void setPoint(const Ogre::Vector3 pos)
Definition: PointColDetector.h:58
Application.h
Central state/object manager and communications hub.
RoR::PointColDetector::refresh_node_positions
void refresh_node_positions()
Definition: PointColDetector.cpp:342
RoR::PointColDetector
Definition: PointColDetector.h:32
RoR::PointColDetector::refelem_t::point
std::array< float, 3 > point
Definition: PointColDetector.h:57
RoR::PointColDetector::hit_list
std::vector< PointidID_t > hit_list
Definition: PointColDetector.h:42
RoR::PointColDetector::pointid_t::nodenum
NodeNum_t nodenum
Definition: PointColDetector.h:39
RoR::PointColDetector::queryrec
void queryrec(int kdindex, int axis)
Definition: PointColDetector.cpp:159
RoR::PointColDetector::pointid_t
Definition: PointColDetector.h:36
RoR::PointColDetector::m_actor
ActorPtr m_actor
Definition: PointColDetector.h:71
RoR::REFELEMID_INVALID
static const RefelemID_t REFELEMID_INVALID
Definition: ForwardDeclarations.h:47
RoR::PointColDetector::hit_list_actorset
std::unordered_set< ActorInstanceID_t > hit_list_actorset
Definition: PointColDetector.h:43
RoR::PointColDetector::kdnode_t::begin
int begin
Definition: PointColDetector.h:68
RoR::PointColDetector::UpdateIntraPoint
void UpdateIntraPoint(bool contactables=false)
Definition: PointColDetector.cpp:30
RoR::PointColDetector::kdnode_t
Definition: PointColDetector.h:61
RoR::PointColDetector::refelem_t
Definition: PointColDetector.h:54
RoR::PointColDetector::kdnode_t::middle
float middle
Definition: PointColDetector.h:67
RoR
Definition: AppContext.h:36
RoR::PointColDetector::update_structures_for_contacters
void update_structures_for_contacters(bool ignoreinternal)
Definition: PointColDetector.cpp:97
RoR::PointColDetector::partintwo
void partintwo(const int start, const int median, const int end, const int axis, float &minex, float &maxex)
Definition: PointColDetector.cpp:292
RoR::PointColDetector::m_collision_partners
std::vector< ActorInstanceID_t > m_collision_partners
IntraPoint: always just owning actor; InterPoint: all colliding actors.
Definition: PointColDetector.h:72
RoR::PointColDetector::query
void query(const Ogre::Vector3 &vec1, const Ogre::Vector3 &vec2, const Ogre::Vector3 &vec3, const float enlargeBB)
Definition: PointColDetector.cpp:126
RoR::PointColDetector::kdnode_t::refid
RefelemID_t refid
Definition: PointColDetector.h:66
RoR::PointColDetector::build_kdtree_incr
void build_kdtree_incr(int axis, int index)
Definition: PointColDetector.cpp:223