Exemple #1
0
        private static Position3D GetPosition(Axis3D moveRay, Plane3D axisPlane)
        {
            var(success, position) = axisPlane.Intersect(moveRay);
            var result = success ? position : moveRay.Offset;

            return(result);
        }
        public static Matrix RotateAroundAxisAtPoint(Axis3D axis, HomogeneousPoint3D point, double angle)
        {
            var    returnPoint       = new HomogeneousPoint3D(-point.X, -point.Y, -point.Z, point.W);
            Matrix moveOriginToPoint = MoveOriginTo(point);
            Matrix rotationMatrix;
            Matrix returnOrigin = MoveOriginTo(returnPoint);

            switch (axis)
            {
            case Axis3D.OX:
                rotationMatrix = RotateAroundXAxis(angle);
                break;

            case Axis3D.OY:
                rotationMatrix = RotateAroundYAxis(angle);
                break;

            case Axis3D.OZ:
                rotationMatrix = RotateAroundZAxis(angle);
                break;

            default:
                throw new ArgumentException("Unknown axis");
            }

            return(returnOrigin.MultiplyBy(rotationMatrix.MultiplyBy(moveOriginToPoint)));
        }
            /// <summary>
            ///     Given a GameObject <paramref name="go" />, an axis <paramref name="axis" /> and a float <paramref name="amount" />,
            ///     move that GameObject in the given axis direction by
            ///     <paramref
            ///         name="amount" />
            ///     units.
            /// </summary>
            /// <param name="go">The GameObject to move.</param>
            /// <param name="axis">The axis to move the GameObject along.</param>
            /// <param name="amount">The amount to move the GameObject by.</param>
            public static void MovePosition(this GameObject go, Axis3D axis, float amount)
            {
                Vector3 tempVec = go.transform.position; // Temporary variable

                // Increment the appropriate axis by the amount and reassign this transform's vector.
                switch (axis)
                {
                case Axis3D.X:
                {
                    tempVec.x += amount;
                    break;
                }

                case Axis3D.Y:
                {
                    tempVec.y += amount;
                    break;
                }

                case Axis3D.Z:
                {
                    tempVec.z += amount;
                    break;
                }
                }

                go.transform.position = tempVec;
            }
Exemple #4
0
        private static void Process(CylinderSensor cylinderSensor,
                                    Body body,
                                    Position3D bodyTouchPosition,
                                    double startX,
                                    double startY,
                                    Axis3D startMoveRay,
                                    double endX,
                                    double endY,
                                    Axis3D endMoveRay,
                                    double canvasWidth,
                                    double canvasHeight,
                                    Camera camera)
        {
            if (startX.EqualsTo(endX) && startY.EqualsTo(endY))
            {
                return;
            }

            var cylinderAxis = new Axis3D(body.Frame.Offset, body.Frame * cylinderSensor.Axis);

            double angle;

            if (IsAxisIsInCameraPlane(cylinderAxis, camera))
            {
                angle = CalculateAngleForAxisLieingInCanvas(bodyTouchPosition, startX, startY, endMoveRay, cylinderAxis, canvasWidth, canvasHeight, camera);
            }
            else
            {
                angle = CalculateAngleForAxisNotLieingInCanvas(startX, startY, startMoveRay, endX, endY, endMoveRay, cylinderAxis, canvasWidth, canvasHeight);
            }

            Rotate(body, cylinderAxis, angle);
        }
        public void Process(ISensor sensor, MoveEvent moveEvent)
        {
            var startX = moveEvent.StartMoveX;
            var startY = moveEvent.StartMoveY;
            var endX   = moveEvent.EndMoveX;
            var endY   = moveEvent.EndMoveY;

            if (startX.EqualsTo(endX) && startY.EqualsTo(endY))
            {
                return;
            }

            var offset            = moveEvent.Camera.Frame.Offset;
            var endMoveOffset     = ViewProjection.ProjectCanvasToSceneSystem(moveEvent.EndMoveX, moveEvent.EndMoveY, moveEvent.CanvasWidth, moveEvent.CanvasHeight, moveEvent.Camera.NearPlane, moveEvent.Camera.Frame);
            var endMoveDirection  = endMoveOffset - offset;
            var endMoveRay        = new Axis3D(endMoveOffset, endMoveDirection);
            var body              = _scene.GetBody(moveEvent.SelectedBodyId);
            var camera            = moveEvent.Camera;
            var canvasWidth       = moveEvent.CanvasWidth;
            var canvasHeight      = moveEvent.CanvasHeight;
            var bodyTouchPosition = moveEvent.BodyTouchPosition;

            var canvasOrigin = ViewProjection.ProjectCanvasToSceneSystem(0.0, 0.0, canvasWidth, canvasHeight, camera.NearPlane, camera.Frame);
            var canvasExPos  = ViewProjection.ProjectCanvasToSceneSystem(1.0, 0.0, canvasWidth, canvasHeight, camera.NearPlane, camera.Frame);
            var canvasEyPos  = ViewProjection.ProjectCanvasToSceneSystem(0.0, 1.0, canvasWidth, canvasHeight, camera.NearPlane, camera.Frame);
            var exAxis       = (canvasExPos - canvasOrigin).Normalize();
            var ezAxis       = (canvasEyPos - canvasOrigin).Normalize();

            var zCylinderAxis = new Axis3D(body.Frame.Offset, ezAxis);
            var xCylinderAxis = new Axis3D(body.Frame.Offset, exAxis);

            Process(body, bodyTouchPosition, startX, startY, endMoveRay, zCylinderAxis, canvasWidth, canvasHeight, camera);
            Process(body, bodyTouchPosition, startX, startY, endMoveRay, xCylinderAxis, canvasWidth, canvasHeight, camera);
        }
Exemple #6
0
        public void Process(ISensor sensor, MoveEvent moveEvent)
        {
            var offset = moveEvent.Camera.Frame.Offset;

            var startMoveOffset    = ViewProjection.ProjectCanvasToSceneSystem(moveEvent.StartMoveX, moveEvent.StartMoveY, moveEvent.CanvasWidth, moveEvent.CanvasHeight, moveEvent.Camera.NearPlane, moveEvent.Camera.Frame);
            var startMoveDirection = startMoveOffset - offset;
            var startMoveRay       = new Axis3D(startMoveOffset, startMoveDirection);

            var endMoveOffset    = ViewProjection.ProjectCanvasToSceneSystem(moveEvent.EndMoveX, moveEvent.EndMoveY, moveEvent.CanvasWidth, moveEvent.CanvasHeight, moveEvent.Camera.NearPlane, moveEvent.Camera.Frame);
            var endMoveDirection = endMoveOffset - offset;
            var endMoveRay       = new Axis3D(endMoveOffset, endMoveDirection);

            var body = _scene.GetBody(moveEvent.SelectedBodyId);

            Process(sensor as CylinderSensor,
                    body,
                    moveEvent.BodyTouchPosition,
                    moveEvent.StartMoveX,
                    moveEvent.StartMoveY,
                    startMoveRay,
                    moveEvent.EndMoveX,
                    moveEvent.EndMoveY,
                    endMoveRay,
                    moveEvent.CanvasWidth,
                    moveEvent.CanvasHeight,
                    moveEvent.Camera);
        }
    public static Vector3 Set(this Vector3 vec, Axis3D axe, float new_value, bool debug = false)
    {
        Vector3 tmp = vec;

        switch (axe)
        {
        case Axis3D.x:
            if (debug)
            {
                Debug.Log("Set with Axe X");
            }
            tmp.x = new_value;
            break;

        case Axis3D.y:
            if (debug)
            {
                Debug.Log("Set with Axe Y");
            }
            tmp.y = new_value;
            break;

        case Axis3D.z:
            if (debug)
            {
                Debug.Log("Set with Axe Z");
            }
            tmp.z = new_value;
            break;
        }
        return(tmp);
    }
 public static Vector3 Clamp(this Vector3 aVector, Axis3D axe, Limit3D limit)
 {
     return(new Vector3(
                Mathf.Clamp(aVector.x, limit.mini.x, limit.maxi.x),
                Mathf.Clamp(aVector.y, limit.mini.y, limit.maxi.y),
                Mathf.Clamp(aVector.x, limit.mini.z, limit.maxi.z)
                ));
 }
        public override void RotateAroundAxis(Axis3D axis, double angle)
        {
            foreach (var o in _objects)
            {
                RotateAroundAxisTransformation(axis, angle, o);
            }

            _rotationAngleAroundAxis[axis] += angle;
        }
        private static ISceneNode CreateDragAxisGizmo(Axis3D axis)
        {
            var node      = AmFactory.Create <SceneNode>();
            var component = AmFactory.Create <DragAlongAxisGizmoComponent>();

            component.Axis = axis;
            node.Components.Add(component);
            return(node);
        }
Exemple #11
0
        public void CalculatePerpendicularPointTest_WhenTwoLinesInPararllelPlaneXY_ThenPlumpPointIsCalculated()
        {
            var baseAxis   = new Axis3D(new Position3D(10, 20, 0), new Vector3D(1, 0, 0));
            var secondAxis = new Axis3D(new Position3D(10, 20, 100), new Vector3D(0, 1, 0));

            var(success, plumpOnBaseAxis) = baseAxis.CalculatePerpendicularPoint(secondAxis);

            Assert.True(success);
            Assert.Equal(baseAxis.Offset, plumpOnBaseAxis);
        }
Exemple #12
0
        public void CalculatePerpendicularPointTest_WhenTwoCrossingLines_ThenPlumpPointIsCrossPoint()
        {
            var baseAxis   = new Axis3D(new Position3D(0, 0, 100), new Vector3D(1, 1, -1));
            var secondAxis = new Axis3D(new Position3D(0, 0, -100), new Vector3D(1, 1, 1));

            var(success, plumpOnBaseAxis) = baseAxis.CalculatePerpendicularPoint(secondAxis);

            Assert.True(success);
            Assert.Equal(new Position3D(100, 100, 0), plumpOnBaseAxis);
        }
Exemple #13
0
        private static (bool, Position3D) GetRayIntersectionWithEdge(Axis3D rayAxis, EdgeHL edge)
        {
            var edgeEnd       = edge.End;
            var edgeOffset    = edge.Start;
            var edgeDirection = edgeEnd - edgeOffset;
            var edgeAxis      = new Axis3D(edgeOffset, edgeDirection);

            var(success, intersection) = edgeAxis.CalculatePerpendicularPoint(rayAxis);

            return(success, intersection);
        }
Exemple #14
0
        public void IntersectTest_WhenParallelStraightLineNotIntersectsPlane_ThenResultIsEmpty()
        {
            var plane = new Plane3D(new Position3D(100, 100, 0), new Vector3D(0, 0, 1));
            var axis  = new Axis3D(new Position3D(100, 100, 100), new Vector3D(1, 1, 0));

            var(success, intersection)   = plane.Intersect(axis);
            var(success2, intersection2) = axis.Intersect(plane);

            Assert.False(success);
            Assert.False(success2);
        }
Exemple #15
0
        private static bool IsAxisIsInCameraPlane(Axis3D cylinderAxis, Camera camera)
        {
            var    cameraDirection = camera.Frame.Ey;
            double limitAngle      = 25.0;
            double alpha           = cylinderAxis.Direction.CounterClockwiseAngleWith(cameraDirection);

            alpha = alpha.Modulo2Pi();
            alpha = alpha.RadToDeg();
            var result = !((Math.Abs(alpha) < limitAngle) || (Math.Abs(alpha) > (180.0 - limitAngle)));

            return(result);
        }
Exemple #16
0
        private static Vector3D CalculateMove(Body body, Vector3D axis, Axis3D startMoveRay, Axis3D endMoveRay)
        {
            var axisOffset    = body.Frame.Offset;
            var axisDirection = body.Frame * axis;
            var moveAxis      = new Axis3D(axisOffset, axisDirection);

            var(startExist, startPlump) = moveAxis.CalculatePerpendicularPoint(startMoveRay);
            var(endExist, endPlump)     = moveAxis.CalculatePerpendicularPoint(endMoveRay);
            var moveVector = startExist && endExist ? endPlump - startPlump : new Vector3D();

            return(moveVector);
        }
Exemple #17
0
        private static void Process(LinearSensor linearSensor, Body body, Axis3D startMoveRay, Axis3D endMoveRay)
        {
            if (startMoveRay.Offset == endMoveRay.Offset)
            {
                return;
            }

            var moveVector = CalculateMove(body, linearSensor.Axis, startMoveRay, endMoveRay);
            var moveFrame  = Matrix44D.CreateTranslation(moveVector);

            body.Frame = moveFrame * body.Frame;
        }
        private static Vector3D CalculateMove(Body body, Vector3D normal, Axis3D startMoveRay, Axis3D endMoveRay)
        {
            var planeOffset = body.Frame.Offset;
            var planeNormal = body.Frame * normal;
            var movePlane   = new Plane3D(planeOffset, planeNormal);

            var(startIsIntersecting, startIntersection) = movePlane.Intersect(startMoveRay);
            var(endIsIntersecting, endIntersection)     = movePlane.Intersect(endMoveRay);
            var moveVector = startIsIntersecting && endIsIntersecting ? endIntersection - startIntersection : new Vector3D();

            return(moveVector);
        }
 /// <summary>
 /// Вращение расчетного центра модели вокруг осей
 /// </summary>
 /// <param name="angle">Угол вращения</param>
 /// <param name="axis">Ось вращения</param>
 /// <returns></returns>
 public int Rotate(float angle, Axis3D axis)
 {
     try
     {
         return(Engine3D.RotatePoint3D(angle, axis, PositionPoint));
     }
     catch (Exception er)
     {
         Graph3DLibrary.ErrorLog.AddErrorMessage("ModelDetalizationSelector", "Rotate", er.Message, -1);
         return(-1);
     }
 }
Exemple #20
0
        public void IntersectTest_WhenStraightLineYIntersectsPlaneXZ_ThenResultIsIntersection()
        {
            var plane = new Plane3D(new Position3D(0, 100, 0), new Vector3D(0, 1, 0));
            var axis  = new Axis3D(new Position3D(100, 0, 100), new Vector3D(0, 1, 0));

            var(success, intersection)   = plane.Intersect(axis);
            var(success2, intersection2) = axis.Intersect(plane);

            Assert.True(success);
            Assert.Equal(new Position3D(100, 100, 100), intersection);
            Assert.True(success2);
            Assert.Equal(new Position3D(100, 100, 100), intersection2);
        }
Exemple #21
0
        public void CalculatePerpendicularPointTest_WhenLineInPlaneXYAndPosition_ThenPlumpPointIsCalculated()
        {
            var position = new Position3D(100, 100, 200);
            var axis     = new Axis3D(new Position3D(), new Vector3D(1, 1, 0));

            var plump  = axis.CalculatePerpendicularPoint(position);
            var plump2 = position.CalculatePerpendicularPoint(axis);

            var expected = new Position3D(100, 100, 0);

            Assert.Equal(expected, plump);
            Assert.Equal(expected, plump2);
        }
Exemple #22
0
        private static double CalculateAngleForAxisLieingInCanvas(
            Position3D bodyTouchPosition,
            double startX,
            double startY,
            Axis3D endMoveRay,
            Axis3D cylinderAxis,
            double canvasWidth,
            double canvasHeight,
            Camera camera
            )
        {
            var angle           = 0.0;
            var cameraDirection = camera.Frame.Ey;

            var direction     = (cameraDirection & cylinderAxis.Direction).Normalize() * 10000.0;
            var offset        = ViewProjection.ProjectCanvasToSceneSystem(startX, startY, canvasWidth, canvasHeight, camera.NearPlane, camera.Frame);
            var p1            = offset - direction;
            var p2            = offset + direction;
            var projectedAxis = new Axis3D(p1, p2 - p1);

            var(success, plump) = projectedAxis.CalculatePerpendicularPoint(endMoveRay);
            if (success)
            {
                // Ermitteln des Vorzeichens für Drehung
                var sign = (plump - p1).Length < (plump - p2).Length ? -1.0 : 1.0;

                // Ermitteln der Länge der Mausbewegung in Richtung senkrecht zur Rotationsachse
                var(endX, endY) = ViewProjection.ProjectSceneSystemToCanvas(plump, canvasWidth, canvasHeight, camera.NearPlane, camera.Frame);
                double delta = Vector2DMath.Length(startX, startY, endX, endY);

                // Projektion Berührungspunkt auf Rotationsachse.
                // Ermittel Scheitelpunkte der Rotation auf Achse senkrecht zur Kamera und Rotationsachse.
                // Projektion der Scheitelpunkte auf Canvas.
                // Abstand Scheitelpunkte auf Achse ist die Mausbewegung für 180°.
                // Winkel ist Verhältnis Länge Mausbewegung zur Länge für 180°.
                var plumpPoint = cylinderAxis.CalculatePerpendicularPoint(bodyTouchPosition);
                var distance   = (bodyTouchPosition - plumpPoint).Length;
                direction = direction.Normalize() * distance;
                var startPosition = cylinderAxis.Offset - direction;
                var endPosition   = cylinderAxis.Offset + direction;
                (startX, startY) = ViewProjection.ProjectSceneSystemToCanvas(startPosition, canvasWidth, canvasHeight, camera.NearPlane, camera.Frame);
                (endX, endY)     = ViewProjection.ProjectSceneSystemToCanvas(endPosition, canvasWidth, canvasHeight, camera.NearPlane, camera.Frame);
                var lengthOfHalfRotation = Vector2DMath.Length(startX, startY, endX, endY);

                var angleInDegree = 180.0 * delta / lengthOfHalfRotation;

                angle = sign * angleInDegree.DegToRad();
            }

            return(angle);
        }
        private static void Process(
            Body body,
            Position3D bodyTouchPosition,
            double startX,
            double startY,
            Axis3D endMoveRay,
            Axis3D cylinderAxis,
            double canvasWidth,
            double canvasHeight,
            Camera camera)
        {
            var angle    = CalculateAngle(bodyTouchPosition, startX, startY, endMoveRay, cylinderAxis, canvasWidth, canvasHeight, camera);
            var rotation = Matrix44D.CreateRotation(cylinderAxis.Offset, cylinderAxis.Direction, angle);

            body.Frame = rotation * body.Frame;
        }
Exemple #24
0
 public static Vector3 MixWith(this Vector3 self, Axis3D axis, Vector3 other)
 {
     if ((axis & Axis3D.X) != 0)
     {
         self.x = other.x;
     }
     if ((axis & Axis3D.Y) != 0)
     {
         self.y = other.y;
     }
     if ((axis & Axis3D.Z) != 0)
     {
         self.z = other.z;
     }
     return(self);
 }
Exemple #25
0
        private static double CalculateAngleSign(Axis3D cylinderAxis, Position3D start, Position3D end)
        {
            var       axisFrame = Matrix44D.CreateRotation(cylinderAxis.Offset, cylinderAxis.Direction);
            Matrix44D invframe  = axisFrame.Inverse();

            var startInFrame = invframe * start;
            var endInFrame   = invframe * end;

            var sx = startInFrame.X;
            var sy = startInFrame.Y;
            var ex = endInFrame.X;
            var ey = endInFrame.Y;

            var sign = TriangleMath.IsCounterClockwise(sx, sy, ex, ey, 0.0, 0.0) ? 1.0 : -1.0;

            return(sign);
        }
    public static Vector3 plus(this Vector3 vector, Axis3D axe, float value)
    {
        switch (axe)
        {
        case Axis3D.x:
            return(new Vector3(vector.x + value, vector.y, vector.z));

        case Axis3D.y:
            return(new Vector3(vector.x, vector.y + value, vector.z));

        case Axis3D.z:
            return(new Vector3(vector.x, vector.y, vector.z + value));

        default:
            return(default(Vector3));
        }
    }
Exemple #27
0
    public static Vector3 ToVector3(float value, Axis3D axe)
    {
        Vector3 temp = Vector3.zero;

        switch (axe)
        {
        case Axis3D.x:
            temp.x = value;
            break;

        case Axis3D.y:
            temp.y = value;
            break;

        case Axis3D.z:
            temp.z = value;
            break;
        }
        return(temp);
    }
Exemple #28
0
        private static double CalculateAngleForAxisNotLieingInCanvas(
            double startX,
            double startY,
            Axis3D startMoveRay,
            double endX,
            double endY,
            Axis3D endMoveRay,
            Axis3D cylinderAxis,
            double canvasWidth,
            double canvasHeight)
        {
            var axisPlane   = new Plane3D(cylinderAxis.Offset, cylinderAxis.Direction);
            var startOffset = GetPosition(startMoveRay, axisPlane);
            var endOffset   = GetPosition(endMoveRay, axisPlane);

            double sign  = CalculateAngleSign(cylinderAxis, startOffset, endOffset);
            var    angle = sign * 1.0 * CalculateAngle(startX, startY, endX, endY, canvasWidth, canvasHeight);

            return(angle);
        }
    public static Vector3 Clamp(this Vector3 aVector, Axis3D axe, LimitF limit)
    {
        Vector3 tmp = aVector;

        switch (axe)
        {
        case Axis3D.x:
            tmp.x = Mathf.Clamp(tmp.x, limit.mini, limit.maxi);
            break;

        case Axis3D.y:
            tmp.y = Mathf.Clamp(tmp.y, limit.mini, limit.maxi);
            break;

        case Axis3D.z:
            tmp.z = Mathf.Clamp(tmp.z, limit.mini, limit.maxi);
            break;
        }
        return(tmp);
    }
Exemple #30
0
 public static Vector3 ToVector3(int value, Axis3D axe)
 {
     return(ToVector3((float)value, axe));
 }