private void UpdateRotation(DateTime time)
        {
            MyContract.RequireFieldNotNull(Maths, "Maths");

            DateTime TargetTime      = time + TimeOffset;
            double   RotationDegrees =
                Maths.current_stellar_day_rotation_progress(TargetTime)
                * 360.0;
            // negative because anti-clockwise
            float TargetRotation = Convert.ToSingle(-RotationDegrees);

            TargetRotation += AssetInitialPitchAndRoll.y;
            //Debug.Log("Target rotation: " + TargetRotation);
            float NeededRotation = TargetRotation
                                   - transform.localEulerAngles.y;

            transform.Rotate(transform.up, NeededRotation, Space.World);
        }
Example #2
0
        RotationRelativeToSunTest(double expected_angle,
                                  DateTime test_time,
                                  OrbitingBodyMathematics planet)
        {
            Vector3 planet_position
                = planet.current_location(test_time);

            Debug.Log("Planet position 3D: " + planet_position.ToString());
            Vector2 planet_position_2d
                = new Vector2(planet_position.x, planet_position.y);

            double rotation_progress
                = planet.current_stellar_day_rotation_progress(test_time);

            Debug.Log("Rotation progress: " + rotation_progress);
            Debug.Log("Anti-clockwise angle = " + (rotation_progress * 360.0));
            float angle_from_up = (float)rotation_progress * 2 * Mathf.PI;
            // angle is anti-clockwise due to earth's/solar system's rotation
            Vector2 rotation
                = new Vector2(Mathf.Sin(angle_from_up), Mathf.Cos(angle_from_up));

            Vector2 planet_normalised   = planet_position_2d / planet_position_2d.magnitude;
            Vector2 rotation_normalised = rotation / rotation.magnitude;

            Debug.Log("Planet vector: " + planet_normalised.ToString());
            Debug.Log("Rotation vector: " + rotation_normalised.ToString());

            double actual_angle
                = Vector2.Angle(planet_normalised, rotation_normalised);

            double acceptable_error = 0.1;
            double actual_error
                = Math.Abs(actual_angle
                           - expected_angle);

            string error_message = differing_results_error_message(
                Convert.ToString(actual_angle),
                Convert.ToString(expected_angle),
                "degrees"
                );

            Assert.LessOrEqual(actual_error, acceptable_error, error_message);
        }
Example #3
0
        RotationAbsoluteTest(double expected_rotation_progress,
                             DateTime test_time,
                             OrbitingBodyMathematics planet)
        {
            double actual_rotation_progress
                = planet.current_stellar_day_rotation_progress(test_time);

            double acceptable_error = 0.001;
            double actual_error
                = Math.Abs(actual_rotation_progress
                           - expected_rotation_progress);
            string error_message = differing_results_error_message(
                Convert.ToString(actual_rotation_progress),
                Convert.ToString(expected_rotation_progress),
                ""
                );

            Assert.LessOrEqual(actual_error, acceptable_error, error_message);
        }