namespace Sandbox.VR; /// /// Represents a physically tracked VR object with a transform /// public record TrackedObject { /// /// Whether or not this object is currently accessible (if false, then the transform will not update). /// public bool Active => _trackedDevice.IsActive; /// /// Local velocity of this object. /// public Vector3 Velocity { get; private set; } /// /// Local angular velocity of this object (degrees/s) /// public Angles AngularVelocity { get; private set; } /// /// The position and rotation of this tracked object in world space (based on the anchor position) /// public virtual Transform Transform => Input.VR.Anchor.ToWorld( _trackedDevice.Transform ); /// /// Which part of the body this tracked object represents - waist, left shoulder, etc. /// public TrackedDeviceRole Role => _trackedDevice.DeviceRole; /// /// What type of object this is - tracker, controller, etc. /// public TrackedDeviceType Type => _trackedDevice.DeviceType; private Transform _previousTransform; internal TrackedDevice _trackedDevice; internal TrackedObject( TrackedDevice trackedDevice ) { _trackedDevice = trackedDevice; } internal virtual void Update() { _trackedDevice.Update(); // Calculate velocities if ( _previousTransform.IsValid ) { var delta = Transform.Position - _previousTransform.Position; Velocity = delta / Time.Delta; var deltaRot = Rotation.Difference( _previousTransform.Rotation, Transform.Rotation ); AngularVelocity = deltaRot.Angles() / Time.Delta; } _previousTransform = Transform; } }