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>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
26 #include "../rfxswf.h"
28 #define BANNER_TEXT "reflex" // banner is disabled due to new font handling
30 #define ID_BANNER 2001
31 #define ID_HIGHLIGHT 2002
32 #define ID_BUTTON 2003
35 int sX[] = { a,-a, a,-a, a,-a, a,-a};
36 int sY[] = { a, a,-a,-a, a, a,-a,-a};
37 int sZ[] = { a, a, a, a,-a,-a,-a,-a};
43 int sin_[512],cos_[512];
49 { d = ((double)i)/128*3.14159;
50 sin_[i] = (int)(sin(d)*256);
51 cos_[i] = (int)(cos(d)*256);
55 void ShapeSquare(LPTAG t,LPSHAPE s,int p1,int p2,int p3,int p4,int dx,int dy)
58 if (((dX[p2]-dX[p1])*(dY[p3]-dY[p1])-(dX[p3]-dX[p1])*(dY[p2]-dY[p1]))<0) return;
60 swf_ShapeSetMove(t,s,dX[p1]+dx,dY[p1]+dy);
61 swf_ShapeSetLine(t,s,dX[p2]-dX[p1],dY[p2]-dY[p1]);
62 swf_ShapeSetLine(t,s,dX[p3]-dX[p2],dY[p3]-dY[p2]);
63 swf_ShapeSetLine(t,s,dX[p4]-dX[p3],dY[p4]-dY[p3]);
64 swf_ShapeSetLine(t,s,dX[p1]-dX[p4],dY[p1]-dY[p4]);
68 void mapBox(int xw,int yw,int zw)
69 // simple trigonometry without using transformation matrices
71 int x1,y1,z1,x2,y2,z2,x3,y3,z3;
83 y1 = ( y*cos_[xw]- z*sin_[xw])>>8;
84 z1 = ( y*sin_[xw]+ z*cos_[xw])>>8;
87 x2 = (x1*cos_[yw]+z1*sin_[yw])>>8;
90 x3 = (x2*cos_[zw]-y2*sin_[zw])>>8;
91 y3 = (x2*sin_[zw]+y2*cos_[zw])>>8;
92 z3 = (z1*cos_[yw]-x1*sin_[yw])>>8;
94 dX[i] = x3*4000/(z3+950);
95 dY[i] = y3*4000/(z3+950);
100 int main (int argc,char ** argv)
106 S32 width = 800,height = 800;
113 /* f = open("Arial.efont",O_RDONLY);
115 { if (FAILED(swf_FontImport(f,&font)))
116 { fprintf(stderr,"Font import failed\n");
122 { fprintf(stderr,"Font not found\n");
127 swf_FontSetID(font,ID_FONT);
128 swf_FontInitUsage(&use);
129 swf_FontUse(&use,BANNER_TEXT);
130 swf_FontReduce(font,&use);
135 memset(&swf,0x00,sizeof(SWF));
138 swf.frameRate = 0x4000;
139 swf.movieSize.xmax = 4*width;
140 swf.movieSize.ymax = 4*height;
142 swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
150 /* This part can't be used because of missing fonts. Nevertheless it shows, how
151 rfxswf handles fonts, fontusages (in order to include only the used glyphs
152 into the output swf) and how to make a simple button
155 t = swf_InsertTag(t,ST_DEFINEFONT);
157 swf_FontSetDefine(t,font);
159 t = swf_InsertTag(t,ST_DEFINEFONTINFO);
161 swf_FontSetInfo(t,font);
163 t = swf_InsertTag(t,ST_DEFINETEXT);
165 swf_SetU16(t,ID_BANNER); // ID
174 swf_SetMatrix(t,NULL);
176 swf_TextCountBits(font,BANNER_TEXT,80,&gbits,&abits);
185 swf_TextSetInfoRecord(t,font,height/4,&rgb,0,200);
186 swf_TextSetCharRecord(t,font,BANNER_TEXT,80,gbits,abits);
190 t = swf_InsertTag(t,ST_DEFINETEXT);
192 swf_SetU16(t,ID_HIGHLIGHT); // ID
201 swf_SetMatrix(t,NULL);
203 swf_TextCountBits(font,BANNER_TEXT,80,&gbits,&abits);
212 swf_TextSetInfoRecord(t,font,height/4,&rgb,0,200);
213 swf_TextSetCharRecord(t,font,BANNER_TEXT,80,gbits,abits);
217 t = swf_InsertTag(t,ST_DEFINEBUTTON);
219 swf_GetMatrix(NULL,&m);
224 swf_SetU16(t,ID_BUTTON); // ID
225 swf_ButtonSetRecord(t,BS_UP,ID_BANNER,1,&m,NULL);
226 swf_ButtonSetRecord(t,BS_DOWN|BS_HIT|BS_OVER,ID_HIGHLIGHT,1,&m,NULL);
227 swf_SetU8(t,0); // End of Button Records
228 swf_SetU8(t,0); // End of Action Records
231 t = swf_InsertTag(t,ST_PLACEOBJECT2);
233 swf_ObjectPlace(t,ID_BUTTON,1,NULL,NULL,NULL);
237 for (frame=0;frame<256;frame+=2)
240 t = swf_InsertTag(t,ST_DEFINESHAPE);
243 rgb.r = rgb.g = 0x00; rgb.b = 0xff;
244 j = swf_ShapeAddLineStyle(s,40,&rgb);
246 swf_SetU16(t,id); // ID
254 swf_SetShapeHeader(t,s);
255 swf_ShapeSetAll(t,s,0,0,j,0,0);
257 mapBox(frame,frame,frame>>1);
259 ShapeSquare(t,s,0,2,3,1,2*width,2*height);
260 ShapeSquare(t,s,4,5,7,6,2*width,2*height);
261 ShapeSquare(t,s,0,4,6,2,2*width,2*height);
262 ShapeSquare(t,s,1,3,7,5,2*width,2*height);
263 ShapeSquare(t,s,0,1,5,4,2*width,2*height);
264 ShapeSquare(t,s,2,6,7,3,2*width,2*height);
270 swf_GetCXForm(NULL,&cx1,1); // get default ColorTransforms
271 swf_GetCXForm(NULL,&cx2,1);
273 cx1.r1 = cx1.g1 = 0x80; // set alpha for blur effect
274 cx2.r1 = cx2.g1 = 0xc0;
276 for (frame=0;frame<256;frame+=2)
278 int id2 = ((frame-2)&255)+1;
279 int id3 = ((frame-4)&255)+1;
282 { t = swf_InsertTag(t,ST_REMOVEOBJECT2); swf_SetU16(t,2); // depth
283 t = swf_InsertTag(t,ST_REMOVEOBJECT2); swf_SetU16(t,3); // depth
284 t = swf_InsertTag(t,ST_REMOVEOBJECT2); swf_SetU16(t,4); // depth
287 t = swf_InsertTag(t,ST_PLACEOBJECT2);
289 swf_ObjectPlace(t,id,4,NULL,NULL,NULL);
291 t = swf_InsertTag(t,ST_PLACEOBJECT2);
293 swf_ObjectPlace(t,id2,3,NULL,&cx1,NULL);
295 t = swf_InsertTag(t,ST_PLACEOBJECT2);
297 swf_ObjectPlace(t,id3,2,NULL,&cx2,NULL);
299 t = swf_InsertTag(t,ST_SHOWFRAME);
302 t = swf_InsertTag(t,ST_END);
304 // swf_WriteCGI(&swf);
307 f = open("box.swf",O_RDWR|O_CREAT|O_TRUNC,0644);
308 if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
314 system("start ..\\box.swf");