diff options
author | dan miller | 2007-10-19 05:15:33 +0000 |
---|---|---|
committer | dan miller | 2007-10-19 05:15:33 +0000 |
commit | 79eca25c945a535a7a0325999034bae17da92412 (patch) | |
tree | 40ff433d94859d629aac933d5ec73b382f62ba1a /libraries/ode-0.9/drawstuff/dstest/dstest.cpp | |
parent | adding ode source to /libraries (diff) | |
download | opensim-SC-79eca25c945a535a7a0325999034bae17da92412.zip opensim-SC-79eca25c945a535a7a0325999034bae17da92412.tar.gz opensim-SC-79eca25c945a535a7a0325999034bae17da92412.tar.bz2 opensim-SC-79eca25c945a535a7a0325999034bae17da92412.tar.xz |
resubmitting ode
Diffstat (limited to 'libraries/ode-0.9/drawstuff/dstest/dstest.cpp')
-rw-r--r-- | libraries/ode-0.9/drawstuff/dstest/dstest.cpp | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/libraries/ode-0.9/drawstuff/dstest/dstest.cpp b/libraries/ode-0.9/drawstuff/dstest/dstest.cpp new file mode 100644 index 0000000..27f042f --- /dev/null +++ b/libraries/ode-0.9/drawstuff/dstest/dstest.cpp | |||
@@ -0,0 +1,125 @@ | |||
1 | /************************************************************************* | ||
2 | * * | ||
3 | * Open Dynamics Engine, Copyright (C) 2001,2002 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 | #include <stdio.h> | ||
24 | #include <math.h> | ||
25 | #include <drawstuff/drawstuff.h> | ||
26 | |||
27 | |||
28 | #ifndef M_PI | ||
29 | #define M_PI (3.14159265358979323846) | ||
30 | #endif | ||
31 | |||
32 | |||
33 | void start() | ||
34 | { | ||
35 | // adjust the starting viewpoint a bit | ||
36 | float xyz[3],hpr[3]; | ||
37 | dsGetViewpoint (xyz,hpr); | ||
38 | hpr[0] += 7; | ||
39 | dsSetViewpoint (xyz,hpr); | ||
40 | } | ||
41 | |||
42 | |||
43 | void simLoop (int pause) | ||
44 | { | ||
45 | float pos[3]; | ||
46 | float R[12]; | ||
47 | static float a = 0; | ||
48 | |||
49 | if (!pause) a += 0.02f; | ||
50 | if (a > (2*M_PI)) a -= (float) (2*M_PI); | ||
51 | float ca = (float) cos(a); | ||
52 | float sa = (float) sin(a); | ||
53 | |||
54 | dsSetTexture (DS_WOOD); | ||
55 | |||
56 | float b = (a > M_PI) ? (2*(a-(float)M_PI)) : a*2; | ||
57 | pos[0] = -0.3f; | ||
58 | pos[1] = 0; | ||
59 | pos[2] = (float) (0.1f*(2*M_PI*b - b*b) + 0.65f); | ||
60 | R[0] = ca; R[1] = 0; R[2] = -sa; | ||
61 | R[4] = 0; R[5] = 1; R[6] = 0; | ||
62 | R[8] = sa; R[9] = 0; R[10] = ca; | ||
63 | dsSetColor (1,0.8f,0.6f); | ||
64 | dsDrawSphere (pos,R,0.3f); | ||
65 | |||
66 | dsSetTexture (DS_NONE); | ||
67 | |||
68 | pos[0] = -0.2f; | ||
69 | pos[1] = 0.8f; | ||
70 | pos[2] = 0.4f; | ||
71 | R[0] = ca; R[1] = -sa; R[2] = 0; | ||
72 | R[4] = sa; R[5] = ca; R[6] = 0; | ||
73 | R[8] = 0; R[9] = 0; R[10] = 1; | ||
74 | float sides[3] = {0.1f,0.4f,0.8f}; | ||
75 | dsSetColor (0.6f,0.6f,1); | ||
76 | dsDrawBox (pos,R,sides); | ||
77 | |||
78 | dsSetTexture (DS_WOOD); | ||
79 | |||
80 | float r = 0.3f; // cylinder radius | ||
81 | float d = (float)cos(a*2) * 0.4f; | ||
82 | float cd = (float)cos(-d/r); | ||
83 | float sd = (float)sin(-d/r); | ||
84 | pos[0] = -0.2f; | ||
85 | pos[1] = -1 + d; | ||
86 | pos[2] = 0.3f; | ||
87 | R[0] = 0; R[1] = 0; R[2] = -1; | ||
88 | R[4] = -sd; R[5] = cd; R[6] = 0; | ||
89 | R[8] = cd; R[9] = sd; R[10] = 0; | ||
90 | dsSetColor (0.4f,1,1); | ||
91 | dsDrawCylinder (pos,R,0.8f,r); | ||
92 | |||
93 | pos[0] = 0; | ||
94 | pos[1] = 0; | ||
95 | pos[2] = 0.2f; | ||
96 | R[0] = 0; R[1] = sa; R[2] = -ca; | ||
97 | R[4] = 0; R[5] = ca; R[6] = sa; | ||
98 | R[8] = 1; R[9] = 0; R[10] = 0; | ||
99 | dsSetColor (1,0.9f,0.2f); | ||
100 | dsDrawCappedCylinder (pos,R,0.8f,0.2f); | ||
101 | } | ||
102 | |||
103 | |||
104 | void command (int cmd) | ||
105 | { | ||
106 | dsPrint ("received command %d (`%c')\n",cmd,cmd); | ||
107 | } | ||
108 | |||
109 | |||
110 | int main (int argc, char **argv) | ||
111 | { | ||
112 | // setup pointers to callback functions | ||
113 | dsFunctions fn; | ||
114 | fn.version = DS_VERSION; | ||
115 | fn.start = &start; | ||
116 | fn.step = &simLoop; | ||
117 | fn.command = command; | ||
118 | fn.stop = 0; | ||
119 | fn.path_to_textures = 0; // uses default | ||
120 | |||
121 | // run simulation | ||
122 | dsSimulationLoop (argc,argv,400,400,&fn); | ||
123 | |||
124 | return 0; | ||
125 | } | ||