Ejemplo n.º 1
0
static void get_vtx(struct asteroid *a, float r)
{
	float theta = 360.0 / NUM_VTX;
	for (int i = 0; i < NUM_VTX;) {
		float x_var = arand() * MAX_VARIANCE * r;
		float y_var = arand() * MAX_VARIANCE * r;
		int deviation_size = NUM_VTX / 2 + rand() % (NUM_VTX / 2);
		deviation_size /= asteroid_smoothness;
		for (int j = 0; j < deviation_size && i < NUM_VTX; j++, i++) {
			x_var += drand() * MAX_INTM_VARIANCE * r;
			y_var += drand() * MAX_INTM_VARIANCE * r;
			float x = cos(deg_to_radf(theta * i)) * r + x_var;
			float y = sin(deg_to_radf(theta * i)) * r + y_var;
			a->vtx[i].x = x;
			a->vtx[i].y = y;
		}
	}
}
Ejemplo n.º 2
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);
}