30 #include "BulletSoftBody/btSoftRigidDynamicsWorld.h"
37 #include <boost/random/random_device.hpp>
38 #include <boost/random/uniform_int_distribution.hpp>
48 tgRigidAutoCompound::tgRigidAutoCompound(std::vector<tgRigidInfo*> rigids)
50 m_rigids.insert(m_rigids.end(), rigids.begin(), rigids.end());
53 tgRigidAutoCompound::tgRigidAutoCompound(std::deque<tgRigidInfo*> rigids) : m_rigids(rigids)
56 std::vector< tgRigidInfo* > tgRigidAutoCompound::execute() {
65 for(
int i=0; i < m_groups.size(); i++) {
68 setRigidInfoForGroup(m_compounded[i], m_groups[i]);
76 void tgRigidAutoCompound::setRigidBodyForGroup(btCollisionObject* body, std::deque<tgRigidInfo*>& group) {
77 for(
int i = 0; i < group.size(); i++) {
78 group[i]->setCollisionObject(body);
82 void tgRigidAutoCompound::setRigidInfoForGroup(
tgRigidInfo* rigidInfo, std::deque<tgRigidInfo*>& group) {
83 for(
int i = 0; i < group.size(); i++) {
84 group[i]->setRigidInfoGroup(rigidInfo);
88 void tgRigidAutoCompound::groupRigids()
90 std::deque<tgRigidInfo*> ungrouped = std::deque<tgRigidInfo*>(m_rigids);
92 while(ungrouped.size() > 0) {
98 std::deque<tgRigidInfo*> group = findGroup(elem, ungrouped);
101 m_groups.push_back(group);
107 std::deque<tgRigidInfo*> tgRigidAutoCompound::findGroup(
tgRigidInfo* rigid, std::deque<tgRigidInfo*>& ungrouped) {
109 std::deque<tgRigidInfo*> group;
112 group.push_back(rigid);
115 ungrouped.erase(std::remove(ungrouped.begin(), ungrouped.end(), rigid), ungrouped.end());
119 while(i < ungrouped.size()) {
122 std::deque<tgRigidInfo*> links = findGroup(other, ungrouped);
123 group.insert(group.end(), links.begin(), links.end());
134 for(
int i=0; i < m_groups.size(); i++) {
135 std::deque<tgRigidInfo*>& group = m_groups[i];
136 if(group.size() == 1) {
138 m_compounded.push_back(group[0]);
141 m_compounded.push_back(compound);
146 tgRigidInfo* tgRigidAutoCompound::createCompound(std::deque<tgRigidInfo*> rigids) {
150 std::stringstream newtag;
152 for(
int i = 0; i < rigids.size(); i++) {
153 rigids[i]->addTags(newtag.str());
159 bool tgRigidAutoCompound::rigidBelongsIn(
tgRigidInfo* rigid, std::deque<tgRigidInfo*> group) {
160 for(
int i = 0; i < group.size(); i++) {
182 boost::random::random_device rng;
185 static const char alphanum[] =
187 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
189 "abcdefghijklmnopqrstuvwxyz";
192 boost::random::uniform_int_distribution<> alphanum_dist(0,
sizeof(alphanum) - 1);
197 for (
int i = 0; i < length; ++i) {
199 s[i] = alphanum[ alphanum_dist(rng) ];
std::string random_tag_hash()
virtual bool sharesNodesWith(const tgRigidInfo &other) const
Definition of class tgCompoundRigidInfo.
void addRigid(tgRigidInfo &rigid)
Rand seeding simular to the evolution and terrain classes.
Definition of class tgRigidAutoCompound.