PhysicsMaterials.h
1 /************************************************************
2 * (C) Voxel Farm Inc. 2015
3 */
4 
5 #pragma once
6 
7 #include "VoxelFarmConfig.h"
8 
9 // we support per-material physics properties. currently, the following 10 basic materials are defined.
10 namespace VoxelFarm
11 {
12  namespace Physics
13  {
14  // base material classes used for realistic physics simulation
15  enum materialClasses
16  {
17  MAT_CORK = 0,
18  MAT_WOOD,
19  MAT_ICE,
20  MAT_WATER,
21  MAT_PLASTIC,
22  MAT_CONCRETE,
23  MAT_ROCK,
24  MAT_METAL,
25  MAT_HELIUM,
26  MAT_DEFAULT
27  };
28  static const unsigned char cMATCLASSES = 10;
29 
30  // common physics properties
31  const float CONST_GRAVITY = -100.f; // ~1x gravity [dm^2/s]
32  const float AIR_DENSITY = 0.000001205f; // air density [Mg/dm^3]
33  const float TERM_VEL = 550.f; // ~terminal velocity [dm/s]
34 
35  // physics material library (one entry per materialClass)
37  {
38  public:
39  CPhysicsMaterialLibrary() { initMaterials(); };
40  private:
41  struct matData
42  {
43  double density; // approx. material density [Mg/dm^3]
44  float* friction = NULL; // coeff of friction [dimensionless]
45  float* rfriction = NULL; // coeff of rolling friction [dimensionless]
46  float restitution; // coeff of restitution (i.e. elasticity) [dimensionless]
47  double cstrength; // compressive strength (breaking pressure -- fracture) [Mg/(dm*s^2)]
48  matData()
49  {
50  friction = (float*)VF_RAWALLOC(cMATCLASSES*sizeof(float));
51  rfriction = (float*)VF_RAWALLOC(cMATCLASSES*sizeof(float));
52  }
53  ~matData()
54  {
55  VF_FREE(friction);
56  VF_FREE(rfriction);
57  }
58  matData& operator =(const matData& a)
59  {
60  density = a.density;
61  restitution = a.restitution;
62  cstrength = a.cstrength;
63  memcpy(friction, a.friction, cMATCLASSES*sizeof(float));
64  memcpy(rfriction, a.rfriction, cMATCLASSES*sizeof(float));
65  return *this;
66  }
67  };
68  void initMaterials();
69  public:
70  TMap<int, matData> m_materials;
71  };
72  };
73 };
Contains all classes and functions for the VoxelFarm engine.