-
Notifications
You must be signed in to change notification settings - Fork 57
Open
Description
Hey. I'm trying to do this. In Monogame.
`using System.Numerics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using PhysX;
using PhysX.VisualDebugger;
namespace Game3
{
public class ErrorOutput : ErrorCallback
{
public override void ReportError(ErrorCode errorCode, string message, string file, int lineNumber)
{
}
}
public class SampleFilterShader : SimulationFilterShader
{
public override FilterResult Filter(int attributes0, FilterData filterData0, int attributes1, FilterData filterData1)
{
return new FilterResult
{
FilterFlag = FilterFlag.Default,
PairFlags = PairFlag.ContactDefault | PairFlag.NotifyTouchFound | PairFlag.NotifyTouchLost
};
}
}
public class EventCallback : SimulationEventCallback
{
public override void OnContact(ContactPairHeader pairHeader, ContactPair[] pairs)
{
base.OnContact(pairHeader, pairs);
}
}
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Physics Physics = null;
Scene Scene = null;
RigidDynamic box = null;
RigidStatic ground = null;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
this.InitializePhysics();
base.Initialize();
}
void InitializePhysics()
{
ErrorOutput errorOutput = new ErrorOutput();
Foundation foundation = new Foundation(errorOutput);
var pvd = new PhysX.VisualDebugger.Pvd(foundation);
this.Physics = new Physics(foundation, true, pvd);
SceneDesc desc = new SceneDesc();
desc.Gravity = new System.Numerics.Vector3(0, -9.81f, 0);
desc.FilterShader = new SampleFilterShader();
desc.Flags |= SceneFlag.EnableGpuDynamics;
desc.BroadPhaseType |= BroadPhaseType.Gpu;
this.Scene = this.Physics.CreateScene(desc);
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.ActorAxes, true);
this.Physics.Pvd.Connect("localhost");
this.box = this.Scene.Physics.CreateRigidDynamic();
this.box.GlobalPose = Matrix4x4.CreateTranslation(new System.Numerics.Vector3(0, 4, 0));
RigidActorExt.CreateExclusiveShape(this.box, new BoxGeometry(1, 1, 1), this.Scene.Physics.CreateMaterial(0.5f, 0.5f, 0.5f), null);
this.Scene.AddActor(this.box);
this.ground = this.Scene.Physics.CreateRigidStatic();
this.ground.GlobalPose = Matrix4x4.CreateTranslation(new System.Numerics.Vector3(0, -8, 0));
RigidActorExt.CreateExclusiveShape(this.ground, new BoxGeometry(16, 8, 16), this.Scene.Physics.CreateMaterial(0.5f, 0.5f, 0.5f), null);
this.Scene.AddActor(this.ground);
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
this.Scene.Simulate(1.0f / 60.0f);
this.Scene.FetchResults(true);
this.Window.Title = this.box.GlobalPose.M42.ToString();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
base.Draw(gameTime);
}
}
}
`
But the contact is not fixed in the event.
What am I doing wrong? Thanks.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels