public ODEDynamics(OdePrim rootp) { rootPrim = rootp; _pParentScene = rootPrim._parent_scene; m_timestep = _pParentScene.ODE_STEPSIZE; m_invtimestep = 1.0f / m_timestep; m_gravmod = rootPrim.GravModifier; }
public void CreateAndDropPhysicalCube() { PrimitiveBaseShape newcube = PrimitiveBaseShape.CreateBox(); Vector3 position = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f), 128f); Vector3 size = new Vector3(0.5f, 0.5f, 0.5f); Quaternion rot = Quaternion.Identity; PhysicsActor prim = ps.AddPrimShape("CoolShape", newcube, position, size, rot, true); OdePrim oprim = (OdePrim)prim; OdeScene pscene = (OdeScene)ps; Assert.That(oprim.m_taintadd); prim.LocalID = 5; for (int i = 0; i < 58; i++) { ps.Simulate(0.133f); Assert.That(oprim.prim_geom != (IntPtr)0); Assert.That(oprim.m_targetSpace != (IntPtr)0); //Assert.That(oprim.m_targetSpace == pscene.space); m_log.Info("TargetSpace: " + oprim.m_targetSpace + " - SceneMainSpace: " + pscene.space); Assert.That(!oprim.m_taintadd); m_log.Info("Prim Position (" + oprim.m_localID + "): " + prim.Position.ToString()); // Make sure we're above the ground //Assert.That(prim.Position.Z > 20f); //m_log.Info("PrimCollisionScore (" + oprim.m_localID + "): " + oprim.m_collisionscore); // Make sure we've got a Body Assert.That(oprim.Body != (IntPtr)0); //m_log.Info( } // Make sure we're not somewhere above the ground Assert.That(prim.Position.Z < 21.5f); ps.RemovePrim(prim); Assert.That(oprim.m_taintremove); ps.Simulate(0.133f); Assert.That(oprim.Body == (IntPtr)0); }
public OdePrim GetPhysicsActor() { if (!COLLIDER_ODE) { return(null); } if (pbs == null) { pbs = mesh.PBS; } if (physicsActor == null) { physicsActor = (OdePrim) PathStore.odeScene.AddPrim(GetObjectName(), LastPosition, LastSize, LastRotation, mesh, pbs, false); physicsActor.UnSubscribeEvents(); } return(physicsActor); }
//public class FallingPrim //{ //public bool DoneMoving = false; //public uint localId; public void FallingPrim(OdeScene ps, CollisionPlane Plane, PhysicsVector position, int x, int y, float offsetZ) { uint localId = Plane.fallingPrims; PrimitiveBaseShape newcube = PrimitiveBaseShape.CreateBox(); OdePrim oprim = (OdePrim)ps.AddPrimShape("FallingPrim_" + localId, newcube, position, new PhysicsVector(0.1f, 0.1f, 2f), Quaternion.Identity, true); oprim.LocalID = localId + 100000; oprim.OnCollisionUpdate += delegate(EventArgs args) { if (!oprim.m_taintremove) { // CollisionEventUpdate arg = (CollisionEventUpdate)args; //simhinfo 58 58 30 // DoneMoving = true; LandingHieghts[x, y] = oprim.Position.Z + offsetZ; fallingPrims--; ps.remCollisionEventReporting(oprim); ps.RemovePrim(oprim); } }; oprim.SubscribeEvents(30000); }
public OdePrim GetPhysicsActor() { if (!COLLIDER_ODE) return null; if (pbs == null) pbs = mesh.PBS; if (physicsActor == null) { physicsActor = (OdePrim) PathStore.odeScene.AddPrim(GetObjectName(), LastPosition, LastSize, LastRotation, mesh, pbs, false); physicsActor.UnSubscribeEvents(); } return physicsActor; }
public override sealed bool Update(SimPosition simObject) { //if (!WorldObjects.MaintainCollisions) return false; if (!simObject.IsRegionAttached) return false; if (MeshOnlySolids && !((MeshableObject) simObject).IsSolid) return false; Quaternion Rotation = simObject.SimRotation; Vector3 Scale = Prim.Scale; //.GetSimScale(); Vector3 Position = simObject.SimPosition; #if COLLIDER_ODE LastSize = new PhysicsVector(1, 1, 1); // we scaled the PrimMesh already! LastRotation = Quaternion.Identity; // we rotated the PrimMesh already! LastPosition = ToPhysicsVector(Position); // we hadn't done position though #endif //pbs. //List<Mesh> MeshList = new List<Mesh>(); //PrimMesh primMesh; //if (false) //{ // // Add Low PrimMesh (IdealistViewer code) // primMesh = PrimitiveToPrimMesh(simObject.thePrim, LevelOfDetail.Low, Scale, Rotation); // AddMesh(primMesh); //} // Add High PrimMesh (IdealistViewer code) Mesh mesh = PrimitiveToMesh(Prim, Scale, Rotation); #if COLLIDER_ODE this.mesh = mesh; if (!RootObject.IsPhantom) physicsActor = GetPhysicsActor(); #endif //MeshList.Add(mesh); //if (false) //{ // // Add based on PrimitiveBaseShape (OpenSim Meshmerizer code) // PrimitiveBaseShape primShape = PrimToBaseShape(simObject.thePrim); // Mesh mesh = CreateMesh(simObject.ToString(), primShape, // new PhysicsVector(Scale.X, Scale.Y, Scale.Z), 32f, Object.IsPhysical, QuaternionToQuat(Rotation)); // why 32? // AddMesh(mesh); // // i am going to see if i can make simple bounding mox meshes for unhollow cubes // if (primShape.ProfileShape == ProfileShape.Square && primShape.HollowShape == HollowShape.Same) // { // Mesh extramesh = Meshmerizer.CreateBoundingBoxMesh(mesh); // AddMesh(extramesh); // } //} if (InnerBoxes == null) InnerBoxes = new List<Box3Fill>(); else InnerBoxes.Clear(); OuterBox.Reset(); CalcBoxesFromMeshes(mesh, InnerBoxes); bool verySmall = OuterBox.EdgeSize < WorldPathSystem.MinEdgeSizeOfSimplify; if (verySmall) { int b = InnerBoxes.Count; InnerBoxes.Clear(); AddPos(Position); InnerBoxes.Add(OuterBox); DLRConsole.DebugWriteLine("Simplfy EdgeSize {0} -> 1 ", b, InnerBoxes.Count + " " + OuterBox.EdgeSize + " " + this.GetObjectName()); } else { if (SimplifyBoxes) { int b = InnerBoxes.Count; InnerBoxes = Box3Fill.Simplify((List<Box3Fill>)InnerBoxes); if (DebugMesh) if (b > 2000 || InnerBoxes.Count * 4 < b) DLRConsole.DebugWriteLine("Simplfy mesh {0} -> {1} ", b, InnerBoxes.Count + " " + OuterBox.Mass + " " + this.GetObjectName()); } AddPos(Position); } #if COLLIDER_TRIANGLE triangles = mesh.triangles; #endif return true; }
public override sealed bool Update(SimPosition simObject) { //if (!WorldObjects.MaintainCollisions) return false; if (!simObject.IsRegionAttached) { return(false); } if (MeshOnlySolids && !((MeshableObject)simObject).IsSolid) { return(false); } Quaternion Rotation = simObject.SimRotation; Vector3 Scale = Prim.Scale; //.GetSimScale(); Vector3 Position = simObject.SimPosition; #if COLLIDER_ODE LastSize = new PhysicsVector(1, 1, 1); // we scaled the PrimMesh already! LastRotation = Quaternion.Identity; // we rotated the PrimMesh already! LastPosition = ToPhysicsVector(Position); // we hadn't done position though #endif //pbs. //List<Mesh> MeshList = new List<Mesh>(); //PrimMesh primMesh; //if (false) //{ // // Add Low PrimMesh (IdealistViewer code) // primMesh = PrimitiveToPrimMesh(simObject.thePrim, LevelOfDetail.Low, Scale, Rotation); // AddMesh(primMesh); //} // Add High PrimMesh (IdealistViewer code) Mesh mesh = PrimitiveToMesh(Prim, Scale, Rotation); #if COLLIDER_ODE this.mesh = mesh; if (!RootObject.IsPhantom) { physicsActor = GetPhysicsActor(); } #endif //MeshList.Add(mesh); //if (false) //{ // // Add based on PrimitiveBaseShape (OpenSim Meshmerizer code) // PrimitiveBaseShape primShape = PrimToBaseShape(simObject.thePrim); // Mesh mesh = CreateMesh(simObject.ToString(), primShape, // new PhysicsVector(Scale.X, Scale.Y, Scale.Z), 32f, Object.IsPhysical, QuaternionToQuat(Rotation)); // why 32? // AddMesh(mesh); // // i am going to see if i can make simple bounding mox meshes for unhollow cubes // if (primShape.ProfileShape == ProfileShape.Square && primShape.HollowShape == HollowShape.Same) // { // Mesh extramesh = Meshmerizer.CreateBoundingBoxMesh(mesh); // AddMesh(extramesh); // } //} if (InnerBoxes == null) { InnerBoxes = new List <Box3Fill>(); } else { InnerBoxes.Clear(); } OuterBox.Reset(); CalcBoxesFromMeshes(mesh, InnerBoxes); bool verySmall = OuterBox.EdgeSize < WorldPathSystem.MinEdgeSizeOfSimplify; if (verySmall) { int b = InnerBoxes.Count; InnerBoxes.Clear(); AddPos(Position); InnerBoxes.Add(OuterBox); DLRConsole.DebugWriteLine("Simplfy EdgeSize {0} -> 1 ", b, InnerBoxes.Count + " " + OuterBox.EdgeSize + " " + this.GetObjectName()); } else { if (SimplifyBoxes) { int b = InnerBoxes.Count; InnerBoxes = Box3Fill.Simplify((List <Box3Fill>)InnerBoxes); if (DebugMesh) { if (b > 2000 || InnerBoxes.Count * 4 < b) { DLRConsole.DebugWriteLine("Simplfy mesh {0} -> {1} ", b, InnerBoxes.Count + " " + OuterBox.Mass + " " + this.GetObjectName()); } } } AddPos(Position); } #if COLLIDER_TRIANGLE triangles = mesh.triangles; #endif return(true); }
void ComputeLandingHeights() { float fromZ = MaxZ + 10; float StepSize = PathStore.StepSize; //0.2f int MAPSPACE = PathStore.MAPSPACE; int MAPSPACE1 = MAPSPACE - 1; // 1279 bool needsInit = false; float[,] _HeightMap = HeightMap; if (LandingHieghts == null) { if (_HeightMap != null) { LandingHieghts = (float[, ])_HeightMap.Clone(); } else { LandingHieghts = new float[MAPSPACE, MAPSPACE]; needsInit = true; } } CollisionIndex[,] MeshIndex = PathStore.MeshIndex; // FallingPrims = new FallingPrim[MAPSPACE, MAPSPACE]; float fy = 256.1f; OdeScene ps = PathStore.odeScene; PrimitiveBaseShape newcube = PrimitiveBaseShape.CreateBox(); uint localId = 6666666; PhysicsVector position = new PhysicsVector(1, 1, 30); OdePrim oprim = (OdePrim)ps.AddPrimShape("FallingPrim_" + localId, newcube, position, new PhysicsVector(0.1f, 0.1f, 2f), Quaternion.Identity, true); oprim.LocalID = localId + 100000; oprim.SubscribeEvents(30000); for (int y = MAPSPACE1; y >= 0; y--) { fy = fy - StepSize; position.Y = fy; float fx = 256.1f; for (int x = MAPSPACE1; x >= 0; x--) { fx = fx - StepSize; position.X = fx; if (needsInit) { LandingHieghts[x, y] = float.MinValue; } if (MeshIndex[x, y] == null) { continue; } float z = MinZ; bool FoundClearZ = false; while (z < MaxZ && !FoundClearZ) { float ClearZ = z; position.Z = z; if (!ps.IsSomethingAt(oprim)) { FoundClearZ = true; float CapZ = 2f + z; while (z < CapZ && FoundClearZ) { if (ps.IsSomethingAt(oprim)) { FoundClearZ = false; break; } } FoundClearZ = true; break; } z += 0.1f; } if (FoundClearZ) { LandingHieghts[x, y] = z; } //FallingPrims[x, y] = new } } _HeightMap = LandingHieghts; }