示例#1
0
static Bool
NV40EXAPictSolid(NVPtr pNv, PicturePtr pPict, int unit)
{
	struct nouveau_pushbuf *push = pNv->pushbuf;

	PUSH_DATAu(push, pNv->scratch, SOLID(unit), 2);
	PUSH_DATA (push, pPict->pSourcePict->solidFill.color);
	PUSH_DATA (push, 0);
	BEGIN_NV04(push, NV30_3D(TEX_OFFSET(unit)), 8);
	PUSH_MTHDl(push, NV30_3D(TEX_OFFSET(unit)), pNv->scratch, SOLID(unit),
			 NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
	PUSH_DATA (push, NV40_3D_TEX_FORMAT_FORMAT_A8R8G8B8 | 0x8000 |
			 NV40_3D_TEX_FORMAT_LINEAR |
			 NV30_3D_TEX_FORMAT_DIMS_2D |
			 NV30_3D_TEX_FORMAT_NO_BORDER |
			 (1 << NV40_3D_TEX_FORMAT_MIPMAP_COUNT__SHIFT) |
			 NV30_3D_TEX_FORMAT_DMA0);
	PUSH_DATA (push, NV30_3D_TEX_WRAP_S_REPEAT |
			 NV30_3D_TEX_WRAP_T_REPEAT |
			 NV30_3D_TEX_WRAP_R_REPEAT);
	PUSH_DATA (push, NV40_3D_TEX_ENABLE_ENABLE);
	PUSH_DATA (push, 0x0000aae4);
	PUSH_DATA (push, NV30_3D_TEX_FILTER_MIN_NEAREST |
			 NV30_3D_TEX_FILTER_MAG_NEAREST | 0x3fd6);
	PUSH_DATA (push, 0x00010001);
	PUSH_DATA (push, 0x00000000);
	BEGIN_NV04(push, NV40_3D(TEX_SIZE1(unit)), 1);
	PUSH_DATA (push, 0x00100040);

	BEGIN_NV04(push, NV30_3D(VP_UPLOAD_CONST_ID), 17);
	PUSH_DATA (push, unit * 4);
	PUSH_DATAf(push, 1.0);
	PUSH_DATAf(push, 0.0);
	PUSH_DATAf(push, 0.0);
	PUSH_DATAf(push, 0.0);
	PUSH_DATAf(push, 0.0);
	PUSH_DATAf(push, 1.0);
	PUSH_DATAf(push, 0.0);
	PUSH_DATAf(push, 0.0);
	PUSH_DATAf(push, 0.0);
	PUSH_DATAf(push, 0.0);
	PUSH_DATAf(push, 1.0);
	PUSH_DATAf(push, 0.0);
	PUSH_DATAf(push, 1.0);
	PUSH_DATAf(push, 1.0);
	PUSH_DATAf(push, 0.0);
	PUSH_DATAf(push, 0.0);
	return TRUE;
}
示例#2
0
文件: physics.cpp 项目: jhunt/cube
bool cornertest(int mip, int x, int y, int dx, int dy, int &bx, int &by, int &bs)    // recursively collide with a mipmapped corner cube
{
    sqr *w = wmip[mip];
    int sz = ssize>>mip;
    bool stest = SOLID(SWS(w, x+dx, y, sz)) && SOLID(SWS(w, x, y+dy, sz));
    mip++;
    x /= 2;
    y /= 2;
    if(SWS(wmip[mip], x, y, ssize>>mip)->type==CORNER)
    {
        bx = x<<mip;
        by = y<<mip;
        bs = 1<<mip;
        return cornertest(mip, x, y, dx, dy, bx, by, bs);
    };
    return stest;
};
示例#3
0
void computeraytable(float vx, float vy)
{
    if(!ocull) return;

    odist = getvar("fog")*1.5f;

    float apitch = (float)fabs(player1->pitch);
    float af = getvar("fov")/2+apitch/1.5f+3;
    float byaw = (player1->yaw-90+af)/360*PI2;
    float syaw = (player1->yaw-90-af)/360*PI2;

    loopi(NUMRAYS)
    {
        float angle = i*PI2/NUMRAYS;
        if((apitch>45 // must be bigger if fov>120
        || (angle<byaw && angle>syaw)
        || (angle<byaw-PI2 && angle>syaw-PI2)
        || (angle<byaw+PI2 && angle>syaw+PI2))
        && !OUTBORD(vx, vy)
        && !SOLID(S(fast_f2nat(vx), fast_f2nat(vy))))       // try to avoid tracing ray if outside of frustrum
        {
            float ray = i*8/(float)NUMRAYS;
            float dx, dy;
            if(ray>1 && ray<3) { dx = -(ray-2); dy = 1; }
            else if(ray>=3 && ray<5) { dx = -1; dy = -(ray-4); }
            else if(ray>=5 && ray<7) { dx = ray-6; dy = -1; }
            else { dx = 1; dy = ray>4 ? ray-8 : ray; };
            float sx = vx;
            float sy = vy;
            for(;;)
            {
                sx += dx;
                sy += dy;
                if(SOLID(S(fast_f2nat(sx), fast_f2nat(sy))))    // 90% of time spend in this function is on this line
                {
                    rdist[i] = (float)(fabs(sx-vx)+fabs(sy-vy));
                    break;
                };
            };
        }
        else
        {
            rdist[i] = 2;
        };
    };
};
示例#4
0
void render_wall(sqr *o, sqr *s, int x1, int y1, int x2, int y2, int mip, sqr *d1, sqr *d2, bool topleft, int dir)
{
    if(minimap) return;
    if(SOLID(o) || o->type==SEMISOLID)
    {
        float c1 = s->floor;
        float c2 = s->floor;
        if(s->type==FHF) { c1 -= d1->vdelta/4.0f; c2 -= d2->vdelta/4.0f; }
        float f1 = s->ceil;
        float f2 = s->ceil;
        if(s->type==CHF) { f1 += d1->vdelta/4.0f; f2 += d2->vdelta/4.0f; }
        //if(f1-c1<=0 && f2-c2<=0) return;
        render_square(o->wtex, c1, c2, f1, f2, x1<<mip, y1<<mip, x2<<mip, y2<<mip, 1<<mip, d1, d2, topleft, dir);
        return;
    }
    {
        float f1 = s->floor;
        float f2 = s->floor;
        float c1 = o->floor;
        float c2 = o->floor;
        if(o->type==FHF && s->type!=FHF)
        {
            c1 -= d1->vdelta/4.0f;
            c2 -= d2->vdelta/4.0f;
        }
        if(s->type==FHF && o->type!=FHF)
        {
            f1 -= d1->vdelta/4.0f;
            f2 -= d2->vdelta/4.0f;
        }
        if(f1>=c1 && f2>=c2) goto skip;
        render_square(o->wtex, f1, f2, c1, c2, x1<<mip, y1<<mip, x2<<mip, y2<<mip, 1<<mip, d1, d2, topleft, dir);
    }
    skip:
    {
        float f1 = o->ceil;
        float f2 = o->ceil;
        float c1 = s->ceil;
        float c2 = s->ceil;
        if(o->type==CHF && s->type!=CHF)
        {
            f1 += d1->vdelta/4.0f;
            f2 += d2->vdelta/4.0f;
        }
        else if(s->type==CHF && o->type!=CHF)
        {
            c1 += d1->vdelta/4.0f;
            c2 += d2->vdelta/4.0f;
        }
        if(c1<=f1 && c2<=f2) return;
        render_square(o->utex, f1, f2, c1, c2, x1<<mip, y1<<mip, x2<<mip, y2<<mip, 1<<mip, d1, d2, topleft, dir);
    }
}
示例#5
0
void perlinarea(block &b, int scale, int seed, int psize)
{
	srand(seed);
	seed = rnd(10000);
	if(!scale) scale = 10;
	for(int x = b.x; x<=b.x+b.xs; x++) for(int y = b.y; y<=b.y+b.ys; y++)
	{
		sqr *s = S(x,y);
		if(!SOLID(s) && x!=b.x+b.xs && y!=b.y+b.ys) s->type = FHF;
		s->vdelta = (int)(perlinnoise_2D(x/((float)scale)+seed, y/((float)scale)+seed, 1000, 0.01f)*50+25);
		if(s->vdelta>128) s->vdelta = 0;
	};
};
示例#6
0
void dxfwriter::WriteCylinder(double centerx0, double centery0, double centerz0,
						   double radius, double height, double angleX)
{
	int num_faces = 16;
	double step = 2*M_PI / num_faces;
	double facelength = radius * sin(step / 2) + (radius - radius * cos(step / 2)) / cos(step / 2);
	double dx0, dy0, dz0, dx1, dy1, dz1, dx2, dy2, dz2, dx3, dy3, dz3;
	for(int i = 0; i < num_faces; i++)
	{
		double angle = i * step;
		dx0 = dx1 = dx2 = dx3 = centerx0 + radius * cos(angle);
		dx0 -= facelength * sin(angle);
		dx3 -= facelength * sin(angle);
		dx1 += facelength * sin(angle);
		dx2 += facelength * sin(angle);

		dy0 = dy1 = dy2 = dy3 = centery0 + radius * sin(angle) * sin(angleX);
		double temp = facelength * cos(angle) * sin(angleX);
		dy0 += temp ;
		dy3 += temp + height * cos(angleX);
		dy1 -= temp ;
		dy2 -= temp - height * cos(angleX);

		dz0 = dz1 = dz2 = dz3 = centerz0+ radius * sin(angle) * cos(angleX);
		temp = facelength * cos(angle) * cos(angleX);
		dz0 += temp ;
		dz3 += temp - height * sin(angleX);
		dz1 -= temp ;
		dz2 -= temp + height * sin(angleX);

		SOLID(0,1,2,3);
		line(0,1);
		line(1,2);
		line(2,3);
		line(3,0);
	}
}
示例#7
0
void dxfwriter::WriteBoxFromPoints(double dx0, double dy0, double dz0,
						   double dx1, double dy1, double dz1,
						   double dx2, double dy2, double dz2,
						   double dx3, double dy3, double dz3,
						   double dx4, double dy4, double dz4,
						   double dx5, double dy5, double dz5,
						   double dx6, double dy6, double dz6,
						   double dx7, double dy7, double dz7)
{

	SOLID(0,1,2,3);
	line(0,1);
	line(1,2);
	line(2,3);
	line(3,0);
	SOLID(0,1,5,4);
	line(0,1);
	line(1,5);
	line(5,4);
	line(4,0);
	SOLID(4,5,6,7);
	line(4,5);
	line(5,6);
	line(6,7);
	line(7,4);
	SOLID(6,7,3,2);
	line(6,7);
	line(7,3);
	line(3,2);
	line(2,6);
	SOLID(1,2,6,5);
	line(1,2);
	line(2,6);
	line(6,5);
	line(5,1);
	SOLID(3,0,4,7);
	line(3,0);
	line(0,4);
	line(4,7);
	line(7,3);
}
示例#8
0
void cursorupdate()                                     // called every frame from hud
{
    flrceil = ((int)(player1->pitch>=0))*2;

    volatile float x = worldpos.x;                      // volatile needed to prevent msvc7 optimizer bug?
    volatile float y = worldpos.y;
    volatile float z = worldpos.z;
    
    cx = (int)x;
    cy = (int)y;

    if(OUTBORD(cx, cy)) return;
    sqr *s = S(cx,cy);
    
    if(fabs(sheight(s,s,z)-z)>1)                        // selected wall
    {
        x += x>player1->o.x ? 0.5f : -0.5f;             // find right wall cube
        y += y>player1->o.y ? 0.5f : -0.5f;

        cx = (int)x;
        cy = (int)y;

        if(OUTBORD(cx, cy)) return;
    };
        
    if(dragging) makesel();

    const int GRIDSIZE = 5;
    const float GRIDW = 0.5f;
    const float GRID8 = 2.0f;
    const float GRIDS = 2.0f;
    const int GRIDM = 0x7;
    
    // render editing grid

    /*
    for(int ix = cx-GRIDSIZE; ix<=cx+GRIDSIZE; ix++) for(int iy = cy-GRIDSIZE; iy<=cy+GRIDSIZE; iy++)
    {
        if(OUTBORD(ix, iy)) continue;
        sqr *s = S(ix,iy);
        if(SOLID(s)) continue;
        float h1 = sheight(s, s, z);
        float h2 = sheight(s, SWS(s,1,0,ssize), z);
        float h3 = sheight(s, SWS(s,1,1,ssize), z);
        float h4 = sheight(s, SWS(s,0,1,ssize), z);
        if(s->tag) linestyle(GRIDW, 0xFF, 0x40, 0x40);
        else if(s->type==FHF || s->type==CHF) linestyle(GRIDW, 0x80, 0xFF, 0x80);
        else linestyle(GRIDW, 0x80, 0x80, 0x80);
        block b = { ix, iy, 1, 1 };
        box(b, h1, h2, h3, h4);
        linestyle(GRID8, 0x40, 0x40, 0xFF);
        if(!(ix&GRIDM))   line(ix,   iy,   h1, ix,   iy+1, h4);
        if(!(ix+1&GRIDM)) line(ix+1, iy,   h2, ix+1, iy+1, h3);
        if(!(iy&GRIDM))   line(ix,   iy,   h1, ix+1, iy,   h2);
        if(!(iy+1&GRIDM)) line(ix,   iy+1, h4, ix+1, iy+1, h3);
    };
    */

    if(!SOLID(s))
    {
        float ih = sheight(s, s, z);
        linestyle(GRIDS, 0xFF, 0xFF, 0xFF);
        block b = { cx, cy, 1, 1 };
        box(b, ih, sheight(s, SWS(s,1,0,ssize), z), sheight(s, SWS(s,1,1,ssize), z), sheight(s, SWS(s,0,1,ssize), z));
        linestyle(GRIDS, 0xFF, 0x00, 0x00);
        dot(cx, cy, ih);
        ch = (int)ih;
    };

    if(selset)
    {
        linestyle(GRIDS, 0xFF, 0x40, 0x40);
        box(sel, (float)selh, (float)selh, (float)selh, (float)selh);

	std::vector< std::pair<block, int> >::iterator sel_it = secondary_sel.begin();
	std::vector< std::pair<block, int> >::iterator sel_end = secondary_sel.end();

	for (; sel_it != sel_end; ++sel_it)
	    box(sel_it->first, (float)sel_it->second, (float)sel_it->second, (float)sel_it->second, (float)sel_it->second);
    };
};