public override void Link(PhysicsActor obj) { BSPrimLinkable parent = obj as BSPrimLinkable; if (parent != null) { BSPhysObject parentBefore = Linkset.LinksetRoot; int childrenBefore = Linkset.NumberOfChildren; Linkset = parent.Linkset.AddMeToLinkset(this); if (Linkset != null) DetailLog( "{0},BSPrimLinkset.link,call,parentBefore={1}, childrenBefore=={2}, parentAfter={3}, childrenAfter={4}", LocalID, parentBefore.LocalID, childrenBefore, Linkset.LinksetRoot.LocalID, Linkset.NumberOfChildren); } return; }
public virtual void LinkGroupToThis(PhysicsActor[] objs) { }
/// <summary> /// Removes a single prim from the group that it is in /// (or removes it entirely from the scene if it is as single prim) /// </summary> /// <param name="prim"></param> public abstract void RemovePrim(PhysicsActor prim);
/// <summary> /// Removes an entire group from the physics scene /// </summary> /// <param name="prim"></param> public abstract void DeletePrim(PhysicsActor prim);
public override void RemoveAvatar(PhysicsActor actor) { }
public override void RemovePrim(PhysicsActor prim) { if (!m_initialized) return; BSPhysObject bsprim = prim as BSPhysObject; if (bsprim != null) { DetailLog("{0},RemovePrim,call", bsprim.LocalID); // MainConsole.Instance.DebugFormat("{0}: RemovePrim. id={1}/{2}", LogHeader, bsprim.Name, bsprim.LocalID); try { lock (PhysObjects) PhysObjects.Remove(bsprim.LocalID); } catch (Exception e) { MainConsole.Instance.ErrorFormat("{0}: Attempt to remove prim that is not in physics scene: {1}", LogHeader, e); } bsprim.Destroy(); // bsprim.dispose(); } else { MainConsole.Instance.ErrorFormat("{0}: Attempt to remove prim that is not a BSPrim type.", LogHeader); } }
private void changelink(UniverseODEPrim newparent) { // If the newly set parent is not null // create link if (_parent == null && newparent != null) { newparent.ParentPrim(this); } // If the newly set parent is null // destroy link else if (_parent != null) { if (_parent is UniverseODEPrim) { if (newparent != _parent) { UniverseODEPrim obj = (UniverseODEPrim) _parent; obj.ChildDelink(this); childPrim = false; if (newparent != null) { newparent.ParentPrim(this); } } } } _parent = newparent; }
public void RemCollisionEventReporting(PhysicsActor obj) { _collisionEventDictionary.TryRemove(obj.UUID, out obj); }
public override void linkGroupToThis(PhysicsActor[] objs) { Linkset.AddGroupToLinkset(objs.Cast<BSPrimLinkable>().ToArray()); DetailLog("{0},BSPrimLinkset.linkGroupToThis,call, childrenAdded={1}, childrenAfter={2}", LocalID, objs.Length, Linkset.NumberOfChildren); }
public override void LinkGroupToThis(PhysicsActor[] objs) { }
public override void DeletePrim(PhysicsActor prim) { BSPrimLinkable linkablePrim = prim as BSPrimLinkable; if (linkablePrim != null && linkablePrim.Linkset.HasAnyChildren) { linkablePrim.BlockPhysicalReconstruction = true; //Remove all the children prims first, then kill the root foreach (BSPrimLinkable childPrim in linkablePrim.Linkset.Children) { childPrim.BlockPhysicalReconstruction = true; RemovePrim(childPrim); } //TODO: DISABLE LINKSET REBUILDING DURING THIS PROCESS } RemovePrim(prim); }
private void ResetPrim(PhysicsActor physicsObject, PhysicsState physicsState, float direction) { physicsObject.Position = physicsState.Position; physicsObject.Orientation = physicsState.Rotation; physicsObject.RotationalVelocity = physicsState.AngularVelocity*direction; physicsObject.Velocity = physicsState.LinearVelocity*direction; physicsObject.ForceSetVelocity(physicsState.LinearVelocity*direction); physicsObject.RequestPhysicsterseUpdate(); }
public void AddPrim(PhysicsActor prm) { PhysicsState state = new PhysicsState { Position = prm.Position, AngularVelocity = prm.RotationalVelocity, LinearVelocity = prm.Velocity, Rotation = prm.Orientation }; m_activePrims[prm.UUID] = state; }
public override void RemovePrim(PhysicsActor prim) { //Add the prim to a queue which will be removed when Simulate has finished what it's doing. RemoveQueue.Enqueue(prim); }
public override void RemoveAvatar(PhysicsActor actor) { BasicCharacterActor act = (BasicCharacterActor) actor; if (_actors.Contains(act)) { _actors.Remove(act); } }
static void Collision_accounting_events(PhysicsActor p1, PhysicsActor p2, ContactPoint contact) { if (!p2.SubscribedEvents() && !p1.SubscribedEvents()) return; if (p1.SubscribedEvents()) p1.AddCollisionEvent(p2.LocalID, contact); if (p2.SubscribedEvents()) p2.AddCollisionEvent(p1.LocalID, contact); }
/// <summary> /// Rebuild the physical representation of all the prims. /// This is used after copying the prim so that all of the object is readded to the physics scene. /// </summary> public void RebuildPhysicalRepresentation(bool keepSelectedStatuses, Action actionWhileNoPhysActor) { // long lock or array copy? in this case lets try array SceneObjectPart[] parts; SceneObjectPart part; int i; lock (m_partsLock)//Force the root to be deleted last parts = m_partsList.OrderBy((sop)=>-sop.LinkNum).ToArray(); if (RootPart.PhysActor != null) RootPart.PhysActor.BlockPhysicalReconstruction = true; for (i = 0; i < parts.Length; i++) { part = parts[i]; if (part.PhysActor != null) { part.PhysActor.RotationalVelocity = Vector3.Zero; part.m_hasSubscribedToCollisionEvent = false; part.PhysActor.OnRequestTerseUpdate -= part.PhysicsRequestingTerseUpdate; part.PhysActor.OnSignificantMovement -= part.ParentGroup.CheckForSignificantMovement; part.PhysActor.OnOutOfBounds -= part.PhysicsOutOfBounds; //Remove the old one so that we don't have more than we should, // as when we copy, it readds it to the PhysicsScene somehow m_scene.PhysicsScene.RemovePrim(part.PhysActor); part.FireOnRemovedPhysics(); part.PhysActor = null; } //Reset any old data that we have part.Velocity = Vector3.Zero; part.AngularVelocity = Vector3.Zero; part.Acceleration = Vector3.Zero; part.GenerateRotationalVelocityFromOmega(); } if(actionWhileNoPhysActor != null) actionWhileNoPhysActor(); //Check for meshes and stuff CheckSculptAndLoad(); // check root part setting that make the entire object not having physics rep if (RootPart.PhysicsType == (byte)PhysicsShapeType.None || ((RootPart.Flags & PrimFlags.Phantom) == PrimFlags.Phantom && !RootPart.VolumeDetectActive)) { Scene.UniverseEventManager.FireGenericEventHandler("ObjectChangedPhysicalStatus", this); if (OnFinishedPhysicalRepresentationBuilding != null) OnFinishedPhysicalRepresentationBuilding(); OnFinishedPhysicalRepresentationBuilding = null; return; } // create the root part bool isPhysical = ((RootPart.Flags & PrimFlags.Physics) != 0); bool isPhantom = ((RootPart.Flags & PrimFlags.Phantom) != 0); bool physical = isPhysical & !isPhantom; RootPart.PhysActor = m_scene.PhysicsScene.AddPrimShape(RootPart.UUID, RootPart.LocalId, RootPart.Name, RootPart.PhysicsType, RootPart.Shape, RootPart.AbsolutePosition, RootPart.Scale, RootPart.GetWorldRotation(), physical, RootPart.Material, RootPart.Friction, RootPart.Restitution, RootPart.GravityMultiplier, RootPart.Density); if (RootPart.PhysActor == null) return; //Don't let it rebuild it until we have all the links done RootPart.PhysActor.VolumeDetect = RootPart.VolumeDetectActive; //Add collision updates RootPart.PhysActor.OnRequestTerseUpdate += RootPart.PhysicsRequestingTerseUpdate; RootPart.PhysActor.OnSignificantMovement += RootPart.ParentGroup.CheckForSignificantMovement; RootPart.PhysActor.OnOutOfBounds += RootPart.PhysicsOutOfBounds; RootPart.FireOnAddedPhysics(); RootPart.aggregateScriptEvents(); PhysicsActor[] actors = new PhysicsActor[parts.Length - 1]; for (i = 0; i < parts.Length; i++) { part = parts[i]; if (part == RootPart || part.PhysicsType == (byte)PhysicsShapeType.None || ((part.Flags & PrimFlags.Phantom) == PrimFlags.Phantom && !part.VolumeDetectActive)) { continue; // ignore phantom prims } //Now read the physics actor to the physics scene isPhysical = ((part.ParentEntity.RootChild.Flags & PrimFlags.Physics) != 0); isPhantom = ((part.ParentEntity.RootChild.Flags & PrimFlags.Phantom) != 0); physical = isPhysical & !isPhantom; part.PhysActor = m_scene.PhysicsScene.AddPrimShape(part.UUID, part.LocalId, part.Name, RootPart.PhysicsType, part.Shape, part.AbsolutePosition, part.Scale, part.GetWorldRotation(), physical, part.Material, part.Friction, part.Restitution, part.GravityMultiplier, part.Density); if (part.PhysActor == null) continue; part.PhysActor.VolumeDetect = part.VolumeDetectActive; //Add collision updates part.PhysActor.OnRequestTerseUpdate += part.PhysicsRequestingTerseUpdate; part.PhysActor.OnSignificantMovement += part.ParentGroup.CheckForSignificantMovement; part.PhysActor.OnOutOfBounds += part.PhysicsOutOfBounds; part.FireOnAddedPhysics(); part.aggregateScriptEvents(); actors[i] = part.PhysActor; if(!m_scene.PhysicsScene.AllowGroupLink) part.PhysActor.link(RootPart.PhysActor); } if (m_scene.PhysicsScene.AllowGroupLink) RootPart.PhysActor.linkGroupToThis(actors); Scene.UniverseEventManager.FireGenericEventHandler("ObjectChangedPhysicalStatus", this); FixVehicleParams(RootPart); //Force deselection here so that it isn't stuck forever IsSelected = keepSelectedStatuses && IsSelected; if (OnFinishedPhysicalRepresentationBuilding != null) OnFinishedPhysicalRepresentationBuilding(); OnFinishedPhysicalRepresentationBuilding = null; }
public override void Link(PhysicsActor obj) { return; }
public abstract void RemoveAvatar(PhysicsActor actor);
public override void RemoveAvatar(PhysicsActor actor) { // MainConsole.Instance.DebugFormat("{0}: RemoveAvatar", LogHeader); if (!m_initialized) return; BSCharacter bsactor = actor as BSCharacter; if (bsactor != null) { try { lock (PhysObjects) PhysObjects.Remove(bsactor.LocalID); // Remove kludge someday lock (m_avatars) m_avatars.Remove(bsactor); } catch (Exception e) { MainConsole.Instance.WarnFormat("{0}: Attempt to remove avatar that is not in physics scene: {1}", LogHeader, e); } bsactor.Destroy(); // bsactor.dispose(); } else { MainConsole.Instance.ErrorFormat( "{0}: Requested to remove avatar that is not a BSCharacter. ID={1}, type={2}", LogHeader, actor.LocalID, actor.GetType().Name); } }
public override void DeletePrim(PhysicsActor prim) { }
public override void RemovePrim(PhysicsActor prim) { }
public virtual void Link(PhysicsActor obj) { }
public override void link(PhysicsActor obj) { }
public void GetContactParam(PhysicsActor actor, ref d.Contact contact) { int vehicleType = 0; if ((_parent != null && (vehicleType = _parent.VehicleType) != (int) Vehicle.TYPE_NONE) || (vehicleType = VehicleType) != (int) Vehicle.TYPE_NONE || (actor is UniverseODEPrim && ((UniverseODEPrim) actor).Parent != null && (vehicleType = ((UniverseODEPrim) actor).Parent.VehicleType) != (int) Vehicle.TYPE_NONE) || (actor is UniverseODEPrim && (vehicleType = ((UniverseODEPrim) actor).VehicleType) != (int) Vehicle.TYPE_NONE)) { if (vehicleType == (int) Vehicle.TYPE_CAR) { contact.surface.bounce = 0; contact.surface.bounce_vel = 0; contact.surface.mu = 2; } else if (vehicleType == (int) Vehicle.TYPE_SLED) { contact.surface.bounce = 0; contact.surface.bounce_vel = 0; contact.surface.mu = 0; } else if (vehicleType == (int) Vehicle.TYPE_AIRPLANE || vehicleType == (int) Vehicle.TYPE_BALLOON || vehicleType == (int) Vehicle.TYPE_BOAT) { contact.surface.bounce = 0; contact.surface.bounce_vel = 0; contact.surface.mu = 100; } } else { float restSquared = Restitution*Restitution*Restitution; float maxVel = Velocity.Z < -1f ? -1f : Velocity.Z > 1f ? 1f : Velocity.Z; contact.surface.bounce = (maxVel*-(restSquared)); //Its about 1:1 surprisingly, even though this constant was for havok if (contact.surface.bounce > 0.5f) contact.surface.bounce = 0.5f; //Limit the bouncing please... if (contact.surface.bounce <= 0) { contact.surface.bounce = 0; contact.surface.bounce_vel = 0; } else contact.surface.bounce_vel = 0.01f*restSquared*(-maxVel*restSquared); //give it a good amount of bounce and have it depend on how much velocity is there too contact.surface.mu = 800; if (contact.surface.bounce_vel != 0) contact.surface.mode |= d.ContactFlags.Bounce; else contact.surface.mode &= d.ContactFlags.Bounce; if (actor.PhysicsActorType == (int) ActorTypes.Prim) contact.surface.mu *= Friction; else if (actor.PhysicsActorType == (int) ActorTypes.Ground) contact.surface.mu *= 2; else contact.surface.mu /= 2; if (m_vehicle.Type != Vehicle.TYPE_NONE && actor.PhysicsActorType != (int) ActorTypes.Agent) contact.surface.mu *= 0.05f; } }
void AddODECollision(d.ContactGeom curContact, PhysicsActor p1, PhysicsActor p2, IntPtr b1, IntPtr b2, ContactPoint maxDepthContact, ref int NotSkipedCount) { IntPtr joint = IntPtr.Zero; bool p2col = true; // We only need to test p2 for 'jump crouch purposes' if (p2 is ODECharacter && p1.PhysicsActorType == (int) ActorTypes.Prim) { // Testing if the collision is at the feet of the avatar if ((p2.Position.Z - maxDepthContact.Position.Z) < (p2.Size.Z*0.5f)) p2col = false; } p2.IsTruelyColliding = true; p2.IsColliding = p2col; // Logic for collision handling // Note, that if *all* contacts are skipped (VolumeDetect) // The prim still detects (and forwards) collision events but // appears to be phantom for the world // No collision on volume detect prims if ((p1 is ODEPrim && p1.VolumeDetect) || (p2 is ODEPrim && p2.VolumeDetect)) return; if (curContact.depth < 0f) return; //Has to be penetrating if (m_filterCollisions && CheckDupe(curContact, p2.PhysicsActorType)) return; if (m_filterCollisions) _perloopContact.Add(curContact); NotSkipedCount++; // If we're colliding against terrain if (p1.PhysicsActorType == (int) ActorTypes.Ground) { if (p2.PhysicsActorType == (int) ActorTypes.Prim) { ((ODEPrim) p2).GetContactParam(p2, ref newGlobalcontact); joint = CreateContacJoint(curContact); } else { newGlobalcontact = new d.Contact(); newGlobalcontact.surface.mode |= d.ContactFlags.SoftERP; newGlobalcontact.surface.mu = 75; newGlobalcontact.surface.bounce = 0.1f; newGlobalcontact.surface.soft_erp = 0.05025f; //GetContactParam(0.0f, AvatarContactBounce, ref newGlobalcontact); joint = CreateContacJoint(curContact); } //Can't collide against anything else, agents do their own ground checks } else if ((p1.PhysicsActorType == (int) ActorTypes.Agent) && (p2.PhysicsActorType == (int) ActorTypes.Agent)) { GetContactParam(0.0f, AvatarContactBounce, ref newGlobalcontact); joint = CreateContacJoint(curContact); } else if (p1.PhysicsActorType == (int) ActorTypes.Prim) { //Add restitution and friction changes // was.. greythane-20160602 >> // ((ODEPrim) p1).GetContactParam(p2, ref newGlobalcontact); ((ODEPrim)p1).GetContactParam (p1, ref newGlobalcontact); joint = CreateContacJoint(curContact); } if (ContinueCollisionProcessing && joint != IntPtr.Zero) { d.JointAttach(joint, b1, b2); lock (_contactcountLock) m_global_contactcount++; } }
public override void link(PhysicsActor obj) { _parent_scene.AddSimulationChange(() => changelink((UniverseODEPrim) obj)); }
public void AddCollisionEventReporting(PhysicsActor obj) { if (!_collisionEventDictionary.ContainsKey(obj.UUID)) _collisionEventDictionary.TryAdd(obj.UUID, obj); }
public override void linkGroupToThis(PhysicsActor[] objs) { for(int i = 0 ; i < objs.Length; i++) _parent_scene.AddSimulationChange(() => ((UniverseODEPrim) objs[i]).changelink(this)); }
public override void RemoveAvatar(PhysicsActor actor) { //MainConsole.Instance.Debug("[ODE Physics]:ODELOCK"); ((ODECharacter) actor).Destroy(); }