Click or drag to resize

PosAndRot Class

Type to hold position and rotation of a transform. It can be serialized.
Inheritance Hierarchy
SystemObject
  KSPDev.TypesPosAndRot

Namespace:  KSPDev.Types
Assembly:  KSPDev_Utils.1.2 (in KSPDev_Utils.1.2.dll) Version: 1.2 for KSP v1.6+
Syntax
C#
public sealed class PosAndRot : IPersistentField
Request Example View Source

The PosAndRot type exposes the following members.

Constructors
  NameDescription
Public methodPosAndRot
Constructs a default instance.
Public methodPosAndRot(PosAndRot)
Constructs a copy of an object of the same type.
Public methodPosAndRot(Vector3, Vector3)
Constructs an object from a transform properties.
Top
Properties
  NameDescription
Public propertyeuler
Euler rotation.
Public propertyrot
Orientation of the transform.
Top
Methods
  NameDescription
Public methodClone
Gives a deep copy of the object.
Public methodStatic memberFromString
Creates a new instance from the provided string.
Public methodCode exampleInverseTransform
Transforms the object from world space to local space of a reference transform.
Public methodParseFromString
Restores the object's state from a plain string.
Public methodSerializeToString
Returns the object's state as a plain string.
Public methodToString
Shows a human readable representation.
(Overrides ObjectToString.)
Public methodCode exampleTransform
Transforms the object from the world space to the local space of a reference transform.
Top
Fields
  NameDescription
Public fieldpos
Position of the transform.
Top
Remarks
The value serializes into 6 numbers separated by a comma. They form two triplets:
  • The first triplet is a position: x, y, z.
  • The second triplet is a Euler rotation around each axis: x, y, z.
Examples
public static void ToLocal() {
  var parent = new GameObject();
  parent.transform.position = Vector3.one;
  parent.transform.rotation = Quaternion.LookRotation(Vector3.up);
  var pr = new PosAndRot(Vector3.one, new Vector3(90, 0, 0));
  Debug.LogFormat("Local: {0}", parent.transform.InverseTransformPosAndRot(pr));
  Debug.LogFormat("World: {0}", pr);
}
public static void ToWorld() {
  var parent = new GameObject();
  parent.transform.position = Vector3.one;
  parent.transform.rotation = Quaternion.LookRotation(Vector3.up);
  var pr = new PosAndRot();
  Debug.LogFormat("Local: {0}", pr);
  Debug.LogFormat("World: {0}", parent.transform.TransformPosAndRot(pr));
}
See Also