private void CircleMesh(Circle circle) { float Radius = circle.radius; int segments = Segments; Vector3 vertice = circle.Vertice; int vertices_count = Segments + 1; Vector3[] vertices = new Vector3[vertices_count]; vertices[0] = vertice; float angledegree = 360.0f; float angleRad = Mathf.Deg2Rad * angledegree; float angleCur = angleRad; float angledelta = angleRad / Segments; VertexSpace[] vertexs = new VertexSpace[vertices_count - 1]; for (int i = 1; i < vertices_count; i++) { float cosA = Mathf.Cos(angleCur); float sinA = Mathf.Sin(angleCur); if (circle.direction == CircleDirection.X) { vertices[i] = new Vector3(vertice.x, vertice.y + Radius * cosA, vertice.z + Radius * sinA); } else if (circle.direction == CircleDirection.Y) { vertices[i] = new Vector3(vertice.x + Radius * cosA, vertice.y, vertice.z + Radius * sinA); } else if (circle.direction == CircleDirection.Z) { vertices[i] = new Vector3(vertice.x + Radius * cosA, vertice.y + Radius * sinA, vertice.z); } vertexs[i - 1] = new VertexSpace(vertices[i]); angleCur -= angledelta; } VertexSpace v1; VertexSpace v2; GeoEdge edge; for (int i = 1; i < vertices_count - 1; i++) { v1 = new VertexSpace(vertices[i]); v2 = new VertexSpace(vertices[i + 1]); edge = new GeoEdge(v1, v2, false); geometryBehaviour.AddElement(edge); } v1 = new VertexSpace(vertices[1]); v2 = new VertexSpace(vertices[vertices_count - 1]); edge = new GeoEdge(v1, v2, false); geometryBehaviour.AddElement(edge); if (circle.displayFace) { GeoFace geoFace = new GeoFace(vertexs, false, circle.faceType); geometryBehaviour.AddElement(geoFace); } }
public override void Init() { base.Init(); Name = "Triangular Pyramid"; Type = GeometryType.TriPyd; float sqrt3 = Mathf.Sqrt(3); Vector3 faceNormal = Vector3.up; VertexFace u0 = new VertexFace(-1, 0, -sqrt3 / 3, faceNormal); VertexFace u1 = new VertexFace(1, 0, -sqrt3 / 3, faceNormal); VertexFace u2 = new VertexFace(0, 0, sqrt3 * 2 / 3, faceNormal); VertexSpace u3 = new VertexSpace(0, sqrt3, 0); AddBaseVertex(u0); AddBaseVertex(u1); AddBaseVertex(u2); AddBaseVertex(u3); GeoVertex v0 = new GeoVertex(u0, true); GeoVertex v1 = new GeoVertex(u1, true); GeoVertex v2 = new GeoVertex(u2, true); GeoVertex v3 = new GeoVertex(u3, true); AddGeoVertex(v0); AddGeoVertex(v1); AddGeoVertex(v2); AddGeoVertex(v3); GeoEdge e0 = new GeoEdge(u0, u1, true); GeoEdge e1 = new GeoEdge(u0, u2, true); GeoEdge e2 = new GeoEdge(u1, u2, true); GeoEdge e3 = new GeoEdge(u0, u3, true); GeoEdge e4 = new GeoEdge(u1, u3, true); GeoEdge e5 = new GeoEdge(u2, u3, true); AddGeoEdge(e0); AddGeoEdge(e1); AddGeoEdge(e2); AddGeoEdge(e3); AddGeoEdge(e4); AddGeoEdge(e5); GeoFace f0 = new GeoFace(new VertexUnit[] { u0, u1, u2 }, true); GeoFace f1 = new GeoFace(new VertexUnit[] { u1, u0, u3 }, true); GeoFace f2 = new GeoFace(new VertexUnit[] { u0, u2, u3 }, true); GeoFace f3 = new GeoFace(new VertexUnit[] { u2, u1, u3 }, true); AddGeoFace(f0); AddGeoFace(f1); AddGeoFace(f2); AddGeoFace(f3); InitDatas(); }
private void SpreadCone() { float Radius = circular.radius1; float height = circular.Vertices[0].y - circular.Vertices[1].y; float width = circular.Vertices[2].z - circular.Vertices[1].z; float fanRadius = Mathf.Sqrt(height * height + width * width); positionZ = fanRadius / 2; geoCamera.TriggerMoveZAnimation(270, 0, positionZ); VertexSpace u0 = new VertexSpace(circular.Vertices[0]); VertexSpace u1 = new VertexSpace(circular.Vertices[2]); VertexSpace u2 = new VertexSpace(circular.Vertices[1]); int segments = 60; float angleRad = Mathf.Deg2Rad * (360 * Radius / fanRadius); float angleCur = Mathf.Deg2Rad * (180 - Mathf.Acos(height / fanRadius) * 180 / Mathf.PI - 360 * Radius / fanRadius); float angledelta = angleRad / segments; int vertices_count = segments + 1; VertexSpace v1; VertexSpace v2; GeoFace f; Vector3[] vertices = new Vector3[vertices_count]; for (int i = 0; i < vertices_count; i++) { float cosA = Mathf.Cos(angleCur); float sinA = Mathf.Sin(angleCur); vertices[i] = new Vector3(u0.Position().x + 0, u0.Position().y + fanRadius * cosA, u0.Position().x + fanRadius * sinA); angleCur += angledelta; } VertexSpace[] vertexs = new VertexSpace[vertices_count + 1]; vertexs[0] = u0; for (int i = 0; i < vertices_count - 1; i++) { v1 = new VertexSpace(vertices[i]); v2 = new VertexSpace(vertices[i + 1]); vertexs[i + 1] = v1; vertexs[i + 2] = v2; geometryBehaviour.AddElement(new GeoEdge(v1, v2, false)); } f = new GeoFace(vertexs, false, FaceType.SpreadFan); geometryBehaviour.AddElement(f); GeoEdge e1 = new GeoEdge(u0, new VertexSpace(vertices[0]), false); GeoEdge e2 = new GeoEdge(u0, new VertexSpace(vertices[vertices_count - 1]), false); geometryBehaviour.AddElement(e1); geometryBehaviour.AddElement(e2); VertexSpace u3 = new VertexSpace(0, circular.Vertices[0].y, fanRadius + Radius); GeoCircle c2 = new GeoCircle(u3, Radius, CircleDirection.X, true, FaceType.SpreadConeCircle); geometryBehaviour.AddElement(c2); }
public override void InitWithGeometry(Geometry geometry) { VertexSpace unit = new VertexSpace(x, y, z); unit.preferredSign = sign; geometry.VertexUnitSetId(unit, 0); units = new VertexUnit[] { unit }; GeoVertex geoVertex = new GeoVertex(unit); elements = new GeoElement[] { geoVertex }; }
private void AddCurFace(float Angle) { float X1 = Radius1 * Mathf.Sin(Mathf.Deg2Rad * Angle); float Z1 = Radius1 * Mathf.Cos(Mathf.Deg2Rad * Angle); float preX1 = Radius1 * Mathf.Sin(Mathf.Deg2Rad * PreAngle); float preZ1 = Radius1 * Mathf.Cos(Mathf.Deg2Rad * PreAngle); float X2 = Radius2 * Mathf.Sin(Mathf.Deg2Rad * Angle); float Z2 = Radius2 * Mathf.Cos(Mathf.Deg2Rad * Angle); float preX2 = Radius2 * Mathf.Sin(Mathf.Deg2Rad * PreAngle); float preZ2 = Radius2 * Mathf.Cos(Mathf.Deg2Rad * PreAngle); if (vertices.Length == 3) { VertexSpace v1 = new VertexSpace(vertices[0].Position()); VertexSpace v2 = new VertexSpace(vertices[1].Position()); VertexSpace v3 = new VertexSpace(X1, vertices[2].Position().y, Z1); VertexSpace v4 = new VertexSpace(preX1, vertices[2].Position().y, preZ1); geometryBehaviour.AddElement(new GeoFace(new VertexUnit[] { v1, v3, v4 })); geometryBehaviour.AddElement(new GeoFace(new VertexUnit[] { v2, v3, v4 })); geometryBehaviour.AddElement(new GeoEdge(v3, v4)); addBorderLine(v1.Position(), v3.Position()); addBorderLine(v2.Position(), v3.Position()); } else if (vertices.Length == 4) { VertexSpace v1 = new VertexSpace(vertices[0].Position()); VertexSpace v2 = new VertexSpace(X2, vertices[3].Position().y, Z2); VertexSpace v3 = new VertexSpace(preX2, vertices[3].Position().y, preZ2); VertexSpace v4 = new VertexSpace(vertices[1].Position()); VertexSpace v5 = new VertexSpace(X1, vertices[2].Position().y, Z1); VertexSpace v6 = new VertexSpace(preX1, vertices[2].Position().y, preZ1); geometryBehaviour.AddElement(new GeoFace(new VertexUnit[] { v1, v2, v3 })); geometryBehaviour.AddElement(new GeoFace(new VertexUnit[] { v4, v5, v6 })); geometryBehaviour.AddElement(new GeoFace(new VertexUnit[] { v2, v5, v6, v3 })); geometryBehaviour.AddElement(new GeoEdge(v2, v3)); geometryBehaviour.AddElement(new GeoEdge(v5, v6)); addBorderLine(v1.Position(), v2.Position()); addBorderLine(v2.Position(), v5.Position()); addBorderLine(v4.Position(), v5.Position()); } PreAngle = Angle; }
public void GenerateResolvedBody(Geometry geometry) { SpinAuxiliary auxiliary = new SpinAuxiliary(); auxiliary.InitWithGeometry(geometry); geometryBehaviour = GameObject.Find("/3D/Geometry").GetComponent <GeometryBehaviour>(); VertexUnit[] vertexUnits = auxiliary.vertices; // Cylinder if (vertexUnits.Length == 4) { VertexUnit vertex1 = vertexUnits[0]; VertexUnit vertex2 = vertexUnits[1]; VertexUnit vertex3 = vertexUnits[2]; VertexUnit vertex4 = vertexUnits[3]; float radius1 = vertexUnits[3].Position().z; float radius2 = vertexUnits[2].Position().z; GeoCircular circular = new GeoCircular(new VertexUnit[] { vertex1, vertex2, vertex3, vertex4 }, radius1, radius2, CircularType.Cylinder); geometry.AddGeoCircular(circular); VertexSpace circle1 = new VertexSpace(0, vertex4.Position().y, 0); VertexSpace circle2 = new VertexSpace(0, vertex3.Position().y, 0); geometry.AddGeoCircle(new GeoCircle(circle1, radius1, CircleDirection.Y, false, FaceType.SpreadCylinderCircle)); geometry.AddGeoCircle(new GeoCircle(circle2, radius2, CircleDirection.Y, false, FaceType.SpreadCylinderCircle)); } // Cone else if (vertexUnits.Length == 3) { VertexUnit vertex1 = vertexUnits[0]; VertexUnit vertex2 = vertexUnits[1]; VertexUnit vertex3 = vertexUnits[2]; float radius = vertexUnits[2].Position().z; GeoCircular circular = new GeoCircular(new VertexUnit[] { vertex1, vertex2, vertex3 }, radius, radius, CircularType.Cone); geometry.AddGeoCircular(circular); VertexSpace circle1 = new VertexSpace(0, vertex3.Position().y, 0); geometry.AddGeoCircle(new GeoCircle(circle1, radius, CircleDirection.Y, false, FaceType.SpreadConeCircle)); } geometryBehaviour.InitGeometry(geometry); StatusButton lockButton = GameObject.Find("LockButton").GetComponent <StatusButton>(); lockButton.SetStatus(0); }
private void SpreadCylinder() { float Radius = circular.radius1; float height = circular.Vertices[0].y - circular.Vertices[1].y; float width = 2 * Mathf.PI * Radius; positionZ = width / 2; geoCamera.TriggerMoveZAnimation(270, 0, positionZ); VertexSpace u0 = new VertexSpace(0, height / 2, Radius); VertexSpace u1 = new VertexSpace(0, -height / 2, Radius); VertexSpace u2 = new VertexSpace(0, -height / 2, Radius + width); VertexSpace u3 = new VertexSpace(0, height / 2, Radius + width); GeoEdge e0 = new GeoEdge(u0, u1, false); GeoEdge e1 = new GeoEdge(u1, u2, false); GeoEdge e2 = new GeoEdge(u2, u3, false); GeoEdge e3 = new GeoEdge(u0, u3, false); geometryBehaviour.AddElement(e0); geometryBehaviour.AddElement(e1); geometryBehaviour.AddElement(e2); geometryBehaviour.AddElement(e3); GeoFace f = new GeoFace(new VertexSpace[] { u0, u1, u2, u3 }, false, FaceType.SpreadRectangle); geometryBehaviour.AddElement(f); VertexSpace u4 = new VertexSpace(0, height / 2 + Radius, width / 2 + Radius); GeoCircle c1 = new GeoCircle(u4, Radius, CircleDirection.X, true, FaceType.SpreadCylinderCircle); geometryBehaviour.AddElement(c1); VertexSpace u5 = new VertexSpace(0, -height / 2 - Radius, width / 2 + Radius); GeoCircle c2 = new GeoCircle(u5, Radius, CircleDirection.X, true, FaceType.SpreadCylinderCircle); geometryBehaviour.AddElement(c2); }
private void AddCurFace(float Angle) { float sin = Mathf.Sin(Mathf.Deg2Rad * Angle); float pre_sin = Mathf.Sin(Mathf.Deg2Rad * PreAngle); float cos = Mathf.Cos(Mathf.Deg2Rad * Angle); float pre_cos = Mathf.Cos(Mathf.Deg2Rad * PreAngle); float X0 = Radius0 * sin; float Z0 = Radius0 * cos; float preX0 = Radius0 * pre_sin; float preZ0 = Radius0 * pre_cos; float X1 = Radius1 * sin; float Z1 = Radius1 * cos; float preX1 = Radius1 * pre_sin; float preZ1 = Radius1 * pre_cos; float X2 = Radius2 * sin; float Z2 = Radius2 * cos; float preX2 = Radius2 * pre_sin; float preZ2 = Radius2 * pre_cos; if (vertices.Length == 3) { VertexSpace v0 = new VertexSpace(X0, vertices[0].Position().y, Z0); VertexSpace v1 = new VertexSpace(preX0, vertices[0].Position().y, preZ0); VertexSpace v2 = new VertexSpace(X1, vertices[1].Position().y, Z1); VertexSpace v3 = new VertexSpace(preX1, vertices[1].Position().y, preZ1); VertexSpace v4 = new VertexSpace(X2, vertices[2].Position().y, Z2); VertexSpace v5 = new VertexSpace(preX2, vertices[2].Position().y, preZ2); geometryBehaviour.AddElement(new GeoFace(new VertexUnit[] { v0, v2, v3, v1 })); geometryBehaviour.AddElement(new GeoFace(new VertexUnit[] { v0, v1, v5, v4 })); geometryBehaviour.AddElement(new GeoFace(new VertexUnit[] { v2, v3, v5, v4 })); geometryBehaviour.AddElement(new GeoEdge(v0, v1)); geometryBehaviour.AddElement(new GeoEdge(v2, v3)); geometryBehaviour.AddElement(new GeoEdge(v4, v5)); addBorderLine(v0.Position(), v2.Position()); addBorderLine(v2.Position(), v4.Position()); addBorderLine(v4.Position(), v0.Position()); } else if (vertices.Length == 4) { float X3 = Radius3 * sin; float Z3 = Radius3 * cos; float preX3 = Radius3 * pre_sin; float preZ3 = Radius3 * pre_cos; VertexSpace v0 = new VertexSpace(X0, vertices[0].Position().y, Z0); VertexSpace v1 = new VertexSpace(preX0, vertices[0].Position().y, preZ0); VertexSpace v2 = new VertexSpace(X1, vertices[1].Position().y, Z1); VertexSpace v3 = new VertexSpace(preX1, vertices[1].Position().y, preZ1); VertexSpace v4 = new VertexSpace(X2, vertices[2].Position().y, Z2); VertexSpace v5 = new VertexSpace(preX2, vertices[2].Position().y, preZ2); VertexSpace v6 = new VertexSpace(X3, vertices[3].Position().y, Z3); VertexSpace v7 = new VertexSpace(preX3, vertices[3].Position().y, preZ3); geometryBehaviour.AddElement(new GeoFace(new VertexUnit[] { v0, v2, v3, v1 })); geometryBehaviour.AddElement(new GeoFace(new VertexUnit[] { v0, v1, v7, v6 })); geometryBehaviour.AddElement(new GeoFace(new VertexUnit[] { v2, v3, v5, v4 })); geometryBehaviour.AddElement(new GeoFace(new VertexUnit[] { v4, v5, v7, v6 })); geometryBehaviour.AddElement(new GeoEdge(v0, v1)); geometryBehaviour.AddElement(new GeoEdge(v2, v3)); geometryBehaviour.AddElement(new GeoEdge(v4, v5)); geometryBehaviour.AddElement(new GeoEdge(v6, v7)); addBorderLine(v0.Position(), v2.Position()); addBorderLine(v2.Position(), v4.Position()); addBorderLine(v4.Position(), v6.Position()); addBorderLine(v6.Position(), v0.Position()); } PreAngle = Angle; }