public void SetTarget(uint contextID, uint objectID, float radius, double quantum) { if (PhysicsObj == null) { return; } ClearTarget(); if (objectID == 0) { var failedTargetInfo = new TargetInfo(); failedTargetInfo.ContextID = contextID; failedTargetInfo.Status = TargetStatus.TimedOut; PhysicsObj.HandleUpdateTarget(failedTargetInfo); return; } TargetInfo = new TargetInfo(contextID, objectID, radius, quantum); var target = PhysicsObj.GetObjectA(objectID); if (target != null) { target.add_voyeur(PhysicsObj.ID, radius, quantum); } }
public void adjust_offset(AFrame offset, double quantum) { if (PhysicsObj == null || TargetID == 0 || !Initialized) { return; } var target = PhysicsObj.GetObjectA(TargetID); var targetPosition = target == null ? TargetPosition : target.Position; offset.Origin = PhysicsObj.Position.GetOffset(targetPosition); offset.Origin = PhysicsObj.Position.GlobalToLocalVec(offset.Origin); offset.Origin.Z = 0.0f; var radius = PhysicsObj.GetRadius(); var dist = Position.CylinderDistanceNoZ(radius, PhysicsObj.Position, TargetRadius, targetPosition) - StickyRadius; if (Vec.NormalizeCheckSmall(ref offset.Origin)) { offset.Origin = Vector3.Zero; } var speed = 0.0f; var minterp = PhysicsObj.get_minterp(); if (minterp != null) { speed = minterp.get_max_speed() * 5.0f; } if (speed < PhysicsGlobals.EPSILON) { speed = 15.0f; } var delta = speed * (float)quantum; if (delta >= Math.Abs(dist)) { delta = dist; } offset.Origin *= delta; var curHeading = PhysicsObj.Position.Frame.get_heading(); var targetHeading = PhysicsObj.Position.heading(targetPosition); var heading = targetHeading - curHeading; if (Math.Abs(heading) < PhysicsGlobals.EPSILON) { heading = 0.0f; } if (heading < -PhysicsGlobals.EPSILON) { heading += 360.0f; } //Console.WriteLine($"StickyManager.AdjustOffset(targetHeading={targetHeading}, curHeading={curHeading}, setHeading={heading})"); offset.set_heading(heading); }
public void update_all_voyeur(PhysicsObj obj, DetectionType type, bool checkDetection = true) { if (obj.ID == 0 || obj.Parent != null || VoyeurTable == null) { return; } if (obj.State.HasFlag(PhysicsState.Hidden) && (checkDetection ? type == DetectionType.EnteredDetection : true)) { return; } foreach (var voyeur_id in VoyeurTable) { if (voyeur_id != obj.ID && voyeur_id != 0) { var voyeur = obj.GetObjectA(voyeur_id); if (voyeur == null) { continue; } var info = new DetectionInfo(obj.ID, type); voyeur.receive_detection_update(info); } } }
public void AddObject(PhysicsObj obj) { readerWriterLockSlim.EnterWriteLock(); try { // check for existing obj? ObjectList.Add(obj); NumObjects++; if (obj.ID == 0 || obj.Parent != null || obj.State.HasFlag(PhysicsState.Hidden) || VoyeurTable == null) { return; } foreach (var voyeur_id in VoyeurTable) { if (voyeur_id != obj.ID && voyeur_id != 0) { var voyeur = obj.GetObjectA(voyeur_id); if (voyeur == null) { continue; } var info = new DetectionInfo(obj.ID, DetectionType.EnteredDetection); voyeur.receive_detection_update(info); } } } finally { readerWriterLockSlim.ExitWriteLock(); } }
public void adjust_offset(AFrame offset, double quantum) { if (TargetID == 0 || !Initialized) { return; } var target = PhysicsObj.GetObjectA(TargetID); var targetPosition = target == null ? TargetPosition : target.Position; offset.Origin = PhysicsObj.Position.GetOffset(targetPosition); offset.Origin = PhysicsObj.Position.GlobalToLocalVec(offset.Origin); offset.Origin.Z = 0.0f; var radius = PhysicsObj.GetRadius(); var dist = Position.CylinderDistanceNoZ(radius, PhysicsObj.Position, TargetRadius, targetPosition) - StickyRadius; CollisionInfo.NormalizeCheckSmall(ref offset.Origin); var speed = 0.0f; var minterp = PhysicsObj.get_minterp(); if (minterp != null) { speed = minterp.get_max_speed() * 5.0f; } var delta = speed * (float)quantum; if (delta >= Math.Abs(dist)) { delta = dist; } offset.Origin *= delta; var heading = PhysicsObj.Position.heading(targetPosition) - PhysicsObj.Position.Frame.get_heading(); if (Math.Abs(heading) < PhysicsGlobals.EPSILON) { heading = 0.0f; } if (heading < -PhysicsGlobals.EPSILON) { heading += 360.0f; } offset.set_heading(heading); }