Click or drag to resize

PosAndRotExtensions Class

Helper extensions to deal with PosAndRot type.
Inheritance Hierarchy
SystemObject
  KSPDev.ExtensionsPosAndRotExtensions

Namespace:  KSPDev.Extensions
Assembly:  KSPDev_Utils.1.2 (in KSPDev_Utils.1.2.dll) Version: 1.2 for KSP v1.6+
Syntax
C#
public static class PosAndRotExtensions
Request Example View Source

The PosAndRotExtensions type exposes the following members.

Methods
  NameDescription
Public methodStatic memberCode exampleInverseTransformPosAndRot
Transforms a pos&rot object from the world space to the local space. The opposite to TransformPosAndRot(Transform, PosAndRot).
Public methodStatic memberSetPosAndRot
Sets position and rotation in one call.///
Public methodStatic memberCode exampleTransformPosAndRot
Transforms a pos&rot object from the local space to the world space. The opposite to InverseTransformPosAndRot(Transform, PosAndRot).
Top
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