
/*
	Ninja Sample
	
	COPYRIGHT (C) SEGA ENTERSRISES,LTD.

	Sample By Akira Matsuo

	1997.10.20
*/

#include "Ninja.h"

#define p_num 12
#define R 400.f

#define POINT_NUM 4000

void MallocP3C(NJS_POINT3COL *p3c, Uint32 n); /* See Sample.c */
void FreeP3C(NJS_POINT3COL *p3c);             /* See Sample.c */

void NormalPolygon3D()
{
    int i = 0;
    NJS_POINT3COL p;
    Float x = R, y = 0;
    Float u = 127.f, v = 0.f;
    Float SinVal = njSin(NJM_DEG_ANG(360/p_num));
    Float CosVal = njCos(NJM_DEG_ANG(360/p_num));

    MallocP3C(&p, p_num);


    do{
        p.p[i].x = R*njCos(NJM_DEG_ANG(360/(p_num))*i);
        p.p[i].y = R*njSin(NJM_DEG_ANG(360/(p_num))*i);
        p.p[i].z = 0.f;/* -2000.f; */
        p.col[i].argb.a = 0xff;
        p.col[i].argb.r = 0xff;
        p.col[i].argb.g = 0xff;
        p.col[i].argb.b = 0xff;
        p.tex[i].tex.u = (short)(128.f*njCos(NJM_DEG_ANG(360/(p_num))*i))+128;
        p.tex[i].tex.v = (short)(128.f* (-njSin(NJM_DEG_ANG(360/(p_num))*i)))+128;
        x = p.p[i].x;
        y = p.p[i].y;
        u = p.tex[i].tex.u;
        v = p.tex[i].tex.v;
        i++;
    }while(i < p_num);

    njDrawPolygon3D(&p, p_num, NJD_DRAW_NORMAL|NJD_FILL|NJD_USE_TEXTURE);
    FreeP3C(&p);
}


void Triangle3D()
{
    int i = 0;
    NJS_POINT3COL p;

    MallocP3C(&p, 3);

    do{
        p.p[i].x = R*njCos(NJM_DEG_ANG(360/(3))*i);
        p.p[i].y = R*njSin(NJM_DEG_ANG(360/(3))*i);
        p.p[i].z = 0.f;/* -2000.f; */
        p.col[i].argb.a = 0xff;
        p.col[i].argb.r = 0xff;
        p.col[i].argb.g = 0xff;
        p.col[i].argb.b = 0xff;
        p.tex[i].tex.u = (short)(128.f*njCos(NJM_DEG_ANG(360/(3))*i))+128;
        p.tex[i].tex.v = (short)(128.f* (-njSin(NJM_DEG_ANG(360/(3))*i)))+128;
        i++;
    }while(i < 3);
    
    njDrawTriangle3D(&p, 1, NJD_DRAW_NORMAL|NJD_FILL|NJD_USE_TEXTURE);
    FreeP3C(&p);
}



void NormalLine3D()
{
    NJS_POINT3COL p;

    MallocP3C(&p, 2);
    p.p[0].x = 0.f;
    p.p[0].y = 0.f;
    p.p[0].z = 0.f;
    p.col[0].color = 0xffff0000;
    p.p[1].x = 450.f;
    p.p[1].y = 0.f;
    p.p[1].z = 0.f;
    p.col[1].color = 0xffff0000;
    njDrawLine3D(&p, 1, NJD_DRAW_NORMAL);
    FreeP3C(&p);
}




void NormalPoint3D()
{
    int i;
    static int j = 0;
    static float ang = 0.f;
    static NJS_POINT3COL p;/* [POINT_NUM]; */
    static NJS_POINT3 p3[POINT_NUM];
    static NJS_COLOR col[POINT_NUM];

    p.p = p3; p.col = col;
    if(j == 0){
        for(i = 0; i < POINT_NUM; i++){
            p.p[i].x = njRandom()*6000.f-3000.f;
            p.p[i].y = njRandom()*6000.f-3000.f;
            p.p[i].z = -njRandom()*10000.f;/* +2000.f; */
            p.col[i].argb.a = (Uint8)(0xff*njRandom());
            p.col[i].argb.r = (Uint8)(0xff*njRandom());
            p.col[i].argb.g = (Uint8)(0xff*njRandom());
            p.col[i].argb.b = (Uint8)(0xff*njRandom());
        }
        j = 1;
    }
    /* njRotateZ(NULL, NJM_DEG_ANG((int)ang)); */
    njDrawPoint3D(&p, POINT_NUM, NJD_DRAW_NORMAL);
    if(ang < 360.f)
        ang +=.1f;
    else
        ang = 0.f;
 }


