public void registerNeighbor(warp_Triangle triangle) { if (!neighbor.Contains(triangle)) { neighbor.Add(triangle); } }
public void regenerateNormal() { float nx = 0; float ny = 0; float nz = 0; for (int i = 0; i < neighbor.Count; ++i) { warp_Triangle tri = neighbor[i]; warp_Vector wn = tri.rawNorm; nx += wn.x; ny += wn.y; nz += wn.z; } n = new warp_Vector(nx, ny, nz).normalize(); }
private warp_Triangle[] getTransparentQueue() { if (transparentQueue.Count == 0) { return(null); } IComparer comp = new tridistZDescCompare(); transparentQueue.Sort(comp); warp_Triangle[] tri = new warp_Triangle[transparentQueue.Count]; int id = 0; for (int i = 0; i < transparentQueue.Count; ++i) { tri[id++] = (warp_Triangle)transparentQueue[i]; } //return sortTriangles(tri, 0, tri.GetLength(0) - 1); return(tri); }
public void removeTriangle(warp_Triangle t) { triangleData.Remove(t); }
public void addTriangle(warp_Triangle newTriangle) { newTriangle.parent = this; triangleData.Add(newTriangle); dirty = true; }
private void drawWireframe(warp_Triangle tri, int defaultcolor) { drawLine(tri.p1, tri.p2, defaultcolor); drawLine(tri.p2, tri.p3, defaultcolor); drawLine(tri.p3, tri.p1, defaultcolor); }
public void render(warp_Triangle tri) { if (!ready || tri.parent == null) { return; } if ((mode & W) != 0) { drawWireframe(tri, color); if ((mode & ~W) == 0) { return; } } warp_Vertex p1 = tri.p1; warp_Vertex p2 = tri.p2; warp_Vertex p3 = tri.p3; warp_Vertex tempVertex; if (p1.y > p2.y) { tempVertex = p1; p1 = p2; p2 = tempVertex; } if (p2.y > p3.y) { tempVertex = p2; p2 = p3; p3 = tempVertex; } if (p1.y > p2.y) { tempVertex = p1; p1 = p2; p2 = tempVertex; } if (p1.y >= height) { return; } if (p3.y < 0) { return; } if (p1.y == p3.y) { return; } if (mode == F) { int lutID = (int)(tri.n2.x * 127 + 127) + ((int)(tri.n2.y * 127 + 127) << 8); int c = warp_Color.multiply(color, diffuse[lutID]); int s = warp_Color.scale(specular[lutID], reflectivity); currentColor = warp_Color.add(c, s); } int x1 = p1.x << 8; int x2 = p2.x << 8; int x3 = p3.x << 8; int y1 = p1.y; int y2 = p2.y; int y3 = p3.y; dy = y2 - y1; int dy31 = y3 - y1; float tf = (float)dy / dy31; int x4 = x1 + (int)((x3 - x1) * tf); dx = (x4 - x2) >> 8; if (dx == 0) { return; } x1 <<= 8; x2 <<= 8; x3 <<= 8; x4 <<= 8; //temp = (dy21 << 8) / dy31; int z1 = p1.z; int z3 = p3.z; //z4 = z1 + ((z3 - z1) >> 8) * temp; int z4 = z1 + (int)((z3 - z1) * tf); int z2 = p2.z; dz = (z4 - z2) / dx; int nx1 = p1.nx; int nx3 = p3.nx; //nx4 = nx1 + ((nx3 - nx1) >> 8) * temp; int nx4 = nx1 + (int)((nx3 - nx1) * tf); int nx2 = p2.nx; dnx = (nx4 - nx2) / dx; int ny1 = p1.ny; int ny3 = p3.ny; //ny4 = ny1 + ((ny3 - ny1) >> 8) * temp; int ny4 = ny1 + (int)((ny3 - ny1) * tf); int ny2 = p2.ny; dny = (ny4 - ny2) / dx; float tx1 = p1.tx * tw; float tx3 = p3.tx * tw; float tx4 = tx1 + ((tx3 - tx1) * tf); float tx2 = p2.tx * tw; dtx = (tx4 - tx2) / dx; float ty1 = p1.ty * th; float ty3 = p3.ty * th; float ty4 = ty1 + ((ty3 - ty1) * tf); float ty2 = p2.ty * th; dty = (ty4 - ty2) / dx; float sw1 = p1.invZ; float sw3 = p3.invZ; float sw4 = sw1 + ((sw3 - sw1) * tf); float sw2 = p2.invZ; dsw = (sw4 - sw2) / dx; if (dx < 0) { int temp = x2; x2 = x4; x4 = temp; z2 = z4; tx2 = tx4; ty2 = ty4; sw2 = sw4; nx2 = nx4; ny2 = ny4; } if (y2 >= 0 && dy > 0) { dxL = (x2 - x1) / dy; dxR = (x4 - x1) / dy; dzBase = (z2 - z1) / dy; dnxBase = (nx2 - nx1) / dy; dnyBase = (ny2 - ny1) / dy; dtxBase = (tx2 - tx1) / dy; dtyBase = (ty2 - ty1) / dy; dswBase = (sw2 - sw1) / dy; xBase = x1; xMax = x1; zBase = z1; nxBase = nx1; nyBase = ny1; txBase = tx1; tyBase = ty1; swBase = sw1; if (y1 < 0) { xBase -= y1 * dxL; xMax -= y1 * dxR; zBase -= y1 * dzBase; nxBase -= y1 * dnxBase; nyBase -= y1 * dnyBase; txBase -= y1 * dtxBase; tyBase -= y1 * dtyBase; swBase -= y1 * dswBase; y1 = 0; } if (y2 > height) { y2 = height; } offset = y1 * width; for (y = y1; y < y2; y++) { renderLine(); } } dy = y3 - y2; if (y2 < height && dy > 0) { dxL = (x3 - x2) / dy; dxR = (x3 - x4) / dy; dzBase = (z3 - z2) / dy; dnxBase = (nx3 - nx2) / dy; dnyBase = (ny3 - ny2) / dy; dtxBase = (tx3 - tx2) / dy; dtyBase = (ty3 - ty2) / dy; dswBase = (sw3 - sw2) / dy; xBase = x2; xMax = x4; zBase = z2; nxBase = nx2; nyBase = ny2; txBase = tx2; tyBase = ty2; swBase = sw2; if (y2 < 0) { xBase -= y2 * dxL; xMax -= y2 * dxR; zBase -= y2 * dzBase; nxBase -= y2 * dnxBase; nyBase -= y2 * dnyBase; txBase -= y2 * dtxBase; tyBase -= y2 * dtyBase; swBase -= y2 * dswBase; y2 = 0; } if (y3 > height) { y3 = height; } offset = y2 * width; for (y = y2; y < y3; y++) { renderLine(); } } }