Advertisement
Guest User

RagdollDemo.h

a guest
Dec 27th, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.35 KB | None | 0 0
  1. /*
  2. RagdollDemo.h
  3. */
  4.  
  5. #ifndef RAGDOLLDEMO_H
  6. #define RAGDOLLDEMO_H
  7.  
  8.  
  9. #include "GlutDemoApplication.h"
  10. #include "GLDebugDrawer.h"
  11. #include "btBulletCollisionCommon.h"
  12. #include "btBulletDynamicsCommon.h"
  13.  
  14.  
  15. int ConsoleWait(void);
  16.  
  17. class RagdollDemo : public GlutDemoApplication
  18. {
  19.     //keep the collision shapes, for deletion/cleanup
  20.     btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
  21.  
  22.     btBroadphaseInterface * m_broadphase;
  23.     btCollisionDispatcher * m_dispatcher;
  24.     btConstraintSolver    * m_solver;
  25.     btDefaultCollisionConfiguration * m_collisionConfiguration;
  26.  
  27.     // one main body,
  28.     // 4x2 leg segments,
  29.     // one north marker,
  30.     // 4 ball elbows.    
  31.     btCollisionShape  * geom[42];  
  32.     btHingeConstraint * joints[8];
  33.     btFixedConstraint * welds[4];
  34.     btCollisionObject * fixedGround;
  35.  
  36.     int IDs[45];
  37.     bool oneStep;
  38.     bool pause;
  39.     double globaljointA;
  40.     double currjointA[8];  
  41.     unsigned long int simtick; 
  42.    
  43.     double touchsensor[4];
  44.    
  45.  
  46. public:
  47.     btRigidBody       * body[42];
  48.     double weights[4][8];
  49.     bool OPTdrawgraphics;
  50.     bool OPTloadbestweights;
  51.     char OPTbestweightsfile[80];
  52.     int touches[43];
  53.     btVector3 touchPoints[43];
  54.     unsigned long int timeStep;
  55.     int threadID;
  56.     bool position_sane;
  57.  
  58. public:
  59.     void initPhysics();
  60.     void exitPhysics();
  61.  
  62.     virtual ~RagdollDemo()
  63.     {
  64.         exitPhysics();
  65.     }
  66.      
  67.     virtual void clientMoveAndDisplay();
  68.     virtual void displayCallback();
  69.     virtual void keyboardCallback(unsigned char key, int x, int y);
  70.    
  71.     static DemoApplication* Create()
  72.     {
  73.         RagdollDemo* demo = new RagdollDemo();
  74.         demo->myinit();
  75.         demo->initPhysics();
  76.         return demo;
  77.     }
  78.  
  79.      virtual void renderme() {               
  80.         extern GLDebugDrawer gDebugDrawer;
  81.         // Call the parent method.
  82.         GlutDemoApplication::renderme();
  83.      }
  84.  
  85.     void CreateBox(
  86.         int index,
  87.         double x,       double y,       double z,
  88.         double length,  double width,   double height );
  89.  
  90.     void CreateCylinder(
  91.         int index,
  92.         double x,       double y,       double z,
  93.         double length,  double width,   double height,
  94.         double xrot ,   double yrot ,   double zrot );
  95.    
  96.     void CreateSphere(
  97.         int index,
  98.         double x,       double y,       double z,
  99.         double radius );
  100.  
  101.     void BuildWallofCans(void);
  102.  
  103.     void CreateHinge(int index,
  104.                      int body1, int body2,
  105.                      double x, double y, double z,
  106.                      double ax, double ay, double az);
  107.  
  108.     void CreateWeld(int index,
  109.                      int body1, int body2 );
  110.  
  111.     void DeleteObject( int index );
  112.     void DestroyHinge( int index );
  113.     void DestroyWeld(  int index );
  114.  
  115.     void ActuateJoint(  int jointIndex, double desiredAngle,
  116.                         double jointOffset, double timeStep);
  117.  
  118.     void ActuateJoint2( int jointIndex, double desiredAngle,
  119.                         double jointOffset, double timeStep);
  120.  
  121.     btVector3 PointWorldToLocal(int index, btVector3 &p);
  122.     btVector3 AxisWorldToLocal( int index, btVector3 &a);
  123.     double ConvertActuatorToJoint(int index, double actang);
  124.     double RandomJoint(void);
  125.     double RandomWeight(void);
  126.     void ConsoleFloat(double cf);
  127.     void ConsoleTouches(void);
  128.     int GetFileWeights(char * GFWname );
  129.     int SavePosition( btRigidBody * spbody, char * SPname );
  130.     void WeightFileHandler(void);
  131.     double Fitness(void);
  132.     void AssignToCallback(void);
  133.     bool SanityCheck(double maxbound);
  134.     inline bool airborne(void);
  135. };
  136.  
  137. inline bool RagdollDemo::airborne(void)
  138. {
  139.     return( (touches[5]==0) && (touches[6]==0) &&  (touches[7]==0) &&(touches[8]==0)    );
  140. }
  141.  
  142.  
  143. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement