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