示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RigidBody{TShapeFigure}"/> class.
        /// TODO:
        /// * Make this class generic, i.e. unaware of the specific shape. It shall take
        ///   the shape as an argument on construction.
        /// * Move all shape-dependent code to the shape class/interface, such as inertia
        ///   calculation (would take the mass as input).
        /// * Perhaps create an internal shape interface.
        /// * The <see cref="IBody{TShape}"/> shall only know one shape, as opposed to
        ///   "original" and "current". The shape shall be able to "update" (transform) itself,
        ///   taking position and orientation as input. The shape then provides the "original"
        ///   and "current" representation of itself. This way, it can be guaranteed that the
        ///   actual transformation is only performed once per step and body/shape.
        /// </summary>
        public RigidBody(
            IBodyCalculationHelper bodyCalculationHelper,
            IIsaacNewtonHelper isaacNewtonHelper,
            double mass,
            IRigidShape <TShapeFigure> shape,
            BodyState initialBodyState)
        {
            ArgumentChecks.AssertNotNull(bodyCalculationHelper, nameof(bodyCalculationHelper));
            ArgumentChecks.AssertNotNull(isaacNewtonHelper, nameof(isaacNewtonHelper));
            ArgumentChecks.AssertIsStrictPositive(mass, nameof(mass));
            ArgumentChecks.AssertNotNull(shape, nameof(shape));

            // Helpers
            this._bodyCalculationHelper = bodyCalculationHelper;
            this._isaacNewtonHelper     = isaacNewtonHelper;

            // Static properties
            this.Mass    = mass;
            this._shape  = shape;
            this.Inertia = this._shape.CalculateInertia(this.Mass);

            // Dynamic properties
            this._appliedForce               = new Vector2();
            this._appliedTorque              = 0;
            this._appliedAcceleration        = new Vector2();
            this._appliedAngularAcceleration = 0;
            this._overrideVelocity           = null;

            this._state = initialBodyState;

            // Update the shape, based on the initial state
            this._shape.Update(this._state.Position, this._state.Orientation);
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShapeFactory"/> class.
        /// </summary>
        public ShapeFactory(
            IPolygonTransformationHelper polygonTransformationHelper,
            IPolygonCalculationHelper polygonCalculationHelper,
            IBodyCalculationHelper bodyCalculationHelper)
        {
            ArgumentChecks.AssertNotNull(polygonTransformationHelper, nameof(polygonTransformationHelper));
            ArgumentChecks.AssertNotNull(polygonCalculationHelper, nameof(polygonCalculationHelper));
            ArgumentChecks.AssertNotNull(bodyCalculationHelper, nameof(bodyCalculationHelper));

            this._polygonTransformationHelper = polygonTransformationHelper;
            this._polygonCalculationHelper    = polygonCalculationHelper;
            this._bodyCalculationHelper       = bodyCalculationHelper;
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ElementFactory"/> class.
        /// </summary>
        public ElementFactory(
            IShapeFactory shapeFactory,
            IBodyCalculationHelper bodyCalculationHelper,
            IIsaacNewtonHelper isaacNewtonHelper)
        {
            ArgumentChecks.AssertNotNull(shapeFactory, nameof(shapeFactory));
            ArgumentChecks.AssertNotNull(bodyCalculationHelper, nameof(bodyCalculationHelper));
            ArgumentChecks.AssertNotNull(isaacNewtonHelper, nameof(isaacNewtonHelper));

            this._shapeFactory          = shapeFactory;
            this._bodyCalculationHelper = bodyCalculationHelper;
            this._isaacNewtonHelper     = isaacNewtonHelper;
        }
示例#4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RigidPolygonShape"/> class.
        /// </summary>
        public RigidPolygonShape(
            IPolygonTransformationHelper polygonTransformationHelper,
            IBodyCalculationHelper bodyCalculationHelper,
            double volume,
            Polygon originalPolygon)
        {
            ArgumentChecks.AssertNotNull(polygonTransformationHelper, nameof(polygonTransformationHelper));
            ArgumentChecks.AssertNotNull(bodyCalculationHelper, nameof(bodyCalculationHelper));
            ArgumentChecks.AssertIsStrictPositive(volume, nameof(volume));
            ArgumentChecks.AssertNotNull(originalPolygon, nameof(originalPolygon));

            this._polygonTransformationHelper = polygonTransformationHelper;
            this._bodyCalculationHelper       = bodyCalculationHelper;
            this.Volume   = volume;
            this.Original = originalPolygon;
            this.Current  = this.Original;
        }