3 Example for transforming a textured triangle
5 Part of the swftools package.
7 Copyright (c) 2001 Rainer Böhme <rfxswf@reflex-studio.de>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
26 #include "../rfxswf.h"
29 #define ID_BITMAP 2004
33 int main (int argc,char ** argv)
39 S32 width = 800,height = 800;
40 int fs,ls; // line & fillstyle
46 memset(&swf,0x00,sizeof(SWF));
49 swf.frameRate = 0x4000;
50 swf.movieSize.xmax = 4*width;
51 swf.movieSize.ymax = 4*height;
53 swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
61 t = swf_InsertTag(t,ST_DEFINEBITSJPEG2);
63 swf_SetU16(t,ID_BITMAP);
65 if (FAILED(swf_SetJPEGBits(t,"texture.jpg",QUALITY)))
66 { fprintf(stderr,"Error: texture.jpg (256x256) not found in work directory.\n");
70 t = swf_InsertTag(t,ST_DEFINESHAPE);
73 rgb.b = rgb.g = rgb.r = 0x00;
77 fs = swf_ShapeAddBitmapFillStyle(s,NULL,ID_BITMAP,0);
79 swf_SetU16(t,ID_SHAPE); // ID
88 swf_SetShapeHeader(t,s);
90 swf_ShapeSetAll(t,s,0,0,ls,fs,0);
91 swf_ShapeSetLine(t,s,width,0);
92 swf_ShapeSetLine(t,s,-width,height);
93 swf_ShapeSetLine(t,s,0,-height);
98 for (frame=0;frame<64;frame++)
101 /* Test procedure for swf_MatrixJoin
105 // set m1 to left rotation
107 m1.sy = m1.sx = (int)(cos(((float)(frame))/32*3.141)*0x10000);
108 m1.r0 = (int)(sin(((float)(frame))/32*3.141)*0x10000);
110 m1.tx = width+frame*4; m1.ty = height;
112 // set m2 to right rotation
114 m2.sy = m2.sx = (int)(cos(((float)(64-frame))/32*3.141)*0x10000);
115 m2.r0 = (int)(sin(((float)(64-frame))/32*3.141)*0x10000);
117 m2.tx = width; m2.ty = height;
119 // joining m1 and m2 should lead to no transformation
121 swf_MatrixJoin(&m,&m1,&m2);
125 int dx0 = width; // constants of shape
128 int px0 = 2*width; // destination of mapping
132 int py1 = 2*width-frame*4;
134 int px2 = 2*width-frame*8;
137 swf_MatrixMapTriangle(&m,dx0,dy0,px0,py0,px1,py1,px2,py2);
139 t = swf_InsertTag(t,ST_PLACEOBJECT2);
142 swf_ObjectPlace(t,ID_SHAPE,1,&m,NULL,NULL);
144 swf_ObjectMove(t,1,&m,NULL);
146 t = swf_InsertTag(t,ST_SHOWFRAME);
150 t = swf_InsertTag(t,ST_END);
152 // swf_WriteCGI(&swf);
154 f = open("transtest.swf",O_RDWR|O_CREAT|O_TRUNC|O_BINARY,0644);
155 if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
161 system("start ..\\transtest.swf");