README 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. Dynamics Library.
  2. =================
  3. CONVENTIONS
  4. -----------
  5. matrix storage
  6. --------------
  7. matrix operations like factorization are expensive, so we must store the data
  8. in a way that is most useful to the matrix code. we want the ability to update
  9. the dynamics library without recompiling applications, e.g. so users can take
  10. advantage of new floating point hardware. so we must settle on a single
  11. format. because of the prevalence of 4-way SIMD, the format is this: store
  12. the matrix by rows or columns, and each column is rounded up to a multiple of
  13. 4 elements. the extra "padding" elements at the end of each row/column are set
  14. to 0. this is called the "standard format". to indicate if the data is stored
  15. by rows or columns, we will say "standard row format" or "standard column
  16. format". hopefully this decision will remain good in the future, as more and
  17. more processors have 4-way SIMD, and 3D graphics always needs fast 4x4
  18. matrices.
  19. exception: matrices that have only one column or row (vectors), are always
  20. stored as consecutive elements in standard row format, i.e. there is no
  21. interior padding, only padding at the end.
  22. thus: all 3x1 floating point vectors are stored as 4x1 vectors: (x,x,x,0).
  23. also: all 6x1 spatial velocities and accelerations are split into 3x1 position
  24. and angular components, which are stored as contiguous 4x1 vectors.
  25. ALL matrices are stored by in standard row format.
  26. arguments
  27. ---------
  28. 3x1 vector arguments to set() functions are supplied as x,y,z.
  29. 3x1 vector result arguments to get() function are pointers to arrays.
  30. larger vectors are always supplied and returned as pointers.
  31. all coordinates are in the global frame except where otherwise specified.
  32. output-only arguments are usually supplied at the end.
  33. memory allocation
  34. -----------------
  35. with many C/C++ libraries memory allocation is a difficult problem to solve.
  36. who allocates the memory? who frees it? must objects go on the heap or can
  37. they go on the stack or in static storage? to provide the maximum flexibility,
  38. the dynamics and collision libraries do not do their own memory allocation.
  39. you must pass in pointers to externally allocated chunks of the right sizes.
  40. the body, joint and colllision object structures are all exported, so you
  41. can make instances of those structure and pass pointers to them.
  42. there are helper functions which allocate objects out of areans, in case you
  43. need loots of dynamic creation and deletion.
  44. BUT!!! this ties us down to the body/joint/collision representation.
  45. a better approach is to supply custom memory allocation functions
  46. (e.g. dlAlloc() etc).
  47. C versus C++ ... ?
  48. ------------------
  49. everything should be C linkable, and there should be C header files for
  50. everything. but we want to develop in C++. so do this:
  51. * all comments are "//". automatically convert to /**/ for distribution.
  52. * structures derived from other structures --> automatically convert?
  53. WORLDS
  54. ------
  55. might want better terminology here.
  56. the dynamics world (DWorld) is a list of systems. each system corresponds to
  57. one or more bodies, or perhaps some other kinds of physical object.
  58. each system corresponds to one or more objects in the collision world
  59. (there does not have to be a one-to-one correspondence between bodies and
  60. collision objects).
  61. systems are simulated separately, perhaps using completely different
  62. techniques. we must do something special when systems collide.
  63. systems collide when collision objects belonging to system A touch
  64. collision objects belonging to system B.
  65. for each collision point, the system must provide matrix equation data
  66. that is used to compute collision forces. once those forces are computed,
  67. the system must incorporate the forces into its timestep.
  68. PROBLEM: what if we intertwine the LCP problems of the two systems - then
  69. this simple approach wont work.
  70. the dynamics world contains two kinds of objects: bodies and joints.
  71. joints connect two bodies together.
  72. the world contains one of more partitions. each partition is a collection of
  73. bodies and joints such that each body is attached (through one or more joints)
  74. to every other body.
  75. Joints
  76. ------
  77. a joint can be connected to one or two bodies.
  78. if the joint is only connected to one body, joint.node[1].body == 0.
  79. joint.node[0].body is always valid.
  80. Linkage
  81. -------
  82. this library will always be statically linked with the app, for these reasons:
  83. * collision space is selected at compile time, it adds data to the geom
  84. objects.
  85. Optimization
  86. ------------
  87. doubles must be aligned on 8 byte boundaries!
  88. MinGW on Windows issues
  89. -----------------------
  90. * the .rc file for drawstuff needs a different include, try winresrc.h.
  91. * it seems we can't have both main() and WinMain() without the entry point
  92. defaulting to main() and having resource loading problems. this screws up
  93. what i was trying to do in the drawstuff library. perhaps main2() ?
  94. * remember to compile resources to COFF format RES files.
  95. Collision
  96. ---------
  97. to plug in your own collision handling, replace (some of?) these functions
  98. with your own. collision should be a separate library that you can link in
  99. or not. your own library can call components in this collision library, e.g.
  100. if you want polymorphic spaces instead of a single statically called space.
  101. creating an object will automatically register the appropriate
  102. class (if necessary). how can we ensure that the minimum amount of code is
  103. linked in? e.g. only one space handler, and sphere-sphere and sphere-box and
  104. box-box collision code (if spheres and boxes instanced).
  105. the user creates a collision space, and for each dynamics object that is
  106. created a collision object is inserted into the space. the collision
  107. object's pos and R pointers are set to the corresponding dynamics
  108. variables.
  109. there should be utility functions which create the dynamics and collision
  110. objects at the same time, e.g. dMakeSphere().
  111. collision objects and dynamics objects keep pointers to each other.