1 /*************************************************************************
3 * Open Dynamics Engine, Copyright (C) 2001,2002 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 *************************************************************************/
25 #include <drawstuff/drawstuff.h>
29 #define M_PI (3.14159265358979323846)
35 // adjust the starting viewpoint a bit
37 dsGetViewpoint (xyz
,hpr
);
39 dsSetViewpoint (xyz
,hpr
);
43 void simLoop (int pause
)
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
);
54 dsSetTexture (DS_WOOD
);
56 float b
= (a
> M_PI
) ? (2*(a
-(float)M_PI
)) : a
*2;
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
);
66 dsSetTexture (DS_NONE
);
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
);
78 dsSetTexture (DS_WOOD
);
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
);
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
);
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
);
104 void command (int cmd
)
106 dsPrint ("received command %d (`%c')\n",cmd
,cmd
);
110 int main (int argc
, char **argv
)
112 // setup pointers to callback functions
114 fn
.version
= DS_VERSION
;
117 fn
.command
= command
;
119 fn
.path_to_textures
= 0; // uses default
122 dsSimulationLoop (argc
,argv
,400,400,&fn
);