glVertex  5.5.2
glvertex_physics.h
Go to the documentation of this file.
1 // (c) by Stefan Roettger, licensed under MIT license
2 
5 #ifndef GLVERTEX_PHYSICS_H
6 #define GLVERTEX_PHYSICS_H
7 
8 #include "glvertex_object.h"
9 
10 #ifndef HAVE_BULLET_PHYSICS
16 #else
17 
18 #include <btBulletDynamicsCommon.h>
19 #include <BulletCollision/CollisionShapes/btShapeHull.h>
20 
22 class lgl_BulletPhysics
23 {
24 public:
25 
27  lgl_BulletPhysics()
28  {
29  // build the broadphase
30  broadphase = new btDbvtBroadphase();
31 
32  // set up the collision configuration and dispatcher
33  collisionConfiguration = new btDefaultCollisionConfiguration();
34  dispatcher = new btCollisionDispatcher(collisionConfiguration);
35 
36  // the actual physics solver
37  solver = new btSequentialImpulseConstraintSolver;
38 
39  // the world
40  dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
41 
42  // the ground
43  groundRigidBody = NULL;
44  }
45 
46  ~lgl_BulletPhysics()
47  {
48  if (groundRigidBody)
49  {
50  dynamicsWorld->removeRigidBody(groundRigidBody);
51  deleteBulletData(groundRigidBody);
52  }
53 
54  delete dynamicsWorld;
55  delete solver;
56  delete broadphase;
57  delete dispatcher;
58  delete collisionConfiguration;
59  }
60 
62  void setBulletGroundPlane(vec3 o, vec3 n, double restitution = 1.0)
63  {
64  if (groundRigidBody)
65  {
66  dynamicsWorld->removeRigidBody(groundRigidBody);
67  deleteBulletData(groundRigidBody);
68  groundRigidBody = NULL;
69  }
70 
71  if (n.norm() > 0)
72  {
73  btCollisionShape *groundShape = new btStaticPlaneShape(btVector3(n.x, n.y, n.z), 0);
74  btDefaultMotionState *groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(o.x, o.y, o.z)));
75 
76  btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0, groundMotionState, groundShape, btVector3(0, 0, 0));
77  groundRigidBody = new btRigidBody(groundRigidBodyCI);
78  groundRigidBody->setRestitution(restitution);
79 
80  dynamicsWorld->addRigidBody(groundRigidBody);
81  }
82  }
83 
85  void setBulletGravity(vec3 g)
86  {
87  dynamicsWorld->setGravity(btVector3(g.x, g.y, g.z));
88  }
89 
91  static btRigidBody *createBulletBox(lgl_PhysicalObject<btRigidBody> *pobj)
92  {
93  vec3 ext2 = 0.5*pobj->getExtent();
94  vec3 center = pobj->getCenter();
95  btTransform offset(btQuaternion(0, 0, 0, 1), btVector3(-center.x, -center.y, -center.z));
96 
97  btTransform transform;
98  transform.setFromOpenGLMatrix((const float *)mat4f(mat4::translate(center) * pobj->getTransformation()));
99 
100  btCollisionShape *shape = new btBoxShape(btVector3(ext2.x, ext2.y, ext2.z));
101  btDefaultMotionState *motionState = new btDefaultMotionState(transform, offset);
102 
103  btScalar mass = pobj->getPhysicalMass();
104  btVector3 inertia(0, 0, 0);
105  shape->calculateLocalInertia(mass, inertia);
106 
107  btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(mass, motionState, shape, inertia);
108  btRigidBody *body = new btRigidBody(rigidBodyCI);
109  body->setRestitution(pobj->getPhysicalRestitution());
110  body->setDamping(0.01, 0.05);
111  body->setSleepingThresholds(0.25, 0.25);
112 
113  return(body);
114  }
115 
117  static btRigidBody *createBulletSphere(lgl_PhysicalObject<btRigidBody> *pobj)
118  {
119  double radius = pobj->getRadius();
120  vec3 center = pobj->getCenter();
121  btTransform offset(btQuaternion(0, 0, 0, 1), btVector3(-center.x, -center.y, -center.z));
122 
123  btTransform transform;
124  transform.setFromOpenGLMatrix((const float *)mat4f(mat4::translate(center) * pobj->getTransformation()));
125 
126  btCollisionShape *shape = new btSphereShape(radius);
127  btDefaultMotionState *motionState = new btDefaultMotionState(transform, offset);
128 
129  btScalar mass = pobj->getPhysicalMass();
130  btVector3 inertia(0, 0, 0);
131  shape->calculateLocalInertia(mass, inertia);
132 
133  btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(mass, motionState, shape, inertia);
134  btRigidBody *body = new btRigidBody(rigidBodyCI);
135  body->setRestitution(pobj->getPhysicalRestitution());
136  body->setDamping(0.01, 0.25);
137  body->setSleepingThresholds(0.25, 0.25);
138 
139  return(body);
140  }
141 
143  static btRigidBody *createBulletEllipsoid(lgl_PhysicalObject<btRigidBody> *pobj)
144  {
145  vec3 ext = pobj->getExtent();
146  vec3 center = pobj->getCenter();
147  btTransform offset(btQuaternion(0, 0, 0, 1), btVector3(-center.x, -center.y, -center.z));
148 
149  btTransform transform;
150  transform.setFromOpenGLMatrix((const float *)mat4f(mat4::translate(center) * pobj->getTransformation()));
151 
152  btVector3 pos(0, 0, 0);
153  btScalar rad = 0.5;
154  btCollisionShape *shape = new btMultiSphereShape(&pos, &rad, 1);
155  shape->setLocalScaling(btVector3(ext.x, ext.y, ext.z));
156  shape->setMargin(0);
157 
158  btDefaultMotionState *motionState = new btDefaultMotionState(transform, offset);
159 
160  btScalar mass = pobj->getPhysicalMass();
161  btVector3 inertia(0, 0, 0);
162  shape->calculateLocalInertia(mass, inertia);
163 
164  btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(mass, motionState, shape, inertia);
165  btRigidBody *body = new btRigidBody(rigidBodyCI);
166  body->setRestitution(pobj->getPhysicalRestitution());
167  body->setDamping(0.01, 0.05);
168  body->setSleepingThresholds(0.25, 0.25);
169 
170  return(body);
171  }
172 
174  static btRigidBody *createBulletHull(lgl_PhysicalObject<btRigidBody> *pobj, std::vector<vec3f> &points)
175  {
176  vec3 center = pobj->getCenter();
177  btTransform offset(btQuaternion(0, 0, 0, 1), btVector3(-center.x, -center.y, -center.z));
178 
179  btTransform transform;
180  transform.setFromOpenGLMatrix((const float *)mat4f(mat4::translate(center) * pobj->getTransformation()));
181 
182  btConvexHullShape *shape = new btConvexHullShape();
183  for (unsigned int i=0; i<points.size(); i++) shape->addPoint(btVector3(points[i].x, points[i].y, points[i].z));
184  shape->setMargin(0);
185 
186  btDefaultMotionState *motionState = new btDefaultMotionState(transform, offset);
187 
188  btScalar mass = pobj->getPhysicalMass();
189  btVector3 inertia(0, 0, 0);
190  shape->calculateLocalInertia(mass, inertia);
191 
192  btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(mass, motionState, shape, inertia);
193  btRigidBody *body = new btRigidBody(rigidBodyCI);
194  body->setSleepingThresholds(0.25f, 0.25f);
195 
196  return(body);
197  }
198 
200  static btRigidBody *createSimplifiedBulletHull(lgl_PhysicalObject<btRigidBody> *pobj, std::vector<vec3f> &points)
201  {
202  vec3 center = pobj->getCenter();
203  btTransform offset(btQuaternion(0, 0, 0, 1), btVector3(-center.x, -center.y, -center.z));
204 
205  btTransform transform;
206  transform.setFromOpenGLMatrix((const float *)mat4f(mat4::translate(center) * pobj->getTransformation()));
207 
208  btConvexHullShape *shape = new btConvexHullShape();
209  for (unsigned int i=0; i<points.size(); i++) shape->addPoint(btVector3(points[i].x, points[i].y, points[i].z));
210  shape->setMargin(0);
211 
212  btShapeHull *hull = new btShapeHull(shape);
213  hull->buildHull(shape->getMargin());
214  delete shape;
215 
216  btConvexHullShape *simplified = new btConvexHullShape();
217  for (int i=0; i<hull->numVertices(); i++) simplified->addPoint(hull->getVertexPointer()[i]);
218  simplified->setMargin(0);
219  delete hull;
220 
221  btDefaultMotionState *motionState = new btDefaultMotionState(transform, offset);
222 
223  btScalar mass = pobj->getPhysicalMass();
224  btVector3 inertia(0, 0, 0);
225  simplified->calculateLocalInertia(mass, inertia);
226 
227  btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(mass, motionState, simplified, inertia);
228  btRigidBody *body = new btRigidBody(rigidBodyCI);
229  body->setSleepingThresholds(0.25f, 0.25f);
230 
231  return(body);
232  }
233 
235  void setBulletMass(btRigidBody *body, btScalar mass)
236  {
237  btVector3 inertia(0, 0, 0);
238  body->getCollisionShape()->calculateLocalInertia(mass, inertia);
239  body->setMassProps(mass, inertia);
240  body->activate();
241  }
242 
244  void setBulletFactor(btRigidBody *body, float factor)
245  {
246  if (factor == 0)
247  {
248  body->setLinearVelocity(btVector3(0, 0, 0));
249  body->setAngularVelocity(btVector3(0, 0, 0));
250  body->setLinearFactor(btVector3(0, 0, 0));
251  body->setAngularFactor(btVector3(0, 0, 0));
252  body->setActivationState(DISABLE_DEACTIVATION);
253  }
254  else
255  {
256  body->setLinearFactor(btVector3(factor, factor, factor));
257  body->setAngularFactor(btVector3(factor, factor, factor));
258  body->setActivationState(WANTS_DEACTIVATION);
259  }
260  }
261 
263  void addBulletBody(btRigidBody *body)
264  {
265  dynamicsWorld->addRigidBody(body);
266  }
267 
269  void removeBulletBody(btRigidBody *body)
270  {
271  dynamicsWorld->removeRigidBody(body);
272  }
273 
275  void updateBullet(double dt)
276  {
277  dynamicsWorld->stepSimulation(dt, 3, 1.0/120);
278  }
279 
281  static mat4 getBulletTransformation(lgl_PhysicalObject<btRigidBody> *pobj)
282  {
283  if (btRigidBody *body=pobj->getPhysicalData())
284  {
285  btScalar matrix[16];
286  body->getCenterOfMassTransform().getOpenGLMatrix(matrix);
287 
288  mat4f mtx;
289  mtx.fromOpenGL(matrix);
290  return(mtx);
291  }
292 
293  return(pobj->getTransformation());
294  }
295 
297  static void setBulletTransformation(lgl_PhysicalObject<btRigidBody> *pobj, const mat4 &m)
298  {
299  if (btRigidBody *body=pobj->getPhysicalData())
300  {
301  btTransform transform;
302  transform.setFromOpenGLMatrix((const float *)mat4f(m));
303  body->setWorldTransform(transform);
304  body->setLinearVelocity(btVector3(0, 0, 0));
305  body->setAngularVelocity(btVector3(0, 0, 0));
306  }
307  }
308 
310  static vec3 getBulletVelocity(lgl_PhysicalObject<btRigidBody> *pobj)
311  {
312  if (btRigidBody *body=pobj->getPhysicalData())
313  {
314  btVector3 velocity = body->getLinearVelocity();
315  return(vec3(velocity.x(), velocity.y(), velocity.z()));
316  }
317 
318  return(pobj->getVelocity());
319  }
320 
322  static void setBulletVelocity(lgl_PhysicalObject<btRigidBody> *pobj, const vec3 &v)
323  {
324  if (btRigidBody *body=pobj->getPhysicalData())
325  {
326  btVector3 velocity(v.x, v.y, v.z);
327  body->setLinearVelocity(velocity);
328  }
329  }
330 
332  static void applyBulletForce(lgl_PhysicalObject<btRigidBody> *pobj, vec3 force, vec3 rel_pos = vec3(0,0,0))
333  {
334  if (btRigidBody *body=pobj->getPhysicalData())
335  {
336  body->activate();
337  body->applyForce(btVector3(force.x, force.y, force.z), btVector3(rel_pos.x, rel_pos.y, rel_pos.z));
338  }
339  }
340 
342  static void applyBulletImpulse(lgl_PhysicalObject<btRigidBody> *pobj, vec3 impulse)
343  {
344  if (btRigidBody *body=pobj->getPhysicalData())
345  {
346  body->activate();
347  body->applyCentralImpulse(btVector3(impulse.x, impulse.y, impulse.z));
348  }
349  }
350 
352  static void applyBulletTorque(lgl_PhysicalObject<btRigidBody> *pobj, vec3 torque)
353  {
354  if (btRigidBody *body=pobj->getPhysicalData())
355  {
356  body->activate();
357  body->applyTorqueImpulse(btVector3(torque.x, torque.y, torque.z));
358  }
359  }
360 
362  static void setUserPointer(btRigidBody *body, lgl_PhysicalObject<btRigidBody> *pobj)
363  {
364  body->getCollisionShape()->setUserPointer(pobj);
365  }
366 
368  static lgl_PhysicalObject<btRigidBody> *getUserPointer(const btRigidBody *body)
369  {
370  return((lgl_PhysicalObject<btRigidBody> *)body->getCollisionShape()->getUserPointer());
371  }
372 
374  lgl_PhysicalObject<btRigidBody> *rayTest(const vec3 &from, vec3 &to)
375  {
376  btVector3 f(from.x, from.y, from.z);
377  btVector3 t(to.x, to.y, to.z);
378  btCollisionWorld::ClosestRayResultCallback rayCallback(f, t);
379  dynamicsWorld->rayTest(f, t, rayCallback);
380 
381  if (rayCallback.hasHit()) {
382  const btRigidBody *body = btRigidBody::upcast(rayCallback.m_collisionObject);
383  btVector3 hit = rayCallback.m_hitPointWorld;
384  to = vec3(hit.x(), hit.y(), hit.z());
385  return(getUserPointer(body));
386  }
387 
388  return(NULL);
389  }
390 
392  static void deleteBulletData(lgl_PhysicalObject<btRigidBody> *pobj)
393  {
394  if (btRigidBody *data=pobj->getPhysicalData())
395  deleteBulletData(data);
396  }
397 
399  static void deleteBulletData(btRigidBody *data)
400  {
401  delete data->getMotionState();
402  delete data->getCollisionShape();
403  delete data;
404  }
405 
406 protected:
407 
408  btDiscreteDynamicsWorld *dynamicsWorld;
409  btSequentialImpulseConstraintSolver *solver;
410  btBroadphaseInterface *broadphase;
411  btCollisionDispatcher *dispatcher;
412  btDefaultCollisionConfiguration *collisionConfiguration;
413 
414  btRigidBody *groundRigidBody;
415 };
416 
418 class lgl_BulletGeometryObject: public lgl_PhysicalGeometryObject<btRigidBody>
419 {
420 public:
421 
423  lgl_BulletGeometryObject(lglVBO *vbo = NULL)
424  : lgl_PhysicalGeometryObject<btRigidBody>(vbo)
425  {
426  lgl_BulletPhysics::deleteBulletData(this);
427  }
428 
429 protected:
430 
431  virtual btRigidBody *createPhysicalData()
432  {
433  btRigidBody *body = lgl_BulletPhysics::createBulletBox(this);
434  lgl_BulletPhysics::setUserPointer(body, this);
435  return(body);
436  }
437 
438  virtual mat4 getPhysicalTransformation()
439  {
440  return(lgl_BulletPhysics::getBulletTransformation(this));
441  }
442 
443  virtual void transformationChanged(const mat4 &m)
444  {
445  lgl_BulletPhysics::setBulletTransformation(this, m);
446  }
447 
448  virtual vec3 getPhysicalVelocity()
449  {
450  return(lgl_BulletPhysics::getBulletVelocity(this));
451  }
452 
453  virtual void velocityChanged(const vec3 &v)
454  {
455  lgl_BulletPhysics::setBulletVelocity(this, v);
456  }
457 
458  virtual void applyForce(vec3 force, vec3 rel_pos = vec3(0,0,0))
459  {
460  lgl_BulletPhysics::applyBulletForce(this, force, rel_pos);
461  }
462 
463  virtual void applyImpulse(vec3 impulse)
464  {
465  lgl_BulletPhysics::applyBulletImpulse(this, impulse);
466  }
467 
468  virtual void applyTorque(vec3 torque)
469  {
470  lgl_BulletPhysics::applyBulletTorque(this, torque);
471  }
472 
473 };
474 
477 {
478 public:
479 
482  : lgl_PhysicalSceneGraphObject<btRigidBody>(root)
483  {
484  lgl_BulletPhysics::deleteBulletData(this);
485  }
486 
487 protected:
488 
489  virtual btRigidBody *createPhysicalData()
490  {
491  btRigidBody *body = lgl_BulletPhysics::createBulletBox(this);
492  lgl_BulletPhysics::setUserPointer(body, this);
493  return(body);
494  }
495 
496  virtual mat4 getPhysicalTransformation()
497  {
498  return(lgl_BulletPhysics::getBulletTransformation(this));
499  }
500 
501  virtual void transformationChanged(const mat4 &m)
502  {
503  lgl_BulletPhysics::setBulletTransformation(this, m);
504  }
505 
506  virtual vec3 getPhysicalVelocity()
507  {
508  return(lgl_BulletPhysics::getBulletVelocity(this));
509  }
510 
511  virtual void velocityChanged(const vec3 &v)
512  {
513  lgl_BulletPhysics::setBulletVelocity(this, v);
514  }
515 
516  virtual void applyForce(vec3 force, vec3 rel_pos = vec3(0,0,0))
517  {
518  lgl_BulletPhysics::applyBulletForce(this, force, rel_pos);
519  }
520 
521  virtual void applyImpulse(vec3 impulse)
522  {
523  lgl_BulletPhysics::applyBulletImpulse(this, impulse);
524  }
525 
526  virtual void applyTorque(vec3 torque)
527  {
528  lgl_BulletPhysics::applyBulletTorque(this, torque);
529  }
530 
531 };
532 
534 class lgl_BulletCubeObject: public lgl_PhysicalCubeObject<btRigidBody>
535 {
536 public:
537 
540  : lgl_PhysicalCubeObject<btRigidBody>()
541  {
542  lgl_BulletPhysics::deleteBulletData(this);
543  }
544 
545 protected:
546 
547  virtual btRigidBody *createPhysicalData()
548  {
549  btRigidBody *body = lgl_BulletPhysics::createBulletBox(this);
550  lgl_BulletPhysics::setUserPointer(body, this);
551  return(body);
552  }
553 
554  virtual mat4 getPhysicalTransformation()
555  {
556  return(lgl_BulletPhysics::getBulletTransformation(this));
557  }
558 
559  virtual void transformationChanged(const mat4 &m)
560  {
561  lgl_BulletPhysics::setBulletTransformation(this, m);
562  }
563 
564  virtual vec3 getPhysicalVelocity()
565  {
566  return(lgl_BulletPhysics::getBulletVelocity(this));
567  }
568 
569  virtual void velocityChanged(const vec3 &v)
570  {
571  lgl_BulletPhysics::setBulletVelocity(this, v);
572  }
573 
574  virtual void applyForce(vec3 force, vec3 rel_pos = vec3(0,0,0))
575  {
576  lgl_BulletPhysics::applyBulletForce(this, force, rel_pos);
577  }
578 
579  virtual void applyImpulse(vec3 impulse)
580  {
581  lgl_BulletPhysics::applyBulletImpulse(this, impulse);
582  }
583 
584  virtual void applyTorque(vec3 torque)
585  {
586  lgl_BulletPhysics::applyBulletTorque(this, torque);
587  }
588 
589 };
590 
592 class lgl_BulletSphereObject: public lgl_PhysicalSphereObject<btRigidBody>
593 {
594 public:
595 
598  : lgl_PhysicalSphereObject<btRigidBody>()
599  {
600  lgl_BulletPhysics::deleteBulletData(this);
601  }
602 
603 protected:
604 
605  virtual btRigidBody *createPhysicalData()
606  {
607  btRigidBody *body;
608 
609  if (hasUniformScale())
610  body = lgl_BulletPhysics::createBulletSphere(this);
611  else
612  body = lgl_BulletPhysics::createBulletEllipsoid(this);
613 
614  lgl_BulletPhysics::setUserPointer(body, this);
615 
616  return(body);
617  }
618 
619  virtual mat4 getPhysicalTransformation()
620  {
621  return(lgl_BulletPhysics::getBulletTransformation(this));
622  }
623 
624  virtual void transformationChanged(const mat4 &m)
625  {
626  lgl_BulletPhysics::setBulletTransformation(this, m);
627  }
628 
629  virtual vec3 getPhysicalVelocity()
630  {
631  return(lgl_BulletPhysics::getBulletVelocity(this));
632  }
633 
634  virtual void velocityChanged(const vec3 &v)
635  {
636  lgl_BulletPhysics::setBulletVelocity(this, v);
637  }
638 
639  virtual void applyForce(vec3 force, vec3 rel_pos = vec3(0,0,0))
640  {
641  lgl_BulletPhysics::applyBulletForce(this, force, rel_pos);
642  }
643 
644  virtual void applyImpulse(vec3 impulse)
645  {
646  lgl_BulletPhysics::applyBulletImpulse(this, impulse);
647  }
648 
649  virtual void applyTorque(vec3 torque)
650  {
651  lgl_BulletPhysics::applyBulletTorque(this, torque);
652  }
653 
654 };
655 
657 class lgl_BulletObjects: public lgl_BulletPhysics, public lgl_PhysicalObjects<btRigidBody>
658 {
659 public:
660 
661  typedef lgl_PhysicalObjects<btRigidBody>::iterator iterator;
662 
665  : lgl_BulletPhysics(),
666  lgl_PhysicalObjects<btRigidBody>()
667  {
668  setBulletGroundPlane(ground_o, ground_n, ground_r);
669  }
670 
671  virtual ~lgl_BulletObjects()
672  {}
673 
675  void setGroundPlane(vec3 o, vec3 n, double r = 1.0)
676  {
678  setBulletGroundPlane(ground_o, ground_n, ground_r);
679  }
680 
682  void setGravity(double g)
683  {
685  setBulletGravity(ground_n*ground_g);
686  }
687 
689  iterator begin()
690  {
692  }
693 
695  iterator end()
696  {
698  }
699 
700 protected:
701 
702  virtual void objectAdded(lgl_PhysicalObject<btRigidBody> *pobj)
703  {
704  if (btRigidBody *body=pobj->getPhysicalData())
705  addBulletBody(body);
706  }
707 
708  virtual void objectRemoved(lgl_PhysicalObject<btRigidBody> *pobj)
709  {
710  if (btRigidBody *body=pobj->getPhysicalData())
711  removeBulletBody(body);
712  }
713 
714  virtual void objectDeactivated(lgl_PhysicalObject<btRigidBody> *pobj, bool yes)
715  {
716  if (btRigidBody *body=pobj->getPhysicalData())
717  setBulletFactor(body, yes?0:1);
718  }
719 
720  virtual void updatePhysicalObjects(double dt)
721  {
722  updateBullet(dt);
723  }
724 
725 };
726 
727 #endif
728 
729 #endif
lgl_Node
scene graph node (base class)
Definition: glvertex_nodes.h:22
lgl_NoPhysicalSceneGraphObject::applyImpulse
virtual void applyImpulse(vec3 impulse)
apply linear impulse to center of mass
Definition: glvertex_object.h:1128
lgl_PhysicalCubeObject
physical cube object (base template)
Definition: glvertex_object.h:1140
lgl_NoPhysicalGeometryObject::applyTorque
virtual void applyTorque(vec3 torque)
apply angular impulse to center of mass
Definition: glvertex_object.h:1004
lgl_NoPhysicalCubeObject::applyTorque
virtual void applyTorque(vec3 torque)
apply angular impulse to center of mass
Definition: glvertex_object.h:1171
lgl_NoPhysicalSceneGraphObject::applyForce
virtual void applyForce(vec3 force, vec3 rel_pos=vec3(0, 0, 0))
apply force to point relative to center of mass
Definition: glvertex_object.h:1127
mat4f
4x4 float matrix
Definition: glslmath.h:2752
lgl_PhysicalObjects< void * >::end
iterator end()
end iterator
Definition: glvertex_object.h:1313
lgl_NoPhysicalSphereObject::applyImpulse
virtual void applyImpulse(vec3 impulse)
apply linear impulse to center of mass
Definition: glvertex_object.h:1225
lgl_PhysicalObject
physical object (base template)
Definition: glvertex_object.h:762
lgl_NoPhysicalGeometryObject::applyForce
virtual void applyForce(vec3 force, vec3 rel_pos=vec3(0, 0, 0))
apply force to point relative to center of mass
Definition: glvertex_object.h:1002
vec3::norm
double norm() const
get squared vector length
Definition: glslmath.h:423
vec3
3D double vector
Definition: glslmath.h:372
lgl_PhysicalObject::getPhysicalMass
double getPhysicalMass()
get physical mass
Definition: glvertex_object.h:803
mat4
4x4 double matrix
Definition: glslmath.h:2116
lgl_Object::getCenter
virtual vec3 getCenter()
get object barycenter relative to object position
Definition: glvertex_object.h:127
lgl_NoPhysicalGeometryObject
no physical geometry object (empty physics implementation)
Definition: glvertex_object.h:988
lgl_NoPhysicalSphereObject::applyForce
virtual void applyForce(vec3 force, vec3 rel_pos=vec3(0, 0, 0))
apply force to point relative to center of mass
Definition: glvertex_object.h:1224
lgl_PhysicalObjects< void * >::begin
iterator begin()
begin iterator
Definition: glvertex_object.h:1307
lgl_PhysicalGeometryObject
physical geometry object (base template)
Definition: glvertex_object.h:916
mat4f::fromOpenGL
void fromOpenGL(const float m[16])
convert from 16-element column-major OpenGL matrix
Definition: glslmath.h:2907
lgl_PhysicalObject::getPhysicalData
T * getPhysicalData()
get physical data
Definition: glvertex_object.h:781
lgl_Object::getRadius
virtual double getRadius()
get bounding object radius
Definition: glvertex_object.h:139
lgl_NoPhysicalSphereObject::applyTorque
virtual void applyTorque(vec3 torque)
apply angular impulse to center of mass
Definition: glvertex_object.h:1226
lgl_Object::getTransformation
mat4 getTransformation()
get object transformation
Definition: glvertex_object.h:81
lgl_NoPhysicalCubeObject::applyForce
virtual void applyForce(vec3 force, vec3 rel_pos=vec3(0, 0, 0))
apply force to point relative to center of mass
Definition: glvertex_object.h:1169
lglVBO
LGL API: vbo class definition.
Definition: glvertex_core.h:5827
lgl_PhysicalObjects
container class for multiple physical objects (base template)
Definition: glvertex_object.h:1236
lgl_NoPhysicalCubeObject
no physical cube object (empty physics implementation)
Definition: glvertex_object.h:1155
lgl_PhysicalSceneGraphObject
physical scene graph object (base template)
Definition: glvertex_object.h:1015
lgl_PhysicalSphereObject
physical sphere object (base template)
Definition: glvertex_object.h:1182
glvertex_object.h
lgl_NoPhysicalSceneGraphObject
no physical scene graph object (empty physics implementation)
Definition: glvertex_object.h:1113
lgl_Object::getExtent
virtual vec3 getExtent()
get bounding box extent
Definition: glvertex_object.h:133
lgl_NoPhysicalSphereObject
no physical sphere object (empty physics implementation)
Definition: glvertex_object.h:1210
lgl_Object::hasUniformScale
bool hasUniformScale()
object has uniform scale?
Definition: glvertex_object.h:121
lgl_PhysicalObjects< void * >::setGravity
void setGravity(double g)
set gravity
Definition: glvertex_object.h:1329
mat4::translate
static mat4 translate(double x, double y, double z)
create translation matrix
Definition: glslmath.h:2427
lgl_PhysicalObject::getVelocity
vec3 getVelocity()
get object velocity
Definition: glvertex_object.h:880
lgl_NoPhysicalCubeObject::applyImpulse
virtual void applyImpulse(vec3 impulse)
apply linear impulse to center of mass
Definition: glvertex_object.h:1170
lgl_PhysicalObject< void * >::createPhysicalData
virtual void * * createPhysicalData()
create physical data
Definition: glvertex_object.h:797
lgl_PhysicalObject::getPhysicalRestitution
double getPhysicalRestitution()
get physical restitution
Definition: glvertex_object.h:816
lgl_NoPhysicalGeometryObject::applyImpulse
virtual void applyImpulse(vec3 impulse)
apply linear impulse to center of mass
Definition: glvertex_object.h:1003
lgl_PhysicalObjects< void * >::setGroundPlane
void setGroundPlane(vec3 o, vec3 n, double r=1.0)
set ground plane
Definition: glvertex_object.h:1321
lgl_NoPhysicalObjects
container class for multiple non-physical objects (empty physics implementation)
Definition: glvertex_object.h:1368
lgl_NoPhysicalSceneGraphObject::applyTorque
virtual void applyTorque(vec3 torque)
apply angular impulse to center of mass
Definition: glvertex_object.h:1129