public override Shape create(string s) { Shape s1 = null; switch (s) { case "C": s1 = new Circle(); break; case "T": s1 = new CTriangle(); break; case "L": s1 = new Line(); break; case "R": s1 = new CRectangle(); break; case "G": s1 = new Group(); break; } return(s1); }
public override void init(string name, Vector2 position, string dataType, int compAddress, params string[] additional) { base.init(name, position, dataType, compAddress, additional); _width = Convert.ToInt32(additional[0]); _height = Convert.ToInt32(additional[1]); _hitBox = new CHitBox(this, 0, 0, _width, _height); //determine corner angles and magnitudes Vector2 center = _hitBox.center + position; _angleTopLeft = MathExt.MathExt.angle(center, position); _angleTopRight = MathExt.MathExt.angle(center, position + new Vector2(_width, 0)); _angleBottomRight = MathExt.MathExt.angle(center, position + new Vector2(_width, _height)); _angleBottomLeft = MathExt.MathExt.angle(center, position + new Vector2(0, _height)); _distToTopLeft = MathExt.MathExt.distance(center, position); _distToTopRight = MathExt.MathExt.distance(center, _position + new Vector2(_width, 0)); _distToBottomRight = MathExt.MathExt.distance(center, _position + new Vector2(_width, _height)); _distToBottomLeft = MathExt.MathExt.distance(center, _position + new Vector2(0, _height)); //calculate triangles _leftTri = MathExt.MathExt.buildTriangle(180.0, _angleBottomLeft - _angleTopLeft, (double)center.X - _width / 2.0, center); _rightTri = MathExt.MathExt.buildTriangle(0, (_angleTopRight + 360) - _angleBottomRight, (double)center.X + _width / 2.0, center); _topTri = MathExt.MathExt.buildTriangle(90.0, _angleTopLeft - _angleTopRight, (double)center.X - _height / 2.0, center); _bottomTri = MathExt.MathExt.buildTriangle(270.0, _angleBottomLeft - _angleBottomRight, (double)center.X + _height / 2.0, center); }
private static void concreetTriangle(int length) { CTriangle square = new CTriangle(length); Console.WriteLine("De omtrek is: {0}", square.GetPerimeter()); Console.WriteLine("De oppervlakte is {0}", square.GetArea()); }
public void AddFaceFromCTriangle(CTriangle ct) { int start_vrt = m_vertex.Count; for (int i = 0; i < 3; i++) { m_vertex.Add(ct.original_verts[i].Position); } bool use_clipped_data = false; DTriangle tri = new DTriangle(ct, start_vrt, 0, use_clipped_data); m_triangle.Add(tri); }
public DTriangle(CTriangle ct, int vert_idx_offset, int triangle_index, bool use_clipped_data) { CVertex[] vdata = use_clipped_data ? ct.clipped_verts : ct.original_verts; int[] vert_index = new int[] { 0, triangle_index + 1, triangle_index + 2 }; for (int i = 0; i < 3; ++i) { this.vert[i] = vert_idx_offset + vert_index[i]; this.normal[i] = vdata[vert_index[i]].Normal; this.tex_uv[i] = vdata[vert_index[i]].UV; } tex_index = ct.tex_index; flags = ct.flags; }
public GMesh ClipGeometryToPlane(GClipPlane gcp) { GMesh clip_gm = new GMesh(); // Add the textures first for (int i = 0; i < m_tex_name.Count; i++) { #if OVERLOAD_LEVEL_EDITOR clip_gm.AddTexture(m_tex_gl_id[i], m_tex_name[i]); #else clip_gm.m_tex_name.Add(m_tex_name[i]); #endif } // Copy the clip planes for (int i = 0; i < (int)EdgeOrder.NUM; i++) { clip_gm.m_clip_plane[i] = new GClipPlane(m_clip_plane[i]); } ClipPlane cp = ClipPlane.CreateFrom3Points(gcp.edge_pos1, gcp.edge_pos2, gcp.edge_pos2 + gcp.normal); for (int i = 0; i < m_triangle.Count; i++) { CTriangle ct = new CTriangle(m_triangle[i], m_vertex[m_triangle[i].vert[0]], m_vertex[m_triangle[i].vert[1]], m_vertex[m_triangle[i].vert[2]]); ct.ClipFacePlane(cp); if (ct.clipped_verts.Length < 3) { continue; } int num_triangles = ct.clipped_verts.Length - 2; for (int clipped_tri_idx = 0; clipped_tri_idx < num_triangles; ++clipped_tri_idx) { CTriangle extracted_ct = ct.ExtractClippedTriangle(clipped_tri_idx); if (extracted_ct.HasDegenerateTriangles(false)) { continue; } clip_gm.AddFaceFromCTriangle(extracted_ct); } } return(clip_gm); }
public void GenerateNonClippedGeometry(Decal d, DMesh dm) { // Limit max repeats based on the size of the face // NOTE: This may not the best way to limit repeats, but it works FindBaseAttributes(d); float max_length = d.side.FindLongestDiagonal(); int max_repeats = 2 + (int)(max_length / 4f); int repeat_u = (d.repeat_u > 0 ? d.repeat_u : max_repeats); int repeat_v = (d.repeat_v > 0 ? d.repeat_v : max_repeats); int offset_u = d.offset_u; switch (d.align) { case DecalAlign.EDGE_RIGHT: case DecalAlign.EDGE_DOWN: case DecalAlign.EDGE_UP: case DecalAlign.EDGE_LEFT: // COMPATIBILITY: Due to a bug Offset U was effectively reversed in the original 1.0.1.0 release // For backwards compatibility, retain this behaviour. offset_u = -offset_u; break; default: break; } // Get the implied offset based on the repeats int implied_offset_u = CalculateImpiedOffset(d.repeat_u, repeat_u); int implied_offset_v = CalculateImpiedOffset(d.repeat_v, repeat_v); // Adjust implied_offset_v for EDGE alignment (add 2) if (d.IsEdgeAlign()) { implied_offset_v += 2; } // Temporary DMesh to hold the dm if it has to be mirrored DMesh temp_dm = new DMesh(dm.name); temp_dm.Copy(dm); temp_dm.MaybeFlip(d.mirror); // Create repeats of the geometry for (int i = 0; i < repeat_u; i++) { for (int j = 0; j < repeat_v; j++) { // Before adding, must do WHOLE clipping (can't do it after because we don't have the data then) // Create a CQuad that covers the outline of the expected area Vector3[] v = CreateGhostQuad(m_base_pos + m_base_rvec * (implied_offset_u - offset_u + i * 4) + m_base_uvec * (implied_offset_v + d.offset_v + j * 4), m_base_rot); CTriangle ct = new CTriangle(v); bool clip = false; // See if that clips against a whole plane, if not add it for (int k = 0; k < (int)EdgeOrder.NUM; k++) { if (m_clip_plane[k].whole) { ClipPlane cp = ClipPlane.CreateFrom3Points(m_clip_plane[k].edge_pos1, m_clip_plane[k].edge_pos2, m_clip_plane[k].edge_pos2 + m_clip_plane[k].normal); if (ct.WouldBeClipped(cp)) { clip = true; } } } if (!clip) { Vector3 offset = m_base_rvec * (implied_offset_u - offset_u + i * 4) + m_base_uvec * (implied_offset_v + d.offset_v + j * 4); Vector3 gcenter = m_base_pos + offset; AddGeometry(temp_dm, gcenter); AddLights(temp_dm, gcenter); } } } // Add the textures for (int i = 0; i < dm.tex_name.Count; i++) { m_tex_name.Add(dm.tex_name[i]); #if OVERLOAD_LEVEL_EDITOR m_tex_gl_id.Add(-1); #endif } }