Esempio n. 1
0
        /// <summary>
        /// default constructor.
        /// </summary>
        /// <param name="w">world to add this body to (done automatically)</param>
        public Body(World w)
        {
            mAABB = new AABB();
            mBaseShape = null;
            mGlobalShape = null;
            mPointMasses = new List<PointMass>();
            mScale = Vector2.One;
            mIsStatic = false;
            mKinematic = false;

            mMaterial = 0;

            w.addBody(this);
        }
Esempio n. 2
0
        public static void RenderAABB(AABB aabb)
        {
            float srodekX = (aabb.Max.X - aabb.Min.X)/2 + aabb.Min.X, strodekY = (aabb.Max.Y - aabb.Min.Y)/2 + aabb.Min.Y;
            Gl.glPushMatrix();

            Gl.glColor3f(0, 0, 1);
            Gl.glBegin(Gl.GL_LINES);

            //wall
            //1
            Gl.glVertex2f(aabb.Min.X, aabb.Min.Y);
            Gl.glVertex2f(aabb.Min.X, aabb.Max.Y);
            //2
            Gl.glVertex2f(aabb.Min.X, aabb.Max.Y);
            Gl.glVertex2f(aabb.Max.X, aabb.Max.Y);
            //3
            Gl.glVertex2f(aabb.Max.X, aabb.Max.Y);
            Gl.glVertex2f(aabb.Max.X, aabb.Min.Y);
            //4
            Gl.glVertex2f(aabb.Max.X, aabb.Min.Y);
            Gl.glVertex2f(aabb.Min.X, aabb.Min.Y);

            //springs
            //1
            Gl.glVertex2f(aabb.Min.X, aabb.Min.Y);
            Gl.glVertex2f(srodekX, strodekY);
            //2
            Gl.glVertex2f(aabb.Min.X, aabb.Max.Y);
            Gl.glVertex2f(srodekX, strodekY);
            //3
            Gl.glVertex2f(aabb.Max.X, aabb.Max.Y);
            Gl.glVertex2f(srodekX, strodekY);
            //4
            Gl.glVertex2f(aabb.Max.X, aabb.Min.Y);
            Gl.glVertex2f(srodekX, strodekY);

            Gl.glEnd();

            Gl.glPopMatrix();
        }
Esempio n. 3
0
        /// <summary>
        /// create a body, and set its shape and position immediately - with individual masses for each PointMass.
        /// </summary>
        /// <param name="w">world to add this body to (done automatically)</param>
        /// <param name="shape">closed shape for this body</param>
        /// <param name="pointMasses">list of masses for each PointMass</param>
        /// <param name="position">global position of the body</param>
        /// <param name="angleInRadians">global angle of the body</param>
        /// <param name="scale">local scale of the body</param>
        /// <param name="kinematic">whether this body is kinematically controlled.</param>
        public void Setup(World w, ClosedShape shape, List<float> pointMasses, Vector2 position, float angleInRadians, Vector2 scale, bool kinematic)
        {
            mAABB = new AABB();
            DerivedPos = position;
            DerivedAngle = angleInRadians;
            mLastAngle = DerivedAngle;
            mScale = scale;
            mMaterial = 0;
            mIsStatic = false;
            mKinematic = kinematic;

            mPointMasses = new List<PointMass>();
            setShape(shape);
            for (int i = 0; i < mPointMasses.Count; i++)
                mPointMasses [i].Mass = pointMasses [i];

            updateAABB(0f, true);

            w.addBody(this);
        }
Esempio n. 4
0
        /// <summary>
        /// create a body, and set its shape and position immediately
        /// </summary>
        /// <param name="w">world to add this body to (done automatically)</param>
        /// <param name="shape">closed shape for this body</param>
        /// <param name="massPerPoint">mass for each PointMass to be created</param>
        /// <param name="position">global position of the body</param>
        /// <param name="angleInRadians">global angle of the body</param>
        /// <param name="scale">local scale of the body</param>
        /// <param name="kinematic">whether this body is kinematically controlled</param>
        public void Setup(World w, ClosedShape shape, float massPerPoint, Vector2 position, float angleInRadians, Vector2 scale, bool kinematic)
        {
            mAABB = new AABB();
            DerivedPos = position;
            DerivedAngle = angleInRadians;
            mLastAngle = DerivedAngle;
            mScale = scale;
            mMaterial = 0;
            mIsStatic = float.IsPositiveInfinity(massPerPoint);
            mKinematic = kinematic;

            mPointMasses = new List<PointMass>();
            setShape(shape);
            for (int i = 0; i < mPointMasses.Count; i++)
                mPointMasses [i].Mass = massPerPoint;

            updateAABB(0f, true);

            w.addBody(this);
            List<Vector2> points = new List<Vector2>();
            foreach (PointMass m in mPointMasses)
            {
                points.Add(m.Position);
            }
        }
Esempio n. 5
0
        public bool intersects(ref AABB box)
        {
            // X overlap check.
            bool overlapX = ((Min.x <= box.Max.x) && (Max.x >= box.Min.x));
            bool overlapY = ((Min.y <= box.Max.y) && (Max.y >= box.Min.y));

            return (overlapX && overlapY);
        }
Esempio n. 6
0
 public void setWorldLimits(Vector2 min, Vector2 max)
 {
     mWorldLimits = new AABB(ref min, ref max);
     mWorldSize = max - min;
     mWorldGridStep = mWorldSize / 32;
 }
Esempio n. 7
0
        public bool intersects(ref AABB box)
        {
            // X overlap check.
            bool overlapX = ((Min.X <= box.Max.X) && (Max.X >= box.Min.X));
            bool overlapY = ((Min.Y <= box.Max.Y) && (Max.Y >= box.Min.Y));

            return (overlapX && overlapY);
        }