public PhysxPhysicWorld(Vector3 gravity, bool connectToRemoteDebugger = false) { physix = new PhysX.Physics(new ErrorCallbackImp(), true); var sceneDesc = new SceneDesc() { Gravity = gravity.AsPhysX() }; scene = physix.CreateScene(sceneDesc); this.scene.SetVisualizationParameter(VisualizationParameter.Scale, 1.0f); this.scene.SetVisualizationParameter(VisualizationParameter.CollisionShapes, true); this.scene.SetVisualizationParameter(VisualizationParameter.JointLocalFrames, true); this.scene.SetVisualizationParameter(VisualizationParameter.JointLimits, true); this.scene.SetVisualizationParameter(VisualizationParameter.ParticleSystemPosition, true); this.scene.SetVisualizationParameter(VisualizationParameter.ActorAxes, true); // Connect to the remote debugger if it's there if (connectToRemoteDebugger) { physix.ConnectToRemoteDebugger("localhost"); } objs = new List<IPhysicObject>(); ctns = new List<IPhysicConstraint>(); cooking = physix.CreateCooking(); }
public PhysxPhysicWorld(Vector3 gravity, bool connectToRemoteDebugger = false) { physix = new PhysX.Physics(new ErrorCallbackImp(), true); var sceneDesc = new SceneDesc() { Gravity = gravity.AsPhysX() }; scene = physix.CreateScene(sceneDesc); this.scene.SetVisualizationParameter(VisualizationParameter.Scale, 1.0f); this.scene.SetVisualizationParameter(VisualizationParameter.CollisionShapes, true); this.scene.SetVisualizationParameter(VisualizationParameter.JointLocalFrames, true); this.scene.SetVisualizationParameter(VisualizationParameter.JointLimits, true); this.scene.SetVisualizationParameter(VisualizationParameter.ParticleSystemPosition, true); this.scene.SetVisualizationParameter(VisualizationParameter.ActorAxes, true); // Connect to the remote debugger if it's there if (connectToRemoteDebugger) { physix.ConnectToRemoteDebugger("localhost"); } objs = new List <IPhysicObject>(); ctns = new List <IPhysicConstraint>(); cooking = physix.CreateCooking(); }
protected override void ProcessKeyboard(Key[] pressedKeys) { // Create a rotation matrix around the y-axis Matrix rotation = Matrix.RotationAxis(Vector3.UnitY, _rotation); // Compute the forwards and right movement vectors // The controller will move in its own space, so rotate the usual forwards and right vectors Vector3 forward = Vector3.TransformNormal(Vector3.UnitZ, rotation); Vector3 right = Vector3.TransformNormal(Vector3.UnitX, rotation); Vector3 moveDelta = Vector3.Zero; if (pressedKeys.Contains(Key.W)) { moveDelta += forward; } if (pressedKeys.Contains(Key.S)) { moveDelta += -forward; } if (pressedKeys.Contains(Key.A)) { moveDelta += -right; } if (pressedKeys.Contains(Key.D)) { moveDelta += right; } // Normalize the distance vector (as we may of added two or more components together) Vector3 d = Vector3.Normalize(moveDelta); // Move the controller in the intended direction * a speed multiplier _controller.Move(d.AsPhysX() * _controllerSpeed, this.Engine.FrameTime); }
public PhysxCapsuleCharacterObject(CapsuleControllerDescription CapsuleControllerDescription, Vector3 position, Matrix rotation, Vector3 scale) { this.scale = scale; this.CapsuleControllerDescription = CapsuleControllerDescription; this.CapsuleControllerDescription.Position = position.AsPhysX(); CapsuleControllerDescription.Height *= scale.Y; CapsuleControllerDescription.Radius *= scale.X; this.rotation = rotation; }
public PhysxCapsuleCharacterObject(CapsuleControllerDescription CapsuleControllerDescription,Vector3 position, Matrix rotation,Vector3 scale) { this.scale = scale; this.CapsuleControllerDescription = CapsuleControllerDescription; this.CapsuleControllerDescription.Position = position.AsPhysX(); CapsuleControllerDescription.Height *= scale.Y; CapsuleControllerDescription.Radius *= scale.X; this.rotation = rotation; }
public PhysxBoxCharacterObject(BoxControllerDescription BoxControllerDescription, Vector3 position, Matrix rotation, Vector3 scale) { this.scale = scale; this.BoxControllerDescription = BoxControllerDescription; this.BoxControllerDescription.Position = position.AsPhysX(); StillDesign.PhysX.MathPrimitives.Vector3 vec = BoxControllerDescription.Size; vec.X *= scale.X; vec.Y *= scale.Y; vec.Z *= scale.Z; BoxControllerDescription.Size = vec; this.rotation = rotation; }
public override void GetPhysicsObjectsInRange(Vector3 position, float distance, CullerConditionAvaliator <IPhysicObject, SceneControl.IObject> CullerAvaliator, List <IPhysicObject> resp) { foreach (var item in Scene.OverlappedShapes(new Sphere(distance, position.AsPhysX()), ShapesType.All)) { if (item.Actor.UserData is IPhysicObject) { IPhysicObject IPhysicObject = item.Actor.UserData as IPhysicObject; if (CullerAvaliator(IPhysicObject, IPhysicObject.ObjectOwner)) { resp.Add(IPhysicObject); } } } }
public PhysxPhysicWorld(Vector3 gravity, bool connectToRemoteDebugger = false, bool safeAndSlowUpdate = true) { this.safeAndSlowUpdate = safeAndSlowUpdate; CoreDescription coreDesc = new CoreDescription(); UserOutput output = new UserOutput(); this.Core = new Core(coreDesc, output); Core core = this.Core; core.SetParameter(PhysicsParameter.VisualizationScale, 2.0f); core.SetParameter(PhysicsParameter.VisualizeCollisionShapes, true); core.SetParameter(PhysicsParameter.VisualizeClothMesh, true); core.SetParameter(PhysicsParameter.VisualizeJointLocalAxes, true); core.SetParameter(PhysicsParameter.VisualizeJointLimits, true); core.SetParameter(PhysicsParameter.VisualizeFluidPosition, true); core.SetParameter(PhysicsParameter.VisualizeFluidEmitters, false); // Slows down rendering a bit too much core.SetParameter(PhysicsParameter.VisualizeForceFields, true); core.SetParameter(PhysicsParameter.VisualizeSoftBodyMesh, true); SceneDescription sceneDesc = new SceneDescription() { Gravity = gravity.AsPhysX(), }; this.Scene = core.CreateScene(sceneDesc); // Connect to the remote debugger if it's there if (connectToRemoteDebugger) { core.Foundation.RemoteDebugger.Connect("localhost"); } ControllerManager = Scene.CreateControllerManager(); objs = new List <IPhysicObject>(); ctns = new List <IPhysicConstraint>(); TriggerReport = new Physics.TriggerReport(); Scene.UserTriggerReport = TriggerReport; Utilities.ErrorReport = errorReport; }
public override void GetPhysicsObjectsInRange(Vector3 position, float distance, CullerConditionAvaliator<IPhysicObject, SceneControl.IObject> CullerAvaliator, List<IPhysicObject> resp) { foreach (var item in Scene.OverlappedShapes(new Sphere(distance, position.AsPhysX()), ShapesType.All)) { if (item.Actor.UserData is IPhysicObject) { IPhysicObject IPhysicObject = item.Actor.UserData as IPhysicObject; if (CullerAvaliator(IPhysicObject, IPhysicObject.ObjectOwner)) { resp.Add(IPhysicObject); } } } }
protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory ,IContentManager contentManager) { PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld; base.LoadContent(GraphicInfo, factory, contentManager); int w = 25; int h = 25; float hw = w / 2.0f; float hh = h / 2.0f; Vector3 p = new Vector3(0, 20, 0); var grid = VertexGrid.CreateGrid(w, h); ClothModel ClothModel = new PloobsEngine.Modelo.ClothModel(factory, PhysxPhysicWorld, new ClothMeshDescription(), grid.Points,grid.TextCoords,grid.Indices, "Textures//meiofio"); var clothDesc = new ClothDescription() { Friction = 0.5f, ClothMesh = ClothModel.ClothMesh, Flags = ClothFlag.Gravity | ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization , Thickness = 0.2f, }; clothDesc.MeshData.AllocatePositions<Vector3>(grid.Points.Length ); clothDesc.MeshData.AllocateIndices<int>(grid.Indices.Length ); clothDesc.MeshData.AllocateNormals<Vector3>(grid.Points.Length ); clothDesc.MeshData.MaximumVertices = grid.Points.Length ; clothDesc.MeshData.MaximumIndices = grid.Indices.Length ; clothDesc.MeshData.NumberOfVertices = grid.Points.Length ; clothDesc.MeshData.NumberOfIndices = grid.Indices.Length ; PhysxClothObject PhysxClothObject = new PloobsEngine.Physics.PhysxClothObject(clothDesc, Matrix.CreateTranslation(-hw, 0, -hh) * Matrix.CreateTranslation(p)); ForwardXNABasicShader ForwardXNABasicShader = new PloobsEngine.Material.ForwardXNABasicShader(); ClothMaterial ClothMaterial = new ClothMaterial(ForwardXNABasicShader); IObject IObject = new PloobsEngine.SceneControl.IObject(ClothMaterial, ClothModel, PhysxClothObject); World.AddObject(IObject); // Four corner boxes to hold it in place var positions = new[] { new StillDesign.PhysX.MathPrimitives.Vector3(0, 0, -hh), // Back new StillDesign.PhysX.MathPrimitives.Vector3(0, 0, hh), // Front new StillDesign.PhysX.MathPrimitives.Vector3(-hw, 0, 0), // Left new StillDesign.PhysX.MathPrimitives.Vector3(hw, 0, 0), // Right }; var sizes = new[] { new StillDesign.PhysX.MathPrimitives.Vector3(w, 1, 1), // Back new StillDesign.PhysX.MathPrimitives.Vector3(w, 1, 1), // Front new StillDesign.PhysX.MathPrimitives.Vector3(1, 1, h), // Left new StillDesign.PhysX.MathPrimitives.Vector3(1, 1, h), //Right }; ///pra preender for (int i = 0; i < 2; i++) { var actorDesc = new ActorDescription() { GlobalPose = StillDesign.PhysX.MathPrimitives.Matrix.Translation(positions[i] + p.AsPhysX()), Shapes = { new BoxShapeDescription(sizes[i]) } }; var actor = PhysxPhysicWorld.Scene.CreateActor(actorDesc); PhysxClothObject.Cloth.AttachToShape(actor.Shapes.First(), (ClothAttachmentFlag)0); } BallThrowPhysx28 BallThrowBullet = new BallThrowPhysx28(this.World, GraphicFactory); this.AttachCleanUpAble(BallThrowBullet); this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo)); }
public override void ApplyImpulse(Vector3 position, Vector3 force) { Actor.AddForceAtLocalPosition(force.AsPhysX(), position.AsPhysX()); }
public override void GetPhysicsObjectsInRange(Vector3 position, float distance, CullerConditionAvaliator<IPhysicObject, SceneControl.IObject> CullerAvaliator, List<IPhysicObject> resp) { SphereGeometry SphereGeometry = new PhysX.SphereGeometry(distance); foreach (var item in scene.OverlapMultiple(SphereGeometry, PhysX.Math.Matrix.Translation(position.AsPhysX()))) { if (item.UserData is IPhysicObject) { IPhysicObject IPhysicObject = item.UserData as IPhysicObject; if (CullerAvaliator(IPhysicObject, IPhysicObject.ObjectOwner)) { resp.Add(IPhysicObject); } } } }
public override void GetPhysicsObjectsInRange(Vector3 position, float distance, CullerConditionAvaliator <IPhysicObject, SceneControl.IObject> CullerAvaliator, List <IPhysicObject> resp) { SphereGeometry SphereGeometry = new PhysX.SphereGeometry(distance); foreach (var item in scene.OverlapMultiple(SphereGeometry, PhysX.Math.Matrix.Translation(position.AsPhysX()))) { if (item.UserData is IPhysicObject) { IPhysicObject IPhysicObject = item.UserData as IPhysicObject; if (CullerAvaliator(IPhysicObject, IPhysicObject.ObjectOwner)) { resp.Add(IPhysicObject); } } } }
public PhysxPhysicWorld(Vector3 gravity, bool connectToRemoteDebugger = false, bool safeAndSlowUpdate = true) { this.safeAndSlowUpdate = safeAndSlowUpdate; CoreDescription coreDesc = new CoreDescription(); UserOutput output = new UserOutput(); this.Core = new Core(coreDesc, output); Core core = this.Core; core.SetParameter(PhysicsParameter.VisualizationScale, 2.0f); core.SetParameter(PhysicsParameter.VisualizeCollisionShapes, true); core.SetParameter(PhysicsParameter.VisualizeClothMesh, true); core.SetParameter(PhysicsParameter.VisualizeJointLocalAxes, true); core.SetParameter(PhysicsParameter.VisualizeJointLimits, true); core.SetParameter(PhysicsParameter.VisualizeFluidPosition, true); core.SetParameter(PhysicsParameter.VisualizeFluidEmitters, false); // Slows down rendering a bit too much core.SetParameter(PhysicsParameter.VisualizeForceFields, true); core.SetParameter(PhysicsParameter.VisualizeSoftBodyMesh, true); SceneDescription sceneDesc = new SceneDescription() { Gravity = gravity.AsPhysX() , }; this.Scene = core.CreateScene(sceneDesc); // Connect to the remote debugger if it's there if(connectToRemoteDebugger) core.Foundation.RemoteDebugger.Connect("localhost"); ControllerManager = Scene.CreateControllerManager(); objs = new List<IPhysicObject>(); ctns = new List<IPhysicConstraint>(); TriggerReport = new Physics.TriggerReport(); Scene.UserTriggerReport = TriggerReport; Utilities.ErrorReport = errorReport; }
protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager) { PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld; base.LoadContent(GraphicInfo, factory, contentManager); int w = 25; int h = 25; float hw = w / 2.0f; float hh = h / 2.0f; Vector3 p = new Vector3(0, 20, 0); var grid = VertexGrid.CreateGrid(w, h); ClothModel ClothModel = new PloobsEngine.Modelo.ClothModel(factory, PhysxPhysicWorld, new ClothMeshDescription(), grid.Points, grid.TextCoords, grid.Indices, "Textures//meiofio"); var clothDesc = new ClothDescription() { Friction = 0.5f, ClothMesh = ClothModel.ClothMesh, Flags = ClothFlag.Gravity | ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization, Thickness = 0.2f, }; clothDesc.MeshData.AllocatePositions <Vector3>(grid.Points.Length); clothDesc.MeshData.AllocateIndices <int>(grid.Indices.Length); clothDesc.MeshData.AllocateNormals <Vector3>(grid.Points.Length); clothDesc.MeshData.MaximumVertices = grid.Points.Length; clothDesc.MeshData.MaximumIndices = grid.Indices.Length; clothDesc.MeshData.NumberOfVertices = grid.Points.Length; clothDesc.MeshData.NumberOfIndices = grid.Indices.Length; PhysxClothObject PhysxClothObject = new PloobsEngine.Physics.PhysxClothObject(clothDesc, Matrix.CreateTranslation(-hw, 0, -hh) * Matrix.CreateTranslation(p)); ForwardXNABasicShader ForwardXNABasicShader = new PloobsEngine.Material.ForwardXNABasicShader(); ClothMaterial ClothMaterial = new ClothMaterial(ForwardXNABasicShader); IObject IObject = new PloobsEngine.SceneControl.IObject(ClothMaterial, ClothModel, PhysxClothObject); World.AddObject(IObject); // Four corner boxes to hold it in place var positions = new[] { new StillDesign.PhysX.MathPrimitives.Vector3(0, 0, -hh), // Back new StillDesign.PhysX.MathPrimitives.Vector3(0, 0, hh), // Front new StillDesign.PhysX.MathPrimitives.Vector3(-hw, 0, 0), // Left new StillDesign.PhysX.MathPrimitives.Vector3(hw, 0, 0), // Right }; var sizes = new[] { new StillDesign.PhysX.MathPrimitives.Vector3(w, 1, 1), // Back new StillDesign.PhysX.MathPrimitives.Vector3(w, 1, 1), // Front new StillDesign.PhysX.MathPrimitives.Vector3(1, 1, h), // Left new StillDesign.PhysX.MathPrimitives.Vector3(1, 1, h), //Right }; ///pra preender for (int i = 0; i < 2; i++) { var actorDesc = new ActorDescription() { GlobalPose = StillDesign.PhysX.MathPrimitives.Matrix.Translation(positions[i] + p.AsPhysX()), Shapes = { new BoxShapeDescription(sizes[i]) } }; var actor = PhysxPhysicWorld.Scene.CreateActor(actorDesc); PhysxClothObject.Cloth.AttachToShape(actor.Shapes.First(), (ClothAttachmentFlag)0); } BallThrowPhysx28 BallThrowBullet = new BallThrowPhysx28(this.World, GraphicFactory); this.AttachCleanUpAble(BallThrowBullet); this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo)); }