Skip to main content
added 534 characters in body
Source Link
Jon
  • 3.7k
  • 1
  • 14
  • 23

You are on the right track.

Your problem is most likely here:

translateObj(posX, posY, 0.0);

You didn't post the code for that method but, from your description, you are translating the object by, and not to (posX, posY). When your objects move, they should replace the translation component of their world matrix.

Edit per your edit:

You want to modify the matrix as follows (sorry for DX style):

//Static method
modelMatrix = Matrix::CreateTranslation(posX, posY, 0.0f);

//or

//Simple enough to just store it
modelMatrix.Translation = Vector3(posX, posY, 0.0f);

Something like this:

virtual void Update(float elapsed)
{
    // move stuff and check for collisions
    if (movingLeft)
    {
        posX -= elapsed* 0.001;
        modelMatrixUpdated = true;
    }
    else if (movingRight)
    {
        posX += elapsed * 0.001;
        modelMatrixUpdated = true;
    }
}

virtual void Render()
{
    setOrthoProj();
    setObjMatrices();
    //translateObj(posX, posY, 0.0);
    mySprite.Draw();
}

//void translateObj(float x, float y, float z)
//{
    //posX = x;
    //posY = y;
    //modelMatrixUpdated = true;
//}

void setObjMatrices()
{
    glUseProgram(program->programID);
    if (modelMatrixUpdated)
    {
       //update or replace modelMatrix here
       modelMatrix.Translation = Vector3(posX, posY, 0.0f);
       modelMatrixUpdated = false;
    }
    program->setModelMatrix(modelMatrix);
    program->setProjectionMatrix(projectionMatrix);
    program->setViewMatrix(viewMatrix);
}

You are on the right track.

Your problem is most likely here:

translateObj(posX, posY, 0.0);

You didn't post the code for that method but, from your description, you are translating the object by, and not to (posX, posY). When your objects move, they should replace the translation component of their world matrix.

Edit per your edit:

You want to modify the matrix as follows (sorry for DX style):

//Static method
modelMatrix = Matrix::CreateTranslation(posX, posY, 0.0f);

//or

//Simple enough to just store it
modelMatrix.Translation = Vector3(posX, posY, 0.0f);

Something like this:

void translateObj(float x, float y, float z)
{
    posX = x;
    posY = y;
    modelMatrixUpdated = true;
}

void setObjMatrices()
{
    glUseProgram(program->programID);
    if (modelMatrixUpdated)
    {
       //update or replace modelMatrix here
       modelMatrix.Translation = Vector3(posX, posY, 0.0f);
       modelMatrixUpdated = false;
    }
    program->setModelMatrix(modelMatrix);
    program->setProjectionMatrix(projectionMatrix);
    program->setViewMatrix(viewMatrix);
}

You are on the right track.

Your problem is most likely here:

translateObj(posX, posY, 0.0);

You didn't post the code for that method but, from your description, you are translating the object by, and not to (posX, posY). When your objects move, they should replace the translation component of their world matrix.

Edit per your edit:

You want to modify the matrix as follows (sorry for DX style):

//Static method
modelMatrix = Matrix::CreateTranslation(posX, posY, 0.0f);

//or

//Simple enough to just store it
modelMatrix.Translation = Vector3(posX, posY, 0.0f);

Something like this:

virtual void Update(float elapsed)
{
    // move stuff and check for collisions
    if (movingLeft)
    {
        posX -= elapsed* 0.001;
        modelMatrixUpdated = true;
    }
    else if (movingRight)
    {
        posX += elapsed * 0.001;
        modelMatrixUpdated = true;
    }
}

virtual void Render()
{
    setOrthoProj();
    setObjMatrices();
    //translateObj(posX, posY, 0.0);
    mySprite.Draw();
}

//void translateObj(float x, float y, float z)
//{
    //posX = x;
    //posY = y;
    //modelMatrixUpdated = true;
//}

void setObjMatrices()
{
    glUseProgram(program->programID);
    if (modelMatrixUpdated)
    {
       //update or replace modelMatrix here
       modelMatrix.Translation = Vector3(posX, posY, 0.0f);
       modelMatrixUpdated = false;
    }
    program->setModelMatrix(modelMatrix);
    program->setProjectionMatrix(projectionMatrix);
    program->setViewMatrix(viewMatrix);
}
added 608 characters in body
Source Link
Jon
  • 3.7k
  • 1
  • 14
  • 23

You are on the right track.

Your problem is most likely here:

translateObj(posX, posY, 0.0);

You didn't post the code for that method but, from your description, you are translating the object by, and not to (posX, posY). When your objects move, they should replace the translation component of their world matrix.

Edit per your edit:

You want to modify the matrix as follows (sorry for DX style):

//Static method
modelMatrix = Matrix::CreateTranslation(posX, posY, 0.0f);

//or

//Simple enough to just store it
modelMatrix.Translation = Vector3(posX, posY, 0.0f);

Something like this:

void translateObj(float x, float y, float z)
{
    posX = x;
    posY = y;
    modelMatrixUpdated = true;
}

void setObjMatrices()
{
    glUseProgram(program->programID);
    if (modelMatrixUpdated)
    {
       //update or replace modelMatrix here
       modelMatrix.Translation = Vector3(posX, posY, 0.0f);
       modelMatrixUpdated = false;
    }
    program->setModelMatrix(modelMatrix);
    program->setProjectionMatrix(projectionMatrix);
    program->setViewMatrix(viewMatrix);
}

You are on the right track.

Your problem is most likely here:

translateObj(posX, posY, 0.0);

You didn't post the code for that method but, from your description, you are translating the object by, and not to (posX, posY). When your objects move, they should replace the translation component of their world matrix.

Edit per your edit:

You want to modify the matrix as follows (sorry for DX style):

//Static method
modelMatrix = Matrix::CreateTranslation(posX, posY, 0.0f);

//or

//Simple enough to just store it
modelMatrix.Translation = Vector3(posX, posY, 0.0f);

You are on the right track.

Your problem is most likely here:

translateObj(posX, posY, 0.0);

You didn't post the code for that method but, from your description, you are translating the object by, and not to (posX, posY). When your objects move, they should replace the translation component of their world matrix.

Edit per your edit:

You want to modify the matrix as follows (sorry for DX style):

//Static method
modelMatrix = Matrix::CreateTranslation(posX, posY, 0.0f);

//or

//Simple enough to just store it
modelMatrix.Translation = Vector3(posX, posY, 0.0f);

Something like this:

void translateObj(float x, float y, float z)
{
    posX = x;
    posY = y;
    modelMatrixUpdated = true;
}

void setObjMatrices()
{
    glUseProgram(program->programID);
    if (modelMatrixUpdated)
    {
       //update or replace modelMatrix here
       modelMatrix.Translation = Vector3(posX, posY, 0.0f);
       modelMatrixUpdated = false;
    }
    program->setModelMatrix(modelMatrix);
    program->setProjectionMatrix(projectionMatrix);
    program->setViewMatrix(viewMatrix);
}
added 290 characters in body
Source Link
Jon
  • 3.7k
  • 1
  • 14
  • 23

You are on the right track.

Your problem is most likely here:

translateObj(posX, posY, 0.0);

You didn't post the code for that method but, from your description, you are translating the object by, and not to (posX, posY). When your objects move, they should replace the translation component of their world matrix.

Edit per your edit:

You want to modify the matrix as follows (sorry for DX style):

//Static method
modelMatrix = Matrix::CreateTranslation(posX, posY, 0.0f);

//or

//Simple enough to just store it
modelMatrix.Translation = Vector3(posX, posY, 0.0f);

You are on the right track.

Your problem is most likely here:

translateObj(posX, posY, 0.0);

You didn't post the code for that method but, from your description, you are translating the object by, and not to (posX, posY). When your objects move, they should replace the translation component of their world matrix.

You are on the right track.

Your problem is most likely here:

translateObj(posX, posY, 0.0);

You didn't post the code for that method but, from your description, you are translating the object by, and not to (posX, posY). When your objects move, they should replace the translation component of their world matrix.

Edit per your edit:

You want to modify the matrix as follows (sorry for DX style):

//Static method
modelMatrix = Matrix::CreateTranslation(posX, posY, 0.0f);

//or

//Simple enough to just store it
modelMatrix.Translation = Vector3(posX, posY, 0.0f);
Source Link
Jon
  • 3.7k
  • 1
  • 14
  • 23
Loading