Ejemplo n.º 1
0
        Vector3 findCenterOfDrag()
        {
            Profiler.BeginSample("[RCSBA] CoD findCenterOfDrag");
            Cd       = 0f;
            position = Vector3.zero;

            /* setup parachutes */
            switch (RCSBuildAid.Mode)
            {
            case PluginMode.Parachutes:
                var parachutes = RCSBuildAid.Parachutes;
                for (int i = 0; i < parachutes.Count; i++)
                {
                    var parachute = (ModuleParachute)parachutes [i];
                    var part      = parachute.part;
                    var dc        = part.DragCubes;
#if DEBUG
                    var vector = parachute.GetComponent <VectorGraphic> ();
                    if (vector == null)
                    {
                        vector = parachute.gameObject.AddComponent <VectorGraphic> ();
                        vector.setColor(Color.blue);
                        vector.minLength = 0.6f;
                    }
#endif
                    dc.SetCubeWeight("DEPLOYED", 1);
                    dc.SetCubeWeight("SEMIDEPLOYED", 0);
                    dc.SetCubeWeight("PACKED", 0);
                    dc.SetOcclusionMultiplier(0);

                    /* I need to do all this since parachute's drag depends of the
                     * orientation of the canopy */
                    Transform t = part.FindModelTransform(parachute.canopyName);
                    t.rotation = Quaternion.LookRotation(-VelocityDirection, part.transform.forward);
                    if (part.symmetryCounterparts != null)
                    {
                        float angle = Mathf.Clamp(parachute.spreadAngle * (part.symmetryCounterparts.Count + 1), 0, 45);
                        t.Rotate(angle, 0, 0, Space.Self);
                    }
                    var rotation = Quaternion.LookRotation(part.partTransform.InverseTransformDirection(t.forward));
                    dc.SetDragVectorRotation(rotation);
#if DEBUG
                    vector.value = part.partTransform.InverseTransformDirection(dc.DragVector) * dc.AreaDrag;
#endif
                }
                break;
            }

            EditorUtils.RunOnVesselParts(calculateDrag);
            EditorUtils.RunOnSelectedParts(calculateDrag);

            position /= (float)Cd;
            Cd       *= PhysicsGlobals.DragMultiplier * reynoldsDragMult;
            Profiler.EndSample();
            return(position);
        }
Ejemplo n.º 2
0
        protected override Vector3 UpdatePosition()
        {
            vectorSum = Vector3.zero;
            totalMass = 0f;

            EditorUtils.RunOnVesselParts(calculateCoM);
            EditorUtils.RunOnSelectedParts(calculateCoM);

            // ReSharper disable once CompareOfFloatsByEqualityOperator
            if (totalMass == 0)
            {
                return(Vector3.zero);
            }

            return(vectorSum / totalMass);
        }
Ejemplo n.º 3
0
        void LateUpdate()
        {
            Profiler.BeginSample("[RCSBA] MoI LateUpdate");
            if (!RCSBuildAid.Enabled)
            {
                Profiler.EndSample();
                return;
            }
            axis = RCSBuildAid.VesselForces.Torque().normalized;
            if (axis == Vector3.zero || EditorLogic.RootPart == null)
            {
                /* no torque, calculating this is meaningless */
                Profiler.EndSample();
                return;
            }
            value = 0f;

            EditorUtils.RunOnVesselParts(calculateMoI);
            EditorUtils.RunOnSelectedParts(calculateMoI);
            Profiler.EndSample();
        }