mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-12 22:53:27 +00:00
added files
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,3 +1,6 @@
|
||||
[submodule "extlibs/googletest"]
|
||||
path = extlibs/googletest
|
||||
url = https://github.com/google/googletest.git
|
||||
[submodule "extlibs/glm"]
|
||||
path = extlibs/glm
|
||||
url = https://github.com/g-truc/glm.git
|
||||
|
||||
1
.idea/vcs.xml
generated
1
.idea/vcs.xml
generated
@@ -2,6 +2,7 @@
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/extlibs/glm" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/extlibs/googletest" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -23,10 +23,10 @@ if(OMATH_BUILD_TESTS)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
if (WIN32 AND OMATH_THREAT_WARNING_AS_ERROR)
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND OMATH_THREAT_WARNING_AS_ERROR)
|
||||
target_compile_options(omath PRIVATE /W4 /WX)
|
||||
elseif(UNIX AND OMATH_THREAT_WARNING_AS_ERROR)
|
||||
target_compile_options(omath PRIVATE -Wall -Wextra -Wpedantic)
|
||||
elseif(OMATH_THREAT_WARNING_AS_ERROR)
|
||||
target_compile_options(omath PRIVATE -Wall -Wextra -Wpedantic -Werror)
|
||||
endif()
|
||||
|
||||
target_include_directories(omath
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
"binaryDir": "${sourceDir}/cmake-build/build/${presetName}",
|
||||
"installDir": "${sourceDir}/cmake-build/install/${presetName}",
|
||||
"cacheVariables": {
|
||||
"CMAKE_C_COMPILER": "cl.exe",
|
||||
"CMAKE_CXX_COMPILER": "cl.exe"
|
||||
"CMAKE_C_COMPILER": "clang.exe",
|
||||
"CMAKE_CXX_COMPILER": "clang++.exe"
|
||||
},
|
||||
"condition": {
|
||||
"type": "equals",
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
add_subdirectory(googletest)
|
||||
add_subdirectory(googletest)
|
||||
add_subdirectory(glm)
|
||||
1
extlibs/glm
Submodule
1
extlibs/glm
Submodule
Submodule extlibs/glm added at 33b4a621a6
35
include/omath/engines/opengl.hpp
Normal file
35
include/omath/engines/opengl.hpp
Normal file
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// Created by Orange on 11/23/2024.
|
||||
//
|
||||
#pragma once
|
||||
#include "omath/Vector3.hpp"
|
||||
#include "omath/Mat.hpp"
|
||||
|
||||
|
||||
namespace omath::opengl
|
||||
{
|
||||
constexpr Vector3 kAbsUp = {0, 1, 0};
|
||||
constexpr Vector3 kAbsRight = {1, 0, 0};
|
||||
constexpr Vector3 kAbsForward = {0, 0, -1};
|
||||
|
||||
template<class Type> requires std::is_floating_point_v<Type> || std::is_integral_v<Type>
|
||||
[[nodiscard]] Mat<4, 4, Type, MatStoreType::COLUMN_MAJOR> PerspectiveProjectionMatrix()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
template<class Type> requires std::is_floating_point_v<Type> || std::is_integral_v<Type>
|
||||
[[nodiscard]] Mat<4, 4, Type, MatStoreType::COLUMN_MAJOR> PerspectiveProjectionMatrix(
|
||||
const float fieldOfView, const Type &aspectRatio, const Type &near, const Type &far)
|
||||
{
|
||||
const float fovHalfTan = std::tan(angles::DegreesToRadians(fieldOfView) / 2);
|
||||
|
||||
return
|
||||
{
|
||||
{static_cast<Type>(1) / (aspectRatio * fovHalfTan), 0, 0, 0},
|
||||
{0, static_cast<Type>(1) / (fovHalfTan), 0, 0},
|
||||
{0, 0, -(far + near) / (far - near), -(static_cast<Type>(2) * far * near) / (far - near)},
|
||||
{0, 0, -1, 0},
|
||||
};
|
||||
}
|
||||
}
|
||||
28
include/omath/engines/source.hpp
Normal file
28
include/omath/engines/source.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// Created by Orange on 11/24/2024.
|
||||
//
|
||||
#pragma once
|
||||
|
||||
|
||||
namespace omath::source
|
||||
{
|
||||
constexpr Vector3 kAbsUp = {0, 0, 1};
|
||||
constexpr Vector3 kAbsRight = {0, -1, 0};
|
||||
constexpr Vector3 kAbsForward = {1, 0, 0};
|
||||
|
||||
|
||||
template<class Type> requires std::is_floating_point_v<Type> || std::is_integral_v<Type>
|
||||
[[nodiscard]] Mat<4, 4, Type, MatStoreType::COLUMN_MAJOR> PerspectiveProjectionMatrix(
|
||||
const float fieldOfView, const Type &aspectRatio, const Type &near, const Type &far)
|
||||
{
|
||||
const float fovHalfTan = std::tan(angles::DegreesToRadians(fieldOfView) / 2);
|
||||
|
||||
return
|
||||
{
|
||||
{static_cast<Type>(1) / (aspectRatio * fovHalfTan), 0, 0, 0},
|
||||
{0, static_cast<Type>(1) / (fovHalfTan), 0, 0},
|
||||
{0, 0, (far + near) / (far - near), -(static_cast<Type>(2) * far * near) / (far - near)},
|
||||
{0, 0, 1, 0},
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -15,8 +15,9 @@ add_executable(unit-tests
|
||||
UnitTestColor.cpp
|
||||
UnitTestVector4.cpp
|
||||
UnitTestLineTrace.cpp
|
||||
UnitTestOpenGL.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(unit-tests PRIVATE gtest gtest_main omath)
|
||||
target_link_libraries(unit-tests PRIVATE gtest gtest_main omath glm)
|
||||
|
||||
gtest_discover_tests(unit-tests)
|
||||
48
tests/UnitTestOpenGL.cpp
Normal file
48
tests/UnitTestOpenGL.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// Created by Orange on 11/23/2024.
|
||||
//
|
||||
#include <complex>
|
||||
#include <gtest/gtest.h>
|
||||
#include <omath/Matrix.hpp>
|
||||
#include <print>
|
||||
#include <omath/engines/opengl.hpp>
|
||||
#include <omath/engines/source.hpp>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include "glm/ext/matrix_clip_space.hpp"
|
||||
#include "glm/ext/matrix_transform.hpp"
|
||||
|
||||
|
||||
TEST(UnitTestOpenGL, Projection)
|
||||
{
|
||||
|
||||
const auto proj_glm = glm::perspective(glm::radians(90.f), 16.f / 9.f, 0.1f, 1000.f);
|
||||
const auto proj_glm2 = glm::perspectiveLH_NO(glm::radians(90.f), 16.f / 9.f, 0.1f, 1000.f);
|
||||
// const auto proj_omath = omath::Mat<4, 4, float, omath::MatStoreType::COLUMN_MAJOR>((const float*)&proj_glm);
|
||||
// EXPECT_EQ(omath::opengl::PerspectiveProjectionMatrix(90, 16.f / 9.f, 0.1f, 1000.f), proj_omath);
|
||||
|
||||
|
||||
glm::vec4 ndc_glm2 = proj_glm * glm::vec4(300.f, 0.f, -1000.f, 1.f);
|
||||
ndc_glm2 /= ndc_glm2.w;
|
||||
const omath::Mat<4, 1, float, omath::MatStoreType::COLUMN_MAJOR> cords_omath =
|
||||
{
|
||||
{0},
|
||||
{0},
|
||||
{-0.2f},
|
||||
{1}
|
||||
};
|
||||
|
||||
//auto ndc_omath = proj_omath * cords_omath;
|
||||
// ndc_omath /= ndc_omath.At(3, 0);
|
||||
|
||||
}
|
||||
TEST(UnitTestOpenGL, Projection2)
|
||||
{
|
||||
const auto orient = omath::Mat<>::OrientationMat(omath::opengl::kAbsForward, omath::opengl::kAbsRight, omath::opengl::kAbsUp);
|
||||
|
||||
const omath::Mat<4, 1> cords_omath =
|
||||
{
|
||||
{0}, {0}, {10}, {1}
|
||||
};
|
||||
std::cout << (orient.Transposed() * cords_omath).ToString();
|
||||
}
|
||||
Reference in New Issue
Block a user