Collision Detection
Posted: Tue Jun 05, 2012 1:28 pm
I have a camera and I've created a Sphere and assigned it's position to the Camera Position, but when the sphere collides with a static mesh I want the camera to stop moving.
How do I go about doing this?
I tried the following:
in my initializing...
sphere = new Sphere(Camera.Position, 1, 1);
sphere.IgnoreShapeChanges = true;
sphere.PositionUpdateMode = PositionUpdateMode.Continuous;
sphere.CollisionInformation.Events.DetectingInitialCollision += RemoveFriction;
sphere.LocalInertiaTensorInverse = new Matrix3X3();
sphere.LinearDamping = 0;
space.Add(sphere);
in my update:
CameraMovement(); // re-position the camera in it's new position
space.Update();
lastPosition = Camera.Position;
in
void RemoveFriction(EntityCollidable sender, BroadPhaseEntry other, NarrowPhasePair pair)
{
var collidablePair = pair as CollidablePairHandler;
if (collidablePair != null)
{
Vector3 direction = Vector3.Normalize(Camera.Position - lastPosition);
Camera.Position = Camera.Position - (direction * collidablePair.Contacts[0].Contact.PenetrationDepth);
collidablePair.UpdateMaterialProperties(new InteractionProperties());
}
}
But that doesn't seem to work, what should I be doing here?
Thanks,
ED
How do I go about doing this?
I tried the following:
in my initializing...
sphere = new Sphere(Camera.Position, 1, 1);
sphere.IgnoreShapeChanges = true;
sphere.PositionUpdateMode = PositionUpdateMode.Continuous;
sphere.CollisionInformation.Events.DetectingInitialCollision += RemoveFriction;
sphere.LocalInertiaTensorInverse = new Matrix3X3();
sphere.LinearDamping = 0;
space.Add(sphere);
in my update:
CameraMovement(); // re-position the camera in it's new position
space.Update();
lastPosition = Camera.Position;
in
void RemoveFriction(EntityCollidable sender, BroadPhaseEntry other, NarrowPhasePair pair)
{
var collidablePair = pair as CollidablePairHandler;
if (collidablePair != null)
{
Vector3 direction = Vector3.Normalize(Camera.Position - lastPosition);
Camera.Position = Camera.Position - (direction * collidablePair.Contacts[0].Contact.PenetrationDepth);
collidablePair.UpdateMaterialProperties(new InteractionProperties());
}
}
But that doesn't seem to work, what should I be doing here?
Thanks,
ED