コード例 #1
0
        public void Leveling7PointsCorectInterpolation()
        {
			PrintLevelingData levelingData = new PrintLevelingData();

			double radius = 100;
			levelingData.SampledPositions = new List<Vector3>();
			Vector2 currentEdgePoint = new Vector2(radius, 0);
			for (int i = 0; i < 6; i++)
			{
				levelingData.SampledPositions.Add(new Vector3(currentEdgePoint, i));
				currentEdgePoint.Rotate(MathHelper.Tau / 6);
			}

			levelingData.SampledPositions.Add(new Vector3(0, 0, 6));

			for (int curPoint = 0; curPoint < 6; curPoint++)
			{
				int nextPoint = curPoint < 5 ? curPoint + 1 : 0;

				// test actual sample position
				Vector2 currentTestPoint = new Vector2(radius, 0);
				currentTestPoint.Rotate(MathHelper.Tau / 6 * curPoint);
				Vector3 outPosition = LevelWizard7PointRadial.GetPositionWithZOffset(new Vector3(currentTestPoint, 0), levelingData);
				Assert.AreEqual(outPosition.z, levelingData.SampledPositions[curPoint].z, .001);

				// test mid point between samples
				Vector3 midPoint = (levelingData.SampledPositions[curPoint] + levelingData.SampledPositions[nextPoint]) / 2;
				currentTestPoint = new Vector2(midPoint.x, midPoint.y);
				outPosition = LevelWizard7PointRadial.GetPositionWithZOffset(new Vector3(currentTestPoint, 0), levelingData);
				Assert.AreEqual(outPosition.z, midPoint.z, .001);

				// test mid point between samples with offset
				Vector3 midPointWithOffset = (levelingData.SampledPositions[curPoint] + levelingData.SampledPositions[nextPoint]) / 2 + new Vector3(0, 0, 3);
				currentTestPoint = new Vector2(midPointWithOffset.x, midPointWithOffset.y);
				outPosition = LevelWizard7PointRadial.GetPositionWithZOffset(new Vector3(currentTestPoint, 3), levelingData);
				Assert.AreEqual(outPosition.z, midPointWithOffset.z, .001);

				// test 1/2 angles (mid way between samples on radius)
				currentTestPoint = new Vector2(radius, 0);
				currentTestPoint.Rotate(MathHelper.Tau / 6 * (curPoint + .5));
				outPosition = LevelWizard7PointRadial.GetPositionWithZOffset(new Vector3(currentTestPoint, 0), levelingData);
				// the center is the higest point so the point on the radius has to be less than the mid point of the sample points (it is lower)
				Assert.IsTrue(outPosition.z < (levelingData.SampledPositions[curPoint].z + levelingData.SampledPositions[nextPoint].z) / 2 - .001);

				// test 1/2 to center
				currentTestPoint = new Vector2(radius / 2, 0);
				currentTestPoint.Rotate(MathHelper.Tau / 6 * curPoint);
				outPosition = LevelWizard7PointRadial.GetPositionWithZOffset(new Vector3(currentTestPoint, 0), levelingData);
				Assert.AreEqual(outPosition.z, (levelingData.SampledPositions[curPoint].z + levelingData.SampledPositions[6].z) / 2, .001);
			}
			
			Vector3 outPosition2 = LevelWizard7PointRadial.GetPositionWithZOffset(Vector3.Zero, levelingData);
			Assert.AreEqual(outPosition2.z, levelingData.SampledPositions[6].z, .001);
		}
コード例 #2
0
		public Vector2 GetPrintLevelPositionToSample(int index, double radius)
        {
            Vector2 bedCenter = ActiveSliceSettings.Instance.BedCenter;
            if (index < NumberOfRadialSamples)
            {
                Vector2 position = new Vector2(radius, 0);
                position.Rotate(MathHelper.Tau / NumberOfRadialSamples * index);
                position += bedCenter;
                return position;
            }
            else
            {
                return bedCenter;
            }
        }
コード例 #3
0
		public void Leveling7PointsNeverGetsTooHigh()
		{
			StaticData.Instance = new MatterHackers.Agg.FileSystemStaticData(Path.Combine("..", "..", "..", "..", "StaticData"));

			PrintLevelingData levelingData = new PrintLevelingData();

			double radius = 100;
			levelingData.SampledPositions = new List<Vector3>();
			levelingData.SampledPositions.Add(new Vector3(130.00, 0.00, 0));
			levelingData.SampledPositions.Add(new Vector3(65.00, 112.58, 10));
			levelingData.SampledPositions.Add(new Vector3(-65.00, 112.58, 0));
			levelingData.SampledPositions.Add(new Vector3(-130.00, 0.00, 10));
			levelingData.SampledPositions.Add(new Vector3(-65.00, -112.58, 0));
			levelingData.SampledPositions.Add(new Vector3(65.00, -112.58, 10));

			levelingData.SampledPositions.Add(new Vector3(0, 0, 0));

			levelingData.SampledPositions.Add(new Vector3(0, 0, 6));

			Vector2 bedCenter = Vector2.Zero;

			RadialLevlingFunctions levelingFunctions7Point = new RadialLevlingFunctions(6, levelingData, bedCenter);
			int totalPoints = 2000;
			for (int curPoint = 0; curPoint < totalPoints; curPoint++)
			{
				Vector2 currentTestPoint = new Vector2(radius, 0);
				currentTestPoint.Rotate(MathHelper.Tau / totalPoints * curPoint);
				Vector3 destPosition = new Vector3(currentTestPoint, 0);
				
				Vector3 outPosition = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
				Assert.IsTrue(outPosition.z <= 10);
				
				string outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
				double outZ = 0;
				Assert.IsTrue(GCodeFile.GetFirstNumberAfter("Z", outPositionString, ref outZ));
				Assert.IsTrue(outZ <= 10);
			}
		}
コード例 #4
0
		public static void WriteTestGCodeFile()
		{
			using (StreamWriter file = new StreamWriter("PerformanceTest.gcode"))
			{
				//int loops = 150000;
				int loops = 150;
				int steps = 200;
				double radius = 50;
				Vector2 center = new Vector2(150, 100);

				file.WriteLine("G28 ; home all axes");
				file.WriteLine("G90 ; use absolute coordinates");
				file.WriteLine("G21 ; set units to millimeters");
				file.WriteLine("G92 E0");
				file.WriteLine("G1 F7800");
				file.WriteLine("G1 Z" + (5).ToString());
				WriteMove(file, center);

				for (int loop = 0; loop < loops; loop++)
				{
					for (int step = 0; step < steps; step++)
					{
						Vector2 nextPosition = new Vector2(radius, 0);
						nextPosition.Rotate(MathHelper.Tau / steps * step);
						WriteMove(file, center + nextPosition);
					}
				}

				file.WriteLine("M84     ; disable motors");
			}
		}
コード例 #5
0
        // ------------------------------------------------------------------------------------------------
        private void MoveAndRotate_UserControlled(Vector3 moveIndicator, Vector2 rotationIndicator, float rollIndicator)
        {
            if (MyInput.Static.IsAnyCtrlKeyPressed())
            {
                if (MyInput.Static.PreviousMouseScrollWheelValue() < MyInput.Static.MouseScrollWheelValue())
                {
                    SpeedModeAngular = Math.Min(SpeedModeAngular * 1.5f, MAX_SPECTATOR_ANGULAR_SPEED);
                }
                else if (MyInput.Static.PreviousMouseScrollWheelValue() > MyInput.Static.MouseScrollWheelValue())
                {
                    SpeedModeAngular = Math.Max(SpeedModeAngular / 1.5f, MIN_SPECTATOR_ANGULAR_SPEED);
                }
            }
            else
            {
                if (MyInput.Static.PreviousMouseScrollWheelValue() < MyInput.Static.MouseScrollWheelValue())
                {
                    SpeedModeLinear = Math.Min(SpeedModeLinear * 1.5f, MAX_SPECTATOR_LINEAR_SPEED);
                }
                else if (MyInput.Static.PreviousMouseScrollWheelValue() > MyInput.Static.MouseScrollWheelValue())
                {
                    SpeedModeLinear = Math.Max(SpeedModeLinear / 1.5f, MIN_SPECTATOR_LINEAR_SPEED);
                }
            }

            //  Physical movement and rotation is based on constant time, therefore is indepedent of time delta
            //  This formulas works even if FPS is low or high, or if step size is 1/10 or 1/10000
            float amountOfMovement = VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * 100;
            float amountOfRotation = 0.0025f * m_speedModeAngular;

            rollIndicator = MyInput.Static.GetDeveloperRoll();
            
            float rollAmount = 0;
            if (rollIndicator != 0)
            {
                Vector3D r, u;
                rollAmount = rollIndicator * m_speedModeAngular * 0.1f;
                rollAmount = MathHelper.Clamp(rollAmount, -0.02f, 0.02f);
                MyUtils.VectorPlaneRotation(m_orientation.Up, m_orientation.Right, out u, out r, rollAmount);
                m_orientation.Right = r;
                m_orientation.Up = u;
            }

            Vector3 moveVector;

            {
                if (AlignSpectatorToGravity)
                {
                    rotationIndicator.Rotate(m_roll); // TODO: ROLL

                    m_yaw -= rotationIndicator.Y * amountOfRotation;
                    m_pitch -= rotationIndicator.X * amountOfRotation;
                    m_roll -= rollAmount;

                    MathHelper.LimitRadians2PI(ref m_yaw);
                    m_pitch = MathHelper.Clamp(m_pitch, -Math.PI * 0.5f, Math.PI * 0.5f);
                    MathHelper.LimitRadians2PI(ref m_roll);

                    ComputeGravityAlignedOrientation(out m_orientation);
                }
                else
                {
                    if (rotationIndicator.Y != 0)
                    {
                        Vector3D r, f;
                        MyUtils.VectorPlaneRotation(m_orientation.Right, m_orientation.Forward, out r, out f,
                            -rotationIndicator.Y * amountOfRotation);

                        m_orientation.Right = r;
                        m_orientation.Forward = f;
                    }

                    if (rotationIndicator.X != 0)
                    {
                        Vector3D u, f;
                        MyUtils.VectorPlaneRotation(m_orientation.Up, m_orientation.Forward, out u, out f,
                            rotationIndicator.X * amountOfRotation);
                        m_orientation.Up = u;
                        m_orientation.Forward = f;
                    }

                    m_lastOrientation = m_orientation;
                    m_lastOrientationWeight = 1;
                    m_roll = 0;
                    m_pitch = 0;
                }

                float afterburner = (MyInput.Static.IsAnyShiftKeyPressed() ? 1.0f : 0.35f) *
                                    (MyInput.Static.IsAnyCtrlKeyPressed() ? 0.3f : 1);
                moveIndicator *= afterburner * SpeedModeLinear;
                moveVector = moveIndicator * amountOfMovement;
            }


            Position += Vector3.Transform(moveVector, m_orientation);
        }
コード例 #6
0
ファイル: AppMain.cs プロジェクト: demuyan/ShootBoss
        // 周期処理
        public override void Tick(float dt)
        {
            const float speed = 80;

            base.Tick (dt);
            if (Game.Instance.Pause)
                return;

            // SIN波の動きで移動
            var pos = this.Position;
            pos.Y += 1.7f * FMath.Sin (FrameCount * 0.015f);
            pos.X += speed * dt * direction;
            this.Position = pos;
            if (direction == 1) {
                if (this.Position.X > Game.Instance.ScreenSize.X - 100) {
                    direction = -1;
                }
            } else {
                if (this.Position.X < 100) {
                    direction = 1;
                }
            }

            counter += dt;

            // 敵弾を発射する周期を算出する
            float countBase = 1;
            if (Game.Instance.OptionDialog != null)
                countBase = 1 - 0.25f * Game.Instance.OptionDialog.BulletInterval / 100;

            if (counter > countBase) {

                // 敵弾を発射
                float[] angles = new float[]{
                     FMath.PI * 4 / 8,  FMath.PI * 3 / 8,  FMath.PI * 2 / 8,  FMath.PI * 1 / 8,0,
                    -FMath.PI * 4 / 8, -FMath.PI * 3 / 8, -FMath.PI * 2 / 8, -FMath.PI * 1 / 8};
                Vector2 srcvec = new Vector2 (0, -100f);
                foreach(float val in angles){
                    Game.Instance.AddQueue.Add (new BossBullet (this.Position, srcvec.Rotate (val)));
                }
                counter = 0;
            }
        }
コード例 #7
0
        public void Leveling7PointsCorectInterpolation()
		{
			PrintLevelingData levelingData = new PrintLevelingData();

			double radius = 100;
			levelingData.SampledPositions = new List<Vector3>();
			Vector2 currentEdgePoint = new Vector2(radius, 0);
			for (int i = 0; i < 6; i++)
			{
				levelingData.SampledPositions.Add(new Vector3(currentEdgePoint, i));
				currentEdgePoint.Rotate(MathHelper.Tau / 6);
			}

			levelingData.SampledPositions.Add(new Vector3(0, 0, 6));

			Vector2 bedCenter = Vector2.Zero;

			RadialLevlingFunctions levelingFunctions7Point = new RadialLevlingFunctions(6, levelingData, bedCenter);
			for (int curPoint = 0; curPoint < 6; curPoint++)
			{
				int nextPoint = curPoint < 5 ? curPoint + 1 : 0;

				// test actual sample position
				Vector2 currentTestPoint = new Vector2(radius, 0);
				currentTestPoint.Rotate(MathHelper.Tau / 6 * curPoint);
				Vector3 destPosition = new Vector3(currentTestPoint, 0);
				Vector3 outPosition = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
				Assert.AreEqual(outPosition.z, levelingData.SampledPositions[curPoint].z, .001);
				string outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
				Assert.AreEqual(GetGCodeString(outPosition), outPositionString);

				// test mid point between samples
				Vector3 midPoint = (levelingData.SampledPositions[curPoint] + levelingData.SampledPositions[nextPoint]) / 2;
				currentTestPoint = new Vector2(midPoint.x, midPoint.y);
				destPosition = new Vector3(currentTestPoint, 0);
				outPosition = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
				Assert.AreEqual(outPosition.z, midPoint.z, .001);
				outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
				Assert.AreEqual(GetGCodeString(outPosition), outPositionString);

				// test mid point between samples with offset
				Vector3 midPointWithOffset = (levelingData.SampledPositions[curPoint] + levelingData.SampledPositions[nextPoint]) / 2 + new Vector3(0, 0, 3);
				currentTestPoint = new Vector2(midPointWithOffset.x, midPointWithOffset.y);
				destPosition = new Vector3(currentTestPoint, 3);
				outPosition = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
				Assert.AreEqual(outPosition.z, midPointWithOffset.z, .001);
				outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
				Assert.AreEqual(GetGCodeString(outPosition), outPositionString);

				// test 1/2 angles (mid way between samples on radius)
				currentTestPoint = new Vector2(radius, 0);
				currentTestPoint.Rotate(MathHelper.Tau / 6 * (curPoint + .5));
				destPosition = new Vector3(currentTestPoint, 0);
				outPosition = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
				// the center is the higest point so the point on the radius has to be less than the mid point of the sample points (it is lower)
				Assert.IsTrue(outPosition.z < (levelingData.SampledPositions[curPoint].z + levelingData.SampledPositions[nextPoint].z) / 2 - .001);
				outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
				Assert.AreEqual(GetGCodeString(outPosition), outPositionString);

				// test 1/2 to center
				currentTestPoint = new Vector2(radius / 2, 0);
				currentTestPoint.Rotate(MathHelper.Tau / 6 * curPoint);
				destPosition = new Vector3(currentTestPoint, 0);
				outPosition = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
				Assert.AreEqual(outPosition.z, (levelingData.SampledPositions[curPoint].z + levelingData.SampledPositions[6].z) / 2, .001);
				outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
				Assert.AreEqual(GetGCodeString(outPosition), outPositionString);
			}

			// prove that relative offsets work
			{
				Vector2 prevTestPoint = new Vector2(radius, 0);
				Vector3 prevDestPosition = new Vector3(prevTestPoint, 0);
				Vector3 prevOutPosition = levelingFunctions7Point.GetPositionWithZOffset(prevDestPosition);
				string prevOutPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(prevDestPosition), prevDestPosition, PrinterMachineInstruction.MovementTypes.Absolute);

				for (int curPoint = 1; curPoint < 6; curPoint++)
				{
					// test actual sample position
					Vector2 currentTestPoint = new Vector2(radius, 0);
					currentTestPoint.Rotate(MathHelper.Tau / 6 * curPoint);
					Vector3 destPosition = new Vector3(currentTestPoint, 0);
					Vector3 outPosition = levelingFunctions7Point.GetPositionWithZOffset(destPosition);

					string outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Relative);
					Vector3 delatFromPrevToCurrent = outPosition - prevOutPosition;
					Assert.AreEqual(GetGCodeString(delatFromPrevToCurrent), outPositionString);

					prevTestPoint = currentTestPoint;
					prevDestPosition = destPosition;
					prevOutPosition = outPosition;
				}
			}

			Vector3 outPosition2 = levelingFunctions7Point.GetPositionWithZOffset(Vector3.Zero);
			Assert.AreEqual(outPosition2.z, levelingData.SampledPositions[6].z, .001);
		}
コード例 #8
0
		public void DrawAACircle(Vector2 start, double radius, IColorType colorIn)
		{
			RGBA_Bytes colorBytes = colorIn.GetAsRGBA_Bytes();
			GL.Color4(colorBytes.red, colorBytes.green, colorBytes.blue, colorBytes.alpha);

			Affine transform = GetTransform();
			if (!transform.is_identity())
			{
				transform.transform(ref start);
			}

			// now draw the end rounds
			int numSegments = 12;
			double anglePerSegment = MathHelper.Tau / numSegments;
			Vector2 currentOffset = new Vector2(0, radius);
			Vector2 curveStart = start + currentOffset;
			for (int i = 0; i < numSegments; i++)
			{
				currentOffset.Rotate(anglePerSegment);
				Vector2 curveEnd = start + currentOffset;

				triangleEddgeInfo.Draw1EdgeTriangle(curveStart, curveEnd, start);
				curveStart = curveEnd;
			}
		}
コード例 #9
0
ファイル: GLUtility.cs プロジェクト: iamchucky/3DpointCloud
        public static void DrawEllipse(GLPen p, Vector2 firstPoint, Vector2 secondPoint, float height)
        {
            Vector2 deltaPoint = new Vector2(firstPoint.X - secondPoint.X, firstPoint.Y - secondPoint.Y);
            double angle = deltaPoint.ToRadians();
            deltaPoint = deltaPoint.Rotate90();
            //Vector2 thirdPoint = deltaPoint.Normalize() * height;
            float length = (float)firstPoint.DistanceTo(secondPoint);

            Vector2 PreRotDrawpoint = new Vector2(0, 0);
            Vector2 PostRotDrawPoint = new Vector2(0, 0);
            p.GLApplyPen();
            Gl.glPushMatrix();
            Gl.glTranslatef((float)firstPoint.X, (float)firstPoint.Y, 0);
            Gl.glBegin(Gl.GL_LINE_LOOP);
            for (double i = 0; i < Math.PI * 2; i += 0.05)
            {
                PreRotDrawpoint = new Vector2((float)(Math.Cos(i) * length), (float)(Math.Sin(i) * height));
                PostRotDrawPoint = PreRotDrawpoint.Rotate(angle);
                Gl.glVertex2f((float)PostRotDrawPoint.X, (float)PostRotDrawPoint.Y);
            }
            Gl.glEnd();
            Gl.glPopMatrix();
        }
コード例 #10
0
		public static Vector2 GetPrintLevelPositionToSample(int index, double radius)
		{
			if (index < 6)
			{
				Vector2 position = new Vector2(radius, 0);
				position.Rotate(MathHelper.Tau / 6 * index);
				position += ActiveSliceSettings.Instance.BedCenter;
				return position;
			}
			else
			{
				return new Vector2(0, 0);
			}
		}
コード例 #11
0
        //  Moves and rotates player by specified vector and angles
        public override void MoveAndRotate(Vector3 moveIndicator, Vector2 rotationIndicator, float rollIndicator)
        {
            switch (SpectatorCameraMovement)
            {
                case MySpectatorCameraMovementEnum.None:
                    return;
                    break;

                case MySpectatorCameraMovementEnum.ConstantDelta:
                    {
                        if (!MyInput.Static.IsAnyAltKeyPressed() && !MyInput.Static.IsAnyCtrlKeyPressed() && !MyInput.Static.IsAnyShiftKeyPressed())
                        {
                            if (MyInput.Static.PreviousMouseScrollWheelValue() < MyInput.Static.MouseScrollWheelValue())
                            {
                                ThirdPersonCameraDelta /= 1.1f;
                            }
                            else if (MyInput.Static.PreviousMouseScrollWheelValue() > MyInput.Static.MouseScrollWheelValue())
                            {
                                ThirdPersonCameraDelta *= 1.1f;
                            }
                        }

                        if (MySession.ControlledEntity != null)
                        {
                            Position = (Vector3D)MySession.ControlledEntity.Entity.PositionComp.GetPosition() + ThirdPersonCameraDelta;
                            Target = (Vector3D)MySession.ControlledEntity.Entity.PositionComp.GetPosition();
                        }
                    }
                    break;

                case MySpectatorCameraMovementEnum.UserControlled:
                    {
                        if (MyInput.Static.IsAnyCtrlKeyPressed())
                        {
                            if (MyInput.Static.PreviousMouseScrollWheelValue() < MyInput.Static.MouseScrollWheelValue())
                            {
                                SpeedModeAngular = Math.Min(SpeedModeAngular * 1.5f, MAX_SPECTATOR_ANGULAR_SPEED);
                            }
                            else if (MyInput.Static.PreviousMouseScrollWheelValue() > MyInput.Static.MouseScrollWheelValue())
                            {
                                SpeedModeAngular = Math.Max(SpeedModeAngular / 1.5f, MIN_SPECTATOR_ANGULAR_SPEED);
                            }
                        }
                        else
                        {
                            if (MyInput.Static.PreviousMouseScrollWheelValue() < MyInput.Static.MouseScrollWheelValue())
                            {
                                SpeedModeLinear = Math.Min(SpeedModeLinear * 1.5f, MAX_SPECTATOR_LINEAR_SPEED);
                            }
                            else if (MyInput.Static.PreviousMouseScrollWheelValue() > MyInput.Static.MouseScrollWheelValue())
                            {
                                SpeedModeLinear = Math.Max(SpeedModeLinear / 1.5f, MIN_SPECTATOR_LINEAR_SPEED);
                            }
                        }

                        //  Physical movement and rotation is based on constant time, therefore is indepedent of time delta
                        //  This formulas works even if FPS is low or high, or if step size is 1/10 or 1/10000
                        float amountOfMovement = MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * 100;
                        float amountOfRotation = 0.0025f * m_speedModeAngular;

                        if (MyFakes.ENABLE_DEVELOPER_SPECTATOR_CONTROLS)
                        {
                            rollIndicator = MyInput.Static.GetDeveloperRoll();
                        }

                        float rollAmount = 0;
                        if (rollIndicator != 0)
                        {
                            Vector3D r, u;
                            rollAmount = rollIndicator * m_speedModeAngular * 0.1f;
                            rollAmount = MathHelper.Clamp(rollAmount, -0.02f, 0.02f);
                            MyUtils.VectorPlaneRotation(m_orientation.Up, m_orientation.Right, out u, out r, rollAmount);
                            m_orientation.Right = r;
                            m_orientation.Up = u;
                        }

                        Vector3 moveVector;

                        if (MyPerGameSettings.RestrictSpectatorFlyMode && !MyFakes.ENABLE_DEVELOPER_SPECTATOR_CONTROLS)
                        {
                            // Spectator has constatnt speed (reset speed to default value)
                            SpeedModeLinear = 11 * MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;
                            if (MyInput.Static.IsAnyShiftKeyPressed())
                                SpeedModeLinear *= 5;

                            Vector3D forward = m_orientation.Forward;
                            double sinX = forward.Dot(ref Vector3D.Up);
                            double angleX = Math.Asin(sinX);
                            double angleY;
                            if (MyUtils.IsZero(sinX - 1f))
                            {
                                // Looking up
                                var up = m_orientation.Up;
                                angleY = Math.Atan2(up.Dot(ref Vector3D.Right), up.Dot(ref Vector3D.Backward));
                            }
                            else if (MyUtils.IsZero(sinX + 1f))
                            {
                                // Looking down
                                var up = m_orientation.Up;
                                angleY = Math.Atan2(up.Dot(ref Vector3D.Left), up.Dot(ref Vector3D.Forward));
                            }
                            else
                            {
                                // non-degenerate case
                                forward.Y = 0.0;
                                forward.Normalize();
                                angleY = Math.Atan2(forward.Dot(ref Vector3D.Left), forward.Dot(ref Vector3D.Forward));
                            }

                            angleX = MathHelper.Clamp(angleX - rotationIndicator.X * amountOfRotation, -MathHelper.PiOver2, MathHelper.PiOver2);

                            angleY -= rotationIndicator.Y * amountOfRotation;
                            if (angleY > MathHelper.Pi) angleY -= MathHelper.TwoPi;
                            if (angleY < -MathHelper.Pi) angleY += MathHelper.TwoPi;

                            m_orientation = MatrixD.CreateRotationX(angleX) * MatrixD.CreateRotationY(angleY);

                            moveIndicator *= SpeedModeLinear;
                            moveVector = moveIndicator * amountOfMovement;
                        }
                        else
                        {
                            if (!MyFakes.ENABLE_SPECTATOR_ROLL_MOVEMENT)
                            {   
                                // TODO: compute from current orientation matrix yaw/pitch/roll

                                rotationIndicator.Rotate(m_roll);

                                m_yaw -= rotationIndicator.Y * amountOfRotation;
                                m_pitch -= rotationIndicator.X * amountOfRotation;
                                m_roll -= rollAmount;                                                               

                                MathHelper.LimitRadians2PI(ref m_yaw);
                                m_pitch = MathHelper.Clamp(m_pitch, -Math.PI * 0.5f, Math.PI * 0.5f);
                                MathHelper.LimitRadians2PI(ref m_roll);                               

                                m_orientation = MatrixD.CreateFromYawPitchRoll(m_yaw, m_pitch, m_roll);                                
                            }
                            else
                            {
                                if (rotationIndicator.Y != 0)
                                {
                                    Vector3D r, f;
                                    MyUtils.VectorPlaneRotation(m_orientation.Right, m_orientation.Forward, out r, out f, -rotationIndicator.Y * amountOfRotation);

                                    m_orientation.Right = r;
                                    m_orientation.Forward = f;
                                }

                                if (rotationIndicator.X != 0)
                                {
                                    Vector3D u, f;
                                    MyUtils.VectorPlaneRotation(m_orientation.Up, m_orientation.Forward, out u, out f, rotationIndicator.X * amountOfRotation);
                                    m_orientation.Up = u;
                                    m_orientation.Forward = f;
                                }
                            }                                                

                            float afterburner = (MyInput.Static.IsAnyShiftKeyPressed() ? 1.0f : 0.35f) * (MyInput.Static.IsAnyCtrlKeyPressed() ? 0.3f : 1);
                            moveIndicator *= afterburner * SpeedModeLinear;
                            moveVector = moveIndicator * amountOfMovement;
                        }


                        Position += Vector3.Transform(moveVector, m_orientation);
                    }
                    break;
            }

        }
コード例 #12
0
        public static void WriteTestGCodeFile()
        {
            StringBuilder gcodeStringBuilder = new StringBuilder();

            int loops = 5;
            int steps = 200;
            double radius = 40;
            Vector2 center = new Vector2(50, 50);

            gcodeStringBuilder.AppendLine("G28 ; home all axes");
            gcodeStringBuilder.AppendLine("G90 ; use absolute coordinates");
            gcodeStringBuilder.AppendLine("G21 ; set units to millimeters");
            gcodeStringBuilder.AppendLine("G92 E0");
            gcodeStringBuilder.AppendLine("G1 F7800.000");
            gcodeStringBuilder.AppendLine("G1 Z" + (30).ToString());
            WriteMove(gcodeStringBuilder, center);

            for (int loop = 0; loop < loops; loop++)
            {
                for (int step = 0; step < steps; step++)
                {
                    Vector2 nextPosition = new Vector2(radius, 0);
                    nextPosition.Rotate(MathHelper.Tau / steps * step);
                    WriteMove(gcodeStringBuilder, center + nextPosition);
                }
            }

            gcodeStringBuilder.AppendLine("M84     ; disable motors");

            System.IO.File.WriteAllText("PerformanceTest.gcode", gcodeStringBuilder.ToString());
        }
コード例 #13
0
ファイル: Math.cs プロジェクト: artron33/PsmFramework
 /// <summary>Lerp 2 (assumed) unit vectors (shortest path).</summary>
 public static Vector2 LerpUnitVectors( Vector2 va, Vector2 vb, float x )
 {
     return va.Rotate( va.Angle( vb ) * x );
 }
コード例 #14
0
		public static Vector2 GetPrintLevelPositionToSample(int index, double radius)
		{
			if (index < 6)
			{
				Vector2 postion = new Vector2(radius, 0);
				postion.Rotate(MathHelper.Tau / 6 * index);
				return postion;
			}
			else
			{
				return new Vector2(0, 0);
			}
		}