mirror of
https://github.com/recp/cglm.git
synced 2025-10-04 17:09:40 +00:00
move io funcs to io header, use util for another purpose
This commit is contained in:
142
include/cglm-io.h
Normal file
142
include/cglm-io.h
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c), Recep Aslantas.
|
||||||
|
*
|
||||||
|
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||||
|
* Full license can be found in the LICENSE file
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef cglm_io_h
|
||||||
|
#define cglm_io_h
|
||||||
|
|
||||||
|
#include "cglm-common.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
CGLM_INLINE
|
||||||
|
void
|
||||||
|
glm_mat4_print(mat4 matrix,
|
||||||
|
FILE * __restrict ostream) {
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
#define m 4
|
||||||
|
#define n 4
|
||||||
|
|
||||||
|
fprintf(ostream, "Matrix (float%dx%d):\n", m, n);
|
||||||
|
|
||||||
|
for (i = 0; i < m; i++) {
|
||||||
|
fprintf(ostream, "\t|");
|
||||||
|
for (j = 0; j < n; j++) {
|
||||||
|
fprintf(ostream, "%0.4f", matrix[j][i]);;
|
||||||
|
|
||||||
|
if (j != n - 1)
|
||||||
|
fprintf(ostream, "\t");
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(ostream, "|\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(ostream, "\n");
|
||||||
|
|
||||||
|
#undef m
|
||||||
|
#undef n
|
||||||
|
}
|
||||||
|
|
||||||
|
CGLM_INLINE
|
||||||
|
void
|
||||||
|
glm_mat3_print(mat3 matrix,
|
||||||
|
FILE * __restrict ostream) {
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
#define m 3
|
||||||
|
#define n 3
|
||||||
|
|
||||||
|
fprintf(ostream, "Matrix (float%dx%d):\n", m, n);
|
||||||
|
|
||||||
|
for (i = 0; i < m; i++) {
|
||||||
|
fprintf(ostream, "\t|");
|
||||||
|
for (j = 0; j < n; j++) {
|
||||||
|
fprintf(ostream, "%0.4f", matrix[j][i]);;
|
||||||
|
|
||||||
|
if (j != n - 1)
|
||||||
|
fprintf(ostream, "\t");
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(ostream, "|\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(ostream, "\n");
|
||||||
|
|
||||||
|
#undef m
|
||||||
|
#undef n
|
||||||
|
}
|
||||||
|
|
||||||
|
CGLM_INLINE
|
||||||
|
void
|
||||||
|
glm_vec4_print(vec4 vec,
|
||||||
|
FILE * __restrict ostream) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
#define m 4
|
||||||
|
|
||||||
|
fprintf(ostream, "Vector (float%d):\n\t|", m);
|
||||||
|
|
||||||
|
for (i = 0; i < m; i++) {
|
||||||
|
fprintf(ostream, "%0.4f", vec[i]);
|
||||||
|
|
||||||
|
if (i != m - 1)
|
||||||
|
fprintf(ostream, "\t");
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(ostream, "|\n\n");
|
||||||
|
|
||||||
|
#undef m
|
||||||
|
}
|
||||||
|
|
||||||
|
CGLM_INLINE
|
||||||
|
void
|
||||||
|
glm_vec3_print(vec3 vec,
|
||||||
|
FILE * __restrict ostream) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
#define m 3
|
||||||
|
|
||||||
|
fprintf(ostream, "Vector (float%d):\n\t|", m);
|
||||||
|
|
||||||
|
for (i = 0; i < m; i++) {
|
||||||
|
fprintf(ostream, "%0.4f", vec[i]);
|
||||||
|
|
||||||
|
if (i != m - 1)
|
||||||
|
fprintf(ostream, "\t");
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(ostream, "|\n\n");
|
||||||
|
|
||||||
|
#undef m
|
||||||
|
}
|
||||||
|
|
||||||
|
CGLM_INLINE
|
||||||
|
void
|
||||||
|
glm_versor_print(versor vec,
|
||||||
|
FILE * __restrict ostream) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
#define m 4
|
||||||
|
|
||||||
|
fprintf(ostream, "Versor (float%d):\n\t|", m);
|
||||||
|
|
||||||
|
for (i = 0; i < m; i++) {
|
||||||
|
fprintf(ostream, "%0.4f", vec[i]);
|
||||||
|
|
||||||
|
if (i != m - 1)
|
||||||
|
fprintf(ostream, "\t");
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(ostream, "|\n\n");
|
||||||
|
|
||||||
|
#undef m
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* cglm_io_h */
|
@@ -10,133 +10,16 @@
|
|||||||
|
|
||||||
#include "cglm-common.h"
|
#include "cglm-common.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
CGLM_INLINE
|
CGLM_INLINE
|
||||||
void
|
float
|
||||||
glm_mat4_print(mat4 matrix,
|
glm_rad(float deg) {
|
||||||
FILE * __restrict ostream) {
|
return deg * M_PI / 180.0f;
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
|
|
||||||
#define m 4
|
|
||||||
#define n 4
|
|
||||||
|
|
||||||
fprintf(ostream, "Matrix (float%dx%d):\n", m, n);
|
|
||||||
|
|
||||||
for (i = 0; i < m; i++) {
|
|
||||||
fprintf(ostream, "\t|");
|
|
||||||
for (j = 0; j < n; j++) {
|
|
||||||
fprintf(ostream, "%0.4f", matrix[j][i]);;
|
|
||||||
|
|
||||||
if (j != n - 1)
|
|
||||||
fprintf(ostream, "\t");
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(ostream, "|\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(ostream, "\n");
|
|
||||||
|
|
||||||
#undef m
|
|
||||||
#undef n
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CGLM_INLINE
|
CGLM_INLINE
|
||||||
void
|
float
|
||||||
glm_mat3_print(mat3 matrix,
|
glm_deg(float rad) {
|
||||||
FILE * __restrict ostream) {
|
return rad * 180.0f / M_PI;
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
|
|
||||||
#define m 3
|
|
||||||
#define n 3
|
|
||||||
|
|
||||||
fprintf(ostream, "Matrix (float%dx%d):\n", m, n);
|
|
||||||
|
|
||||||
for (i = 0; i < m; i++) {
|
|
||||||
fprintf(ostream, "\t|");
|
|
||||||
for (j = 0; j < n; j++) {
|
|
||||||
fprintf(ostream, "%0.4f", matrix[j][i]);;
|
|
||||||
|
|
||||||
if (j != n - 1)
|
|
||||||
fprintf(ostream, "\t");
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(ostream, "|\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(ostream, "\n");
|
|
||||||
|
|
||||||
#undef m
|
|
||||||
#undef n
|
|
||||||
}
|
|
||||||
|
|
||||||
CGLM_INLINE
|
|
||||||
void
|
|
||||||
glm_vec4_print(vec4 vec,
|
|
||||||
FILE * __restrict ostream) {
|
|
||||||
int i;
|
|
||||||
|
|
||||||
#define m 4
|
|
||||||
|
|
||||||
fprintf(ostream, "Vector (float%d):\n\t|", m);
|
|
||||||
|
|
||||||
for (i = 0; i < m; i++) {
|
|
||||||
fprintf(ostream, "%0.4f", vec[i]);
|
|
||||||
|
|
||||||
if (i != m - 1)
|
|
||||||
fprintf(ostream, "\t");
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(ostream, "|\n\n");
|
|
||||||
|
|
||||||
#undef m
|
|
||||||
}
|
|
||||||
|
|
||||||
CGLM_INLINE
|
|
||||||
void
|
|
||||||
glm_vec3_print(vec3 vec,
|
|
||||||
FILE * __restrict ostream) {
|
|
||||||
int i;
|
|
||||||
|
|
||||||
#define m 3
|
|
||||||
|
|
||||||
fprintf(ostream, "Vector (float%d):\n\t|", m);
|
|
||||||
|
|
||||||
for (i = 0; i < m; i++) {
|
|
||||||
fprintf(ostream, "%0.4f", vec[i]);
|
|
||||||
|
|
||||||
if (i != m - 1)
|
|
||||||
fprintf(ostream, "\t");
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(ostream, "|\n\n");
|
|
||||||
|
|
||||||
#undef m
|
|
||||||
}
|
|
||||||
|
|
||||||
CGLM_INLINE
|
|
||||||
void
|
|
||||||
glm_versor_print(versor vec,
|
|
||||||
FILE * __restrict ostream) {
|
|
||||||
int i;
|
|
||||||
|
|
||||||
#define m 4
|
|
||||||
|
|
||||||
fprintf(ostream, "Versor (float%d):\n\t|", m);
|
|
||||||
|
|
||||||
for (i = 0; i < m; i++) {
|
|
||||||
fprintf(ostream, "%0.4f", vec[i]);
|
|
||||||
|
|
||||||
if (i != m - 1)
|
|
||||||
fprintf(ostream, "\t");
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(ostream, "|\n\n");
|
|
||||||
|
|
||||||
#undef m
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* cglm_util_h */
|
#endif /* cglm_util_h */
|
||||||
|
@@ -12,10 +12,11 @@
|
|||||||
#include "cglm-vec.h"
|
#include "cglm-vec.h"
|
||||||
#include "cglm-mat.h"
|
#include "cglm-mat.h"
|
||||||
#include "cglm-mat3.h"
|
#include "cglm-mat3.h"
|
||||||
#include "cglm-util.h"
|
|
||||||
#include "cglm-affine.h"
|
#include "cglm-affine.h"
|
||||||
#include "cglm-cam.h"
|
#include "cglm-cam.h"
|
||||||
#include "cglm-quat.h"
|
#include "cglm-quat.h"
|
||||||
#include "cglm-euler.h"
|
#include "cglm-euler.h"
|
||||||
|
#include "cglm-util.h"
|
||||||
|
#include "cglm-io.h"
|
||||||
|
|
||||||
#endif /* cglm_h */
|
#endif /* cglm_h */
|
||||||
|
Reference in New Issue
Block a user