drawstuff.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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 Initializes output console.
  80. *
  81. * The function performs initialization routines for the application console.
  82. *
  83. * The function is to be called only if @fn dsSimulationLoop is not invoked.
  84. *
  85. * @param argc Reserved for future use
  86. * @param argv Reserved for future use
  87. * @ingroup drawstuff
  88. */
  89. DS_API void dsInitializeConsole(int argc, char **argv);
  90. /**
  91. * @brief Finalizes output console.
  92. *
  93. * The function performs all the necessary finalization for the application console.
  94. *
  95. * The function is to be called only if @fn dsSimulationLoop is not invoked.
  96. *
  97. * @ingroup drawstuff
  98. */
  99. DS_API void dsFinalizeConsole();
  100. #define DS_SIMULATION_DEFAULT_WIDTH 1280
  101. #define DS_SIMULATION_DEFAULT_HEIGHT 720
  102. /**
  103. * @brief Does the complete simulation.
  104. * @ingroup drawstuff
  105. * This function starts running the simulation, and only exits when the simulation is done.
  106. * Function pointers should be provided for the callbacks.
  107. * @param argv supports flags like '-notex' '-noshadow' '-pause'
  108. * @param fn Callback functions.
  109. */
  110. DS_API void dsSimulationLoop (int argc, char **argv,
  111. int window_width, int window_height,
  112. struct dsFunctions *fn);
  113. /**
  114. * @brief exit with error message.
  115. * @ingroup drawstuff
  116. * This function displays an error message then exit.
  117. * @param msg format strin, like printf, without the newline character.
  118. */
  119. DS_API void dsError (const char *msg, ...);
  120. /**
  121. * @brief exit with error message and core dump.
  122. * @ingroup drawstuff
  123. * this functions tries to dump core or start the debugger.
  124. * @param msg format strin, like printf, without the newline character.
  125. */
  126. DS_API void dsDebug (const char *msg, ...);
  127. /**
  128. * @brief print log message
  129. * @ingroup drawstuff
  130. * @param msg format string, like printf, without the \n.
  131. */
  132. DS_API void dsPrint (const char *msg, ...);
  133. /**
  134. * @brief Sets the viewpoint
  135. * @ingroup drawstuff
  136. * @param xyz camera position.
  137. * @param hpr contains heading, pitch and roll numbers in degrees. heading=0
  138. * points along the x axis, pitch=0 is looking towards the horizon, and
  139. * roll 0 is "unrotated".
  140. */
  141. DS_API void dsSetViewpoint (const float xyz[3], const float hpr[3]);
  142. /**
  143. * @brief Gets the viewpoint
  144. * @ingroup drawstuff
  145. * @param xyz position
  146. * @param hpr heading,pitch,roll.
  147. */
  148. DS_API void dsGetViewpoint (float xyz[3], float hpr[3]);
  149. /**
  150. * @brief Stop the simulation loop.
  151. * @ingroup drawstuff
  152. * Calling this from within dsSimulationLoop()
  153. * will cause it to exit and return to the caller. it is the same as if the
  154. * user used the exit command. using this outside the loop will have no
  155. * effect.
  156. */
  157. DS_API void dsStop();
  158. /**
  159. * @brief Get the elapsed time (on wall-clock)
  160. * @ingroup drawstuff
  161. * It returns the nr of seconds since the last call to this function.
  162. */
  163. DS_API double dsElapsedTime();
  164. /**
  165. * @brief Toggle the rendering of textures.
  166. * @ingroup drawstuff
  167. * It changes the way objects are drawn. these changes will apply to all further
  168. * dsDrawXXX() functions.
  169. * @param the texture number must be a DS_xxx texture constant.
  170. * The current texture is colored according to the current color.
  171. * At the start of each frame, the texture is reset to none and the color is
  172. * reset to white.
  173. */
  174. DS_API void dsSetTexture (int texture_number);
  175. /**
  176. * @brief Set the color with which geometry is drawn.
  177. * @ingroup drawstuff
  178. * @param red Red component from 0 to 1
  179. * @param green Green component from 0 to 1
  180. * @param blue Blue component from 0 to 1
  181. */
  182. DS_API void dsSetColor (float red, float green, float blue);
  183. /**
  184. * @brief Set the color and transparency with which geometry is drawn.
  185. * @ingroup drawstuff
  186. * @param alpha Note that alpha transparency is a misnomer: it is alpha opacity.
  187. * 1.0 means fully opaque, and 0.0 means fully transparent.
  188. */
  189. DS_API void dsSetColorAlpha (float red, float green, float blue, float alpha);
  190. /**
  191. * @brief Draw a box.
  192. * @ingroup drawstuff
  193. * @param pos is the x,y,z of the center of the object.
  194. * @param R is a 3x3 rotation matrix for the object, stored by row like this:
  195. * [ R11 R12 R13 0 ]
  196. * [ R21 R22 R23 0 ]
  197. * [ R31 R32 R33 0 ]
  198. * @param sides[] is an array of x,y,z side lengths.
  199. */
  200. DS_API void dsDrawBox (const float pos[3], const float R[12], const float sides[3]);
  201. /**
  202. * @brief Draw a sphere.
  203. * @ingroup drawstuff
  204. * @param pos Position of center.
  205. * @param R orientation.
  206. * @param radius
  207. */
  208. DS_API void dsDrawSphere (const float pos[3], const float R[12], float radius);
  209. /**
  210. * @brief Draw a triangle.
  211. * @ingroup drawstuff
  212. * @param pos Position of center
  213. * @param R orientation
  214. * @param v0 first vertex
  215. * @param v1 second
  216. * @param v2 third vertex
  217. * @param solid set to 0 for wireframe
  218. */
  219. DS_API void dsDrawTriangle (const float pos[3], const float R[12],
  220. const float *v0, const float *v1, const float *v2, int solid);
  221. /**
  222. * @brief Draw triangles.
  223. * @ingroup drawstuff
  224. * @param pos Position of center
  225. * @param R orientation
  226. * @param v list of vertices (x0, y0, z0, x1, y1, z1, ...)
  227. * @param n number of vertices
  228. * @param solid set to 0 for wireframe
  229. */
  230. DS_API void dsDrawTriangles (const float pos[3], const float R[12],
  231. const float *v, const int n, int solid);
  232. /**
  233. * @brief Draw a z-aligned cylinder
  234. * @ingroup drawstuff
  235. */
  236. DS_API void dsDrawCylinder (const float pos[3], const float R[12],
  237. float length, float radius);
  238. /**
  239. * @brief Draw a z-aligned capsule
  240. * @ingroup drawstuff
  241. */
  242. DS_API void dsDrawCapsule (const float pos[3], const float R[12],
  243. float length, float radius);
  244. /**
  245. * @brief Draw a line.
  246. * @ingroup drawstuff
  247. */
  248. DS_API void dsDrawLine (const float pos1[3], const float pos2[3]);
  249. /**
  250. * @brief Draw a convex shape.
  251. * @ingroup drawstuff
  252. */
  253. DS_API void dsDrawConvex(const float pos[3], const float R[12],
  254. const float *_planes,
  255. unsigned int _planecount,
  256. const float *_points,
  257. unsigned int _pointcount,
  258. const unsigned int *_polygons);
  259. /* these drawing functions are identical to the ones above, except they take
  260. * double arrays for `pos' and `R'.
  261. */
  262. DS_API void dsDrawBoxD (const double pos[3], const double R[12],
  263. const double sides[3]);
  264. DS_API void dsDrawSphereD (const double pos[3], const double R[12],
  265. const float radius);
  266. DS_API void dsDrawTriangleD (const double pos[3], const double R[12],
  267. const double *v0, const double *v1, const double *v2, int solid);
  268. DS_API void dsDrawTrianglesD (const double pos[3], const double R[12],
  269. const double *v, const int n, int solid);
  270. DS_API void dsDrawCylinderD (const double pos[3], const double R[12],
  271. float length, float radius);
  272. DS_API void dsDrawCapsuleD (const double pos[3], const double R[12],
  273. float length, float radius);
  274. DS_API void dsDrawLineD (const double pos1[3], const double pos2[3]);
  275. DS_API void dsDrawConvexD(const double pos[3], const double R[12],
  276. const double *_planes,
  277. unsigned int _planecount,
  278. const double *_points,
  279. unsigned int _pointcount,
  280. const unsigned int *_polygons);
  281. /**
  282. * @brief Set the quality with which curved objects are rendered.
  283. * @ingroup drawstuff
  284. * Higher numbers are higher quality, but slower to draw.
  285. * This must be set before the first objects are drawn to be effective.
  286. * Default sphere quality is 1, default capsule quality is 3.
  287. */
  288. DS_API void dsSetSphereQuality (int n); /* default = 1 */
  289. DS_API void dsSetCapsuleQuality (int n); /* default = 3 */
  290. /**
  291. * @brief Set Drawmode 0=Polygon Fill,1=Wireframe).
  292. * Use the DS_POLYFILL and DS_WIREFRAME macros.
  293. * @ingroup drawstuff
  294. */
  295. DS_API void dsSetDrawMode(int mode);
  296. /* Backwards compatible API */
  297. #define dsDrawCappedCylinder dsDrawCapsule
  298. #define dsDrawCappedCylinderD dsDrawCapsuleD
  299. #define dsSetCappedCylinderQuality dsSetCapsuleQuality
  300. /* closing bracket for extern "C" */
  301. #ifdef __cplusplus
  302. }
  303. #endif
  304. #endif