⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 database.c

📁 学习c++必备
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * database.c   $Revision: 1.2 $ */#include <stdlib.h>#include <stdio.h>#include <math.h>#include "skyfly.h"#if defined(_WIN32)#pragma warning (disable:4244)  /* disable bogus conversion warnings */#pragma warning (disable:4305)  /* VC++ 5.0 version of above warning. */#endif#define cosf(a)		cos((float)a)#define sinf(a)  	sin((float)a)#define sqrtf(a)  	sqrt((float)a)#define expf(a)  	exp((float)a)static void create_terrain(void);static void erode_terrain(void);static void color_terrain(void);static void init_cells(void);static void put_cell(float *source, perfobj_t *pobj);static void put_paper_plane(float *source, perfobj_t *pobj);static void put_texture_bind(int bind, perfobj_t *pobj);int clouds;static float paper_plane_vertexes[] = {/*Nx  Ny  Nz   Vx     Vy    Vz *//* ----------------------------    Top view of plane, middle streached open  */ 0.2, 0., .98, -.10,    0,  .02,/* vertex #'s      4 (.48,0,-.06)            */ 0., 0., 1.,   -.36,  .20, -.04,/*                 .                         */ 0., 0., 1.,    .36,  .01,    0,/*                ...                        */ 0., 0.,-1.,   -.32,  .02,    0,/*                 .             +X          */ 0., 1., 0.,    .48,    0, -.06,/*               2 . 6,8          ^          */ 0., 1., 0.,   -.30,    0, -.12,/*               . . .            |          */ 0.,-1., 0.,    .36, -.01,    0,/*              .. . ..           |          */ 0.,-1., 0.,   -.32, -.02,    0,/*               . . .            |          */ 0., 0.,-1.,    .36, -.01,    0,/*             . . . . .  +Y<-----*          */ 0., 0.,-1.,   -.36, -.20, -.04,/*               . . .     for this picture  */ -0.2, 0., .98,  -.10,  0,  .02,/*            .  . . .  .  coord system rot. */ -0.2, 0., -.98, -.10,  0,  .02,/*               . . .     90 degrees        */ 0., 0., -1.,  -.36,  .20, -.04,/*           .   . . .   .                   */ 0., 0., -1.,   .36,  .01,    0,/*               . # .           # marks     */ 0., 0., 1.,   -.32,  .02,    0,/*          .    . . .    .   (0,0) origin   */ 0., -1., 0.,   .48,    0, -.06,/*               . . .         (z=0 at top   */ 0., -1., 0.,  -.30,    0, -.12,/*         .     0 . 10    .    of plane)    */ 0.,1., 0.,     .36, -.01,    0,/*             . . . . .                     */ 0.,1., 0.,    -.32, -.02,    0,/*        .  .   . . .   .  .                */ 0., 0.,1.,     .36, -.01,    0,/*         .     . . .     .                 */ 0., 0.,1.,    -.36, -.20, -.04,/*       1.......3.5.7.......9               */ 0.2, 0., -.98,  -.10,  0,  .02,/* (-.36,.2,-.04)                            */};#define SIZE    400float *A;void init_paper_planes(void){    perfobj_t       *pobj;    /*      * create various perf-objs for planes      */    pobj = &(SharedData->paper_plane_obj);    pobj->flags = SharedData->paper_plane_flags;    pobj->vdata = (float *) SharedData->paper_plane_verts;    put_paper_plane(paper_plane_vertexes, pobj);    pobj = &(SharedData->paper_plane_start_obj);    pobj->flags = SharedData->paper_plane_start_flags;    *(pobj->flags) = PD_PAPER_PLANE_MODE;    *(pobj->flags + 1) = PLANES_START;    *(pobj->flags + 2) = PD_END;    pobj = &(SharedData->paper_plane_2ndpass_obj);    pobj->flags = SharedData->paper_plane_2ndpass_flags;    *(pobj->flags) = PD_PAPER_PLANE_MODE;    *(pobj->flags + 1) = PLANES_SECOND_PASS;    *(pobj->flags + 2) = PD_END;    pobj = &(SharedData->paper_plane_end_obj);    pobj->flags = SharedData->paper_plane_end_flags;    *(pobj->flags) = PD_PAPER_PLANE_MODE;    *(pobj->flags + 1) = PLANES_END;    *(pobj->flags + 2) = PD_END;}/* * create perfobj from static definition of plane geometry above */static void put_paper_plane(float *source, perfobj_t *pobj){    int             j;    perfobj_vert_t *pdataptr =(perfobj_vert_t *) pobj->vdata;    unsigned int  *flagsptr = pobj->flags;    float          *sp = source;    *flagsptr++ = PD_DRAW_PAPER_PLANE;    for (j = 0; j < 22; j++) {        putn3fdata(sp + 0, pdataptr);        putv3fdata(sp + 3, pdataptr);        sp += 6;        pdataptr++;    }    *flagsptr++ = PD_END;}static void put_texture_bind(int bind, perfobj_t *pobj){	unsigned int  *flagsptr = pobj->flags;	*flagsptr++ = PD_TEXTURE_BIND;	*flagsptr++ = bind;	*flagsptr++ = PD_END;}static void put_clouds_vert(float s, float t, float x, float y, float z,				perfobj_vert_t *pdataptr){	float           D[5];	D[0] = s;	D[1] = t;	D[2] = x;	D[3] = y;	D[4] = z;	putt2fdata(D, pdataptr);	putv3fdata(D + 2, pdataptr);}float S[SIZE][SIZE];float T[SIZE][SIZE];float C[SIZE][SIZE][3];int   M[SIZE][SIZE];void init_terrain(void){	GridDim = CellDim * NumCells;	XYScale = (float)GRID_RANGE / (float)GridDim;	CellSize = (float)GRID_RANGE / (float)NumCells;	create_terrain();	erode_terrain();	color_terrain();	init_cells();}#define SKY                             50.void init_clouds(void){    perfobj_t *pobj;    perfobj_vert_t *pdataptr;	clouds = 0;    pobj = &(SharedData->clouds_texture_obj);    pobj->flags = SharedData->clouds_texture_flags;    put_texture_bind(2,pobj);    pobj = &(SharedData->clouds_obj);    pobj->flags = SharedData->clouds_flags;    pobj->vdata = (float *)SharedData->clouds_verts;    *(pobj->flags+ 0) = PD_DRAW_CLOUDS;    *(pobj->flags+ 1) = PD_END;    pdataptr =(perfobj_vert_t *) pobj->vdata;    put_clouds_vert(0.,0., -SKY, -SKY, SKY_HIGH,pdataptr);    pdataptr++;    put_clouds_vert(24.,0.,  SKY+GRID_RANGE, -SKY, SKY_HIGH,pdataptr);    pdataptr++;    put_clouds_vert(24.,24.,  SKY+GRID_RANGE,  SKY+GRID_RANGE, SKY_HIGH,pdataptr);    pdataptr++;    put_clouds_vert(0.,24., -SKY,  SKY+GRID_RANGE, SKY_HIGH,pdataptr);}static void create_terrain(void){	int             r, c, i, x1, y1, x2, y2;	int             hillsize;    hillsize = GRID_RANGE / 12;    A = (float*)calloc(GridDim * GridDim, sizeof(float));    /*     *  initialize elevation to zero, except band down middle     *  where make a maximum height 'hill' that will later be     *  inverted to make the negative elevation 'canyon'     */    for (r = 0; r < GridDim; r++)        for (c = 0; c < GridDim; c++)             if(r>=(GridDim/2-2-IRND(2)) && r<=(GridDim/2+2+IRND(2)))                A[r * GridDim + c] = 1.0;             else                A[r * GridDim + c] = 0.0;    /*     * create random sinusoidal hills that add on top     * of each other     */    for (i = 1; i <= 10*GridDim; i++) {        /* randomly position hill */        x1 = IRND(GridDim - hillsize);        x2 = x1 + hillsize/ 8 + IRND(hillsize-hillsize/ 8);        y1 = IRND(GridDim - hillsize);        y2 = y1 + hillsize/ 8 + IRND(hillsize-hillsize/ 8);        if((x1<=GridDim/2-4 && x2>=GridDim/2-4) ||            (x1<=GridDim/2+4 && x2>=GridDim/2+4))        {            x1 = IRND(2)-2 + GridDim/2;            x2 = x1 + IRND(GridDim/2 - x1 + 2);        }        /* make a sinusoidal hill */        for (r = x1; r < x2; r++)            for (c = y1; c < y2; c++) {                A[r * GridDim + c] +=.35 *                    (sinf(M_PI * (float) (r - x1) / (float) (x2 - x1)) *					 (sinf(M_PI * (float) (c - y1) / (float) (y2 - y1))));            }    }    /* clamp the elevation of the terrain */	for (r = 1; r < GridDim; r++)		for (c = 1; c < GridDim; c++) {			A[r * GridDim + c] = MIN(A[r * GridDim + c], .95);			A[r * GridDim + c] = MAX(A[r * GridDim + c], 0.);		}}#define NUM_DROPS                       80static void erode_terrain(void){    float           x, y, xv, yv, dx, dy;    float           cut, min, take;    int             nm;    int             t, xi, yi, xo, yo, done;    int             ii, jj, r, c;    for (nm = 1; nm < NUM_DROPS*GridDim; nm++) {        /* find a random position to start the 'rain drop' */        x = (float) (IRND(GridDim));        y = (float) (IRND(GridDim));        /* Clamp x and y to be inside grid */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -