libsf3
Loading...
Searching...
No Matches
sf3_physics_model.h
Go to the documentation of this file.
1#ifndef __SF3_PHYSICS_MODEL__
2#define __SF3_PHYSICS_MODEL__
3#include "sf3_core.h"
4
6#define SF3_FORMAT_ID_PHYSICS_MODEL 0x06
7
21
25 float transform[16];
26 uint8_t type;
28 float w;
30 float h;
32 float d;
33};
34
37 float transform[16];
38 uint8_t type;
40 float w;
42 float h;
44 float d;
45};
46
49 float transform[16];
50 uint8_t type;
56 float height;
57};
58
61 float transform[16];
62 uint8_t type;
68 float height;
69};
70
73 float transform[16];
74 uint8_t type;
76 uint16_t count;
78 float vertices[];
79};
80
92 float transform[16];
95 uint8_t type;
96};
97
102 struct sf3_identifier identifier;
104 float mass;
107 float tensor[9];
109 uint16_t shape_count;
110 struct sf3_physics_shape shapes[];
111};
112
118 const char *base = (char*)shape;
119 switch(shape->type){
121 return (const struct sf3_physics_shape *)(base+sizeof(struct sf3_shape_ellipsoid));
123 return (const struct sf3_physics_shape *)(base+sizeof(struct sf3_shape_box));
125 return (const struct sf3_physics_shape *)(base+sizeof(struct sf3_shape_cylinder));
127 return (const struct sf3_physics_shape *)(base+sizeof(struct sf3_shape_pill));
129 const struct sf3_shape_mesh *mesh = (const struct sf3_shape_mesh *)shape;
130 return (const struct sf3_physics_shape *)(mesh->vertices+(mesh->count*3));
131 }
132 default: return 0;
133 }
134}
135
138 switch(type){
139 case SF3_PHYSICS_SHAPE_ELLIPSOID: return "ellipsoid";
140 case SF3_PHYSICS_SHAPE_BOX: return "box";
141 case SF3_PHYSICS_SHAPE_CYLINDER: return "cylinder";
142 case SF3_PHYSICS_SHAPE_PILL: return "pill";
143 case SF3_PHYSICS_SHAPE_MESH: return "mesh";
144 default: return "Unknown";
145 }
146}
147
149SF3_EXPORT size_t sf3_physics_model_size(const struct sf3_physics_model *physics_model){
150 if(physics_model->shape_count == 0) return sizeof(struct sf3_physics_model);
151 const struct sf3_physics_shape *shape = &physics_model->shapes[0];
152 for(uint16_t i=0; i<physics_model->shape_count; ++i){
153 shape = sf3_physics_model_next_shape(shape);
154 }
155 const void *start = (const void *)physics_model;
156 const void *end = (const void *)shape;
157 return (end-start);
158}
159#endif
#define SF3_INLINE
Definition sf3_core.h:16
#define SF3_EXPORT
Definition sf3_core.h:13
#define SF3_PACK
Definition sf3_core.h:9
SF3_EXPORT size_t sf3_physics_model_size(const struct sf3_physics_model *physics_model)
Computes the size of the physics model file in bytes.
sf3_physics_shape_type
The shape types that can be stored in a physics model.
@ SF3_PHYSICS_SHAPE_PILL
The shape is an sf3_shape_pill.
@ SF3_PHYSICS_SHAPE_MESH
The shape is an sf3_shape_mesh.
@ SF3_PHYSICS_SHAPE_BOX
The shape is an sf3_shape_box.
@ SF3_PHYSICS_SHAPE_ELLIPSOID
The shape is an sf3_shape_ellipsoid.
@ SF3_PHYSICS_SHAPE_CYLINDER
The shape is an sf3_shape_cylinder.
SF3_INLINE const struct sf3_physics_shape * sf3_physics_model_next_shape(const struct sf3_physics_shape *shape)
The basic header structure of every SF3 file.
Definition sf3_core.h:70
uint16_t shape_count
The number of shapes that comprise the model.
float mass
The mass of the entire model in Kg.
struct sf3_physics_shape shapes[]
A box shape described by the half-widths along the principal axes.
float w
The half-size in X.
float d
The half-size in Z.
float h
The half-size in Y.
A cylindrical shape described by two radii and a half-height.
float bottom_radius
The radius of the cap in Y-.
float top_radius
The radius of the cap in Y+.
float height
The half-size in Y.
float w
The radius along X.
float d
The radius along Z.
float h
The radius along Y.
A convex hull described by its edge vertices.
uint16_t count
The number of vertices stored.
float vertices[]
The vertices described as triplets of X, Y, Z coordinates.
A pill-box shape described by two radii and a half-height.
float bottom_radius
The radius of the sphere in Y-.
float height
The half-size in Y between the two spheres.
float top_radius
The radius of the sphere in Y+.