Page 1 of 1

Getting Objects to move.

Posted: Wed Aug 17, 2011 9:29 pm
by theneonirvana
First thing, ive read the starter documentation, and alot about the position updater. but i cant seem to get this right, i dnt quite understand how BEPU is handeling things so this is what im doing,...

I have 3 types of complicated objects that are 3D objects that have properties like , model, position, rotation, etc.

i have added a feild to the base class called _3D for a ISpaceObject for BEPU,

Whenever i create an object, it makes a new ISpaceObject for it, if the ISpaceObject for the _3D Class is not null, and then changed, it removes it from space before adding the new one. so i dont get duplicate entities.

one the _3D object is created and has its ISpaceObject i add the ISpaceObject to my Space.

So Technically it should all be running in the background just not rendering, Awsome, excellent, and easy... but...

how do i access the position or rotation information that is being used for that entitiy? so i can update my objects with the information comming out of the engine

for example...

this.Cub1.Position = this.PhySpace.Entities.IndexOf(Cube1).Position

Now, i understand its not stright over, and i understand that for maybe 1 object passed into the engine, it created multiple entitiys, so maybe my way, cant be done... thats fine....

then how do i do this?

Re: Getting Objects to move.

Posted: Wed Aug 17, 2011 10:05 pm
by Norbo
ISpaceObject is an extremely high level interface defining an object which can belong to a Space. It covers everything from constraints to environment meshes. Because of this, it's not a good candidate for storing in a gameplay object if you need to extract any information from it.

The Entity class defines objects which have position and velocity. You can access this data directly using the entity's properties like Position, Orientation, LinearVelocity, AngularVelocity, etc.

Keep in mind that StaticMesh, InstancedMesh, Terrain, and other immobile collidable objects are not Entities. They are Collidables.

If the game logic seems to require a single object to cover both StaticMeshes and mobile Entities, then there's going to be a problem since the two objects share no direct common features except for ISpaceObject. In this situation, I would recommend refactoring the game logic away from 'inheritance tree' approaches and towards composition or component approaches, or anything that removes the cover-all requirement.

If you want to keep a link from an entity to your gameplay object, put the gameplay object in the entity's Tag property. It's designed to hold arbitrary user data.

Here's a description of how the common objects relate to each other.
-Entity covers all objects with position and velocity. Dynamic (respond to collisions) and kinematic (do not respond to collisions) entities exist. The Entity class itself manages the motion and dynamics, not the collision.
-BroadPhaseEntry lives in the collision detection pipeline, starting in the BroadPhase. The BroadPhase creates BroadPhaseOverlaps between BroadPhaseEntries.
-Collidable inherits from BroadPhaseEntry. Collidables are objects which generally create contact points with other objects during collisions.
-StaticMesh, Terrain, and InstancedMesh inherit from Collidable.
-EntityCollidable inherits from Collidable.
-Entity does not inherit from EntityCollidable. Entity has no parent class (other than Object). Entity has an EntityCollidable in the entity.CollisionInformation property. The entity.CollisionInformation object acts as the Entity's proxy in the collision pipeline.

Re: Getting Objects to move.

Posted: Thu Aug 18, 2011 12:09 am
by theneonirvana
So your saying, if i were to say when i add a Prefab Box to my Space, i count my entitys to find the last index and then set the last indexed entities Tag property to my object like so.

Space.Entities[count].Tag = Cube1;

Then during my updates i can simply Find the Entity for Cube1 using a method,

and then update Cube1.Position = Space.Entities[FoundIndexNumber].Position;

and the rest of my draw and crap runs for Cube1-3 so it should filter down, Correct?>


Got to run out for 30 min then gunna try that

Re: Getting Objects to move.

Posted: Thu Aug 18, 2011 12:15 am
by Norbo
No, just keep a direct reference to the Entity itself and completely bypass searching in an array. :)

Re: Getting Objects to move.

Posted: Thu Aug 18, 2011 1:36 am
by theneonirvana
So your saying to do for example

ok so your saying

Create like a prefab box for Cube1 and Add that prefab Box to Space.

Then store the Entity in say, Cube1.Entity
Right?

but when i add somthing to space it does return any value, if you use Space.Entitys.IndexOf is asks for a Entity (of course) lol but no overload's, nor any other methods i see of retriving the object, so i go down to counting them as i add them and keeping a list. i know im missing somthing,

Re: Getting Objects to move.

Posted: Thu Aug 18, 2011 1:42 am
by Norbo
A constructor, like "new Box(position, 1,1,1,1)" returns a Box instance. You don't have to immediately add that to the Space with Space.Add. Instead, you can take the Box returned by that constructor and put it somewhere else- like in your Entity property. Then, add it to the space.

Re: Getting Objects to move.

Posted: Thu Aug 18, 2011 1:44 am
by theneonirvana
*SMACKS FORHEAD* FFS LMFAO TY

Re: Getting Objects to move.

Posted: Thu Aug 18, 2011 2:33 am
by theneonirvana
So my Gravity is set to the 0f,-9.34f, 0 vector in the force updater as well and the objects seem to go in random directors or almost "gone with the wind" and then fly upward in the Y+ direction

Re: Getting Objects to move.

Posted: Thu Aug 18, 2011 2:36 am
by Norbo
There could be a lot of things wrong ;)

My first guess would be that things are stuck inside each other, so when it runs, they try to de-penetrate. This can cause explosions.

I would recommend fiddling around in the BEPUphysicsDemos project source (found in the main source download: http://bepuphysics.codeplex.com/SourceC ... changesets) to get a feel for everything. The BEPUphysicsDrawer makes it easy to see where objects are located, removing the guesswork.

Re: Getting Objects to move.

Posted: Thu Aug 18, 2011 2:50 am
by theneonirvana
rite again, i set the Box LxWxH to high making them explode.... Thank you so much for your quick reply's and awsome information,

ill look through the info you sent me to try to fix the other litte problems, (my objects go straight up, and then go into like a waving up and down into the posative x+ lol, i probably forgot a negative sign on the Gravity Vector :) again ty