public void AddTriangles(Triangle[] triangles)
 {
     // Add Tessellated triangles to the opened GeometrySink
     foreach (var triangle in triangles)
     {
         _geometrySink.BeginFigure(triangle.Point1, FigureBegin.Filled);
         _geometrySink.AddLine(triangle.Point2);
         _geometrySink.AddLine(triangle.Point3);
         _geometrySink.EndFigure(FigureEnd.Closed);
     }
 }
 public static Triangle MakeTri(Vector3 v0, Vector3 v1, Vector3 v2, Vector2 UV0, Vector2 UV1, Vector2 UV2, Vector3 norm)
 {
     Triangle res = new Triangle();
     res.v0 = v0;
     res.v1 = v1;
     res.v2 = v2;
     res.UV0 = UV0;
     res.UV1 = UV1;
     res.UV2 = UV2;
     res.norm = norm;
     return res;
 }
Example #3
0
 public void copy(Shape s)
 {
     Shape temp;
     if (s!=null)
     {
         temp = new Rect(0,0,1,1,Color.Black);
         //is s a rectangle...?
         if (temp.GetType() == s.GetType()) temp = new Rect((Rect)s);
         else
         {
             //is it an oval...?
             temp = new Oval(0,0,1,1,Color.Black);
             if (temp.GetType() == s.GetType()) temp = new Oval((Oval)s);
             else
             {
                 //is it a line...?
                 temp = new Segment(0,0,1,1,Color.Black,1);
                 if (temp.GetType() == s.GetType()) temp = new Segment((Segment)s);
                 else
                 {
                     //is it a triangle...?
                     Point p1 = new Point();
                     Point p2 = new Point();
                     Point p3 = new Point();
                     temp = new Triangle(p1,p2,p3,Color.Black);
                     if (temp.GetType() == s.GetType()) temp = new Triangle((Triangle)s);
                 }
             }
         }
         //put the brand new copy into myShapes right after(above in the picture) the original
         myShapes.Insert(myShapes.IndexOf(s)+1,temp);
     }
     //if s is null, do nothing
     return;
 }
 private void ModelEditor_MouseClick(object sender, MouseEventArgs e)
 {
     if (Model != null)
     {
         Ray r = Camera.GetMouseRay(new Vector2(e.X, e.Y), game.GraphicsDevice.Viewport, game.camera);
         BoundingBox box = new BoundingBox(new Vector3(Model.CompressionBounds.X.Min, Model.CompressionBounds.Y.Min, Model.CompressionBounds.Z.Min),
             new Vector3(Model.CompressionBounds.X.Max, Model.CompressionBounds.Y.Max, Model.CompressionBounds.Z.Max));
         if (e.Button == MouseButtons.Left)
         {
             if (r.Intersects(box) != null)
             {
                 Nullable<float> last = null;
                 int index = -1;
                 for (int i = 0; i < game.IsRendered.Length; i++)
                 {
                     if (!game.IsRendered[i]) continue;
                     for (int g = 0; g < game.RenderModel.Sections[i].mesh.Groups.Length; g++)
                     {
                         if (r.Intersects(game.RenderModel.Sections[i].mesh.Groups[g].BoundingBox) != null)
                         {
                             for (int indice = game.RenderModel.Sections[i].mesh.Groups[g].IndiceStart;
                                 indice < game.RenderModel.Sections[i].mesh.Groups[g].IndiceStart + game.RenderModel.Sections[i].mesh.Groups[g].IndiceCount - 2;
                                 indice++)
                             {
                                 Triangle Temp = new Triangle(game.RenderModel.Sections[i].mesh.Vertices[game.RenderModel.Sections[i].mesh.Indices[indice + 0]].Position,
                                     game.RenderModel.Sections[i].mesh.Vertices[game.RenderModel.Sections[i].mesh.Indices[indice + 1]].Position,
                                     game.RenderModel.Sections[i].mesh.Vertices[game.RenderModel.Sections[i].mesh.Indices[indice + 2]].Position);
                                 Nullable<float> distance = Temp.Intersects(r);
                                 if (distance.HasValue && (distance < last || !last.HasValue))
                                 {
                                     index = i;
                                     last = distance; break;
                                 }
                             }
                         }
                     }
                 }
                 ChangeSelection(index);
             }
             else ChangeSelection(-1);
         }
     }
     else if (CollisionModel != null)
     {
         if (e.Button == MouseButtons.Left)
         {
             Ray r = Camera.GetMouseRay(new Vector2(e.X, e.Y), game.GraphicsDevice.Viewport, game.camera);
             game.DrawRay(r);
             Nullable<float> f = game.SelectedBSP.Trace(r);
             //game.Points.Clear();
             if (f != null)
             {
                 game.DrawPoint(r.Position + Vector3.Multiply(r.Direction, f.Value), Color.Orange);
             }
         }
     }
 }
Example #5
0
		private async void ConvertButtonOnClick(object sender, EventArgs e)
		{
			_convertButton.Enabled = false;
			if (_ofd != null)
			{
				SaveFileDialog sfd = new SaveFileDialog { Filter = "LDraw Data File|*.dat", FileName = "Part.dat" };
				if (sfd.ShowDialog() == DialogResult.OK)
				{
					await Task.Run(new Action(() =>
					{
						Invoke((MethodInvoker) delegate { _progressBar.Value = 0; });

						using (Stream output = sfd.OpenFile())
						using (BinaryReader br = new BinaryReader(_ofd.OpenFile()))
						{
							byte[] header = br.ReadBytes(80);
							uint n = br.ReadUInt32();

							Invoke((MethodInvoker) delegate { _progressBar.Maximum = (int) n; });

							HashSet<Tuple<Vector3, Vector3, Triangle>> edges = new HashSet<Tuple<Vector3, Vector3, Triangle>>();

							for (int i = 0; i < n; i++)
							{
								if (i % 500 == 0)
									Invoke((MethodInvoker) delegate { _progressBar.Value = i; }); 

								// normal
								Vector3 normal = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());

								// triangle
								Vector3 a = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()) * (double) _scaleBox.Value;
								Vector3 b = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()) * (double) _scaleBox.Value;
								Vector3 c = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()) * (double) _scaleBox.Value;

								// attrs
								br.ReadUInt16();
								Triangle t = new Triangle(a, b, c, normal);

								// assume colour 16
								string tri = string.Format("3 16 {0:F} {1:F} {2:F} {3:F} {4:F} {5:F} {6:F} {7:F} {8:F}\n",
									t.A.X, t.A.Y, t.A.Z,
									t.B.X, t.B.Y, t.B.Z,
									t.C.X, t.C.Y, t.C.Z);
								output.Write(Encoding.ASCII.GetBytes(tri), 0, tri.Length);

								var curedges = t.Edges;
								foreach (var edge in curedges)
								{
									// use oct-tree for efficiency... later
									Tuple<Vector3, Vector3, Triangle> match = null;
									foreach (var j in edges)
									{
										const double epsilon = 0.000001;
										if ((j.Item1 - edge.Item1).LenSq < epsilon && (j.Item2 - edge.Item2).LenSq < epsilon)
										{
											match = j;
											break;
										}
										else if ((j.Item1 - edge.Item2).LenSq < epsilon && (j.Item2 - edge.Item1).LenSq < epsilon)
										{
											match = j;
											break;
										}
									}

									if (match != null)
									{
										double dot = match.Item3.Normal.Dot(edge.Item3.Normal);

										if (dot < 0.9999)
										{
											if (dot > 0.20)
											{
												// draw optional line
												Vector3 c1 = edge.Item3.Centre, c2 = match.Item3.Centre;
												string line = string.Format("5 24 {0:F} {1:F} {2:F} {3:F} {4:F} {5:F} {6:F} {7:F} {8:F} {9:F} {10:F} {11:F}\n",
												edge.Item1.X, edge.Item1.Y, edge.Item1.Z,
												edge.Item2.X, edge.Item2.Y, edge.Item2.Z,
												c1.X, c1.Y, c1.Z,
												c2.X, c2.Y, c2.Z);
												output.Write(Encoding.ASCII.GetBytes(line), 0, line.Length);
											}
											else
											{
												// permanent line
												string line = string.Format("2 24 {0:F} {1:F} {2:F} {3:F} {4:F} {5:F}\n",
													edge.Item1.X, edge.Item1.Y, edge.Item1.Z,
													edge.Item2.X, edge.Item2.Y, edge.Item2.Z);
												output.Write(Encoding.ASCII.GetBytes(line), 0, line.Length);
											}
										}

										edges.Remove(match);
									}
								}

								foreach (var j in curedges)
								{
									edges.Add(j);
								}
							}

							// unpaired edges
							/*
							foreach (var j in edges)
							{
								string line = string.Format("2 24 {0:F} {1:F} {2:F} {3:F} {4:F} {5:F}\n",
									j.Item1.X, j.Item1.Y, j.Item1.Z,
									j.Item2.X, j.Item2.Y, j.Item2.Z);
								output.Write(Encoding.ASCII.GetBytes(line), 0, line.Length);
							}
							*/
						}
					}));
					_progressBar.Value = 0;
				}
			}
			_convertButton.Enabled = true;
		}
 private LinkedList<Triangle> TriangleTransform(List<ConstructRow> ListStreamOpen)
 {
     List<List<int>> strNumbers = CheckTriangleTransform(ListStreamOpen);
     int length = strNumbers.Count;
     for (int i = 0; i < length; i++)
     {
         if (strNumbers[i][0] != strNumbers[i][1])
         {
             Triangle triangle = new Triangle();
             triangle.Area = ListStreamOpen.ElementAt(strNumbers[i][0]).StrTypeCalculation.Equals("Area") ?
                 ListStreamOpen.ElementAt(strNumbers[i][0]).StrValue : null;
             triangle.Perimeter = ListStreamOpen.ElementAt(strNumbers[i][1]).StrTypeCalculation.Equals("Perimeter") ?
                 ListStreamOpen.ElementAt(strNumbers[i][1]).StrValue : null;
             if (!ListStreamOpen.ElementAt(strNumbers[i][0]).StrTypeCalculation.Equals("Area"))
                 triangle.Perimeter = ListStreamOpen.ElementAt(strNumbers[i][0]).StrTypeCalculation.Equals("Perimeter") ?
                     ListStreamOpen.ElementAt(strNumbers[i][0]).StrValue : null;
             if (!ListStreamOpen.ElementAt(strNumbers[i][1]).StrTypeCalculation.Equals("Perimeter"))
                 triangle.Perimeter = ListStreamOpen.ElementAt(strNumbers[i][1]).StrTypeCalculation.Equals("Area") ?
                     ListStreamOpen.ElementAt(strNumbers[i][1]).StrValue : null;
             Triangles.AddLast(triangle);
         }
         else
         {
             Triangle triangle = new Triangle();
             triangle.Area = ListStreamOpen.ElementAt(strNumbers[i][0]).StrTypeCalculation.Equals("Area") ?
                   ListStreamOpen.ElementAt(strNumbers[i][0]).StrValue : null;
             triangle.Perimeter = ListStreamOpen.ElementAt(strNumbers[i][0]).StrTypeCalculation.Equals("Perimeter") ?
                 ListStreamOpen.ElementAt(strNumbers[i][0]).StrValue : null;
             Triangles.AddLast(triangle);
         }
     }
     return Triangles;
 }
 private LinkedList<Triangle> TriangleTransform(string fileFolder)
 {
     StreamReader stream = new StreamReader(fileFolder);
     XmlReader xmlReader = new XmlTextReader(stream);
     while (xmlReader.Read())
     {
         if (xmlReader.Name == "Triangle")
         {
             Triangle triangle = new Triangle();
             xmlReader.Read();
             xmlReader.Read();
             xmlReader.Read();
             xmlReader.Read();
             if (xmlReader.Name == "Area")
             {
                 triangle.Area = double.Parse(xmlReader.ReadElementString());
             }
             if (xmlReader.Name == "Perimeter")
             {
                 triangle.Perimeter = double.Parse(xmlReader.ReadElementString());
             }
             Triangles.AddLast(triangle);
         }
     }
     xmlReader.Close();
     return Triangles;
 }
Example #8
0
        /// <summary>
        /// Draws the background
        /// </summary>
        private void DrawBackground()
        {
            Color color = Otter.Editor.Properties.Settings.Default.ViewBackgroundColor;

            if (Otter.Editor.Properties.Settings.Default.ViewBackgroundMode == Otter.Editor.BackgroundMode.Color)
            {
                Otter.Interface.Graphics.Instance.DrawRectangle(-1, 0, 0, mScene.Resolution.Width, mScene.Resolution.Height, color.ToArgb());
            }
            else
            {
                int viewWidth = mScene.Resolution.Width;
                int viewHeight = mScene.Resolution.Height;
                int texWidth = 512;
                int texHeight = 512;

                for (int x = 0; x < viewWidth; x += texWidth)
                {
                    for (int y = 0; y < viewHeight; y += texHeight)
                    {
                        int w = (viewWidth - x) > texWidth ? texWidth : (viewWidth - x);
                        int h = (viewHeight - y) > texHeight ? texHeight : (viewHeight - y);

                        float u = w / (float)texWidth;
                        float v = h / (float)texHeight;

                        Triangle[] triangles = new Triangle[2];
                        triangles[0] = new Triangle();
                        triangles[0].SetVertex(0, x, y, 0.0f, 0.0f, 0.0f, Color.White.ToArgb());
                        triangles[0].SetVertex(1, x + w, y, 0.0f, u, 0.0f, Color.White.ToArgb());
                        triangles[0].SetVertex(2, x + w, y + h, 0.0f, u, v, Color.White.ToArgb());

                        triangles[1] = new Triangle();
                        triangles[1].SetVertex(0, x + w, y + h, 0.0f, u, v, Color.White.ToArgb());
                        triangles[1].SetVertex(1, x, y + h, 0.0f, 0.0f, v, Color.White.ToArgb());
                        triangles[1].SetVertex(2, x, y, 0.0f, 0.0f, 0.0f, Color.White.ToArgb());

                        Otter.Interface.Graphics.Instance.DrawTriangles(mBackgroundTextureID, triangles);
                    }
                }
            }
        }
Example #9
0
        /// <summary>
        /// Draws a box highlighting the control
        /// </summary>
        /// <param name="control"></param>
        /// <param name="color"></param>
        private void DrawHighlightBox(GUIControl control, bool drawGrips, Color color, Color color2)
        {
            if (control == null)
                return;

            Matrix matrix = control.FullTransform;

            Otter.Interface.Graphics.Instance.PushMatrix(matrix.Entries);
            {
                float w = control.Size.Width;
                float h = control.Size.Height; 
                float gw = 8; // Grip Width

                if (drawGrips)
                {
                    //------------------------------------------
                    // Grips (filled)
                    //------------------------------------------

                    // Grips
                    Otter.Interface.Graphics.Instance.DrawRectangle(-1, -gw, -gw, gw, gw, color2.ToArgb()); // Top Left
                    Otter.Interface.Graphics.Instance.DrawRectangle(-1, (control.Size.Width / 2) - 4, -gw, gw, gw, color2.ToArgb()); // Top
                    Otter.Interface.Graphics.Instance.DrawRectangle(-1, control.Size.Width, -gw, gw, gw, color2.ToArgb()); // Top Right
                    Otter.Interface.Graphics.Instance.DrawRectangle(-1, -gw, (control.Size.Height / 2) - 4, gw, gw, color2.ToArgb()); // Left
                    Otter.Interface.Graphics.Instance.DrawRectangle(-1, control.Size.Width, (control.Size.Height / 2) - 4, gw, gw, color2.ToArgb()); // Right
                    Otter.Interface.Graphics.Instance.DrawRectangle(-1, -gw, control.Size.Height, gw, gw, color2.ToArgb()); // Bottom Left
                    Otter.Interface.Graphics.Instance.DrawRectangle(-1, (control.Size.Width / 2) - 4, control.Size.Height, gw, gw, color2.ToArgb()); // Bottom
                    Otter.Interface.Graphics.Instance.DrawRectangle(-1, control.Size.Width, control.Size.Height, gw, gw, color2.ToArgb()); // Bottom Right

                    //------------------------------------------
                    // Grips (outlines) and frame
                    //------------------------------------------

                    // Draw the frame
                    // Top Horizontal
                    Otter.Interface.Graphics.Instance.DrawLine(-gw, 0, 0, w + gw, 0, 0, color.ToArgb());

                    // Top Left Corner
                    Otter.Interface.Graphics.Instance.DrawLine(-gw, -gw, 0, 0, -gw, 0, color.ToArgb());
                    Otter.Interface.Graphics.Instance.DrawLine(-gw, -gw, 0, -gw, 0, 0, color.ToArgb());

                    // Top
                    Otter.Interface.Graphics.Instance.DrawLine((control.Size.Width / 2) - 4, -gw, 0, (control.Size.Width / 2) + 4, -gw, 0, color.ToArgb());
                    Otter.Interface.Graphics.Instance.DrawLine((control.Size.Width / 2) - 4, -gw, 0, (control.Size.Width / 2) - 4, 0, 0, color.ToArgb());
                    Otter.Interface.Graphics.Instance.DrawLine((control.Size.Width / 2) + 4, -gw, 0, (control.Size.Width / 2) + 4, 0, 0, color.ToArgb());

                    // Right Vertical
                    Otter.Interface.Graphics.Instance.DrawLine(w, -gw, 0, w, h + gw, 0, color.ToArgb());

                    // Top Right Corner
                    Otter.Interface.Graphics.Instance.DrawLine(w + gw, -gw, 0, w, -gw, 0, color.ToArgb());
                    Otter.Interface.Graphics.Instance.DrawLine(w + gw, -gw, 0, w + gw, 0, 0, color.ToArgb());

                    // Right
                    Otter.Interface.Graphics.Instance.DrawLine(w, (control.Size.Height / 2) - 4, 0, w + gw, (control.Size.Height / 2) - 4, 0, color.ToArgb());
                    Otter.Interface.Graphics.Instance.DrawLine(w, (control.Size.Height / 2) + 4, 0, w + gw, (control.Size.Height / 2) + 4, 0, color.ToArgb());
                    Otter.Interface.Graphics.Instance.DrawLine(w + gw, (control.Size.Height / 2) - 4, 0, w + gw, (control.Size.Height / 2) + 4, 0, color.ToArgb());

                    // Bottom Horizontal
                    Otter.Interface.Graphics.Instance.DrawLine(-gw, h, 0, w + gw, h, 0, color.ToArgb());

                    // Bottom Right Corner
                    Otter.Interface.Graphics.Instance.DrawLine(w + gw, h + gw, 0, w, h + gw, 0, color.ToArgb());
                    Otter.Interface.Graphics.Instance.DrawLine(w + gw, h + gw, 0, w + gw, h, 0, color.ToArgb());

                    // Bottom
                    Otter.Interface.Graphics.Instance.DrawLine((control.Size.Width / 2) - 4, h + gw, 0, (control.Size.Width / 2) + 4, h + gw, 0, color.ToArgb());
                    Otter.Interface.Graphics.Instance.DrawLine((control.Size.Width / 2) - 4, h, 0, (control.Size.Width / 2) - 4, h + gw, 0, color.ToArgb());
                    Otter.Interface.Graphics.Instance.DrawLine((control.Size.Width / 2) + 4, h, 0, (control.Size.Width / 2) + 4, h + gw, 0, color.ToArgb());

                    // Left Vertical
                    Otter.Interface.Graphics.Instance.DrawLine(0, -gw, 0, 0, h + gw, 0, color.ToArgb());

                    // Bottom Left Corner
                    Otter.Interface.Graphics.Instance.DrawLine(-gw, h + gw, 0, 0, h + gw, 0, color.ToArgb());
                    Otter.Interface.Graphics.Instance.DrawLine(-gw, h + gw, 0, -gw, h, 0, color.ToArgb());

                    // Left
                    Otter.Interface.Graphics.Instance.DrawLine(-gw, (control.Size.Height / 2) - 4, 0, 0, (control.Size.Height / 2) - 4, 0, color.ToArgb());
                    Otter.Interface.Graphics.Instance.DrawLine(-gw, (control.Size.Height / 2) + 4, 0, 0, (control.Size.Height / 2) + 4, 0, color.ToArgb());
                    Otter.Interface.Graphics.Instance.DrawLine(-gw, (control.Size.Height / 2) - 4, 0, -gw, (control.Size.Height / 2) + 4, 0, color.ToArgb());

                    //---------------------------------
                    // Center (filled)
                    //---------------------------------
                    float x = control.Center.X;
                    float y = control.Center.Y;

                    Triangle[] triangles = new Triangle[2];
                    triangles[0] = new Triangle();
                    triangles[0].SetVertex(0, x - 6, y, 0.0f, 0.0f, 0.0f, color2.ToArgb());
                    triangles[0].SetVertex(1, x, y - 6, 0.0f, 0.0f, 0.0f, color2.ToArgb());
                    triangles[0].SetVertex(2, x + 6, y, 0.0f, 0.0f, 0.0f, color2.ToArgb());

                    triangles[1] = new Triangle();
                    triangles[1].SetVertex(0, x - 6, y, 0.0f, 0.0f, 0.0f, color2.ToArgb());
                    triangles[1].SetVertex(1, x + 6, y, 0.0f, 0.0f, 0.0f, color2.ToArgb());
                    triangles[1].SetVertex(2, x, y + 6, 0.0f, 0.0f, 0.0f, color2.ToArgb());

                    Otter.Interface.Graphics.Instance.DrawTriangles(-1, triangles);

                    //---------------------------------
                    // Center (outlines)
                    //---------------------------------
                    Otter.Interface.Graphics.Instance.DrawLine(x - 6, y, 0, x, y - 6, 0, color.ToArgb());
                    Otter.Interface.Graphics.Instance.DrawLine(x, y - 6, 0, x + 6, y, 0, color.ToArgb());
                    Otter.Interface.Graphics.Instance.DrawLine(x + 6, y, 0, x, y + 6, 0, color.ToArgb());
                    Otter.Interface.Graphics.Instance.DrawLine(x, y + 6, 0, x - 6, y, 0, color.ToArgb());
                }
                else
                {
                    Otter.Interface.Graphics.Instance.DrawLine(0, 0, 0, w, 0, 0, color.ToArgb());
                    Otter.Interface.Graphics.Instance.DrawLine(0, h, 0, w, h, 0, color.ToArgb());
                    Otter.Interface.Graphics.Instance.DrawLine(0, 0, 0, 0, h, 0, color.ToArgb());
                    Otter.Interface.Graphics.Instance.DrawLine(w, 0, 0, w, h, 0, color.ToArgb());
                }
            }
            Otter.Interface.Graphics.Instance.PopMatrix();
        }
Example #10
0
        private void DrawNormalTriangle(Triangle Tri, Material Mat)
        {
            GL.Begin(BeginMode.Triangles);

            for (int j = 0; j < 3; j++)
            {
                if (Mat != null)
                {
                    if (TextureCoordinates.Count != 0 && Tri.TexCoordIndex[j] != -1)
                        GL.TexCoord3(
                            TextureCoordinates[Tri.TexCoordIndex[j]].U,
                            TextureCoordinates[Tri.TexCoordIndex[j]].V,
                            TextureCoordinates[Tri.TexCoordIndex[j]].W);
                }

                if (Normals.Count != 0 && Tri.NormalIndex[j] != -1)
                    GL.Normal3(Normals[Tri.NormalIndex[j]].X, Normals[Tri.NormalIndex[j]].Y, Normals[Tri.NormalIndex[j]].Z);

                /* Should never trip!! */
                if (Tri.VertIndex[j] != -1)
                    GL.Vertex3(Vertices[Tri.VertIndex[j]].X, Vertices[Tri.VertIndex[j]].Y, Vertices[Tri.VertIndex[j]].Z);
                else
                    throw new Exception("Invalid vertex index detected; should've been filtered out beforehand!");
            }

            GL.End();
        }
Example #11
0
        private void DrawTriangle(Triangle Tri, Material Mat)
        {
            if (Mat != null)
            {
                /* Normal, textured model rendering */
                if (_MaterialLighting == true)
                {
                    GL.Enable(EnableCap.ColorMaterial);
                    GL.ColorMaterial(MaterialFace.FrontAndBack, ColorMaterialParameter.AmbientAndDiffuse);
                    GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Ambient, Mat.Ka);
                    GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Diffuse, Mat.Kd);
                    GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Specular, Mat.Ks);
                }

                //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (float)TextureMinFilter.Nearest);
                //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (float)TextureMagFilter.Nearest);

                DrawNormalTriangle(Tri, Mat);
            }
            else
            {
                DrawHighlightedTriangle(Tri, new Color4(1.0f, 0.0f, 0.0f, 0.25f), true);
            }
        }
Example #12
0
        private void DrawHighlightedTriangle(Triangle Tri, Color4 Color, bool Outlined)
        {
            /* Setup */
            GL.Disable(EnableCap.Texture2D);
            GL.Enable(EnableCap.PolygonOffsetFill);
            GL.PolygonOffset(-1.0f, -1.0f);

            /* Polygons */
            GL.Color4(Color);
            DrawNormalTriangle(Tri, null);

            /* Outlines */
            if (Outlined == true)
            {
                GL.Color4(0.0f, 0.0f, 0.0f, 1.0f);
                GL.LineWidth(3.0f);
                GL.PolygonMode(MaterialFace.Front, PolygonMode.Line);
                DrawNormalTriangle(Tri, null);
            }

            /* Reset */
            GL.LineWidth(1.0f);
            GL.PolygonMode(MaterialFace.Front, PolygonMode.Fill);
            GL.PolygonOffset(0.0f, 0.0f);
        }
Example #13
0
 private static List<Vertex> AddedVertexs(Triangle t1, Triangle t2, out List<Vertex> Shared, out List<Vertex> UnShared)
 {
     Shared = new List<Vertex>();
     UnShared = new List<Vertex>();
     List<Vertex> lsit = new List<Vertex>();
     lsit.Add(t1.v1);
     lsit.Add(t1.v2);
     lsit.Add(t1.v3);
     Vertex v = t2.v1;
     if (lsit.Remove(v))
     {
         Shared.Add(v);
     }
     else
     {
         UnShared.Add(v);
     }
     v = t2.v2;
     if (lsit.Remove(v))
     {
         Shared.Add(v);
     }
     else
     {
         UnShared.Add(v);
     }
     v = t2.v3;
     if (lsit.Remove(v))
     {
         Shared.Add(v);
     }
     else
     {
         UnShared.Add(v);
     }
     return lsit;
 }
Example #14
0
 private static int SharedVertexs(Triangle t1, Triangle t2, Vertex[] shared,Vertex[] unshared)
 {
     int sharedV = 0;
     int unsharedV = 0;
     bool[] t2Shared = new bool[3];
     if (t1.v1 == t2.v1)
     {
         shared[sharedV] = t1.v1;
         t2Shared[0] = true;
         sharedV++;
     }
     else
         if (t1.v1 == t2.v2)
         {
             shared[sharedV] = t1.v1;
             t2Shared[1] = true;
             sharedV++;
         }
         else
             if (t1.v1 == t2.v3)
             {
                 shared[sharedV] = t1.v1;
                 t2Shared[2] = true;
                 sharedV++;
             }
             else
             {
                 unshared[unsharedV] = t1.v1;
                 unsharedV++;
             }
     if (t1.v2 == t2.v1)
     {
         shared[sharedV] = t1.v2;
         t2Shared[0] = true;
         sharedV++;
     }
     else
         if (t1.v2 == t2.v2)
         {
             shared[sharedV] = t1.v2;
             t2Shared[1] = true;
             sharedV++;
         }
         else
             if (t1.v2 == t2.v3)
             {
                 shared[sharedV] = t1.v2;
                 t2Shared[2] = true;
                 sharedV++;
             }
             else
             {
                 unshared[unsharedV] = t1.v2;
                 unsharedV++;
             }
     if (t1.v3 == t2.v1)
     {
         shared[sharedV] = t1.v3;
         t2Shared[0] = true;
         sharedV++;
     }
     else
         if (t1.v3 == t2.v2)
         {
             shared[sharedV] = t1.v3;
             t2Shared[1] = true;
             sharedV++;
         }
         else
             if (t1.v3 == t2.v3)
             {
                 shared[sharedV] = t1.v3;
                 t2Shared[2] = true;
                 sharedV++;
             }
             else
             {
                 unshared[unsharedV] = t1.v3;
                 unsharedV++;
             }
     if (sharedV==2 && unsharedV<2)
     {
         if (unshared[0] != t2.v1)
         {
             if (!t2Shared[0])
             {
                 unshared[1] = t2.v1;
                 return sharedV;
             }
         }
         if (unshared[0] != t2.v2)
         {
             if (!t2Shared[1])
             {
                 unshared[1] = t2.v2;
                 return sharedV;
             }
         }
         unshared[1] = t2.v3;
         
     }
     return sharedV;
 }
Example #15
0
 private static int SharedVertexs(Triangle t1, Triangle t2)
 {
     int sharedV = 0;
     if (t1.v1 == t2.v1) sharedV++;
     else
         if (t1.v1 == t2.v2) sharedV++;
         else
             if (t1.v1 == t2.v3) sharedV++;
     if (t1.v2 == t2.v1) sharedV++;
     else
         if (t1.v2 == t2.v2) sharedV++;
         else
             if (t1.v2 == t2.v3) sharedV++;
     if (t1.v3 == t2.v1 || t1.v3 == t2.v2 || t1.v3 == t2.v3) return sharedV + 1;
     return sharedV;
 }
Example #16
0
        public static Individ procreation(Individ Parent1, Individ Parent2, Random rand)
        {
            //initialize a cutoff point where all the genes of parent 1 will be transferred from before the point
            //and all the genes from parent 2 will be transferred to the kid from after the point
            int cutoff = rand.Next(0, Parent1.genes.Length);

            //Initialize kid
            Individ kid = new Individ(Parent1.source, Parent1.genes.Length, rand);
            Triangle[] kid_Genes = new Triangle[kid.genes.Length];

            for (int i = 0; i < kid.genes.Length; i++)
            {
                if (i < cutoff)
                {
                    kid_Genes[i] = Parent1.genes[i];
                }
                else kid_Genes[i] = Parent2.genes[i];
            }

            kid.Genes = kid_Genes;

            return kid;
        }