Space.add()

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
TheTrigger
Posts: 3
Joined: Tue Nov 27, 2012 12:05 pm

Space.add()

Post by TheTrigger »

Hi, I started using recently DEPU,
i should use the command Space.Add() to add an item to the emulator,
Can I use it with lists in another part of the code? (like Update)

Code: Select all

        List<Box> lBoxs = new List<Box>();
        int i = 0;

        public override void Update(float dt)
        {
            if (Game.KeyboardInput.IsKeyDown(Keys.Space))
            {
                lBoxs.Add(new Box(Game.Camera.Position, 1, 1, 1, 1));

                lBoxs[i].Position = Game.Camera.Position;
                lBoxs[i].LinearVelocity = new Vector3(10, 0, 0);
                // ....

                Space.Add(lBoxs[i]);

                ++i;
            }

//...
This does not work.. with no errors..

How can i create objects while playing?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Space.add()

Post by Norbo »

Space.Add doesn't care where it's called from (as long as it isn't asynchronous and interfering with the update or other bookkeeping!); that should work fine.

Is it possible that the box is actually being created, but it is invisible because no graphics get created for it?
TheTrigger
Posts: 3
Joined: Tue Nov 27, 2012 12:05 pm

Re: Space.add()

Post by TheTrigger »

but it is invisible because no graphics get created for it?
Exactly! I just tried, how set the graphics?

where can I find a documentation? ty
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Space.add()

Post by Norbo »

The physics engine has no built-in graphics; it's totally unaware of anything but the physical simulation itself. Any graphical system can be used to represent the simulation.

The BEPUphysicsDemos use the BEPUphysicsDrawer, a debug visualization library for drawing simple flat-shaded shapes. You get it, either download the main source or grab one of the documentation demos that uses it (like this one). But again, this is just a simple visualizer, not a graphics engine. For another example, the GettingStartedDemo just uses XNA Models and BasicEffects to draw boxes.
TheTrigger
Posts: 3
Joined: Tue Nov 27, 2012 12:05 pm

Re: Space.add()

Post by TheTrigger »

Thanks it worked, but there is a problem..
what caused it?

..and how can I make a model has the collisions according to its own form?

thanks!
Attachments
the cube behind is visible
the cube behind is visible
box.PNG (35.5 KiB) Viewed 5308 times
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Space.add()

Post by Norbo »

Depth states appear to be incorrect. Something else likely changed them so that depth writes/tests are disabled. A common source of sneaky state changes is the SpriteBatch; it's common enough that googling will find the answer. But again, the physics engine is totally separate from graphics.
and how can I make a model has the collisions according to its own form?
If you're asking how to make an entity which has a collision shape similar to the graphical model used to represent it, then I'd recommend checking out the BEPUphysicsDemos. Theres dozens of simulations in there showing how to make a bunch of different shapes. You can construct stuff from a variety of primitives, bundle those primitives together, create convex hulls, or even use mobile meshes directly (though mobile meshes are quite expensive).
Post Reply