1 /*************************************************************************
3 * Open Dynamics Engine, Copyright (C) 2001-2003 Russell L. Smith. *
4 * All rights reserved. Email: russ@q12.org Web: www.q12.org *
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 *
13 * (2) The BSD-style license that is included with this library in *
14 * the file LICENSE-BSD.TXT. *
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. *
21 *************************************************************************/
23 /** @defgroup drawstuff DrawStuff
25 DrawStuff is a library for rendering simple 3D objects in a virtual
26 environment, for the purposes of demonstrating the features of ODE.
27 It is provided for demonstration purposes and is not intended for
32 In the virtual world, the z axis is "up" and z=0 is the floor.
34 The user is able to click+drag in the main window to move the camera:
35 * left button - pan and tilt.
36 * right button - forward and sideways.
37 * left + right button (or middle button) - sideways and up.
41 #ifndef __DRAWSTUFF_H__
42 #define __DRAWSTUFF_H__
44 /* Define a DLL export symbol for those platforms that need it */
45 #if defined(ODE_PLATFORM_WINDOWS)
47 #define DS_API __declspec(dllexport)
48 #elif !defined(DS_LIB)
49 #define DS_DLL_API __declspec(dllimport)
62 #include <drawstuff/version.h>
66 enum DS_TEXTURE_NUMBER
68 DS_NONE
= 0, /* uses the current color instead of a texture */
78 #define DS_WIREFRAME 1
82 * @brief Set of functions to be used as callbacks by the simulation loop.
85 typedef struct dsFunctions
{
86 int version
; /* put DS_VERSION here */
88 void (*start
)(); /* called before sim loop starts */
89 void (*step
) (int pause
); /* called before every frame */
90 void (*command
) (int cmd
); /* called if a command key is pressed */
91 void (*stop
)(); /* called after sim loop exits */
93 const char *path_to_textures
; /* if nonzero, path to texture files */
98 * @brief Initializes output console.
100 * The function performs initialization routines for the application console.
102 * The function is to be called only if @fn dsSimulationLoop is not invoked.
104 * @param argc Reserved for future use
105 * @param argv Reserved for future use
108 DS_API
void dsInitializeConsole(int argc
, char **argv
);
112 * @brief Finalizes output console.
114 * The function performs all the necessary finalization for the application console.
116 * The function is to be called only if @fn dsSimulationLoop is not invoked.
120 DS_API
void dsFinalizeConsole();
124 * @brief Does the complete simulation.
126 * This function starts running the simulation, and only exits when the simulation is done.
127 * Function pointers should be provided for the callbacks.
128 * @param argv supports flags like '-notex' '-noshadow' '-pause'
129 * @param fn Callback functions.
131 DS_API
void dsSimulationLoop (int argc
, char **argv
,
132 int window_width
, int window_height
,
133 struct dsFunctions
*fn
);
136 * @brief exit with error message.
138 * This function displays an error message then exit.
139 * @param msg format strin, like printf, without the newline character.
141 DS_API
void dsError (const char *msg
, ...);
144 * @brief exit with error message and core dump.
146 * this functions tries to dump core or start the debugger.
147 * @param msg format strin, like printf, without the newline character.
149 DS_API
void dsDebug (const char *msg
, ...);
152 * @brief print log message
154 * @param msg format string, like printf, without the \n.
156 DS_API
void dsPrint (const char *msg
, ...);
159 * @brief Sets the viewpoint
161 * @param xyz camera position.
162 * @param hpr contains heading, pitch and roll numbers in degrees. heading=0
163 * points along the x axis, pitch=0 is looking towards the horizon, and
164 * roll 0 is "unrotated".
166 DS_API
void dsSetViewpoint (float xyz
[3], float hpr
[3]);
170 * @brief Gets the viewpoint
172 * @param xyz position
173 * @param hpr heading,pitch,roll.
175 DS_API
void dsGetViewpoint (float xyz
[3], float hpr
[3]);
178 * @brief Stop the simulation loop.
180 * Calling this from within dsSimulationLoop()
181 * will cause it to exit and return to the caller. it is the same as if the
182 * user used the exit command. using this outside the loop will have no
185 DS_API
void dsStop();
188 * @brief Get the elapsed time (on wall-clock)
190 * It returns the nr of seconds since the last call to this function.
192 DS_API
double dsElapsedTime();
195 * @brief Toggle the rendering of textures.
197 * It changes the way objects are drawn. these changes will apply to all further
198 * dsDrawXXX() functions.
199 * @param the texture number must be a DS_xxx texture constant.
200 * The current texture is colored according to the current color.
201 * At the start of each frame, the texture is reset to none and the color is
204 DS_API
void dsSetTexture (int texture_number
);
207 * @brief Set the color with which geometry is drawn.
209 * @param red Red component from 0 to 1
210 * @param green Green component from 0 to 1
211 * @param blue Blue component from 0 to 1
213 DS_API
void dsSetColor (float red
, float green
, float blue
);
216 * @brief Set the color and transparency with which geometry is drawn.
218 * @param alpha Note that alpha transparency is a misnomer: it is alpha opacity.
219 * 1.0 means fully opaque, and 0.0 means fully transparent.
221 DS_API
void dsSetColorAlpha (float red
, float green
, float blue
, float alpha
);
226 * @param pos is the x,y,z of the center of the object.
227 * @param R is a 3x3 rotation matrix for the object, stored by row like this:
231 * @param sides[] is an array of x,y,z side lengths.
233 DS_API
void dsDrawBox (const float pos
[3], const float R
[12], const float sides
[3]);
236 * @brief Draw a sphere.
238 * @param pos Position of center.
239 * @param R orientation.
242 DS_API
void dsDrawSphere (const float pos
[3], const float R
[12], float radius
);
245 * @brief Draw a triangle.
247 * @param pos Position of center
248 * @param R orientation
249 * @param v0 first vertex
251 * @param v2 third vertex
252 * @param solid set to 0 for wireframe
254 DS_API
void dsDrawTriangle (const float pos
[3], const float R
[12],
255 const float *v0
, const float *v1
, const float *v2
, int solid
);
258 * @brief Draw triangles.
260 * @param pos Position of center
261 * @param R orientation
262 * @param v list of vertices (x0, y0, z0, x1, y1, z1, ...)
263 * @param n number of vertices
264 * @param solid set to 0 for wireframe
266 DS_API
void dsDrawTriangles (const float pos
[3], const float R
[12],
267 const float *v
, const int n
, int solid
);
270 * @brief Draw a z-aligned cylinder
273 DS_API
void dsDrawCylinder (const float pos
[3], const float R
[12],
274 float length
, float radius
);
277 * @brief Draw a z-aligned capsule
280 DS_API
void dsDrawCapsule (const float pos
[3], const float R
[12],
281 float length
, float radius
);
284 * @brief Draw a line.
287 DS_API
void dsDrawLine (const float pos1
[3], const float pos2
[3]);
290 * @brief Draw a convex shape.
293 DS_API
void dsDrawConvex(const float pos
[3], const float R
[12],
294 const float *_planes
,
295 unsigned int _planecount
,
296 const float *_points
,
297 unsigned int _pointcount
,
298 const unsigned int *_polygons
);
300 /* these drawing functions are identical to the ones above, except they take
301 * double arrays for `pos' and `R'.
303 DS_API
void dsDrawBoxD (const double pos
[3], const double R
[12],
304 const double sides
[3]);
305 DS_API
void dsDrawSphereD (const double pos
[3], const double R
[12],
307 DS_API
void dsDrawTriangleD (const double pos
[3], const double R
[12],
308 const double *v0
, const double *v1
, const double *v2
, int solid
);
309 DS_API
void dsDrawTrianglesD (const double pos
[3], const double R
[12],
310 const double *v
, const int n
, int solid
);
311 DS_API
void dsDrawCylinderD (const double pos
[3], const double R
[12],
312 float length
, float radius
);
313 DS_API
void dsDrawCapsuleD (const double pos
[3], const double R
[12],
314 float length
, float radius
);
315 DS_API
void dsDrawLineD (const double pos1
[3], const double pos2
[3]);
316 DS_API
void dsDrawConvexD(const double pos
[3], const double R
[12],
317 const double *_planes
,
318 unsigned int _planecount
,
319 const double *_points
,
320 unsigned int _pointcount
,
321 const unsigned int *_polygons
);
324 * @brief Set the quality with which curved objects are rendered.
326 * Higher numbers are higher quality, but slower to draw.
327 * This must be set before the first objects are drawn to be effective.
328 * Default sphere quality is 1, default capsule quality is 3.
330 DS_API
void dsSetSphereQuality (int n
); /* default = 1 */
331 DS_API
void dsSetCapsuleQuality (int n
); /* default = 3 */
334 * @brief Set Drawmode 0=Polygon Fill,1=Wireframe).
335 * Use the DS_POLYFILL and DS_WIREFRAME macros.
338 DS_API
void dsSetDrawMode(int mode
);
340 /* Backwards compatible API */
341 #define dsDrawCappedCylinder dsDrawCapsule
342 #define dsDrawCappedCylinderD dsDrawCapsuleD
343 #define dsSetCappedCylinderQuality dsSetCapsuleQuality
345 /* closing bracket for extern "C" */