drawstuff.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /*************************************************************************
  2. * *
  3. * Open Dynamics Engine, Copyright (C) 2001-2003 Russell L. Smith. *
  4. * All rights reserved. Email: [email protected] Web: www.q12.org *
  5. * *
  6. * This library is free software; you can redistribute it and/or *
  7. * modify it under the terms of EITHER: *
  8. * (1) The GNU Lesser General Public License as published by the Free *
  9. * Software Foundation; either version 2.1 of the License, or (at *
  10. * your option) any later version. The text of the GNU Lesser *
  11. * General Public License is included with this library in the *
  12. * file LICENSE.TXT. *
  13. * (2) The BSD-style license that is included with this library in *
  14. * the file LICENSE-BSD.TXT. *
  15. * *
  16. * This library is distributed in the hope that it will be useful, *
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
  19. * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
  20. * *
  21. *************************************************************************/
  22. /** @defgroup drawstuff DrawStuff
  23. DrawStuff is a library for rendering simple 3D objects in a virtual
  24. environment, for the purposes of demonstrating the features of ODE.
  25. It is provided for demonstration purposes and is not intended for
  26. production use.
  27. @section Notes
  28. In the virtual world, the z axis is "up" and z=0 is the floor.
  29. The user is able to click+drag in the main window to move the camera:
  30. * left button - pan and tilt.
  31. * right button - forward and sideways.
  32. * left + right button (or middle button) - sideways and up.
  33. */
  34. #ifndef __DRAWSTUFF_H__
  35. #define __DRAWSTUFF_H__
  36. /* Define a DLL export symbol for those platforms that need it */
  37. #if defined(ODE_PLATFORM_WINDOWS)
  38. #if defined(DS_DLL)
  39. #define DS_API __declspec(dllexport)
  40. #elif !defined(DS_LIB)
  41. #define DS_DLL_API __declspec(dllimport)
  42. #endif
  43. #endif
  44. #if !defined(DS_API)
  45. #define DS_API
  46. #endif
  47. #ifdef __cplusplus
  48. extern "C" {
  49. #endif
  50. #include <drawstuff/version.h>
  51. /* texture numbers */
  52. enum DS_TEXTURE_NUMBER
  53. {
  54. DS_NONE = 0, /* uses the current color instead of a texture */
  55. DS_WOOD,
  56. DS_CHECKERED,
  57. DS_GROUND,
  58. DS_SKY
  59. };
  60. /* draw modes */
  61. #define DS_POLYFILL 0
  62. #define DS_WIREFRAME 1
  63. /**
  64. * @struct dsFunctions
  65. * @brief Set of functions to be used as callbacks by the simulation loop.
  66. * @ingroup drawstuff
  67. */
  68. typedef struct dsFunctions {
  69. int version; /* put DS_VERSION here */
  70. /* version 1 data */
  71. void (*start)(); /* called before sim loop starts */
  72. void (*step) (int pause); /* called before every frame */
  73. void (*command) (int cmd); /* called if a command key is pressed */
  74. void (*stop)(); /* called after sim loop exits */
  75. /* version 2 data */
  76. const char *path_to_textures; /* if nonzero, path to texture files */
  77. } dsFunctions;
  78. /**
  79. * @brief Does the complete simulation.
  80. * @ingroup drawstuff
  81. * This function starts running the simulation, and only exits when the simulation is done.
  82. * Function pointers should be provided for the callbacks.
  83. * @param argv supports flags like '-notex' '-noshadow' '-pause'
  84. * @param fn Callback functions.
  85. */
  86. DS_API void dsSimulationLoop (int argc, char **argv,
  87. int window_width, int window_height,
  88. struct dsFunctions *fn);
  89. /**
  90. * @brief exit with error message.
  91. * @ingroup drawstuff
  92. * This function displays an error message then exit.
  93. * @param msg format strin, like printf, without the newline character.
  94. */
  95. DS_API void dsError (const char *msg, ...);
  96. /**
  97. * @brief exit with error message and core dump.
  98. * @ingroup drawstuff
  99. * this functions tries to dump core or start the debugger.
  100. * @param msg format strin, like printf, without the newline character.
  101. */
  102. DS_API void dsDebug (const char *msg, ...);
  103. /**
  104. * @brief print log message
  105. * @ingroup drawstuff
  106. * @param msg format string, like printf, without the \n.
  107. */
  108. DS_API void dsPrint (const char *msg, ...);
  109. /**
  110. * @brief Sets the viewpoint
  111. * @ingroup drawstuff
  112. * @param xyz camera position.
  113. * @param hpr contains heading, pitch and roll numbers in degrees. heading=0
  114. * points along the x axis, pitch=0 is looking towards the horizon, and
  115. * roll 0 is "unrotated".
  116. */
  117. DS_API void dsSetViewpoint (float xyz[3], float hpr[3]);
  118. /**
  119. * @brief Gets the viewpoint
  120. * @ingroup drawstuff
  121. * @param xyz position
  122. * @param hpr heading,pitch,roll.
  123. */
  124. DS_API void dsGetViewpoint (float xyz[3], float hpr[3]);
  125. /**
  126. * @brief Stop the simulation loop.
  127. * @ingroup drawstuff
  128. * Calling this from within dsSimulationLoop()
  129. * will cause it to exit and return to the caller. it is the same as if the
  130. * user used the exit command. using this outside the loop will have no
  131. * effect.
  132. */
  133. DS_API void dsStop();
  134. /**
  135. * @brief Get the elapsed time (on wall-clock)
  136. * @ingroup drawstuff
  137. * It returns the nr of seconds since the last call to this function.
  138. */
  139. DS_API double dsElapsedTime();
  140. /**
  141. * @brief Toggle the rendering of textures.
  142. * @ingroup drawstuff
  143. * It changes the way objects are drawn. these changes will apply to all further
  144. * dsDrawXXX() functions.
  145. * @param the texture number must be a DS_xxx texture constant.
  146. * The current texture is colored according to the current color.
  147. * At the start of each frame, the texture is reset to none and the color is
  148. * reset to white.
  149. */
  150. DS_API void dsSetTexture (int texture_number);
  151. /**
  152. * @brief Set the color with which geometry is drawn.
  153. * @ingroup drawstuff
  154. * @param red Red component from 0 to 1
  155. * @param green Green component from 0 to 1
  156. * @param blue Blue component from 0 to 1
  157. */
  158. DS_API void dsSetColor (float red, float green, float blue);
  159. /**
  160. * @brief Set the color and transparency with which geometry is drawn.
  161. * @ingroup drawstuff
  162. * @param alpha Note that alpha transparency is a misnomer: it is alpha opacity.
  163. * 1.0 means fully opaque, and 0.0 means fully transparent.
  164. */
  165. DS_API void dsSetColorAlpha (float red, float green, float blue, float alpha);
  166. /**
  167. * @brief Draw a box.
  168. * @ingroup drawstuff
  169. * @param pos is the x,y,z of the center of the object.
  170. * @param R is a 3x3 rotation matrix for the object, stored by row like this:
  171. * [ R11 R12 R13 0 ]
  172. * [ R21 R22 R23 0 ]
  173. * [ R31 R32 R33 0 ]
  174. * @param sides[] is an array of x,y,z side lengths.
  175. */
  176. DS_API void dsDrawBox (const float pos[3], const float R[12], const float sides[3]);
  177. /**
  178. * @brief Draw a sphere.
  179. * @ingroup drawstuff
  180. * @param pos Position of center.
  181. * @param R orientation.
  182. * @param radius
  183. */
  184. DS_API void dsDrawSphere (const float pos[3], const float R[12], float radius);
  185. /**
  186. * @brief Draw a triangle.
  187. * @ingroup drawstuff
  188. * @param pos Position of center
  189. * @param R orientation
  190. * @param v0 first vertex
  191. * @param v1 second
  192. * @param v2 third vertex
  193. * @param solid set to 0 for wireframe
  194. */
  195. DS_API void dsDrawTriangle (const float pos[3], const float R[12],
  196. const float *v0, const float *v1, const float *v2, int solid);
  197. /**
  198. * @brief Draw a z-aligned cylinder
  199. * @ingroup drawstuff
  200. */
  201. DS_API void dsDrawCylinder (const float pos[3], const float R[12],
  202. float length, float radius);
  203. /**
  204. * @brief Draw a z-aligned capsule
  205. * @ingroup drawstuff
  206. */
  207. DS_API void dsDrawCapsule (const float pos[3], const float R[12],
  208. float length, float radius);
  209. /**
  210. * @brief Draw a line.
  211. * @ingroup drawstuff
  212. */
  213. DS_API void dsDrawLine (const float pos1[3], const float pos2[3]);
  214. /**
  215. * @brief Draw a convex shape.
  216. * @ingroup drawstuff
  217. */
  218. DS_API void dsDrawConvex(const float pos[3], const float R[12],
  219. const float *_planes,
  220. unsigned int _planecount,
  221. const float *_points,
  222. unsigned int _pointcount,
  223. const unsigned int *_polygons);
  224. /* these drawing functions are identical to the ones above, except they take
  225. * double arrays for `pos' and `R'.
  226. */
  227. DS_API void dsDrawBoxD (const double pos[3], const double R[12],
  228. const double sides[3]);
  229. DS_API void dsDrawSphereD (const double pos[3], const double R[12],
  230. const float radius);
  231. DS_API void dsDrawTriangleD (const double pos[3], const double R[12],
  232. const double *v0, const double *v1, const double *v2, int solid);
  233. DS_API void dsDrawCylinderD (const double pos[3], const double R[12],
  234. float length, float radius);
  235. DS_API void dsDrawCapsuleD (const double pos[3], const double R[12],
  236. float length, float radius);
  237. DS_API void dsDrawLineD (const double pos1[3], const double pos2[3]);
  238. DS_API void dsDrawConvexD(const double pos[3], const double R[12],
  239. const double *_planes,
  240. unsigned int _planecount,
  241. const double *_points,
  242. unsigned int _pointcount,
  243. const unsigned int *_polygons);
  244. /**
  245. * @brief Set the quality with which curved objects are rendered.
  246. * @ingroup drawstuff
  247. * Higher numbers are higher quality, but slower to draw.
  248. * This must be set before the first objects are drawn to be effective.
  249. * Default sphere quality is 1, default capsule quality is 3.
  250. */
  251. DS_API void dsSetSphereQuality (int n); /* default = 1 */
  252. DS_API void dsSetCapsuleQuality (int n); /* default = 3 */
  253. /**
  254. * @brief Set Drawmode 0=Polygon Fill,1=Wireframe).
  255. * Use the DS_POLYFILL and DS_WIREFRAME macros.
  256. * @ingroup drawstuff
  257. */
  258. DS_API void dsSetDrawMode(int mode);
  259. /* Backwards compatible API */
  260. #define dsDrawCappedCylinder dsDrawCapsule
  261. #define dsDrawCappedCylinderD dsDrawCapsuleD
  262. #define dsSetCappedCylinderQuality dsSetCapsuleQuality
  263. /* closing bracket for extern "C" */
  264. #ifdef __cplusplus
  265. }
  266. #endif
  267. #endif