public void TestCleanup() { _physics.Dispose(); _physics = null; _actor = null; }
public PhysxPhysicObject(Scene scene, Geometry geometry, float mass, Matrix localTransformation, Matrix worldTransformation, Vector3 scale, MaterialDescription MaterialDescription) { Scale = scale; rigidActor = scene.Physics.CreateRigidDynamic(worldTransformation.AsPhysX()); material = scene.Physics.CreateMaterial(MaterialDescription.StaticFriction, MaterialDescription.DynamicFriction, MaterialDescription.Bounciness); var boxShape = rigidActor.CreateShape(geometry, material, localTransformation.AsPhysX()); rigidActor.SetMassAndUpdateInertia(mass); }
public void TestInitalize() { _physics = CreatePhysicsAndScene(); _material = _physics.Physics.CreateMaterial(0.5f, 0.5f, 0.1f); _actor = _physics.Physics.CreateRigidDynamic(); _physics.Scene.AddActor(_actor); }
public void TestInitalize() { _physics = CreatePhysicsAndScene(); _material = _physics.Physics.CreateMaterial(0.5f, 0.5f, 0.1f); _actor = _physics.Physics.CreateRigidDynamic(); // Make the actor kinematic because Triangle mesh, heightfield and plane geometry shapes require it. _actor.RigidBodyFlags = RigidBodyFlag.Kinematic; _physics.Scene.AddActor(_actor); }
public void TestInitalize() { _physics = CreatePhysicsAndScene(); _material = _physics.Physics.CreateMaterial(0.5f, 0.5f, 0.1f); _actor = _physics.Physics.CreateRigidDynamic(); // Make the actor kinematic because Triangle mesh, heightfield and plane geometry shapes require it. _actor.Flags = RigidDynamicFlags.Kinematic; _physics.Scene.AddActor(_actor); }
private void ProcessMouseManipulation() { if (!MouseTracker.LeftMousePressed) { checkForHit = true; hitActor = null; HookPoint = Point3d.Unset; HookPointOnMouseLine = Point3d.Unset; } else { if (checkForHit) { checkForHit = false; Vector3d mouseLineDirection = MouseTracker.MouseLine.Direction; mouseLineDirection.Unitize(); PxGhManager.Scene.Raycast( MouseTracker.MouseLine.From.ToSystemVector(), mouseLineDirection.ToSystemVector(), 9999f, 999, HitCallback, HitFlag.Position); } if (hitActor != null) { Rhino.Geometry.Plane frame = hitActor.GlobalPose.ToRhinoPlane(); HookPoint = frame.Origin + frame.XAxis * hookPoint.X + frame.YAxis * hookPoint.Y + frame.ZAxis * hookPoint.Z; HookPointOnMouseLine = MouseTracker.MouseLine.ClosestPoint(HookPoint, false); if (MouseManipulationMode == MouseManipulationMode.Position) { frame.Origin = HookPointOnMouseLine + (frame.Origin - HookPoint); hitActor.GlobalPose = frame.ToMatrix(); hitActor.LinearVelocity = Vector3.Zero; hitActor.AddForceAtLocalPosition((hitActor.Mass * -Gravity).ToSystemVector(), hookPoint.ToSystemVector(), ForceMode.Force, true); } else { Vector3d force = (HookPointOnMouseLine - HookPoint) * MouseManipulationStrength * (MouseManipulationMode == MouseManipulationMode.Acceleration ? hitActor.Mass : 1.0); hitActor.AddForceAtLocalPosition(force.ToSystemVector(), hookPoint.ToSystemVector(), ForceMode.Force, true); } } } }
protected override void LoadPhysics(PhysX.Scene scene) { var material = scene.Physics.CreateMaterial(0.7f, 0.7f, 0.1f); var sphereA = scene.Physics.CreateRigidDynamic(); sphereA.CreateShape(new SphereGeometry(1), material); sphereA.GlobalPose = Matrix4x4.CreateTranslation(0, 30, 0); scene.AddActor(sphereA); // var sphereB = scene.Physics.CreateRigidDynamic(); sphereB.CreateShape(new SphereGeometry(1), material); sphereB.GlobalPose = Matrix4x4.CreateTranslation(0, 40, 0); scene.AddActor(sphereB); // var sphereC = scene.Physics.CreateRigidDynamic(); sphereC.CreateShape(new SphereGeometry(1), material); sphereC.GlobalPose = Matrix4x4.CreateTranslation(0, 50, 0); scene.AddActor(sphereC); _sphereC = sphereC; // var revoluteABJoint = scene.CreateJoint <RevoluteJoint>(sphereA, Matrix4x4.Identity, sphereB, Matrix4x4.Identity); revoluteABJoint.SetGlobalFrame(new Vector3(0, 35, 0), new Vector3(0, 0, 1)); revoluteABJoint.ConstraintFlags = ConstraintFlag.Visualization; var revoluteBCJoint = scene.CreateJoint <RevoluteJoint>(sphereB, Matrix4x4.Identity, sphereC, Matrix4x4.Identity); revoluteBCJoint.SetGlobalFrame(new Vector3(0, 45, 0), new Vector3(0, 0, 1)); revoluteBCJoint.ConstraintFlags = ConstraintFlag.Visualization; var revoluteAJoint = scene.CreateJoint <RevoluteJoint>(sphereA, Matrix4x4.Identity, null, Matrix4x4.Identity); revoluteAJoint.SetGlobalFrame(new Vector3(0, 30, 0), new Vector3(0, 0, 1)); revoluteAJoint.ConstraintFlags = ConstraintFlag.Visualization; }
private bool HitCallback(RaycastHit[] hits) { foreach (RaycastHit hit in hits) { if (!(hit.Actor is RigidDynamic)) { continue; } hitActor = (RigidDynamic)hit.Actor; Rhino.Geometry.Plane frame = hitActor.GlobalPose.ToRhinoPlane(); Vector3d v = hit.Position.ToRhinoPoint() - frame.Origin; hookPoint = new Point3d(v * frame.XAxis, v * frame.YAxis, v * frame.ZAxis); return(true); } return(false); }
public void CreateBox(Scene.Entity3D ent) { Scene.Bounds bb = ent.Bounds; ID = PhysicsManager.py.CreateRigidDynamic(); BoxGeometry ge = new BoxGeometry(bb.W / 2, bb.H / 2, bb.D / 2); // Shape = ID.CreateShape ( ge, Mat ); ID.LinearVelocity = new System.Numerics.Vector3(0, 0, 0); Shape = RigidActorExt.CreateExclusiveShape(ID, ge, Mat); //Pose = ID.GlobalPose; var wm = ent.WorldNoScale; float m11 = wm.M11; float m12 = wm.M12; float m13 = wm.M13; float m14 = wm.M14; float m21 = wm.M21; float m22 = wm.M22; float m23 = wm.M23; float m24 = wm.M24; float m31 = wm.M31; float m32 = wm.M32; float m33 = wm.M33; float m34 = wm.M34; float m41 = wm.M41; float m42 = wm.M42; float m43 = wm.M43; float m44 = wm.M44; System.Numerics.Matrix4x4 tm = new System.Numerics.Matrix4x4(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44); ID.GlobalPose = tm; ID.SetMassAndUpdateInertia(3); Physics.PhysicsManager.Scene.AddActor(ID); }
protected override void LoadPhysics(PhysX.Scene scene) { var material = scene.Physics.CreateMaterial(0.7f, 0.7f, 0.1f); var sphereA = scene.Physics.CreateRigidDynamic(); sphereA.CreateShape(new SphereGeometry(1), material); sphereA.GlobalPose = Matrix4x4.CreateTranslation(0, 30, 0); scene.AddActor(sphereA); // var sphereB = scene.Physics.CreateRigidDynamic(); sphereB.CreateShape(new SphereGeometry(1), material); sphereB.GlobalPose = Matrix4x4.CreateTranslation(0, 40, 0); scene.AddActor(sphereB); // var sphereC = scene.Physics.CreateRigidDynamic(); sphereC.CreateShape(new SphereGeometry(1), material); sphereC.GlobalPose = Matrix4x4.CreateTranslation(0, 50, 0); scene.AddActor(sphereC); _sphereC = sphereC; // var revoluteABJoint = scene.CreateJoint<RevoluteJoint>(sphereA, Matrix4x4.Identity, sphereB, Matrix4x4.Identity); revoluteABJoint.SetGlobalFrame(new Vector3(0, 35, 0), new Vector3(0, 0, 1)); revoluteABJoint.ConstraintFlag = ConstraintFlag.Visualization; var revoluteBCJoint = scene.CreateJoint<RevoluteJoint>(sphereB, Matrix4x4.Identity, sphereC, Matrix4x4.Identity); revoluteBCJoint.SetGlobalFrame(new Vector3(0, 45, 0), new Vector3(0, 0, 1)); revoluteBCJoint.ConstraintFlag = ConstraintFlag.Visualization; var revoluteAJoint = scene.CreateJoint<RevoluteJoint>(sphereA, Matrix4x4.Identity, null, Matrix4x4.Identity); revoluteAJoint.SetGlobalFrame(new Vector3(0, 30, 0), new Vector3(0, 0, 1)); revoluteAJoint.ConstraintFlag = ConstraintFlag.Visualization; }