コード例 #1
0
ファイル: Part.cs プロジェクト: dewiniaid/krpc
 public Tuple3 CenterOfMass(ReferenceFrame referenceFrame)
 {
     if (ReferenceEquals(referenceFrame, null))
     {
         throw new ArgumentNullException("referenceFrame");
     }
     return(referenceFrame.PositionFromWorldSpace(InternalPart.CenterOfMass()).ToTuple());
 }
コード例 #2
0
 public Tuple3 Position(ReferenceFrame referenceFrame)
 {
     if (ReferenceEquals(referenceFrame, null))
     {
         throw new ArgumentNullException(nameof(referenceFrame));
     }
     return(referenceFrame.PositionFromWorldSpace(InternalPart.transform.position).ToTuple());
 }
コード例 #3
0
ファイル: DockingPort.cs プロジェクト: zentarul/krpc
 public Tuple3 Position(ReferenceFrame referenceFrame)
 {
     if (ReferenceEquals(referenceFrame, null))
     {
         throw new ArgumentNullException("referenceFrame");
     }
     return(referenceFrame.PositionFromWorldSpace(port.nodeTransform.position).ToTuple());
 }
コード例 #4
0
        /// <summary>
        /// Computes the axis-aligned bounding box for a part in the given reference frame.
        /// </summary>
        /// <remarks>
        /// This is an expensive calculation. It iterates over the parts collider meshes
        /// to compute a tight axis-aligned bounding box.
        /// It does not use part.collider.bounds, as this is aligned to world space and
        /// would not provide a tight bounding box in the given reference frame.
        /// </remarks>
        public static Bounds GetBounds(this Part part, ReferenceFrame referenceFrame)
        {
            var colliders = part.GetComponentsInChildren <MeshCollider> ();
            var bounds    = new Bounds(referenceFrame.PositionFromWorldSpace(part.WCoM), Vector3.zero);

            foreach (var collider in colliders)
            {
                var vertices = collider.sharedMesh.bounds.ToVertices();
                for (int i = 0; i < vertices.Length; i++)
                {
                    // part space -> world space -> reference frame space
                    var vertex = referenceFrame.PositionFromWorldSpace(collider.transform.TransformPoint(vertices [i]));
                    bounds.Encapsulate(vertex);
                }
            }
            return(bounds);
        }
コード例 #5
0
        /// <summary>
        /// Computes the axis-aligned bounding box for a part in the given reference frame.
        /// </summary>
        /// <remarks>
        /// This is an expensive calculation. It iterates over the parts collider meshes
        /// to compute a tight axis-aligned bounding box.
        /// It does not use part.collider.bounds, as this is aligned to world space and
        /// would not provide a tight bounding box in the given reference frame.
        /// </remarks>
        public static Bounds GetBounds(this Part part, ReferenceFrame referenceFrame)
        {
            var bounds = new Bounds(referenceFrame.PositionFromWorldSpace(part.WCoM), Vector3.zero);
            var meshes = part.GetComponentsInChildren <MeshFilter> ();

            for (int i = 0; i < meshes.Length; i++)
            {
                var mesh     = meshes [i];
                var vertices = mesh.mesh.bounds.ToVertices();
                for (int j = 0; j < vertices.Length; j++)
                {
                    // mesh space -> world space -> reference frame space
                    var vertex = referenceFrame.PositionFromWorldSpace(mesh.transform.TransformPoint(vertices [j]));
                    bounds.Encapsulate(vertex);
                }
            }
            return(bounds);
        }
コード例 #6
0
ファイル: Thruster.cs プロジェクト: thinkyfish/krpc
 public Tuple3 GimbalPosition(ReferenceFrame referenceFrame)
 {
     if (ReferenceEquals(referenceFrame, null))
     {
         throw new ArgumentNullException(nameof(referenceFrame));
     }
     CheckGimballed();
     return(referenceFrame.PositionFromWorldSpace(gimbal.gimbalTransforms [transformIndex].position).ToTuple());
 }
コード例 #7
0
ファイル: Thruster.cs プロジェクト: thinkyfish/krpc
        public Tuple3 InitialThrustPosition(ReferenceFrame referenceFrame)
        {
            if (ReferenceEquals(referenceFrame, null))
            {
                throw new ArgumentNullException(nameof(referenceFrame));
            }
            StashGimbalRotation();
            var position = WorldTransform.position;

            RestoreGimbalRotation();
            return(referenceFrame.PositionFromWorldSpace(position).ToTuple());
        }
コード例 #8
0
ファイル: SpaceCenter.cs プロジェクト: krpc/krpc
 public static Tuple3 TransformPosition (Tuple3 position, ReferenceFrame from, ReferenceFrame to)
 {
     CheckReferenceFrames (from, to);
     return to.PositionFromWorldSpace (from.PositionToWorldSpace (position.ToVector ())).ToTuple ();
 }
コード例 #9
0
 public Tuple3 Position(ReferenceFrame referenceFrame)
 {
     return(referenceFrame.PositionFromWorldSpace(InternalPart.transform.position).ToTuple());
 }
コード例 #10
0
 public Tuple3 Position(ReferenceFrame referenceFrame)
 {
     return(referenceFrame.PositionFromWorldSpace(port.nodeTransform.position).ToTuple());
 }