BambooIsland: C:/Users/easterbunny/Desktop/Echtzeitgraphik-LU/trunk/src/SceneObject.cpp Source File

BambooIsland Abgabe 2

- Main Page
- Related Pages
- Classes
- Files

- File List

# C:/Users/easterbunny/Desktop/Echtzeitgraphik-LU/trunk/src/SceneObject.cpp

    00001 #include <glm/gtc/matrix_projection.hpp>
    00002 #include <glm/gtx/inverse_transpose.hpp>
    00003 #include <glm/gtc/matrix_transform.hpp>
    00004 #include <glm/gtx/transform.hpp>
    00005 #include <glm/gtx/transform2.hpp>
    00006 #include <glm/gtc/type_ptr.hpp>
    00007
    00008 #include "ShaderManager.h"
    00009 #include "Camera.h"
    00010 #include "SceneObject.h"
    00011 #include "LightManager.h"
    00012
    00013 void SceneObject::setTransformMatrix(glm::mat4 transformMatrix)
    00014 {
    00015     this->transformMatrix = transformMatrix;
    00016 }
    00017
    00018 glm::mat4 SceneObject::getTransformMatrix()
    00019 {
    00020     return this->transformMatrix;
    00021 }
    00022
    00023 glm::mat4 SceneObject::getFullTransformMatrix()
    00024 {
    00025     return this->completeTransformMatrix;
    00026 }
    00027
    00028 void SceneObject::addChild(SceneObject *obj)
    00029 {
    00030     this->children.push_back(obj);
    00031 }
    00032
    00033 void SceneObject::clearChilds()
    00034 {
    00035     this->children.clear();
    00036 }
    00037
    00038 void SceneObject::sendTransformMatrices(bool sendNormalMatrix)
    00039 {
    00040     glm::mat4 full_ModelTransformationMatrix = this->getFullTransformMatrix();
    00041
    00042     glUniformMatrix4fv(ShaderManager::instance()->getUniform("Camera_ProjectionMatrix"), 1, GL_FALSE, &Camera::instance()->getProjectionMatrix()[0][0]);
    00043     glUniformMatrix4fv(ShaderManager::instance()->getUniform("Camera_TransformMatrix"), 1, GL_FALSE, &Camera::instance()->getModelviewMatrix()[0][0]);
    00044
    00045     glUniformMatrix4fv(ShaderManager::instance()->getUniform("Model_TransformMatrix"), 1, GL_FALSE, &full_ModelTransformationMatrix[0][0]);
    00046
    00047     GLint l_lastFrameTransformMatrix = ShaderManager::instance()->getUniform("Camera_TransformMatrix_LastFrame");
    00048
    00049     if (l_lastFrameTransformMatrix != -1)
    00050         glUniformMatrix4fv(l_lastFrameTransformMatrix, 1, GL_FALSE, &Camera::instance()->getLastFrameModelViewMatrix()[0][0]);
    00051
    00052     GLint l_tempTransformMatrix = ShaderManager::instance()->getUniform("Camera_TempTransformMatrix");
    00053
    00054     if (l_tempTransformMatrix != -1)
    00055         glUniformMatrix4fv(l_tempTransformMatrix, 1, GL_FALSE, &Camera::instance()->getUsedLightProjModelViewMatrix()[0][0]);
    00056
    00057     if (sendNormalMatrix)
    00058         glUniformMatrix3fv(ShaderManager::instance()->getUniform("NormalMatrix"), 1, GL_FALSE, &(glm::mat3(glm::inverseTranspose(Camera::instance()->getModelviewMatrix() * full_ModelTransformationMatrix)))[0][0]);
    00059
    00060     sendLightPosition();
    00061 }
    00062
    00063 void SceneObject::sendLightPosition()
    00064 {
    00065     GLint l_Light0Position = ShaderManager::instance()->getUniform("Light0Position");
    00066
    00067     if (l_Light0Position != -1)
    00068     {
    00069         float *light0Position = LightManager::instance()->getCurrentLightPosition();
    00070         glUniform4f(l_Light0Position, light0Position[0], light0Position[1], light0Position[2], light0Position[3]);
    00071     }
    00072
    00073 }
    00074
    00075 void SceneObject::render(glm::mat4 parents_transformMatrix, RenderState currentRenderState)
    00076 {
    00077     m_tRenderState = currentRenderState;
    00078
    00079     this->itlBeforeRender();
    00080
    00081     this->completeTransformMatrix = parents_transformMatrix * this->transformMatrix;
    00082
    00083         // call this method in every child
    00084     for (int a=0; a < this->children.size(); a++)
    00085         this->children[a]->render(this->completeTransformMatrix, m_tRenderState);
    00086
    00087     this->sendTransformMatrices();
    00088
    00089     this->itlRender();
    00090 }
    00091
    00092 SceneObject::SceneObject() : transformMatrix(glm::mat4())
    00093 {
    00094
    00095 }
    00096
    00097 SceneObject::~SceneObject()
    00098 {
    00099
    00100 }

All Classes Functions Variables Enumerations Enumerator