public void ReadServerAPI()
    {
        // memoryBridge.CoMD = memoryBridge.GetVector3("CoMD" + memoryBridge.fileName);
        memoryBridge.CurrentCOM   = memoryBridge.GetVector3("CurrentCOM" + memoryBridge.fileName);
        memoryBridge.LocalCOM     = memoryBridge.GetVector3("LocalCOM" + memoryBridge.fileName);
        memoryBridge.Acceleration = memoryBridge.GetVector3("Acceleration" + memoryBridge.fileName);
        memoryBridge.obt_velocity = memoryBridge.GetVector3("obt_velocity" + memoryBridge.fileName);
        memoryBridge.srf_velocity = memoryBridge.GetVector3("srf_velocity" + memoryBridge.fileName);

        memoryBridge.altitude           = memoryBridge.GetFloat("altitude" + memoryBridge.fileName);
        memoryBridge.heightFromTerrain  = memoryBridge.GetFloat("heightFromTerrain" + memoryBridge.fileName);
        memoryBridge.horizontalSrfSpeed = memoryBridge.GetFloat("horizontalSrfSpeed" + memoryBridge.fileName);
        memoryBridge.latitude           = memoryBridge.GetFloat("latitude" + memoryBridge.fileName);
        memoryBridge.longitude          = memoryBridge.GetFloat("longitude" + memoryBridge.fileName);
        memoryBridge.mach = memoryBridge.GetFloat("mach" + memoryBridge.fileName);

        memoryBridge.srfSpeed           = memoryBridge.GetFloat("srfSpeed" + memoryBridge.fileName);
        memoryBridge.terrainAltitude    = memoryBridge.GetFloat("terrainAltitude" + memoryBridge.fileName);
        memoryBridge.verticalSpeed      = memoryBridge.GetFloat("verticalSpeed" + memoryBridge.fileName);
        memoryBridge.currentStage       = memoryBridge.GetFloat("currentStage" + memoryBridge.fileName);
        memoryBridge.geeForce_immediate = memoryBridge.GetFloat("geeForce_immediate" + memoryBridge.fileName);
        memoryBridge.heightFromSurface  = memoryBridge.GetFloat("heightFromSurface" + memoryBridge.fileName);
        memoryBridge.obt_speed          = memoryBridge.GetFloat("obt_speed" + memoryBridge.fileName);

        memoryBridge.directSunlight = memoryBridge.GetBool("directSunlight" + memoryBridge.fileName);
        memoryBridge.Landed         = memoryBridge.GetBool("Landed" + memoryBridge.fileName);
        memoryBridge.loaded         = memoryBridge.GetBool("loaded" + memoryBridge.fileName);
        memoryBridge.Splashed       = memoryBridge.GetBool("Splashed" + memoryBridge.fileName);
    }
Exemplo n.º 2
0
    public void CheckClearance()
    {
        if (IKactive)//& legMode == LegMode.Translate)
        {
            //limbMirror.contactPoint.position = limbMirror.servoWrist.transform.TransformPoint(memoryBridge.GetVector3(limbMirror.servoWrist.servoName + "CollisionPoint"));
            // limbIK.contactPoint.position = limbIK.servoWrist.transform.TransformPoint(memoryBridge.GetVector3(limbMirror.servoWrist.servoName + "CollisionPoint"));
        }
        torque             = memoryBridge.GetVector3(limbMirror.servoWrist.servoName + "torque");
        velocity           = torque.magnitude;
        explosionPotential = memoryBridge.GetFloat(limbMirror.servoWrist.servoName + "explosionPotential");
        gExplodeChance     = memoryBridge.GetFloat(limbMirror.servoWrist.servoName + "gExplodeChance");
        footActive         = memoryBridge.GetBool(limbMirror.servoWrist.servoName + "active");
        hasExploded        = memoryBridge.GetBool(limbMirror.servoWrist.servoName + "exploded");

        if (hasExploded)
        {
            CamUI.SetCamText(name + " has exploded");
            Debug.LogError("Exploded Leg : " + name + " Velocity : " + velocity + " Mode : " + limbIK.gaitSequenceMode.ToString() + " Percent : " + CalculateStridePercent());
        }

        rawClearance = memoryBridge.GetFloat(limbMirror.servoWrist.servoName + "KSPFootClearance");
        //if(limbMirror.limbEnd == null)
        //{
        //    Debug.Log("end point null");
        //}
        var contactPointOffSet = limbMirror.servoWrist.transform.position.y - limbMirror.trueLimbEnd.position.y;

        footClearance = rawClearance - contactPointOffSet;
        if (footClearance < .03f)
        {
            footClearance = 0;
        }
        groundContact = memoryBridge.GetBool(limbMirror.servoWrist.servoName + "GroundContact");

        //if (!collisionPoint)
        //{
        //    collisionPoint = new GameObject("CollisionPoint").transform;
        //   // DebugVector.DrawVector(collisionPoint, DebugVector.Direction.all, .5f, .1f, Color.red, Color.white, Color.blue);
        //}
        //collisionPoint.position = limbMirror.servoWrist.transform.TransformPoint(memoryBridge.GetVector3(limbMirror.servoWrist.servoName + "CollisionPoint"));

        // limbMirror.
        //if(limbIK)


        //if (!groundContact)
        // ground.position = limbMirror.servoWrist.transform.position - new Vector3(0, rawClearance, 0);
        var localPoint = limbMirror.limbEnd.localPosition - new Vector3(0, .4f, 0);

        ground.position = limbMirror.servoWrist.transform.TransformPoint(localPoint) - new Vector3(0, rawClearance, 0);
    }
    public void VesselUpdate()
    {
        var vesselOffst = memoryBridge.GetVector3("AdjustedVesselCOMoffset" + memoryBridge.fileName);

        vessel.meshOffset.localPosition         = vesselOffst;
        targetVessel.vesselOffset.localPosition = vesselOffst;

        var kspOffset = memoryBridge.GetQuaternion("VesselGimbleOffset" + memoryBridge.fileName);

        vessel.transform.rotation = kspOffset;

        adjustedGimbal.rotation = vessel.transform.rotation;

        var tempRot = adjustedGimbal.localRotation;

        tempRot.x = 0;
        tempRot.z = 0;
        adjustedGimbal.localRotation = tempRot;

        if (controlMode == FlightControlMode.RawStick)
        {
            targetVessel.vessel.rotation = adjustedGimbal.rotation;

            System.TimeSpan deltaTime = TimeSpan.FromSeconds(Time.fixedDeltaTime);

            bool recievingPitchInput = false;
            bool recievingRollInput  = false;
            bool recievingYawInput   = false;

            var rollInput  = Input.GetAxis("Roll");
            var pitchInput = Input.GetAxis("Pitch");
            var yawInput   = Input.GetAxis("Yaw");

            //  Debug.Log(pitcInput);

            if (rollInput != 0)
            {
                recievingRollInput = true;
            }
            if (pitchInput != 0)
            {
                recievingPitchInput = true;
            }
            if (yawInput != 0)
            {
                recievingYawInput = true;
            }

            // var tempVesselRot = targetVessel.vessel.transform.rotation;
            if (recievingYawInput)
            {
                memoryBridge.SetFloat("VesselYaw", yawInput);
                // tempVesselRot.y = mirrorVessel.vessel.transform.rotation.y;
            }
            else
            {
                memoryBridge.SetFloat("VesselYaw", 1.1f);
            }
            if (recievingPitchInput)
            {
                memoryBridge.SetFloat("VesselPitch", pitchInput);
                // tempVesselRot.x = mirrorVessel.vessel.transform.rotation.x;
            }
            else
            {
                memoryBridge.SetFloat("VesselPitch", 1.1f);
            }
            if (recievingRollInput)
            {
                memoryBridge.SetFloat("VesselRoll", rollInput);
                // tempVesselRot.z = mirrorVessel.vessel.transform.rotation.z;
            }
            else
            {
                memoryBridge.SetFloat("VesselRoll", 1.1f);
            }
            //  targetVessel.vessel.transform.rotation = tempVesselRot;

            var targetVesselOffset = Quaternion.Inverse(targetVessel.vessel.rotation) * vessel.transform.rotation;

            //if (rollInput > 0 & Math.Abs(rollInput) <= 1)
            //{
            //    memoryBridge.SetFloat("VesselRoll", rollInput);
            //}
            //else
            //{
            //    memoryBridge.SetFloat("VesselRoll", PIDroll.CalculateResult(targetVesselOffset.z * 10, deltaTime));
            //}

            //memoryBridge.SetFloat("VesselPitch", pitchInput);
            //memoryBridge.SetFloat("VesselYaw", yawInput);

            // var targetVesselOffset = targetVessel.vessel.localEulerAngles - mirrorVessel.vessel.localEulerAngles;

            //   Debug.Log(targetVesselOffset);



            // memoryBridge.SetFloat("VesselPitch", PIDpitch.CalculateResult(targetVesselOffset.x * 10, deltaTime));
        }


        //  memoryBridge.SetFloat("VesselYaw", PIDyaw.CalculateResult(targetVesselOffset.y, deltaTime));

        //var rawRoll = targetVesselOffset.x;
        //float rollError = 0;

        //if (rawRoll > 180)
        //{
        //    rollError = 360 - rawRoll;
        //}
        //else
        //{
        //    rollError = -rawRoll;
        //}



        //if (autoPilot)
        //{
        //    //Debug.Log(Quaternion.Angle(adjustedGimbal.rotation, transform.rotation));
        //    var targetAngle = Quaternion.Angle(adjustedGimbal.rotation, transform.rotation);
        //    if (targetAngle < 3 & !vesselInRange)
        //    {
        //        OnVesselEnterTargerRange();
        //    }
        //    if (targetAngle >= 3 & vesselInRange)
        //    {
        //        OnVesselExitTargetRange();
        //    }
        //}
    }