home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The CDPD Public Domain Collection for CDTV 3
/
CDPDIII.bin
/
pd
/
commodities
/
superdark
/
blankers
/
anim.dark.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-20
|
10KB
|
410 lines
/* Fichier star.dark.c */
/* Module appele par le programme principal */
/* pour effectuer un effet defini..appele par */
/* loadseg */
#include <time.h>
#include <exec/types.h>
#include <intuition/intuition.h>
#include <intuition/gadgetclass.h>
#include <graphics/gfx.h>
#include <graphics/gfxmacros.h>
#include <graphics/rastport.h>
#include <graphics/displayinfo.h>
#include <graphics/gfxbase.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/gadtools_protos.h>
#include "/includes/struct.h"
#include "/includes/tom_gadget.h"
char p_ver[]="$VER: Anim v1.2 (20/03/93)";
char *p_text_info=" anim\n\nThis effect just show you\na 3d object on screen\nbut this effect is still\nin developement!\n\nBy Thomas Landspurg";
UBYTE *TypeLabels[] = {
"Computer",
"Logo commodore",
0l };
struct tom_gadget my_gadg[]={
{"_Object", MX, 167,14,17,20,0, 0,0,0,(char *)TypeLabels},
{0, END_LISTE, 0, 0, 0, 0, 0,0,0,0,0}
};
extern struct GfxBase *GfxBase;
#define DEPTH 1
#define WIDTH 320
#define HEIGHT 256
#define MAX_PT 100
UWORD ColorTable[]={0,0xf0};
extern struct Screen *s;
extern struct RastPort *rp;
typedef struct pt{
int x,y,z;
};
typedef struct line{
int deb,fin;
};
typedef struct pt_2d{
int x,y;
};
typedef struct obj{
int nb_pt; /* Nombre de pt de l'element */
int nb_lines; /* nombre de lignes */
int ax,ay,az; /* Angles relatifs */
int cx,cy,cz; /* Deplacements relatifs */
struct pt *p_pt; /* tableau des pts de l'elem */
struct line *p_lines; /* tableau des lignes */
};
struct pt pt_comm[]={
{40,-20,10},{-10,-20,10},{-20,-10,10},
{-20,10,10},{-10, 20,10},{ 40, 20,10},
{25, 10,10},{10,10,10}, {10,35,10},
{-15,35,10},{-35,20,10},{-35,-20,10},
{-15,-35,10},{10,-35,10},{10,-10,10},{25,-10,10},
{40,-20,-10},{-10,-20,-10},{-20,-10,-10},
{-20,10,-10},{-10, 20,-10},{ 40, 20,-10},
{25, 10,-10},{10,10,-10}, {10,35,-10},
{-15,35,-10},{-35,20,-10},{-35,-20,-10},
{-15,-35,-10},{10,-35,-10},{10,-10,-10},{25,-10,-10}
};
struct line lines_comm[]={
{0,1},{1,2},{2,3},{3,4},{4,5},{5,6},{6,7},{7,8},{8,9},{9,10},{10,11},
{11,12},{12,13},{13,14},{14,15},{15,0},
{16,17},{17,18},{18,19},{19,20},{20,21},{21,22},{22,23},{23,24},{24,25},
{25,26},{26,27},{27,28},{28,29},{29,30},{30,31},{31,16},
{0,16},{5,21},{6,22},{7,23},{14,30},{15,31},
{8,24},{13,29},{10,26},{11,27}
};
struct obj logo_comm={32,32+10,0,0,0,0,0,0,pt_comm,lines_comm};
struct pt pt_corps[]={
{-20, 20,-20},{ 20, 20,-20},{ 20,-20,-20},{-20,-20,-20},
{-20, 20, 20},{ 20, 20, 20},{ 20,-20, 20},{-20,-20, 20},
{-28,-30,20},{28,-30,20},{30,-40,40},{-30,-40,40},
{-28,-30,10},{28,-30,10},{30,-40,10},{-30,-40,10},
{10,-5,10},{5,-10,10},{-10,10,10},
{7,-3,10},{4,-6,10},
{1,-7,10},{-2,-10,10},{-13,5,10}
};
struct line lines_corps[]={
{0,1},{1,2},{2,3},{3,0},
{4,5},{5,6},{6,7},{7,4},
{0,4},{1,5},{2,6},{3,7},
{8,9},{9,10},{10,11},{11,8},
{12,13},{13,14},{14,15},{15,12},
{8,12},{9,13},{10,14},{11,15},
{16,17},{17,18},{19,20},{21,22},{22,23}
};
struct obj corp={24,29,0,0,0,0,0,0,pt_corps,lines_corps};
int de=300; /* distance de l'ecran a l'observateur */
int d=600; /* distance de l'observateur au pt 0 */
/* tables de sinus et cosinus */
int t_cos[360]={
256,255,255,255,255,255,254,254,
253,252,252,251,250,249,248,247,
246,244,243,242,240,238,237,235,
233,232,230,228,226,223,221,219,
217,214,212,209,207,204,201,198,
196,193,190,187,184,181,177,174,
171,167,164,161,157,154,150,146,
143,139,135,131,127,124,120,116,
112,108,104,100,95,91,87,83,
79,74,70,66,61,57,53,48,
44,40,35,31,26,22,17,13,
8,4,0,-4,-8,-13,-17,-22,
-26,-31,-35,-40,-44,-48,-53,-57,
-61,-66,-70,-74,-79,-83,-87,-91,
-95,-100,-104,-108,-112,-116,-120,-124,
-128,-131,-135,-139,-143,-146,-150,-154,
-157,-161,-164,-167,-171,-174,-177,-181,
-184,-187,-190,-193,-196,-198,-201,-204,
-207,-209,-212,-214,-217,-219,-221,-223,
-226,-228,-230,-232,-233,-235,-237,-238,
-240,-242,-243,-244,-246,-247,-248,-249,
-250,-251,-252,-252,-253,-254,-254,-255,
-255,-255,-255,-255,-256,-255,-255,-255,
-255,-255,-254,-254,-253,-252,-252,-251,
-250,-249,-248,-247,-246,-244,-243,-242,
-240,-238,-237,-235,-233,-232,-230,-228,
-226,-223,-221,-219,-217,-214,-212,-209,
-207,-204,-201,-198,-196,-193,-190,-187,
-184,-181,-177,-174,-171,-167,-164,-161,
-157,-154,-150,-146,-143,-139,-135,-131,
-127,-124,-120,-116,-112,-108,-104,-100,
-95,-91,-87,-83,-79,-74,-70,-66,
-61,-57,-53,-48,-44,-40,-35,-31,
-26,-22,-17,-13,-8,-4,0,4,
8,13,17,22,26,31,35,40,
44,48,53,57,61,66,70,74,
79,83,87,91,95,100,104,108,
112,116,120,124,128,131,135,139,
143,146,150,154,157,161,164,167,
171,174,177,181,184,187,190,193,
196,198,201,204,207,209,212,214,
217,219,221,223,226,228,230,232,
233,235,237,238,240,242,243,244,
246,247,248,249,250,251,252,252,
253,254,254,255,255,255,255,255};
int t_sin[360]={
0,4,8,13,17,22,26,31,
35,40,44,48,53,57,61,66,
70,74,79,83,87,91,95,100,
104,108,112,116,120,124,128,131,
135,139,143,146,150,154,157,161,
164,167,171,174,177,181,184,187,
190,193,196,198,201,204,207,209,
212,214,217,219,221,223,226,228,
230,232,233,235,237,238,240,242,
243,244,246,247,248,249,250,251,
252,252,253,254,254,255,255,255,
255,255,256,255,255,255,255,255,
254,254,253,252,252,251,250,249,
248,247,246,244,243,242,240,238,
237,235,233,232,230,228,226,223,
221,219,217,214,212,209,207,204,
201,198,196,193,190,187,184,181,
177,174,171,167,164,161,157,154,
150,146,143,139,135,131,127,124,
120,116,112,108,104,100,95,91,
87,83,79,74,70,66,61,57,
53,48,44,40,35,31,26,22,
17,13,8,4,0,-4,-8,-13,
-17,-22,-26,-31,-35,-40,-44,-48,
-53,-57,-61,-66,-70,-74,-79,-83,
-87,-91,-95,-100,-104,-108,-112,-116,
-120,-124,-128,-131,-135,-139,-143,-146,
-150,-154,-157,-161,-164,-167,-171,-174,
-177,-181,-184,-187,-190,-193,-196,-198,
-201,-204,-207,-209,-212,-214,-217,-219,
-221,-223,-226,-228,-230,-232,-233,-235,
-237,-238,-240,-242,-243,-244,-246,-247,
-248,-249,-250,-251,-252,-252,-253,-254,
-254,-255,-255,-255,-255,-255,-256,-255,
-255,-255,-255,-255,-254,-254,-253,-252,
-252,-251,-250,-249,-248,-247,-246,-244,
-243,-242,-240,-238,-237,-235,-233,-232,
-230,-228,-226,-223,-221,-219,-217,-214,
-212,-209,-207,-204,-201,-198,-196,-193,
-190,-187,-184,-181,-177,-174,-171,-167,
-164,-161,-157,-154,-150,-146,-143,-139,
-135,-131,-128,-124,-120,-116,-112,-108,
-104,-100,-95,-91,-87,-83,-79,-74,
-70,-66,-61,-57,-53,-48,-44,-40,
-35,-31,-26,-22,-17,-13,-8,-4
};
/********************* Rotation dans le plan ************/
void rot(angle,p_x,p_y)
int angle,*p_x,*p_y;
{
int x,y;
x= (*p_x)*t_cos[angle]+(*p_y)*t_sin[angle];
y=-(*p_x)*t_sin[angle]+(*p_y)*t_cos[angle];
*p_x=x>>8;
*p_y=y>>8;
}
/***************** Calcul de la projection 3D->2D ******/
void calc_coord(p_pt,p_x,p_y)
struct pt *p_pt;
int *p_x,*p_y;
{
if(d+p_pt->z!=NULL){
*p_x= WIDTH/2+(p_pt->x*de)/(d+p_pt->z);
*p_y=HEIGHT/2-(p_pt->y*de)/(d+p_pt->z);
}
}
/************** Affichage de l'objet ******************/
void AffObj(rp,p_obj,ax,ay,az,ox,oy,oz,old_pt)
struct RastPort *rp;
struct obj *p_obj;
int ax,ay,az;
int ox,oy,oz;
struct pt_2d *old_pt;
{
int i;
struct line *p_lines;
struct pt *p_pt,pt_cour;
int cx,cy,cz,deb,fin;
struct pt_2d tab_pt[MAX_PT];
/* Calcul du point de depart */
cx=4*p_obj->cx;
cy=4*p_obj->cy;
cz=4*p_obj->cz;
rot(az,&cx,&cy);
rot(ax,&cy,&cz);
rot(ay,&cz,&cx);
/* nouveau angles de rotation */
p_pt=p_obj->p_pt;
ax=((360+ax+p_obj->ax))%360;
ay=((360+ay+p_obj->ay))%360;
az=((360+az+p_obj->az))%360;
/* rotation et passage 3d/2D pour tt les points */
for(i=0;i<p_obj->nb_pt;i++){
pt_cour.x=4*(p_pt->x);
pt_cour.y=4*(p_pt->y);
pt_cour.z=4*(p_pt->z);
rot(az,&pt_cour.x,&pt_cour.y);
rot(ax,&pt_cour.y,&pt_cour.z);
rot(ay,&pt_cour.z,&pt_cour.x);
pt_cour.x+=cx+ox;
pt_cour.y+=cy+oy;
pt_cour.z+=cz+oz;
calc_coord(&pt_cour,&tab_pt[i].x,&tab_pt[i].y);
p_pt++;
}
p_pt=p_obj->p_pt;
p_lines=p_obj->p_lines;
/* affichage des lignes */
for(i=0;i<p_obj->nb_lines;i++){
deb=p_lines->deb;
if(deb>=0){
Move(rp,tab_pt[deb].x,tab_pt[deb].y);
}else{
if(deb==-MAX_PT)deb=0;
Move(rp,old_pt[-deb].x,old_pt[-deb].y);
}
fin=p_lines->fin;
if(fin>=0){
Draw(rp,tab_pt[fin].x,tab_pt[fin].y);
}else{
if(fin==-MAX_PT)fin=0;
Draw(rp,old_pt[-fin].x,old_pt[-fin].y);
}
p_lines++;
}
}
/************** Programme principal ********************************/
void __saveds dark()
{
int i,dir;
struct RasInfo ri;
struct BitMap b1,b2,*b;
struct ViewPort vp;
struct View v,*oldview;
struct RastPort rp1,rp2,*rp;
struct obj *p_obj;
int flg_err;
oldview=((struct GfxBase *)GfxBase)->ActiView;
InitView(&v);
v.ViewPort=&vp;
InitVPort(&vp);
vp.DWidth=WIDTH;
vp.DHeight=HEIGHT;
vp.RasInfo=&ri;
vp.ColorMap=(struct ColorMap *)GetColorMap(1<<DEPTH);
flg_err=FALSE;
InitBitMap(&b1,DEPTH,WIDTH,HEIGHT);
InitBitMap(&b2,DEPTH,WIDTH,HEIGHT);
for(i=0;i<DEPTH;i++){
b1.Planes[i]=(PLANEPTR)AllocRaster(WIDTH,HEIGHT);
if(b1.Planes[i]==0){
flg_err=TRUE;
}
b2.Planes[i]=(PLANEPTR)AllocRaster(WIDTH,HEIGHT);
if(b2.Planes[i]==0){
flg_err=TRUE;
}
}
InitRastPort(&rp1);
InitRastPort(&rp2);
rp1.BitMap=&b1;
rp2.BitMap=&b2;
ri.BitMap=&b1;
ri.RxOffset=0;
ri.RyOffset=0;
ri.Next=NULL;
LoadRGB4(&vp,ColorTable,1<<DEPTH);
FreeSprite (0);
GfxBase->SpriteReserved|=1;
dir=2;
switch(my_gadg[0].value){
case 0:
p_obj=&corp;
break;
case 1:
default:
p_obj=&logo_comm;
break;
}
p_obj->cz=2000;
while((tst_end()==FALSE)&&(flg_err==FALSE)){
i++;
if(p_obj->cz>0)p_obj->cz-=10;
if((i%2)==1){
b=&b1;
rp=&rp1;
}else{
b=&b2;
rp=&rp2;
}
SetRast(rp,0);
SetAPen(rp,1);
/* affichage de l'objet */
AffObj(rp,p_obj,0,0,0,0,0,100,NULL);
/* Calcul du mvt des ailes */
p_obj->ay+=1;
ri.BitMap=b;
MakeVPort(&v,&vp);
MrgCop(&v);
LoadView(&v);
WaitTOF();
}
cleanup3:
for(i=0;i<DEPTH;i++){
if(b1.Planes[i]!=0){
FreeRaster(b1.Planes[i],WIDTH,HEIGHT);
}
if(b2.Planes[i]!=0){
FreeRaster(b2.Planes[i],WIDTH,HEIGHT);
}
}
LoadView(oldview);
FreeColorMap(vp.ColorMap);
FreeVPortCopLists(&vp);
FreeCprList(v.LOFCprList);
}
void proc_init()
{
}
void proc_save()
{
}
void proc_end()
{
}