-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgodot_chipmunk.h
122 lines (100 loc) · 3.21 KB
/
godot_chipmunk.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#ifndef GODOT_CHIPMUNK_H
#define GODOT_CHIPMUNK_H
#include <object.h>
#include <reference.h>
#include <chipmunk/chipmunk.h>
/***********************************************************************
* Callback data
**********************************************************************/
struct ChipmunkCallbackBinding
{
ObjectID id;
StringName method;
void call();
void call(const Variant &arg0);
};
/***********************************************************************
* Enable conversion from Variant to any class derived from Object
**********************************************************************/
template<class O>
struct VariantCaster<O*>
{
static O *cast(const Variant &p_variant)
{
auto *obj = (Object*)p_variant;
return obj ? obj->cast_to<O>() : NULL;
}
};
/***********************************************************************
* cpShapeFilter
**********************************************************************/
class ChipmunkShapeFilter : public Reference
{
OBJ_TYPE(ChipmunkShapeFilter, Reference);
public:
/** Lifecycle */
ChipmunkShapeFilter();
public:
/** Chipmunk properties */
int group;
int categories;
int mask;
public:
/** Properties setters/getters */
void set_group(int p_group);
int get_group() const;
void set_categories(int p_categories);
int get_categories() const;
void set_mask(int p_mask);
int get_mask() const;
protected:
/** Godot bindings */
static void _bind_methods();
public:
/** Chipmunk interoperability */
operator cpShapeFilter() const;
ChipmunkShapeFilter(const cpShapeFilter&);
};
/***********************************************************************
* 2D Math interoperability
**********************************************************************/
static inline cpVect CP(const Vector2 &v) { return cpv(v.x, v.y); }
static inline cpBB CP(const Rect2 &v) { return cpBBNew(v.pos.x, v.pos.y, v.pos.x + v.size.x, v.pos.y + v.size.y); }
static inline cpTransform CP(const Matrix32 &v)
{
return cpTransform
{
v.elements[0].x, v.elements[0].y,
v.elements[1].x, v.elements[1].y,
v.elements[2].x, v.elements[2].y
};
}
static inline cpShapeFilter CP(const Ref<ChipmunkShapeFilter> &v)
{
return v.is_valid() ? (cpShapeFilter)**v : CP_SHAPE_FILTER_ALL;
}
static inline Vector2 GD(const cpVect &v) { return Vector2(v.x, v.y); }
static inline Rect2 GD(const cpBB &v) { return Rect2(v.l, v.b, v.r - v.l, v.t - v.b); }
static inline Matrix32 GD(const cpTransform &v)
{
return Matrix32(v.a, v.b, v.c, v.d, v.tx, v.ty);
}
/***********************************************************************
* Include entities
**********************************************************************/
class ChipmunkSpace;
class ChipmunkBody;
class ChipmunkShape;
class ChipmunkConstraint;
class ChipmunkCollisionHandler;
class ChipmunkArbiter;
#include "src/chipmunk_space.h"
#include "src/chipmunk_body.h"
#include "src/chipmunk_shape.h"
#include "src/chipmunk_constraint.h"
#include "src/chipmunk_collision_handler.h"
#include "src/chipmunk_arbiter.h"
#include "src/chipmunk_pin_joint.h"
#include "src/chipmunk_pivot_joint.h"
#include "src/chipmunk_damped_spring.h"
#endif