Exemplo n.º 1
0
        public CelestialBody(Universe universe)
        {
            position = new Vector3();
            rotation = new Quaternion();

            radius = 0;

            mass = 0;
            gravParameter = 0;

            this.universe = universe;
        }
Exemplo n.º 2
0
        public void update(global::Vessel vessel)
        {
            centerOfMass = new Vector3(vessel.findWorldCenterOfMass());

            mass = 0;
            torque = new Vector3(0, 0, 0);
            momentumOfInertia = new Vector3(0, 0, 0);
            angularMomentum = new Vector3(0, 0, 0);

            foreach(Part p in vessel.parts)
            {
                if (p.physicalSignificance != Part.PhysicalSignificance.NONE)
                {
                    double partMass = p.mass + p.GetResourceMass();
                    mass += partMass;
                }

                if (p is CommandPod)
                {
                    torque = torque + Vector3.one * Math.Abs(((CommandPod)p).rotPower);
                }

                foreach (PartModule pm in p.Modules)
                {
                    if (!pm.isEnabled) continue;

                    if (pm is ModuleReactionWheel)
                    {
                        ModuleReactionWheel rw = (ModuleReactionWheel)pm;
                        if (rw.wheelState == ModuleReactionWheel.WheelState.Active)
                        {
                            torque = torque + new Vector3(rw.PitchTorque, rw.RollTorque, rw.YawTorque);
                        }
                    }
                }
            }

            var inertiaTensor = new Matrix3x3();

            foreach (Part p in vessel.parts)
            {
                if (p.Rigidbody == null) continue;

                Vector3d principalMoments = p.Rigidbody.inertiaTensor;
                UnityEngine.Quaternion princAxesRot = UnityEngine.Quaternion.Inverse(vessel.GetTransform().rotation) * p.transform.rotation * p.Rigidbody.inertiaTensorRotation;
                UnityEngine.Quaternion invPrincAxesRot = UnityEngine.Quaternion.Inverse(princAxesRot);

                for (int i = 0; i < 3; i++)
                {
                    Vector3d iHat = Vector3d.zero;
                    iHat[i] = 1;
                    for (int j = 0; j < 3; j++)
                    {
                        Vector3d jHat = Vector3d.zero;
                        jHat[j] = 1;
                        inertiaTensor[i, j] += Vector3d.Dot(iHat, princAxesRot * Vector3d.Scale(principalMoments, invPrincAxesRot * jHat));
                    }
                }

                double partMass = p.mass + p.GetResourceMass();
                UnityEngine.Vector3 partPosition = vessel.GetTransform().InverseTransformDirection(p.Rigidbody.worldCenterOfMass - centerOfMass.unity);

                for (int i = 0; i < 3; i++)
                {
                    inertiaTensor[i, i] += partMass * partPosition.sqrMagnitude;

                    for (int j = 0; j < 3; j++)
                    {
                        inertiaTensor[i, j] += -partMass * partPosition[i] * partPosition[j];
                    }
                }
            }

            momentumOfInertia = new Vector3(inertiaTensor[0, 0], inertiaTensor[2, 2], inertiaTensor[1, 1]);

            Vector3 angularVelocity = new Quaternion(vessel.GetTransform().rotation).inverse * new Vector3(vessel.rigidbody.angularVelocity);

            angularMomentum = inertiaTensor * angularVelocity;
            angularMomentum = new Vector3(angularMomentum.x, angularMomentum.z, angularMomentum.y);
        }
Exemplo n.º 3
0
 public void updateState(global::Vessel vessel)
 {
     _rootRotation = new Quaternion(vessel.GetTransform().rotation);
 }
Exemplo n.º 4
0
        public void update(global::Vessel vessel)
        {
            body.update(vessel);
            orbit.update(vessel.orbit, Planetarium.GetUniversalTime());

            _rootRotation = new Quaternion(vessel.GetTransform().rotation);

            _rotatingFrameVelocity = new Vector3(vessel.mainBody.getRFrmVel(position.unity));

            gravity = new Vector3(FlightGlobals.getGeeForceAtPosition(position.unity));

            altitude = vessel.mainBody.GetAltitude(position.unity);

            UnityEngine.RaycastHit sfc;
            if (UnityEngine.Physics.Raycast(position.unity, -up.unity, out sfc, (float)altitude + 10000.0F, 1 << 15))
            {
                altitude = sfc.distance;
            }
            else if (vessel.mainBody.pqsController != null)
            {
                altitude -= (vessel.mainBody.pqsController.GetSurfaceHeight(UnityEngine.QuaternionD.AngleAxis(vessel.mainBody.GetLongitude(position.unity), Vector3d.down) * UnityEngine.QuaternionD.AngleAxis(vessel.mainBody.GetLatitude(position.unity), Vector3d.forward) * Vector3d.right) - vessel.mainBody.pqsController.radius);
            }

            double altitudeASL = vessel.mainBody.GetAltitude(position.unity);

            double atmosphericPressure = FlightGlobals.getStaticPressure(altitudeASL, vessel.mainBody);
            if (atmosphericPressure < vessel.mainBody.atmosphereMultiplier * 1e-6) atmosphericPressure = 0;

            atmosphericDensity = FlightGlobals.getAtmDensity(atmosphericPressure);

            //parts (info for rcs, engines, intakes, tanks)
        }
Exemplo n.º 5
0
        public Vessel(Universe universe)
        {
            _rootRotation = new Quaternion();
            _rotatingFrameVelocity = new Vector3();
            gravity = new Vector3();

            orbit = new math.Orbit(universe);
            body = new RigidBody();
        }
Exemplo n.º 6
0
        protected override void onSetup(Screen screen)
        {
            window.area.set(300, 500, 400, 150);
            content.views.clear();

            _sensetivity = new Selector(0.1f, 1, 10, "Sensetivity");
            _inertia = new Selector(1, 1, 10, "Inertia");

            content.views.add(_sensetivity.view);

            _controller = new PIDControllerV(10000, 0, 800, -1000000, 1000000);

            target = Quaternion.identity;

            controlYaw = Control.No;
            controlPitch = Control.No;
            controlRoll = Control.No;
        }
Exemplo n.º 7
0
        public void update(global::CelestialBody body)
        {
            name = body.GetName();

            position = new Vector3(body.position);
            rotation = new Quaternion(body.rotation);

            radius = body.Radius;

            mass = body.Mass;
            gravParameter = body.gravParameter;
        }