3 Example for drawing 3D grind objects
5 Part of the swftools package.
7 Copyright (c) 2000, 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"
18 #define BANNER_TEXT "reflex" // banner is disabled due to new font handling
20 #define ID_BANNER 2001
21 #define ID_HIGHLIGHT 2002
22 #define ID_BUTTON 2003
25 int sX[] = { a,-a, a,-a, a,-a, a,-a};
26 int sY[] = { a, a,-a,-a, a, a,-a,-a};
27 int sZ[] = { a, a, a, a,-a,-a,-a,-a};
33 int sin_[512],cos_[512];
39 { d = ((double)i)/128*3.14159;
40 sin_[i] = (int)(sin(d)*256);
41 cos_[i] = (int)(cos(d)*256);
45 void ShapeSquare(LPTAG t,LPSHAPE s,int p1,int p2,int p3,int p4,int dx,int dy)
48 if (((dX[p2]-dX[p1])*(dY[p3]-dY[p1])-(dX[p3]-dX[p1])*(dY[p2]-dY[p1]))<0) return;
50 swf_ShapeSetMove(t,s,dX[p1]+dx,dY[p1]+dy);
51 swf_ShapeSetLine(t,s,dX[p2]-dX[p1],dY[p2]-dY[p1]);
52 swf_ShapeSetLine(t,s,dX[p3]-dX[p2],dY[p3]-dY[p2]);
53 swf_ShapeSetLine(t,s,dX[p4]-dX[p3],dY[p4]-dY[p3]);
54 swf_ShapeSetLine(t,s,dX[p1]-dX[p4],dY[p1]-dY[p4]);
58 void mapBox(int xw,int yw,int zw)
59 // simple trigonometry without using transformation matrices
61 int x1,y1,z1,x2,y2,z2,x3,y3,z3;
73 y1 = ( y*cos_[xw]- z*sin_[xw])>>8;
74 z1 = ( y*sin_[xw]+ z*cos_[xw])>>8;
77 x2 = (x1*cos_[yw]+z1*sin_[yw])>>8;
80 x3 = (x2*cos_[zw]-y2*sin_[zw])>>8;
81 y3 = (x2*sin_[zw]+y2*cos_[zw])>>8;
82 z3 = (z1*cos_[yw]-x1*sin_[yw])>>8;
84 dX[i] = x3*4000/(z3+950);
85 dY[i] = y3*4000/(z3+950);
90 int main (int argc,char ** argv)
96 S32 width = 800,height = 800;
103 /* f = open("Arial.efont",O_RDONLY);
105 { if (FAILED(swf_FontImport(f,&font)))
106 { fprintf(stderr,"Font import failed\n");
112 { fprintf(stderr,"Font not found\n");
117 swf_FontSetID(font,ID_FONT);
118 swf_FontInitUsage(&use);
119 swf_FontUse(&use,BANNER_TEXT);
120 swf_FontReduce(font,&use);
125 memset(&swf,0x00,sizeof(SWF));
128 swf.frameRate = 0x4000;
129 swf.movieSize.xmax = 4*width;
130 swf.movieSize.ymax = 4*height;
132 swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
140 /* This part can't be used because of missing fonts. Nevertheless it shows, how
141 rfxswf handles fonts, fontusages (in order to include only the used glyphs
142 into the output swf) and how to make a simple button
145 t = swf_InsertTag(t,ST_DEFINEFONT);
147 swf_FontSetDefine(t,font);
149 t = swf_InsertTag(t,ST_DEFINEFONTINFO);
151 swf_FontSetInfo(t,font);
153 t = swf_InsertTag(t,ST_DEFINETEXT);
155 swf_SetU16(t,ID_BANNER); // ID
164 swf_SetMatrix(t,NULL);
166 swf_TextCountBits(font,BANNER_TEXT,80,&gbits,&abits);
175 swf_TextSetInfoRecord(t,font,height/4,&rgb,0,200);
176 swf_TextSetCharRecord(t,font,BANNER_TEXT,80,gbits,abits);
180 t = swf_InsertTag(t,ST_DEFINETEXT);
182 swf_SetU16(t,ID_HIGHLIGHT); // ID
191 swf_SetMatrix(t,NULL);
193 swf_TextCountBits(font,BANNER_TEXT,80,&gbits,&abits);
202 swf_TextSetInfoRecord(t,font,height/4,&rgb,0,200);
203 swf_TextSetCharRecord(t,font,BANNER_TEXT,80,gbits,abits);
207 t = swf_InsertTag(t,ST_DEFINEBUTTON);
209 swf_GetMatrix(NULL,&m);
214 swf_SetU16(t,ID_BUTTON); // ID
215 swf_ButtonSetRecord(t,BS_UP,ID_BANNER,1,&m,NULL);
216 swf_ButtonSetRecord(t,BS_DOWN|BS_HIT|BS_OVER,ID_HIGHLIGHT,1,&m,NULL);
217 swf_SetU8(t,0); // End of Button Records
218 swf_SetU8(t,0); // End of Action Records
221 t = swf_InsertTag(t,ST_PLACEOBJECT2);
223 swf_ObjectPlace(t,ID_BUTTON,1,NULL,NULL,NULL);
227 for (frame=0;frame<256;frame+=2)
230 t = swf_InsertTag(t,ST_DEFINESHAPE);
233 rgb.r = rgb.g = 0x00; rgb.b = 0xff;
234 j = swf_ShapeAddLineStyle(s,40,&rgb);
236 swf_SetU16(t,id); // ID
244 swf_SetShapeHeader(t,s);
245 swf_ShapeSetAll(t,s,0,0,j,0,0);
247 mapBox(frame,frame,frame>>1);
249 ShapeSquare(t,s,0,2,3,1,2*width,2*height);
250 ShapeSquare(t,s,4,5,7,6,2*width,2*height);
251 ShapeSquare(t,s,0,4,6,2,2*width,2*height);
252 ShapeSquare(t,s,1,3,7,5,2*width,2*height);
253 ShapeSquare(t,s,0,1,5,4,2*width,2*height);
254 ShapeSquare(t,s,2,6,7,3,2*width,2*height);
260 swf_GetCXForm(NULL,&cx1,1); // get default ColorTransforms
261 swf_GetCXForm(NULL,&cx2,1);
263 cx1.r1 = cx1.g1 = 0x80; // set alpha for blur effect
264 cx2.r1 = cx2.g1 = 0xc0;
266 for (frame=0;frame<256;frame+=2)
268 int id2 = ((frame-2)&255)+1;
269 int id3 = ((frame-4)&255)+1;
272 { t = swf_InsertTag(t,ST_REMOVEOBJECT2); swf_SetU16(t,2); // depth
273 t = swf_InsertTag(t,ST_REMOVEOBJECT2); swf_SetU16(t,3); // depth
274 t = swf_InsertTag(t,ST_REMOVEOBJECT2); swf_SetU16(t,4); // depth
277 t = swf_InsertTag(t,ST_PLACEOBJECT2);
279 swf_ObjectPlace(t,id,4,NULL,NULL,NULL);
281 t = swf_InsertTag(t,ST_PLACEOBJECT2);
283 swf_ObjectPlace(t,id2,3,NULL,&cx1,NULL);
285 t = swf_InsertTag(t,ST_PLACEOBJECT2);
287 swf_ObjectPlace(t,id3,2,NULL,&cx2,NULL);
289 t = swf_InsertTag(t,ST_SHOWFRAME);
292 t = swf_InsertTag(t,ST_END);
294 // swf_WriteCGI(&swf);
297 f = open("box.swf",O_RDWR|O_CREAT|O_TRUNC,0644);
298 if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
304 system("start ..\\box.swf");