protected double PopulateSingleCutFacePositiveDirection(ref CrossSection face, GLVector3d CutPoint, int iQuadrant, double fHalfCubeWidth, bool bOuter) { iQuadrant = NormalizeQuadrant(iQuadrant); face.RemoveAllPoints(); GLVector3d StartPoint = new GLVector3d(CutPoint); GLVector3d EndPoint = null; if (iQuadrant < iNumberFaces - 1) { EndPoint = ReferenceVertices[iQuadrant + 1] * fHalfCubeWidth / 0.5; } else { EndPoint = ReferenceVertices[0] * fHalfCubeWidth / 0.5; } if (bOuter) { face.AddPoint(StartPoint); face.AddPoint(EndPoint); } else { face.AddPoint(EndPoint); face.AddPoint(StartPoint); } return((EndPoint - StartPoint).length()); }
protected double PopulateCompleteSide(ref CrossSection face, int iQuadrant, double fHalfCubeWidth, bool bOuter) { iQuadrant = NormalizeQuadrant(iQuadrant); face.RemoveAllPoints(); GLVector3d StartPoint = ReferenceVertices[iQuadrant]; GLVector3d EndPoint = null; if (iQuadrant < iNumberFaces - 1) { EndPoint = ReferenceVertices[iQuadrant + 1]; } else { EndPoint = ReferenceVertices[0]; } StartPoint = StartPoint * fHalfCubeWidth / 0.5; EndPoint = EndPoint * fHalfCubeWidth / 0.5; if (bOuter) { face.AddPoint(StartPoint.x, StartPoint.y, StartPoint.z); face.AddPoint(EndPoint.x, EndPoint.y, EndPoint.z); } else { face.AddPoint(EndPoint.x, EndPoint.y, EndPoint.z); face.AddPoint(StartPoint.x, StartPoint.y, StartPoint.z); } return(2 * fHalfCubeWidth); }
public Tube(IRenderer renderer) { ReferenceVertices = new GLVector3d[4]; ReferenceVertices[0] = new GLVector3d(0.5, -0.5, 0); ReferenceVertices[1] = new GLVector3d(0.5, 0.5, 0); ReferenceVertices[2] = new GLVector3d(-0.5, 0.5, 0); ReferenceVertices[3] = new GLVector3d(-0.5, -0.5, 0); iFirstOuterFace = 0; iLastOuterFace = 3; iNumberFaces = 4; bShowCut = false; bShowHollow = false; iCutStart = 0; iCutEnd = MaxCut; this.renderer = renderer; SendRendererCallbacksToCrossSections(); rotationalextrusionpath.UpdatePath(); BuildFaces(); }
GLVector3d CalculateNormal(GLVector3d p1, GLVector3d p2, GLVector3d p3, GLVector3d p4) { GLVector3d vectorac = p3 - p1; GLVector3d vectorbd = p4 - p2; return(vectorac.getCross(vectorbd).unit()); }
protected void BuildCutFaces(GLVector3d cutstartouterface, GLVector3d cutstartinnerface, GLVector3d cutendouterface, GLVector3d cutendinnerface) { CutFaces[0].RemoveAllPoints(); if (bShowHollow) { CutFaces[0].AddPoint(cutstartinnerface); } else { CutFaces[0].AddPoint(0, 0, 0); } CutFaces[0].AddPoint(cutstartouterface); CutFaces[0].TextureMapping = texturemapping; CutFaces[1].RemoveAllPoints(); CutFaces[1].AddPoint(cutendouterface); if (bShowHollow) { CutFaces[1].AddPoint(cutendinnerface); } else { CutFaces[1].AddPoint(0, 0, 0); } CutFaces[1].TextureMapping = texturemapping; }
public Prism(IRenderer renderer) { ReferenceVertices = new GLVector3d[3]; ReferenceVertices[0] = new GLVector3d(0.5, -0.2886751, 0); ReferenceVertices[1] = new GLVector3d(0, 0.57735, 0); ReferenceVertices[2] = new GLVector3d(-0.5, -0.2886751, 0); iFirstOuterFace = 0; iLastOuterFace = 2; iNumberFaces = 3; bShowCut = false; bShowHollow = false; iCutStart = 0; iCutEnd = MaxCut; this.renderer = renderer; SendRendererCallbacksToCrossSections(); linearextrusionpath.UpdatePath(); BuildFaces(); }
//! BAsically we check the quadrant (0 to 3), then intersect the radius with the face corresponding to that quadrant // The cut starts from the clockwise-end vertex of quadrant 0, and rotates anticlockwise; assuming x points right and y points up GLVector3d GetCutIntersect(int iCut, double fCubeHalfWidth) { int iCutQuadrant = GetCutQuadrant(iCut); double fCutRatio = (double)iCut / (double)MaxCut; GLVector3d lineend = null; GLVector3d linestart = ReferenceVertices[iCutQuadrant] * fCubeHalfWidth / 0.5; if (iCutQuadrant < iNumberFaces - 1) { lineend = ReferenceVertices[iCutQuadrant + 1] * fCubeHalfWidth / 0.5; } else { lineend = ReferenceVertices[0] * fCubeHalfWidth / 0.5; } double fAngle = GetAngleWithXAxis(fCutRatio); // CutVectorPerp is perpendicular to the radius vector, I think GLVector3d CutVectorPerp = new GLVector3d(-Math.Sin(fAngle), Math.Cos(fAngle), 0); // Grabbed this from http://softsurfer.com/Archive/algorithm_0104/algorithm_0104B.htm GLVector3d IntersectPoint = linestart - (lineend - linestart) * CutVectorPerp.dot(linestart) / CutVectorPerp.dot(lineend - linestart); //Console.WriteLine( "GetCutIntersect iCut " + iCut.ToString() + " cubehalfwidth " + fCubeHalfWidth.ToString() + " linestart " + linestart.ToString() + // lineend.ToString() + " fAngle " + fAngle.ToString() + " CutVectorPerp " + CutVectorPerp.ToString() + " intersectpoint " + IntersectPoint.ToString() ); return(IntersectPoint); }
// useful for triangles protected GLVector3d CalculateNormal(GLVector3d p1, GLVector3d p2, GLVector3d p3) { GLVector3d vectorab = p2 - p1; GLVector3d vectorac = p3 - p1; return(vectorab.getCross(vectorac).unit()); }
public void Render(ExtrusionPath extrusionpath) { for (int i = 0; i < extrusionpath.NumberOfTransforms - 1; i++) { for (int j = 0; j < iNumPoints - 1; j++) { // p1 - p4 are the quad we are rendering GLVector3d p1 = extrusionpath.GetTransformedVertex(points[j], i); GLVector3d p2 = extrusionpath.GetTransformedVertex(points[j + 1], i); GLVector3d p3 = extrusionpath.GetTransformedVertex(points[j + 1], i + 1); GLVector3d p4 = extrusionpath.GetTransformedVertex(points[j], i + 1); Vector2 t1 = texturemapping.GetTextureCoordinate(new Vector2((double)j / (iNumPoints - 1), (double)i / (extrusionpath.NumberOfTransforms - 1))); Vector2 t2 = texturemapping.GetTextureCoordinate(new Vector2((double)(j + 1) / (iNumPoints - 1), (double)i / (extrusionpath.NumberOfTransforms - 1))); Vector2 t3 = texturemapping.GetTextureCoordinate(new Vector2((double)(j + 1) / (iNumPoints - 1), (double)(i + 1) / (extrusionpath.NumberOfTransforms - 1))); Vector2 t4 = texturemapping.GetTextureCoordinate(new Vector2((double)j / (iNumPoints - 1), (double)(i + 1) / (extrusionpath.NumberOfTransforms - 1))); GLVector3d normal = CalculateNormal(p1, p2, p3, p4); renderer.SetNormal(normal.x, normal.y, normal.z); renderer.StartTriangle(); renderer.SetTextureCoord(t1.x, t1.y); renderer.AddVertex(p1.x, p1.y, p1.z); renderer.SetTextureCoord(t2.x, t2.y); renderer.AddVertex(p2.x, p2.y, p2.z); renderer.SetTextureCoord(t3.x, t3.y); renderer.AddVertex(p3.x, p3.y, p3.z); renderer.EndTriangle(); renderer.StartTriangle(); renderer.SetTextureCoord(t1.x, t1.y); renderer.AddVertex(p1.x, p1.y, p1.z); renderer.SetTextureCoord(t3.x, t3.y); renderer.AddVertex(p3.x, p3.y, p3.z); renderer.SetTextureCoord(t4.x, t4.y); renderer.AddVertex(p4.x, p4.y, p4.z); renderer.EndTriangle(); } } }
//! BAsically we check the quadrant, then intersect it, then we just intersect the radius with the appropriate face protected virtual GLVector3d GetCutIntersect(int iCut, double fCubeHalfWidth) { int iCutQuadrant = GetCutQuadrant(iCut); double fCutRatio = (double)iCut / (double)MaxCut; GLVector3d linestart = ReferenceVertices[iCutQuadrant] * fCubeHalfWidth / 0.5; GLVector3d lineend = null; if (iCutQuadrant < iNumberFaces - 1) { lineend = ReferenceVertices[iCutQuadrant + 1] * fCubeHalfWidth / 0.5; } else { lineend = ReferenceVertices[0] * fCubeHalfWidth / 0.5; } double fAngle = GetAngleWithXAxis(fCutRatio); GLVector3d CutVectorPerp = new GLVector3d(-Math.Sin(fAngle), Math.Cos(fAngle), 0); // Grabbed this from http://softsurfer.com/Archive/algorithm_0104/algorithm_0104B.htm return(linestart - (lineend - linestart) * CutVectorPerp.dot(linestart) / CutVectorPerp.dot(lineend - linestart)); }
protected override void BuildFaces() { if (iCutStart == 0 && iCutEnd == MaxCut) { bShowCut = false; } else { bShowCut = true; } if (iExtrusionStart == 0 && iExtrusionEnd == 200) { bShowEndCaps = false; } else { bShowEndCaps = true; } if (iHollow == 0) { bShowHollow = false; } else { bShowHollow = true; } double fHollowRatio = (double)iHollow / 100; GLVector3d cutstartouterface = GetCutIntersect(iCutStart, 0.5); GLVector3d cutendouterface = GetCutIntersect(iCutEnd, 0.5); GLVector3d cutstartinnerface = null; GLVector3d cutendinnerface = null; if (bShowHollow) { cutstartinnerface = GetCutIntersect(iCutStart, fHollowRatio * 0.5); cutendinnerface = GetCutIntersect(iCutEnd, fHollowRatio * 0.5); } if (bShowCut) { BuildCutFaces(cutstartouterface, cutstartinnerface, cutendouterface, cutendinnerface); } OuterFaces[0].RemoveAllPoints(); InnerFaces[0].RemoveAllPoints(); double fStartAngle = (double)iCutStart / (double)MaxCut * 2 * Math.PI; double fEndAngle = (double)iCutEnd / (double)MaxCut * 2 * Math.PI; GLVector3d NextOuterPoint = new GLVector3d(); GLVector3d NextInnerPoint = new GLVector3d(); for (int iFacePoint = 0; iFacePoint <= iLevelOfDetail; iFacePoint++) { double fAngle = fStartAngle + (double)iFacePoint / (double)iLevelOfDetail * (fEndAngle - fStartAngle); NextOuterPoint.x = 0.5 * Math.Cos(fAngle); NextOuterPoint.y = 0.5 * Math.Sin(fAngle); OuterFaces[0].AddPoint(NextOuterPoint); } if (bShowHollow) { for (int iFacePoint = iLevelOfDetail; iFacePoint >= 0; iFacePoint--) { double fAngle = fStartAngle + (double)iFacePoint / (double)iLevelOfDetail * (fEndAngle - fStartAngle); NextInnerPoint.x = 0.5 * Math.Cos(fAngle) * (double)iHollow / 100.0; NextInnerPoint.y = 0.5 * Math.Sin(fAngle) * (double)iHollow / 100.0; InnerFaces[0].AddPoint(NextInnerPoint); } } OuterFaces[0].TextureMapping = texturemapping; InnerFaces[0].TextureMapping = texturemapping; AssignFaces(); }
public GLVector3d GetTransformedVertex(GLVector3d PointToTransform, int iTransformIndex) { return(transforms[iTransformIndex] * PointToTransform); }
public void AddPoint(double x, double y, double z) { points[iNumPoints] = new GLVector3d(x, y, z); iNumPoints++; }
public void AddPoint(GLVector3d point) { points[iNumPoints] = new GLVector3d(point); iNumPoints++; }
protected virtual void RenderEndCapNoHollow(bool IsTop) { GLVector3d rawcentre = new GLVector3d(); if (!IsTop) { GLVector3d p0 = rotationalextrusionpath.GetTransformedVertex(new GLVector3d(0, 0, 0), 0); Vector2 t0 = texturemapping.GetTextureCoordinate(new Vector2(0.5, 0.5)); for (int i = iFirstOuterFace; i <= iLastOuterFace; i++) { GLVector3d p1 = OuterFaces[i].GetTransformedVertex(rotationalextrusionpath, 0, 0); GLVector3d p2 = OuterFaces[i].GetTransformedVertex(rotationalextrusionpath, 0, 1); GLVector3d r1 = OuterFaces[i].GetRawVertex(0); GLVector3d r2 = OuterFaces[i].GetRawVertex(1); Vector2 t1 = texturemapping.GetTextureCoordinate(new Vector2(1 - (r1.x + 0.5), r1.y + 0.5)); Vector2 t2 = texturemapping.GetTextureCoordinate(new Vector2(1 - (r2.x + 0.5), r2.y + 0.5)); GLVector3d normal = CalculateNormal(p2, p1, p0); renderer.SetNormal(normal.x, normal.y, normal.z); renderer.StartTriangle(); renderer.SetTextureCoord(t0.x, t0.y); renderer.AddVertex(p0.x, p0.y, p0.z); renderer.SetTextureCoord(t2.x, t2.y); renderer.AddVertex(p2.x, p2.y, p2.z); renderer.SetTextureCoord(t1.x, t1.y); renderer.AddVertex(p1.x, p1.y, p1.z); renderer.EndTriangle(); } } else { GLVector3d p0 = rotationalextrusionpath.GetTransformedVertex(new GLVector3d(0, 0, 0), rotationalextrusionpath.NumberOfTransforms - 1); Vector2 t0 = texturemapping.GetTextureCoordinate(new Vector2(0.5, 0.5)); for (int i = iFirstOuterFace + 1; i < iLastOuterFace; i++) { GLVector3d p1 = OuterFaces[i].GetTransformedVertex(rotationalextrusionpath, rotationalextrusionpath.NumberOfTransforms - 1, 0); GLVector3d p2 = OuterFaces[i].GetTransformedVertex(rotationalextrusionpath, rotationalextrusionpath.NumberOfTransforms - 1, 1); GLVector3d r1 = OuterFaces[i].GetRawVertex(0); GLVector3d r2 = OuterFaces[i].GetRawVertex(1); Vector2 t1 = texturemapping.GetTextureCoordinate(new Vector2(r1.x + 0.5, r1.y + 0.5)); Vector2 t2 = texturemapping.GetTextureCoordinate(new Vector2(r2.x + 0.5, r2.y + 0.5)); GLVector3d normal = CalculateNormal(p2, p1, p0); renderer.SetNormal(normal.x, normal.y, normal.z); renderer.StartTriangle(); renderer.SetTextureCoord(t0.x, t0.y); renderer.AddVertex(p0.x, p0.y, p0.z); renderer.SetTextureCoord(t1.x, t1.y); renderer.AddVertex(p1.x, p1.y, p1.z); renderer.SetTextureCoord(t2.x, t2.y); renderer.AddVertex(p2.x, p2.y, p2.z); renderer.EndTriangle(); } } }
protected virtual void RenderEndCapHollow(bool IsTop) { if (!IsTop) { for (int i = iFirstOuterFace; i <= iLastOuterFace; i++) { GLVector3d p1 = OuterFaces[i].GetTransformedVertex(rotationalextrusionpath, 0, 0); GLVector3d p2 = OuterFaces[i].GetTransformedVertex(rotationalextrusionpath, 0, 1); GLVector3d p3 = InnerFaces[i].GetTransformedVertex(rotationalextrusionpath, 0, 0); GLVector3d p4 = InnerFaces[i].GetTransformedVertex(rotationalextrusionpath, 0, 1); GLVector3d r1 = OuterFaces[i].GetRawVertex(0); GLVector3d r2 = OuterFaces[i].GetRawVertex(1); GLVector3d r3 = InnerFaces[i].GetRawVertex(0); GLVector3d r4 = InnerFaces[i].GetRawVertex(1); Vector2 t1 = texturemapping.GetTextureCoordinate(new Vector2(1 - (r1.x + 0.5), r1.y + 0.5)); Vector2 t2 = texturemapping.GetTextureCoordinate(new Vector2(1 - (r2.x + 0.5), r2.y + 0.5)); Vector2 t3 = texturemapping.GetTextureCoordinate(new Vector2(1 - (r3.x + 0.5), r3.y + 0.5)); Vector2 t4 = texturemapping.GetTextureCoordinate(new Vector2(1 - (r4.x + 0.5), r4.y + 0.5)); GLVector3d normal = CalculateNormal(p4, p3, p2, p1); renderer.SetNormal(normal.x, normal.y, normal.z); renderer.StartTriangle(); renderer.SetTextureCoord(t4.x, t4.y); renderer.AddVertex(p4.x, p4.y, p4.z); renderer.SetTextureCoord(t3.x, t3.y); renderer.AddVertex(p3.x, p3.y, p3.z); renderer.SetTextureCoord(t2.x, t2.y); renderer.AddVertex(p2.x, p2.y, p2.z); renderer.EndTriangle(); renderer.StartTriangle(); renderer.SetTextureCoord(t2.x, t2.y); renderer.AddVertex(p2.x, p2.y, p2.z); renderer.SetTextureCoord(t1.x, t1.y); renderer.AddVertex(p1.x, p1.y, p1.z); renderer.SetTextureCoord(t4.x, t4.y); renderer.AddVertex(p4.x, p4.y, p4.z); renderer.EndTriangle(); } } else { for (int i = iFirstOuterFace; i <= iLastOuterFace; i++) { GLVector3d p1 = OuterFaces[i].GetTransformedVertex(rotationalextrusionpath, rotationalextrusionpath.NumberOfTransforms - 1, 0); GLVector3d p2 = OuterFaces[i].GetTransformedVertex(rotationalextrusionpath, rotationalextrusionpath.NumberOfTransforms - 1, 1); GLVector3d p3 = InnerFaces[i].GetTransformedVertex(rotationalextrusionpath, rotationalextrusionpath.NumberOfTransforms - 1, 0); GLVector3d p4 = InnerFaces[i].GetTransformedVertex(rotationalextrusionpath, rotationalextrusionpath.NumberOfTransforms - 1, 1); GLVector3d r1 = OuterFaces[i].GetRawVertex(0); GLVector3d r2 = OuterFaces[i].GetRawVertex(1); GLVector3d r3 = InnerFaces[i].GetRawVertex(0); GLVector3d r4 = InnerFaces[i].GetRawVertex(1); Vector2 t1 = texturemapping.GetTextureCoordinate(new Vector2(r1.x + 0.5, r1.y + 0.5)); Vector2 t2 = texturemapping.GetTextureCoordinate(new Vector2(r2.x + 0.5, r2.y + 0.5)); Vector2 t3 = texturemapping.GetTextureCoordinate(new Vector2(r3.x + 0.5, r3.y + 0.5)); Vector2 t4 = texturemapping.GetTextureCoordinate(new Vector2(r4.x + 0.5, r4.y + 0.5)); GLVector3d normal = CalculateNormal(p1, p2, p3, p4); renderer.SetNormal(normal.x, normal.y, normal.z); renderer.StartTriangle(); renderer.SetTextureCoord(t1.x, t1.y); renderer.AddVertex(p1.x, p1.y, p1.z); renderer.SetTextureCoord(t2.x, t2.y); renderer.AddVertex(p2.x, p2.y, p2.z); renderer.SetTextureCoord(t3.x, t3.y); renderer.AddVertex(p3.x, p3.y, p3.z); renderer.EndTriangle(); renderer.StartTriangle(); renderer.SetTextureCoord(t3.x, t3.y); renderer.AddVertex(p3.x, p3.y, p3.z); renderer.SetTextureCoord(t4.x, t4.y); renderer.AddVertex(p4.x, p4.y, p4.z); renderer.SetTextureCoord(t1.x, t1.y); renderer.AddVertex(p1.x, p1.y, p1.z); renderer.EndTriangle(); } } }
// render a fan, from p1, to avoid having to calculate centre protected override void RenderEndCapNoHollow(bool IsTop) { if (!IsTop) { renderer.SetNormal(0, 0, -1); GLVector3d p0 = rotationalextrusionpath.GetTransformedVertex(new GLVector3d(0, 0, 0), 0); Vector2 t0 = texturemapping.GetTextureCoordinate(new Vector2(0.5, 0.5)); for (int iFacePoint = 0; iFacePoint < iLevelOfDetail; iFacePoint++) { GLVector3d p1 = OuterFaces[0].GetTransformedVertex(rotationalextrusionpath, 0, iFacePoint); GLVector3d p2 = OuterFaces[0].GetTransformedVertex(rotationalextrusionpath, 0, iFacePoint + 1); GLVector3d r1 = OuterFaces[0].GetRawVertex(iFacePoint); GLVector3d r2 = OuterFaces[0].GetRawVertex(iFacePoint + 1); Vector2 t1 = texturemapping.GetTextureCoordinate(new Vector2(1 - (r1.x + 0.5), r1.y + 0.5)); Vector2 t2 = texturemapping.GetTextureCoordinate(new Vector2(1 - (r2.x + 0.5), r2.y + 0.5)); GLVector3d normal = CalculateNormal(p2, p1, p0); renderer.SetNormal(normal.x, normal.y, normal.z); renderer.StartTriangle(); renderer.SetTextureCoord(t2.x, t2.y); renderer.AddVertex(p2.x, p2.y, p2.z); renderer.SetTextureCoord(t1.x, t1.y); renderer.AddVertex(p1.x, p1.y, p1.z); renderer.SetTextureCoord(t0.x, t0.y); renderer.AddVertex(p0.x, p0.y, p0.z); renderer.EndTriangle(); } } else { GLVector3d p0 = rotationalextrusionpath.GetTransformedVertex(new GLVector3d(0, 0, 0), rotationalextrusionpath.NumberOfTransforms - 1); Vector2 t0 = texturemapping.GetTextureCoordinate(new Vector2(0.5, 0.5)); for (int iFacePoint = 1; iFacePoint < iLevelOfDetail - 1; iFacePoint++) { GLVector3d p1 = OuterFaces[0].GetTransformedVertex(rotationalextrusionpath, rotationalextrusionpath.NumberOfTransforms - 1, iFacePoint); GLVector3d p2 = OuterFaces[0].GetTransformedVertex(rotationalextrusionpath, rotationalextrusionpath.NumberOfTransforms - 1, iFacePoint + 1); GLVector3d r1 = OuterFaces[0].GetRawVertex(iFacePoint); GLVector3d r2 = OuterFaces[0].GetRawVertex(iFacePoint + 1); Vector2 t1 = texturemapping.GetTextureCoordinate(new Vector2(r1.x + 0.5, r1.y + 0.5)); Vector2 t2 = texturemapping.GetTextureCoordinate(new Vector2(r2.x + 0.5, r2.y + 0.5)); GLVector3d normal = CalculateNormal(p0, p1, p2); renderer.SetNormal(normal.x, normal.y, normal.z); renderer.StartTriangle(); renderer.SetTextureCoord(t0.x, t0.y); renderer.AddVertex(p0.x, p0.y, p0.z); renderer.SetTextureCoord(t1.x, t1.y); renderer.AddVertex(p1.x, p1.y, p1.z); renderer.SetTextureCoord(t2.x, t2.y); renderer.AddVertex(p2.x, p2.y, p2.z); renderer.EndTriangle(); } } }
protected override void BuildFaces() { if (iCutStart == 0 && iCutEnd == MaxCut) { bShowCut = false; } else { bShowCut = true; } if (iHollow == 0) { bShowHollow = false; } else { bShowHollow = true; } double fHollowRatio = (double)iHollow / 100; int iCutStartDiagQuadrant, iCutEndDiagQuadrant; //!< quadrant 0 is -45 to +45 degrees, quad 2 is +45 to +135, etc iCutStartDiagQuadrant = GetCutQuadrant(iCutStart); iCutEndDiagQuadrant = GetCutQuadrant(iCutEnd - 1); GLVector3d cutstartouterface = GetCutIntersect(iCutStart, 0.5); GLVector3d cutendouterface = GetCutIntersect(iCutEnd, 0.5); GLVector3d cutstartinnerface = null; GLVector3d cutendinnerface = null; if (bShowHollow) { cutstartinnerface = GetCutIntersect(iCutStart, fHollowRatio * 0.5); cutendinnerface = GetCutIntersect(iCutEnd, fHollowRatio * 0.5); } if (bShowCut) { BuildCutFaces(cutstartouterface, cutstartinnerface, cutendouterface, cutendinnerface); } if (iCutStartDiagQuadrant == iCutEndDiagQuadrant) { iFirstOuterFace = iLastOuterFace = iCutStartDiagQuadrant; OuterFaces[0].RemoveAllPoints(); OuterFaces[0].AddPoint(cutstartouterface); OuterFaces[0].AddPoint(cutendouterface); OuterFaces[0].TextureMapping = texturemapping; if (bShowHollow) { InnerFaces[0].RemoveAllPoints(); InnerFaces[0].AddPoint(cutstartinnerface); InnerFaces[0].AddPoint(cutendinnerface); InnerFaces[0].TextureMapping = texturemapping; } } else { iFirstOuterFace = iCutStartDiagQuadrant; double fTotalInnerLength = 0; double fStartSideInnerLength = 0; double fWholeSideLength = 0; double fEndSideInnerLength = 0; PopulateSingleCutFacePositiveDirection(ref OuterFaces[iFirstOuterFace], cutstartouterface, iCutStartDiagQuadrant, 0.5, true); OuterFaces[iFirstOuterFace].TextureMapping = texturemapping; if (bShowHollow) { fStartSideInnerLength = PopulateSingleCutFacePositiveDirection(ref InnerFaces[iFirstOuterFace], cutstartinnerface, iCutStartDiagQuadrant, fHollowRatio * 0.5, false); fTotalInnerLength += fStartSideInnerLength; } int iQuadrant = iCutStartDiagQuadrant + 1; while (iQuadrant < iCutEndDiagQuadrant) { PopulateCompleteSide(ref OuterFaces[iQuadrant], iQuadrant, 0.5, true); OuterFaces[iQuadrant].TextureMapping = texturemapping; if (bShowHollow) { fWholeSideLength = PopulateCompleteSide(ref InnerFaces[iQuadrant], iQuadrant, fHollowRatio * 0.5, false); fTotalInnerLength += fWholeSideLength; } iQuadrant++; } PopulateSingleCutFaceNegativeDirection(ref OuterFaces[iQuadrant], cutendouterface, iCutEndDiagQuadrant, 0.5, true); OuterFaces[iQuadrant].TextureMapping = texturemapping; if (bShowHollow) { fEndSideInnerLength = PopulateSingleCutFaceNegativeDirection(ref InnerFaces[iQuadrant], cutendinnerface, iCutEndDiagQuadrant, fHollowRatio * 0.5, false); fTotalInnerLength += fEndSideInnerLength; } iLastOuterFace = iQuadrant; if (bShowHollow) { SetupInnerFaceTextureOffsets(fStartSideInnerLength, fWholeSideLength, fTotalInnerLength); } } AssignFaces(); }
protected override void RenderEndCapHollow(bool IsTop) { if (!IsTop) { for (int iFacePoint = 0; iFacePoint < iLevelOfDetail; iFacePoint++) { GLVector3d o1 = OuterFaces[0].GetTransformedVertex(rotationalextrusionpath, 0, iFacePoint); GLVector3d o2 = OuterFaces[0].GetTransformedVertex(rotationalextrusionpath, 0, iFacePoint + 1); GLVector3d i1 = InnerFaces[0].GetTransformedVertex(rotationalextrusionpath, 0, iLevelOfDetail - iFacePoint - 1); GLVector3d i2 = InnerFaces[0].GetTransformedVertex(rotationalextrusionpath, 0, iLevelOfDetail - iFacePoint); GLVector3d ro1 = OuterFaces[0].GetRawVertex(iFacePoint); GLVector3d ro2 = OuterFaces[0].GetRawVertex(iFacePoint + 1); GLVector3d ri1 = InnerFaces[0].GetRawVertex(iLevelOfDetail - iFacePoint - 1); GLVector3d ri2 = InnerFaces[0].GetRawVertex(iLevelOfDetail - iFacePoint); Vector2 to1 = texturemapping.GetTextureCoordinate(new Vector2(1 - (ro1.x + 0.5), ro1.y + 0.5)); Vector2 to2 = texturemapping.GetTextureCoordinate(new Vector2(1 - (ro2.x + 0.5), ro2.y + 0.5)); Vector2 ti1 = texturemapping.GetTextureCoordinate(new Vector2(1 - (ri1.x + 0.5), ri1.y + 0.5)); Vector2 ti2 = texturemapping.GetTextureCoordinate(new Vector2(1 - (ri2.x + 0.5), ri2.y + 0.5)); GLVector3d normal = CalculateNormal(i2, i1, o2, o1); renderer.SetNormal(normal.x, normal.y, normal.z); renderer.StartTriangle(); renderer.SetTextureCoord(to1.x, to1.y); renderer.AddVertex(o1.x, o1.y, o1.z); renderer.SetTextureCoord(ti2.x, ti2.y); renderer.AddVertex(i2.x, i2.y, i2.z); renderer.SetTextureCoord(ti1.x, ti1.y); renderer.AddVertex(i1.x, i1.y, i1.z); renderer.EndTriangle(); renderer.StartTriangle(); renderer.SetTextureCoord(ti1.x, ti1.y); renderer.AddVertex(i1.x, i1.y, i1.z); renderer.SetTextureCoord(to2.x, to2.y); renderer.AddVertex(o2.x, o2.y, o2.z); renderer.SetTextureCoord(to1.x, to1.y); renderer.AddVertex(o1.x, o1.y, o1.z); renderer.EndTriangle(); } } else { for (int iFacePoint = 0; iFacePoint < iLevelOfDetail; iFacePoint++) { GLVector3d o1 = OuterFaces[0].GetTransformedVertex(rotationalextrusionpath, rotationalextrusionpath.NumberOfTransforms - 1, iFacePoint); GLVector3d o2 = OuterFaces[0].GetTransformedVertex(rotationalextrusionpath, rotationalextrusionpath.NumberOfTransforms - 1, iFacePoint + 1); GLVector3d i1 = InnerFaces[0].GetTransformedVertex(rotationalextrusionpath, rotationalextrusionpath.NumberOfTransforms - 1, iLevelOfDetail - iFacePoint - 1); GLVector3d i2 = InnerFaces[0].GetTransformedVertex(rotationalextrusionpath, rotationalextrusionpath.NumberOfTransforms - 1, iLevelOfDetail - iFacePoint); GLVector3d ro1 = OuterFaces[0].GetRawVertex(iFacePoint); GLVector3d ro2 = OuterFaces[0].GetRawVertex(iFacePoint + 1); GLVector3d ri1 = InnerFaces[0].GetRawVertex(iLevelOfDetail - iFacePoint - 1); GLVector3d ri2 = InnerFaces[0].GetRawVertex(iLevelOfDetail - iFacePoint); Vector2 to1 = texturemapping.GetTextureCoordinate(new Vector2(ro1.x + 0.5, ro1.y + 0.5)); Vector2 to2 = texturemapping.GetTextureCoordinate(new Vector2(ro2.x + 0.5, ro2.y + 0.5)); Vector2 ti1 = texturemapping.GetTextureCoordinate(new Vector2(ri1.x + 0.5, ri1.y + 0.5)); Vector2 ti2 = texturemapping.GetTextureCoordinate(new Vector2(ri2.x + 0.5, ri2.y + 0.5)); GLVector3d normal = CalculateNormal(o1, o2, i1, i2); renderer.SetNormal(normal.x, normal.y, normal.z); renderer.StartTriangle(); renderer.SetTextureCoord(to1.x, to1.y); renderer.AddVertex(o1.x, o1.y, o1.z); renderer.SetTextureCoord(to2.x, to2.y); renderer.AddVertex(o2.x, o2.y, o2.z); renderer.SetTextureCoord(ti1.x, ti1.y); renderer.AddVertex(i1.x, i1.y, i1.z); renderer.EndTriangle(); renderer.StartTriangle(); renderer.SetTextureCoord(to1.x, to1.y); renderer.AddVertex(o1.x, o1.y, o1.z); renderer.SetTextureCoord(ti1.x, ti1.y); renderer.AddVertex(i1.x, i1.y, i1.z); renderer.SetTextureCoord(ti2.x, ti2.y); renderer.AddVertex(i2.x, i2.y, i2.z); renderer.EndTriangle(); } } }