Consider Normalizing Constraint constructors.

Post and discuss features you'd like to see in the BEPUphysics library.
Post Reply
bryanedds
Posts: 14
Joined: Tue Jul 13, 2010 6:17 pm

Consider Normalizing Constraint constructors.

Post by bryanedds »

Hi!

I had to write this code to get dynamic constraint creation / editing working in my editor -

Code: Select all

using BEPUphysics.Constraints;
using Microsoft.Xna.Framework;

namespace ProjectY
{
    public class AngularMotorY : AngularMotor
    {
        public AngularMotorY() : base(null, null) { }
    }

    public class BallSocketJointY : BallSocketJoint
    {
        public BallSocketJointY() : base(null, null, Vector3.Zero) { }
    }

    public class DistanceJointY : DistanceJoint
    {
        public DistanceJointY() : base(null, null, Vector3.Zero, Vector3.Zero) { }
    }

    public class DistanceLimitY : DistanceLimit
    {
        public DistanceLimitY() : base(null, null, Vector3.Zero, Vector3.Zero, 0, float.MaxValue) { }
    }

    public class EllipseSwingLimitY : EllipseSwingLimit
    {
        public EllipseSwingLimitY() : base(null, null, Vector3.Up, float.MaxValue, float.MaxValue) { }
    }

    public class LinearAxisLimitY : LinearAxisLimit
    {
        public LinearAxisLimitY() : base(null, null, Vector3.Zero, Vector3.Zero, Vector3.Up, 0, float.MaxValue) { }
    }

    public class LinearAxisMotorY : LinearAxisMotor
    {
        public LinearAxisMotorY() : base(null, null, Vector3.Zero, Vector3.Zero, Vector3.Up) { }
    }

    public class LineSliderJointY : LineSliderJoint
    {
        public LineSliderJointY() : base(null, null, Vector3.Zero, Vector3.Up, Vector3.Zero) { }
    }

    public class MaximumAngularSpeedConstraintY : MaximumAngularSpeedConstraint
    {
        public MaximumAngularSpeedConstraintY() : base(null, float.MaxValue) { }
    }

    public class MaximumLinearSpeedConstraintY : MaximumLinearSpeedConstraint
    {
        public MaximumLinearSpeedConstraintY() : base(null, float.MaxValue) { }
    }

    public class NoRotationJointY : NoRotationJoint
    {
        public NoRotationJointY() : base(null, null) { }
    }

    public class PointOnLineJointY : PointOnLineJoint
    {
        public PointOnLineJointY() : base(null, null, Vector3.Zero, Vector3.Up, Vector3.Zero) { }
    }

    public class PointOnPlaneJointY : PointOnPlaneJoint
    {
        public PointOnPlaneJointY() : base(null, null, Vector3.Zero, Vector3.Up, Vector3.Zero) { }
    }

    public class RevoluteAngularJointY : RevoluteAngularJoint
    {
        public RevoluteAngularJointY() : base(null, null, Vector3.Up) { }
    }

    public class RevoluteLimitY : RevoluteLimit
    {
        public RevoluteLimitY() : base(null, null) { }
    }

    public class RevoluteMotorY : RevoluteMotor
    {
        public RevoluteMotorY() : base(null, null, Vector3.Up) { }
    }

    public class SingleEntityAngularMotorY : SingleEntityAngularMotor
    {
        public SingleEntityAngularMotorY() : base() { }
    }

    public class SingleEntityLinearMotorY : SingleEntityLinearMotor
    {
        public SingleEntityLinearMotorY() : base() { }
    }

    public class SwingLimitY : SwingLimit
    {
        public SwingLimitY() : base(null, null, Vector3.Zero, Vector3.Zero, float.MaxValue) { }
    }

    public class SwivelHingeAngularJointY : SwivelHingeAngularJoint
    {
        public SwivelHingeAngularJointY() : base(null, null, Vector3.Up, Vector3.Up) { }
    }

    public class TwistJointY : TwistJoint
    {
        public TwistJointY() : base(null, null, Vector3.Up, Vector3.Up) { }
    }

    public class TwistLimitY : TwistLimit
    {
        public TwistLimitY() : base(null, null, Vector3.Up, Vector3.Up, 0, float.MaxValue) { }
    }

    public class TwistMotorY : TwistMotor
    {
        public TwistMotorY() : base(null, null, Vector3.Up, Vector3.Up) { }
    }
}
All of these classes can validly have empty constructors overloads. I need these constructors to be consistent so I can use reflection to instantiate these classes via simple string definitions in my editor. Could you consider writing those so that I can get rid of these gnarly sub-classes?

Thanks!
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Consider Normalizing Constraint constructors.

Post by Norbo »

Alright, I'll try to fit it into v0.15.0. It may also be useful for other advanced users that seek to avoid the constraint's 'guessed' initialization in favor of custom object initializers.
bryanedds
Posts: 14
Joined: Tue Jul 13, 2010 6:17 pm

Re: Consider Normalizing Constraint constructors.

Post by bryanedds »

Awesome Norbo!

Also note that for the constraints, I change their entities in real-time in the editor. This works okay with the simple constraints, but not on the other connectors such as LineSliderJoint, other SolverGroup-derived objects, et al. Those only allow you to set their entities in the constructor and that not going to really work in a dynamic editor without a lot of extra hackery.

But, if that doesn't make any sense, the main thing is to allow me to get rid of that awful code file I pasted by normalized the simpler connectors :P

cheers and thanks!
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Consider Normalizing Constraint constructors.

Post by Norbo »

I don't see any good workaround for the SolverGroup connection issue. I was going to say change each individual constraint's connection until a better option was available, but I think there may actually be a bug that would prevent that from working. I'll look into it for v0.15.0.

Until then, that leaves the less desirable option of dealing with each child constraint individually outside of a solver group.
Post Reply