3 Math and matrix functions, misc tools
\r
5 Extension module for the rfxswf library.
\r
6 Part of the swftools package.
\r
8 Copyright (c) 2000, 2001 Rainer Böhme <rfxswf@reflex-studio.de>
\r
10 This file is distributed under the GPL, see file COPYING for details
\r
14 // Matrix & Math tools for SWF files
\r
16 #define S64 long long
\r
17 SFIXED SP(SFIXED a1,SFIXED a2,SFIXED b1,SFIXED b2)
\r
19 a = (S64)a1*(S64)b1+(S64)a2*(S64)b2;
\r
20 return (SFIXED)(a>>16);
\r
22 SFIXED QFIX(int zaehler,int nenner) // bildet Quotient von zwei INTs in SFIXED
\r
23 { S64 z = zaehler<<16;
\r
24 S64 a = z/(S64)nenner;
\r
29 LPMATRIX MatrixJoin(LPMATRIX d,LPMATRIX s1,LPMATRIX s2)
\r
31 if (!d) return NULL;
\r
32 if (!s1) return (s2)?(LPMATRIX)memcpy(d,s2,sizeof(MATRIX)):NULL;
\r
33 if (!s2) return (LPMATRIX)memcpy(d,s1,sizeof(MATRIX));
\r
35 d->tx = s1->tx + s2->tx;
\r
36 d->ty = s1->ty + s2->ty;
\r
38 d->sx = SP(s1->sx,s1->r1,s2->sx,s2->r0);
\r
39 d->sy = SP(s1->r0,s1->sy,s2->r1,s2->sy);
\r
40 d->r0 = SP(s1->r0,s1->sy,s2->sx,s2->r0);
\r
41 d->r1 = SP(s1->sx,s1->r1,s2->r1,s2->sy);
\r
43 //DumpMatrix(NULL,d);
\r
48 LPMATRIX MatrixMapTriangle(LPMATRIX m,int dx,int dy,int x0,int y0,
\r
49 int x1,int y1,int x2,int y2)
\r
50 { int dx1 = x1 - x0;
\r
55 if (!m) return NULL;
\r
56 if ((!dx)||(!dy)) return NULL; // check DIV by zero
\r
60 m->sx = QFIX(dx1,dx);
\r
61 m->sy = QFIX(dy2,dy);
\r
62 m->r0 = QFIX(dy1,dx);
\r
63 m->r1 = QFIX(dx2,dy);
\r
68 U16 GetDefineID(LPTAG t)
\r
73 oldTagPos = GetTagPos(t);
\r
76 switch (GetTagID(t))
\r
77 { case ST_DEFINESHAPE:
\r
78 case ST_DEFINESHAPE2:
\r
79 case ST_DEFINESHAPE3:
\r
80 case ST_DEFINEMORPHSHAPE:
\r
82 case ST_DEFINEBITSJPEG2:
\r
83 case ST_DEFINEBITSJPEG3:
\r
84 case ST_DEFINEBITSLOSSLESS:
\r
85 case ST_DEFINEBITSLOSSLESS2:
\r
86 case ST_DEFINEBUTTON:
\r
87 case ST_DEFINEBUTTON2:
\r
88 case ST_DEFINEBUTTONCXFORM:
\r
89 case ST_DEFINEBUTTONSOUND:
\r
91 case ST_DEFINEFONT2:
\r
92 case ST_DEFINEFONTINFO:
\r
94 case ST_DEFINETEXT2:
\r
95 case ST_DEFINESOUND:
\r
96 case ST_DEFINESPRITE:
\r
101 SetTagPos(t,oldTagPos);
\r
106 U16 GetPlaceID(LPTAG t)
\r
111 oldTagPos = GetTagPos(t);
\r
114 switch (GetTagID(t))
\r
115 { case ST_PLACEOBJECT:
\r
116 case ST_REMOVEOBJECT:
\r
117 case ST_STARTSOUND:
\r
121 case ST_PLACEOBJECT2:
\r
122 { U8 flags = GetU8(t);
\r
124 id = (flags&PF_CHAR)?GetU16(t):id;
\r
129 SetTagPos(t,oldTagPos);
\r
134 int definingtagids[] =
\r
138 ST_DEFINEMORPHSHAPE,
\r
145 ST_DEFINEBITSJPEG2,
\r
146 ST_DEFINEBITSJPEG3,
\r
147 ST_DEFINEBITSLOSSLESS,
\r
148 ST_DEFINEBITSLOSSLESS2,
\r
157 // tags which may be used inside a sprite definition
\r
158 int spritetagids[] =
\r
163 ST_REMOVEOBJECT2, //?
\r
167 ST_SOUNDSTREAMHEAD,
\r
168 ST_SOUNDSTREAMHEAD2,
\r
169 ST_SOUNDSTREAMBLOCK,
\r
174 char isAllowedSpriteTag (TAG*tag)
\r
178 while(spritetagids[t]>=0)
\r
180 if(spritetagids[t] == id)
\r
187 char isDefiningTag (TAG*tag)
\r
191 while(definingtagids[t]>=0)
\r
193 if(definingtagids[t] == id)
\r
200 U16 GetDepth(LPTAG t)
\r
205 oldTagPos = GetTagPos(t);
\r
208 switch (GetTagID(t))
\r
209 { case ST_PLACEOBJECT:
\r
210 case ST_REMOVEOBJECT:
\r
214 case ST_REMOVEOBJECT2:
\r
217 case ST_PLACEOBJECT2:
\r
218 { U8 flags = GetU8(t);
\r
222 SetTagPos(t,oldTagPos);
\r
226 char* GetName(LPTAG t)
\r
232 oldTagPos = GetTagPos(t);
\r
234 switch(GetTagID(t))
\r
236 case ST_FRAMELABEL:
\r
237 name = GetTagPosPtr(t);
\r
239 case ST_PLACEOBJECT2: {
\r
240 U8 flags = GetU8(t);
\r
241 GetU16(t); //depth;
\r
244 if(flags&PF_MATRIX)
\r
246 if(flags&PF_CXFORM)
\r
247 GetCXForm(t, &c, 1);
\r
250 if(flags&PF_NAME) {
\r
252 name = GetTagPosPtr(t);
\r
257 SetTagPos(t,oldTagPos);
\r