Page 1 of 1

Compund Objects

Posted: Tue Dec 09, 2008 3:09 pm
by goldsword
I'm having some trouble using compund objects, I cant find a way to orient an object making up the compund. Setting the orientationQuaternion property of an object making up the compund will have no effect. Creating a cylinder, rotating it and then attaching it to an object will cause the cylinder to have an orientation of Quaternion.Identity. It doesnt help setting the orientation before adding it to the compund or setting it after the compound been created.

Re: Compund Objects

Posted: Tue Dec 09, 2008 9:31 pm
by Zukarakox
What method are you using to create the compound? Try downloading the BEPUphysics demos source and looking at the compoundbody example.

Something like this should work -

Code: Select all

CompoundBody body;
List<Entity> subbody = new List<Entity>();

Entity a = new Cylinder(Vector3.Zero,  10, 1, 5);
a.orientationQuaternion = Quaternion.CreateFromAxisAngle(Vector3.Forward, MathHelper.PiOver2);
subbody.add(a);
Entity b = new Cylinder(Vector3.Zero, 10, 1, 5);
subbody.add(b);

body = new CompoundBody(subbody);
space.add(body);

Re: Compund Objects

Posted: Tue Dec 09, 2008 11:31 pm
by Norbo
Another thing to note is that the entity.orientationQuaternion field is double buffered. This means that its value will only be set when the entity is next updated.

Subbodies are not updated like other entities, so the write buffer never gets used. Try using the entity.internalOrientationQuaternion; it is not buffered.

Re: Compund Objects

Posted: Mon May 04, 2009 5:53 pm
by b3n
Hi guys,

I have the same problem as mentoined with he current version of the BepuPhysics Lib. Even the code above as provided doesnt work. The compound sub objects are not rotated, no matter you do before adding them. When adding the same subobject to the SPACE instead of to the compound objects they are right aligned. But as far as they are part of the compount object, their aligment is lost.

Unfortunately BepuPhysics is not open source, so I can't figure out what is the problem. Therefore I would need help of the BepuTeam I guess?

Here is the code I use, you can insert it in the SpaceShip example of the Demos, to test it instead of the space ship creation:

Code: Select all

                    List<Entity> subbody = new List<Entity>();

                    Vector3 Position = new Vector3(0, 5, 0);

                    Box newBox = new Box(Position, 2, 1, 5, 10);
                    newBox.Add(frontCenter);
                    
                    Capsule capsuleRight = new Capsule(Position + new Vector3(1.0f, 0, 0), 5.0f, 1, 1);
                    capsuleRight.orientationQuaternion = Quaternion.CreateFromAxisAngle(Vector3.Right, (float)Math.PI / 2.0f);
                    subbody.Add(capsuleRight);
                    //space.add(capsuleRight);

                    Capsule capsuleLeft = new Capsule(Position + new Vector3(-1.0f, 0, 0), 5.0f, 1, 1);
                    capsuleLeft.orientationQuaternion = Quaternion.CreateFromAxisAngle(Vector3.Right, (float)Math.PI / 2.0f);
                    subbody.Add(capsuleLeft);
                    //space.add(capsuleLeft);

                    CompoundBody ship = new CompoundBody(subbody);
I also noticed that in ALL demos you never rotate a compound sub object. So is it not working at all in the current implementation of BEPU physics? If not, please implement that, else compound object would much less flexible i guess.

Cheers,
b3n

Re: Compund Objects

Posted: Mon May 04, 2009 7:13 pm
by Norbo
Try using the internalOrientationQuaternion property instead of orientationQuaternion. As I mentioned in my previous post, the orientationQuaternion field is double buffered for thread safety. However, as the subobjects are never updated like a normal object (they are not in the space), these buffered fields are not updated. The 'internal__' properties directly modify the values and do not require a space update.

This has always been a little confusing and I'd like to address it in some way in a future version.