mirror of
https://github.com/guezoloic/t3dsr.git
synced 2026-01-25 06:34:23 +00:00
feat: add c++ file and remove mconfig file
This commit is contained in:
@@ -1,12 +1,20 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
project(t3dsr C)
|
||||
project(t3dsr C CXX)
|
||||
|
||||
set(CMAKE_C_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS src/*.c)
|
||||
file(GLOB_RECURSE HEADERS CONFIGURE_DEPENDS src/*.h)
|
||||
# ==== sources ====
|
||||
file(GLOB_RECURSE C_SOURCES CONFIGURE_DEPENDS src/*.c)
|
||||
file(GLOB_RECURSE CPP_SOURCES CONFIGURE_DEPENDS src/*.cpp)
|
||||
file(GLOB_RECURSE HEADERS CONFIGURE_DEPENDS src/*.h src/*.hpp)
|
||||
|
||||
add_executable(main ${SOURCES} ${HEADERS})
|
||||
file(GLOB MAIN_SRC CONFIGURE_DEPENDS src/main.*)
|
||||
|
||||
set(ALL_SOURCES ${C_SOURCES} ${CPP_SOURCES})
|
||||
list(REMOVE_ITEM ALL_SOURCES ${MAIN_SRC})
|
||||
|
||||
add_executable(main ${MAIN_SRC} ${ALL_SOURCES} ${HEADERS})
|
||||
if(NOT MSVC)
|
||||
target_link_libraries(main m)
|
||||
endif()
|
||||
@@ -14,13 +22,11 @@ endif()
|
||||
|
||||
# ==== tests ====
|
||||
enable_testing()
|
||||
|
||||
file(GLOB_RECURSE TEST_SOURCES CONFIGURE_DEPENDS tests/*.c)
|
||||
list(FILTER SOURCES EXCLUDE REGEX ".*src/main\\.c$")
|
||||
|
||||
foreach(test_src ${TEST_SOURCES})
|
||||
get_filename_component(test_name ${test_src} NAME_WE)
|
||||
add_executable(${test_name} ${test_src} ${SOURCES})
|
||||
add_executable(${test_name} ${test_src} ${ALL_SOURCES})
|
||||
if(NOT MSVC)
|
||||
target_link_libraries(${test_name} m)
|
||||
endif()
|
||||
|
||||
36
src/main.c
36
src/main.c
@@ -1,36 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include "math/mat4.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
float arr[16] = {
|
||||
1, 2, 3, 4,
|
||||
5, 6, 7, 8,
|
||||
9, 10, 11, 12,
|
||||
13, 14, 15, 16
|
||||
};
|
||||
|
||||
Mat4f_t mat1 = mat4f_from_array(arr);
|
||||
Mat4f_t* mat_tps = mat4f_tpo_r(&mat1);
|
||||
|
||||
printf("%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n",
|
||||
mat1.m[0],
|
||||
mat1.m[1],
|
||||
mat1.m[2],
|
||||
mat1.m[3],
|
||||
mat1.m[4],
|
||||
mat1.m[5],
|
||||
mat1.m[6],
|
||||
mat1.m[7],
|
||||
mat1.m[8],
|
||||
mat1.m[9],
|
||||
mat1.m[10],
|
||||
mat1.m[11],
|
||||
mat1.m[12],
|
||||
mat1.m[13],
|
||||
mat1.m[14],
|
||||
mat1.m[15]
|
||||
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
13
src/main.cpp
Normal file
13
src/main.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <iostream>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "math/mat4.h"
|
||||
#include "math/vec3.h"
|
||||
#include "math/vec4.h"
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -300,4 +300,22 @@ Mat4f_t mat4f_tpo(const Mat4f_t *restrict m)
|
||||
Mat4f_t res = mat4f_clone(m);
|
||||
mat4f_tpo_r(&res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
float mat4f_det(const Mat4f_t* m)
|
||||
{
|
||||
float det;
|
||||
return det;
|
||||
}
|
||||
|
||||
Mat4f_t* mat4f_inv_r(Mat4f_t* __restrict m)
|
||||
{
|
||||
return m;
|
||||
}
|
||||
|
||||
Mat4f_t mat4f_inv(const Mat4f_t* m)
|
||||
{
|
||||
Mat4f_t mout = mat4f_clone(m);
|
||||
mat4f_inv_r(&mout);
|
||||
return mout;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,22 @@
|
||||
#ifndef MATRIX4_H
|
||||
#define MATRIX4_H
|
||||
|
||||
#include "mconfig.h"
|
||||
#if defined(__x86_64__) || defined(__amd64__) || defined(_M_X64)
|
||||
#define SIMD_X86
|
||||
#include <xmmintrin.h>
|
||||
|
||||
#elif defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64)
|
||||
#define SIMD_ARCH
|
||||
#include <arm_neon.h>
|
||||
|
||||
#else
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define ALIGN16 __declspec(align(16))
|
||||
#else
|
||||
#define ALIGN16 __attribute__((aligned(16)))
|
||||
#endif
|
||||
|
||||
#define MAT_SIZE 16
|
||||
#define MAT_DIM 4
|
||||
@@ -37,8 +52,9 @@ Mat4f_t* mat4f_mul_r(Mat4f_t* out, const Mat4f_t* m2);
|
||||
Mat4f_t mat4f_tpo(const Mat4f_t *__restrict m);
|
||||
Mat4f_t* mat4f_tpo_r(Mat4f_t *__restrict m);
|
||||
|
||||
// float mat4_det(const Mat4_t* m);
|
||||
float mat4f_det(const Mat4f_t* m);
|
||||
|
||||
// Mat4_t mat4_inv(const Mat4_t* m);
|
||||
Mat4f_t mat4f_inv(const Mat4f_t* m);
|
||||
Mat4f_t* mat4f_inv_r(Mat4f_t* __restrict m);
|
||||
|
||||
#endif // MATRIX4_H
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
// Common math library
|
||||
|
||||
#ifndef MCONFIG_H
|
||||
#define MCONFIG_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
#if defined(__x86_64__) || defined(__amd64__) || defined(_M_X64)
|
||||
#define SIMD_X86
|
||||
#define SIMD_ENABLE
|
||||
#include <xmmintrin.h>
|
||||
|
||||
#elif defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64)
|
||||
#define SIMD_ARCH
|
||||
#define SIMD_ENABLE
|
||||
#include <arm_neon.h>
|
||||
|
||||
#else
|
||||
#define SIMD_NONE
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define ALIGN16 __declspec(align(16))
|
||||
#else
|
||||
#define ALIGN16 __attribute__((aligned(16)))
|
||||
#endif
|
||||
|
||||
#endif // MCONFIG_H
|
||||
@@ -1,7 +1,5 @@
|
||||
#include "vec3.h"
|
||||
|
||||
#define VEC_SIZE 4
|
||||
|
||||
Vec3f_t vec3f(float x, float y, float z)
|
||||
{
|
||||
Vec3f_t vec = {.x = x, .y = y, .z = z};
|
||||
|
||||
@@ -8,11 +8,33 @@
|
||||
#ifndef vec3_h
|
||||
#define vec3_h
|
||||
|
||||
#include "mconfig.h"
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
typedef union
|
||||
{
|
||||
struct {float x, y, z; };
|
||||
#if defined(__x86_64__) || defined(__amd64__) || defined(_M_X64)
|
||||
#define SIMD_X86
|
||||
#define SIMD_ENABLE
|
||||
#include <xmmintrin.h>
|
||||
|
||||
#elif defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64)
|
||||
#define SIMD_ARCH
|
||||
#define SIMD_ENABLE
|
||||
#include <arm_neon.h>
|
||||
|
||||
#else
|
||||
#define SIMD_NONE
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define ALIGN16 __declspec(align(16))
|
||||
#else
|
||||
#define ALIGN16 __attribute__((aligned(16)))
|
||||
#endif
|
||||
|
||||
#define VEC_SIZE 3
|
||||
|
||||
typedef union {
|
||||
struct { float x, y, z; };
|
||||
float data[4];
|
||||
} ALIGN16 Vec3f_t;
|
||||
|
||||
@@ -58,4 +80,6 @@ Vec3f_t vec3f_refl(Vec3f_t v, Vec3f_t normal);
|
||||
|
||||
float vec3f_dist(Vec3f_t a, Vec3f_t b);
|
||||
|
||||
#undef VEC_SIZE
|
||||
|
||||
#endif /* vec3_h */
|
||||
|
||||
@@ -1,10 +1,33 @@
|
||||
#ifndef VECTOR4_H
|
||||
#define VECTOR4_H
|
||||
|
||||
#include "mconfig.h"
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
#if defined(__x86_64__) || defined(__amd64__) || defined(_M_X64)
|
||||
#define SIMD_X86
|
||||
#define SIMD_ENABLE
|
||||
#include <xmmintrin.h>
|
||||
|
||||
#elif defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64)
|
||||
#define SIMD_ARCH
|
||||
#define SIMD_ENABLE
|
||||
#include <arm_neon.h>
|
||||
|
||||
#else
|
||||
#define SIMD_NONE
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define ALIGN16 __declspec(align(16))
|
||||
#else
|
||||
#define ALIGN16 __attribute__((aligned(16)))
|
||||
#endif
|
||||
|
||||
#define VEC_SIZE 4
|
||||
|
||||
|
||||
|
||||
// must be aligned by 16 Bytes (less instruction executed for SSE)
|
||||
typedef union
|
||||
{
|
||||
@@ -54,4 +77,6 @@ Vec4f_t vec4f_refl(Vec4f_t v, Vec4f_t normal);
|
||||
|
||||
float vec4f_dist(Vec4f_t a, Vec4f_t b);
|
||||
|
||||
#undef VEC_SIZE
|
||||
|
||||
#endif // VECTOR4_H
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "../src/math/mconfig.h"
|
||||
#include "../src/math/mat4.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void config() {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include "../src/math/mconfig.h"
|
||||
|
||||
#include "../src/math/vec3.h"
|
||||
#include "../src/math/vec4.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user