Initial revision
[blender.git] / source / gameengine / Physics / Sumo / include / solid.h
1 #ifndef SOLID_H
2 #define SOLID_H
3
4 #include "solid_types.h"
5
6 #ifdef __cplusplus
7 extern "C" { 
8 #endif
9     
10 DT_DECLARE_HANDLE(DT_ObjectHandle);
11 DT_DECLARE_HANDLE(DT_SceneHandle);
12 DT_DECLARE_HANDLE(DT_ShapeHandle);
13 DT_DECLARE_HANDLE(DT_RespTableHandle);
14
15 typedef enum DT_ScalarType {
16         DT_FLOAT,
17         DT_DOUBLE
18 } DT_ScalarType;
19
20 typedef enum DT_ResponseType { 
21         DT_NO_RESPONSE,              
22         DT_SIMPLE_RESPONSE,
23         DT_WITNESSED_RESPONSE,
24         DT_DEPTH_RESPONSE,
25 } DT_ResponseType;
26     
27 typedef struct DT_CollData {
28         DT_Vector3 point1;
29         DT_Vector3 point2;
30         DT_Vector3 normal;
31 } DT_CollData;
32
33 typedef void (*DT_ResponseCallback)(
34         void *client_data,
35         void *client_object1,
36         void *client_object2,
37         const DT_CollData *coll_data);
38
39 /* Shape definition, similar to OpenGL  */
40
41 extern DT_ShapeHandle DT_Box(DT_Scalar x, DT_Scalar y, DT_Scalar z);
42 extern DT_ShapeHandle DT_Cone(DT_Scalar radius, DT_Scalar height);
43 extern DT_ShapeHandle DT_Cylinder(DT_Scalar radius, DT_Scalar height);
44 extern DT_ShapeHandle DT_Sphere(DT_Scalar radius);
45 extern DT_ShapeHandle DT_Ray(DT_Scalar x, DT_Scalar y, DT_Scalar z);
46
47 extern DT_ShapeHandle DT_NewComplexShape();
48 extern void           DT_EndComplexShape();
49
50 extern DT_ShapeHandle DT_NewPolyhedron();
51 extern void           DT_EndPolyhedron();
52
53 extern void DT_Begin();
54 extern void DT_End();
55
56 extern void DT_Vertex(DT_Scalar x, DT_Scalar y, DT_Scalar z);
57
58 /* Vertex arrays maintained by the client application can be accessed directly
59    by SUMO. For instance, you have a vertex struct in the client of the form:
60    
61    struct Vertex {
62    float xyz[3];
63    float uv[2];
64    float normal[3];
65    };
66    
67    And maintain vertex arrays e.g. as
68
69    struct Vertex vertices[328];
70
71    Within a Polyhedron or a ComplexShape you can use this data by specifying
72
73    DT_VertexBase(vertices, DT_FLOAT, sizeof(struct Vertex));
74
75    and refer to vertices in the array using   
76
77    DT_VertexIndex(10);
78
79    or 
80
81    DT_Index indices[5] = { 6, 4, 8, 1, 3 };
82    DT_VertexIndices(5, indices);
83
84    or even
85
86    DT_VertexRange(8, 4);
87
88    for the range 8, 9, 10, 11.
89 */
90
91
92 extern void DT_SetVertexBase(const void *base, DT_ScalarType type,
93                                                          DT_Size stride);
94 extern void DT_VertexIndex(DT_Index index);
95 extern void DT_VertexIndices(DT_Count count, const DT_Index *indices);
96 extern void DT_VertexRange(DT_Index first, DT_Count count); 
97
98
99 /* currently not implemented */
100 extern void DT_ChangeVertexBase(DT_ShapeHandle shape, const void *base);
101
102 extern void DT_DeleteShape(DT_ShapeHandle shape);
103
104 /* Scene */
105
106 extern DT_SceneHandle DT_CreateScene(); 
107 extern void           DT_DeleteScene(DT_SceneHandle scene);
108
109 extern void DT_AddObject(DT_SceneHandle scene, DT_ObjectHandle object);
110 extern void DT_RemoveObject(DT_SceneHandle scene, DT_ObjectHandle object);
111
112
113
114 /* Object  */
115
116 extern DT_ObjectHandle DT_CreateObject(
117         void *client_object,      /* pointer to object in client memory */
118         DT_ShapeHandle shape  /* the shape or geometry of the object */
119         );
120
121 extern void DT_DeleteObject(DT_ObjectHandle object);
122
123 extern void DT_SetScaling(DT_ObjectHandle object, const DT_Vector3 scaling);
124 extern void DT_SetPosition(DT_ObjectHandle object, const DT_Vector3 position);
125 extern void DT_SetOrientation(DT_ObjectHandle object, const DT_Quaternion orientation);
126
127 extern void DT_SetMargin(DT_ObjectHandle object, DT_Scalar margin);
128
129 extern void DT_SetMatrixf(DT_ObjectHandle object, const float *m); 
130 extern void DT_GetMatrixf(DT_ObjectHandle object, float *m); 
131
132 extern void DT_SetMatrixd(DT_ObjectHandle object, const double *m); 
133 extern void DT_GetMatrixd(DT_ObjectHandle object, double *m); 
134
135 extern void DT_GetWorldCoord(DT_ObjectHandle object,
136                                                          const DT_Vector3 local,
137                                                          DT_Vector3 world);
138
139 extern DT_Scalar DT_GetClosestPair(DT_ObjectHandle object1, DT_ObjectHandle object2,
140                                                                    DT_Vector3 point1, DT_Vector3 point2);  
141
142
143 /* Response, see SOLID user manual */
144
145 extern DT_RespTableHandle DT_CreateRespTable(); 
146 extern void               DT_DeleteRespTable(DT_RespTableHandle respTable); 
147
148 extern void DT_CallResponse(DT_RespTableHandle respTable,
149                                                         DT_ObjectHandle object1,
150                                                         DT_ObjectHandle object2,
151                                                         const DT_CollData *coll_data);
152
153 extern void DT_SetDefaultResponse(DT_RespTableHandle respTable,
154                                                                   DT_ResponseCallback response, 
155                                                                   DT_ResponseType type, 
156                                                                   void *client_data);
157
158 extern void DT_ClearDefaultResponse(DT_RespTableHandle respTable);
159
160 extern void DT_SetObjectResponse(DT_RespTableHandle respTable,
161                                                                  DT_ObjectHandle object,
162                                                                  DT_ResponseCallback response,
163                                                                  DT_ResponseType type, void *client_data);
164 extern void DT_ClearObjectResponse(DT_RespTableHandle respTable,
165                                                                    DT_ObjectHandle object);
166
167 extern void DT_SetPairResponse(DT_RespTableHandle respTable,
168                                                            DT_ObjectHandle object1,
169                                                            DT_ObjectHandle object2, 
170                                                            DT_ResponseCallback  response,
171                                                            DT_ResponseType type, 
172                                                            void *client_data);
173 extern void DT_ClearPairResponse(DT_RespTableHandle respTable,
174                                                                  DT_ObjectHandle object1, 
175                                                                  DT_ObjectHandle object2);
176
177
178
179 /* Perform a collision test for a given scene, using a response table */
180  
181 extern DT_Count DT_Test(DT_SceneHandle scene, DT_RespTableHandle respTable);
182
183 extern void *DT_RayTest(DT_SceneHandle scene, void *ignore_client,
184                                                 const DT_Vector3 from, const DT_Vector3 to,
185                                                 DT_Vector3 spot, DT_Vector3 normal);
186
187 extern int DT_ObjectRayTest(DT_ObjectHandle object,
188                                                         const DT_Vector3 from, const DT_Vector3 to,
189                                                         DT_Vector3 spot, DT_Vector3 normal);
190
191 #ifdef __cplusplus
192 }
193 #endif
194
195 #endif