Ejemplo n.º 1
0
void sphericalHarmonics::drawSHFunction(const SHFunction& func) const
{
	int n = 64;
	double du = PI / (n+1);
	double dv = 2 * PI/ (n+1);
	//float r; 
	XYZ col;
	glBegin(GL_QUADS);
	for (double v = 0; v < 2 * PI; v += dv)
	{
		for (double u = 0; u < PI; u += du)
		{
			XYZ p[4] =
			{
				func.getVector(u, v),
					func.getVector(u + du, v),
					func.getVector(u + du, v + dv),
					func.getVector(u, v + dv)
			};
			
			SHSample s00(u,v);
			SHSample s10(u+du,v);
			SHSample s01(u,v+dv);
			SHSample s11(u+du,v+dv);
#ifdef SH_DEBUG			
			s00.calcCoe();
			s10.calcCoe();
			s01.calcCoe();
			s11.calcCoe();
#endif
			//r = func.getFloat(s01);
			col = func.getColor(s01);
			
			glColor3f(col.x, col.y, col.z);
			glVertex3f(p[3].x, p[3].y, p[3].z);
			
			//r = func.getFloat(s11);
			col = func.getColor(s11);
			
			glColor3f(col.x, col.y, col.z);
			glVertex3f(p[2].x, p[2].y, p[2].z);
			
			//r = func.getFloat(s10);
			col = func.getColor(s10);
			
			glColor3f(col.x, col.y, col.z);
			glVertex3f(p[1].x, p[1].y, p[1].z);
			
			//r = func.getFloat(s00);
			col = func.getColor(s00);
			
			glColor3f(col.x, col.y, col.z);
			glVertex3f(p[0].x, p[0].y, p[0].z);
		}
	}
	glEnd();
}
Ejemplo n.º 2
0
void triangle(Vec3i t0, Vec3i t1, Vec3i t2, Vec2i uv0, Vec2i uv1, Vec2i uv2,
              float intensity, int* zbuf, TGAImage& image) {
    if (isDegenerated(t0,t1,t2)) return;
    if (t0.y > t1.y) {
        std::swap(t0, t1);
        std::swap(uv0, uv1);
    }
    if (t0.y > t2.y) {
        std::swap(t0, t2);
        std::swap(uv0, uv2);
    }
    if (t1.y > t2.y) {
        std::swap(t1, t2);
        std::swap(uv1, uv2);
    }
    int* boundbox = getBoundBox(t0, t1, t2);
    Vec2i vertex(t1.x - t0.x, t1.y - t0.y);
    Vec2i tmpUv(uv1.x - uv0.x, uv1.y - uv0.y);
    for (int x = boundbox[0]; x <= boundbox[2]; x++) {
        for (int y = boundbox[1]; y <= boundbox[3]; y++) {
            if (insideTriangle(x, y, t0, t1, t2)) {
                int idx = x + y * width;
                int z = find_z(x, y, t0, t1, t2);
                Vec2i P(x, y), v(t0.x, t0.y);
                Vec2i s01(t1.x - t0.x, t1.y - t0.y), s02(t2.x - t0.x, t2.y - t0.y), sp0(t0.x - P.x, t0.y - P.y);
                Vec3i tmp1(s01.x, s02.x, sp0.x), tmp2(s01.y, s02.y, sp0.y);
                Vec3i tmp3 = tmp1 ^ tmp2;
                Vec3f res(tmp3.x, tmp3.y, tmp3.z);
                if (res.z != 0) {
                    res = res * (1 / res.z);
                } else {
                    continue;
                }
                Vec2f uvP =  uv0 * (1 - res.x - res.y) + uv1 * res.x + uv2 * res.y;
                if (zbuf[idx] < z) {
                    zbuf[idx] =  z;
                    TGAColor color = model->getDiffusive(uvP);
                    image.set(x, y, TGAColor(color.r * intensity , color.g * intensity , color.b * intensity , 255));
                }
            }
        }
    }
    delete[] boundbox;
}
Ejemplo n.º 3
0
LOCAL_C void testSurrogateAwareInterfaces()
	{
	test.Next(_L("new TDesC interfaces"));
	TInt count;
	
	// string 1: all BMP characters
	_LIT(KBmpString1,			"abcdcf");
	TBuf16<128> s01(KBmpString1);
	test(s01.FindCorruptSurrogate() == KErrNotFound);
	test(s01.Locate2('f') == 5);
	test(s01.LocateReverse2('c') == 4);
	test(s01.Match(_L("*cdc*")) == 2);
	test(s01.Match2(_L("*bcdc*")) == 1);
	test(s01.Match2(_L("*c?c*")) == 2);
	
	// string 2: all non-BMP characters
	_LIT(KSurrogateString1,		"\xD840\xDDAA\xD840\xDDAB\xD840\xDDAC\xD840\xDDAD\xD840\xDDAE\xD840\xDDAF");
	TBuf16<128> s02(KSurrogateString1);
	for (count=0; count<=11; count++)
	test(s02.FindCorruptSurrogate() == KErrNotFound);
	test(s02.Locate2(0x201AE) == 8);
	test(s02.LocateReverse2(0x201AC) == 4);
	test(s02.Match2(_L("*\xD840\xDDAB\xD840\xDDAC*")) == 2);
	test(s02.Match2(_L("*\xD840\xDDBB*")) == KErrNotFound);
	test(s02.Match2(_L("*\xD840\xDDAD*")) == 6);

	// string 3: mixed
	_LIT(KMixedString1,			"ab\xD840\xDDAD e\xD801\xDC27");
	TBuf16<128> s03(KMixedString1);
	test(s03.FindCorruptSurrogate() == KErrNotFound);
	test(s03.Locate2(0x10427) == 6);
	test(s03.Locate2('e') == 5);
	test(s03.LocateF2(0x1044F) == 6);	// lower case=U+1044F(D801, DC4F), upper case=U+10427(D801, DC27), title case=U+10427
	TBuf16<128> s03a;
	s03a.CopyLC2(s03);
	s03a.Append2(0x21000);
	TBuf16<128> s03b;
	s03b.Copy(s03);
	
	s03b.AppendFill2(0x21000, 2);
	test(s03a != s03b);
	test(s03.Match2(_L("*b\xD840\xDDAD*")) == 1);
	test(s03.Match2(_L("* e*")) == 4);
	test(s03.Match2(_L("*\xD840\xDDAD?*")) == 2);
	
	// string 4: mixed, with corrupt surrogate
	_LIT(KCorruptString1,		"ab\xD840\xDDAD e\xDDAD\xD840");
	TBuf16<128> s04(KCorruptString1);
	test(s04.FindCorruptSurrogate() == 6);
	
	// string 5: fill
	_LIT(KOddString5,           "0123456");
	TBuf16<128> s05(KOddString5);
	s05.Fill2(0x21000);
    test(s05 == _L("\xD844\xDC00\xD844\xDC00\xD844\xDC00\xD844"));
    s05.Fill2(' ');
    test(s05 == _L("       "));
	s05.AppendFill2(0x22222, 2);
	s05.AppendFill2(0x22222, 3);
	test(s05 == _L("       \xD848\xDE22\xD848\xDE22\xD848"));
	
	// string 6: locate
	// from Unicode 5.0, CaseFolding.txt
	// 10400; C; 10428; # DESERET CAPITAL LETTER LONG I
	// 0x10400's fold is 0x10428
	TCharF f06(0x10400);
	test(f06 == 0x10428);  // just to ensure the property is correct
	// 0x10400: D801, DC00
	// 0x10428: D801, DC28
	_LIT(KMixedString6,         "ab\xD801\xDC00 e\xD801\xDC27");
	TBuf16<128> s06(KMixedString6);
	TInt pos6 = s06.LocateReverseF2(0x10428);
	test(pos6 == 2);
	}