Exemple #1
0
 /// <summary>
 /// Clamp a vector to the given minimum and maximum vectors
 /// </summary>
 /// <param name="vec">Input vector</param>
 /// <param name="min">Minimum vector</param>
 /// <param name="max">Maximum vector</param>
 /// <returns>The clamped vector</returns>
 public static Vector3Float Clamp(Vector3Float vec, Vector3Float min, Vector3Float max)
 {
     vec.X = vec.X <min.X?min.X : vec.X> max.X ? max.X : vec.X;
     vec.Y = vec.Y <min.Y?min.Y : vec.Y> max.Y ? max.Y : vec.Y;
     vec.Z = vec.Z <min.Z?min.Z : vec.Z> max.Z ? max.Z : vec.Z;
     return(vec);
 }
 public RenderFeatureRetract(Vector3 position, double extrusionAmount, int extruderIndex, double mmPerSecond)
     : base(extruderIndex)
 {
     this.extrusionAmount = (float)extrusionAmount;
     this.mmPerSecond     = (float)mmPerSecond;
     this.position        = new Vector3Float(position);
 }
Exemple #3
0
 /// <summary>Transform a direction vector by the given Matrix
 /// Assumes the matrix has a bottom row of (0,0,0,1), that is the translation part is ignored.
 /// </summary>
 /// <param name="vec">The vector to transform</param>
 /// <param name="mat">The desired transformation</param>
 /// <returns>The transformed vector</returns>
 public static Vector3Float TransformVector(this Vector3Float vec, Matrix4X4 mat)
 {
     return(new Vector3Float(
                vec.Dot(new Vector3Float(mat.Column0)),
                vec.Dot(new Vector3Float(mat.Column1)),
                vec.Dot(new Vector3Float(mat.Column2))));
 }
		public RenderFeatureRetract(Vector3 position, double extrusionAmount, int extruderIndex, double mmPerSecond)
			: base(extruderIndex)
		{
			this.extrusionAmount = (float)extrusionAmount;
			this.mmPerSecond = (float)mmPerSecond;
			this.position = new Vector3Float(position);
		}
Exemple #5
0
        /// <summary>Calculates the angle (in radians) between two vectors.</summary>
        /// <param name="first">The first vector.</param>
        /// <param name="second">The second vector.</param>
        /// <param name="result">Angle (in radians) between the vectors.</param>
        /// <remarks>Note that the returned angle is never bigger than the constant Pi.</remarks>
        public static void CalculateAngle(this Vector3Float first, ref Vector3Float second, out float result)
        {
            float temp;

            first.Dot(ref second, out temp);
            result = (float)Math.Acos(temp / (first.Length * second.Length));
        }
Exemple #6
0
        /// <summary>Transform a Vector by the given Matrix</summary>
        /// <param name="vec">The vector to transform</param>
        /// <param name="mat">The desired transformation</param>
        /// <returns>The transformed vector</returns>
        public static Vector3Float Transform(this Vector3Float vec, Matrix4X4 mat)
        {
            Vector3Float result;

            Transform(vec, ref mat, out result);
            return(result);
        }
Exemple #7
0
        private Func <int, int, Vector3Float> vertexFunc; // 64 bits

        public MinimalTriangle(Func <int, int, Vector3Float> vertexFunc, int faceIndex)
        {
            this.FaceIndex  = faceIndex;
            this.vertexFunc = vertexFunc;
            var    planeNormal        = (vertex(1) - vertex(0)).Cross(vertex(2) - vertex(0)).GetNormal();
            double distanceFromOrigin = vertex(0).Dot(planeNormal);

            Plane = new PlaneFloat(new Vector3Float(planeNormal), (float)distanceFromOrigin);

            center = new Vector3Float((vertex(0) + vertex(1) + vertex(2)) / 3);
            var aabbMinXYZ = vertex(0).ComponentMin(vertex(1)).ComponentMin(vertex(2));
            var aabbMaxXYZ = vertex(0).ComponentMax(vertex(1)).ComponentMax(vertex(2));
            var aabb       = new AxisAlignedBoundingBox(aabbMinXYZ, aabbMaxXYZ);

            aabbSize = new Vector3Float(aabb.Size);

            var normalLengths = new[] { Math.Abs(planeNormal.X), Math.Abs(planeNormal.Y), Math.Abs(planeNormal.Z) };

            MajorAxis = (byte)normalLengths.Select((v, i) => new { Axis = i, Value = Math.Abs(v) }).OrderBy(o => o.Value).Last().Axis;

            for (int i = 0; i < 3; i++)
            {
                boundsOnMajorAxis.Left   = Math.Min(vertex(i)[xForMajorAxis], boundsOnMajorAxis.Left);
                boundsOnMajorAxis.Right  = Math.Max(vertex(i)[xForMajorAxis], boundsOnMajorAxis.Right);
                boundsOnMajorAxis.Bottom = Math.Min(vertex(i)[yForMajorAxis], boundsOnMajorAxis.Bottom);
                boundsOnMajorAxis.Top    = Math.Max(vertex(i)[yForMajorAxis], boundsOnMajorAxis.Top);
            }
        }
    internal void Set(int x, int y, int z, float value)
    {
        int index = ItemIndex(x, y, z);

        if (index != -1)
        {
            items[index].value = value;
        }
        else
        {
            for (int i = 0; i < itemsCount; i++)
            {
                if (items[i] == null)
                {
                    Vector3Float item = new Vector3Float();
                    item.x     = x;
                    item.y     = y;
                    item.z     = z;
                    item.value = value;
                    items[i]   = item;
                    return;
                }
            }
        }
    }
Exemple #9
0
        public override void CreateRender3DData(VectorPOD <ColorVertexData> colorVertexData, VectorPOD <int> indexData, GCodeRenderInfo renderInfo)
        {
            if ((renderInfo.CurrentRenderType & RenderType.Extrusions) == RenderType.Extrusions)
            {
                Vector3Float start  = this.GetStart(renderInfo);
                Vector3Float end    = this.GetEnd(renderInfo);
                double       radius = GetRadius(renderInfo.CurrentRenderType);

                Color lineColor;

                if (renderInfo.CurrentRenderType.HasFlag(RenderType.SpeedColors))
                {
                    lineColor = color;
                }
                else if (renderInfo.CurrentRenderType.HasFlag(RenderType.GrayColors))
                {
                    lineColor = ActiveTheme.Instance.IsDarkTheme ? Color.DarkGray : Color.Gray;
                }
                else
                {
                    lineColor = renderInfo.GetMaterialColor(extruderIndex);
                }

                CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), radius, 6, lineColor, layerHeight);
            }
        }
Exemple #10
0
        public TriangleShape(Vector3 vertex0, Vector3 vertex1, Vector3 vertex2, MaterialAbstract material)
        {
            Vector3 planeNormal        = Vector3Ex.Cross(vertex1 - vertex0, vertex2 - vertex0).GetNormal();
            double  distanceFromOrigin = Vector3Ex.Dot(vertex0, planeNormal);

            Plane       = new PlaneFloat(new Vector3Float(planeNormal), (float)distanceFromOrigin);
            Material    = material;
            vertices[0] = new Vector3Float(vertex0);
            vertices[1] = new Vector3Float(vertex1);
            vertices[2] = new Vector3Float(vertex2);

            center = new Vector3Float((vertex0 + vertex1 + vertex2) / 3);

            var normalLengths = new [] { Math.Abs(planeNormal.X), Math.Abs(planeNormal.Y), Math.Abs(planeNormal.Z) };

            MajorAxis = (byte)normalLengths.Select((v, i) => new { Axis = i, Value = Math.Abs(v) }).OrderBy(o => o.Value).Last().Axis;

            for (int i = 0; i < 3; i++)
            {
                boundsOnMajorAxis.Left   = Math.Min(vertices[i][xForMajorAxis], boundsOnMajorAxis.Left);
                boundsOnMajorAxis.Right  = Math.Max(vertices[i][xForMajorAxis], boundsOnMajorAxis.Right);
                boundsOnMajorAxis.Bottom = Math.Min(vertices[i][yForMajorAxis], boundsOnMajorAxis.Bottom);
                boundsOnMajorAxis.Top    = Math.Max(vertices[i][yForMajorAxis], boundsOnMajorAxis.Top);
            }

            aabbMinXYZ = vertices[0].ComponentMin(vertices[1]).ComponentMin(vertices[2]);
            aabbMaxXYZ = vertices[0].ComponentMax(vertices[1]).ComponentMax(vertices[2]);
        }
Exemple #11
0
        /// <summary>
        /// Calculate the cross (vector) product of two vectors
        /// </summary>
        /// <param name="left">First operand</param>
        /// <param name="right">Second operand</param>
        /// <returns>The cross product of the two inputs</returns>
        public static Vector3Float Cross(this Vector3Float left, Vector3Float right)
        {
            Vector3Float result;

            left.Cross(ref right, out result);
            return(result);
        }
Exemple #12
0
        public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo)
        {
            if ((renderInfo.CurrentRenderType & RenderType.Retractions) == RenderType.Retractions)
            {
                double  radius   = Radius(renderInfo.LayerScale);
                Vector2 position = new Vector2(this.position.x, this.position.y);

                if (renderInfo.CurrentRenderType.HasFlag(RenderType.HideExtruderOffsets))
                {
                    Vector2 offset = renderInfo.GetExtruderOffset(extruderIndex);
                    position = position + offset;
                }

                renderInfo.Transform.transform(ref position);

                Color retractionColor = new Color(Color.Red, 200);
                if (extrusionAmount > 0)
                {
                    // unretraction
                    retractionColor = new Color(Color.Blue, 200);
                }

                // render the part using opengl
                if (graphics2D is Graphics2DOpenGL graphics2DGl)
                {
                    graphics2DGl.DrawAACircle(position, radius, retractionColor);
                }
                else
                {
                    Ellipse extrusion = new Ellipse(position, radius);
                    graphics2D.Render(extrusion, retractionColor);
                }
            }
        }
        public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo)
        {
            if ((renderInfo.CurrentRenderType & RenderType.Moves) == RenderType.Moves)
            {
                double     movementLineWidth = 0.35 * renderInfo.LayerScale;
                RGBA_Bytes movementColor     = new RGBA_Bytes(10, 190, 15);

                PathStorage pathStorage = new PathStorage();
                VertexSourceApplyTransform transformedPathStorage = new VertexSourceApplyTransform(pathStorage, renderInfo.Transform);
                Stroke stroke = new Stroke(transformedPathStorage, movementLineWidth);

                stroke.line_cap(LineCap.Round);
                stroke.line_join(LineJoin.Round);

                Vector3Float start = this.GetStart(renderInfo);
                Vector3Float end   = this.GetEnd(renderInfo);

                pathStorage.Add(start.x, start.y, ShapePath.FlagsAndCommand.CommandMoveTo);
                if (end.x != start.x || end.y != start.y)
                {
                    pathStorage.Add(end.x, end.y, ShapePath.FlagsAndCommand.CommandLineTo);
                }
                else
                {
                    pathStorage.Add(end.x + .01, end.y, ShapePath.FlagsAndCommand.CommandLineTo);
                }
                graphics2D.Render(stroke, 0, movementColor);
            }
        }
Exemple #14
0
 /// <summary>
 /// Returns a new Vector that is the linear blend of the 2 given Vectors
 /// </summary>
 /// <param name="a">First input vector</param>
 /// <param name="b">Second input vector</param>
 /// <param name="blend">The blend factor. a when blend=0, b when blend=1.</param>
 /// <returns>a when blend=0, b when blend=1, and a linear combination otherwise</returns>
 public static Vector3Float Lerp(Vector3Float a, Vector3Float b, float blend)
 {
     a.X = blend * (b.X - a.X) + a.X;
     a.Y = blend * (b.Y - a.Y) + a.Y;
     a.Z = blend * (b.Z - a.Z) + a.Z;
     return(a);
 }
Exemple #15
0
        public bool RayHitPlane(Ray ray, out float distanceToHit, out bool hitFrontOfPlane)
        {
            distanceToHit   = float.PositiveInfinity;
            hitFrontOfPlane = false;

            float normalDotRayDirection = Vector3Float.Dot(Normal, new Vector3Float(ray.directionNormal));

            if (normalDotRayDirection < TreatAsZero && normalDotRayDirection > -TreatAsZero)             // the ray is parallel to the plane
            {
                return(false);
            }

            if (normalDotRayDirection < 0)
            {
                hitFrontOfPlane = true;
            }

            float distanceToRayOriginFromOrigin = Vector3Float.Dot(Normal, new Vector3Float(ray.origin));

            float distanceToPlaneFromRayOrigin = DistanceFromOrigin - distanceToRayOriginFromOrigin;

            bool originInFrontOfPlane = distanceToPlaneFromRayOrigin < 0;

            bool originAndHitAreOnSameSide = originInFrontOfPlane == hitFrontOfPlane;

            if (!originAndHitAreOnSameSide)
            {
                return(false);
            }

            distanceToHit = distanceToPlaneFromRayOrigin / normalDotRayDirection;
            return(true);
        }
        public void Draw(GuiWidget sender, IObject3D item, bool isSelected, DrawEventArgs e, Matrix4X4 itemMaxtrix, WorldView world)
        {
            if (!isSelected ||
                item.Mesh?.Faces.Count <= 0)
            {
                return;
            }

            var frustum = world.GetClippingFrustum();

            var mesh = item.Mesh;

            foreach (var face in mesh.Faces)
            {
                int          vertexCount = 0;
                Vector3Float faceCenter  = Vector3Float.Zero;
                foreach (var v in new[] { face.v0, face.v1, face.v2 })
                {
                    var vertex = mesh.Vertices[v];

                    faceCenter += vertex;
                    vertexCount++;
                }

                faceCenter /= vertexCount;

                var matrix = item.WorldMatrix();

                var transformed1 = faceCenter.Transform(matrix);
                var normal       = face.normal.TransformNormal(matrix).GetNormal();

                world.Render3DLineNoPrep(frustum, transformed1, transformed1 + normal, Color.Red, 2);
            }
        }
        /// <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
            var verticesArray = new Vector3Float[vertices.Count];

            for (int i = 0; i < vertices.Count; i++)
            {
                verticesArray[i] = new Vector3Float(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));
        }
        public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo)
        {
            if ((renderInfo.CurrentRenderType & RenderType.Extrusions) == RenderType.Extrusions)
            {
                double extrusionLineWidths = GetRadius(renderInfo.CurrentRenderType) * 2 * renderInfo.LayerScale;

                RGBA_Bytes extrusionColor = RGBA_Bytes.Black;
                if (extruderIndex > 0)
                {
                    extrusionColor = MeshViewerWidget.GetMaterialColor(extruderIndex + 1);
                }
                if ((renderInfo.CurrentRenderType & RenderType.SpeedColors) == RenderType.SpeedColors)
                {
                    extrusionColor = color;
                }

                PathStorage pathStorage = new PathStorage();
                VertexSourceApplyTransform transformedPathStorage = new VertexSourceApplyTransform(pathStorage, renderInfo.Transform);
                Stroke stroke = new Stroke(transformedPathStorage, extrusionLineWidths);

                stroke.line_cap(LineCap.Round);
                stroke.line_join(LineJoin.Round);

                Vector3Float start = this.GetStart(renderInfo);
                Vector3Float end   = this.GetEnd(renderInfo);

                pathStorage.Add(start.x, start.y, ShapePath.FlagsAndCommand.CommandMoveTo);
                pathStorage.Add(end.x, end.y, ShapePath.FlagsAndCommand.CommandLineTo);

                graphics2D.Render(stroke, 0, extrusionColor);
            }
        }
Exemple #19
0
 /// <summary>
 /// Calculate the component-wise maximum of two vectors
 /// </summary>
 /// <param name="a">First operand</param>
 /// <param name="b">Second operand</param>
 /// <returns>The component-wise maximum</returns>
 public static Vector3Float ComponentMax(this Vector3Float a, Vector3Float b)
 {
     a.X = a.X > b.X ? a.X : b.X;
     a.Y = a.Y > b.Y ? a.Y : b.Y;
     a.Z = a.Z > b.Z ? a.Z : b.Z;
     return(a);
 }
Exemple #20
0
 /// <summary>Transform a Normal by the (transpose of the) given Matrix</summary>
 /// <remarks>
 /// This version doesn't calculate the inverse matrix.
 /// Use this version if you already have the inverse of the desired transform to hand
 /// </remarks>
 /// <param name="norm">The normal to transform</param>
 /// <param name="invMat">The inverse of the desired transformation</param>
 /// <returns>The transformed normal</returns>
 public static Vector3Float TransformNormalInverse(this Vector3Float norm, Matrix4X4 invMat)
 {
     return(new Vector3Float(
                norm.Dot(new Vector3Float(invMat.Row0)),
                norm.Dot(new Vector3Float(invMat.Row1)),
                norm.Dot(new Vector3Float(invMat.Row2))));
 }
Exemple #21
0
        public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo)
        {
            if (renderInfo.CurrentRenderType.HasFlag(RenderType.Extrusions))
            {
                double extrusionLineWidths = GetExtrusionWidth(renderInfo.CurrentRenderType) * 2 * renderInfo.LayerScale;

                Color extrusionColor = Color.Black;

                if (renderInfo.CurrentRenderType.HasFlag(RenderType.SpeedColors))
                {
                    extrusionColor = color;
                }
                else if (renderInfo.CurrentRenderType.HasFlag(RenderType.GrayColors))
                {
                    extrusionColor = Color.Gray;
                }
                else
                {
                    extrusionColor = renderInfo.GetMaterialColor(extruderIndex);
                }

                if (renderInfo.CurrentRenderType.HasFlag(RenderType.TransparentExtrusion))
                {
                    extrusionColor = new Color(extrusionColor, 200);
                }

                // render the part using opengl
                Graphics2DOpenGL graphics2DGl = graphics2D as Graphics2DOpenGL;
                if (graphics2DGl != null)
                {
                    Vector3Float startF = this.GetStart(renderInfo);
                    Vector3Float endF   = this.GetEnd(renderInfo);
                    Vector2      start  = new Vector2(startF.x, startF.y);
                    renderInfo.Transform.transform(ref start);

                    Vector2 end = new Vector2(endF.x, endF.y);
                    renderInfo.Transform.transform(ref end);

                    graphics2DGl.DrawAALineRounded(start, end, extrusionLineWidths / 2, extrusionColor);
                }
                else
                {
                    VertexStorage pathStorage = new VertexStorage();
                    VertexSourceApplyTransform transformedPathStorage = new VertexSourceApplyTransform(pathStorage, renderInfo.Transform);
                    Stroke stroke = new Stroke(transformedPathStorage, extrusionLineWidths / 2);

                    stroke.line_cap(LineCap.Round);
                    stroke.line_join(LineJoin.Round);

                    Vector3Float start = this.GetStart(renderInfo);
                    Vector3Float end   = this.GetEnd(renderInfo);

                    pathStorage.Add(start.x, start.y, ShapePath.FlagsAndCommand.MoveTo);
                    pathStorage.Add(end.x, end.y, ShapePath.FlagsAndCommand.LineTo);

                    graphics2D.Render(stroke, 0, extrusionColor);
                }
            }
        }
 public RenderFeatureTravel(int instructionIndex, Vector3 start, Vector3 end, int toolIndex, double travelSpeed)
     : base(instructionIndex, toolIndex)
 {
     this.toolIndex   = toolIndex;
     this.start       = new Vector3Float(start);
     this.end         = new Vector3Float(end);
     this.travelSpeed = (float)travelSpeed;
 }
Exemple #23
0
 public RenderFeatureTravel(Vector3 start, Vector3 end, int extruderIndex, double travelSpeed)
     : base(extruderIndex)
 {
     this.extruderIndex = extruderIndex;
     this.start         = new Vector3Float(start);
     this.end           = new Vector3Float(end);
     this.travelSpeed   = (float)travelSpeed;
 }
Exemple #24
0
        public Face(int v0, int v1, int v2, Vector3Float normal)
        {
            this.v0 = v0;
            this.v1 = v1;
            this.v2 = v2;

            this.normal = normal;
        }
Exemple #25
0
        /// <summary>
        /// Scale a vector to unit length
        /// </summary>
        /// <param name="vec">The input vector</param>
        /// <param name="result">The normalized vector</param>
        public static void Normalize(ref Vector3Float vec, out Vector3Float result)
        {
            float scale = 1.0f / vec.Length;

            result.X = vec.X * scale;
            result.Y = vec.Y * scale;
            result.Z = vec.Z * scale;
        }
		public RenderFeatureTravel(Vector3 start, Vector3 end, int extruderIndex, double travelSpeed)
			: base(extruderIndex)
		{
			this.extruderIndex = extruderIndex;
			this.start = new Vector3Float(start);
			this.end = new Vector3Float(end);
			this.travelSpeed = (float)travelSpeed;
		}
Exemple #27
0
        /// <summary>Transform a Vector by the given Matrix</summary>
        /// <param name="vec">The vector to transform</param>
        /// <param name="mat">The desired transformation</param>
        /// <param name="result">The transformed vector</param>
        public static void Transform(this Vector3Float inVec, ref Matrix4X4 mat, out Vector3Float result)
        {
            Vector3 vec = new Vector3(inVec);
            Vector4 v4  = new Vector4(vec.X, vec.Y, vec.Z, 1.0);

            Vector4.Transform(v4, ref mat, out v4);
            result = new Vector3Float(v4.Xyz);
        }
Exemple #28
0
 public TriangleShapeUv(Vector3Float vertex0, Vector3Float vertex1, Vector3Float vertex2,
                        Vector2Float uv0, Vector2Float uv1, Vector2Float uv2,
                        MaterialAbstract material)
     : base(vertex0.AsVector3(), vertex1.AsVector3(), vertex2.AsVector3(), material)
 {
     this.uv0 = uv0;
     this.uv1 = uv1;
     this.uv2 = uv2;
 }
Exemple #29
0
 public override void CreateRender3DData(VectorPOD <ColorVertexData> colorVertexData, VectorPOD <int> indexData, GCodeRenderInfo renderInfo)
 {
     if ((renderInfo.CurrentRenderType & RenderType.Moves) == RenderType.Moves)
     {
         Vector3Float start = this.GetStart(renderInfo);
         Vector3Float end   = this.GetEnd(renderInfo);
         CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), .1, 6, GCodeRenderer.TravelColor, .2);
     }
 }
Exemple #30
0
        /// <summary>
        /// Scale a vector to unit length
        /// </summary>
        /// <param name="vec">The input vector</param>
        /// <returns>The normalized vector</returns>
        public static Vector3Float Normalize(Vector3Float vec)
        {
            float scale = 1.0f / vec.Length;

            vec.X *= scale;
            vec.Y *= scale;
            vec.Z *= scale;
            return(vec);
        }
Exemple #31
0
        public void CalculateNormal(List <Vector3Float> vertices)
        {
            var position0  = vertices[this.v0];
            var position1  = vertices[this.v1];
            var position2  = vertices[this.v2];
            var v11MinusV0 = position1 - position0;
            var v2MinusV0  = position2 - position0;

            normal = v11MinusV0.Cross(v2MinusV0).GetNormal();
        }
Exemple #32
0
 public PrinterMachineInstruction(string Line, PrinterMachineInstruction copy, bool clientInsertion = false)
     : this(Line)
 {
     xyzPosition          = copy.xyzPosition;
     FeedRate             = copy.FeedRate;
     EPosition            = copy.EPosition;
     MovementType         = copy.MovementType;
     SecondsToEndFromHere = copy.SecondsToEndFromHere;
     ToolIndex            = copy.ToolIndex;
 }
Exemple #33
0
		public float GetDistanceToIntersection(Vector3Float pointOnLine, Vector3Float lineDirection)
		{
			float normalDotRayDirection = Vector3Float.Dot(planeNormal, lineDirection);
			if (normalDotRayDirection < TreatAsZero && normalDotRayDirection > -TreatAsZero) // the ray is parallel to the plane
			{
				return float.PositiveInfinity;
			}

			float planeNormalDotPointOnLine = Vector3Float.Dot(planeNormal, pointOnLine);
			return (distanceToPlaneFromOrigin - planeNormalDotPointOnLine) / normalDotRayDirection;
		}
		public PrinterMachineInstruction(string Line, PrinterMachineInstruction copy, bool clientInsertion = false)
			: this(Line)
		{
			xyzPosition = copy.xyzPosition;
			feedRate = copy.feedRate;
			ePosition = copy.ePosition;
			movementType = copy.movementType;
			secondsToEndFromHere = copy.secondsToEndFromHere;
			ExtruderIndex = copy.ExtruderIndex;
			this.clientInsertion = clientInsertion;
		}
Exemple #35
0
		public TriangleShape(Vector3 vertex0, Vector3 vertex1, Vector3 vertex2, MaterialAbstract material)
		{
			Vector3 planeNormal = Vector3.Cross(vertex1 - vertex0, vertex2 - vertex0).GetNormal();
			double distanceFromOrigin = Vector3.Dot(vertex0, planeNormal);
			plane = new PlaneFloat(new Vector3Float(planeNormal), (float)distanceFromOrigin);
			Material = material;
			vertices[0] = new Vector3Float(vertex0);
			vertices[1] = new Vector3Float(vertex1);
			vertices[2] = new Vector3Float(vertex2);
			center = new Vector3Float((vertex0 + vertex1 + vertex2) / 3);
			if (Math.Abs(planeNormal.x) > Math.Abs(planeNormal.y))
			{
				if (Math.Abs(planeNormal.x) > Math.Abs(planeNormal.z))
				{
					// mostly facing x axis
					majorAxis = 0;
				}
				else if (Math.Abs(planeNormal.y) > Math.Abs(planeNormal.z))
				{
					// mostly facing z
					majorAxis = 2;
				}
			}
			else if (Math.Abs(planeNormal.y) > Math.Abs(planeNormal.z))
			{
				// mostly facing y
				majorAxis = 1;
			}
			else
			{
				// mostly facing z
				majorAxis = 2;
			}
			for (int i = 0; i < 3; i++)
			{
				boundsOnMajorAxis.Left = Math.Min(vertices[i][xForMajorAxis], boundsOnMajorAxis.Left);
				boundsOnMajorAxis.Right = Math.Max(vertices[i][xForMajorAxis], boundsOnMajorAxis.Right);
				boundsOnMajorAxis.Bottom = Math.Min(vertices[i][yForMajorAxis], boundsOnMajorAxis.Bottom);
				boundsOnMajorAxis.Top = Math.Max(vertices[i][yForMajorAxis], boundsOnMajorAxis.Top);
			}
		}
Exemple #36
0
		public override AxisAlignedBoundingBox GetAxisAlignedBoundingBox()
		{
			if (aabbMinXYZ.x == double.NegativeInfinity)
			{
				aabbMinXYZ = Vector3Float.ComponentMin(Vector3Float.ComponentMin(vertices[0], vertices[1]), vertices[2]);
				aabbMaxXYZ = Vector3Float.ComponentMax(Vector3Float.ComponentMax(vertices[0], vertices[1]), vertices[2]);
			}

			return new AxisAlignedBoundingBox(new Vector3(aabbMinXYZ), new Vector3(aabbMaxXYZ));
		}
Exemple #37
0
		public PlaneFloat(Vector3Float planeNormal, float distanceFromOrigin)
		{
			this.planeNormal = planeNormal.GetNormal();
			this.distanceToPlaneFromOrigin = distanceFromOrigin;
		}
Exemple #38
0
		public PlaneFloat(Vector3Float point0, Vector3Float point1, Vector3Float point2)
		{
			this.planeNormal = Vector3Float.Cross((point1 - point0), (point2 - point0)).GetNormal();
			this.distanceToPlaneFromOrigin = Vector3Float.Dot(planeNormal, point0);
		}
 internal void Set(int x, int y, int z, float value)
 {
     int index = ItemIndex(x, y, z);
     if (index != -1)
     {
         items[index].value = value;
     }
     else
     {
         for (int i = 0; i < itemsCount; i++)
         {
             if (items[i] == null)
             {
                 Vector3Float item = new Vector3Float();
                 item.x = x;
                 item.y = y;
                 item.z = z;
                 item.value = value;
                 items[i] = item;
                 return;
             }
         }
     }
 }
Exemple #40
0
		public float GetDistanceFromPlane(Vector3Float positionToCheck)
		{
			float distanceToPointFromOrigin = Vector3Float.Dot(positionToCheck, planeNormal);
			return distanceToPointFromOrigin - distanceToPlaneFromOrigin;
		}
Exemple #41
0
 public RenderFeatureTravel(Vector3 start, Vector3 end, double travelSpeed)
 {
     this.start = new Vector3Float(start);
     this.end = new Vector3Float(end);
     this.travelSpeed = (float)travelSpeed;
 }
		private List<Vector3Float> FindWithinDist(List<Vector3Float> positions, Vector3Float position, double distance)
		{
			List<Vector3Float> found = new List<Vector3Float>();
			for (int i = 0; i < positions.Count; i++)
			{
				if ((positions[i] - position).Length <= distance)
				{
					found.Add(positions[i]);
				}
			}
			return found;
		}
Exemple #43
0
		public override RGBA_Floats GetColor(IntersectInfo info)
		{
			if (Material.HasTexture)
			{
				Vector3Float Position = plane.planeNormal;
				Vector3Float vecU = new Vector3Float(Position.y, Position.z, -Position.x);
				Vector3Float vecV = Vector3Float.Cross(vecU, plane.planeNormal);

				double u = Vector3Float.Dot(new Vector3Float(info.hitPosition), vecU);
				double v = Vector3Float.Dot(new Vector3Float(info.hitPosition), vecV);
				return Material.GetColor(u, v);
			}
			else
			{
				return Material.GetColor(0, 0);
			}
		}