void update_matrix_3d( float *matrix, float x, float y, float z, float rx, float ry) { float a[16]; float b[16]; int width, height; glfwGetFramebufferSize(window, &width, &height); glViewport(0, 0, width, height); float aspect = (float)width / height; mat_identity(a); mat_translate(b, -x, -y, -z); mat_multiply(a, b, a); mat_rotate(b, cosf(rx), 0, sinf(rx), ry); mat_multiply(a, b, a); mat_rotate(b, 0, 1, 0, -rx); mat_multiply(a, b, a); if (ortho) { int size = 32; mat_ortho(b, -size * aspect, size * aspect, -size, size, -256, 256); } else { mat_perspective(b, fov, aspect, 0.1, 1024.0); } mat_multiply(a, b, a); mat_identity(matrix); mat_multiply(matrix, a, matrix); }
void set_matrix_3d( float *matrix, int width, int height, float x, float y, float z, float rx, float ry, float fov, int ortho) { float a[16]; float b[16]; float aspect = (float)width / height; mat_identity(a); mat_translate(b, -x, -y - 0.1, -z); mat_multiply(a, b, a); mat_rotate(b, cosf(rx), 0, sinf(rx), ry); mat_multiply(a, b, a); mat_rotate(b, 0, 1, 0, -rx); mat_multiply(a, b, a); if (ortho) { int size = 32; mat_ortho(b, -size * aspect, size * aspect, -size, size, -256, 256); } else { mat_perspective(b, fov, aspect, 1 / 8.0, 256.0); } mat_multiply(a, b, a); mat_identity(matrix); mat_multiply(matrix, a, matrix); }
void set_matrix_3d( float *matrix, int width, int height, float x, float y, float z, float rx, float ry, float fov, int ortho, int radius) { float a[16]; float b[16]; float aspect = (float)width / height; float znear = 0.125; float zfar = radius * 32 + 64; mat_identity(a); mat_translate(b, -x, -y, -z); mat_multiply(a, b, a); mat_rotate(b, cosf(rx), 0, sinf(rx), ry); mat_multiply(a, b, a); mat_rotate(b, 0, 1, 0, -rx); mat_multiply(a, b, a); if (ortho) { int size = ortho; mat_ortho(b, -size * aspect, size * aspect, -size, size, -zfar, zfar); } else { mat_perspective(b, fov, aspect, znear, zfar); } mat_multiply(a, b, a); mat_identity(matrix); mat_multiply(matrix, a, matrix); }
void update_matrix_3d( float *matrix, float x, float y, float z, float rx, float ry) { float a[16]; float b[16]; int width, height; glfwGetWindowSize(&width, &height); glViewport(0, 0, width, height); float aspect = (float)width / height; mat_identity(a); mat_translate(b, -x, -y, -z); mat_multiply(a, b, a); mat_rotate(b, cosf(rx), 0, sinf(rx), ry); mat_multiply(a, b, a); mat_rotate(b, 0, 1, 0, -rx); mat_multiply(a, b, a); if (ortho) { int size = 32; mat_ortho(b, -size * aspect, size * aspect, -size, size, -256, 256); } else { mat_perspective(b, 65.0, aspect, 0.1, 1024.0); } mat_multiply(a, b, a); for (int i = 0; i < 16; i++) { matrix[i] = a[i]; } }
// Render a text displaying a int at x, y (opengl coords) void render_inventory_number_at(Attrib *attrib, int num, float x, float y) { int nx = (g->width / 2) + (g->width / 2) * x; int ny = (g->height / 2) + (g->height / 2) * y; float matrix[16]; mat_ortho(matrix, 0, g->width, 0, g->height, -1, 10); glUseProgram(attrib->program); glUniformMatrix4fv(attrib->matrix, 1, GL_FALSE, matrix); glUniform1i(attrib->sampler, 1); // GL_TEXTURE1 char text_buffer[16]; snprintf(text_buffer, 16, "%02d", num); print(attrib, 1, nx, ny, 12, text_buffer); }
void set_matrix_item(float *matrix, int width, int height) { float a[16]; float b[16]; float aspect = (float)width / height; float size = 64; float box = height / size / 2; float xoffset = 1 - size / width * 2; float yoffset = 1 - size / height * 2; mat_identity(a); mat_rotate(b, 0, 1, 0, -PI / 4); mat_multiply(a, b, a); mat_rotate(b, 1, 0, 0, -PI / 10); mat_multiply(a, b, a); mat_ortho(b, -box * aspect, box * aspect, -box, box, -1, 1); mat_multiply(a, b, a); mat_translate(b, -xoffset, -yoffset, 0); mat_multiply(a, b, a); mat_identity(matrix); mat_multiply(matrix, a, matrix); }
void set_matrix_item_r(float *matrix, int width, int height, float scale, float xoffset, float yoffset, float rx, float ry, float rz) { float a[16]; float b[16]; float aspect = (float)width / height; float size = 64 * scale; float box = height / size / 2; mat_identity(a); mat_rotate(b, 0, 1, 0, rx); mat_multiply(a, b, a); mat_rotate(b, 1, 0, 0, ry); mat_multiply(a, b, a); mat_rotate(b, 0, 0, 1, rz); mat_multiply(a, b, a); mat_ortho(b, -box * aspect, box * aspect, -box, box, -3, 2); mat_multiply(a, b, a); mat_translate(b, -xoffset, -yoffset, 0); mat_multiply(a, b, a); mat_identity(matrix); mat_multiply(matrix, a, matrix); }
void update_matrix_item(float *matrix) { float a[16]; float b[16]; int width, height; glfwGetFramebufferSize(window, &width, &height); glViewport(0, 0, width, height); float aspect = (float)width / height; float size = 64; float box = height / size / 2; float xoffset = 1 - size / width * 2; float yoffset = 1 - size / height * 2; mat_identity(a); mat_rotate(b, 0, 1, 0, PI / 4); mat_multiply(a, b, a); mat_rotate(b, 1, 0, 0, -PI / 10); mat_multiply(a, b, a); mat_ortho(b, -box * aspect, box * aspect, -box, box, -1, 1); mat_multiply(a, b, a); mat_translate(b, -xoffset, -yoffset, 0); mat_multiply(a, b, a); mat_identity(matrix); mat_multiply(matrix, a, matrix); }
void update_matrix_2d(float *matrix) { int width, height; glfwGetFramebufferSize(window, &width, &height); glViewport(0, 0, width, height); mat_ortho(matrix, 0, width, 0, height, -1, 1); }
void set_matrix_2d(float *matrix, int width, int height) { mat_ortho(matrix, 0, width, 0, height, -1, 1); }
int main(int argc, char *argv[]) { (void)argc; (void)argv; #ifdef __SSE__ printf("SSE "); #endif #ifdef __SSE2__ printf("SSE2 "); #endif #ifdef __SSE3__ printf("SSE3 "); #endif #ifdef __SSE4__ printf("SSE4 "); #endif #ifdef __SSE4_1__ printf("SSE4.1 "); #endif #ifdef __SSE4_2__ printf("SSE4.2 "); #endif #ifdef __AVX__ printf("AVX "); #endif #ifdef __FMA4__ printf("FMA4 "); #endif printf("\n"); printv(vec(1, 2, 3, 4)); printv(vzero()); printm(mzero()); printm(midentity()); vec4 a = { 1, 2, 3, 4 }, b = { 5, 6, 7, 8 }; printv(a); printv(b); printf("\nshuffles:\n"); printv(vshuffle(a, a, 0, 1, 2, 3)); printv(vshuffle(a, a, 3, 2, 1, 0)); printv(vshuffle(a, b, 0, 1, 0, 1)); printv(vshuffle(a, b, 2, 3, 2, 3)); printf("\ndot products:\n"); printv(vdot(a, b)); printv(vdot(b, a)); printv(vdot3(a, b)); printv(vdot3(b, a)); //vec4 blendmask = { 1, -1, 1, -1 }; //printv(vblend(x, y, blendmask)); vec4 x = { 1, 0, 0, 0 }, y = { 0, 1, 0, 0 }, z = { 0, 0, 1, 0 }, w = { 0, 0, 0, 1 }; printf("\ncross products:\n"); printv(vcross(x, y)); printv(vcross(y, x)); printv(vcross_scalar(x, y)); printv(vcross_scalar(y, x)); printf("\nquaternion products:\n"); printv(qprod(x, y)); printv(qprod(y, x)); printv(qprod_mad(x, y)); printv(qprod_mad(y, x)); printv(qprod_scalar(x, y)); printv(qprod_scalar(y, x)); printf("\nquaternion conjugates:\n"); printv(qconj(x)); printv(qconj(y)); printv(qconj(z)); printv(qconj(w)); printf("\nmat from quat:\n"); printm(quat_to_mat(w)); printm(quat_to_mat_mmul(w)); printm(quat_to_mat_scalar(w)); vec4 angles = { 0.0, 0.0, 0.0, 0.0 }; printf("\neuler to quaternion:\n"); printv(quat_euler(angles)); printv(quat_euler_scalar(angles)); printv(quat_euler_gems(angles)); printf("\neuler to matrix:\n"); printm(mat_euler(angles)); printm(mat_euler_scalar(angles)); printm(quat_to_mat(quat_euler(angles))); printf("\nperspective matrix:\n"); printm(mat_perspective_fovy(M_PI/4.0, 16.0/9.0, 0.1, 100.0)); printm(mat_perspective_fovy_inf_z(M_PI/4.0, 16.0/9.0, 0.1)); printm(mat_perspective_fovy_scalar(M_PI/4.0, 16.0/9.0, 0.1, 100.0)); printf("\northogonal matrix:\n"); printm(mat_ortho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0)); printm(mat_ortho(-1.0, 2.0, -1.0, 2.0, -1.0, 2.0)); printf("\ntranslate matrix:\n"); printm(mtranslate(a)); printf("\nscale matrix:\n"); printm(mscale(a)); return 0; }
void update_matrix_2d(float *matrix) { int width, height; glfwGetWindowSize(&width, &height); glViewport(0, 0, width, height); mat_ortho(matrix, 0, width, 0, height, -1, 1); }