Page 2 of 2

Re: Compound B can't hold entities as angular velocity increases

Posted: Fri Nov 26, 2010 12:13 am
by Spankenstein
Thanks Norbo. I'll get on it but just stick with spheres and single contact points for now :)

Re: Compound B can't hold entities as angular velocity increases

Posted: Fri Nov 26, 2010 12:56 am
by Spankenstein
I can't get the custom entities' bounding box to draw. Have I constructed it correctly:

Code: Select all

    class HollowSphere : Entity
    {
        private Game1 game;
        private float radius;

        public HollowSphere(Game1 game, Vector3 position, float radius)
        {
            this.game = game;
            this.radius = radius;

            TeleportTo(position);
        }

        public void Draw()
        {
            //game.ShapeDrawer.DrawShape(entity, 0);

            // Draw the physics entity's bounding box
            if (game.Debug.Switch)
            {
                game.WireShapeDrawer.DrawWireBox(BoundingBox, Color.Red);
            }
        }

        protected override void Initialize(bool physicallySimulated)
        {
            ForceBoundingBoxRefit(0);
            InitializeNonDynamicData();
            maximumRadiusFromCenterPosition = radius;   //outerRadius;
            maximumRadius = maximumRadiusFromCenterPosition + CenterOfMassOffset.Length();
        }

        public override void GetExtremePoint(ref Microsoft.Xna.Framework.Vector3 d, ref Microsoft.Xna.Framework.Vector3 positionToUse, ref Microsoft.Xna.Framework.Quaternion orientationToUse, float margin, out Microsoft.Xna.Framework.Vector3 extremePoint)
        {
            throw new NotImplementedException();
        }

        public override void GetExtremePoints(ref Microsoft.Xna.Framework.Vector3 d, out Microsoft.Xna.Framework.Vector3 min, out Microsoft.Xna.Framework.Vector3 max, float margin)
        {
            throw new NotImplementedException();
        }

        public override void GetExtremePoints(ref Microsoft.Xna.Framework.Vector3 d, ref Microsoft.Xna.Framework.Vector3 positionToUse, ref Microsoft.Xna.Framework.Quaternion orientationToUse, out Microsoft.Xna.Framework.Vector3 min, out Microsoft.Xna.Framework.Vector3 max, float margin)
        {
            d.Normalize();

            max = d * (radius + margin) + positionToUse;
            min = -d * (radius + margin) + positionToUse;
        }

        public float Radius
        {
            get { return radius; }
            set { radius = value; }
        }
    }

Re: Compound B can't hold entities as angular velocity increases

Posted: Fri Nov 26, 2010 1:03 am
by Norbo
At a glance it looks okay; define the other two GetExtremePoints functions too.

Re: Compound B can't hold entities as angular velocity increases

Posted: Fri Nov 26, 2010 11:19 pm
by Spankenstein
I've defined the other ExtremePoints:

Code: Select all

        public override void GetExtremePoint(ref Microsoft.Xna.Framework.Vector3 d, ref Microsoft.Xna.Framework.Vector3 positionToUse, ref Microsoft.Xna.Framework.Quaternion orientationToUse, float margin, out Microsoft.Xna.Framework.Vector3 extremePoint)
        {
            d.Normalize();

            extremePoint = d * (radius + margin) + positionToUse;
        }

        public override void GetExtremePoints(ref Microsoft.Xna.Framework.Vector3 d, out Microsoft.Xna.Framework.Vector3 min, out Microsoft.Xna.Framework.Vector3 max, float margin)
        {
            d.Normalize();

            max = d * (radius + margin);
            min = -d * (radius + margin);
        }

        public override void GetExtremePoints(ref Microsoft.Xna.Framework.Vector3 d, ref Microsoft.Xna.Framework.Vector3 positionToUse, ref Microsoft.Xna.Framework.Quaternion orientationToUse, out Microsoft.Xna.Framework.Vector3 min, out Microsoft.Xna.Framework.Vector3 max, float margin)
        {
            d.Normalize();

            max = d * (radius + margin) + positionToUse;
            min = -d * (radius + margin) + positionToUse;
        }
The BoundingBox is still returning:

Min = (0,0,0)
Max = (0,0,0)

Re: Compound B can't hold entities as angular velocity increases

Posted: Fri Nov 26, 2010 11:42 pm
by Norbo
How are you getting the bounding box? Put some breakpoints into the get extreme points tests to see what they are returning, even though the relevant one appears to be perfectly fine.

By the way, before you get too far into making a custom concave entity, I should remind you that if all you are using is spheres, then a DistanceLimit constraint would be a really good and simple approach here. The only problems with a distance limit constraint are that it won't change angular momentums in the same way as a rotating shell (for spheres, you can't tell; for boxes, you can), and that you'd have to apply your own impulses to make everything move in circles. If you don't plan on creating a hollowsphere-box special case, then you might want to consider just using the DistanceLimit. Even if you plan to eventually include boxes, it might be enough until v0.15.0 comes out and you can use a better system to create your custom shapes.

Re: Compound B can't hold entities as angular velocity increases

Posted: Fri Nov 26, 2010 11:48 pm
by Spankenstein
None of the overriding GetExtremePoints methods are ever called?!

Neither is the overriding Initialize method.

Re: Compound B can't hold entities as angular velocity increases

Posted: Fri Nov 26, 2010 11:56 pm
by Norbo
Ah yes- forgot something: call Initalize in your constructor. All of this annoyance is going away in v0.15.0 :)

Then, add it to your space like any other entity.

Re: Compound B can't hold entities as angular velocity increases

Posted: Sat Nov 27, 2010 12:06 am
by Spankenstein
Excellent, thank you. The min/max values are now set correctly for the BoundingBox property but the TeleportTo method has no affect on the box's poisition:

Code: Select all

        public HollowSphere(Game1 game, Vector3 position, float radius)
        {
            this.game = game;
            this.radius = radius;

            TeleportTo(position);
            Initialize(true);
        }
In other words it can't be moved when the entity moves?

Re: Compound B can't hold entities as angular velocity increases

Posted: Sat Nov 27, 2010 12:13 am
by Norbo
The teleports usually happen after the initialization, but it shouldn't really matter. Be sure you're not looking at a buffered property after the entity is added to the space. Buffered properties read values don't update until the end of a frame. CenterPosition is a buffered property. Use the InternalCenterPosition for non-buffered values.

To prevent such confusion in v0.15.0, the buffered/interpolated values are all stuck into a manager of their own on the Entity, separate from the normal properties.

Re: Compound B can't hold entities as angular velocity increases

Posted: Sat Nov 27, 2010 12:25 am
by Spankenstein
The BoundingBox never appears at its intended (teleported) position on any consequent frame. All other bounding boxes draw correctly by using

(Indices) 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7

and

BoundingBox.GetCorners()

The corners are returned with the correct scale applied but there is no translation.

This only occurs with the custom Entity and no other Entity.

Re: Compound B can't hold entities as angular velocity increases

Posted: Sat Nov 27, 2010 1:06 am
by Norbo
Breakpoint various spots and see what the values are in the extreme points, internal center position, IsActive, etc. Find something that may be responsible for the end result and keep working back as far as you can. Try setting its position from a different context (after construction). If you hit something that seems to be within the engine, let me know and I'll try to help. v0.15.0 is absorbing all of my time right now :)