public TransMemberCurve(string propName, Ease ease, float dur, Trans start, Trans end, bool slerp) : base(propName, ease, dur) { _start = start; _end = end; _useSlerp = slerp; }
public TransMemberCurve(string propName, float dur, Trans start, Trans end) : base(propName, dur) { _start = start; _end = end; _useSlerp = false; }
public Vector3 GetForce(Trans forceOrigin, Trans forceTarget) { switch (_direction) { case ForceDirection.Relative: return (forceTarget.Position - forceOrigin.Position).normalized * _strength; case ForceDirection.Random: return RandomUtil.Standard.OnUnitSphere() * _strength; case ForceDirection.Forward: return forceOrigin.Forward * _strength; } return Vector3.zero; }
public static Quaternion InverseTransformRotation(Trans t, Quaternion rot) { //return rot * Quaternion.Inverse(t.Rotation); return Quaternion.Inverse(t.Rotation) * rot; }
public void ApplyForce(Trans forceOrigin, Rigidbody body) { var force = this.GetForce(forceOrigin, Trans.GetGlobal(body.transform)); body.AddForce(force, _forceMode); }
public static void LocalTransposeAroundAnchor(this Transform trans, Trans anchor, Vector3 position, Quaternion rotation) { var anchorPos = rotation * Vector3.Scale(anchor.Position, trans.localScale); trans.localPosition = position - anchorPos; trans.localRotation = anchor.Rotation * rotation; }
/// <summary> /// Set the position and rotation of a Transform as if its origin were that of 'anchor'. /// Anchor should be in world space. /// </summary> /// <param name="trans">The transform to transpose.</param> /// <param name="anchor">The point around which to transpose in world space.</param> /// <param name="position">The new position in world space.</param> /// <param name="rotation">The new rotation in world space.</param> public static void TransposeAroundGlobalAnchor(this Transform trans, Trans anchor, Vector3 position, Quaternion rotation) { //anchor.Matrix *= trans.worldToLocalMatrix; anchor.Matrix = trans.worldToLocalMatrix * anchor.Matrix; if (trans.parent != null) { position = trans.parent.InverseTransformPoint(position); rotation = trans.parent.InverseTransformRotation(rotation); } LocalTransposeAroundAnchor(trans, anchor, position, rotation); }
public static Trans InverseTransformTrans(this Trans t, Trans t2) { t2.Matrix *= t.Matrix.inverse; return t2; }
public static Trans TransformTrans(this Transform t, Trans t2) { t2.Matrix *= t.localToWorldMatrix; return t2; }
public static Sphere FromMesh(Mesh mesh, BoundingSphereAlgorithm algorithm, Trans transform) { if (mesh == null) return new Sphere(); var arr = mesh.vertices; if (arr.Length > 0) { for (int i = 0; i < arr.Length; i++) { arr[i] = transform.TransformPoint(arr[i]); } return FromPoints(arr, algorithm); } else { return new Sphere(); } }
public static Sphere FromCollider(Collider c, bool local = false) { if (c is SphereCollider) { return(FromCollider(c as SphereCollider, local)); } else if (c is CapsuleCollider) { return(FromCollider(c as CapsuleCollider, local)); } else if (GeomUtil.DefaultBoundingSphereAlgorithm != BoundingSphereAlgorithm.FromBounds && c is MeshCollider) { return(FromMesh((c as MeshCollider).sharedMesh, GeomUtil.DefaultBoundingSphereAlgorithm, Trans.GetGlobal(c.transform))); } else { var bounds = AABBox.FromCollider(c, local); return(new Sphere(bounds.Center, bounds.Extents.magnitude)); } }
public static bool IsNaN(Trans t) { return(VectorUtil.IsNaN(t.Position) || VectorUtil.IsNaN(t.Scale) || QuaternionUtil.IsNaN(t.Rotation)); }
protected override void ReflectiveInit(object start, object end, object option) { _start = (start is Trans) ? (Trans)start : Trans.Identity; _end = (end is Trans) ? (Trans)end : Trans.Identity; _useSlerp = ConvertUtil.ToBool(option); }
/// <summary> /// Apply a transform to a Trans. /// </summary> /// <param name="m"></param> /// <param name="t"></param> /// <returns></returns> public static Trans TransformTrans(this Matrix4x4 m, Trans t) { t.Matrix *= m; return t; }
public static Trans Transform(Matrix4x4 mat) { var t = new Trans(); t.Matrix = mat; return t; }
public static Trans TransformTrans(this Trans t, Trans t2) { t2.Matrix *= t.Matrix; return t2; }
public static Trans GetLocal(Transform trans) { var t = new Trans(); t.Position = trans.localPosition; t.Rotation = trans.localRotation; t.Scale = trans.localScale; return t; }
public static Trans InverseTransformTrans(this Matrix4x4 m, Trans t) { t.Matrix *= m.inverse; return t; }
public static Trans GetGlobal(Transform trans) { var t = new Trans(); t.Position = trans.position; t.Rotation = trans.rotation; t.Scale = trans.lossyScale; return t; }
public static Trans InverseTransformTrans(this Transform t, Trans t2) { t2.Matrix *= t.worldToLocalMatrix; return t2; }
public static bool IsNaN(Trans t) { return VectorUtil.IsNaN(t.Position) || VectorUtil.IsNaN(t.Scale) || QuaternionUtil.IsNaN(t.Rotation); }
/// <summary> /// Set the position and rotation of a Transform as if its origin were that of 'anchor'. /// Anchor should be local to the Transform where <0,0,0> would be the same as its true origin. /// </summary> /// <param name="trans">The transform to transpose.</param> /// <param name="anchor">The point around which to transpose in local space.</param> /// <param name="position">The new position in world space.</param> /// <param name="rotation">The new rotation in world space.</param> public static void TransposeAroundAnchor(this Transform trans, Trans anchor, Vector3 position, Quaternion rotation) { if (trans.parent != null) { position = trans.parent.InverseTransformPoint(position); rotation = trans.parent.InverseTransformRotation(rotation); } LocalTransposeAroundAnchor(trans, anchor, position, rotation); }
public static Trans Slerp(Trans start, Trans end, float t) { start.Position = Vector3.SlerpUnclamped(start.Position, end.Position, t); start.Rotation = Quaternion.SlerpUnclamped(start.Rotation, end.Rotation, t); start.Scale = Vector3.LerpUnclamped(start.Scale, end.Scale, t); return start; }
public static Vector2 GetDirection(IPlanarSurface surface, ForceDirection dir, Trans forceOrigin, Trans forceTarget) { if (surface == null) return Vector2.zero; switch (dir) { case ForceDirection.Relative: return surface.ProjectVectorTo2D(forceOrigin.Position, (forceTarget.Position - forceOrigin.Position)).normalized; case ForceDirection.Random: return RandomUtil.Standard.OnUnitCircle(); case ForceDirection.Forward: return surface.ProjectVectorTo2D(forceOrigin.Position, forceOrigin.Forward).normalized; } return Vector2.zero; }
public static Quaternion TransformRotation(Trans t, Quaternion rot) { return rot * t.Rotation; }
public static Vector3 GetDirection(ForceDirection dir, Trans forceOrigin, Trans forceTarget) { switch (dir) { case ForceDirection.Relative: return (forceTarget.Position - forceOrigin.Position).normalized; case ForceDirection.Random: return RandomUtil.Standard.OnUnitSphere(); case ForceDirection.Forward: return forceOrigin.Forward; } return Vector3.zero; }
public static Vector2 GetDirection(IPlanarSurface surface, ForceDirection dir, Trans forceOrigin, Trans forceTarget) { if (surface == null) { return(Vector2.zero); } switch (dir) { case ForceDirection.Relative: return(surface.ProjectVectorTo2D(forceOrigin.Position, (forceTarget.Position - forceOrigin.Position)).normalized); case ForceDirection.Random: return(RandomUtil.Standard.OnUnitCircle()); case ForceDirection.Forward: return(surface.ProjectVectorTo2D(forceOrigin.Position, forceOrigin.Forward).normalized); } return(Vector2.zero); }