-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransform.h
More file actions
78 lines (59 loc) · 2.76 KB
/
transform.h
File metadata and controls
78 lines (59 loc) · 2.76 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
#ifndef TRANSFORM_H_INCLUDED
#define TRANSFORM_H_INCLUDED
#include "basics.h"
#include "vec2d.h"
#include "Chipmunk/headers/chipmunk.h"
typedef struct {
double a, b, c;
double d, e, f;
} Mat23;
typedef struct {
double tx, ty; // translate
float cx, cy; // center, a secondary translate on top of the scale
float s, invs; // scale, inverse scale
Mat23 M;
} Transform;
typedef vec2d (*m_update_func) ( Transform *T, double d1, double d2, double d3, double d4 );
vec2d update_TM( Transform *T, double unused1, double unused2, double unused3, double unused4 );
vec2d update_TM_object_rotated( Transform *T, double unused, double obj_angle, double obj_x, double obj_y );
vec2d update_TM_world_rotated( Transform *T, double world_angle, double unused1, double unused2, double unused3 );
vec2d update_TM_combined( Transform *T, double world_angle, double obj_angle, double obj_x, double obj_y );
void set_scale( Transform *T, float s );
static inline float atfX( float x, Transform T ){
return T.cx + ( T.s * (x - T.tx) );
}
static inline float atfY( float y, Transform T ){
return T.cy + ( T.s * (y - T.ty) );
}
static inline float rtfX( float x, Transform T ){
return ((x - T.cx) * T.invs) + T.tx;
}
static inline float rtfY( float y, Transform T ){
return ((y - T.cy) * T.invs) + T.ty;
}
vec2d apply_transform_v2d( vec2d *vec, Transform *T );
vec2d reverse_transform_v2d( vec2d *vec, Transform *T );
cpVect apply_transform_cpv( cpVect vec, Transform *T );
cpVect reverse_transform_cpv( cpVect vec, Transform *T );
SDL_FPoint apply_transform_fp( SDL_FPoint p, Transform *T );
SDL_FPoint reverse_transform_fp( SDL_FPoint p, Transform *T );
SDL_Rect apply_transform_rect( SDL_Rect *rct, Transform *T );
SDL_Rect reverse_transform_rect( SDL_Rect *rct, Transform *T );
SDL_FRect apply_transform_frect( SDL_FRect *rct, Transform *T );
SDL_FRect reverse_transform_frect( SDL_FRect *rct, Transform *T );
void constrain_Transform( Transform *T, SDL_FRect window_rct, SDL_FRect bounds );
vec2d apply_Mat23_v2d( vec2d world, const Mat23 *M );
#define TM_APPLY_TO(out, in, M) \
do { \
double tx = (M).a * (in).x + (M).b * (in).y + (M).c; \
double ty = (M).d * (in).x + (M).e * (in).y + (M).f; \
(out).x = tx; \
(out).y = ty; \
} while (0)
#define TM_APPLY(type, in, M) \
((type){ \
.x = (M).a * (in).x + (M).b * (in).y + (M).c, \
.y = (M).d * (in).x + (M).e * (in).y + (M).f \
})
vec2d reverse_Mat23_v2d( vec2d screen, const Mat23 *M );
#endif