Esempio n. 1
0
        public void TestExplicitOperator()
        {
            var rad = new Radian(1.0f);

              Assert.AreEqual((Radian)1.0f, rad);
              Assert.AreEqual(1.0f, (float)rad);
        }
Esempio n. 2
0
        /**
         * @param margin Collision margin
         * @param switchingMode Determine the state of the camera when switching to this camera mode from another
         */
        public FreeCameraMode(CameraControlSystem cam
              , Vector3 initialPosition
              , Degree initialRotationX
              , Degree initialRotationY
              , SwitchingMode switchingMode = SwitchingMode.CurrentState
              , float margin = 0.1f)
            : base(cam)
        {
            CameraCS = cam;
            Margin = margin;

            _fixedAxis = Vector3.UNIT_Y;
            _moveFactor = 1;
            _rotationFactor = 0.13f;
            _rotX = initialRotationX;
            _rotY = initialRotationY;
            _initialPosition = initialPosition;
            _initialRotationX = initialRotationX;
            _initialRotationY = initialRotationY;
            _lastRotationX = initialRotationX;
            _lastRotationY = initialRotationY;
            _lastPosition = initialPosition;
            _switchingMode = switchingMode;

            CameraPosition = initialPosition;

            this.CollisionFunc = this.DefaultCollisionDetectionFunction;
        }
Esempio n. 3
0
        /**
         * @param relativePositionToCameraTarget Default camera position with respecto to camera target
         * @param autoResetTime If greater than zero the camera will be resetted to its initial position after the amount of seconds specified.
         * @param resetDistance true for correcting the camera distance to the target when resetting. If false, the camera will maintaing the current distance to target.
         * @param resetRotationFactor Speed factor for correcting the camera rotation when resetting.
         * @param offset Offset applied to the center of the sphere.
         */
        public SphericCameraMode(CameraControlSystem cam
             , Vector3 relativePositionToCameraTarget
             , float outerSphereRadius
            , Vector3 offset
             , Vector3 fixedAxis, float innerSphereRadius = 0.0f
             , float autoResetTime = 3.0f
             , bool resetDistance = true
             , float resetRotationFactor = 1.0f)
            : base(cam)
        {
            _relativePositionToCameraTarget = relativePositionToCameraTarget;
            _outerSphereRadius = outerSphereRadius;
            _innerSphereRadius = innerSphereRadius;
            _autoResetTime = autoResetTime;
            _resetDistance = resetDistance;
            _resetRotationFactor = resetRotationFactor;
            _offset = offset;
            _fixedAxis = fixedAxis;
            _resseting = false;
            _LastRessetingDiff = new Radian(2.0f * Mogre.Math.PI);

            if (innerSphereRadius > outerSphereRadius) { throw new Exception("Inner radious greater than outer radious"); }
            if (innerSphereRadius > relativePositionToCameraTarget.Length
                || outerSphereRadius < relativePositionToCameraTarget.Length) {
                throw new Exception("relativePositionToCameraTarget param value not valid.");
            }
        }
Esempio n. 4
0
 public virtual void SetCameraOrientation(Radian roll, Radian yaw, Radian pitch)
 {
     _lastOrientation = new Quaternion(roll, Vector3.UNIT_Z)
         * new Quaternion(yaw, Vector3.UNIT_Y)
         * new Quaternion(pitch, Vector3.UNIT_X);
     CameraOrientation = _lastOrientation;
 }
Esempio n. 5
0
        public override void MakeOrthoMatrix(Radian fov, Real aspectRatio, Real near, Real far, out Matrix4 dest, bool forGpuPrograms)
        {
            float thetaY = Utility.DegreesToRadians(fov / 2.0f);
            float tanThetaY = Utility.Tan(thetaY);
            float tanThetaX = tanThetaY * aspectRatio;

            float halfW = tanThetaX * near;
            float halfH = tanThetaY * near;

            var w = 1.0f / (halfW);
            var h = 1.0f / (halfH);
            var q = 0.0f;

            if (far != 0)
            {
                q = 1.0f / (far - near);
            }

            dest = Matrix4.Zero;
            dest.m00 = w;
            dest.m11 = h;
            dest.m22 = q;
            dest.m23 = -near / (far - near);
            dest.m33 = 1;

            if (forGpuPrograms)
            {
                dest.m22 = -dest.m22;
            }
        }
		public override void MakeOrthoMatrix( Radian fovy, Real aspectRatio, Real near, Real far, out Matrix4 dest,
		                                      bool forGpuPrograms )
		{
			var thetaY = fovy/2.0f;
			var tanThetaY = Utility.Tan( thetaY );
			var tanThetaX = tanThetaY*aspectRatio;

			var half_w = tanThetaX*near;
			var half_h = tanThetaY*near;

			var iw = 1.0f/( half_w );
			var ih = 1.0f/( half_h );
			Real q = 0.0f;

			if ( far != 0 )
			{
				q = 1.0/( far - near );
			}

			dest = Matrix4.Zero;
			dest.m00 = iw;
			dest.m11 = ih;
			dest.m22 = q;
			dest.m23 = -near/( far - near );
			dest.m33 = 1;

			if ( forGpuPrograms )
			{
				dest.m22 = -dest.m22;
			}
		}
        /// <summary>
        /// Creates a Rotater. This removes any existing nlerpers and rotaters attached to the lthing.
        /// </summary>
        /// <param name="owner">What lthing are we affecting?</param>
        /// <param name="duration">How long as we going to rotate?</param>
        /// <param name="angle">Rotation angle</param>
        /// <param name="mode">Rotation axis mode</param>
        /// <returns>The new rotater</returns>
        public Rotater CreateRotater(LThing owner, float duration, Radian angle, RotaterAxisMode mode)
        {
            RemoveRotater(owner);

            Rotater newRotater = new Rotater(owner, duration, angle, mode);
            Rotaters.TryAdd(owner, newRotater);
            return newRotater;
        }
Esempio n. 8
0
 /// <summary>
 /// Constructor to create a new Euler Angle struct from angle values. 
 /// The rotation will be applied in the order Yaw-Pitch- Roll, which are related to the axis order Y-X-Z. 
 /// </summary>
 public Euler(Radian yaw, Radian pitch, Radian roll)
 {
     mYaw = yaw;
     mPitch = pitch;
     mRoll = roll;
     mChanged = true;
     mCachedQuaternion = Quaternion.IDENTITY;
 }
 public OrbitalWithMouseCameraMode(CameraControlSystem cam
      , MOIS.MouseButtonID activateButton
      , Radian initialHorizontalRotation
      , Radian initialVerticalRotation, float initialZoom = 1)
     : base(cam, initialHorizontalRotation, initialVerticalRotation, initialZoom)
 {
     _activateButton = activateButton;
 }
Esempio n. 10
0
 public Sprite(Texture texture)
 {
     Texture = texture;
     Color = Color.White;
     Position = Vector2.Zero;
     Scale = new Vector2(1.0f, 1.0f);
     Rotation = new Radian(0.0f);
     SourceRect = new Rectangle(0, 0, Texture.Width, Texture.Height);
 }
        /// <summary>
        /// Creates a Rotater. This removes any existing nlerpers and rotaters attached to the lthing.
        /// </summary>
        /// <param name="owner">What lthing are we affecting?</param>
        /// <param name="duration">How long as we going to rotate?</param>
        /// <param name="angle">Rotation angle</param>
        /// <param name="axis">Axis of rotation</param>
        /// <param name="mode">Rotation axis mode</param>
        /// <returns>The new rotater</returns>
        public Rotater CreateRotater(LThing owner, float duration, Radian angle, Vector3 axis, RotaterAxisMode mode = RotaterAxisMode.Explicit)
        {
            RemoveRotater(owner);
            RemoveNlerper(owner);

            Rotater newRotater = new Rotater(owner, duration, angle, axis, mode);
            Rotaters.TryAdd(owner, newRotater);
            return newRotater;
        }
Esempio n. 12
0
        public void TestEquatable()
        {
            var rad = new Radian(1.0f);
              var f = 1.0f;

              Assert.IsTrue(rad.Equals(rad));
              Assert.IsTrue(rad.Equals(f));
              Assert.IsFalse(rad.Equals(null));
        }
Esempio n. 13
0
			public override void SetDesiredVelocity( Radian velocity, float maxTorque )
			{
				if( joint.jointID == dJointID.Zero )
					return;

				Ode.dJointSetHingeParam( joint.jointID, Ode.dJointParams.dParamVel,
					joint.Body1.Static ? velocity : -velocity );
				Ode.dJointSetHingeParam( joint.jointID, Ode.dJointParams.dParamFMax, maxTorque );
			}
Esempio n. 14
0
        public override void Update(int elapsed)
        {
            float rotateFactor = elapsed * 0.125f / 1000.0f;
            var yawAmount = new Radian((0.4f + 0.25f * MathUtils.Sin(new Radian(this.game.TotalGameTime / 15040))) * rotateFactor);
            Yaw(yawAmount);
            var pitchAmount = new Radian((0.35f + 0.212f * MathUtils.Cos(new Radian(this.game.TotalGameTime / 38040))) * rotateFactor);

            float moveFactor = elapsed * 27.5f / 1000.0f;
            MoveRelative(Vector3.UnitZ * moveFactor);
        }
        public virtual void SetCameraRelativePosition(Vector3 posRelativeToCameraTarget
            , Radian roll, Radian yaw, Radian pitch)
        {
            RelativePosToTarget = posRelativeToCameraTarget;

            _rotationOffset = new Quaternion(roll, Vector3.UNIT_Z)
                            * new Quaternion(yaw, Vector3.UNIT_Y)
                            * new Quaternion(pitch, Vector3.UNIT_X);

            InstantUpdate();
        }
Esempio n. 16
0
        protected override void Rotate(Radian yawAngle, Radian pitchAngle)
        {
            base.Rotate(yawAngle,pitchAngle);

            var debugOverlay = OverlayManager.Singleton.GetByName("Core/DebugOverlay");
            debugOverlay.Show();

            var myCurr = OverlayManager.Singleton.GetOverlayElement("Core/CurrFps");

            myCurr.Caption = State.CameraManager.RenderWindow.LastFPS.ToString();
        }
Esempio n. 17
0
        public void Radian_Wrap_Test()
        {
            var radian = new Radian(MathUtils.PI);
            var wrapAngle = new Radian(MathUtils.PI);
            Assert.AreEqual(new Radian(0.0f), radian.Wrap(wrapAngle));

            radian = new Radian(MathUtils.PI / 4);
            Assert.AreEqual(new Radian(MathUtils.PI / 4), radian.Wrap(wrapAngle));

            radian = new Radian(-MathUtils.PI / 4);
            Assert.AreEqual(new Radian(MathUtils.PI * 3 / 4), radian.Wrap(wrapAngle));
        }
Esempio n. 18
0
        /// <summary>
        /// USE THE LThingHelperManager FOR THIS!
        /// </summary>
        public Rotater(LThing thingToRotate, float duration, Radian angle, Vector3 axis, RotaterAxisMode mode = RotaterAxisMode.Explicit)
        {
            this.thing = thingToRotate;
            this.duration = duration;
            this.angle = angle;
            this.axis = axis;
            this.mode = mode;

            orient = new Quaternion();

            PhysicsMain.PreSimulate += PreSimulate;
        }
Esempio n. 19
0
        protected void initLampPost(SceneNode parent, Vector3 position, Radian direction)
        {
            Entity    lamp;
            SceneNode lampNode;
            int       id = LevelView.PropCounter;

            lamp             = sceneMgr.CreateEntity("Lamp" + id, "LampPost.mesh");
            lamp.CastShadows = EngineConfig.ShadowsQuality > 0;

            lampNode = parent.CreateChildSceneNode("LampNode" + LevelView.PropCounter, position);
            lampNode.Yaw(direction);
            lampNode.AttachObject(lamp);
        }
        public void ToStringTest()
        {
            Radian angle = new Radian(1.23);

            Assert.AreEqual(angle.ToString(), 1.23.ToString());

            Assert.AreEqual(angle.ToString("N3"), 1.23.ToString("N3"));

            System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.CreateSpecificCulture("de-DE");
            Assert.AreEqual(angle.ToString(culture), 1.23.ToString(culture));

            Assert.AreEqual(angle.ToString("N3", culture), 1.23.ToString("N3", culture));
        }
        public void DivisionTest()
        {
            Radian angle1 = new Radian(6.0);
            Radian result = angle1 / 3.0;

            double delta = result - 2.0;

            if (delta < 0.0)
            {
                delta *= -1;
            }
            Assert.IsTrue(delta <= double.Epsilon);
        }
Esempio n. 22
0
        /// <summary>
        /// Causes a walking animation to occur.
        /// </summary>
        public void Walking()
        {
            radius    = 0.1f;
            direction = Vector3.ZERO;
            angle     = 0f;

            time = new Timer();
            ///PrintAnimationName();
            animationChanged = false;
            animationName    = "Walk";
            LoadAnimation();
            Console.WriteLine("Walking Animation!");
        }
Esempio n. 23
0
        public override void Rotate(Radian yawAngle, Radian pitchAngle)
        {
            var xAxis = new Vector3();
            var yAxis = new Vector3();
            var zAxis = new Vector3();

            Body.Orientation.ToAxes(out xAxis, out yAxis, out zAxis);
            //            var yaw = new Quaternion(yawAngle, Vector3.UNIT_Y);
            //            var pitch = new Quaternion(pitchAngle, xAxis);

            var data = Body.UserData as PhysicsControlData;
            data.Torque += (yAxis * yawAngle.ValueRadians + xAxis * pitchAngle.ValueRadians)/5.0f;
        }
Esempio n. 24
0
        public void Shooting(FrameEvent evt)
        {
            radius    = 0.01f;
            direction = Vector3.ZERO;
            angle     = 0f;

            time             = new Timer();
            animationChanged = false;
            animationName    = "Shoot";
            LoadAnimation();

            AnimationMesh(evt);
        }
Esempio n. 25
0
        /// <summary>
        /// This method set up all the field needed for animation
        /// </summary>
        private void AnimationSetup()
        {
            radius    = 0.01f;        //f = floating point number
            direction = Vector3.ZERO; // 0 0 0
            angle     = 0f;


            time = new Timer();
            PrintAnimationNames();
            animationChanged = false;
            animationName    = "Walk"; //animation name in the skeleton file
            LoadAnimation();
        }
Esempio n. 26
0
        private static void DrawSphericalJoint(SphericalJoint joint)
        {
            Vector3 target = GetAnchor(joint, JointBody.Target);
            Vector3 anchor = GetAnchor(joint, JointBody.Anchor);
            Vector3 center = target;

            Rigidbody rigidbody = joint.GetBody(JointBody.Target);

            if (rigidbody != null)
            {
                center = rigidbody.SceneObject.Position;
            }

            Gizmos.Color = Color.White;
            Gizmos.DrawSphere(center, 0.05f);

            Gizmos.Color = Color.Yellow;
            Gizmos.DrawSphere(target, 0.05f);
            Gizmos.DrawSphere(anchor, 0.05f);

            Gizmos.Color = Color.Green;
            Gizmos.DrawLine(target, center);

            Gizmos.Color = Color.Green;
            if (joint.HasFlag(SphericalJointFlag.Limit))
            {
                LimitConeRange limit = joint.Limit;

                Radian zAngle = MathEx.Min(new Degree(360), limit.zLimitAngle * 2.0f);
                Radian yAngle = MathEx.Min(new Degree(360), limit.yLimitAngle * 2.0f);

                Gizmos.Transform = joint.SceneObject.WorldTransform;
                Gizmos.DrawWireArc(Vector3.Zero, Vector3.ZAxis, 0.25f, zAngle * -0.5f + new Degree(90), zAngle);
                Gizmos.DrawWireArc(Vector3.Zero, Vector3.YAxis, 0.25f, yAngle * -0.5f + new Degree(90), yAngle);

                Gizmos.Color = Color.Red;
                Radian remainingZAngle = new Degree(360) - zAngle;
                Radian remainingYAngle = new Degree(360) - yAngle;

                Gizmos.DrawWireArc(Vector3.Zero, Vector3.ZAxis, 0.25f, zAngle * 0.5f + new Degree(90), remainingZAngle);
                Gizmos.DrawWireArc(Vector3.Zero, Vector3.YAxis, 0.25f, yAngle * 0.5f + new Degree(90), remainingYAngle);
            }
            else
            {
                Gizmos.Color     = Color.Green;
                Gizmos.Transform = joint.SceneObject.WorldTransform;

                Gizmos.DrawWireDisc(Vector3.Zero, Vector3.ZAxis, 0.25f);
                Gizmos.DrawWireDisc(Vector3.Zero, Vector3.YAxis, 0.25f);
            }
        }
        /// Builds the shape
        public Shape realizeShape()
        {
            Radian alpha = Math.ACos((mLengthB * mLengthB + mLengthC * mLengthC - mLengthA * mLengthA) / (2 * mLengthB * mLengthC));

            Shape s = new Shape();

            s.addPoint(0.0f, 0.0f);
            s.addPoint(Math.Cos(alpha) * mLengthB, Math.Sin(alpha) * mLengthB);
            s.addPoint(mLengthC, 0.0f);
            s.close();
            s.translate((Math.Cos(alpha) * mLengthB + mLengthC) / -3.0f, mLengthB / -3.0f);

            return(s);
        }
Esempio n. 28
0
        private void AnimationSetup()
        {
            radius    = 0.01f;
            direction = Vector3.ZERO;
            angle     = 0f;

            #region Part2: Uncomment for Part 3 of Lab 2
            time = new Timer();
            PrintAnimationNames();
            animationChanged = false;
            animationName    = "Walk";
            LoadAnimation();
            #endregion
        }
Esempio n. 29
0
        // NH & KEEN - reworked the homing function for better accuracy
        private void MomentaryTurnToPositionUpdate(Vec3 turnToPosition)
        {
            if (targetBody != null)
            {
                turnToPosition = targetBody.Position;

                if (targetShape != null)
                {
                    turnToPosition += (targetShape.Position * targetBody.Rotation);
                }

                if (Type.HomingPrediction > 0.0f)
                {
                    float flyTime = (turnToPosition - Position).Length() / Type.Velocity;

                    turnToPosition += targetBody.LinearVelocity * flyTime * Type.HomingPrediction;
                }
            }

            Vec3 diff = (turnToPosition - Position);

            Degree horizontalAngle = new Radian(-MathFunctions.ATan(diff.Y, diff.X)).InDegrees();
            Degree verticalAngle   = new Radian(MathFunctions.ATan(diff.Z, diff.ToVec2().Length())).InDegrees();

            Quat collisionRotation = new Angles(0, 0, horizontalAngle).ToQuat();

            collisionRotation *= new Angles(0, verticalAngle, 0).ToQuat();

            Radian targetAngle = Quat.GetAngle(Rotation, collisionRotation);

            float PI = (float)Math.PI;

            if (targetAngle > PI)
            {
                targetAngle = (2 * PI) - targetAngle;
            }

            Radian maxTurnAbility = Type.HomingCorrection.InRadians() * TickDelta;

            if (targetAngle > maxTurnAbility)
            {
                float relativeCorrection = maxTurnAbility / targetAngle;

                Rotation = Quat.Slerp(Rotation, collisionRotation, relativeCorrection);
            }
            else
            {
                Rotation = collisionRotation;
            }
        }
Esempio n. 30
0
        static Quaternion GlobalEulerToQuat(Radian rotX, Radian rotY, Radian rotZ)
        {
            Quaternion q1 = new Quaternion(),
                       q2 = new Quaternion(),
                       q3 = new Quaternion(),
                       q = new Quaternion();
            q1.FromAngleAxis(rotX, Vector3.UNIT_X);
            q2.FromAngleAxis(rotY, Vector3.UNIT_Y);
            q3.FromAngleAxis(rotZ, Vector3.UNIT_Z);

            // global axes
            q = q3 * q2 * q1;
            return q;
        }
Esempio n. 31
0
        public void Radian_Constructor_Test()
        {
            var r = new Radian();
            Assert.AreEqual(0.0f, r.Value);

            r = new Radian(3.14f);
            Assert.AreEqual(3.14f, r.Value);

            var r2 = new Radian(r);
            Assert.AreEqual(r.Value, r2.Value);

            var r3 = r;
            Assert.AreEqual(r.Value, r3.Value);
        }
Esempio n. 32
0
        public override void Rotate(Radian yawAngle, Radian pitchAngle)
        {
            var xAxis = new Vector3();
            var yAxis = new Vector3();
            var zAxis = new Vector3();

            Body.Orientation.ToAxes(out xAxis, out yAxis, out zAxis);
//            var yaw = new Quaternion(yawAngle, Vector3.UNIT_Y);
//            var pitch = new Quaternion(pitchAngle, xAxis);

            var data = Body.UserData as PhysicsControlData;

            data.Torque += (yAxis * yawAngle.ValueRadians + xAxis * pitchAngle.ValueRadians) / 5.0f;
        }
            public void PlaneAngleUnits()
            {
                Cycles cycles  = (Cycles)1.0;
                Radian radians = (Radian)cycles;
                Degree degrees = (Degree)radians;
                Grad   grads   = (Grad)degrees;

                cycles = (Cycles)grads;

                Assert.AreEqual((Radian)(2.0 * Math.PI), radians, "Cycles-to-Radian conversion failed");
                Assert.AreEqual((Degree)360.0, degrees, "Radian-to-Degree conversion failed");
                Assert.AreEqual((Grad)400.0, grads, "Degree-to-Grad conversion failed");
                Assert.AreEqual((Cycles)1.0, cycles, "Grad-to-Cycles conversion failed");
            }
Esempio n. 34
0
        void Server_TickSendWeaponVerticalAngleToClients()
        {
            Vec3  diff  = TurnToPosition - Position;
            float angle = -MathFunctions.ATan(diff.Z, diff.ToVec2().Length());

            MathFunctions.Clamp(ref angle, -MathFunctions.PI / 2, MathFunctions.PI / 2);

            if (Math.Abs(server_sentWeaponVerticalAngle - angle) > .01f)
            {
                Server_SendWeaponVerticalAngleToClients(EntitySystemWorld.Instance.RemoteEntityWorlds,
                                                        angle);
                server_sentWeaponVerticalAngle = angle;
            }
        }
Esempio n. 35
0
        public void PanGestureDetectorClearAngles()
        {
            tlog.Debug(tag, $"PanGestureDetectorClearAngles START");
            PanGestureDetector a1 = new PanGestureDetector();

            Radian angle = new Radian(4);

            a1.AddAngle(angle);

            a1.ClearAngles();

            tlog.Debug(tag, $"PanGestureDetectorClearAngles END (OK)");
            Assert.Pass("PanGestureDetectorClearAngles");
        }
Esempio n. 36
0
            void SnapAngle(ref Radian angle)
            {
                //snapping
                Degree snapDegree = Owner.GetSnapRotate();

                if (snapDegree != 0)
                {
                    Radian snap = snapDegree.InRadians();
                    angle += snap / 2;
                    angle /= snap;
                    angle  = (int)angle;
                    angle *= snap;
                }
            }
Esempio n. 37
0
        public void PanGestureDetectorRemoveDirection()
        {
            tlog.Debug(tag, $"PanGestureDetectorRemoveDirection START");
            PanGestureDetector a1 = new PanGestureDetector();

            Radian angle = new Radian(4);

            a1.AddDirection(angle);

            a1.RemoveDirection(angle);

            tlog.Debug(tag, $"PanGestureDetectorRemoveDirection END (OK)");
            Assert.Pass("PanGestureDetectorClearAngles");
        }
Esempio n. 38
0
        public NodeAnimation(List <SceneNode> nodes, float animationDuration, string name, Radian cycleLength)
        {
            if (animationDuration <= 0)
            {
                animationDuration = 1;
            }
            this.nodes       = nodes;
            duration         = animationDuration;
            this.name        = name;
            this.cycleLength = cycleLength;

            amplitudeAtEnd   = animationFunction((float)cycleLength.ValueRadians);
            amplitudeAtStart = animationFunction(0);
        }
Esempio n. 39
0
        public static PointF2D[] RotateAroundPoint(Radian angle, PointF2D center, PointF2D[] points)
        {
            double num1 = System.Math.Sin(angle.Value);
            double num2 = System.Math.Cos(angle.Value);

            PointF2D[] pointF2DArray = new PointF2D[points.Length];
            for (int index = 0; index < points.Length; ++index)
            {
                double x = center[0] + (num2 * (points[index][0] - center[0]) + num1 * (points[index][1] - center[1]));
                double y = center[1] + (-num1 * (points[index][0] - center[0]) + num2 * (points[index][1] - center[1]));
                pointF2DArray[index] = new PointF2D(x, y);
            }
            return(pointF2DArray);
        }
Esempio n. 40
0
        /// <summary>
        /// Converts euler angles to quaternion
        /// </summary>
        /// <param name="YAngle">Yaw-Angle</param>
        /// <param name="XAngle">Pitch-Angle</param>
        /// <param name="ZAngle">Roll-Angle</param>
        /// <returns>orientation</returns>
        private Quaternion EulerAnglesToQuaternion(Degree YAngle, Degree XAngle, Degree ZAngle)
        {
            Radian radToYaw   = new Radian(YAngle);
            Radian radToPitch = new Radian(XAngle);
            Radian radToRoll  = new Radian(ZAngle);

            Quaternion orientation = Quaternion.IDENTITY;

            orientation *= new Quaternion(radToYaw, Vector3.UNIT_Y);
            orientation *= new Quaternion(radToPitch, Vector3.UNIT_X);
            orientation *= new Quaternion(radToRoll, Vector3.UNIT_Z);

            return(orientation);
        }
Esempio n. 41
0
        public void PanGestureDetectorGetAngleCount()
        {
            tlog.Debug(tag, $"PanGestureDetectorGetAngleCount START");
            PanGestureDetector a1 = new PanGestureDetector();

            Radian angle = new Radian(4);

            a1.AddAngle(angle);

            a1.GetAngleCount();

            tlog.Debug(tag, $"PanGestureDetectorGetAngleCount END (OK)");
            Assert.Pass("PanGestureDetectorAddDirection");
        }
Esempio n. 42
0
        public override object ConvertFromInvariantString(string value)
        {
            // public Rotation(Radian radian(float), Vector3 vector3)
            // Default: <View Orientation="45.0,12,13,0" />
            // Oritation="D:23, 0, 0, 1"
            // Oritation="R:23, 0, 0, 1"
            if (value != null)
            {
                string[] parts = value.Split(',');
                if (parts.Length == 4)
                {
                    bool     useDefault = true;
                    Radian   radian     = null;
                    string[] head       = parts[0].Trim().Split(':');
                    if (head.Length == 2)
                    {
                        useDefault = false;
                        string radianOrDegree = head[0].Trim().ToUpperInvariant();
                        if (radianOrDegree == "D" || radianOrDegree == "DEGREE")
                        {
                            // Oritation="D:23, 0, 0, 1"
                            radian = new Radian(new Degree(Single.Parse(head[1].Trim(), CultureInfo.InvariantCulture)));
                        }
                        else if (radianOrDegree == "R" || radianOrDegree == "RADIAN")
                        {
                            // Oritation="R:23, 0, 0, 1"
                            radian = new Radian(Single.Parse(head[1].Trim(), CultureInfo.InvariantCulture));
                        }
                        else
                        {
                            throw new InvalidOperationException($"Cannot convert the first parameter \"{value}\" into Radian of {typeof(Rotation)}");
                        }
                    }

                    if (useDefault)
                    {
                        // Default: <View Orientation="45.0,12,13,0" />
                        radian = new Radian(Single.Parse(parts[0].Trim(), CultureInfo.InvariantCulture));
                    }

                    Vector3 vector3 = new Vector3(Single.Parse(parts[1].Trim(), CultureInfo.InvariantCulture),
                                                  Single.Parse(parts[2].Trim(), CultureInfo.InvariantCulture),
                                                  Single.Parse(parts[3].Trim(), CultureInfo.InvariantCulture));
                    return(new Rotation(radian, vector3));
                }
            }

            throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Rotation)}");
        }
Esempio n. 43
0
            public override Radian GetAngle()
            {
                if (joint.jointID == IntPtr.Zero)
                {
                    return(0);
                }

                Radian value = Ode.dJointGetAMotorAngle(joint.aMotorID, index - 1);

                if (joint.Body1.Static)
                {
                    value = -value;
                }
                return(value);
            }
Esempio n. 44
0
        public Kart(ThingBlock block, ThingDefinition def)
            : base(block, def)
        {
            DefaultMaxSpeed = MaxSpeed = def.GetFloatProperty("maxspeed", 180f);
            MaxReverseSpeed = def.GetFloatProperty("maxreversespeed", 4f);

            MaxSpeedSquared = MaxSpeed * MaxSpeed;
            MaxReverseSpeedSquared = MaxReverseSpeed * MaxReverseSpeed;

            IsInAir = false;

            FrontDriftAngle = new Degree(def.GetFloatProperty("FrontDriftAngle", 46)).ValueRadians;
            BackDriftAngle = new Degree(def.GetFloatProperty("BackDriftAngle", 55)).ValueRadians;
            DriftTransitionAngle = new Degree(def.GetFloatProperty("DriftTransitionAngle", 40));
        }
Esempio n. 45
0
        /// <summary>
        /// Rotates a set of points around another around point with a given angle clockwise.
        /// </summary>
        /// <returns>The around point.</returns>
        /// <param name="angle">Angle.</param>
        /// <param name="center">Center.</param>
        /// <param name="points">Points.</param>
        public static PointF2D[] RotateAroundPoint(Radian angle, PointF2D center, PointF2D[] points)
        {
            double sin = System.Math.Sin(angle.Value);
            double cos = System.Math.Cos(angle.Value);

            PointF2D[] rotated = new PointF2D[points.Length];
            for (int idx = 0; idx < points.Length; idx++)
            {
                double newX = center [0] + (cos * (points[idx] [0] - center[0]) + sin * (points[idx] [1] - center [1]));
                double newY = center [1] + (-sin * (points[idx] [0] - center[0]) + cos * (points[idx] [1] - center [1]));

                rotated[idx] = new PointF2D(newX, newY);
            }
            return(rotated);
        }
Esempio n. 46
0
        public void DegreeConstructorWithRadian()
        {
            tlog.Debug(tag, $"DegreeConstructorWithRadian START");

            using (Radian radian = new Radian(1.0f))
            {
                var testingTarget = new Degree(radian);
                Assert.IsNotNull(testingTarget, "null handle");
                Assert.IsInstanceOf <Degree>(testingTarget, "Should return Degree instance.");

                testingTarget.Dispose();
            }

            tlog.Debug(tag, $"DegreeConstructorWithRadian END (OK)");
        }
Esempio n. 47
0
        public void RadianValue()
        {
            tlog.Debug(tag, $"RadianValue START");

            var testingTarget = new Radian(10.0f);

            Assert.IsNotNull(testingTarget, "null handle");
            Assert.IsInstanceOf <Radian>(testingTarget, "Should return Radian instance.");

            testingTarget.Value = 30.0f;
            Assert.AreEqual(30.0f, testingTarget.Value, "radian function does not work, return error value");

            testingTarget.Dispose();
            tlog.Debug(tag, $"RadianValue END (OK)");
        }
Esempio n. 48
0
        public Meter DistanceReal(GeoCoordinate point)
        {
            Meter  meter   = (Meter)6371000.0;
            Radian radian1 = (Radian) new Degree(this.Latitude);
            Radian radian2 = (Radian) new Degree(this.Longitude);
            Radian radian3 = (Radian) new Degree(point.Latitude);
            Radian radian4 = (Radian) new Degree(point.Longitude);
            double num1    = (radian3 - radian1).Value;
            Radian radian5 = radian2;
            double num2    = (radian4 - radian5).Value;
            double d       = System.Math.Pow(System.Math.Sin(num1 / 2.0), 2.0) + System.Math.Cos(radian1.Value) * System.Math.Cos(radian3.Value) * System.Math.Pow(System.Math.Sin(num2 / 2.0), 2.0);
            double num3    = 2.0 * System.Math.Atan2(System.Math.Sqrt(d), System.Math.Sqrt(1.0 - d));

            return((Meter)(meter.Value * num3));
        }
Esempio n. 49
0
        public void RadianConstructorWithDegree()
        {
            tlog.Debug(tag, $"RadianConstructorWithDegree START");

            using (Degree degree = new Degree())
            {
                var testingTarget = new Radian(degree);
                Assert.IsNotNull(testingTarget, "null handle");
                Assert.IsInstanceOf <Radian>(testingTarget, "Should return Radian instance.");

                testingTarget.Dispose();
            }

            tlog.Debug(tag, $"RadianConstructorWithDegree END (OK)");
        }
Esempio n. 50
0
        public void SetLookDirection(Vec3 pos)
        {
            Vec2 diff = pos.ToVec2() - Position.ToVec2();

            if (diff == Vec2.Zero)
            {
                return;
            }

            Radian dir = MathFunctions.ATan16(diff.Y, diff.X);

            float halfAngle = dir * 0.5f;
            Quat  rot       = new Quat(new Vec3(0, 0, MathFunctions.Sin16(halfAngle)), MathFunctions.Cos16(halfAngle));

            Rotation = rot;
        }
Esempio n. 51
0
        public PolarPoint <TRadius, TAngle> ToPolar <TRadius, TAngle>(AngleRange range)
            where TRadius : LinearUnit, new()
            where TAngle : AngularUnit, new()
        {
            TRadius radius = new TRadius();

            double tempX = this.X.ChangeTo <TRadius>().Value;

            double tempY = this.Y.ChangeTo <TRadius>().Value;

            radius.Value = Math.Sqrt(tempX * tempX + tempY * tempY);

            Radian angle = new Radian(Math.Atan2(tempY, tempX), range);                  //use tempX and tempY

            return(new PolarPoint <TRadius, TAngle>(radius, angle.ChangeTo <TAngle>())); //do not need to cast!
        }
Esempio n. 52
0
        public void PanGestureDetectorAddDirection()
        {
            tlog.Debug(tag, $"PanGestureDetectorAddDirection START");
            PanGestureDetector a1 = new PanGestureDetector();

            Radian angle     = new Radian(4);
            Radian threshold = new Radian(15);

            a1.AddDirection(angle);

            a1.AddDirection(angle, threshold);


            tlog.Debug(tag, $"PanGestureDetectorAddDirection END (OK)");
            Assert.Pass("PanGestureDetectorAddDirection");
        }
Esempio n. 53
0
        public void Radian_Operators_Test()
        {
            Assert.AreEqual(new Radian(1.0f),  +new Radian(1.0f));
            Assert.AreEqual(new Radian(3.0f),  new Radian(1.0f) + new Radian(2.0f));
            Assert.AreEqual(new Radian(-1.0f), -new Radian(1.0f));
            Assert.AreEqual(new Radian(-1.0f), new Radian(1.0f) - new Radian(2.0f));
            Assert.AreEqual(new Radian(3.0f),  new Radian(1.0f) * 3);
            Assert.AreEqual(new Radian(3.0f),  3 * new Radian(1.0f));
            Assert.AreEqual(new Radian(3.0f),  new Radian(1.0f) * new Radian(3.0f));
            Assert.AreEqual(new Radian(1.5f),  new Radian(3.0f) / 2);

            Radian r1 = new Radian(1.0f);
            Assert.AreEqual(new Radian(3.0f), r1 += new Radian(2.0f));
            Assert.AreEqual(new Radian(2.0f), r1 -= new Radian(1.0f));
            Assert.AreEqual(new Radian(4.0f), r1 *= 2);
            Assert.AreEqual(new Radian(2.0f), r1 /= 2);
        }
Esempio n. 54
0
 public OrbitalCameraMode(CameraControlSystem cam, Radian initialHorizontalRotation,
      Radian initialVerticalRotation, float initialZoom = 1
      , bool resetToInitialPosition = true, float collisionmargin = 0.1f)
     : base(cam, Vector3.ZERO, new Radian(0), new Radian(0), new Radian(0), collisionmargin)
 {
     _zoomFactor = 1;
     _rotationFactor = 0.13f;
     _initialRotHorizontal = initialHorizontalRotation;
     _initialRotVertical = initialVerticalRotation;
     _initialZoom = initialZoom;
     _zoom = initialZoom;
     _rotHorizontal = 0;
     _rotVertical = 0;
     _zoomDisplacement = 0;
     _resetToInitialPosition = resetToInitialPosition;
     this.CameraTightness = 1;
 }
Esempio n. 55
0
        public RTSCameraMode(CameraControlSystem cam, Vector3 initialPosition, Vector3 upAxis, Vector3 leftAxis, Radian cameraPitch, float minZoom = 0, float maxZoom = 0)
            : base(cam)
        {
            _upAxis = upAxis.NormalisedCopy;
            _leftAxis = leftAxis.NormalisedCopy;
            _moveFactor = 1;
            _cameraPitch = cameraPitch;
            _minZoom = minZoom;
            _maxZoom = maxZoom;
            _zoom = 0;

            _rotation = new Quaternion(cameraPitch, leftAxis);
            _heightAxis = -upAxis.CrossProduct(leftAxis).NormalisedCopy;
            CameraPosition = initialPosition;

            _heightDisplacement = 0;
            _lateralDisplacement = 0;
            _verticalDisplacement = 0;
        }
Esempio n. 56
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="vc"></param>
 /// <param name="height"></param>
 /// <param name="radius"></param>
 /// <param name="alpha"></param>
 /// <param name="beta"></param>
 /// <param name="numberOfBlocks"></param>
 /// <param name="na"></param>
 /// <param name="nb"></param>
 /// <param name="nc"></param>
 public GeometryManager(VClouds vc,
     Vector2 height, float radius,
     Radian alpha, Radian beta,
     int numberOfBlocks, int na, int nb, int nc)
 {
     _vclouds = vc;
     this.IsCreated = false;
     _height = height;
     _radius = radius;
     _alpha = alpha;
     _beta = beta;
     _phie = Utility.TWO_PI / (float)numberOfBlocks;
     _numberOfBlocks = numberOfBlocks;
     _na = na;
     _nb = nb;
     _nc = nc;
     _worldOffset = new Vector2(0, 0);
     _lastCameraPosition = Vector3.ZERO;
 }
Esempio n. 57
0
        public void Sprite_Transform_Test()
        {
            var sprite = CreateSprite();

            Assert.AreEqual(Vector2.Zero, sprite.Position);
            var newPos = new Vector2(1.0f, 2.0f);
            sprite.Position = newPos;
            Assert.AreEqual(newPos, sprite.Position);

            Assert.AreEqual(new Vector2(1.0f, 1.0f), sprite.Scale);
            var newScale = new Vector2(0.5f, 2.0f);
            sprite.Scale = newScale;
            Assert.AreEqual(newScale, sprite.Scale);

            Assert.AreEqual(new Radian(0.0f), sprite.Rotation);
            var newRotation = new Radian(MathUtils.PI);
            sprite.Rotation = newRotation;
            Assert.AreEqual(newRotation, sprite.Rotation);
        }
Esempio n. 58
0
        public void Matrix3_CreateFromYawPitchRoll_Test()
        {
            Radian yaw = new Radian(MathUtils.PI / 6),
                   pitch = new Radian(MathUtils.PI / 5),
                   roll = new Radian(MathUtils.PI / 4);
            var actual = Matrix3.CreateFromYawPitchRoll(yaw, pitch, roll);

            float cos = MathUtils.Cos(new Radian(yaw));
            float sin = MathUtils.Sin(new Radian(yaw));
            var yMat = new Matrix3(cos, 0, -sin, 0, 1, 0, sin, 0, cos);

            cos = MathUtils.Cos(new Radian(pitch));
            sin = MathUtils.Sin(new Radian(pitch));
            var xMat = new Matrix3(1, 0, 0, 0, cos, sin, 0, -sin, cos);

            cos = MathUtils.Cos(new Radian(roll));
            sin = MathUtils.Sin(new Radian(roll));
            var zMat = new Matrix3(cos, sin, 0, -sin, cos, 0, 0, 0, 1);

            Assert.AreEqual(zMat * xMat * yMat, actual);
        }
        //indexers
        //explicit and implicit conversion

         //just for the sake of programming
        //Degree to Radian is implicit
        //Radian to Degree is explicit
        public void execute()
        {
            
            ClassA X = new ClassA();
            X[3] = 10;
            Debug.Log(X);
            
            Radian x = new Radian();
            x.value = Math.PI * 2;

            Degree degree = (Degree)x;
            Debug.Log(degree.value);

            Degree degree360 = new Degree();
            degree360.value = 360;

            Radian radian360 = degree360;//implicit
            Debug.Log(radian360.value);//2 Pi


        }
Esempio n. 60
0
        public override void MakeProjectionMatrix(Radian fov, Real aspectRatio, Real near, Real far, out Matrix4 dest, bool forGpuProgram)
        {
            float theta = Utility.DegreesToRadians((float)fov * 0.5f);
            float h = 1.0f / Utility.Tan(theta);
            float w = h / aspectRatio;
            float q, qn;

            if (far == 0)
            {
                q = 1 - Frustum.InfiniteFarPlaneAdjust;
                qn = near * (Frustum.InfiniteFarPlaneAdjust - 1);
            }
            else
            {
                q = far / (far - near);
                qn = -q * near;
            }

            dest = Matrix4.Zero;

            dest.m00 = w;
            dest.m11 = h;

            if (forGpuProgram)
            {
                dest.m22 = -q;
                dest.m32 = -1.0f;
            }
            else
            {
                dest.m22 = q;
                dest.m32 = 1.0f;
            }

            dest.m23 = qn;
        }