コード例 #1
0
ファイル: Track.cs プロジェクト: GrJo/KSPPersistentTrails
        private bool sufficientChange(Waypoint newNode, RecordingThresholds thresholds)
        {
            if (waypoints.Count == 0)
                return true; //always add first waypoint

            //SourceVessel.GetSrfVelocity().sqrMagnitude < 0.5f

            if (Quaternion.Angle(waypoints.Last().orientation, newNode.orientation) > thresholds.minOrientationAngleChange )
            {
                //Debug.Log("orientation fulfilled");
                return true;
            }
            if (Vector3.Angle(waypoints.Last().velocity.normalized, newNode.velocity.normalized) > thresholds.minVelocityAngleChange)
            {
                //accept velocity direction changes only if we are actually moving
                if (newNode.velocity.sqrMagnitude > 0.5f)
                {
                    //Debug.Log("velocity fulfilled");
                    return true;
                }
            }
            float relativeSpeedChange = waypoints.Last().velocity.magnitude / newNode.velocity.magnitude;

            if (Mathf.Abs(1 - relativeSpeedChange) > thresholds.minSpeedChangeFactor)
            {
                //Debug.Log("speed fulfilled");
                return true;
            }

            return false;
        }
コード例 #2
0
ファイル: Track.cs プロジェクト: GrJo/KSPPersistentTrails
        //copy constructor
        public Waypoint(Waypoint other)
        {
            longitude = other.longitude;
            latitude = other.latitude;
            altitude = other.altitude;

            velocity = other.velocity;
            orientation = other.orientation;

            recordTime = other.recordTime;
        }
コード例 #3
0
ファイル: Track.cs プロジェクト: GrJo/KSPPersistentTrails
        //check thresholds and maybe add new node if sufficient change happened
        public void tryAddWaypoint(RecordingThresholds thresholds)
        {
            //Debug.Log("Track.addWaypoint");
            //Debug.Log("TrackDump: + " + serialized());
            Waypoint newNode = new Waypoint(SourceVessel);

            //only record if vessel is moving
            if (!sufficientChange(newNode, thresholds))
                return;

            //Vector3 velocity = SourceVessel.rigidbody.velocity;
            //Quaternion orientation = SourceVessel.rigidbody.rotation;

            //Debug.Log("adding waypoint to list");
            waypoints.Add(newNode);
            Modified = true;

            //add new point to renderer
            if (Visible && waypoints.Count % SamplingFactor == 0){
                int index = waypoints.Count / SamplingFactor - 1;
                lineRenderer.SetVertexCount(index + 1);

                Vector3 currentPos = this.referenceBody.GetWorldSurfacePosition(SourceVessel.latitude, SourceVessel.longitude, SourceVessel.altitude);
                lineRenderer.SetPosition(index, currentPos);

                //mapLineRenderer.SetVertexCount(index + 1);
                //mapLineRenderer.SetPosition(index, ScaledSpace.LocalToScaledSpace(currentPos));
                //this.renderCoords.Add(currentPos);
            }

            //Debug.Log("done");
        }