예제 #1
0
void
sqrt(int p2) {
#ifndef NEQN
	float nps;

	nps = (int)(EFFPS(((eht[p2]*9)/10+(resolution/POINT-1))/(resolution/POINT)));
#endif /* NEQN */
	yyval.token = p2;
#ifndef NEQN
	eht[yyval.token] = VERT(EM(1.2, nps));
	if(dbg)printf(".\tsqrt: S%d <- S%d;b=%g, h=%g\n", 
		yyval.token, p2, ebase[yyval.token], eht[yyval.token]);
	if (ital(rfont[yyval.token]))
		printf(".as %d \\|\n", yyval.token);
#endif /* NEQN */
	nrwid(p2, ps, p2);
#ifndef NEQN
	printf(".ds %d \\v'%gp'\\s%s\\v'-.2m'\\(sr\\l'\\n(%du\\(rn'\\v'.2m'\\s%s", 
		yyval.token, ebase[p2], tsize(nps), p2, tsize(ps));
	printf("\\v'%gp'\\h'-\\n(%du'\\*(%d\n", -ebase[p2], p2, p2);
	lfont[yyval.token] = ROM;
#else /* NEQN */
	printf(".ds %d \\v'%du'\\e\\L'%du'\\l'\\n(%du'",
		p2, ebase[p2], -eht[p2], p2);
	printf("\\v'%du'\\h'-\\n(%du'\\*(%d\n", eht[p2]-ebase[p2], p2, p2);
	eht[p2] += VERT(1);
	if(dbg)printf(".\tsqrt: S%d <- S%d;b=%d, h=%d\n", 
		p2, p2, ebase[p2], eht[p2]);
#endif /* NEQN */
}
예제 #2
0
void
lpile(int type, int p1, int p2) {
	int i, nlist, nlist2, mid;
#ifndef	NEQN
	float h, b, bi, hi, gap;
#else	/* NEQN */
	int h, b, bi, hi, gap;
#endif	/* NEQN */
	yyval.token = oalloc();
#ifndef NEQN
	gap = VERT(EM(0.4, ps)); /* 4/10 m between blocks */
#else /* NEQN */
	gap = VERT(1);
#endif /* NEQN */
	if( type=='-' ) gap = 0;
	nlist = p2 - p1;
	nlist2 = (nlist+1)/2;
	mid = p1 + nlist2 -1;
	h = 0;
	for( i=p1; i<p2; i++ )
		h += eht[lp[i]];
	eht[yyval.token] = h + (nlist-1)*gap;
	b = 0;
	for( i=p2-1; i>mid; i-- )
		b += eht[lp[i]] + gap;
	ebase[yyval.token] = (nlist%2) ? b + ebase[lp[mid]]
#ifndef NEQN
			: b - VERT(EM(0.5, ps)) - gap;
#else /* NEQN */
			: b - VERT(1) - gap;
예제 #3
0
void
boverb(int p1, int p2) {
	int treg;
#ifndef	NEQN
	float h, b, d;
#else	/* NEQN */
	int h, b, d;
#endif	/* NEQN */

	treg = oalloc();
	yyval.token = p1;
#ifndef NEQN
	d = VERT(EM(0.3, ps));
	h = eht[p1] + eht[p2] + d;
#else /* NEQN */
	d = VERT(1);
	h = eht[p1] + eht[p2];
#endif /* NEQN */
	b = eht[p2] - d;
#ifndef	NEQN
	if(dbg)printf(".\tb:bob: S%d <- S%d over S%d; b=%g, h=%g\n", 
		yyval.token, p1, p2, b, h);
#else	/* NEQN */
	if(dbg)printf(".\tb:bob: S%d <- S%d over S%d; b=%d, h=%d\n", 
		yyval.token, p1, p2, b, h);
#endif	/* NEQN */
	nrwid(p1, ps, p1);
	nrwid(p2, ps, p2);
	printf(".nr %d \\n(%d\n", treg, p1);
	printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n", p2, treg, treg, p2);
#ifndef NEQN
	printf(".nr %d \\n(%d+\\s%s.5m\\s0\n", treg, treg, tsize(EFFPS(ps)));
	printf(".ds %d \\v'%gp'\\h'\\n(%du-\\n(%du/2u'\\*(%d\\\n", 
		yyval.token, eht[p2]-ebase[p2]-d, treg, p2, p2);
	printf("\\h'-\\n(%du-\\n(%du/2u'\\v'%gp'\\*(%d\\\n", 
		p2, p1, -(eht[p2]-ebase[p2]+d+ebase[p1]), p1);
	printf("\\h'-\\n(%du-\\n(%du/2u+.1m'\\v'%gp'\\l'\\n(%du-.2m'\\h'.1m'\\v'%gp'\n", 
		 treg, p1, ebase[p1]+d, treg, d);
#else /* NEQN */
	printf(".ds %d \\v'%du'\\h'\\n(%du-\\n(%du/2u'\\*(%d\\\n", 
		yyval.token, eht[p2]-ebase[p2]-d, treg, p2, p2);
	printf("\\h'-\\n(%du-\\n(%du/2u'\\v'%du'\\*(%d\\\n", 
		p2, p1, -eht[p2]+ebase[p2]-ebase[p1], p1);
	printf("\\h'-\\n(%du-\\n(%du-2u/2u'\\v'%du'\\l'\\n(%du'\\v'%du'\n", 
		 treg, p1, ebase[p1], treg, d);
#endif /* NEQN */
	ebase[yyval.token] = b;
	eht[yyval.token] = h;
	lfont[yyval.token] = rfont[yyval.token] = 0;
	ofree(p2);
	ofree(treg);
}
예제 #4
0
파일: io.c 프로젝트: bapt/heirloom-doctools
void
putout(int p1) {
#ifndef	NEQN
	float before, after;
	if(dbg)printf(".\tanswer <- S%d, h=%g,b=%g\n",p1, eht[p1], ebase[p1]);
#else	/* NEQN */
	int before, after;
	if(dbg)printf(".\tanswer <- S%d, h=%d,b=%d\n",p1, eht[p1], ebase[p1]);
#endif	/* NEQN */
	eqnht = eht[p1];
	printf(".ds %d ", p1);
	/* suppposed to leave room for a subscript or superscript */
#ifndef NEQN
	before = eht[p1] - ebase[p1] - VERT(EM(1.2, ps));
#else /* NEQN */
	before = eht[p1] - ebase[p1] - VERT(3);	/* 3 = 1.5 lines */
#endif /* NEQN */
	if (spaceval != NULL)
		printf("\\x'0-%s'", spaceval);
	else if (before > 0)
#ifndef	NEQN
		printf("\\x'0-%gp'", before);
#else	/* NEQN */
		printf("\\x'0-%du'", before);
#endif	/* NEQN */
	printf("\\f%c\\s%s\\*(%d%s\n",
		gfont, tsize(gsize), p1, ital(rfont[p1]) ? "\\|" : "");
	printf(".ie \\n(.X=0 .as %d \\s\\n(99\n", p1);
	printf(".el .as %d \\s[\\n(99]\n", p1);
	printf(".as %d \\f\\n(98", p1);
#ifndef NEQN
	after = ebase[p1] - VERT(EM(0.2, ps));
#else /* NEQN */
	after = ebase[p1] - VERT(1);
#endif /* NEQN */
	if (spaceval == NULL && after > 0)
#ifndef	NEQN
		printf("\\x'%gp'", after);
#else	/* NEQN */
		printf("\\x'%du'", after);
#endif	/* NEQN */
	putchar('\n');
	eqnreg = p1;
	if (spaceval != NULL) {
		free(spaceval);
		spaceval = NULL;
	}

}
예제 #5
0
static void mgaFastRenderClippedPoly( GLcontext *ctx, const GLuint *elts, 
				       GLuint n )
{
   mgaContextPtr mmesa = MGA_CONTEXT( ctx );
   GLuint vertex_size = mmesa->vertex_size;
   GLuint *vb = mgaAllocDmaLow( mmesa, (n-2) * 3 * 4 * vertex_size );
   GLubyte *vertptr = (GLubyte *)mmesa->verts;			
   const GLuint *start = (const GLuint *)VERT(elts[0]);
   int i,j;

   for (i = 2 ; i < n ; i++) {
      EMIT_VERT( j, vb, vertex_size, (mgaVertexPtr) VERT(elts[i-1]) );
      EMIT_VERT( j, vb, vertex_size, (mgaVertexPtr) VERT(elts[i]) );
      EMIT_VERT( j, vb, vertex_size, (mgaVertexPtr) start );
   }
}
예제 #6
0
void
text(int t, char *p1)
{
	int c;
	char *p;
	tbl *tp, *lookup();
	extern tbl *restbl[];

	yyval = oalloc();
	ebase[yyval] = 0;
#ifndef NEQN
	eht[yyval] = VERT(EM(1.0, EFFPS(ps)));	/* ht in machine units */
#else	/* NEQN */
	eht[yyval] = VERT(2);	/* 2 half-spaces */
#endif	/* NEQN */
	lfont[yyval] = rfont[yyval] = ROM;
	if (t == QTEXT)
		p = p1;
	else if (t == SPACE)
		p = "\\ ";
	else if (t == THIN)
		p = "\\|";
	else if (t == TAB)
		p = "\\t";
	else if ((tp = lookup(restbl, p1, NULL)) != NULL)
		p = tp->defn;
	else {
		lf = rf = 0;
		for (csp = psp = 0; (c = p1[psp++]) != '\0'; ) {
			rf = trans(c, p1);
			if (lf == 0)
				lf = rf;	/* save first */
			if (csp > CSSIZE)
				error(FATAL, gettext(
				    "converted token %.25s... too long"), p1);
		}
		cs[csp] = '\0';
		p = cs;
		lfont[yyval] = lf;
		rfont[yyval] = rf;
	}
	if (dbg)
		printf(".\t%dtext: S%d <- %s; b=%d,h=%d,lf=%c,rf=%c\n",
		    t, yyval, p, ebase[yyval], eht[yyval], lfont[yyval],
		    rfont[yyval]);
	printf(".ds %d \"%s\n", yyval, p);
}
예제 #7
0
void
setintegral(void) {
	const char *f;

	yyval.token = oalloc();
	f = "\\(is";
#ifndef NEQN
	printf(".ds %d \\s%s\\v'.1m'\\s+4%s\\s-4\\v'-.1m'\\s%s\n", 
		yyval.token, tsize(ps), f, tsize(ps));
	eht[yyval.token] = VERT(EM(1.15, ps+4));
	ebase[yyval.token] = VERT(EM(0.3, ps));
#else /* NEQN */
	printf(".ds %d %s\n", yyval.token, f);
	eht[yyval.token] = VERT(2);
	ebase[yyval.token] = 0;
#endif /* NEQN */
	lfont[yyval.token] = rfont[yyval.token] = ROM;
}
예제 #8
0
int moveRight(uint64_t *block) {
	uint64_t v = *block;
	for (int i = 0; i < 8; i++) {
		if (v & (1LLU<<VERT(i, 7)))
			return 0;
	}
	*block <<= 1;
	return 1;
}
예제 #9
0
int moveDown(uint64_t *block) {
	uint64_t v = *block;
	for (int i = 0; i < 8; i++) {
		if (v & (1LLU<<VERT(7, i)))
			return 0;
	}
	*block <<= 8;
	return 1;
}
예제 #10
0
int moveLeft(uint64_t *block) {
	uint64_t v = *block;
	for (int i = 0; i < 8; i++) {
		if (v & (1LLU<<VERT(i, 0)))
			return 0;
	}
	*block >>= 1;
	return 1;
}
예제 #11
0
int moveUp(uint64_t *block) {
	uint64_t v = *block;
	for (int i = 0; i < 8; i++) {
		if (v & (1LLU<<VERT(0, i)))
			return 0;
	}
    *block >>= 8;
    return 1;
}
예제 #12
0
파일: sis_tris.c 프로젝트: aosm/X11
static void sisFastRenderClippedPoly( GLcontext *ctx, const GLuint *elts,
				      GLuint n )
{
   sisContextPtr smesa = SIS_CONTEXT( ctx );
   GLuint vertsize = smesa->vertex_size;
   GLuint *vb = r128AllocDmaLow( rmesa, (n-2) * 3 * 4 * vertsize );
   GLubyte *sisverts = (GLubyte *)smesa->verts;
   const GLuint shift = smesa->vertex_stride_shift;
   const GLuint *start = (const GLuint *)VERT(elts[0]);
   int i,j;

   smesa->num_verts += (n-2) * 3;

   for (i = 2 ; i < n ; i++) {
      COPY_DWORDS( j, vb, vertsize, (sisVertexPtr) VERT(elts[i-1]) );
      COPY_DWORDS( j, vb, vertsize, (sisVertexPtr) VERT(elts[i]) );
      COPY_DWORDS( j, vb, vertsize, (sisVertexPtr) start );
   }
}
예제 #13
0
void AMBRE()
{
 for(unsigned long i=0;i<240;i++) 
 {
   _delay_us(60); 
   VERT();
   _delay_us(150);
   ROUGE();
 }
}
예제 #14
0
int v_setmodefixed(struct v_board_t *board)
{
    int iob=board->io_base;
    int tmp;

#ifdef SAVEVGA
    v_savetextmode(board);
#endif

    v1k_softreset(board);

    /* switching to native mode */
    v_out8(iob+MODEREG, NATIVE_MODE);

    /* flipping some bytes */
    v_out8(iob+MEMENDIAN, MEMENDIAN_HW);

    /* try programming 1024x768@70 in highcolor */
    tmp=v_in32(iob+DRAMCTL)&0xdfff;              /* reset bit 13 */
    v_out32(iob+DRAMCTL, tmp|DEFAULT_WREFRESH);

    /* program pixel clock */
    if (board->chip == V1000_DEVICE) {
        set_PLL(iob, combineNMP(21, 55, 0));
    } 
    else {
	tmp = (~0x1800) & v_in32(iob+DRAMCTL);
        v_out32(iob+DRAMCTL, tmp);
        v_out32(iob+PCLKPLL, v2kcombineNMP(2, 21, 2));
    }
    usleep(500);
  
    v_initdac(board, 16, 0);
  
    v_out32(iob+CRTCHORZ, HORZ(24, 136, 144, 1024));
    v_out32(iob+CRTCVERT, VERT(3, 6, 29, 768));

    board->mode.screenwidth=1024;
    board->mode.virtualwidth=1024;
    board->mode.bitsperpixel=16;
    board->mode.fifosize=128;

    board->init=1;
    v_setframebase(board, 0);

    v_out32(iob+CRTCCTL, CTL(0, 0, 0)
                         |V_PIXFMT_565 
                         |CRTCCTL_VIDEOFIFOSIZE128
                         |CRTCCTL_HSYNCENABLE
                         |CRTCCTL_VSYNCENABLE
                         |CRTCCTL_VIDEOENABLE);

  return 0;
}
예제 #15
0
static void TessellateSphere(std::vector<float>& vertexes, std::vector<u16>& indexes, int level)
{
	/* Start with a tetrahedron, then tessellate */
	float s = sqrtf(0.5f);
#define VERT(a,b,c) vertexes.push_back(a); vertexes.push_back(b); vertexes.push_back(c);
	VERT(-s,  0, -s);
	VERT( s,  0, -s);
	VERT( s,  0,  s);
	VERT(-s,  0,  s);
	VERT( 0, -1,  0);
	VERT( 0,  1,  0);
#define FACE(a,b,c) \
	TessellateSphereFace( \
		CVector3D(vertexes[a*3], vertexes[a*3+1], vertexes[a*3+2]), a, \
		CVector3D(vertexes[b*3], vertexes[b*3+1], vertexes[b*3+2]), b, \
		CVector3D(vertexes[c*3], vertexes[c*3+1], vertexes[c*3+2]), c, \
		vertexes, indexes, level);
	FACE(0,4,1);
	FACE(1,4,2);
	FACE(2,4,3);
	FACE(3,4,0);
	FACE(1,5,0);
	FACE(2,5,1);
	FACE(3,5,2);
	FACE(0,5,3);
#undef FACE
#undef VERT
}
예제 #16
0
파일: integral.c 프로젝트: n-t-roff/DWB3.3
int
setintegral(void) {
	char *f;
	int yyval;

	yyval = oalloc();
	f = "\\(is";
	printf(".ds %d %s\n", yyval, f);
	eht[yyval] = VERT(2);
	ebase[yyval] = 0;
	lfont[yyval] = rfont[yyval] = ROM;
	return yyval;
}
예제 #17
0
파일: text.c 프로젝트: n-t-roff/DWB3.3
int
text(int t, char *p1) {
	int c;
	char *p;
	tbl *tp;
	extern tbl *restbl;
	int yyval;

	yyval = oalloc();
	ebase[yyval] = 0;
	eht[yyval] = VERT(2);	/* 2 half-spaces */
	lfont[yyval] = rfont[yyval] = ROM;
	if (t == QTEXT)
		p = p1;
	else if ( t == SPACE )
		p = "\\ ";
	else if ( t == THIN )
		p = "\\|";
	else if ( t == TAB )
		p = "\\t";
	else if ((tp = lookup(&restbl, p1, NULL)) != NULL)
		p = tp->defn;
	else {
		lf = rf = 0;
		for (csp=psp=0; (c=p1[psp++])!='\0';) {
			rf = trans(c, p1);
			if (lf == 0)
				lf = rf;	/* save first */
			if (csp >= CSSIZE)
				error(FATAL,"converted token %.25s... too long",p1);
		}
		cs[csp] = '\0';
		p = cs;
		lfont[yyval] = lf;
		rfont[yyval] = rf;
	}
	if (dbg)
		printf(".\t%dtext: S%d <- %s; b=%d,h=%d,lf=%c,rf=%c\n",
		    t, yyval, p, ebase[yyval], eht[yyval],
		    lfont[yyval], rfont[yyval]);
	printf(".ds %d \"%s\n", yyval, p);
	return yyval;
}
예제 #18
0
void Heightfield::Refine(vector<Reference<Shape> > &refined) const {
    int ntris = 2*(nx-1)*(ny-1);
    refined.reserve(ntris);
    int *verts = new int[3*ntris];
    Point *P = new Point[nx*ny];
    float *uvs = new float[2*nx*ny];
    int nverts = nx*ny;

    int x, y;
    // Compute heightfield vertex positions
    int pos = 0;
    for (y = 0; y < ny; ++y) {
        for (x = 0; x < nx; ++x) {
            P[pos].x = uvs[2*pos]   = (float)x / (float)(nx-1);
            P[pos].y = uvs[2*pos+1] = (float)y / (float)(ny-1);
            P[pos].z = z[pos];
            ++pos;
        }
    }

    // Fill in heightfield vertex offset array
    int *vp = verts;
    for (y = 0; y < ny-1; ++y) {
        for (x = 0; x < nx-1; ++x) {
#define VERT(x,y) ((x)+(y)*nx)
            *vp++ = VERT(x, y);
            *vp++ = VERT(x+1, y);
            *vp++ = VERT(x+1, y+1);
    
            *vp++ = VERT(x, y);
            *vp++ = VERT(x+1, y+1);
            *vp++ = VERT(x, y+1);
        }
#undef VERT
    }
    ParamSet paramSet;
    paramSet.AddInt("indices", verts, 3*ntris);
    paramSet.AddFloat("uv", uvs, 2 * nverts);
    paramSet.AddPoint("P", P, nverts);
    refined.push_back(CreateTriangleMeshShape(ObjectToWorld, WorldToObject, ReverseOrientation, paramSet));
    delete[] P;
    delete[] uvs;
    delete[] verts;
}
예제 #19
0
void ceDeviceGL20::DrawRect(const ceRect &rect)
{
  glDisable(GL_CULL_FACE);
  ApplyShaderStates();

#define VERT(u, v) glTexCoord2f(u, v); glVertex3f(rect.x + u*rect.w, rect.y + v*rect.h, -1)
  glActiveTexture(GL_TEXTURE0);
  glBegin(GL_TRIANGLES);
    VERT(0, 0);
    VERT(0, 1);
    VERT(1, 1);

    VERT(0, 0);
    VERT(1, 1);
    VERT(1, 0);
  glEnd();
#undef VERT
  glEnable(GL_CULL_FACE);
}
예제 #20
0
void
shift2(int p1, int p2, int p3)
{
	int effps, h1, h2, h3, b1, b2, b3, subsh, d1, d2, supsh, treg;
#ifndef NEQN
	int effps2;
#endif	/* NEQN */

	treg = oalloc();
	yyval = p1;
	if (dbg) printf(".\tshift2 s%d <- %d %d %d\n", yyval, p1, p2, p3);
	effps = EFFPS(ps+deltaps);
#ifndef NEQN
	eht[p3] = h3 = VERT((eht[p3] * effps) / EFFPS(ps));
	ps += deltaps;
	effps2 = EFFPS(ps+deltaps);
#endif	/* NEQN */
	h1 = eht[p1]; b1 = ebase[p1];
	h2 = eht[p2]; b2 = ebase[p2];
#ifndef NEQN
	b3 = ebase[p3];
	d1 = VERT(EM(0.5, effps2));
#else	/* NEQN */
	h3 = eht[p3]; b3 = ebase[p3];
	d1 = VERT(1);
#endif	/* NEQN */
	subsh = -d1+h2-b2;
	if (d1+b1 > h2) /* move little sub down */
		subsh = b1-b2;
#ifndef NEQN
	supsh = -VERT((4*(h1-b1))/10) - b3;
	d2 = VERT(EM(0.2, effps));
	if (VERT(4*(h1-b1)/10)+h3 < h1-b1)
#else	/* NEQN */
	supsh = - VERT(1) - b3;
	d2 = VERT(1);
	if (VERT(1)+h3 < h1-b1)
#endif	/* NEQN */
		supsh = -(h1-b1) + (h3-b3) - d2;
#ifndef NEQN
	eht[yyval] = h1 + max(0, h3-VERT((6*(h1-b1))/10)) + max(0, h2-b1-d1);
#else	/* NEQN */
	eht[yyval] = h1 + max(0, h3-VERT(1)) + max(0, h2-b1-d1);
#endif	/* NEQN */
	ebase[yyval] = b1+max(0, h2-b1-d1);
#ifndef NEQN
	if (rfont[p1] == ITAL && lfont[p2] == ROM)
		printf(".ds %d \\|\\*(%d\n", p2, p2);
	if (rfont[p2] == ITAL)
		printf(".as %d \\|\n", p2);
#endif	/* NEQN */
	nrwid(p2, effps, p2);
#ifndef NEQN
	if (rfont[p1] == ITAL && lfont[p3] == ROM)
		printf(".ds %d \\|\\|\\*(%d\n", p3, p3);
	else
		printf(".ds %d \\|\\*(%d\n", p3, p3);
#endif	/* NEQN */
	nrwid(p3, effps, p3);
	printf(".nr %d \\n(%d\n", treg, p3);
	printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n", p2, treg, treg, p2);
#ifndef NEQN
	printf(".as %d \\v'%du'\\s%d\\*(%d\\h'-\\n(%du'\\v'%du'\\\n",
	    p1, subsh, effps, p2, p2, -subsh+supsh);
	printf("\\s%d\\*(%d\\h'-\\n(%du+\\n(%du'\\s%d\\v'%du'\n",
	    effps, p3, p3, treg, effps2, -supsh);
#else	/* NEQN */
	printf(".as %d \\v'%du'\\*(%d\\h'-\\n(%du'\\v'%du'\\\n",
	    p1, subsh, p2, p2, -subsh+supsh);
	printf("\\*(%d\\h'-\\n(%du+\\n(%du'\\v'%du'\n",
	    p3, p3, treg, -supsh);
#endif	/* NEQN */
	ps += deltaps;
#ifndef NEQN
	if (rfont[p2] == ITAL)
		rfont[yyval] = 0;	/* lie */
#endif	/* NEQN */
	ofree(p2); ofree(p3); ofree(treg);
}
예제 #21
0
static void ExportSection(ExportContext& Context, const CBaseMeshLod& Lod, const CMeshVertex* Verts, int SectonIndex, FArchive& Ar)
{
	guard(ExportSection);

	int VertexSize = Context.IsSkeletal() ? sizeof(CSkelMeshVertex) : sizeof(CStaticMeshVertex);

	const CMeshSection& S = Lod.Sections[SectonIndex];
	bool bLast = (SectonIndex == Lod.Sections.Num()-1);

	// Remap section indices to local indices
	CIndexBuffer::IndexAccessor_t GetIndex = Lod.Indices.GetAccessor();
	TArray<int> indexRemap; // old vertex index -> new vertex index
	indexRemap.Init(-1, Lod.NumVerts);
	int numLocalVerts = 0;
	int numLocalIndices = S.NumFaces * 3;
	for (int idx = 0; idx < numLocalIndices; idx++)
	{
		int vertIndex = GetIndex(S.FirstIndex + idx);
		if (indexRemap[vertIndex] == -1)
		{
			indexRemap[vertIndex] = numLocalVerts++;
		}
	}

	// Prepare buffers
	int IndexBufIndex = Context.Data.AddZeroed();
	int PositionBufIndex = Context.Data.AddZeroed();
	int NormalBufIndex = Context.Data.AddZeroed();
	int TangentBufIndex = Context.Data.AddZeroed();

	int BonesBufIndex = -1;
	int WeightsBufIndex = -1;
	if (Context.IsSkeletal())
	{
		BonesBufIndex = Context.Data.AddZeroed();
		WeightsBufIndex = Context.Data.AddZeroed();
	}

	int UVBufIndex[MAX_MESH_UV_SETS];
	for (int i = 0; i < Lod.NumTexCoords; i++)
	{
		UVBufIndex[i] = Context.Data.AddZeroed();
	}

	BufferData& IndexBuf = Context.Data[IndexBufIndex];
	BufferData& PositionBuf = Context.Data[PositionBufIndex];
	BufferData& NormalBuf = Context.Data[NormalBufIndex];
	BufferData& TangentBuf = Context.Data[TangentBufIndex];
	BufferData* UVBuf[MAX_MESH_UV_SETS];
	BufferData* BonesBuf = NULL;
	BufferData* WeightsBuf = NULL;

	PositionBuf.Setup(numLocalVerts, "VEC3", BufferData::FLOAT, sizeof(CVec3));
	NormalBuf.Setup(numLocalVerts, "VEC3", BufferData::FLOAT, sizeof(CVec3));
	TangentBuf.Setup(numLocalVerts, "VEC4", BufferData::FLOAT, sizeof(CVec4));
	for (int i = 0; i < Lod.NumTexCoords; i++)
	{
		UVBuf[i] = &Context.Data[UVBufIndex[i]];
		UVBuf[i]->Setup(numLocalVerts, "VEC2", BufferData::FLOAT, sizeof(CMeshUVFloat));
	}

	if (Context.IsSkeletal())
	{
		BonesBuf = &Context.Data[BonesBufIndex];
		WeightsBuf = &Context.Data[WeightsBufIndex];
		BonesBuf->Setup(numLocalVerts, "VEC4", BufferData::UNSIGNED_SHORT, sizeof(uint16)*4);
		WeightsBuf->Setup(numLocalVerts, "VEC4", BufferData::UNSIGNED_BYTE, sizeof(uint32), /*InNormalized=*/ true);
	}

	// Prepare and build indices
	TArray<int> localIndices;
	localIndices.AddUninitialized(numLocalIndices);
	int* pIndex = localIndices.GetData();
	for (int i = 0; i < numLocalIndices; i++)
	{
		*pIndex++ = GetIndex(S.FirstIndex + i);
	}

	if (numLocalVerts <= 65536)
	{
		IndexBuf.Setup(numLocalIndices, "SCALAR", BufferData::UNSIGNED_SHORT, sizeof(uint16));
		for (int idx = 0; idx < numLocalIndices; idx++)
		{
			IndexBuf.Put<uint16>(indexRemap[localIndices[idx]]);
		}
	}
	else
	{
		IndexBuf.Setup(numLocalIndices, "SCALAR", BufferData::UNSIGNED_INT, sizeof(uint32));
		for (int idx = 0; idx < numLocalIndices; idx++)
		{
			IndexBuf.Put<uint32>(indexRemap[localIndices[idx]]);
		}
	}

	// Build reverse index map for fast lookup of vertex by its new index.
	// It maps new vertex index to old vertex index.
	TArray<int> revIndexMap;
	revIndexMap.AddUninitialized(numLocalVerts);
	for (int i = 0; i < indexRemap.Num(); i++)
	{
		int newIndex = indexRemap[i];
		if (newIndex != -1)
		{
			revIndexMap[newIndex] = i;
		}
	}

	// Build vertices
	for (int i = 0; i < numLocalVerts; i++)
	{
		int vertIndex = revIndexMap[i];
		const CMeshVertex& V = VERT(vertIndex);

		CVec3 Position = V.Position;

		CVec4 Normal, Tangent;
		Unpack(Normal, V.Normal);
		Unpack(Tangent, V.Tangent);
		// Unreal (and we are) using normal.w for computing binormal. glTF
		// uses tangent.w for that. Make this value exactly 1.0 of -1.0 to make glTF
		// validator happy.
	#if 0
		// There's some problem: V.Normal.W == 0x80 -> -1.008 instead of -1.0
		if (Normal.w > 1.001 || Normal.w < -1.001)
		{
			appError("%X -> %g\n", V.Normal.Data, Normal.w);
		}
	#endif
		Tangent.w = (Normal.w < 0) ? -1 : 1;

		TransformPosition(Position);
		TransformDirection(Normal);
		TransformDirection(Tangent);

		Normal.Normalize();
		Tangent.Normalize();

		// Fill buffers
		PositionBuf.Put(Position);
		NormalBuf.Put(Normal.xyz);
		TangentBuf.Put(Tangent);
		UVBuf[0]->Put(V.UV);
	}

	// Compute bounds for PositionBuf
	CVec3 Mins, Maxs;
	ComputeBounds((CVec3*)PositionBuf.Data, numLocalVerts, sizeof(CVec3), Mins, Maxs);
	char buf[256];
	appSprintf(ARRAY_ARG(buf), "[ %g, %g, %g ]", VECTOR_ARG(Mins));
	PositionBuf.BoundsMin = buf;
	appSprintf(ARRAY_ARG(buf), "[ %g, %g, %g ]", VECTOR_ARG(Maxs));
	PositionBuf.BoundsMax = buf;

	if (Context.IsSkeletal())
	{
		for (int i = 0; i < numLocalVerts; i++)
		{
			int vertIndex = revIndexMap[i];
			const CMeshVertex& V0 = VERT(vertIndex);
			const CSkelMeshVertex& V = static_cast<const CSkelMeshVertex&>(V0);

			int16 Bones[NUM_INFLUENCES];
			static_assert(NUM_INFLUENCES == 4, "Code designed for 4 influences");
			static_assert(sizeof(Bones) == sizeof(V.Bone), "Unexpected V.Bones size");
			memcpy(Bones, V.Bone, sizeof(Bones));
			for (int j = 0; j < NUM_INFLUENCES; j++)
			{
				// We have INDEX_NONE as list terminator, should replace with something else for glTF
				if (Bones[j] == INDEX_NONE)
				{
					Bones[j] = 0;
				}
			}

			BonesBuf->Put(*(uint64*)&Bones);
			WeightsBuf->Put(V.PackedWeights);
		}
	}

	// Secondary UVs
	for (int uvIndex = 1; uvIndex < Lod.NumTexCoords; uvIndex++)
	{
		BufferData* pBuf = UVBuf[uvIndex];
		const CMeshUVFloat* srcUV = Lod.ExtraUV[uvIndex-1];
		for (int i = 0; i < numLocalVerts; i++)
		{
			int vertIndex = revIndexMap[i];
			pBuf->Put(srcUV[vertIndex]);
		}
	}

	// Write primitive information to json
	Ar.Printf(
		"        {\n"
		"          \"attributes\" : {\n"
		"            \"POSITION\" : %d,\n"
		"            \"NORMAL\" : %d,\n"
		"            \"TANGENT\" : %d,\n",
		PositionBufIndex, NormalBufIndex, TangentBufIndex
	);
	if (Context.IsSkeletal())
	{
		Ar.Printf(
			"            \"JOINTS_0\" : %d,\n"
			"            \"WEIGHTS_0\" : %d,\n",
			BonesBufIndex, WeightsBufIndex
		);
	}
	for (int i = 0; i < Lod.NumTexCoords; i++)
	{
		Ar.Printf(
			"            \"TEXCOORD_%d\" : %d%s\n",
			i, UVBufIndex[i], i < (Lod.NumTexCoords-1) ? "," : ""
		);
	}

	Ar.Printf(
		"          },\n"
		"          \"indices\" : %d,\n"
		"          \"material\" : %d\n"
		"        }%s\n",
		IndexBufIndex, SectonIndex,
		SectonIndex < (Lod.Sections.Num()-1) ? "," : ""
	);

	unguard;
}
예제 #22
0
static mesh* build_gear(ID3D11Device* dev, int triangle_budget, float inner_radius, float outer_radius, float width, int teeth, float tooth_depth)
{
    int i, j, k;
    float r0, r1, r2;
    float da;
    float nx, ny, nz;
    int face;
    int segs = 4;
    int base_triangles = teeth * segs * 2 * 2;
    int divs0 = (triangle_budget / base_triangles) - 1;
    int divs = (divs0 > 0) ? divs0 : 1;
    float* c = (float*)malloc(teeth * segs * sizeof(float));
    float* s = (float*)malloc(teeth * segs * sizeof(float));
    float* dc = (float*)malloc(teeth * segs * divs * sizeof(float));
    float* ds = (float*)malloc(teeth * segs * divs * sizeof(float));
    int num_vertices = teeth * segs * 2 * (3 + 2 * divs);
    int num_triangles = base_triangles * (1 + divs);
    printf("Creating gear with %i teeth using %i vertices used in %i triangles\n", teeth, num_vertices, num_triangles);
    triangle_list_indices<> indices;
    std::vector<vertex> vertices;

    r0 = inner_radius;
    r1 = outer_radius - tooth_depth / 2.0f;
    r2 = outer_radius + tooth_depth / 2.0f;

    da = (float)(2.0 * M_PI / (teeth * segs * divs));
    for(i = 0; i < teeth * segs * divs; ++i) {
        float angle = da * i;
        ds[i] = sin(angle);
        dc[i] = cos(angle);
    }

    for(i = 0; i < teeth * segs; ++i) {
        s[i] = ds[i * divs];
        c[i] = dc[i * divs];
    }

    /* faces */
    for(face = -1; face <= 1; face += 2) {
        float z = width * face * 0.5f;
        nx = 0.0f;
        ny = 0.0f;
        nz = (float)face;

        indices.flip = face > 0;

        assert(segs == 4);
        for(i = 0; i < teeth; ++i) {
            VERT(r1 * c[segs * i], r1 * s[segs * i], z);
            VERT(r2 * c[segs * i + 1], r2 * s[segs * i + 1], z);
            VERT(r2 * c[segs * i + 2], r2 * s[segs * i + 2], z);
            VERT(r1 * c[segs * i + 3], r1 * s[segs * i + 3], z);
        }

        for(i = 0; i < teeth * segs * divs; ++i) {
            VERT(r0 * dc[i], r0 * ds[i], z);
        }

        for(i = 0; i < teeth; ++i) {
            for(j = i * segs; j < (i + 1) * segs; ++j) {
                int nextj = j + 1;
                if(nextj == teeth * segs)
                    nextj = 0;

                for(k = j * divs; k < (j + 1) * divs; ++k) {
                    int nextk = k + 1;
                    if(nextk == teeth * segs * divs)
                        nextk = 0;
                    indices.poly(teeth * segs + k, j, teeth * segs + nextk);
                }

                indices.poly(teeth * segs + nextj * divs, j, nextj);
            }
        }

        indices.base += teeth * segs * (1 + divs);
    }

    /* teeth faces */
    indices.flip = true;
    float z = width * 0.5f;

    float* coords = (float*)malloc((segs + 1) * 2 * sizeof(float));
    nz = 0;
    for(i = 0; i < teeth; i++) {
        int next = i + 1;
        if(next == teeth)
            next = 0;

        coords[0] = r1 * c[segs * i];
        coords[1] = r1 * s[segs * i];
        coords[2] = r2 * c[segs * i + 1];
        coords[3] = r2 * s[segs * i + 1];
        coords[4] = r2 * c[segs * i + 2];
        coords[5] = r2 * s[segs * i + 2];
        coords[6] = r1 * c[segs * i + 3];
        coords[7] = r1 * s[segs * i + 3];
        coords[8] = r1 * c[segs * next];
        coords[9] = r1 * s[segs * next];

        for(int j = 0; j < segs; ++j) {
            float dx = coords[j * 2] - coords[j * 2 + 2];
            float dy = coords[j * 2 + 1] - coords[j * 2 + 3];
            float len = hypotf(dx, dy);
            nx = -dy / len;
            ny = dx / len;
            VERT(coords[j * 2], coords[j * 2 + 1], z);
            VERT(coords[j * 2], coords[j * 2 + 1], -z);
            VERT(coords[j * 2 + 2], coords[j * 2 + 3], z);
            VERT(coords[j * 2 + 2], coords[j * 2 + 3], -z);

            indices.poly(0, 1, 3, 2);
            indices.base += 4;
        }
    }
    free(coords);

    /* inner part - simulate a cylinder */
    indices.flip = true;
    for(i = 0; i < teeth * segs * divs; i++) {
        int next = i + 1;
        if(next == teeth * segs * divs)
            next = 0;

        nx = -dc[i];
        ny = -ds[i];
        VERT(r0 * dc[i], r0 * ds[i], -width * 0.5f);
        VERT(r0 * dc[i], r0 * ds[i], width * 0.5f);

        indices.poly(i * 2, i * 2 + 1, next * 2 + 1, next * 2);
    }

    indices.base += teeth * segs * divs * 2;
    free(c);
    free(s);
    free(dc);
    free(ds);

    D3D11_INPUT_ELEMENT_DESC elements[2] =
    {
        {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
        {"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
    };

    return new mesh(dev, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST,
                    elements, 2,
                    g_vs, sizeof(g_vs),
                    &vertices[0], sizeof(vertices[0]), vertices.size(),
                    &indices[0], sizeof(indices[0]), indices.size());
}
예제 #23
0
void
bshiftb(int p1, int dir, int p2)
{
	int shval, d1, h1, b1, h2, b2;
#ifndef NEQN
	int diffps, effps, effps2;
	char *sh1, *sh2;
#endif	/* NEQN */

	yyval = p1;
	h1 = eht[p1];
	b1 = ebase[p1];
	h2 = eht[p2];
	b2 = ebase[p2];
#ifndef NEQN
	effps = EFFPS(ps);
	effps2 = EFFPS(ps+deltaps);
	diffps = deltaps;
	sh1 = sh2 = "";
#endif	/* NEQN */
	if (dir == SUB) {	/* subscript */
#ifndef NEQN
		/* top 1/2m above bottom of main box */
		d1 = VERT(EM(0.5, effps2));
#else	/* NEQN */
		d1 = VERT(1);
#endif	/* NEQN */
		shval = - d1 + h2 - b2;
		if (d1+b1 > h2) /* move little sub down */
			shval = b1-b2;
		ebase[yyval] = b1 + max(0, h2-b1-d1);
		eht[yyval] = h1 + max(0, h2-b1-d1);
#ifndef NEQN
		if (rfont[p1] == ITAL && lfont[p2] == ROM)
			sh1 = "\\|";
		if (rfont[p2] == ITAL)
			sh2 = "\\|";
#endif	/* NEQN */
	} else {	/* superscript */
#ifndef NEQN
		/* 4/10 up main box */
		d1 = VERT(EM(0.2, effps));
#else	/* NEQN */
		d1 = VERT(1);
#endif	/* NEQN */
		ebase[yyval] = b1;
#ifndef NEQN
		shval = -VERT((4 * (h1-b1)) / 10) - b2;
		if (VERT(4*(h1-b1)/10) + h2 < h1-b1)	/* raise little super */
#else	/* NEQN */
		shval = -VERT(1) - b2;
		if (VERT(1) + h2 < h1-b1)	/* raise little super */
#endif	/* NEQN */
			shval = -(h1-b1) + h2-b2 - d1;
#ifndef NEQN
		eht[yyval] = h1 + max(0, h2-VERT((6*(h1-b1))/10));
		if (rfont[p1] == ITAL)
			sh1 = "\\|";
		if (rfont[p2] == ITAL)
			sh2 = "\\|";
#else	/* NEQN */
		eht[yyval] = h1 + max(0, h2 - VERT(1));
#endif	/* NEQN */
	}
	if (dbg)
		printf(".\tb:b shift b: S%d <- S%d vert %d S%d vert %d; "
		    "b=%d, h=%d\n", yyval, p1, shval, p2, -shval,
		    ebase[yyval], eht[yyval]);
#ifndef NEQN
	printf(".as %d \\v'%du'\\s-%d%s\\*(%d\\s+%d%s\\v'%du'\n",
	    yyval, shval, diffps, sh1, p2, diffps, sh2, -shval);
	ps += deltaps;
	if (rfont[p2] == ITAL)
		rfont[p1] = 0;
	else
		rfont[p1] = rfont[p2];
#else	/* NEQN */
	printf(".as %d \\v'%du'\\*(%d\\v'%du'\n",
	    yyval, shval, p2, -shval);
#endif	/* NEQN */
	ofree(p2);
}
예제 #24
0
void
paren(int leftc, int p1, int rightc)
{
	int n, m, h1, j, b1, v;
	h1 = eht[p1]; b1 = ebase[p1];
	yyval = p1;
#ifndef NEQN
	lfont[yyval] = rfont[yyval] = 0;
	n = (h1 + EM(1.0, EFFPS(ps)) - 1) / EM(1.0, EFFPS(ps));
#else	/* NEQN */
	n = max(b1+VERT(1), h1-b1-VERT(1)) / VERT(1);
#endif	/* NEQN */
	if (n < 2) n = 1;
	m = n-2;
	if (leftc == '{' || rightc == '}') {
		if ((n % 2) == 0) {
			n++;
		}
		if (n < 3) n = 3;
		m = n-3;
	}
#ifndef NEQN
	eht[yyval] = VERT(EM(n, ps));
	ebase[yyval] = b1 + (eht[yyval]-h1)/2;
	v = b1 - h1/2 + VERT(EM(0.4, ps));
#else	/* NEQN */
	eht[yyval] = VERT(2 * n);
	ebase[yyval] = (n)/2 * VERT(2);
	if (n%2 == 0)
		ebase[yyval] -= VERT(1);
	v = b1 - h1/2 + VERT(1);
#endif	/* NEQN */
	printf(".ds %d \\|\\v'%du'", yyval, v);
	switch (leftc) {
		case 'n':	/* nothing */
		case '\0':
			break;
		case 'f':	/* floor */
			if (n <= 1)
				printf("\\(lf");
			else
				brack(m, "\\(bv", "\\(bv", "\\(lf");
			break;
		case 'c':	/* ceiling */
			if (n <= 1)
				printf("\\(lc");
			else
				brack(m, "\\(lc", "\\(bv", "\\(bv");
			break;
		case '{':
			printf("\\b'\\(lt");
			for (j = 0; j < m; j += 2) printf("\\(bv");
			printf("\\(lk");
			for (j = 0; j < m; j += 2) printf("\\(bv");
			printf("\\(lb'");
			break;
		case '(':
			brack(m, "\\(lt", "\\(bv", "\\(lb");
			break;
		case '[':
			brack(m, "\\(lc", "\\(bv", "\\(lf");
			break;
		case '|':
			brack(m, "\\(bv", "\\(bv", "\\(bv");
			break;
		default:
			brack(m, (char *)&leftc, (char *)&leftc,
			    (char *)&leftc);
			break;
		}
	printf("\\v'%du'\\*(%d", -v, p1);
	if (rightc) {
		printf("\\|\\v'%du'", v);
		switch (rightc) {
			case 'f':	/* floor */
				if (n <= 1)
					printf("\\(rf");
				else
					brack(m, "\\(bv", "\\(bv", "\\(rf");
				break;
			case 'c':	/* ceiling */
				if (n <= 1)
					printf("\\(rc");
				else
					brack(m, "\\(rc", "\\(bv", "\\(bv");
				break;
			case '}':
				printf("\\b'\\(rt");
				for (j = 0; j < m; j += 2) printf("\\(bv");
				printf("\\(rk");
				for (j = 0; j < m; j += 2) printf("\\(bv");
				printf("\\(rb'");
				break;
			case ']':
				brack(m, "\\(rc", "\\(bv", "\\(rf");
				break;
			case ')':
				brack(m, "\\(rt", "\\(bv", "\\(rb");
				break;
			case '|':
				brack(m, "\\(bv", "\\(bv", "\\(bv");
				break;
			default:
				brack(m, (char *)&rightc, (char *)&rightc,
				    (char *)&rightc);
				break;
		}
		printf("\\v'%du'", -v);
	}
	printf("\n");
	if (dbg)
		printf(".\tcurly: h=%d b=%d n=%d v=%d l=%c, r=%c\n",
		    eht[yyval], ebase[yyval], n, v, leftc, rightc);
}
예제 #25
0
파일: pile.c 프로젝트: andreiw/polaris
void
lpile(int type, int p1, int p2)
{
	int bi, hi, i, gap, h, b, nlist, nlist2, mid;
	yyval = oalloc();
#ifndef NEQN
	gap = VERT(EM(0.4, ps)); /* 4/10 m between blocks */
#else	/* NEQN */
	gap = VERT(1);
#endif	/* NEQN */
	if (type == '-') gap = 0;
	nlist = p2 - p1;
	nlist2 = (nlist+1)/2;
	mid = p1 + nlist2 -1;
	h = 0;
	for (i = p1; i < p2; i++)
		h += eht[lp[i]];
	eht[yyval] = h + (nlist-1)*gap;
	b = 0;
	for (i = p2-1; i > mid; i--)
		b += eht[lp[i]] + gap;
#ifndef NEQN
	ebase[yyval] = (nlist%2) ? b + ebase[lp[mid]]
	    : b - VERT(EM(0.5, ps)) - gap;
#else	/* NEQN */
	ebase[yyval] = (nlist%2) ? b + ebase[lp[mid]]
	    : b - VERT(1) - gap;
#endif	/* NEQN */
	if (dbg) {
		printf(".\tS%d <- %c pile of:", yyval, type);
		for (i = p1; i < p2; i++)
			printf(" S%d", lp[i]);
		printf(";h=%d b=%d\n", eht[yyval], ebase[yyval]);
	}
	nrwid(lp[p1], ps, lp[p1]);
	printf(".nr %d \\n(%d\n", yyval, lp[p1]);
	for (i = p1+1; i < p2; i++) {
		nrwid(lp[i], ps, lp[i]);
		printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n",
		    lp[i], yyval, yyval, lp[i]);
	}
	printf(".ds %d \\v'%du'\\h'%du*\\n(%du'\\\n", yyval, ebase[yyval],
	    type == 'R' ? 1 : 0, yyval);
	for (i = p2-1; i >= p1; i--) {
		hi = eht[lp[i]];
		bi = ebase[lp[i]];
	switch (type) {

	case 'L':
		printf("\\v'%du'\\*(%d\\h'-\\n(%du'\\v'0-%du'\\\n",
		    -bi, lp[i], lp[i], hi-bi+gap);
		continue;
	case 'R':
		printf("\\v'%du'\\h'-\\n(%du'\\*(%d\\v'0-%du'\\\n",
		    -bi, lp[i], lp[i], hi-bi+gap);
		continue;
	case 'C':
	case '-':
		printf("\\v'%du'\\h'\\n(%du-\\n(%du/2u'\\*(%d",
		    -bi, yyval, lp[i], lp[i]);
		printf("\\h'-\\n(%du-\\n(%du/2u'\\v'0-%du'\\\n",
		    yyval, lp[i], hi-bi+gap);
		continue;
		}
	}
	printf("\\v'%du'\\h'%du*\\n(%du'\n", eht[yyval]-ebase[yyval]+gap,
	    type != 'R' ? 1 : 0, yyval);
	for (i = p1; i < p2; i++)
		ofree(lp[i]);
	lfont[yyval] = rfont[yyval] = 0;
}
예제 #26
0
int v_setmode(struct v_board_t *board, struct v_modeinfo_t *mode)
{
    int tmp;
    int doubleclock=0;
    int M, N, P;
    int iob=board->io_base;
 
    /* switching to native mode */
    v_out8(iob+MODEREG, NATIVE_MODE|VESA_MODE);

    /* flipping some bytes */
    /* Must be something better to do than this -- FIX */
    switch (mode->bitsperpixel) {
    case 32:
      v_out8(iob+MEMENDIAN, MEMENDIAN_NO);
      break;
    case 16:
      v_out8(iob+MEMENDIAN, MEMENDIAN_HW);
      break;
    case 8:
      v_out8(iob+MEMENDIAN, MEMENDIAN_END);
      break;
    }

    if (OFLG_ISSET(OPTION_OVERCLOCK_MEM, &vga256InfoRec.options)) {
	/* increase Mem/Sys clock to avoid nasty artifacts */
	if (board->chip != V1000_DEVICE) {
	  v_out32(iob+SCLKPLL, 0xa484d);  /* mclk=110 sclk=55 */
					  /* M/N/P/P = 77/5/2/4 */
	  usleep(500);
	}
    }

    /* this has something to do with memory */
    tmp=v_in32(iob+DRAMCTL)&0xdfff;              /* reset bit 13 */
    v_out32(iob+DRAMCTL, tmp|0x330000);
 
    /* program pixel clock */
    if (board->chip == V1000_DEVICE) {
        if (110.0 < V1000CalcClock(mode->clock/1000.0, &M, &N, &P)) {
            P++;
            doubleclock=1;
        }
        set_PLL(iob, combineNMP(N, M, P));
    } 
    else {
	tmp = (~0x1800) & v_in32(iob+DRAMCTL);
        v_out32(iob+DRAMCTL, tmp);
        V2200CalcClock(mode->clock/1000.0, &M, &N, &P);
        v_out32(iob+PCLKPLL, v2kcombineNMP(N, M, P));
    }
    usleep(500);

    /* init the ramdac */
    v_initdac(board, mode->bitsperpixel, doubleclock);

    v_out32(iob+CRTCHORZ, HORZ(mode->hsyncstart-mode->hdisplay, 
                               mode->hsyncend-mode->hsyncstart,
                               mode->htotal-mode->hsyncend,
                               mode->hdisplay));
    v_out32(iob+CRTCVERT, VERT(mode->vsyncstart-mode->vdisplay, 
                               mode->vsyncend-mode->vsyncstart,
                               mode->vtotal-mode->vsyncend,
                               mode->vdisplay));

    /* fill in the mode parameters */
    memcpy(&(board->mode), mode, sizeof(struct v_modeinfo_t));
    board->mode.fifosize=128;
    board->mode.pll_m=M;
    board->mode.pll_n=N;
    board->mode.pll_p=P;
    board->mode.doubleclock=doubleclock;
    if (0 == board->mode.virtualwidth)
        board->mode.virtualwidth=board->mode.screenwidth;

    board->init=1;
    v_setframebase(board, 0);

    /* Need to fix up syncs */

    /* enable the display */
    v_out32(iob+CRTCCTL, CTL(0, mode->hsynchi, mode->vsynchi)
                        |mode->pixelformat
                        |CRTCCTL_VIDEOFIFOSIZE128
                        |CRTCCTL_HSYNCENABLE
                        |CRTCCTL_VSYNCENABLE
                        |CRTCCTL_VIDEOENABLE);
   return 0;
}
예제 #27
0
파일: SelectIdx.cpp 프로젝트: nixz/covise
coDistributedObject *SelectIdx::selectObj(coDistributedObject *inObj,
                                          const char *outName,
                                          int numElem, int numSelected,
                                          const char *selArr)
{

    int i;
    char buffer[128];

    /////////////////// SET ?
    {
        coDoSet *in_set = dynamic_cast<coDoSet *>(inObj);
        if (in_set)
        {
            int i, numSetElem;
            coDistributedObject *const *inObject = in_set->getAllElements(&numSetElem);
            coDistributedObject **outObject = new coDistributedObject *[numSetElem + 1];
            for (i = 0; i < numSetElem; i++)
            {
                sprintf(buffer, "%s_%d", outName, i);
                outObject[i] = selectObj(inObject[i], buffer, numElem, numSelected, selArr);
            }
            outObject[numSetElem] = NULL;
            coDoSet *resObj = new coDoSet(outName, outObject);
            resObj->copyAllAttributes(inObj);
            return resObj;
        }
    }

    /////////////////// USG Scalar Data ?
    {
        coDoFloat *usg_scalar = dynamic_cast<coDoFloat *>(inObj);

        if (usg_scalar)
        {
            int size = usg_scalar->getNumPoints();
            if (size != numElem)
            {
                sendError("Size mismatch");
                return NULL;
            }
            float *inData, *outData;
            usg_scalar->getAddress(&inData);
            coDoFloat *resObj = new coDoFloat(outName, numSelected);
            resObj->copyAllAttributes(inObj);
            resObj->getAddress(&outData);
            for (i = 0; i < numElem; i++)
            {
                if (selArr[i])
                {
                    *outData = inData[i];
                    outData++;
                }
            }
            return resObj;
        }
    }

    /////////////////// Struct Scalar Data ? (use scope to hide variables)
    {
        coDoFloat *str_scalar = dynamic_cast<coDoFloat *>(inObj);

        if (str_scalar)
        {
            int sx, sy, sz, size;
            str_scalar->getGridSize(&sx, &sy, &sz);
            size = sx * sy * sz;
            if (size != numElem)
            {
                sendError("Size mismatch");
                return NULL;
            }
            float *inData, *outData;
            str_scalar->getAddress(&inData);
            coDoFloat *resObj = new coDoFloat(outName, numSelected);
            resObj->copyAllAttributes(inObj);
            resObj->getAddress(&outData);
            for (i = 0; i < numElem; i++)
            {
                if (selArr[i])
                {
                    *outData = inData[i];
                    outData++;
                }
            }
            return resObj;
        }
    }

    /////////////////// Struct Vector Data ?
    {
        coDoVec3 *str_vector = dynamic_cast<coDoVec3 *>(inObj);

        if (str_vector)
        {
            int sx, sy, sz, size;
            str_vector->getGridSize(&sx, &sy, &sz);
            size = sx * sy * sz;
            if (size != numElem)
            {
                sendError("Size mismatch");
                return NULL;
            }
            float *inU, *inV, *inW, *outU, *outV, *outW;
            str_vector->getAddresses(&inU, &inV, &inW);
            coDoVec3 *resObj = new coDoVec3(outName, numSelected);
            resObj->copyAllAttributes(inObj);
            resObj->getAddresses(&outU, &outV, &outW);
            for (i = 0; i < numElem; i++)
            {
                if (selArr[i])
                {
                    *outU = inU[i];
                    outU++;
                    *outV = inV[i];
                    outV++;
                    *outW = inW[i];
                    outW++;
                }
            }
            return resObj;
        }
    }

    /////////////////// Rectilinear Grid : index PER CELL so far
    {
        coDoRectilinearGrid *rectGrd = dynamic_cast<coDoRectilinearGrid *>(inObj);

        if (rectGrd)
        {
            int sx, sy, sz, size;
            rectGrd->getGridSize(&sx, &sy, &sz);

            float *rx, *ry, *rz;
            rectGrd->getAddresses(&rx, &ry, &rz);

            size = (sx - 1) * (sy - 1) * (sz - 1); // idx per cell
            if (size != numElem)
            {
                sendError("Size mismatch");
                return NULL;
            }

            // vertex coordinate translation table
            int *vertTrans = new int[sx * sy * sz];
            for (i = 0; i < sx * sy * sz; i++)
                vertTrans[i] = -1;
            int numVert = 0;

            int ix, iy, iz;
            int cellNo = 0;

// #define VERT(i,j,k) ( (i) + (j)*sx + (k)*sx*sy )
#define VERT(k, j, i) ((i) + (j)*sx + (k)*sx * sy)

            for (iz = 0; iz < sz - 1; iz++)
                for (iy = 0; iy < sy - 1; iy++)
                    for (ix = 0; ix < sx - 1; ix++)
                    {
                        int vx, vy, vz;
                        if (selArr[cellNo])
                        {
                            for (vz = 0; vz < 2; vz++)
                                for (vy = 0; vy < 2; vy++)
                                    for (vx = 0; vx < 2; vx++)
                                    {
                                        int vertexID = VERT(ix + vx, iy + vy, iz + vz);
                                        if (vertTrans[vertexID] == -1)
                                        {
                                            vertTrans[vertexID] = numVert;
                                            numVert++;
                                        }
                                    }
                        }
                        cellNo++;
                    }

            coDoUnstructuredGrid *resObj = new coDoUnstructuredGrid(outName, numSelected, 8 * numSelected, numVert, 1);
            resObj->copyAllAttributes(inObj);

            int *elemList, *connList, *typeList;
            float *xc, *yc, *zc;
            resObj->getAddresses(&elemList, &connList, &xc, &yc, &zc);
            resObj->getTypeList(&typeList);

            cellNo = 0;
            int actCell = 0;

            for (iz = 0; iz < sz - 1; iz++)
                for (iy = 0; iy < sy - 1; iy++)
                    for (ix = 0; ix < sx - 1; ix++)
                    {
                        if (selArr[cellNo])
                        {
                            *elemList = actCell * 8;
                            elemList++;
                            *typeList = TYPE_HEXAEDER;
                            typeList++;
                            actCell++;

                            *connList = vertTrans[VERT(ix, iy, iz)];
                            connList++;
                            *connList = vertTrans[VERT(ix + 1, iy, iz)];
                            connList++;
                            *connList = vertTrans[VERT(ix + 1, iy + 1, iz)];
                            connList++;
                            *connList = vertTrans[VERT(ix, iy + 1, iz)];
                            connList++;

                            *connList = vertTrans[VERT(ix, iy, iz + 1)];
                            connList++;
                            *connList = vertTrans[VERT(ix + 1, iy, iz + 1)];
                            connList++;
                            *connList = vertTrans[VERT(ix + 1, iy + 1, iz + 1)];
                            connList++;
                            *connList = vertTrans[VERT(ix, iy + 1, iz + 1)];
                            connList++;
                        }
                        cellNo++;
                    }

            cellNo = 0;
            for (iz = 0; iz < sz; iz++)
                for (iy = 0; iy < sy; iy++)
                    for (ix = 0; ix < sx; ix++)
                    {
                        int vertexID = VERT(ix, iy, iz);
                        int trafo = vertTrans[vertexID];
                        if (trafo > -1)
                        {
                            xc[trafo] = rx[ix];
                            yc[trafo] = ry[iy];
                            zc[trafo] = rz[iz];
                        }
                        cellNo++;
                    }
            return resObj;
        }
    }
#undef VERT

    /////////////////// unknown so far
    sprintf(buffer, "Type `%s` not yet implemented", inObj->getType());
    sendError(buffer);

    return NULL;
}
예제 #28
0
/*
 * "Load" the current states of the VCS widgets from the
 * information in the given v5d struct.
 */
static void load_vertical_widgets( v5dstruct *v5d )
{
   int v, i, n;
   int maxnl;
   double size;

   switch (v5d->VerticalSystem) {
      case 0:  /* linear, equally spaced, generic */
         v = 0;
         n = 2;
         LUI_NewLabelChangeText( vertlabel[0], "Bottom Bound:" );
         LUI_NewLabelChangeText( vertlabel[1], "Level Increment:" );
         LUI_NewLabelChangeText( vertlabel[2], "" );
         LUI_NewLabelChangeText( vertlabel[3], "" );
         LUI_ScrollBarSet( vert_scrollbar, 100.0, 0.0 );
         break;
      case 1:  /* equal km */
         v = 1;
         n = 2;
         LUI_NewLabelChangeText( vertlabel[0], "Bottom Bound (km):" );
         LUI_NewLabelChangeText( vertlabel[1], "Level Increment (km):" );
         LUI_NewLabelChangeText( vertlabel[2], "" );        
         LUI_NewLabelChangeText( vertlabel[3], "" );
         LUI_ScrollBarSet( vert_scrollbar, 100.0, 0.0 );
         break;
      case 2:  /* unequal km */
         v = 2;
         n = 4;
         LUI_NewLabelChangeText( vertlabel[0], "Level 1 Height (km):" );
         LUI_NewLabelChangeText( vertlabel[1], "Level 2 Height (km):" );
         LUI_NewLabelChangeText( vertlabel[2], "Level 3 Height (km):" );
         LUI_NewLabelChangeText( vertlabel[3], "Level 4 Height (km):" );
         maxnl = LUI_FieldGetInt( levels_field );
         if (maxnl<=MAX_VERT_FIELDS) {
            size = 100.0;
         }
         else {
            size = 100 * MAX_VERT_FIELDS / maxnl;
         }
         LUI_ScrollBarSet( vert_scrollbar, size, 0.0 );
         break;
      case 3:  /* unequal mb */
         v = 3;
         n = 4;
         LUI_NewLabelChangeText( vertlabel[0], "Level 1 Pressure (mb):" );
         LUI_NewLabelChangeText( vertlabel[1], "Level 2 Pressure (mb):" );
         LUI_NewLabelChangeText( vertlabel[2], "Level 3 Pressure (mb):" );
         LUI_NewLabelChangeText( vertlabel[3], "Level 4 Pressure (mb):" );
         maxnl = LUI_FieldGetInt( levels_field );
         if (maxnl<=MAX_VERT_FIELDS) {
            size = 100.0;
         }
         else {
            size = 100 * MAX_VERT_FIELDS / maxnl;
         }
         LUI_ScrollBarSet( vert_scrollbar, size, 0.0 );
         break;
      default:
         /* VCS not initialized yet */
         v = 0;
         n = 0;
   }

   if (LUI_RadioGetCurrent(vert_radio) != v) {
      LUI_RadioSetCurrent( vert_radio, v );
   }
   for (i=0;i<n;i++) {
     LUI_FieldSetDouble( vertfield[i], VERT(v5d, v5d->VertArgs[i]) );
   }
   for (i=n;i<MAX_VERT_FIELDS;i++) {
      LUI_FieldSetText( vertfield[i], "" );
   }
}
예제 #29
0
	void RegenerateMesh()
	{	
		{
			DebugDrawDX dd(m_grpBB.get());

			duDebugDrawBoxWire(&dd,
				m_modelInfo->min.x, m_modelInfo->min.z, m_modelInfo->min.y,
				m_modelInfo->max.x, m_modelInfo->max.z, m_modelInfo->max.y,
				m_color, 1.0);
		}

#if RENDER_MODELS
		if (!m_targetted)
			return;

		DebugDrawDX dd(m_grpModel.get());

		// iterate over all the things!
		if (m_modelInfo->oldModel)
		{
			auto verts = m_modelInfo->oldModel->GetVertices();
			auto polys = m_modelInfo->oldModel->GetPolygons();

#define VERT(PX) { \
	glm::vec3 p0; const glm::vec3& p = verts[iter->verts[PX]].pos; \
	p0.x = p.y; \
	p0.y = p.z; \
	p0.z = p.x; \
	dd.vertex(&p0.x, 0xffffffff); \
}

			for (auto iter = polys.begin(); iter != polys.end(); ++iter)
			{
				//if (iter->flags & 0x11)
				//	continue;

				dd.begin(DU_DRAW_TRIS);

				VERT(0);
				VERT(1);
				VERT(2);

				dd.end();
			}
		}

		if (m_modelInfo->newModel)
		{
			auto verts = m_modelInfo->newModel->GetVertices();
			auto polys = m_modelInfo->newModel->GetPolygons();

			for (auto iter = polys.begin(); iter != polys.end(); ++iter)
			{
				//if (iter->flags & 0x11)
				//	continue;
				dd.begin(DU_DRAW_TRIS);

				VERT(0);
				VERT(1);
				VERT(2);

				dd.end();
			}
		}
#endif
	}
예제 #30
0
void initialize(uint64_t *block, int row, int col, int size) {
	*block = sq[size]<<(VERT(row, col));
}