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 file is distributed under the GPL, see file COPYING for details
16 #include "../rfxswf.h"
19 #define ID_BITMAP 2004
23 int main (int argc,char ** argv)
29 S32 width = 800,height = 800;
30 int fs,ls; // line & fillstyle
36 memset(&swf,0x00,sizeof(SWF));
39 swf.frameRate = 0x4000;
40 swf.movieSize.xmax = 4*width;
41 swf.movieSize.ymax = 4*height;
43 swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
51 t = swf_InsertTag(t,ST_DEFINEBITSJPEG2);
53 swf_SetU16(t,ID_BITMAP);
55 if (FAILED(swf_SetJPEGBits(t,"texture.jpg",QUALITY)))
56 { fprintf(stderr,"Error: texture.jpg (256x256) not found in work directory.\n");
60 t = swf_InsertTag(t,ST_DEFINESHAPE);
63 rgb.b = rgb.g = rgb.r = 0x00;
67 fs = swf_ShapeAddBitmapFillStyle(s,NULL,ID_BITMAP,0);
69 swf_SetU16(t,ID_SHAPE); // ID
78 swf_SetShapeHeader(t,s);
80 swf_ShapeSetAll(t,s,0,0,ls,fs,0);
81 swf_ShapeSetLine(t,s,width,0);
82 swf_ShapeSetLine(t,s,-width,height);
83 swf_ShapeSetLine(t,s,0,-height);
88 for (frame=0;frame<64;frame++)
91 /* Test procedure for swf_MatrixJoin
95 // set m1 to left rotation
97 m1.sy = m1.sx = (int)(cos(((float)(frame))/32*3.141)*0x10000);
98 m1.r0 = (int)(sin(((float)(frame))/32*3.141)*0x10000);
100 m1.tx = width+frame*4; m1.ty = height;
102 // set m2 to right rotation
104 m2.sy = m2.sx = (int)(cos(((float)(64-frame))/32*3.141)*0x10000);
105 m2.r0 = (int)(sin(((float)(64-frame))/32*3.141)*0x10000);
107 m2.tx = width; m2.ty = height;
109 // joining m1 and m2 should lead to no transformation
111 swf_MatrixJoin(&m,&m1,&m2);
115 int dx0 = width; // constants of shape
118 int px0 = 2*width; // destination of mapping
122 int py1 = 2*width-frame*4;
124 int px2 = 2*width-frame*8;
127 swf_MatrixMapTriangle(&m,dx0,dy0,px0,py0,px1,py1,px2,py2);
129 t = swf_InsertTag(t,ST_PLACEOBJECT2);
132 swf_ObjectPlace(t,ID_SHAPE,1,&m,NULL,NULL);
134 swf_ObjectMove(t,1,&m,NULL);
136 t = swf_InsertTag(t,ST_SHOWFRAME);
140 t = swf_InsertTag(t,ST_END);
142 // swf_WriteCGI(&swf);
144 f = open("transtest.swf",O_RDWR|O_CREAT|O_TRUNC,0644);
145 if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
151 system("start ..\\transtest.swf");