Esempio n. 1
0
 public void BuildAxisAlignedRectangle(Vector3 a, Vector3 b, Vector3 normal)
 {
     Vector3 c = new Vector3();
     Vector3 d = new Vector3();
     if (a.X == b.X)
     {
         if (normal.X > 0)
         {
             c = new Vector3(a.X, a.Y, b.Z);
             d = new Vector3(a.X, b.Y, a.Z);
         }
         else
         {
             c = new Vector3(a.X, b.Y, a.Z);
             d = new Vector3(a.X, a.Y, b.Z);
         }
     }
     else if (a.Y == b.Y)
     {
         if (normal.Y > 0)
         {
             c = new Vector3(b.X, a.Y, a.Z);
             d = new Vector3(a.X, a.Y, b.Z);
         }
         else
         {
             c = new Vector3(a.X, a.Y, b.Z);
             d = new Vector3(b.X, a.Y, a.Z);
         }
     }
     else if (a.Z == b.Z)
     {
         if (normal.Z > 0)
         {
             c = new Vector3(a.X, b.Y, a.Z);
             d = new Vector3(b.X, a.Y, a.Z);
         }
         else
         {
             c = new Vector3(b.X, a.Y, a.Z);
             d = new Vector3(a.X, b.Y, a.Z);
         }
     }
     else
         return;
     Indices[index++] = (int)vertex;
     Indices[index++] = (int)(vertex + 1);
     Indices[index++] = (int)(vertex + 2);
     Indices[index++] = (int)(vertex + 2);
     Indices[index++] = (int)(vertex + 3);
     Indices[index++] = (int)vertex;
     Vertices[vertex++] = new PositionNormal(a, normal);
     Vertices[vertex++] = new PositionNormal(c, normal);
     Vertices[vertex++] = new PositionNormal(b, normal);
     Vertices[vertex++] = new PositionNormal(d, normal);
 }
Esempio n. 2
0
 public void BuildTriangle(Vector3 a, Vector3 b, Vector3 c, Vector3 normal, bool recalculateNormal = true)
 {
     if (recalculateNormal)
     {
         Vector3 n2 = Vector3.Cross(b - a, c - a);
         n2.Normalize();
         if (Vector3.Dot(normal, n2) < 0)
             n2 = -n2;
         normal = n2;
     }
     Indices[index++] = (int)vertex;
     Indices[index++] = (int)(vertex + 1);
     Indices[index++] = (int)(vertex + 2);
     Vertices[vertex++] = new PositionNormal(a, normal);
     Vertices[vertex++] = new PositionNormal(b, normal);
     Vertices[vertex++] = new PositionNormal(c, normal);
 }