Example #1
0
///
// Draw triangles using the shader pair created in Init()
//
void gl_rect_draw(GL_STATE_T *p_state)
{
	RectInstanceData *userData = p_state->user_data;
	GLShapeInstanceData *shapeData = &userData->shape;
	GLRectDisplayData *displayData = p_state->rectDisplayData;
	
	mat4x4 projection;
	mat4x4 modelView;
	mat4x4 projection_scaled;
	mat4x4 translation;
	mat4x4 projection_final;
	
	GLfloat vVertices[] = { 0.0f, 0.0f, 0.0f,  // Position 0
		0.0f,  1.0f, 0.0f,  // Position 1
		1.0f,  1.0f, 0.0f,  // Position 2
		1.0f,  0.0f, 0.0f,  // Position 3
	};
	
	GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
	//GLushort indices[] = {1, 0, 3, 0, 2, 0, 1 };
	
	// Use the program object
	glUseProgram ( displayData->programObject );
	
	// Load the vertex position
	glVertexAttribPointer ( displayData->positionLoc, 3, GL_FLOAT,
			       GL_FALSE, 3 * sizeof(GLfloat), vVertices );
	
	glEnableVertexAttribArray ( displayData->positionLoc );

	mat4x4_identity(projection);
	mat4x4_scale_aniso(projection_scaled, projection,
			   2.0/p_state->width,
			   -2.0/p_state->height,
			   1.0);
	mat4x4_translate(translation, -1, 1, 0);
	mat4x4_mul(projection_final, translation, projection_scaled);
	
	mat4x4_translate(translation, shapeData->objectX, shapeData->objectY, 0.0);
	mat4x4_identity(projection);
	mat4x4_scale_aniso(projection_scaled, projection,
			   shapeData->objectWidth,
			   shapeData->objectHeight,
			   1.0);
	mat4x4_mul(modelView, translation, projection_scaled);
	
	glUniformMatrix4fv ( displayData->projectionLoc, 1, GL_FALSE, (GLfloat *)projection_final);
	glUniformMatrix4fv ( displayData->modelViewLoc,  1, GL_FALSE, (GLfloat *)modelView);
	
	glUniform3f ( displayData->colorLoc, userData->red, userData->green, userData->blue );
	
	glDrawElements ( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices );
	//glDrawElements ( GL_TRIANGLE_STRIP, 6, GL_UNSIGNED_SHORT, indices );
}
Example #2
0
void Camera_view_projection(Camera* const camera, mat4x4 matrix) {

    mat4x4 position_matrix, orientation_matrix, scale_matrix;

    mat4x4_translate(
        position_matrix,
        -camera->transform.position[0],
        -camera->transform.position[1],
        -camera->transform.position[2]
    );

    quat q;
    quat_conj(q, camera->transform.orientation);
    mat4x4_from_quat(orientation_matrix, q);

    vec3 v = {
        1.0f / camera->transform.scale[0],
        1.0f / camera->transform.scale[1],
        1.0f / camera->transform.scale[2]
    };
    mat4x4 m;
    mat4x4_identity(m);
    mat4x4_scale_aniso(scale_matrix, m, v[0], v[1], v[2]);

    mat4x4_mul(matrix, scale_matrix, orientation_matrix);
    mat4x4_mul(matrix, matrix, position_matrix);

    mat4x4_mul(matrix, camera->projection, matrix);
}
Example #3
0
void lndr_gen_jet_mv_matrix(Lander *lander)
{
    if(lander->jetState == JS_OFF)
        return;

    float scale = 0;
    if(lander->jetState == JS_INCREASING || lander->jetState == JS_DECREASING)
        scale = lander->jetFrames / FLAME_GROW_RATE;
    else if(lander->jetState == JS_ON)
    {
        if(lander->jetFrames < 10)
            return;

        lander->jetFrames = 0;

        int rnd = rand() % 6 - 3;
        scale = 1.0 + (0.07 * rnd);
    }

    mat4x4 ident, temp;
    mat4x4_identity(ident);

    mat4x4_translate_in_place(ident, 0, -0.3529412, 0);
    mat4x4_scale_aniso(temp, ident, 1.0, scale, 1.0);
    mat4x4_translate_in_place(temp, 0, 0.3529412, 0);

    mat4x4_transpose(lander->jetMatrix, temp);
}
Example #4
0
void lndr_gen_mv_matrix(Lander *lander)
{
    mat4x4 ident, temp, trans;
    mat4x4_identity(ident);

    /*
    float glx = 2 / glob_game.ppw;
    float gly = 2 / glob_game.pph;
    */

    /*
    glx *= lander->x;
    gly *= lander->y;

    glx--;
    gly--;
    */

    float glx = lander->x;
    float gly = lander->y;

    mat4x4_scale_aniso(temp, ident, DEFAULT_SCALE, DEFAULT_SCALE, DEFAULT_SCALE);
    
    mat4x4_rotate_Z(temp, temp, lander->rotation);
    mat4x4_translate(trans, glx, gly, 0);
    mat4x4_mul(ident, trans, temp);
    mat4x4_transpose(lander->mvMatrix, ident);
}
Example #5
0
static void
recalculate_matrices(struct ball *b)
{
    mat4x4_identity(b->model_matrix);
    mat4x4_translate_in_place(b->model_matrix, b->x, b->y, b->z);
    mat4x4_scale_aniso(b->model_matrix, b->model_matrix, SCALE_FACTOR, SCALE_FACTOR, SCALE_FACTOR);

    mat4x4_invert(b->normal_matrix, b->model_matrix);
    mat4x4_transpose(b->normal_matrix, b->normal_matrix);

}
Example #6
0
static inline void mvp_matrix(mat4x4 model_view_projection_matrix, Params params, mat4x4 view_projection_matrix)
{

    mat4x4 model_matrix;
    mat4x4_identity(model_matrix);

    mat4x4 id;
    mat4x4_identity(id);


    mat4x4_translate(model_matrix, -params.anchor.x, -params.anchor.y, params.anchor.z);

    mat4x4 scaled;
    mat4x4_identity(scaled);
    mat4x4_scale_aniso(scaled, scaled, params.scale.x, -params.scale.y, params.scale.z);


    mat4x4 tmp;
    mat4x4_dup(tmp, model_matrix);

    mat4x4_mul(model_matrix, scaled, tmp);





    mat4x4 rotate;
    mat4x4_dup(rotate, id);
    mat4x4_rotate_Z2(rotate, id, deg_to_radf(-params.rotation));


    mat4x4_dup(tmp, model_matrix);

    mat4x4_mul(model_matrix, rotate, tmp);

    mat4x4_translate_independed(model_matrix, params.position.x, -params.position.y, params.position.z);



    mat4x4 model_matrix3;
    mat4x4_identity(model_matrix3);



    mat4x4 mm;

    mat4x4_mul(mm, model_matrix3, view_projection_matrix);

    mat4x4_mul(model_view_projection_matrix, mm, model_matrix);

    mat4x4_translate_independed(model_view_projection_matrix, 0, -y_offset/view_projection_matrix[3][3], 0);
}
Example #7
0
///
// Draw triangles using the shader pair created in Init()
//
void gl_image_draw(GL_STATE_T *p_state)
{
	ImageInstanceData *userData = p_state->user_data;
	GLShapeInstanceData *shapeData = &userData->shape;
	GLImageDisplayData *displayData = p_state->imageDisplayData;
	
	mat4x4 projection;
	mat4x4 modelView;
	mat4x4 projection_scaled;
	mat4x4 translation;
	mat4x4 projection_final;
	
	GLfloat vVertices[] = { 0.0f, 0.0f, 0.0f,  // Position 0
		0.0f,  0.0f,        // TexCoord 0
		0.0f,  1.0f, 0.0f,  // Position 1
		0.0f,  1.0f,        // TexCoord 1
		1.0f,  1.0f, 0.0f,  // Position 2
		1.0f,  1.0f,        // TexCoord 2
		1.0f,  0.0f, 0.0f,  // Position 3
		1.0f,  0.0f         // TexCoord 3
	};
	
	GLfloat texCoords[8];
	TexCoordsForRotation(shapeData->orientation, texCoords);
	vVertices[3] = texCoords[0];
	vVertices[4] = texCoords[1];
	vVertices[8] = texCoords[2];
	vVertices[9] = texCoords[3];
	vVertices[13] = texCoords[4];
	vVertices[14] = texCoords[5];
	vVertices[18] = texCoords[6];
	vVertices[19] = texCoords[7];
	
	GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
	//GLushort indices[] = {1, 0, 3, 0, 2, 0, 1 };
	
	// Use the program object
	glUseProgram ( displayData->programObject );
	
	// Load the vertex position
	glVertexAttribPointer ( displayData->positionLoc, 3, GL_FLOAT,
			       GL_FALSE, 5 * sizeof(GLfloat), vVertices );
	// Load the texture coordinate
	glVertexAttribPointer ( displayData->texCoordLoc, 2, GL_FLOAT,
			       GL_FALSE, 5 * sizeof(GLfloat), &vVertices[3] );
	
	glEnableVertexAttribArray ( displayData->positionLoc );
	glEnableVertexAttribArray ( displayData->texCoordLoc );
	
	// Bind the texture
	glActiveTexture ( GL_TEXTURE0 );
	glBindTexture ( GL_TEXTURE_2D, userData->textureId );
	
	// Set the sampler texture unit to 0
	glUniform1i ( displayData->samplerLoc, 0 );
	
	mat4x4_identity(projection);
	mat4x4_scale_aniso(projection_scaled, projection,
			   2.0/p_state->width,
			   -2.0/p_state->height,
			   1.0);
	mat4x4_translate(translation, -1, 1, 0);
	mat4x4_mul(projection_final, translation, projection_scaled);
	
	mat4x4_translate(translation, shapeData->objectX, shapeData->objectY, 0.0);
	mat4x4_identity(projection);
	mat4x4_scale_aniso(projection_scaled, projection,
			   shapeData->objectWidth,
			   shapeData->objectHeight,
			   1.0);
	mat4x4_mul(modelView, translation, projection_scaled);
	
	glUniformMatrix4fv ( displayData->projectionLoc, 1, GL_FALSE, (GLfloat *)projection_final);
	glUniformMatrix4fv ( displayData->modelViewLoc,  1, GL_FALSE, (GLfloat *)modelView);
	
	glDrawElements ( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices );
	//glDrawElements ( GL_TRIANGLE_STRIP, 6, GL_UNSIGNED_SHORT, indices );
}