Ejemplo n.º 1
0
    public bool updatePhysics(float elapsed)
    {
        // get the object position
        mPos.x = transform.position.x;
        mPos.y = transform.position.y;

        //-------------------------------------------

        mVel = mVel * (1.0f - GlobalVariable.PHYSICS_FRICTION * elapsed);

        float displacementX = mVel.x * elapsed;
        float displacementy = mVel.y * elapsed;

        matrix.setTranslationMat(displacementX, displacementy);
        mPos = matrix * mPos;

        /*Back up solution
         * Vector2 displacement = new Vector2(displacementX, displacementy);
         * mPos.x += displacement.x;
         * mPos.y += displacement.y;*/

        //-----------------------------------------------
        tempPos.x = mPos.x;
        tempPos.y = mPos.y;

        transform.position = tempPos;
        // transform.position = new Vector2(transform.position.x + mVel.x, transform.position.y + mVel.y);
        return(true);
    }
Ejemplo n.º 2
0
    public bool updatePhysics(float elapsed)
    {
        // get the object position
        mPos.x = transform.position.x;
        mPos.y = transform.position.y;

        //-------------------------------------------

        //Stores the displacement in a vector
        HVector2D displacement = mVel * elapsed;

        //Creates a new Matrix
        HMatrix2D transMatrix = new HMatrix2D();

        //Set the translation matrix with displacement values
        transMatrix.setTranslationMat(displacement.x, displacement.y);

        //Updates original vector pos with translation matrix
        mPos = transMatrix * mPos;

        //Adds friction physics to the Velocity, so the ball slows down.
        mVel = mVel * GlobalVariable.PHYSICS_FRICTION;

        //-----------------------------------------------
        tempPos.x = mPos.x;
        tempPos.y = mPos.y;

        transform.position = tempPos;
        //transform.position = new Vector2(transform.position.x + mVel.x, transform.position.y + mVel.y);
        return(true);
    }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        HVector2D vA = new HVector2D();

        vA.x = 1;
        vA.y = 2;

        HVector2D vB   = new HVector2D(5, 7);
        HVector2D vSum = vA + vB;

        float dp = vA.dotProduct(vB);

        HVector2D mPos         = new HVector2D(10, 10);
        HVector2D displacement = new HVector2D(3, 4);

        HMatrix2D translationMatrix = new HMatrix2D();

        translationMatrix.setTranslationMat(displacement.x, displacement.y);
        mPos = translationMatrix * mPos;
    }