Page 1 of 1

Remove or Replace Box

Posted: Sun Jan 22, 2012 11:09 am
by galodoido794
I must be very beginner hehehe I'm having a Box remove the space.
For example:

var = entityCollision raycastResult.HitObject the EntityCollidable;
Box box = (Box) entityCollision.Entity;
Space.Remove (box):

It seems that he was physically removed, but the design it is not removed ...

What is the best approach for this?

What I'm trying to do is remove the box and put another in his place with other features. I'm researching how do I put a new box without impacting the neighbors Box.

Re: Remove or Replace Box

Posted: Sun Jan 22, 2012 5:17 pm
by Norbo
Do you mean the graphic is not removed? Since the physics engine has no knowledge or understanding of graphics, removing something from the Space will not affect any related graphics system. The graphics system in use must be notified of the change somehow.

Re: Remove or Replace Box

Posted: Sun Jan 22, 2012 5:53 pm
by galodoido794
I do not know if there is any problem to get the entity class EntityCollidable ...

I was debugging and noticed that it happened in about six methods remove (in Space), but did not remove the design but only the physical

I'm still thinking about what can be ..

Re: Remove or Replace Box

Posted: Sun Jan 22, 2012 6:01 pm
by Norbo
Sorry, I'm not sure what you mean.

Is it throwing exceptions when you try to cast the BroadPhaseEntry to an EntityCollidable? If the thing hit by the ray is not an EntityCollidable, that will happen; the type should be tested before attempting to cast it. Same thing for the box entity, though you do not need to cast to a Box to remove it from the Space; the Space understands what an entity is.

Re: Remove or Replace Box

Posted: Sun Jan 22, 2012 6:07 pm
by galodoido794
Simulate this situation is easy. Just change the part of code:

Code: Select all

 
                    if (Space.RayCast(new Ray(game.Camera.Position, game.Camera.WorldMatrix.Forward), 1000, rayCastFilter, out raycastResult))
                    {
                        var entityCollision = raycastResult.HitObject as EntityCollidable;
                        if (entityCollision != null && entityCollision.Entity.IsDynamic)
                        {
                                Box b = (Box)entityCollision.Entity;
                                Space.Remove(b);
                       }
                    }
I'm using the latest version of the Fork.
What happens is that is physically removed, but still designed BOX.

Re: Remove or Replace Box

Posted: Sun Jan 22, 2012 6:34 pm
by Norbo
What do you expect to occur, and what is happening that is different?

If I use that code in the demos right-click ray cast, I get the expected result- if it hits a dynamic entity, it tries to remove it from the space. If it's not a Box entity, it crashes. If it is a Box, it's removed from the space, but the graphic remains in place because the space knows nothing about graphics.

Re: Remove or Replace Box

Posted: Sun Jan 22, 2012 6:41 pm
by galodoido794
Finally... LOL

Code: Select all

game.ModelDrawer.Remove(entityCollision.Entity);