Page 1 of 1

Space.add()

Posted: Tue Nov 27, 2012 12:47 pm
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?

Re: Space.add()

Posted: Tue Nov 27, 2012 9:02 pm
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?

Re: Space.add()

Posted: Tue Nov 27, 2012 9:44 pm
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

Re: Space.add()

Posted: Tue Nov 27, 2012 10:13 pm
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.

Re: Space.add()

Posted: Wed Nov 28, 2012 9:20 pm
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!

Re: Space.add()

Posted: Wed Nov 28, 2012 9:46 pm
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).