public override void AddObject(IPhysicObject obj) { if (obj is PhysxPhysicObject) { PhysxPhysicObject PhysxPhysicObject = obj as PhysxPhysicObject; if (PhysxPhysicObject.Actor == null) { PhysxPhysicObject.Actor = Scene.CreateActor(PhysxPhysicObject.ActorDesc, int.MaxValue); PhysxPhysicObject.Actor.UserData = obj; for (int i = 0; i < PhysxPhysicObject.ActorDesc.Shapes.Count; i++) { PhysxPhysicObject.Actor.Shapes[i].UserData = PhysxPhysicObject.ActorDesc.Shapes[i].UserData; } } else { PhysxPhysicObject.Actor.UserData = obj; } } else if (obj is PhysxClothObject) { PhysxClothObject PhysxPhysicObject = obj as PhysxClothObject; PhysxPhysicObject.Cloth = Scene.CreateCloth(PhysxPhysicObject.ClothDesc); PhysxPhysicObject.Cloth.UserData = obj; } else if (obj is PhysxFluidObject) { PhysxFluidObject PhysxPhysicObject = obj as PhysxFluidObject; PhysxPhysicObject.Fluid = Scene.CreateFluid(PhysxPhysicObject.FluidDesc); PhysxPhysicObject.Fluid.UserData = obj; } else if (obj is PhysxCapsuleCharacterObject) { PhysxCapsuleCharacterObject PhysxPhysicObject = obj as PhysxCapsuleCharacterObject; PhysxPhysicObject.Controller = ControllerManager.CreateController <CapsuleController>(PhysxPhysicObject.CapsuleControllerDescription); PhysxPhysicObject.Controller.UserData = obj; } else if (obj is PhysxBoxCharacterObject) { PhysxBoxCharacterObject PhysxPhysicObject = obj as PhysxBoxCharacterObject; PhysxPhysicObject.Controller = ControllerManager.CreateController <BoxController>((PhysxPhysicObject.BoxControllerDescription)); PhysxPhysicObject.Controller.UserData = obj; } objs.Add(obj); }
protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory ,IContentManager contentManager) { PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld; base.LoadContent(GraphicInfo, factory, contentManager); { SimpleModel simpleModel = new SimpleModel(factory, "Model//cenario"); PhysxTriangleMesh tmesh = new PhysxTriangleMesh(PhysxPhysicWorld, simpleModel, Matrix.Identity, Vector3.One); ForwardXNABasicShader shader = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default()); ForwardMaterial fmaterial = new ForwardMaterial(shader); IObject obj = new IObject(fmaterial, simpleModel, tmesh); this.World.AddObject(obj); } { ///Controller description ///YOu have BoxControllerDescription and SphereControllerDescription BoxControllerDescription desc = new BoxControllerDescription(1, 1, 1); desc.UpDirection = Axis.Y; desc.SlopeLimit = 0; desc.SkinWidth = 0.2f; desc.StepOffset = 0.5f; desc.InteractionFlag = CCTInteractionFlag.Include | CCTInteractionFlag.UseFilter; SimpleModel sm = new SimpleModel(factory, "..\\Content\\Model\\block"); sm.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Blue), TextureType.DIFFUSE); ForwardXNABasicShader shader = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default()); ForwardMaterial mat = new ForwardMaterial(shader); ///Character Object PhysxBoxCharacterObject PhysxCapsuleCharacterObject = new PhysxBoxCharacterObject(desc, new Vector3(50) ,Matrix.Identity, Vector3.One * 5); IObject marine = new IObject(mat, sm, PhysxCapsuleCharacterObject); this.World.AddObject(marine); marine.OnUpdate += new OnUpdate(marine_OnUpdate); } BallThrowPhysx28 BallThrowBullet = new BallThrowPhysx28(this.World, GraphicFactory); this.AttachCleanUpAble(BallThrowBullet); this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo)); }
public override void RemoveObject(IPhysicObject obj) { if (obj is PhysxPhysicObject) { PhysxPhysicObject PhysxPhysicObject = obj as PhysxPhysicObject; PhysxPhysicObject.Actor.UserData = null; PhysxPhysicObject.Actor.Dispose(); } else if (obj is PhysxClothObject) { PhysxClothObject PhysxPhysicObject = obj as PhysxClothObject; PhysxPhysicObject.Cloth.UserData = null; PhysxPhysicObject.Cloth.Dispose(); } else if (obj is PhysxFluidObject) { PhysxFluidObject PhysxPhysicObject = obj as PhysxFluidObject; PhysxPhysicObject.Fluid.UserData = null; PhysxPhysicObject.Fluid.Dispose(); } else if (obj is PhysxCapsuleCharacterObject) { PhysxCapsuleCharacterObject PhysxPhysicObject = obj as PhysxCapsuleCharacterObject; PhysxPhysicObject.Controller.UserData = null; PhysxPhysicObject.Controller.Dispose(); } else if (obj is PhysxBoxCharacterObject) { PhysxBoxCharacterObject PhysxPhysicObject = obj as PhysxBoxCharacterObject; PhysxPhysicObject.Controller.UserData = null; PhysxPhysicObject.Controller.Dispose(); } objs.Remove(obj); }