Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ode/ode-0.9/include/drawstuff/drawstuff.h @ 216

Last change on this file since 216 was 216, checked in by mathiask, 17 years ago

[Physik] add ode-0.9

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