protected void BuildEndCapCutNoHollow(bool top) { V3ToV3Xna XnaOMV = new V3ToV3Xna(); float z = top ? 0.5f : -0.5f; for (int i = FirstOuterFace; i <= LastOuterFace; i++) { int pointCount = OuterFaces[i].GetNumPoints(); for (int j = 0; j < pointCount - 1; j++) { Vector3 first = XnaOMV.V3ToV3X(OuterFaces[i].GetRawVertex(j)); first.Z = z; Vector3 second = XnaOMV.V3ToV3X(OuterFaces[i].GetRawVertex(j + 1)); second.Z = z; Vector3 center = new Vector3(0, 0, z); // TODO: Texturemapping stuff //Vector2 t1 = texturemapping.GetTextureCoordinate(new Vector2(1 - (p1.x + 0.5), p1.y + 0.5)); //Vector2 t2 = texturemapping.GetTextureCoordinate(new Vector2(1 - (p2.x + 0.5), p2.y + 0.5)); float transformRatio = top ? 1 : 0; first = Transform(first, transformRatio); second = Transform(second, transformRatio); center = Transform(center, transformRatio); Vertexes.Add(new VertexPositionColor(first, color)); Vertexes.Add(new VertexPositionColor(second, color)); Vertexes.Add(new VertexPositionColor(center, color)); } } }
// Handles the first face in the cut, starting from cutstart, // and running anticlockwise to first reference vertex private float PopulateSingleCutFacePositiveDirection(ref CrossSection face, OpenMetaverse.Vector3 cutPoint, int quadrant, float halfCubeWidth, bool outer) { V3ToV3Xna XnaOMV = new V3ToV3Xna(); quadrant = NormalizeQuadrant(quadrant); face.RemoveAllPoints(); OpenMetaverse.Vector3 startPoint = cutPoint; OpenMetaverse.Vector3 endPoint; if (quadrant < NumberFaces - 1) { endPoint = XnaOMV.V3XToV3(ReferenceVertices[quadrant + 1] * halfCubeWidth / 0.5f); } else { endPoint = XnaOMV.V3XToV3(ReferenceVertices[0] * halfCubeWidth / 0.5f); } if (outer) { face.AddPoint(startPoint); face.AddPoint(endPoint); } else { face.AddPoint(endPoint); face.AddPoint(startPoint); } return OpenMetaverse.Vector3.Distance(startPoint, endPoint); }
private float PopulateCompleteSide(ref CrossSection face, int quadrant, float halfCubeWidth, bool outer) { V3ToV3Xna XnaOMV = new V3ToV3Xna(); quadrant = NormalizeQuadrant(quadrant); face.RemoveAllPoints(); OpenMetaverse.Vector3 startPoint = XnaOMV.V3XToV3(ReferenceVertices[quadrant]); OpenMetaverse.Vector3 endPoint; if (quadrant < NumberFaces - 1) { endPoint = XnaOMV.V3XToV3(ReferenceVertices[quadrant + 1]); } else { endPoint = XnaOMV.V3XToV3(ReferenceVertices[0]); } startPoint = startPoint * halfCubeWidth / 0.5f; endPoint = endPoint * halfCubeWidth / 0.5f; if (outer) { face.AddPoint(startPoint); face.AddPoint(endPoint); } else { face.AddPoint(endPoint); face.AddPoint(startPoint); } return 2f * halfCubeWidth; }
private OpenMetaverse.Vector3 GetCutIntersect(float cut, float cubeHalfWidth) { V3ToV3Xna XnaOMV = new V3ToV3Xna(); int cutQuadrant = GetCutQuadrant(cut); OpenMetaverse.Vector3 lineend; OpenMetaverse.Vector3 linestart = XnaOMV.V3XToV3(ReferenceVertices[cutQuadrant] * cubeHalfWidth); linestart = OpenMetaverse.Vector3.Divide(linestart, 0.5f); if (cutQuadrant < NumberFaces - 1) { lineend = XnaOMV.V3XToV3(ReferenceVertices[cutQuadrant + 1] * cubeHalfWidth); } else { lineend = XnaOMV.V3XToV3(ReferenceVertices[0] * cubeHalfWidth); } lineend = OpenMetaverse.Vector3.Divide(lineend, 0.5f); // float angle = GetAngleWithXAxis(cut); // CutVectorPerp is perpendicular to the radius vector OpenMetaverse.Vector3 cutVectorPerp = new OpenMetaverse.Vector3((float)-Math.Sin(angle), (float)Math.Cos(angle), 0); OpenMetaverse.Vector3 delta = lineend - linestart; // From http://softsurfer.com/Archive/algorithm_0104/algorithm_0104B.htm OpenMetaverse.Vector3 result = linestart - delta * OpenMetaverse.Vector3.Dot(cutVectorPerp, linestart) / OpenMetaverse.Vector3.Dot(cutVectorPerp, delta); return result; }
protected void BuildSideVertexes(CrossSection[] crossSection, int transforms) { V3ToV3Xna XnaOMV = new V3ToV3Xna(); float transformOffset = 1.0f / (float)transforms; float currentOffset = -0.5f; for (int i = 0; i < transforms; i++) { for (int j = 0; j < crossSection.Length; j++) { int pointCount = crossSection[j].GetNumPoints(); if (pointCount > 0) { for (int k = 0; k < pointCount - 1; k++) { Vector3 lower1, lower2, upper1, upper2; float lowerRatio = (float)i / (float)transforms; float upperRatio = (float)(i + 1) / (float)transforms; lower1 = XnaOMV.V3ToV3X(crossSection[j].GetRawVertex(k)); lower2 = XnaOMV.V3ToV3X(crossSection[j].GetRawVertex(k + 1)); lower1.Z = currentOffset; lower2.Z = currentOffset; upper1 = lower1; upper2 = lower2; upper1.Z = currentOffset + transformOffset; upper2.Z = currentOffset + transformOffset; lower1 = Transform(lower1, lowerRatio); lower2 = Transform(lower2, lowerRatio); upper1 = Transform(upper1, upperRatio); upper2 = Transform(upper2, upperRatio); Vertexes.Add(new VertexPositionColor(lower1, color)); Vertexes.Add(new VertexPositionColor(lower2, color)); Vertexes.Add(new VertexPositionColor(upper2, color)); Vertexes.Add(new VertexPositionColor(lower1, color)); Vertexes.Add(new VertexPositionColor(upper2, color)); Vertexes.Add(new VertexPositionColor(upper1, color)); } } } currentOffset += transformOffset; } }
protected void BuildEndCapNoCutNoHollow(bool top) { V3ToV3Xna XnaOMV = new V3ToV3Xna(); float z = top ? 0.5f : -0.5f; for (int i = 0; i < OuterFaces.Length; i++) { int pointCount = OuterFaces[i].GetNumPoints(); if (pointCount > 0) { for (int j = 0; j < pointCount - 1; j++) { Vector3 first = XnaOMV.V3ToV3X((OuterFaces[i].GetRawVertex(j))); first.Z = z; Vector3 second = XnaOMV.V3ToV3X(OuterFaces[i].GetRawVertex(j + 1)); second.Z = z; Vector3 center = new Vector3(0, 0, z); float transformRatio = top ? 1 : 0; // Apply the transformation to each vertex first = Transform(first, transformRatio); second = Transform(second, transformRatio); center = Transform(center, transformRatio); Vertexes.Add(new VertexPositionColor(first, color)); Vertexes.Add(new VertexPositionColor(second, color)); Vertexes.Add(new VertexPositionColor(center, color)); } } } }