Example #1
0
void glTranslatef(GLfloat x, GLfloat y, GLfloat z) {
	int mode = ctr_state.matrix_current;
	int depth = ctr_state.matrix_depth[mode];
	matrix_4x4 *mat = &ctr_state.matrix[mode][depth];
	if (!mat) {
		return;
	}
	m4x4_translate(mat, x, y, z);
}
Example #2
0
/** 
 * Draws the gears in GLES 2 mode.
 */
static void draw_sceneGLES2(void)
{
   GLfloat transform[16];
   m4x4_identity(transform);

   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   /* Translate and rotate the view */
   m4x4_translate(transform, 0.9, 0.0, -state->viewDist);
   m4x4_rotate(transform, view_rotx, 1, 0, 0);
   m4x4_rotate(transform, view_roty, 0, 1, 0);
   m4x4_rotate(transform, view_rotz, 0, 0, 1);

   /* Draw the gears */
   draw_gearGLES2(state->gear1, transform, -3.0, -2.0, state->angle);
   draw_gearGLES2(state->gear2, transform, 3.1, -2.0, -2 * state->angle - 9.0);
   draw_gearGLES2(state->gear3, transform, -3.1, 4.2, -2 * state->angle - 25.0);
}
Example #3
0
void matrixstack_translate(float x, float y) {
  m4x4_translate(matrixstack_head(), x, y, 0.0f);
}
Example #4
0
/**
 * Draws a gear in GLES 2 mode.
 *
 * @param gear the gear to draw
 * @param transform the current transformation matrix
 * @param x the x position to draw the gear at
 * @param y the y position to draw the gear at
 * @param angle the rotation angle of the gear
 * @param color the color of the gear
 */
static void draw_gearGLES2(gear_t *gear, GLfloat *transform,
      GLfloat x, GLfloat y, GLfloat angle)
{
   // The direction of the directional light for the scene */
   static const GLfloat LightSourcePosition[4] = { 5.0, 5.0, 10.0, 1.0};

   GLfloat model_view[16];
   GLfloat normal_matrix[16];
   GLfloat model_view_projection[16];

   /* Translate and rotate the gear */
   m4x4_copy(model_view, transform);
   m4x4_translate(model_view, x, y, 0);
   m4x4_rotate(model_view, angle, 0, 0, 1);

   /* Create and set the ModelViewProjectionMatrix */
   m4x4_copy(model_view_projection, state->ProjectionMatrix);
   m4x4_multiply(model_view_projection, model_view);

   glUniformMatrix4fv(state->ModelViewProjectionMatrix_location, 1, GL_FALSE,
                      model_view_projection);
   glUniformMatrix4fv(state->ModelViewMatrix_location, 1, GL_FALSE,
                      model_view);
   /* Set the LightSourcePosition uniform in relation to the object */
   glUniform4fv(state->LightSourcePosition_location, 1, LightSourcePosition);

   glUniform1i(state->DiffuseMap_location, 0);

   /* 
    * Create and set the NormalMatrix. It's the inverse transpose of the
    * ModelView matrix.
    */
   m4x4_copy(normal_matrix, model_view);
   m4x4_invert(normal_matrix);
   m4x4_transpose(normal_matrix);
   glUniformMatrix4fv(state->NormalMatrix_location, 1, GL_FALSE, normal_matrix);

   /* Set the gear color */
   glUniform4fv(state->MaterialColor_location, 1, gear->color);

   if (state->useVBO) {
     glBindBuffer(GL_ARRAY_BUFFER, gear->vboId);
  	 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gear->iboId);
   }

   /* Set up the position of the attributes in the vertex buffer object */
   // setup where vertex data is
   glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,
         sizeof(vertex_t), gear->vertex_p);
   // setup where normal data is
   glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE,
         sizeof(vertex_t), gear->normal_p);
   // setup where uv data is
   glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE,
         sizeof(vertex_t), gear->texCoords_p);

   /* Enable the attributes */
   glEnableVertexAttribArray(0);
   glEnableVertexAttribArray(1);
   glEnableVertexAttribArray(2);

   // Bind texture surface to current vertices
   glBindTexture(GL_TEXTURE_2D, state->texId);
    
   glDrawElements(state->drawMode, gear->tricount, GL_UNSIGNED_SHORT,
                   gear->index_p);

   /* Disable the attributes */
   glDisableVertexAttribArray(2);
   glDisableVertexAttribArray(1);
   glDisableVertexAttribArray(0);
 
}