Turn matrix_4x4_lookat into macro, remove matrix_4x4.c

This commit is contained in:
twinaphex 2017-04-16 07:57:31 +02:00
parent 257410d058
commit 9b3519f850
5 changed files with 29 additions and 72 deletions

View File

@ -776,7 +776,6 @@ OBJ += gfx/video_context_driver.o \
$(LIBRETRO_COMM_DIR)/gfx/math/vector_2.o \
$(LIBRETRO_COMM_DIR)/gfx/math/vector_3.o \
$(LIBRETRO_COMM_DIR)/gfx/math/vector_4.o \
$(LIBRETRO_COMM_DIR)/gfx/math/matrix_4x4.o \
$(LIBRETRO_COMM_DIR)/gfx/math/matrix_3x3.o
ifeq ($(HAVE_KMS), 1)

View File

@ -276,7 +276,7 @@ static void fft_render(glfft_t *fft, GLuint backbuffer, unsigned width, unsigned
printf("center %.2f %.2f %.2f\n", center[0], center[1], center[2]);
printf("up %.2f %.2f %.2f\n", up[0], up[1], up[2]);
#endif
matrix_4x4_lookat(&mvp_lookat, eye, center, up);
matrix_4x4_lookat(mvp_lookat, eye, center, up);
#ifdef GLM_USE_DEBUG
printf("mvp_lookat: \n %.2f, %.2f, %.2f, %.2f \n %.2f, %.2f, %.2f, %.2f \n %.2f, %.2f, %.2f, %.2f \n %.2f, %.2f, %.2f, %.2f \n\n",
MAT_ELEM_4X4(mvp_lookat, 0, 0),

View File

@ -281,7 +281,6 @@ VIDEO IMAGE
VIDEO DRIVER
============================================================ */
#include "../libretro-common/gfx/math/matrix_4x4.c"
#include "../libretro-common/gfx/math/matrix_3x3.c"
#include "../libretro-common/gfx/math/vector_2.c"
#include "../libretro-common/gfx/math/vector_3.c"

View File

@ -1,65 +0,0 @@
/* Copyright (C) 2010-2017 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (matrix_4x4.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <string.h>
#include <math.h>
#include <gfx/math/matrix_4x4.h>
#include <gfx/math/vector_3.h>
void matrix_4x4_lookat(math_matrix_4x4 *out,
vec3_t eye,
vec3_t center,
vec3_t up)
{
vec3_t zaxis; /* the "forward" vector */
vec3_t xaxis; /* the "right" vector */
vec3_t yaxis; /* the "up" vector */
vec3_copy(&zaxis[0], center);
vec3_subtract(&zaxis[0], eye);
vec3_normalize(&zaxis[0]);
vec3_cross(&xaxis[0], &zaxis[0], up);
vec3_normalize(&xaxis[0]);
vec3_cross(&yaxis[0], &xaxis[0], zaxis);
MAT_ELEM_4X4(*out, 0, 0) = xaxis[0];
MAT_ELEM_4X4(*out, 0, 1) = yaxis[0];
MAT_ELEM_4X4(*out, 0, 2) = -zaxis[0];
MAT_ELEM_4X4(*out, 0, 3) = 0.0;
MAT_ELEM_4X4(*out, 1, 0) = xaxis[1];
MAT_ELEM_4X4(*out, 1, 1) = yaxis[1];
MAT_ELEM_4X4(*out, 1, 2) = -zaxis[1];
MAT_ELEM_4X4(*out, 1, 3) = 0.0f;
MAT_ELEM_4X4(*out, 2, 0) = xaxis[2];
MAT_ELEM_4X4(*out, 2, 1) = yaxis[2];
MAT_ELEM_4X4(*out, 2, 2) = -zaxis[2];
MAT_ELEM_4X4(*out, 2, 3) = 0.0f;
MAT_ELEM_4X4(*out, 3, 0) = -(xaxis[0] * eye[0] + xaxis[1] * eye[1] + xaxis[2] * eye[2]);
MAT_ELEM_4X4(*out, 3, 1) = -(yaxis[0] * eye[0] + yaxis[1] * eye[1] + yaxis[2] * eye[2]);
MAT_ELEM_4X4(*out, 3, 2) = -(zaxis[0] * eye[0] + zaxis[1] * eye[1] + zaxis[2] * eye[2]);
MAT_ELEM_4X4(*out, 3, 3) = 1.f;
}

View File

@ -207,10 +207,34 @@ typedef struct math_matrix_4x4
MAT_ELEM_4X4(mat, 3, 3) = 1.0f; \
}
void matrix_4x4_lookat(math_matrix_4x4 *out,
vec3_t eye,
vec3_t center,
vec3_t up);
#define matrix_4x4_lookat(out, eye, center, up) \
{ \
vec3_t zaxis; /* the "forward" vector */ \
vec3_t xaxis; /* the "right" vector */ \
vec3_t yaxis; /* the "up" vector */ \
vec3_copy(&zaxis[0], center); \
vec3_subtract(&zaxis[0], eye); \
vec3_normalize(&zaxis[0]); \
vec3_cross(&xaxis[0], &zaxis[0], up); \
vec3_normalize(&xaxis[0]); \
vec3_cross(&yaxis[0], &xaxis[0], zaxis); \
MAT_ELEM_4X4(out, 0, 0) = xaxis[0]; \
MAT_ELEM_4X4(out, 0, 1) = yaxis[0]; \
MAT_ELEM_4X4(out, 0, 2) = -zaxis[0]; \
MAT_ELEM_4X4(out, 0, 3) = 0.0; \
MAT_ELEM_4X4(out, 1, 0) = xaxis[1]; \
MAT_ELEM_4X4(out, 1, 1) = yaxis[1]; \
MAT_ELEM_4X4(out, 1, 2) = -zaxis[1]; \
MAT_ELEM_4X4(out, 1, 3) = 0.0f; \
MAT_ELEM_4X4(out, 2, 0) = xaxis[2]; \
MAT_ELEM_4X4(out, 2, 1) = yaxis[2]; \
MAT_ELEM_4X4(out, 2, 2) = -zaxis[2]; \
MAT_ELEM_4X4(out, 2, 3) = 0.0f; \
MAT_ELEM_4X4(out, 3, 0) = -(xaxis[0] * eye[0] + xaxis[1] * eye[1] + xaxis[2] * eye[2]); \
MAT_ELEM_4X4(out, 3, 1) = -(yaxis[0] * eye[0] + yaxis[1] * eye[1] + yaxis[2] * eye[2]); \
MAT_ELEM_4X4(out, 3, 2) = -(zaxis[0] * eye[0] + zaxis[1] * eye[1] + zaxis[2] * eye[2]); \
MAT_ELEM_4X4(out, 3, 3) = 1.f; \
}
/*
* Multiplies a with b, stores the result in out