public styles_gouraud(mesh_ctrl mesh, GammaLut gamma) { uint i; for (i = 0; i < mesh.num_triangles(); i++) { mesh_triangle t = mesh.triangle(i); mesh_point p1 = mesh.vertex(t.p1); mesh_point p2 = mesh.vertex(t.p2); mesh_point p3 = mesh.vertex(t.p3); RGBA_Bytes c1 = p1.color; RGBA_Bytes c2 = p2.color; RGBA_Bytes c3 = p3.color; c1.ApplyGammaDir(gamma); c2.ApplyGammaDir(gamma); c3.ApplyGammaDir(gamma); SpanGouraudRgba <T> gouraud = new SpanGouraudRgba <T>(c1, c2, c3, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y); gouraud.Prepare(); m_triangles.Add(gouraud); } }
public void generate(int cols, int rows, T cell_w, T cell_h, T start_x, T start_y) { m_cols = cols; m_rows = rows; m_cell_w = cell_w; m_cell_h = cell_h; m_start_x = start_x; m_start_y = start_y; m_vertices.RemoveAll(); for (int i = 0; i < m_rows; i++) { T x = start_x; for (int j = 0; j < m_cols; j++) { T dx = M.New <T>(random(-0.5, 0.5)); T dy = M.New <T>(random(-0.5, 0.5)); RGBA_Bytes c = new RGBA_Bytes(rand.Next() & 0xFF, rand.Next() & 0xFF, rand.Next() & 0xFF); RGBA_Bytes dc = new RGBA_Bytes(rand.Next() & 1, rand.Next() & 1, rand.Next() & 1); m_vertices.Add(new mesh_point(x, start_y, dx, dy, c, dc)); x.AddEquals(cell_w); } start_y.AddEquals(cell_h); } // 4---3 // |t2/| // | / | // |/t1| // 1---2 m_triangles.RemoveAll(); m_edges.RemoveAll(); for (int i = 0; i < m_rows - 1; i++) { for (int j = 0; j < m_cols - 1; j++) { int p1 = i * m_cols + j; int p2 = p1 + 1; int p3 = p2 + m_cols; int p4 = p1 + m_cols; m_triangles.Add(new mesh_triangle((uint)p1, (uint)p2, (uint)p3)); m_triangles.Add(new mesh_triangle((uint)p3, (uint)p4, (uint)p1)); int curr_cell = i * (m_cols - 1) + j; int left_cell = j != 0 ? (int)(curr_cell - 1) : -1; int bott_cell = i != 0 ? (int)(curr_cell - (m_cols - 1)) : -1; int curr_t1 = curr_cell * 2; int curr_t2 = curr_t1 + 1; int left_t1 = (left_cell >= 0) ? left_cell * 2 : -1; int left_t2 = (left_cell >= 0) ? left_t1 + 1 : -1; int bott_t1 = (bott_cell >= 0) ? bott_cell * 2 : -1; int bott_t2 = (bott_cell >= 0) ? bott_t1 + 1 : -1; m_edges.Add(new mesh_edge((uint)p1, (uint)p2, curr_t1, bott_t2)); m_edges.Add(new mesh_edge((uint)p1, (uint)p3, curr_t2, curr_t1)); m_edges.Add(new mesh_edge((uint)p1, (uint)p4, left_t1, curr_t2)); if (j == m_cols - 2) // Last column { m_edges.Add(new mesh_edge((uint)p2, (uint)p3, curr_t1, -1)); } if (i == m_rows - 2) // Last row { m_edges.Add(new mesh_edge((uint)p3, (uint)p4, curr_t2, -1)); } } } }