Facing manipulation

Discuss any questions about BEPUphysics or problems encountered.
kavatortank
Posts: 91
Joined: Tue May 14, 2013 12:17 pm

Re: Facing manipulation

Post by kavatortank »

Okay, I will try this later.
How I can catch the global bounding box of the vehicle ?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Facing manipulation

Post by Norbo »

For the body, you can use Vehicle.Body.CollisionInformation.BoundingBox. The wheels are not included in that bounding box. If you want to include them, iterate through the Vehicle's Wheels and check the Wheel.Shape.Detector.CollisionInformation.BoundingBox. To get the whole bounding box, merge all of those individual bounding boxes together.
kavatortank
Posts: 91
Joined: Tue May 14, 2013 12:17 pm

Re: Facing manipulation

Post by kavatortank »

Okok, and I've got a question about the bepuphysicDrawer.
This is your engine ? Because this is really optmise :)
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Facing manipulation

Post by Norbo »

Yup, I made it all- but while BEPUphysics itself is decently optimized, I wouldn't quite call the drawer ultraspeedy :) I should be able to improve on the drawer when it gets moved over to MonoGame.
kavatortank
Posts: 91
Joined: Tue May 14, 2013 12:17 pm

Re: Facing manipulation

Post by kavatortank »

1 - How has BepuPhysics grace, I can do a replay as a killcam in the video war games like callofduty?
2 - How can I réalister BepuPhysics thanks to a kind of slow motion?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Facing manipulation

Post by Norbo »

kavatortank wrote:1 - How has BepuPhysics grace, I can do a replay as a killcam in the video war games like callofduty?
If you want to support that kind of replay, the easiest way is to store a running window of 'keyframes' representing the latest motion and state of relevant objects. The replay would just then be a simple nonsimulated animation working through the frames.

(Attempting to rewind and replay by actually doing simulation in a deterministic fashion is a horrible minefield which is best avoided.)
kavatortank wrote:2 - How can I réalister BepuPhysics thanks to a kind of slow motion?
If you want to do slow motion while using the parameterless Space.Update(), set the Space.TimeStepSettings.TimeStepDuration to value appropriate for the slow-mo for the duration of the effect (e.g. if you want to progress have half speed and you're using the default of 1/60f, set it to 1/120f). Since the parameterless Space.Update() takes a single time step of length Space.TimeStepSettings.TimeStepDuration, the simulation will advance forward more slowly.

If you're using the Space.Update(dt) version (that is, you're using internal time stepping based on the accumulated time), then you can pass in a dt scaled by the slow motion speed factor. This will make the engine take fewer steps.

If the slow motion is slow enough, you may want to also set the Space.TimeStepSettings.TimeStepDuration to a proportionately smaller value even if you're using the Space.Update(dt) method so that the simulation is higher quality.
kavatortank
Posts: 91
Joined: Tue May 14, 2013 12:17 pm

Re: Facing manipulation

Post by kavatortank »

Sorry but can you be more precisly ? With some examples.
Because I did'nt understand the global idea.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Facing manipulation

Post by Norbo »

Could you narrow down the question?
kavatortank
Posts: 91
Joined: Tue May 14, 2013 12:17 pm

Re: Facing manipulation

Post by kavatortank »

1-
Norbo wrote:Could you narrow down the question?
I don't know how to narrow my question because I just don't understand your answers.


2-

I want to know how I can disable collision response with all objet ? For example, I have a box and I want to know when this box is collided but I don't want any collision response.
I saw the detector volume demo, but I don't know if it's appropriate to my problem.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Facing manipulation

Post by Norbo »

I don't know how to narrow my question because I just don't understand your answers.
When I'm helping someone, it is very valuable to know what they actually need help with so I don't spend extra time blabbering about unhelpful things.

It is often possible to narrow it down further based on isolating sources of confusion. I suspect you did actually understand bits and pieces of the post, even if you didn't see how it fit together to form a solution. In general, if you are able to pinpoint pieces that you do understand, you can more easily isolate the pieces you do not understand.

It's also helpful to determine the type of confusion. Here are a few examples of such misunderstanding types:
-Sometimes, it's just a matter of someone not being a native English speaker, so they end up using Google Translate or something similar and the meaning gets corrupted. Other times, it's as simple as using the wrong kind of vocabulary (for example, difficult or obscure terms) in important areas, causing the meaning to be lost. Knowing that this is source of confusion is helpful since it suggests solutions. For example, a simple rephrasing may provide enough variation to understand it, or at least progress to a different type of misunderstanding.
-Sometimes people understand the atomic building blocks- say, at the level of individual function calls- but don't see how a combination of building blocks does something useful. If this is the source of the confusion, then focusing on the high conceptual level is most important.
-Sometimes people understand the high level, but don't know enough about the low implementation level. If this is the source of the confusion, then using example source or demos is usually effective where applicable. If such things are not applicable (in the cases where an example doesn't exist, and it would take too much work to create), answering narrowed implementation questions as needed is usually effective.

This process of isolating and refining the misunderstanding can be thought of as bridging a gap: by putting the pieces in place that you can, your side of the bridge gets closer to my side. In addition, to complete the bridge faster, I need to know which pieces should be put down to extend and connect my side to yours.

Very rarely is something simply not understood on any level, as if the text were just a blank page, an empty chasm, with no possibility of a more targeted question. It is sufficiently rare that I've never seen it truly happen, and I've been doing this a while (both on this forum and elsewhere :)).

For now, I'll try a rephrasing:
1 - How has BepuPhysics grace, I can do a replay as a killcam in the video war games like callofduty?
I assumed this meant you wanted to replay a portion of previous gameplay. To do this, create an animation representing the previous motion, and then play it on demand. It's just like a regular character animation- it has a series of frames, the current time is used to find a frame to use (or interpolate between adjacent frames for smoother motion), and as time progresses the animation progresses.

You can't go back in time to make the replay once you want it, though, so you'll need to be always 'recording' the animation. Maintain a circular buffer of frames of sufficient length to cover any such replay.

The reason you should use an animation like this rather than resetting the simulation to its original state and resimulating is that simulation is not deterministic. Making simulation fully deterministic is very difficult.
2 - How can I réalister BepuPhysics thanks to a kind of slow motion?
I assumed this meant you wanted to make the physics simulation proceed in slow motion. The way to do this depends on how your game updates BEPUphysics. There are two Space.Update functions; one is parameterless, the other takes a float representing the time since the last frame.

The parameterless Space.Update() moves the simulation forward by one time step of length Space.TimeStepSettings.TimeStepDuration. So, if you're calling Space.Update() one time per frame and you want to run in slow motion, you essentially want the simulation to move forward by less time per time step. So, set the Space.TimeStepSettings.TimeStepDuration to a smaller value. Try this in the demos and watch what happens.

The Space.Update(dt) version of the method, on the other hand, takes as many time steps of length Space.TimeStepSettings.TimeStepDuration as needed to simulate the accumulated time. This is called 'internal time stepping'. The "accumulated time" is the amount of time built up over multiple calls of Space.Update(dt). Each call adds 'dt' to the accumulator, and then the update calls as many time steps as can fit within the accumulated time. (There is usually a bit left over. The remainder is used to interpolate between the current and previous frames using interpolation, and the results are stored in the interpolated state buffers. See section 2.B.)

To make the Space.Update(dt) function simulate in slow-mo, you can simply pass in a dt value which is smaller than the actual dt value. However, keep in mind that it is still taking steps of length Space.TimeStepSettings.TimeStepDuration; if you want to increase simulation accuracy, you should decrease Space.TimeStepSettings.TimeStepDuration so more, smaller steps are taken.
I want to know how I can disable collision response with all objet ? For example, I have a box and I want to know when this box is collided but I don't want any collision response.
Collision rules would be appropriate. Defining a rule of NoSolver where appropriate would stop collision response, but allow collision detection.
kavatortank
Posts: 91
Joined: Tue May 14, 2013 12:17 pm

Re: Facing manipulation

Post by kavatortank »

Norbo wrote:
I want to know how I can disable collision response with all objet ? For example, I have a box and I want to know when this box is collided but I don't want any collision response.
Collision rules would be appropriate. Defining a rule of NoSolver where appropriate would stop collision response, but allow collision detection.
I test that :

Code: Select all

kapow.CollisionInformation.Events.ContactCreated += new BEPUphysics.BroadPhaseEntries.Events.ContactCreatedEventHandler<BEPUphysics.BroadPhaseEntries.MobileCollidables.EntityCollidable>(Events_ContactCreated);
kapow.CollisionInformation.CollisionRules.Personal = CollisionRule.NoSolver;
            
And in the method Events_ContactCreated I delete the kapow from the space.

And I have this exeption :

Code: Select all

throw new ArgumentException("Cannot remove that member from this DeactivationManager; it belongs to a different or no manager.");
And I have the impression that the kapow is not checking all collision ( because it's deleted after a certain time after the collision between objets ), but the update mode is continuous.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Facing manipulation

Post by Norbo »

That exception is caused by an attempt to remove the same object multiple times. Chances are, multiple contacts were generated in a single frame. The deferred event handler ran for each of those contacts once the frame ended. The second execution of the handler will cause a crash since the object was already removed.

To avoid this, only remove the object once. One simple way to do this is to check if the object's Space property is null. If it is, the object does not belong to a space and a removal should not be attempted.
kavatortank
Posts: 91
Joined: Tue May 14, 2013 12:17 pm

Re: Facing manipulation

Post by kavatortank »

Ok, I tried that but now I have a error :

Code: Select all

public override Entities.Entity EntityB
{
          get { return compoundInfoB.entity; }
}
This is a getter in this class : CompoundPairHandler
compoundInfoB = null, so I have an error, do you know why ?

This error occure when I'm deleting the tank when the missile impact it.

or this error :

Code: Select all

        public override Entities.Entity EntityB
        {
            get { return convexInfo.entity; }
        }
in CompoundConvexPairHandler class. ConverxInfo = null
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Facing manipulation

Post by Norbo »

It sounds like the pair has been kept around after it has been cleaned up and returned to a resource pool. Make sure that the pair isn't used outside of the event handler; it is not guaranteed to stay alive.

It may also be possible for a cleaned-up pair to be passed into a deferred event handler, but this would require some odd conditions. The mix of space removals and deferred events is too complicated for me to debug remotely without a bunch of context. If this isn't caused by just keeping a reference around to a dead pair, this may require a runnable reproduction in the BEPUphysicsDemos for me to look at to verify that it is or is not expected behavior. (Incidentally, I'd like to delete the current deferred event implementation.)
kavatortank
Posts: 91
Joined: Tue May 14, 2013 12:17 pm

Re: Facing manipulation

Post by kavatortank »

1/ In my event I have this :

Code: Select all

void Events_ContactCreated(BEPUphysics.BroadPhaseEntries.MobileCollidables.EntityCollidable sender, Collidable other, CollidablePairHandler pair, ContactData contact)
{
      if (sender.Entity.Space == Space)
      {
           string str = (string)other.Tag;
           if (pair.EntityB != null && (string)pair.EntityB.Tag == "missile")
           {
                   Space.Remove(Vehicle);
                   Space.Remove(turret);
                   Space.Remove(turret2);
           }
}
And I think, if I add this, it works great :

Code: Select all

void Events_ContactCreated(BEPUphysics.BroadPhaseEntries.MobileCollidables.EntityCollidable sender, Collidable other, CollidablePairHandler pair, ContactData contact)
{
      if (sender.Entity.Space == Space && Vehicle.Body.Space != null && turret.Space != null && turret2.Space != null)
      {
           string str = (string)other.Tag;
           if (pair.EntityB != null && (string)pair.EntityB.Tag == "missile")
           {
                   Space.Remove(Vehicle);
                   Space.Remove(turret);
                   Space.Remove(turret2);
           }
}
But I don't know why. You see ?

EDIT :

2/ I think also ( question 2 ), that when I delete a thing in the creatingContact event, bepu have bugs. But it's occure only when the objet is colliding with multiple objets. Why ?
Post Reply