/// <summary> /// Creates a new PhysX.RigidDynamic using our defaults /// </summary> /// <param name="shape"></param> /// <param name="position"></param> /// <param name="rotation"></param> /// <returns></returns> public static PhysX.RigidDynamic CreateRigidDynamic(PhysxScene scene, PhysicsShape shape, OpenMetaverse.Vector3 position, OpenMetaverse.Quaternion rotation, bool physical, bool kinematic, Material material) { PhysX.RigidDynamic physActor = scene.SceneImpl.Physics.CreateRigidDynamic(); if (kinematic) { physActor.Flags |= PhysX.RigidDynamicFlags.Kinematic; } SetCommonProperties(scene, shape, position, rotation, physActor, physical, material); if (physical) { physActor.UpdateMassAndInertia(material.Density); physActor.MaxAngularVelocity *= 4; physActor.AngularDamping = DEFAULT_ANGULAR_DAMPING; physActor.LinearDamping = DEFAULT_LINEAR_DAMPING; } physActor.SleepThreshold = SLEEP_THRESHOLD; return(physActor); }
private void AssignActor(PhysX.RigidActor myActor, PhysicsShape newShape, bool isPhysical, DeleteActorFlags flags) { PhysX.RigidActor oldActor = _actor; PhysicsShape oldShape = null; if (newShape != null) { oldShape = _myShape; _myShape = newShape; } _actor = myActor; if (_actor != null && _actor is PhysX.RigidDynamic) { _dynActor = (PhysX.RigidDynamic)_actor; CacheMassData(); } else { _dynActor = null; } bool wasPhysical = _isPhysical; _isPhysical = isPhysical; if (HasActor) _scene.SceneImpl.AddActor(_actor); //add to physx scene this.DeleteActor(oldActor, oldShape, wasPhysical, flags); if (_actor != null) { _actor.UserData = this; this.IndexAndConfigurePrimaryShapes(); } ClearForcesAndSendUpdate(); ChangeGravityIfNeeded(); }
private void ChangeToChild(PhysxPrim parent, OpenMetaverse.Vector3 localPos, OpenMetaverse.Quaternion localRot) { _parentPrim = parent; //this prim no longer has its old shape or its actor _scene.PrimBecameChild(this); //if we have children, we need to unref their shapes here, as our new parent (ours and our children) //may require different shape types and will be rebuilt this.DeleteActor(_actor, _myShape, _isPhysical, DeleteActorFlags.UnrefChildShapes); _actor = null; _dynActor = null; _myShape = null; _position = localPos; _rotation = localRot; }
private void button1_Click(object sender, EventArgs e) { PhysX.Physics phys = new PhysX.Physics(); PhysX.SceneDesc desc = new PhysX.SceneDesc(); desc.Gravity = new PhysX.Math.Vector3(0f, 0f, -9.8f); PhysX.Scene scene = phys.CreateScene(desc); material = scene.Physics.CreateMaterial(0.5f, 0.5f, 0.1f); var conn = phys.ConnectToRemoteDebugger("localhost", null, null, null, PhysX.RemoteDebuggerConnectionFlags.Debug); /*scene.SetVisualizationParameter(PhysX.VisualizationParameter.Scale, 1.0f); * scene.SetVisualizationParameter(PhysX.VisualizationParameter.CollisionShapes, true); * scene.SetVisualizationParameter(PhysX.VisualizationParameter.JointLocalFrames, true); * scene.SetVisualizationParameter(PhysX.VisualizationParameter.JointLimits, true); * scene.SetVisualizationParameter(PhysX.VisualizationParameter.ParticleSystemPosition, true); * scene.SetVisualizationParameter(PhysX.VisualizationParameter.ActorAxes, true);*/ var hfGeom = this.CreateHfGeom(scene); while (true) { PhysX.RigidDynamic sphere = CreateSphere(scene, 0); sphere.Dispose(); PhysX.RigidStatic ground = CreateGround(scene, hfGeom); ground.Dispose(); GC.Collect(); } scene.AddActor(CreateGround(scene)); /*PhysX.RigidDynamic box1 = null; * for (int i = 0; i < 10; i += 2) * { * PhysX.RigidDynamic mahBox = CreateBox(scene, i); * scene.AddActor(mahBox); * * if (i == 0) * { * box1 = mahBox; * ((PhysX.Actor)box1).Flags = PhysX.ActorFlag.DisableGravity; * } * }*/ for (int i = 0; i < 10; i += 2) { PhysX.RigidDynamic mahBox = CreateSphere(scene, i); scene.AddActor(mahBox); } Stopwatch sw = new Stopwatch(); while (true) { sw.Start(); scene.Simulate(0.025f); scene.FetchResults(true); sw.Stop(); int sleep = 25 - (int)sw.ElapsedMilliseconds; if (sleep < 0) { sleep = 0; } System.Threading.Thread.Sleep(sleep); sw.Reset(); //label1.Text = DecomposeToPosition(mahBox.GlobalPose).ToString(); this.Update(); } }