add option to set phase of rotation in Render Cylinder
This commit is contained in:
parent
572d5438ed
commit
4ad63ac725
1 changed files with 10 additions and 8 deletions
|
|
@ -43,17 +43,19 @@ namespace MatterHackers.MeshVisualizer
|
|||
world.RenderCylinderOutline(worldMatrix, center, diameter, height, sides, color, color, lineWidth, extendLineLength);
|
||||
}
|
||||
|
||||
public static void RenderCylinderOutline(this WorldView world, Matrix4X4 worldMatrix, Vector3 center, double diameter, double height, int sides, Color color1, Color color2, double lineWidth = 1, double extendLineLength = 0)
|
||||
public static void RenderCylinderOutline(this WorldView world, Matrix4X4 worldMatrix, Vector3 center, double diameter, double height, int sides, Color topBottomRingColor, Color sideLinesColor, double lineWidth = 1, double extendLineLength = 0, double phase = 0)
|
||||
{
|
||||
GLHelper.PrepareFor3DLineRender(true);
|
||||
Frustum frustum = world.GetClippingFrustum();
|
||||
|
||||
for (int i = 0; i < sides; i++)
|
||||
{
|
||||
var rotatedPoint = new Vector3(Math.Cos(MathHelper.Tau * i / sides), Math.Sin(MathHelper.Tau * i / sides), 0) * diameter / 2;
|
||||
var startAngle = MathHelper.Tau * i / sides + phase;
|
||||
var rotatedPoint = new Vector3(Math.Cos(startAngle), Math.Sin(startAngle), 0) * diameter / 2;
|
||||
var sideTop = Vector3Ex.Transform(center + rotatedPoint + new Vector3(0, 0, height / 2), worldMatrix);
|
||||
var sideBottom = Vector3Ex.Transform(center + rotatedPoint + new Vector3(0, 0, -height / 2), worldMatrix);
|
||||
var rotated2Point = new Vector3(Math.Cos(MathHelper.Tau * (i + 1) / sides), Math.Sin(MathHelper.Tau * (i + 1) / sides), 0) * diameter / 2;
|
||||
var endAngle = MathHelper.Tau * (i + 1) / sides + phase;
|
||||
var rotated2Point = new Vector3(Math.Cos(endAngle), Math.Sin(endAngle), 0) * diameter / 2;
|
||||
var topStart = sideTop;
|
||||
var topEnd = Vector3Ex.Transform(center + rotated2Point + new Vector3(0, 0, height / 2), worldMatrix);
|
||||
var bottomStart = sideBottom;
|
||||
|
|
@ -64,15 +66,15 @@ namespace MatterHackers.MeshVisualizer
|
|||
GLHelper.ExtendLineEnds(ref sideTop, ref sideBottom, extendLineLength);
|
||||
}
|
||||
|
||||
if (color2 != Color.Transparent)
|
||||
if (sideLinesColor != Color.Transparent)
|
||||
{
|
||||
world.Render3DLineNoPrep(frustum, sideTop, sideBottom, color2, lineWidth);
|
||||
world.Render3DLineNoPrep(frustum, sideTop, sideBottom, sideLinesColor, lineWidth);
|
||||
}
|
||||
|
||||
if (color1 != Color.Transparent)
|
||||
if (topBottomRingColor != Color.Transparent)
|
||||
{
|
||||
world.Render3DLineNoPrep(frustum, topStart, topEnd, color1, lineWidth);
|
||||
world.Render3DLineNoPrep(frustum, bottomStart, bottomEnd, color1, lineWidth);
|
||||
world.Render3DLineNoPrep(frustum, topStart, topEnd, topBottomRingColor, lineWidth);
|
||||
world.Render3DLineNoPrep(frustum, bottomStart, bottomEnd, topBottomRingColor, lineWidth);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue