Sure....and thanks for the help!
inside namespace
const char* textureFilenames[] = {
"interior.png",
"exterior.png",
"ruedas.png",
"motorTrenDel.png" };
// Model scale factor
float kChasisScale = 100.0f;
float kInteriorScale = 100.0f;
float kWheelScale = 100.0f;
float kLastChasisScale = kChasisScale;
float kLastInteriorScale = kInteriorScale;
float kLastWheelScale = kWheelScale;
float floatAngleX = 0.0f;
float floatAngleY = 0.0f;
float floatAngleZ = 0.0f;
int interiorTexture = 2;
int chasisTexture = 1;
int wheelTexture = 0;
QCAR::Matrix44F mCurrentRotation = SampleMath::Matrix44FIdentity();
QCAR::Matrix44F mAccumulatedRotation = SampleMath::Matrix44FIdentity();
and inside renderFrameQCAR
// OpenGL 2
QCAR::Matrix44F modelViewProjection;
glUseProgram(shaderProgramID);
// MOTOR
modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(trackable->getPose());
mCurrentRotation = SampleMath::Matrix44FIdentity();
ShaderUtils::scalePoseMatrix(kWheelScale, kWheelScale, kWheelScale, &modelViewMatrix.data[0]);
ShaderUtils::rotatePoseMatrix(floatAngleZ, 0.0f, 0.0f, 1.0f, &mCurrentRotation.data[0]);
ShaderUtils::rotatePoseMatrix(floatAngleY, 0.0f, 1.0f, 0.0f, &mCurrentRotation.data[0]);
ShaderUtils::rotatePoseMatrix(floatAngleX, 1.0f, 0.0f, 0.0f, &mCurrentRotation.data[0]);
ShaderUtils::multiplyMatrix(&mCurrentRotation.data[0], &mAccumulatedRotation.data[0], &mAccumulatedRotation.data[0]);
ShaderUtils::multiplyMatrix(&modelViewMatrix.data[0], &mAccumulatedRotation.data[0], &modelViewMatrix.data[0]);
ShaderUtils::multiplyMatrix(&qUtils.projectionMatrix.data[0], &modelViewMatrix.data[0], &modelViewProjection.data[0]);
floatAngleX = 0.0f;
floatAngleY = 0.0f;
floatAngleZ = 0.0f;
glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &motorTrenDelVerts[0]);
glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &motorTrenDelNormals[0]);
glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &motorTrenDelTexCoords[0]);
glEnableVertexAttribArray(vertexHandle);
glEnableVertexAttribArray(normalHandle);
glEnableVertexAttribArray(textureCoordHandle);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, [[textures objectAtIndex:3] textureID]);
glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (const GLfloat*)&modelViewProjection.data[0]);
glDrawArrays(GL_TRIANGLES, 0, motorTrenDelNumVerts);
// INTERIOR
modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(trackable->getPose());
ShaderUtils::scalePoseMatrix(kWheelScale, kWheelScale, kWheelScale, &modelViewMatrix.data[0]);
ShaderUtils::rotatePoseMatrix(floatAngleZ, 0.0f, 0.0f, 1.0f, &mCurrentRotation.data[0]);
ShaderUtils::rotatePoseMatrix(floatAngleY, 0.0f, 1.0f, 0.0f, &mCurrentRotation.data[0]);
ShaderUtils::rotatePoseMatrix(floatAngleX, 1.0f, 0.0f, 0.0f, &mCurrentRotation.data[0]);
ShaderUtils::multiplyMatrix(&mCurrentRotation.data[0], &mAccumulatedRotation.data[0], &mAccumulatedRotation.data[0]);
ShaderUtils::multiplyMatrix(&modelViewMatrix.data[0], &mAccumulatedRotation.data[0], &modelViewMatrix.data[0]);
ShaderUtils::multiplyMatrix(&qUtils.projectionMatrix.data[0], &modelViewMatrix.data[0], &modelViewProjection.data[0]);
floatAngleX = 0.0f;
floatAngleY = 0.0f;
floatAngleZ = 0.0f;
glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &interiorVerts[0]);
glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &interiorNormals[0]);
glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &interiorTexCoords[0]);
glEnableVertexAttribArray(vertexHandle);
glEnableVertexAttribArray(normalHandle);
glEnableVertexAttribArray(textureCoordHandle);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, [[textures objectAtIndex:0] textureID]);
glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (const GLfloat*)&modelViewProjection.data[0]);
glDrawArrays(GL_TRIANGLES, 0, interiorNumVerts);
// EXTERIOR
modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(trackable->getPose());
ShaderUtils::scalePoseMatrix(kWheelScale, kWheelScale, kWheelScale, &modelViewMatrix.data[0]);
ShaderUtils::rotatePoseMatrix(floatAngleZ, 0.0f, 0.0f, 1.0f, &mCurrentRotation.data[0]);
ShaderUtils::rotatePoseMatrix(floatAngleY, 0.0f, 1.0f, 0.0f, &mCurrentRotation.data[0]);
ShaderUtils::rotatePoseMatrix(floatAngleX, 1.0f, 0.0f, 0.0f, &mCurrentRotation.data[0]);
ShaderUtils::multiplyMatrix(&mCurrentRotation.data[0], &mAccumulatedRotation.data[0], &mAccumulatedRotation.data[0]);
ShaderUtils::multiplyMatrix(&modelViewMatrix.data[0], &mAccumulatedRotation.data[0], &modelViewMatrix.data[0]);
ShaderUtils::multiplyMatrix(&qUtils.projectionMatrix.data[0], &modelViewMatrix.data[0], &modelViewProjection.data[0]);
floatAngleX = 0.0f;
floatAngleY = 0.0f;
floatAngleZ = 0.0f;
glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &exteriorVerts[0]);
glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &exteriorNormals[0]);
glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &exteriorTexCoords[0]);
glEnableVertexAttribArray(vertexHandle);
glEnableVertexAttribArray(normalHandle);
glEnableVertexAttribArray(textureCoordHandle);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, [[textures objectAtIndex:1] textureID]);
glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (const GLfloat*)&modelViewProjection.data[0]);
glDrawArrays(GL_TRIANGLES, 0, exteriorNumVerts);
// RUEDAS
modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(trackable->getPose());
ShaderUtils::scalePoseMatrix(kWheelScale, kWheelScale, kWheelScale, &modelViewMatrix.data[0]);
ShaderUtils::rotatePoseMatrix(floatAngleZ, 0.0f, 0.0f, 1.0f, &mCurrentRotation.data[0]);
ShaderUtils::rotatePoseMatrix(floatAngleY, 0.0f, 1.0f, 0.0f, &mCurrentRotation.data[0]);
ShaderUtils::rotatePoseMatrix(floatAngleX, 1.0f, 0.0f, 0.0f, &mCurrentRotation.data[0]);
ShaderUtils::multiplyMatrix(&mCurrentRotation.data[0], &mAccumulatedRotation.data[0], &mAccumulatedRotation.data[0]);
ShaderUtils::multiplyMatrix(&modelViewMatrix.data[0], &mAccumulatedRotation.data[0], &modelViewMatrix.data[0]);
ShaderUtils::multiplyMatrix(&qUtils.projectionMatrix.data[0], &modelViewMatrix.data[0], &modelViewProjection.data[0]);
floatAngleX = 0.0f;
floatAngleY = 0.0f;
floatAngleZ = 0.0f;
glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &ruedasVerts[0]);
glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &ruedasNormals[0]);
glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &ruedasTexCoords[0]);
glEnableVertexAttribArray(vertexHandle);
glEnableVertexAttribArray(normalHandle);
glEnableVertexAttribArray(textureCoordHandle);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, [[textures objectAtIndex:2] textureID]);
glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (const GLfloat*)&modelViewProjection.data[0]);
glDrawArrays(GL_TRIANGLES, 0, ruedasNumVerts);
ShaderUtils::checkGlError("EAGLView renderFrameQCAR");
All objects are drawn and maintain rotation perfectly. The only issue I'm having is, even when all objects are parts of a unique model (a car), each 'part' is displayed with a different scale and position to the one in the model they're taken from, instead of maintaining the correct proportions between them.
Hi juanjuan
If they have different sizes, it could be that the modelview matrix is not being reset initialised correctly for each object, in which case some of the transformations might be cumulative.
If you need them to form a single object, then effectively you may need a mini scene graph with a parent object and each of your four objects underneath as a child - which means that each child object needs its own matrix. This is possible but will involve a little effort.
The other alternative might be to combine the objects into one, though this might be impractical for your needs.
HTH
N