Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.14 KB | None | 0 0
  1. Index: src/scenes/critterding/entities/bodypart.cpp
  2. ===================================================================
  3. --- src/scenes/critterding/entities/bodypart.cpp (revision 849)
  4. +++ src/scenes/critterding/entities/bodypart.cpp (working copy)
  5. @@ -10,10 +10,15 @@
  6.  
  7. shape = new btBoxShape( dimensions );
  8.  
  9. + cerr << "Bodypart dimensions: " << dimensions.x() << ":" << dimensions.y() << ":" << dimensions.z() << endl;
  10. btVector3 localInertia(0,0,0);
  11. - if (weight != 0.f) // weight of non zero = dynamic
  12. - shape->calculateLocalInertia(weight,localInertia);
  13. + if (weight == 0.f) // weight of non zero = dynamic
  14. + {
  15. + cerr << "Danger, static bodypart." << endl;
  16. + }
  17.  
  18. + shape->calculateLocalInertia(weight,localInertia);
  19. +
  20. myMotionState = new btDefaultMotionState(offset*transform);
  21.  
  22. btRigidBody::btRigidBodyConstructionInfo rbInfo(weight,myMotionState,shape,localInertia);
  23. @@ -40,29 +45,9 @@
  24.  
  25. void Bodypart::changeScale(float scale)
  26. {
  27. - m_ownerWorld->getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs(body->getBroadphaseHandle(),m_ownerWorld->getDispatcher());
  28. - m_ownerWorld->removeRigidBody(body);
  29. - delete body;
  30. -
  31. shape->setLocalScaling(btVector3(scale,scale,scale));
  32. -
  33. - btVector3 localInertia(0,0,0);
  34. - if (weight != 0.f) // weight of non zero = dynamic
  35. - shape->calculateLocalInertia(weight,localInertia);
  36. -
  37. -
  38. - btRigidBody::btRigidBodyConstructionInfo rbInfo(weight,myMotionState,shape,localInertia);
  39. - body = new btRigidBody(rbInfo);
  40. const btBoxShape* boxShape = static_cast<const btBoxShape*>(shape);
  41. halfExtent = boxShape->getHalfExtentsWithMargin();
  42. -
  43. - // Has to be cast to Entity* for RTTI to continue to allow dynamic_cast<>
  44. - body->setUserPointer(dynamic_cast<Entity*>(this));
  45. - body->setDamping(0.05, 0.85);
  46. - body->setDeactivationTime(0.001);
  47. - body->setSleepingThresholds(1.6, 2.5);
  48. -
  49. - m_ownerWorld->addRigidBody(body);
  50. }
  51.  
  52. Bodypart::~Bodypart()
  53. Index: src/scenes/critterding/entities/worldb.cpp
  54. ===================================================================
  55. --- src/scenes/critterding/entities/worldb.cpp (revision 849)
  56. +++ src/scenes/critterding/entities/worldb.cpp (working copy)
  57. @@ -112,6 +112,7 @@
  58. m_dynamicsWorld->getSolverInfo().m_solverMode = SOLVER_USE_WARMSTARTING | SOLVER_SIMD | SOLVER_ENABLE_FRICTION_DIRECTION_CACHING;
  59. m_dynamicsWorld->getSolverInfo().m_numIterations = 8;
  60.  
  61. + m_dynamicsWorld->setGravity( btVector3(0.0f, -1.0f * (float)settings->getCVar("gravity"), 0.0f) );
  62. // raycast
  63. raycast = new Raycast(m_dynamicsWorld);
  64.  
  65. @@ -297,7 +298,9 @@
  66.  
  67. void WorldB::childPositionOffset(btVector3* v)
  68. {
  69. - v->setY(insertHight);
  70. + float worldscalefactor = (float)Settings::Instance()->getCVar("worldscalefactor");
  71. + float wsf_inv = worldscalefactor / 1000.0f;
  72. + v->setY(insertHight / wsf_inv);
  73. }
  74.  
  75. void WorldB::procreate( CritterB* c )
  76. @@ -656,7 +659,12 @@
  77.  
  78. btVector3 WorldB::findPosition()
  79. {
  80. - return btVector3( (float)randgen->Instance()->get( 0, 100**worldsizeX ) / 100, insertHight, (float)randgen->Instance()->get( 0, 100**worldsizeY ) / 100 );
  81. + float worldscalefactor = (float)Settings::Instance()->getCVar("worldscalefactor");
  82. + float wsf_inv = worldscalefactor / 1000.0f;
  83. + float sX = *worldsizeX / wsf_inv;
  84. + float sY = *worldsizeY / wsf_inv;
  85. +
  86. + return btVector3( (float)randgen->Instance()->get( 0, 100*sX ) / 100, insertHight/wsf_inv, (float)randgen->Instance()->get( 0, 100*sY ) / 100 );
  87. }
  88.  
  89. void WorldB::removeCritter(unsigned int cid)
  90. @@ -882,11 +890,16 @@
  91.  
  92. void WorldB::resetCamera()
  93. {
  94. - unsigned int biggest = *worldsizeX;
  95. - if ( *worldsizeY > biggest )
  96. - biggest = 1.4f**worldsizeY;
  97. + float worldscalefactor = (float)Settings::Instance()->getCVar("worldscalefactor");
  98. + float wsf_inv = worldscalefactor / 1000.0f;
  99. + float sX = *worldsizeX / wsf_inv;
  100. + float sY = *worldsizeY / wsf_inv;
  101.  
  102. - m_sceneNodeCamera.setOrigin( btVector3( 0.5f**worldsizeX, 1.3f*biggest, 0.5f**worldsizeY) );
  103. + unsigned int biggest = sX;
  104. + if ( sY > biggest )
  105. + biggest = 1.4f * sY;
  106. +
  107. + m_sceneNodeCamera.setOrigin( btVector3( 0.5f * sX, 1.3f * biggest, 0.5f * sY) );
  108. // camera.position.setRotation(btQuaternion(btVector3(1, 0, 0), btScalar(90)));
  109. m_sceneNodeCamera.pitch( -SIMD_HALF_PI ); // 1.5707f (float)*energy/10
  110.  
  111. @@ -1015,15 +1028,21 @@
  112. }
  113. }
  114.  
  115. + float worldscalefactor = (float)Settings::Instance()->getCVar("worldscalefactor");
  116. // Wall Constants
  117. - float WallWidth = 0.5f;
  118. + float WallWidth = 500.0f / worldscalefactor;
  119. + float WallHeight = 2000.0f * (float)Settings::Instance()->getCVar("worldsizeZ") / worldscalefactor;
  120. float WallHalfWidth = WallWidth/2.0f;
  121. - float WallHeight = 2.0f;
  122. float WallHalfHeight = WallHeight/2.0f;
  123.  
  124. + float wsf_inv = worldscalefactor / 1000.0f;
  125. // Ground Floor
  126. - btVector3 position( *worldsizeX/2.0f, -WallHalfWidth, *worldsizeY/2.0f );
  127. - Wall* w = new Wall( *worldsizeX, WallWidth, *worldsizeY, position, m_dynamicsWorld, BeColor(0.3f,0.2f,0.1f,0.0f));
  128. +
  129. + float sX = *worldsizeX / wsf_inv;
  130. + float sY = *worldsizeY / wsf_inv;
  131. + //float sZ = *worldsizeZ / wsf_inv;
  132. + btVector3 position( sX/2.0f, -WallHalfWidth, sY/2.0f );
  133. + Wall* w = new Wall( sX, WallWidth, sY, position, m_dynamicsWorld, BeColor(0.3f,0.2f,0.1f,0.0f));
  134. entities.push_back(w);
  135.  
  136. if ( settings->getCVar("worldwalls") )
  137. @@ -1035,20 +1054,20 @@
  138. wc.a=0.0f;
  139.  
  140. // Left Wall
  141. - position = btVector3 ( 0.0f-WallHalfWidth, WallHalfHeight-WallWidth, *worldsizeY/2.0f );
  142. - w = new Wall( WallWidth, WallHeight, *worldsizeY, position, m_dynamicsWorld, wc );
  143. + position = btVector3 ( 0.0f-WallHalfWidth, WallHalfHeight-WallWidth, sY/2.0f );
  144. + w = new Wall( WallWidth, WallHeight, sY, position, m_dynamicsWorld, wc );
  145. entities.push_back(w);
  146. // Right Wall
  147. - position = btVector3 ( *worldsizeX+WallHalfWidth, WallHalfHeight-WallWidth, *worldsizeY/2.0f );
  148. - w = new Wall( WallWidth, WallHeight, *worldsizeY, position, m_dynamicsWorld, wc );
  149. + position = btVector3 ( sX+WallHalfWidth, WallHalfHeight-WallWidth, sY/2.0f );
  150. + w = new Wall( WallWidth, WallHeight, sY, position, m_dynamicsWorld, wc );
  151. entities.push_back(w);
  152. // Top Wall
  153. - position = btVector3 ( *worldsizeX/2.0f, WallHalfHeight-WallWidth, 0.0f-WallHalfWidth );
  154. - w = new Wall( *worldsizeX+(WallWidth*2), WallHeight, WallWidth, position, m_dynamicsWorld, wc );
  155. + position = btVector3 ( sX/2.0f, WallHalfHeight-WallWidth, 0.0f-WallHalfWidth );
  156. + w = new Wall( sX+(WallWidth*2), WallHeight, WallWidth, position, m_dynamicsWorld, wc );
  157. entities.push_back(w);
  158. // Bottom Wall
  159. - position = btVector3 ( *worldsizeX/2.0f, WallHalfHeight-WallWidth, *worldsizeY+WallHalfWidth );
  160. - w = new Wall( *worldsizeX+(WallWidth*2), WallHeight, WallWidth, position, m_dynamicsWorld, wc );
  161. + position = btVector3 ( sX/2.0f, WallHalfHeight-WallWidth, sY+WallHalfWidth );
  162. + w = new Wall( sX+(WallWidth*2), WallHeight, WallWidth, position, m_dynamicsWorld, wc );
  163. entities.push_back(w);
  164. }
  165. }
  166. Index: src/scenes/critterding/entities/body.cpp
  167. ===================================================================
  168. --- src/scenes/critterding/entities/body.cpp (revision 849)
  169. +++ src/scenes/critterding/entities/body.cpp (working copy)
  170. @@ -91,22 +91,25 @@
  171. transform.setIdentity();
  172. transform.setOrigin( btVector3( 0.0f, 0.0f, 0.0f ) );
  173.  
  174. + float worldscalefactor = (float)Settings::Instance()->getCVar("worldscalefactor");
  175. + float densityscalefactor = (float)Settings::Instance()->getCVar("densityscalefactor");
  176. +
  177. for ( unsigned int i=0; i < bodyArch->archBodyparts.size(); i++ )
  178. {
  179. archBodypart *bp = &bodyArch->archBodyparts[i];
  180.  
  181. // calculate weight
  182. - float weight = ((bp->x*bp->y*bp->z)/1000) * 0.001f; // FIXME 0.001 is density of material
  183. + float weight = ((bp->x*bp->y*bp->z)/worldscalefactor) * 0.001f * densityscalefactor; // FIXME 0.001 is density of material
  184. totalWeight += weight;
  185.  
  186. Bodypart *b = NULL;
  187. if ( bp->type == archBodypart::DEFAULT )
  188. {
  189. - b = new Bodypart(m_ownerWorld, owner, btVector3( bp->x/1000, bp->y/1000, bp->z/1000 ), weight, offset, transform, bodycolor, CRITTER);
  190. + b = new Bodypart(m_ownerWorld, owner, btVector3( bp->x/worldscalefactor, bp->y/worldscalefactor, bp->z/worldscalefactor ), weight, offset, transform, bodycolor, CRITTER);
  191. b->addColor(speciescolor);
  192. }
  193. else if ( bp->type == archBodypart::HEAD )
  194. - b = new Mouth(m_ownerWorld, owner, btVector3( bp->x/1000, bp->y/1000, bp->z/1000 ), weight, offset, transform, BeColor(1.0f,0.0f,0.0f,0.0f));
  195. + b = new Mouth(m_ownerWorld, owner, btVector3( bp->x/worldscalefactor, bp->y/worldscalefactor, bp->z/worldscalefactor ), weight, offset, transform, BeColor(1.0f,0.0f,0.0f,0.0f));
  196.  
  197. bodyparts.push_back( b );
  198.  
  199. @@ -118,13 +121,15 @@
  200. {
  201. archConstraint *co = &bodyArch->archConstraints[i];
  202.  
  203. + float wsf_inv = 1000/worldscalefactor;
  204. +
  205. localA.setIdentity();
  206. localA.getBasis().setEulerZYX( co->rot_x_1, co->rot_y_1, co->rot_z_1 );
  207. - localA.setOrigin( btVector3(co->pos_x_1, co->pos_y_1, co->pos_z_1) );
  208. + localA.setOrigin( btVector3(co->pos_x_1*wsf_inv, co->pos_y_1*wsf_inv, co->pos_z_1*wsf_inv) );
  209.  
  210. localB.setIdentity();
  211. localB.getBasis().setEulerZYX( co->rot_x_2, co->rot_y_2, co->rot_z_2 );
  212. - localB.setOrigin( btVector3(co->pos_x_2, co->pos_y_2, co->pos_z_2) );
  213. + localB.setOrigin( btVector3(co->pos_x_2*wsf_inv, co->pos_y_2*wsf_inv, co->pos_z_2*wsf_inv) );
  214.  
  215. // find the ID's to connect
  216. int bpID_1 = bodyArch->findBodypart( co->id_1 );
  217. Index: src/scenes/critterding/entities/constraint.cpp
  218. ===================================================================
  219. --- src/scenes/critterding/entities/constraint.cpp (revision 849)
  220. +++ src/scenes/critterding/entities/constraint.cpp (working copy)
  221. @@ -80,7 +80,7 @@
  222. hinge->setMaxMotorImpulse(*maximumimpulse);
  223. }
  224. else
  225. - hinge->enableAngularMotor(true, (f1 + f2 - 10)*10, *maximumimpulse);
  226. + hinge->enableAngularMotor(true, (f1 + f2 - 10)*100, *maximumimpulse);
  227. }
  228.  
  229. Constraint::~Constraint()
  230. Index: src/scenes/critterding/entities/food.cpp
  231. ===================================================================
  232. --- src/scenes/critterding/entities/food.cpp (revision 849)
  233. +++ src/scenes/critterding/entities/food.cpp (working copy)
  234. @@ -11,7 +11,7 @@
  235. color.r = 0.0f;
  236. color.g = 0.5f;
  237. color.b = 0.0f;
  238. - color.a = 0.5f;
  239. + color.a = 0.0f;
  240.  
  241. body.m_ownerWorld = m_dynamicsWorld;
  242.  
  243. @@ -21,7 +21,9 @@
  244. btTransform transform; transform.setIdentity();
  245. transform.setOrigin( btVector3(0.0f, 0.10f, 0.0f) );
  246.  
  247. - body.addBodyPart_Box(this, (float)*food_size/1000, (float)*food_size/1000, (float)*food_size/1000, 1.0f, offset, transform, color, FOOD);
  248. + float worldscalefactor = (float)Settings::Instance()->getCVar("worldscalefactor");
  249. + body.addBodyPart_Box(this, (float)*food_size/worldscalefactor, (float)*food_size/worldscalefactor, (float)*food_size/worldscalefactor,
  250. + Settings::Instance()->getCVar("densityscalefactor"), offset, transform, color, FOOD);
  251.  
  252. myMotionState = (btDefaultMotionState*)body.bodyparts[0]->body->getMotionState();
  253. boxShape = static_cast<btBoxShape*>(body.bodyparts[0]->shape);
  254. Index: src/common/be_mouse_picker.cpp
  255. ===================================================================
  256. --- src/common/be_mouse_picker.cpp (revision 849)
  257. +++ src/common/be_mouse_picker.cpp (working copy)
  258. @@ -18,8 +18,8 @@
  259.  
  260. // create constraint and add it to bulletworld
  261. constraint = new btPoint2PointConstraint(*pickedBody,localPivot);
  262. - constraint->m_setting.m_impulseClamp = 30.f;
  263. - constraint->m_setting.m_tau = 0.1f;
  264. + //constraint->m_setting.m_impulseClamp = 500000.f;
  265. + //constraint->m_setting.m_tau = 0.1f;
  266. btDynWorld->addConstraint(constraint);
  267.  
  268. oldPickingDist = (attachPosition - rayFrom).length();
  269. Index: src/critterding.cpp
  270. ===================================================================
  271. --- src/critterding.cpp (revision 849)
  272. +++ src/critterding.cpp (working copy)
  273. @@ -57,8 +57,11 @@
  274. settings->registerCVar("camerasensitivity", 20, 1, 1000, false, "sensitivity of the camera");
  275.  
  276. settings->registerCVar("maximumimpulse", 5000, 0, 1000000, false, "maximum impulse per-tick");
  277. - settings->registerCVar("absolutemotorneurons", 0, 0, 1, true, "muscle neurons determine angle + dt directly");
  278. - settings->registerCVar("selfcollisions", 1, 0, 1, true, "critters can exploit physics glitches");
  279. + settings->registerCVar("absolutemotorneurons", 0, 0, 1, true, "muscle neurons determine angle + dt directly");
  280. + settings->registerCVar("selfcollisions", 0, 0, 1, true, "critters can exploit physics glitches");
  281. + settings->registerCVar("worldscalefactor", 1000, 1, 1000, false, "all world sizes reduced by a factor of");
  282. + settings->registerCVar("densityscalefactor", 1, 1, 1000000, false, "all world densities increased by a factor of");
  283. + settings->registerCVar("gravity", 10, 1, 1000, false, "force of gravity");
  284.  
  285. settings->registerCVar("colormode", 0, 0, 1, true, "colors genetically exact critters identically");
  286. settings->registerCVar("exit_if_empty", 0, 0, 1, true, "exit simulation if there are no critters");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement