// The equivalent to glTranslate applied to the model matrix void translate(float x, float y, float z) { float aux[16]; setTranslationMatrix(aux,x,y,z); multMatrix(modelMatrix,aux); setModelMatrix(); }
// Constructor(s) ################################################ //################################################################ Object3D(bool active = true, glm::mat4 scaleMatrix = glm::mat4(), glm::mat4 translationMatrix = glm::mat4(), glm::mat4 rotationalMatrix_0 = glm::mat4(), glm::mat4 rotationalMatrix_1 = glm::mat4()) { setActive(active); setRotationMatrix_0(rotationalMatrix_0); setRotationMatrix_1(rotationalMatrix_1); setScaleMatrix(scaleMatrix); setTranslationMatrix(translationMatrix); setLastModelMatrix(getModelMatrix()); }
void setCamera(float posX, float posY, float posZ, float lookAtX, float lookAtY, float lookAtZ) { float dir[3], right[3], up[3]; up[0] = 0.0f; up[1] = 1.0f; up[2] = 0.0f; dir[0] = (lookAtX - posX); dir[1] = (lookAtY - posY); dir[2] = (lookAtZ - posZ); normalize(dir); crossProduct(dir,up,right); normalize(right); crossProduct(right,dir,up); normalize(up); float viewMatrix[16],aux[16]; viewMatrix[0] = right[0]; viewMatrix[4] = right[1]; viewMatrix[8] = right[2]; viewMatrix[12] = 0.0f; viewMatrix[1] = up[0]; viewMatrix[5] = up[1]; viewMatrix[9] = up[2]; viewMatrix[13] = 0.0f; viewMatrix[2] = -dir[0]; viewMatrix[6] = -dir[1]; viewMatrix[10] = -dir[2]; viewMatrix[14] = 0.0f; viewMatrix[3] = 0.0f; viewMatrix[7] = 0.0f; viewMatrix[11] = 0.0f; viewMatrix[15] = 1.0f; setTranslationMatrix(aux, -posX, -posY, -posZ); multMatrix(viewMatrix, aux); glBindBuffer(GL_UNIFORM_BUFFER, matricesUniBuffer); glBufferSubData(GL_UNIFORM_BUFFER, ViewMatrixOffset, MatrixSize, viewMatrix); glBindBuffer(GL_UNIFORM_BUFFER,0); }
// Constructor(s) ################################################ //################################################################ Object3D(char* objName, char* fileName, UINT32 vertexCount, float modelSize, bool active = true, glm::mat4 scaleMatrix = glm::mat4(), glm::mat4 translationMatrix = glm::mat4(), glm::mat4 rotationalMatrix = glm::mat4()){ setObjName(objName); setFileName(fileName); setVertexCount(vertexCount); setModelSize(modelSize); setActive(active); //Unless default function parameters are overwritten, //we will write identity matrices to the matrices setRotationMatrix(rotationalMatrix); setScaleMatrix(scaleMatrix); setTranslationMatrix(translationMatrix); }
void setCamera(float posX, float posY, float posZ, float lookAtX, float lookAtY, float lookAtZ) { float dir[3], right[3], up[3]; up[0] = 0.0f; up[1] = 1.0f; up[2] = 0.0f; dir[0] = (lookAtX - posX); dir[1] = (lookAtY - posY); dir[2] = (lookAtZ - posZ); normalize(dir); crossProduct(dir,up,right); normalize(right); crossProduct(right,dir,up); normalize(up); float aux[16]; viewMatrix[0] = right[0]; viewMatrix[4] = right[1]; viewMatrix[8] = right[2]; viewMatrix[12] = 0.0f; viewMatrix[1] = up[0]; viewMatrix[5] = up[1]; viewMatrix[9] = up[2]; viewMatrix[13] = 0.0f; viewMatrix[2] = -dir[0]; viewMatrix[6] = -dir[1]; viewMatrix[10] = -dir[2]; viewMatrix[14] = 0.0f; viewMatrix[3] = 0.0f; viewMatrix[7] = 0.0f; viewMatrix[11] = 0.0f; viewMatrix[15] = 1.0f; setTranslationMatrix(aux, -posX, -posY, -posZ); multMatrix(viewMatrix, aux); }
void setupCamera(ShaderProgram * sp, const Camera * camera) { /* Pointers */ GLint viewProjP, viewPosP; /* Matrices */ mat4 viewTrMatrix, viewRotMatrix, viewMatrix; mat4 projMatrix, viewProjMatrix; setPerspectiveMatrix(projMatrix, camera->viewAngleY, camera->aspect, camera->znear, camera->zfar); setMatrixFromQuaternion(viewRotMatrix, camera->q); setTranslationMatrix(viewTrMatrix, -camera->pos[0], -camera->pos[1], -camera->pos[2]); setMulMatrix(viewMatrix, viewRotMatrix, viewTrMatrix); setMulMatrix(viewProjMatrix, projMatrix, viewMatrix); glUseProgram(sp->p); viewProjP = glGetUniformLocation(sp->p, "transform.viewProjection"); /* TODO: if (viewProjP == -1) {} */ glUniformMatrix4fv(viewProjP, 1, GL_TRUE, viewProjMatrix); viewPosP = glGetUniformLocation(sp->p, "transform.viewPosition"); /* TODO: if (viewPosP == -1) {} */ glUniform3fv(viewPosP, 1, camera->pos); #ifdef DEBUG validateShaderProgram(sp->p); #endif CHECK_OPENGL_ERRORS(__FILE__, __LINE__); }
void setCamera() { Vec3 dir(Unit(origin-eye)); Vec3 right(Unit(dir^up)); up=Unit(right^dir); float aux[16]; viewMatrix[0] = float(right.x); viewMatrix[4] = float(right.y); viewMatrix[8] = float(right.z); viewMatrix[12] = 0.0f; viewMatrix[1] = float(up.x); viewMatrix[5] = float(up.y); viewMatrix[9] = float(up.z); viewMatrix[13] = 0.0f; viewMatrix[2] = float(-dir.x); viewMatrix[6] = float(-dir.y); viewMatrix[10] = float(-dir.z); viewMatrix[14] = 0.0f; viewMatrix[3] = 0.0f; viewMatrix[7] = 0.0f; viewMatrix[11] = 0.0f; viewMatrix[15] = 1.0f; setTranslationMatrix(aux, float(-eye.x), float(-eye.y), float(-eye.z)); multMatrix(viewMatrix, aux); //set the projection matrix double d(1-zoom); setIdentityMatrix4x4(projMatrix); projMatrix[0]=float(1/d); projMatrix[5]=float(1/d); projMatrix[10]=float(-2/(zfar-znear)); projMatrix[14]=float(-(zfar+znear)/(zfar-znear)); }