/// <summary> /// Classifies the face if one of its vertices are classified as INSIDE or OUTSIDE /// </summary> /// <returns>true if the face could be classified, false otherwise</returns> public bool SimpleClassify() { FaceStatus status1 = v1.Status; FaceStatus status2 = v2.Status; FaceStatus status3 = v3.Status; if (status1 == FaceStatus.Inside || status1 == FaceStatus.Outside) { this.Status = status1; return(true); } else if (status2 == FaceStatus.Inside || status2 == FaceStatus.Outside) { this.Status = status2; return(true); } else if (status3 == FaceStatus.Inside || status3 == FaceStatus.Outside) { this.Status = status3; return(true); } else { return(false); } }
/// <summary> /// Composes a solid based on the faces status of the two operators solids /// </summary> /// <param name="faceStatus1">status expected for the first solid faces</param> /// <param name="faceStatus2">other status expected for the first solid faces /// (expected a status for the faces coincident with second solid faces)</param> /// <param name="faceStatus3">status expected for the second solid faces</param> /// <returns></returns> private Solid ComposeSolid(FaceStatus faceStatus1, FaceStatus faceStatus2, FaceStatus faceStatus3) { var vertices = new List <Vertex>(); var indices = new List <int>(); //group the elements of the two solids whose faces fit with the desired status reporter?.Invoke("Group Components 1", .9); GroupObjectComponents(object1, vertices, indices, faceStatus1, faceStatus2); reporter?.Invoke("Group Components 2", .9); GroupObjectComponents(object2, vertices, indices, faceStatus3, faceStatus3); //turn the arrayLists to arrays Vector3[] verticesArray = new Vector3[vertices.Count]; for (int i = 0; i < vertices.Count; i++) { verticesArray[i] = vertices[i].Position; } int[] indicesArray = new int[indices.Count]; for (int i = 0; i < indices.Count; i++) { indicesArray[i] = indices[i]; } //returns the solid containing the grouped elements reporter?.Invoke("Create Solid", .9); return(new Solid(verticesArray, indicesArray)); }
/// <summary> /// Constructs a vertex with unknown status /// </summary> /// <param name="position"></param> public Vertex(Vector3 position) { this.Position = position; adjacentVertices = new List <Vertex>(); Status = FaceStatus.Unknown; }
/// <summary> /// Constructs a vertex with a definite status /// </summary> /// <param name="x">coordinate on the x axis</param> /// <param name="y">coordinate on the y axis</param> /// <param name="z">coordinate on the z axis</param> /// <param name="status">vertex status - UNKNOWN, BOUNDARY, INSIDE or OUTSIDE</param> public Vertex(double x, double y, double z, FaceStatus status) { this.Position = new Vector3(x, y, z); adjacentVertices = new List <Vertex>(); this.Status = status; }
/// <summary> /// Constructs a face with unknown status. /// </summary> /// <param name="v1">a face vertex</param> /// <param name="v2">a face vertex</param> /// <param name="v3">a face vertex</param> public CsgFace(Vertex v1, Vertex v2, Vertex v3) { this.v1 = v1; this.v2 = v2; this.v3 = v3; center = (v1.Position + v2.Position + v3.Position) / 3.0; Status = FaceStatus.Unknown; }
/// <summary> /// Constructs a vertex with definite status /// </summary> /// <param name="position">vertex position</param> /// <param name="status">vertex status - UNKNOWN, BOUNDARY, INSIDE or OUTSIDE</param> public Vertex(Vector3 position, FaceStatus status) { Position.X = position.X; Position.Y = position.Y; Position.Z = position.Z; adjacentVertices = new List <Vertex>(); this.Status = status; }
/// <summary> /// Constructs a vertex with unknown status /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="z"></param> public Vertex(double x, double y, double z) { this.Position.X = x; this.Position.Y = y; this.Position.Z = z; adjacentVertices = new List <Vertex>(); Status = FaceStatus.Unknown; }
/// <summary> /// Method used to add a vertex properly for internal methods /// </summary> /// <param name="pos">vertex position</param> /// <param name="status">vertex status</param> /// <returns>The vertex inserted (if a similar vertex already exists, this is returned).</returns> private Vertex AddVertex(Vector3 pos, FaceStatus status) { Vertex vertex; // if the vertex is already there, it is not inserted if (!addedVertices.TryGetValue(pos.GetLongHashCode(), out int position)) { position = vertices.Count; addedVertices.Add(pos.GetLongHashCode(), position); vertex = new Vertex(pos, status); vertices.Add(vertex); } vertex = vertices[position]; vertex.Status = status; return(vertex); }
/// <summary> /// Sets the vertex status, setting equally the adjacent ones /// </summary> /// <param name="status"></param> public void Mark(FaceStatus status) { var items = new Stack <Vertex>(new Vertex[] { this }); while (items.Any()) { Vertex item = items.Pop(); //mark vertex item.Status = status; //mark adjacent vertices Vertex[] adjacentVerts = GetAdjacentVertices(); for (int i = 0; i < adjacentVerts.Length; i++) { if (adjacentVerts[i].Status == FaceStatus.Unknown) { items.Push(adjacentVertices[i]); } } } }
/// <summary> /// Fills solid arrays with data about faces of an object generated whose status is as required /// </summary> /// <param name="obj"></param> /// <param name="vertices"></param> /// <param name="indices"></param> /// <param name="faceStatus1"></param> /// <param name="faceStatus2"></param> private void GroupObjectComponents(CsgObject3D obj, List <Vertex> vertices, List <int> indices, FaceStatus faceStatus1, FaceStatus faceStatus2) { var vertexIndexByHashCode = new Dictionary <Vector3, int>(); //for each face.. foreach (CsgFace face in obj.Faces.All()) { //if the face status fits with the desired status... if (face.Status == faceStatus1 || face.Status == faceStatus2) { //adds the face elements into the arrays Vertex[] faceVerts = { face.v1, face.v2, face.v3 }; for (int j = 0; j < faceVerts.Length; j++) { if (vertexIndexByHashCode.ContainsKey(faceVerts[j].Position)) { indices.Add(vertexIndexByHashCode[faceVerts[j].Position]); } else { vertexIndexByHashCode.Add(faceVerts[j].Position, vertices.Count); indices.Add(vertices.Count); vertices.Add(faceVerts[j]); } } } } }
/// <summary> /// Constructs a new die. /// </summary> /// <param name="index">Index of the die (0-5) from left to right.</param> /// <param name="dieFace">TextureEntryFace for this die.</param> public Die(int index, Primitive.TextureEntryFace dieFace) { this.Index = index; this.Value = GetDieValueFromFace(dieFace); this.Status = GetDieStatus(dieFace); }
/// <summary> /// Constructs a new die /// </summary> /// <param name="index">Index of the die (0-5) from left to right.</param> /// <param name="value">Face value of the die (1-6).</param> /// <param name="status">State of the die.</param> public Die(int index, int value, FaceStatus status) { this.Index = index; this.Value = value; this.Status = status; }
public void Draw(Cube c, Face F, FaceStatus FS, int X, int Y) { int BaseY = 67; int BaseX = 53; int PicX = 0; int PicY = 0; int PicH = 67; int PicW = 53; this.Reset(); if ( F != Face.None ) { if ( F == Face.Health1 ) { PicY = 0; } else if ( F == Face.Health2 ) { PicY = BaseY; } else if ( F == Face.Health3 ) { PicY = BaseY * 2; } else if ( F == Face.Health4 ) { PicY = BaseY * 3; } else if ( F == Face.Health5 ) { PicY = BaseY * 4; } else if ( F == Face.GameOver ) { PicY = 331; PicX = 0; } else if ( F == Face.OhYes ) { PicY = 331; PicX = BaseX * 1; } else { throw new System.ArgumentException("Invalid Argument Face"); } if ( F != Face.GameOver && F != Face.OhYes ) { if ( FS == FaceStatus.Normal ) { if (this.FaceAnimState == -1 || this.CurrentFace != F ) { this.FaceAnimState = 0; this.FaceAnimCallback = this.FaceAnim; this.CurrentFace = F; DoomGuyState dgs = new DoomGuyState(); dgs.PicY = PicY; dgs.Cube = c; dgs.X = X; dgs.Y = Y; this.FaceAnimTimer = new Timer(this.FaceAnimCallback, dgs, 0, 500); } return; } else if ( FS == FaceStatus.Grin ) { PicX = 1; } else if ( FS == FaceStatus.Angry ) { PicX = 1 + BaseX; } else if ( FS == FaceStatus.Surprise ) { PicX = 1 + ( BaseX * 2); } else if ( FS == FaceStatus.Left ) { PicX = 313; PicW = 60; } else if ( FS == FaceStatus.Right ) { PicX = 373; PicW = 60; } else { throw new System.ArgumentException("invalid FaceStatus"); } } if ( ! Pause ) { DrawFace(c, X, Y, PicX, PicY, PicW, PicH); } } this.CurrentFace = F; }