]> git.sesse.net Git - kdenlive/blob - src/onmonitoritems/rotoscoping/graphicsgems.h
rotoscoping: allow adding new points to the spline
[kdenlive] / src / onmonitoritems / rotoscoping / graphicsgems.h
1 /* 
2  * GraphicsGems.h  
3  * Version 1.0 - Andrew Glassner
4  * from "Graphics Gems", Academic Press, 1990
5  */
6
7 #ifndef GG_H
8 #define GG_H
9
10 /*********************/
11 /* 2d geometry types */
12 /*********************/
13
14 typedef struct Point2Struct {   /* 2d point */
15         double x, y;
16         } Point2;
17 typedef Point2 Vector2;
18
19 typedef struct IntPoint2Struct {        /* 2d integer point */
20         int x, y;
21         } IntPoint2;
22
23 typedef struct Matrix3Struct {  /* 3-by-3 matrix */
24         double element[3][3];
25         } Matrix3;
26
27 typedef struct Box2dStruct {            /* 2d box */
28         Point2 min, max;
29         } Box2;
30         
31
32 /*********************/
33 /* 3d geometry types */
34 /*********************/
35
36 typedef struct Point3Struct {   /* 3d point */
37         double x, y, z;
38         } Point3;
39 typedef Point3 Vector3;
40
41 typedef struct IntPoint3Struct {        /* 3d integer point */
42         int x, y, z;
43         } IntPoint3;
44
45
46 typedef struct Matrix4Struct {  /* 4-by-4 matrix */
47         double element[4][4];
48         } Matrix4;
49
50 typedef struct Box3dStruct {            /* 3d box */
51         Point3 min, max;
52         } Box3;
53
54
55
56 /***********************/
57 /* one-argument macros */
58 /***********************/
59
60 /* absolute value of a */
61 #define ABS(a)          (((a)<0) ? -(a) : (a))
62
63 /* round a to nearest int */
64 #define ROUND(a)        ((a)>0 ? (int)((a)+0.5) : -(int)(0.5-(a)))
65
66 /* take sign of a, either -1, 0, or 1 */
67 #define ZSGN(a)         (((a)<0) ? -1 : (a)>0 ? 1 : 0)  
68
69 /* take binary sign of a, either -1, or 1 if >= 0 */
70 #define SGN(a)          (((a)<0) ? -1 : 1)
71
72 /* shout if something that should be true isn't */
73 #define ASSERT(x) \
74 if (!(x)) fprintf(stderr," Assert failed: x\n");
75
76 /* square a */
77 #define SQR(a)          ((a)*(a))       
78
79
80 /***********************/
81 /* two-argument macros */
82 /***********************/
83
84 /* find minimum of a and b */
85 #define MIN(a,b)        (((a)<(b))?(a):(b))     
86
87 /* find maximum of a and b */
88 #define MAX(a,b)        (((a)>(b))?(a):(b))     
89
90 /* swap a and b (see Gem by Wyvill) */
91 #define SWAP(a,b)       { a^=b; b^=a; a^=b; }
92
93 /* linear interpolation from l (when a=0) to h (when a=1)*/
94 /* (equal to (a*h)+((1-a)*l) */
95 #define LERP(a,l,h)     ((l)+(((h)-(l))*(a)))
96
97 /* clamp the input to the specified range */
98 #define CLAMP(v,l,h)    ((v)<(l) ? (l) : (v) > (h) ? (h) : v)
99
100
101 /****************************/
102 /* memory allocation macros */
103 /****************************/
104
105 /* create a new instance of a structure (see Gem by Hultquist) */
106 #define NEWSTRUCT(x)    (struct x *)(malloc((unsigned)sizeof(struct x)))
107
108 /* create a new instance of a type */
109 #define NEWTYPE(x)      (x *)(malloc((unsigned)sizeof(x)))
110
111
112 /********************/
113 /* useful constants */
114 /********************/
115
116 #ifndef PI
117 #define PI              3.141592        /* the venerable pi */
118 #endif
119 #define PITIMES2        6.283185        /* 2 * pi */
120 #define PIOVER2         1.570796        /* pi / 2 */
121 #define E               2.718282        /* the venerable e */
122 #define SQRT2           1.414214        /* sqrt(2) */
123 #define SQRT3           1.732051        /* sqrt(3) */
124 #define GOLDEN          1.618034        /* the golden ratio */
125 #define DTOR            0.017453        /* convert degrees to radians */
126 #define RTOD            57.29578        /* convert radians to degrees */
127
128
129 /************/
130 /* booleans */
131 /************/
132
133 #ifndef TRUE
134 #define TRUE            1
135 #endif
136
137 #ifndef FALSE
138 #define FALSE           0
139 #endif
140
141 #define ON              1
142 #define OFF             0
143 typedef int boolean;                    /* boolean data type */
144 typedef boolean flag;                   /* flag data type */
145
146
147
148 /*extern double V2SquaredLength(Vector2 *a), V2Length();
149 extern double V2Dot(Vector2 *a, Vector2 *b), V2DistanceBetween2Points(); 
150 extern Vector2 *V2Negate(), *V2Normalize(), *V2Scale(), *V2Add(), *V2Sub(Vector2 *a, Vector2 *b, Vector2 *c);
151 extern Vector2 *V2Lerp(), *V2Combine(), *V2Mul(), *V2MakePerpendicular();
152 extern Vector2 *V2New(), *V2Duplicate();
153 extern Point2 *V2MulPointByMatrix();
154 extern Matrix3 *V2MatMul();
155
156 extern double V3SquaredLength(), V3Length();
157 extern double V3Dot(), V3DistanceBetween2Points();
158 extern Vector3 *V3Normalize(), *V3Scale(), *V3Add(), *V3Sub();
159 extern Vector3 *V3Lerp(), *V3Combine(), *V3Mul(), *V3Cross();
160 extern Vector3 *V3New(), *V3Duplicate();
161 extern Point3 *V3MulPointByMatrix();
162 extern Matrix4 *V3MatMul();
163
164 extern double RegulaFalsi(), NewtonRaphson(), findroot();*/
165
166 #endif