|
|
|
@ -1,4 +1,5 @@ |
|
|
|
|
#pragma once |
|
|
|
|
#ifndef COMMON_MAT_H |
|
|
|
|
#define COMMON_MAT_H |
|
|
|
|
|
|
|
|
|
typedef struct vec3 { |
|
|
|
|
float v[3]; |
|
|
|
@ -16,7 +17,7 @@ typedef struct mat4 { |
|
|
|
|
float v[4*4]; |
|
|
|
|
} mat4; |
|
|
|
|
|
|
|
|
|
static inline mat3 matmul3(const mat3 &a, const mat3 &b) { |
|
|
|
|
static inline mat3 matmul3(const mat3 a, const mat3 b) { |
|
|
|
|
mat3 ret = {{0.0}}; |
|
|
|
|
for (int r=0; r<3; r++) { |
|
|
|
|
for (int c=0; c<3; c++) { |
|
|
|
@ -30,7 +31,7 @@ static inline mat3 matmul3(const mat3 &a, const mat3 &b) { |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static inline vec3 matvecmul3(const mat3 &a, const vec3 &b) { |
|
|
|
|
static inline vec3 matvecmul3(const mat3 a, const vec3 b) { |
|
|
|
|
vec3 ret = {{0.0}}; |
|
|
|
|
for (int r=0; r<3; r++) { |
|
|
|
|
for (int c=0; c<3; c++) { |
|
|
|
@ -40,7 +41,7 @@ static inline vec3 matvecmul3(const mat3 &a, const vec3 &b) { |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static inline mat4 matmul(const mat4 &a, const mat4 &b) { |
|
|
|
|
static inline mat4 matmul(const mat4 a, const mat4 b) { |
|
|
|
|
mat4 ret = {{0.0}}; |
|
|
|
|
for (int r=0; r<4; r++) { |
|
|
|
|
for (int c=0; c<4; c++) { |
|
|
|
@ -54,7 +55,7 @@ static inline mat4 matmul(const mat4 &a, const mat4 &b) { |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static inline vec4 matvecmul(const mat4 &a, const vec4 &b) { |
|
|
|
|
static inline vec4 matvecmul(const mat4 a, const vec4 b) { |
|
|
|
|
vec4 ret = {{0.0}}; |
|
|
|
|
for (int r=0; r<4; r++) { |
|
|
|
|
for (int c=0; c<4; c++) { |
|
|
|
@ -66,7 +67,7 @@ static inline vec4 matvecmul(const mat4 &a, const vec4 &b) { |
|
|
|
|
|
|
|
|
|
// scales the input and output space of a transformation matrix
|
|
|
|
|
// that assumes pixel-center origin.
|
|
|
|
|
static inline mat3 transform_scale_buffer(const mat3 &in, float s) { |
|
|
|
|
static inline mat3 transform_scale_buffer(const mat3 in, float s) { |
|
|
|
|
// in_pt = ( transform(out_pt/s + 0.5) - 0.5) * s
|
|
|
|
|
|
|
|
|
|
mat3 transform_out = {{ |
|
|
|
@ -83,3 +84,5 @@ static inline mat3 transform_scale_buffer(const mat3 &in, float s) { |
|
|
|
|
|
|
|
|
|
return matmul3(transform_in, matmul3(in, transform_out)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|