#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <proto/intuition.h>
#include <proto/gadtools.h>
#include <proto/graphics.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <dos/dos.h>
#include <exec/types.h>
#include <exec/memory.h>
#include <exec/libraries.h>
#include <datatypes/datatypes.h>
#include <datatypes/datatypesclass.h>
#include <datatypes/pictureclass.h>
#include <graphics/gfx.h>
#include <intuition/intuition.h>
#include <intuition/pointerclass.h>
#include <intuition/gadgetclass.h>
#include <libraries/gadtools.h>
#include <clib/intuition_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/graphics_protos.h>
#include <clib/exec_protos.h>
#include <clib/alib_protos.h>
#include <clib/datatypes_protos.h>
#include <clib/dos_protos.h>
#include <pragmas/datatypes_pragmas.h>
#include <pragmas/dos_pragmas.h>
#include <pragmas/exec_pragmas.h>
#include <pragmas/graphics_pragmas.h>
#include <pragmas/intuition_pragmas.h>
#include "pt/play.h"

#include <stdio.h>
struct Screen         *Scr = NULL;
struct IntuitionBase	*IntuitionBase;
struct GfxBase		*GfxBase;
struct Library		*GadToolsBase;
APTR                   VisualInfo = NULL;
struct RastPort *rp;
float a=0;

struct point3D
{
	int x;
	int y;
	int z;
};

struct matrix_3_3
{
	float A1;
	float A2;
	float A3;
	float B1;
	float B2;
	float B3;
	float C1;
	float C2;
	float C3;
};	

void face(struct point3D *a, struct point3D *b,
          struct point3D *c, struct point3D *d)
{
	long nz;

	nz = (long)(b->x - a->x) * (c->y - a->y)
	   - (long)(b->y - a->y) * (c->x - a->x);

	if(nz < 0)
	{
		Move(rp, a->x, a->y);
		Draw(rp, b->x, b->y);
		Draw(rp, c->x, c->y);
		Draw(rp, d->x, d->y);
		Draw(rp, a->x, a->y);
	}
}

int main()
{
int i;
struct point3D p1;
struct point3D p2;
struct point3D p3;
struct point3D p4;
struct point3D p5;
struct point3D p6;
struct point3D p7;
struct point3D p8;
struct point3D p1b;
struct point3D p2b;
struct point3D p3b;
struct point3D p4b;
struct point3D p5b;
struct point3D p6b;
struct point3D p7b;
struct point3D p8b;
float teta=0;
struct matrix_3_3 mat;

IntuitionBase	= (struct IntuitionBase *)OpenLibrary("intuition.library", 37);
GfxBase		= (struct GfxBase *)OpenLibrary("graphics.library", 37);
GadToolsBase	= OpenLibrary("gadtools.library", 37);
if ( ! ( Scr = OpenScreenTags( NULL, SA_Left,	0,
				SA_Top,		0,
				SA_Width,	320,
				SA_Height,	256,
				SA_Depth,	8,
				SA_Type,	CUSTOMSCREEN,
				SA_DisplayID,	PAL_MONITOR_ID,
				SA_Interleaved,	FALSE,
				SA_ShowTitle,	FALSE,
				SA_Behind,	FALSE,
				SA_Title,	"Rouflaquette3",
				TAG_DONE ))) return( 1L );

VisualInfo = GetVisualInfo( Scr, TAG_DONE );


p1.x=-1;
p1.y=-225;
p1.z=-1;

p2.x=-76;
p2.y=-150;
p2.z=-76;

p3.x=-28;
p3.y=-150;
p3.z=102;

p4.x=102;
p4.y=-150;
p4.z=-28;

p5.x=-103;
p5.y=-75;
p5.z=27;

p6.x=27;
p6.y=-75;
p6.z=-103;

p7.x=75;
p7.y=-76;
p7.z=75;

p8.x=0;
p8.y=0;
p8.z=0;
	

rp = &Scr->RastPort;
play_init("bigred-russiantecno.mod");
for(i=0;i<30000;i++)
{
	mat.A1=cos(teta);
	mat.A2=0;
	mat.A3=-sin(teta);
	mat.B1=0;
	mat.B2=1;
	mat.B3=0;
	mat.C1=sin(teta);
	mat.C2=0;
	mat.C3=cos(teta);
	
		p1b.x=mat.A1*p1.x+mat.B1*p1.y+mat.C1*p1.z+160;
	p1b.y=mat.A2*p1.x+mat.B2*p1.y+mat.C2*p1.z+240;
	p1b.z=mat.A3*p1.x+mat.B3*p1.y+mat.C3*p1.z;

	p2b.x=mat.A1*p2.x+mat.B1*p2.y+mat.C1*p2.z+160;
	p2b.y=mat.A2*p2.x+mat.B2*p2.y+mat.C2*p2.z+240;
	p2b.z=mat.A3*p2.x+mat.B3*p2.y+mat.C3*p2.z;

	p3b.x=mat.A1*p3.x+mat.B1*p3.y+mat.C1*p3.z+160;
	p3b.y=mat.A2*p3.x+mat.B2*p3.y+mat.C2*p3.z+240;
	p3b.z=mat.A3*p3.x+mat.B3*p3.y+mat.C3*p3.z;

	p4b.x=mat.A1*p4.x+mat.B1*p4.y+mat.C1*p4.z+160;
	p4b.y=mat.A2*p4.x+mat.B2*p4.y+mat.C2*p4.z+240;
	p4b.z=mat.A3*p4.x+mat.B3*p4.y+mat.C3*p4.z;

	p5b.x=mat.A1*p5.x+mat.B1*p5.y+mat.C1*p5.z+160;
	p5b.y=mat.A2*p5.x+mat.B2*p5.y+mat.C2*p5.z+240;
	p5b.z=mat.A3*p5.x+mat.B3*p5.y+mat.C3*p5.z;

	p6b.x=mat.A1*p6.x+mat.B1*p6.y+mat.C1*p6.z+160;
	p6b.y=mat.A2*p6.x+mat.B2*p6.y+mat.C2*p6.z+240;
	p6b.z=mat.A3*p6.x+mat.B3*p6.y+mat.C3*p6.z;

	p7b.x=mat.A1*p7.x+mat.B1*p7.y+mat.C1*p7.z+160;
	p7b.y=mat.A2*p7.x+mat.B2*p7.y+mat.C2*p7.z+240;
	p7b.z=mat.A3*p7.x+mat.B3*p7.y+mat.C3*p7.z;

	p8b.x=mat.A1*p8.x+mat.B1*p8.y+mat.C1*p8.z+160;
	p8b.y=mat.A2*p8.x+mat.B2*p8.y+mat.C2*p8.z+240;
	p8b.z=mat.A3*p8.x+mat.B3*p8.y+mat.C3*p8.z;
	
	teta=teta+0.02;	
		SetAPen(rp, 1);
	face(&p8b,&p6b,&p2b,&p5b);
	face(&p7b,&p3b,&p1b,&p4b);
	face(&p8b,&p7b,&p4b,&p6b);
	face(&p5b,&p2b,&p1b,&p3b);
	face(&p8b,&p5b,&p3b,&p7b);
	face(&p6b,&p4b,&p1b,&p2b);

	WaitTOF();
	WaitTOF();

	SetAPen(rp, 0);
	face(&p8b,&p6b,&p2b,&p5b);
	face(&p7b,&p3b,&p1b,&p4b);
	face(&p8b,&p7b,&p4b,&p6b);
	face(&p5b,&p2b,&p1b,&p3b);
	face(&p8b,&p5b,&p3b,&p7b);
	face(&p6b,&p4b,&p1b,&p2b);

	};

play_end();
if(VisualInfo)
	{
	FreeVisualInfo( VisualInfo );
	VisualInfo = NULL;
	}
if(Scr)	{
	CloseScreen( Scr );
	Scr = NULL;
	}

/*
		       /\
      /..\       _
     /....\   _ // AMIGA
    /......\  \X/  Powered by Motorola.
   /_......_\
     |....|
     |....|                             Taste the power. TODAY!
____ l....l _________________________ Amiga, Multitasking since 1985. ___
     |....|
     |....|             __________________________________________________
     |....|            |==================================================|
     |....|            | __  ___________  ___________            AMIGA == |
     |....|            |[_j  L_I_I_I_I_j  L_I_I_I_I_j            ~~~~~ == |
     |....|            |________________________________ _______ ______==_|
     |....|            |[__I_I_I_I_I_I_I_I_I_I_I_I_I_I_] [__I__] [_I_I_I_]|
     |....|            |[___I_I_I_I_I_I_I_I_I_I_I_I_]  |    _    [_I_I_I_]|
     |....|            |[__I_I_I_I_I_I_I_I_I_I_I_I_L___|  _[_]_  [_I_I_I_]|
     |....|            |[_____I_I_I_I_I_I_I_I_I_I_I____] [_I_I_] [_I_I_T ||
     |....|            | [__I__I_________________I__L_] ________ [___I_I_j|
     `----'            |                                                  |
                       l__________________________________________________|
	*/
	
}
