void Renderer::Render(const Uniform &uniform, const Camera &camera) const { glUniform4fv(uniform.uv4k_Color, 1, mesh_.GetColor().v); GLKMatrix4 modelViewProjectionMatrix = GLKMatrix4Multiply(camera.GetProjectionMatrix(), GLKMatrix4Multiply(camera.GetViewMatrix(), modelMatrix_)); glUniformMatrix4fv(uniform.um4k_Modelviewprojection, 1, 0, modelViewProjectionMatrix.m); mesh_.Draw(); }
virtual void Draw() { glActiveTexture(GL_TEXTURE0); s_currentShader->Begin(); if (s_currentShader == s_defaultShader) { // TODO only change these when necessary. // TODO Check for using default shader or a different one GLKMatrix4& projectionMatrix = s_matrices[AmjuGL::AMJU_PROJECTION_MATRIX]; GLKMatrix4& modelViewMatrix = s_matrices[AmjuGL::AMJU_MODELVIEW_MATRIX]; // Moldelview * projection matrix for world transforms GLKMatrix4 modelViewProjectionMatrix = GLKMatrix4Multiply(projectionMatrix, modelViewMatrix); s_currentShader->Set(AMJU_ES2_DEFAULT_SHADER_MODELVIEWPROJECTION_MATRIX, modelViewProjectionMatrix.m); s_currentShader->Set(AMJU_ES2_DEFAULT_SHADER_MODELVIEW_MATRIX, modelViewMatrix.m); if (s_lightingEnabled || s_tt == AmjuGL::AMJU_TEXTURE_SPHERE_MAP) { // Inverse transpose of modelview matrix to rotate normals GLKMatrix3 normalMatrix = GLKMatrix3InvertAndTranspose(GLKMatrix4GetMatrix3(modelViewMatrix), NULL); s_currentShader->SetMatrix3x3(AMJU_ES2_DEFAULT_SHADER_NORMAL_MATRIX, normalMatrix.m); } s_currentShader->Set(AMJU_ES2_DEFAULT_SHADER_TEXTURE, (AmjuGL::TextureHandle)0); s_currentShader->Set(AMJU_ES2_DEFAULT_SHADER_COLOUR, s_colour); s_currentShader->Set(AMJU_ES2_DEFAULT_SHADER_USE_LIGHTING, (float)(s_lightingEnabled ? 0 : 1)); s_currentShader->SetInt(AMJU_ES2_DEFAULT_SHADER_USE_SPHEREMAP, (int)s_tt); s_currentShader->Set(AMJU_ES2_DEFAULT_SHADER_LIGHT_DIR, s_lightPos); s_currentShader->Set(AMJU_ES2_DEFAULT_SHADER_EYE_POS, s_eyePos); } glBindVertexArrayOES(m_vertexArray); glDrawArrays(GL_TRIANGLES, 0, m_numVerts); }
void AmjuGLOpenGLES2::Scale(float x, float y, float z) { AMJU_CALL_STACK; GLKMatrix4 mat = GLKMatrix4MakeScale(x, y, z); s_matrices[s_matrixMode] = GLKMatrix4Multiply(s_matrices[s_matrixMode], mat); }
void AmjuGLOpenGLES2::SetPerspectiveProjection(float fov, float aspectRatio, float nearDist, float farDist) { AMJU_CALL_STACK; // Expect current matrix mode to be perspective s_matrices[AmjuGL::AMJU_PROJECTION_MATRIX] = GLKMatrix4Multiply( s_matrices[AmjuGL::AMJU_PROJECTION_MATRIX], GLKMatrix4MakePerspective(DegToRad(fov), aspectRatio, nearDist, farDist)); }
GLKMatrix4 Transform_GetMV(const Transform *slf){ GLKMatrix4 tMat = GLKMatrix4MakeTranslation(slf->position.x, slf->position.y, slf->position.z); GLKMatrix4 rMat = GLKMatrix4MakeWithQuaternion(slf->orientation); GLKMatrix4 sMat = GLKMatrix4MakeScale(slf->scale.x, slf->scale.y, slf->scale.z); GLKMatrix4 mv = GLKMatrix4Multiply(tMat, GLKMatrix4Multiply(rMat, sMat)); // mv = GLKMatrix4Translate(mv, slf->position.x, slf->position.y, slf->position.z); // mv = GLKMatrix4Multiply(mv, rMat); // mv = GLKMatrix4RotateWithVector3(mv, GLKQuaternionAngle(slf->orientation), GLKQuaternionAxis(slf->orientation)); // // mv = GLKMatrix4Rotate(mv, slf->rotation.w, slf->rotation.x, slf->rotation.y, slf->rotation.z); // mv = GLKMatrix4Scale(mv, slf->scale.x, slf->scale.y, slf->scale.z); if (slf->parent) { mv = GLKMatrix4Multiply(Transform_GetMV(slf->parent), mv); } return mv; }
void AmjuGLOpenGLES2::LookAt(float eyeX, float eyeY, float eyeZ, float x, float y, float z, float upX, float upY, float upZ) { AMJU_CALL_STACK; s_eyePos = AmjuGL::Vec3(eyeX, eyeY, eyeZ); // Expect current matrix mode to be mview s_matrices[AmjuGL::AMJU_MODELVIEW_MATRIX] = GLKMatrix4Multiply( s_matrices[AmjuGL::AMJU_MODELVIEW_MATRIX], GLKMatrix4MakeLookAt(eyeX, eyeY, eyeZ, x, y, z, upX, upY, upZ)); }
void AmjuGLOpenGLES2::MultMatrix(const float array[16]) { AMJU_CALL_STACK; GLKMatrix4 mat = GLKMatrix4MakeWithArray((float*)array); s_matrices[s_matrixMode] = GLKMatrix4Multiply(s_matrices[s_matrixMode], mat); }
GLKMatrix4 Transform_GetMVP(const Transform *slf, const GLKMatrix4 projection){ return GLKMatrix4Multiply(projection, Transform_GetMV(slf)); }