-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathcomposable.hh
More file actions
131 lines (109 loc) · 3.5 KB
/
Copy pathcomposable.hh
File metadata and controls
131 lines (109 loc) · 3.5 KB
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
123
124
125
126
127
128
129
130
131
#pragma once
#include "entity.hh"
#include "group.hh"
class world;
class composable : public entity
{
public:
b2FixtureDef fd;
b2Fixture *fx_sensor;
/**
* C++ doesn't allow classes with constructors in unions,
* otherwise we would have used union here
**/
struct /*union */{
struct { b2PolygonShape shape; } poly;
struct { b2CircleShape shape; } circle;
} orig;
struct /*union */{
struct { b2PolygonShape shape; } poly;
struct { b2CircleShape shape; } circle;
} active;
composable()
{
this->set_flag(ENTITY_IS_COMPOSABLE, true);
this->fd.shape = 0;
this->fx_sensor = 0;
}
~composable()
{
}
void grouped_update();
virtual void set_position(float x, float y, uint8_t frame=0);
void set_angle(float a);
b2Vec2 get_position(void);
float get_angle(void);
b2Vec2 local_to_world(b2Vec2 p, uint8_t frame);
b2Vec2 world_to_local(b2Vec2 p, uint8_t frame);
b2Vec2 local_to_body(b2Vec2 p, uint8_t frame);
b2Vec2 local_vector_to_body(b2Vec2 p, uint8_t frame);
b2Body *get_body(uint8_t frame);
void set_as_circle(float r);
virtual void set_as_rect(float width, float height);
void set_as_tri(float width, float height);
void set_as_poly(b2Vec2 *verts, int num_verts);
void recreate_shape(void);
void update_shape(b2Vec2 local_pos, float local_angle);
virtual void update_frame(bool hard){};
void refresh_poly_shape();
void refresh_circle_shape();
void recreate_fixtures(bool initial);
void add_to_world();
void remove_from_world();
virtual void create_sensor();
virtual float get_sensor_radius() { return 0.f; };
virtual b2Vec2 get_sensor_offset() { return b2Vec2(0.f, 0.f); };
friend class group;
};
class composable_simpleconnect : public composable, public b2RayCastCallback
{
public:
b2Vec2 query_pt;
b2Vec2 query_vec; /* Set in the constructor of the
object, direction of raycast */
entity *query_result;
b2Fixture *query_fx;
uint8_t query_frame;
connection c;
composable_simpleconnect()
{
this->c.init_owned(0, this);
this->c.type = CONN_GROUP;
this->query_vec = b2Vec2(0.f, -.5f);
this->query_pt = b2Vec2(0.f, 0.f);
}
connection *load_connection(connection &conn);
float32 ReportFixture(b2Fixture *f, const b2Vec2 &pt, const b2Vec2 &nor, float32 fraction);
void find_pairs();
};
class composable_multiconnect : public composable
{
public:
connection c_side[4];
composable_multiconnect()
{
this->c_side[0].init_owned(0, this); this->c_side[0].type = CONN_GROUP;
this->c_side[1].init_owned(1, this); this->c_side[1].type = CONN_GROUP;
this->c_side[2].init_owned(2, this); this->c_side[2].type = CONN_GROUP;
this->c_side[3].init_owned(3, this); this->c_side[3].type = CONN_GROUP;
}
connection *load_connection(connection &conn);
void find_pairs();
void set_as_rect(float width, float height);
};
void composable_fast_update(struct tms_entity *t);
inline void composable::grouped_update()
{
b2Vec2 p = this->gr->body->GetWorldPoint(this->_pos);
float a = this->gr->body->GetAngle()+this->_angle;
float c,s;
tmath_sincos(a, &s, &c);
this->M[0] = c;
this->M[1] = s;
this->M[4] = -s;
this->M[5] = c;
this->M[12] = p.x;
this->M[13] = p.y;
this->M[14] = this->prio * LAYER_DEPTH;
tmat3_copy_mat4_sub3x3(this->N, this->M);
}