Esempio n. 1
0
  void update_rotation(const GLVector<XYZ>& rotation) {
#ifndef M_PI
#define M_PI 3.14159265359
#endif
    static const double to_rad = 1.0 / 180.0 * M_PI;

    GLMatrix mx;
    mx.set_data(0, 0, 1);
    mx.set_data(1, 1, cos(rotation[0] * to_rad));
    mx.set_data(1, 2, sin(rotation[0] * to_rad));
    mx.set_data(2, 2, mx.get_data(1, 1));
    mx.set_data(2, 1, -mx.get_data(1, 2));
    mx.set_data(3, 3, 1);

    GLMatrix my;
    my.set_data(0, 0, cos(rotation[1] * to_rad));
    my.set_data(0, 2, -sin(rotation[1] * to_rad));
    my.set_data(1, 1, 1);
    my.set_data(2, 0, -my.get_data(0, 2));
    my.set_data(2, 2, my.get_data(0, 0));
    my.set_data(3, 3, 1);

    GLMatrix mz;
    mz.set_data(0, 0, cos(rotation[2] * to_rad));
    mz.set_data(0, 1, sin(rotation[2] * to_rad));
    mz.set_data(1, 0, -mz.get_data(0, 1));
    mz.set_data(1, 1, mz.get_data(0, 0));
    mz.set_data(2, 2, 1);
    mz.set_data(3, 3, 1);

    update_rotation(mz * my * mx);
  }
Esempio n. 2
0
File: Grid.cpp Progetto: PennTao/GPU
void display(void)
{
    ///////////////////////////////////////////////////////////////////////////
    // Update
	//Tao
	time_update = time_update + delta;
	//
	glm::mat4 model = glm::translate(update_rotation(), glm::vec3(-0.5, -0.5, 0.0));
    glm::mat4 mvp = persp * view * model;
	//Tao
	glUniform1f(location_uniform,time_update);
    ///////////////////////////////////////////////////////////////////////////
    // Render

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    // Shader and vertex buffers already bound
	glUniformMatrix4fv(u_modelViewPerspectiveLocation,1,GL_FALSE,&mvp[0][0]);
	glDrawElements(GL_LINES, numberOfIndices, GL_UNSIGNED_SHORT,0);

    glutPostRedisplay();
	glutSwapBuffers();
}