Open GL Mathematics - Code Samples

Code Samples

// Compute a triangle normal: # include void computeNormal(triangle & Triangle) { glm::vec3 const & a = Triangle.Position; glm::vec3 const & b = Triangle.Position; glm::vec3 const & c = Triangle.Position; Triangle.Normal = glm::normalize(glm::cross(c - a, b - a)); } // Matrix transform: # include // glm::vec3, glm::vec4, glm::ivec4, glm::mat4 # include // glm::perspective # include // glm::translate, glm::rotate, glm::scale # include // glm::value_ptr void transform { glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.f); glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Translate)); glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Rotate.y, glm::vec3(-1.0f, 0.0f, 0.0f)); glm::mat4 View = glm::rotate(ViewRotateX, Rotate.x, glm::vec3(0.0f, 1.0f, 0.0f)); glm::mat4 Model = glm::scale(glm::mat4(1.0f), glm::vec3(0.5f)); glm::mat4 MVP = Projection * View * Model; glUniformMatrix4fv(LocationMVP, 1, GL_FALSE, glm::value_ptr(MVP)); }

Read more about this topic:  Open GL Mathematics

Famous quotes containing the words code and/or samples:

    ... the self respect of individuals ought to make them demand of their leaders conformity with an agreed-upon code of ethics and moral conduct.
    Mary Barnett Gilson (1877–?)

    Good government cannot be found on the bargain-counter. We have seen samples of bargain-counter government in the past when low tax rates were secured by increasing the bonded debt for current expenses or refusing to keep our institutions up to the standard in repairs, extensions, equipment, and accommodations. I refuse, and the Republican Party refuses, to endorse that method of sham and shoddy economy.
    Calvin Coolidge (1872–1933)