restructured project
This commit is contained in:
parent
b68a05bcb1
commit
e137549b2e
@ -1,19 +1,17 @@
|
|||||||
cmake_minimum_required (VERSION 3.16)
|
cmake_minimum_required (VERSION 3.16)
|
||||||
|
|
||||||
|
# Dependencies
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
|
||||||
|
|
||||||
set(USE_SYSTEM_OCCT ON CACHE INTERNAL "")
|
set(USE_SYSTEM_OCCT ON CACHE INTERNAL "")
|
||||||
|
|
||||||
include(${CMAKE_SOURCE_DIR}/cmake/glad.cmake)
|
|
||||||
include(${CMAKE_SOURCE_DIR}/cmake/stb.cmake)
|
|
||||||
include(${CMAKE_SOURCE_DIR}/cmake/imgui.cmake)
|
|
||||||
include(${CMAKE_SOURCE_DIR}/cmake/occt.cmake)
|
|
||||||
|
|
||||||
|
|
||||||
|
# Main project
|
||||||
project(
|
project(
|
||||||
hyporo
|
project-hyporo
|
||||||
VERSION 0.20.0
|
VERSION 0.10.0
|
||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -22,16 +20,12 @@ option(WITH_GTESTS "Enable GTest unit testing" ON)
|
|||||||
enable_testing()
|
enable_testing()
|
||||||
|
|
||||||
if(WITH_GTESTS)
|
if(WITH_GTESTS)
|
||||||
|
option(INSTALL_GMOCK "" OFF)
|
||||||
|
option(INSTALL_GTEST "" OFF)
|
||||||
include(${CMAKE_SOURCE_DIR}/cmake/googletest.cmake)
|
include(${CMAKE_SOURCE_DIR}/cmake/googletest.cmake)
|
||||||
include(GoogleTest)
|
include(GoogleTest)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
|
|
||||||
add_definitions(-DPRECISION_DOUBLE)
|
|
||||||
|
|
||||||
add_subdirectory(source)
|
add_subdirectory(source)
|
||||||
|
#add_subdirectory(docs)
|
||||||
add_subdirectory(docs)
|
|
@ -9,7 +9,7 @@ CPMAddPackage(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if(imgui_external_ADDED)
|
if(imgui_external_ADDED)
|
||||||
project(imgui)
|
set(EXTERNAL_PROJECT_NAME imgui)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ if(imgui_external_ADDED)
|
|||||||
find_package(OpenGL REQUIRED)
|
find_package(OpenGL REQUIRED)
|
||||||
pkg_search_module(GLFW REQUIRED glfw3)
|
pkg_search_module(GLFW REQUIRED glfw3)
|
||||||
|
|
||||||
add_library(${PROJECT_NAME} STATIC
|
add_library(${EXTERNAL_PROJECT_NAME} STATIC
|
||||||
${imgui_external_SOURCE_DIR}/imgui.cpp
|
${imgui_external_SOURCE_DIR}/imgui.cpp
|
||||||
${imgui_external_SOURCE_DIR}/imgui_demo.cpp
|
${imgui_external_SOURCE_DIR}/imgui_demo.cpp
|
||||||
${imgui_external_SOURCE_DIR}/imgui_draw.cpp
|
${imgui_external_SOURCE_DIR}/imgui_draw.cpp
|
||||||
@ -31,11 +31,11 @@ if(imgui_external_ADDED)
|
|||||||
${imgui_external_SOURCE_DIR}/misc/freetype/imgui_freetype.cpp
|
${imgui_external_SOURCE_DIR}/misc/freetype/imgui_freetype.cpp
|
||||||
${imgui_external_SOURCE_DIR}/misc/cpp/imgui_stdlib.cpp
|
${imgui_external_SOURCE_DIR}/misc/cpp/imgui_stdlib.cpp
|
||||||
)
|
)
|
||||||
add_library(imgui::imgui ALIAS ${PROJECT_NAME})
|
add_library(imgui::imgui ALIAS ${EXTERNAL_PROJECT_NAME})
|
||||||
|
|
||||||
add_compile_definitions(IMGUI_IMPL_OPENGL_LOADER_GLAD)
|
add_compile_definitions(IMGUI_IMPL_OPENGL_LOADER_GLAD)
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME}
|
target_include_directories(${EXTERNAL_PROJECT_NAME}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
$<BUILD_INTERFACE:${imgui_external_SOURCE_DIR}>
|
$<BUILD_INTERFACE:${imgui_external_SOURCE_DIR}>
|
||||||
$<BUILD_INTERFACE:${imgui_external_SOURCE_DIR}/backends>
|
$<BUILD_INTERFACE:${imgui_external_SOURCE_DIR}/backends>
|
||||||
@ -46,14 +46,14 @@ if(imgui_external_ADDED)
|
|||||||
${GLFW_INCLUDE_DIRS}
|
${GLFW_INCLUDE_DIRS}
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME}
|
target_link_libraries(${EXTERNAL_PROJECT_NAME}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
Freetype::Freetype
|
Freetype::Freetype
|
||||||
glfw
|
glfw
|
||||||
OpenGL::GL
|
OpenGL::GL
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties(${PROJECT_NAME}
|
set_target_properties(${EXTERNAL_PROJECT_NAME}
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
POSITION_INDEPENDENT_CODE ON
|
POSITION_INDEPENDENT_CODE ON
|
||||||
OUTPUT_NAME imgui
|
OUTPUT_NAME imgui
|
||||||
@ -63,21 +63,21 @@ if(imgui_external_ADDED)
|
|||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
install(
|
install(
|
||||||
TARGETS ${PROJECT_NAME}
|
TARGETS ${EXTERNAL_PROJECT_NAME}
|
||||||
EXPORT ${PROJECT_NAME}Targets
|
EXPORT ${EXTERNAL_PROJECT_NAME}Targets
|
||||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${EXTERNAL_PROJECT_NAME}
|
||||||
)
|
)
|
||||||
|
|
||||||
install(
|
install(
|
||||||
EXPORT ${PROJECT_NAME}Targets
|
EXPORT ${EXTERNAL_PROJECT_NAME}Targets
|
||||||
FILE ${PROJECT_NAME}Targets.cmake
|
FILE ${EXTERNAL_PROJECT_NAME}Targets.cmake
|
||||||
NAMESPACE ${PROJECT_NAME}::
|
NAMESPACE ${EXTERNAL_PROJECT_NAME}::
|
||||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${EXTERNAL_PROJECT_NAME}
|
||||||
)
|
)
|
||||||
|
|
||||||
install(
|
install(
|
||||||
DIRECTORY ${imgui_external_SOURCE_DIR}
|
DIRECTORY ${imgui_external_SOURCE_DIR}
|
||||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${EXTERNAL_PROJECT_NAME}
|
||||||
COMPONENT devel
|
COMPONENT devel
|
||||||
FILES_MATCHING
|
FILES_MATCHING
|
||||||
PATTERN "*.h"
|
PATTERN "*.h"
|
||||||
|
52
cmake/macros.cmake
Normal file
52
cmake/macros.cmake
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
|
||||||
|
macro(add_component_library COMPONENT LIBRARY_TYPE COMPONENT_SOURCES)
|
||||||
|
add_library(${COMPONENT} ${LIBRARY_TYPE} ${COMPONENT_SOURCES})
|
||||||
|
add_library(${PROJECT_NAME}::${COMPONENT} ALIAS ${COMPONENT})
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
macro(install_component_source COMPONENT)
|
||||||
|
set_target_properties(${COMPONENT}
|
||||||
|
PROPERTIES
|
||||||
|
VERSION ${${PROJECT_NAME}_VERSION}
|
||||||
|
SOVERSION ${${PROJECT_NAME}_VERSION_MAJOR}
|
||||||
|
OUTPUT_NAME ${PROJECT_NAME}-${COMPONENT}
|
||||||
|
)
|
||||||
|
|
||||||
|
install(
|
||||||
|
TARGETS ${COMPONENT}
|
||||||
|
EXPORT ${COMPONENT}Targets
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}
|
||||||
|
)
|
||||||
|
|
||||||
|
install(
|
||||||
|
EXPORT ${COMPONENT}Targets
|
||||||
|
FILE ${COMPONENT}Targets.cmake
|
||||||
|
NAMESPACE ${PROJECT_NAME}::
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
|
||||||
|
)
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
macro(install_component_headers COMPONENT)
|
||||||
|
|
||||||
|
#target_include_directories(${COMPONENT}
|
||||||
|
# PUBLIC
|
||||||
|
# $<INSTALL_INTERFACE:include>
|
||||||
|
# $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>#/${CMAKE_PROJECT_NAME}>#/include>
|
||||||
|
# )
|
||||||
|
|
||||||
|
install(
|
||||||
|
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}#/${COMPONENT}
|
||||||
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}#/${COMPONENT}
|
||||||
|
COMPONENT devel
|
||||||
|
FILES_MATCHING
|
||||||
|
PATTERN "*.h"
|
||||||
|
PATTERN "*.hpp"
|
||||||
|
)
|
||||||
|
|
||||||
|
install(
|
||||||
|
FILES ${CMAKE_CURRENT_SOURCE_DIR}/../${COMPONENT}.hpp
|
||||||
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}#/${COMPONENT}
|
||||||
|
COMPONENT devel
|
||||||
|
)
|
||||||
|
|
||||||
|
endmacro()
|
@ -8,17 +8,17 @@ CPMAddPackage(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if(stb_external_ADDED)
|
if(stb_external_ADDED)
|
||||||
project(stb)
|
set(EXTERNAL_PROJECT_NAME stb)
|
||||||
|
|
||||||
add_library(${PROJECT_NAME} INTERFACE)
|
add_library(${EXTERNAL_PROJECT_NAME} INTERFACE)
|
||||||
add_library(stb::stb ALIAS ${PROJECT_NAME})
|
add_library(stb::stb ALIAS ${EXTERNAL_PROJECT_NAME})
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME}
|
target_include_directories(${EXTERNAL_PROJECT_NAME}
|
||||||
INTERFACE
|
INTERFACE
|
||||||
$<BUILD_INTERFACE:${stb_external_SOURCE_DIR}>
|
$<BUILD_INTERFACE:${stb_external_SOURCE_DIR}>
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties(${PROJECT_NAME}
|
set_target_properties(${EXTERNAL_PROJECT_NAME}
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
OUTPUT_NAME stb
|
OUTPUT_NAME stb
|
||||||
)
|
)
|
||||||
@ -26,21 +26,21 @@ if(stb_external_ADDED)
|
|||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
install(
|
install(
|
||||||
TARGETS ${PROJECT_NAME}
|
TARGETS ${EXTERNAL_PROJECT_NAME}
|
||||||
EXPORT ${PROJECT_NAME}Targets
|
EXPORT ${EXTERNAL_PROJECT_NAME}Targets
|
||||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${EXTERNAL_PROJECT_NAME}
|
||||||
)
|
)
|
||||||
|
|
||||||
install(
|
install(
|
||||||
EXPORT ${PROJECT_NAME}Targets
|
EXPORT ${EXTERNAL_PROJECT_NAME}Targets
|
||||||
FILE ${PROJECT_NAME}Targets.cmake
|
FILE ${EXTERNAL_PROJECT_NAME}Targets.cmake
|
||||||
NAMESPACE ${PROJECT_NAME}::
|
NAMESPACE ${EXTERNAL_PROJECT_NAME}::
|
||||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${EXTERNAL_PROJECT_NAME}
|
||||||
)
|
)
|
||||||
|
|
||||||
install(
|
install(
|
||||||
DIRECTORY ${stb_external_SOURCE_DIR}
|
DIRECTORY ${stb_external_SOURCE_DIR}
|
||||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${EXTERNAL_PROJECT_NAME}
|
||||||
COMPONENT devel
|
COMPONENT devel
|
||||||
FILES_MATCHING
|
FILES_MATCHING
|
||||||
PATTERN "*.h"
|
PATTERN "*.h"
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
add_subdirectory(hyporo)
|
add_subdirectory(hpr)
|
||||||
add_subdirectory(creator)
|
add_subdirectory(creator)
|
||||||
add_subdirectory(applications)
|
#add_subdirectory(applications)
|
208
source/applications/periodic/lattice.hpp
Normal file
208
source/applications/periodic/lattice.hpp
Normal file
@ -0,0 +1,208 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../../hyporo/hyplib/scalar/scalar.hpp"
|
||||||
|
#include "../../hyporo/hyplib/vector/vector.hpp"
|
||||||
|
#include "../../hyporo/hyplib/array/array.hpp"
|
||||||
|
#include "../../hyporo/hyplib/matrix/matrix.hpp"
|
||||||
|
#include "../../hyporo/csg/csg.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
namespace hpr::csg
|
||||||
|
{
|
||||||
|
void prints(scalar point)
|
||||||
|
{
|
||||||
|
std::cout << point << std::endl;
|
||||||
|
}
|
||||||
|
class Lattice : public csg::Shape
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
enum class System
|
||||||
|
{
|
||||||
|
Triclinic,
|
||||||
|
Monoclinic,
|
||||||
|
Orthorhombic,
|
||||||
|
Tetragonal,
|
||||||
|
Rhombohedral,
|
||||||
|
Hexagonal,
|
||||||
|
Cubic,
|
||||||
|
Unknown
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class Type
|
||||||
|
{
|
||||||
|
Primitive,
|
||||||
|
BaseCentered,
|
||||||
|
BodyCentered,
|
||||||
|
FaceCentered,
|
||||||
|
Unknown
|
||||||
|
};
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
vec3 p_lengths;
|
||||||
|
vec3 p_angles;
|
||||||
|
Type p_type;
|
||||||
|
scalar p_radius;
|
||||||
|
darray<vec3> p_controlPoints;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
Lattice() = delete;
|
||||||
|
|
||||||
|
Lattice(const vec3& lengths, const vec3& angles, scalar radius, Type type) :
|
||||||
|
csg::Shape {},
|
||||||
|
p_lengths {lengths},
|
||||||
|
p_angles {angles},
|
||||||
|
p_radius {radius},
|
||||||
|
p_type {type}
|
||||||
|
{
|
||||||
|
generateControlPoints();
|
||||||
|
darray<csg::Shape> spheres;
|
||||||
|
for (const auto& point : controlPoints()) {
|
||||||
|
spheres.push(csg::sphere(point, p_radius));
|
||||||
|
print(point);
|
||||||
|
}
|
||||||
|
|
||||||
|
p_shape = csg::Compound(spheres).tshape();//csg::fuse({spheres.front()}, spheres.slice(spheres.begin() + 1, spheres.end())).tshape();
|
||||||
|
}
|
||||||
|
|
||||||
|
darray<vec3> controlPoints() const
|
||||||
|
{
|
||||||
|
return p_controlPoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 lengths() const
|
||||||
|
{
|
||||||
|
return p_lengths;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 angles() const
|
||||||
|
{
|
||||||
|
return p_angles;
|
||||||
|
}
|
||||||
|
|
||||||
|
void generateControlPoints()
|
||||||
|
{
|
||||||
|
if (p_type == Type::Unknown)
|
||||||
|
throw std::runtime_error("Unknown type of lattice");
|
||||||
|
p_controlPoints.resize(14);
|
||||||
|
//
|
||||||
|
vec3 ox {1, 0, 0};
|
||||||
|
vec3 oy {0, 1, 0};
|
||||||
|
vec3 oz {0, 0, 1};
|
||||||
|
vec3 ox1 = hpr::rotate(ox, oz, radians(-p_angles[2]));
|
||||||
|
p_controlPoints.push(vec3{0, 0, 0});
|
||||||
|
p_controlPoints.push(vec3{0, p_lengths[0], 0});
|
||||||
|
vec3 t1 = hpr::translate(p_controlPoints.back(), ox1 * p_lengths[1]);
|
||||||
|
p_controlPoints.push(t1);
|
||||||
|
p_controlPoints.push(hpr::translate(p_controlPoints.front(), ox1 * p_lengths[1]));
|
||||||
|
print(t1);
|
||||||
|
print(ox1);
|
||||||
|
scalar c1 = cos(radians(p_angles[2])), c2 = cos(radians(p_angles[1])), c3 = cos(radians(p_angles[0]));
|
||||||
|
scalar D1 = sqrt(mat3(
|
||||||
|
1, cos(radians(p_angles[2])), cos(radians(p_angles[1])),
|
||||||
|
cos(radians(p_angles[2])), 1, cos(radians(p_angles[0])),
|
||||||
|
cos(radians(p_angles[1])), cos(radians(p_angles[0])), 1).det());
|
||||||
|
scalar volume = 1. / 6. * p_lengths[0] * p_lengths[1] * p_lengths[2] *
|
||||||
|
D1;
|
||||||
|
scalar s1 = sqrt(std::pow(p_lengths[0], 2) + std::pow(p_lengths[1], 2) - 2 *
|
||||||
|
p_lengths[0] * p_lengths[1] * cos(radians(p_angles[2])));
|
||||||
|
scalar s2 = sqrt(std::pow(p_lengths[1], 2) + std::pow(p_lengths[2], 2) - 2 *
|
||||||
|
p_lengths[1] * p_lengths[2] * cos(radians(p_angles[1])));
|
||||||
|
scalar s3 = sqrt(std::pow(p_lengths[0], 2) + std::pow(p_lengths[2], 2) - 2 *
|
||||||
|
p_lengths[0] * p_lengths[2] * cos(radians(p_angles[0])));
|
||||||
|
scalar area = 1. / 2. * p_lengths[0] * p_lengths[1] *
|
||||||
|
sqrt(mat2{1, cos(radians(p_angles[2])), cos(radians(p_angles[2])), 1}.det());
|
||||||
|
scalar h1 = 3 * volume / area;
|
||||||
|
scalar a1 = asin(h1 / p_lengths[2]);
|
||||||
|
scalar sh1 = sqrt(std::pow(p_lengths[2], 2) - std::pow(h1, 2));
|
||||||
|
scalar sh2 = p_lengths[2] * cos(radians(p_angles[0]));
|
||||||
|
scalar a2 = acos(sh2 / sh1);
|
||||||
|
|
||||||
|
vec3 ox2 = hpr::rotate(ox, oy, a1);
|
||||||
|
if (!std::isnan(a2))
|
||||||
|
ox2 = hpr::rotate(ox2, oz, a2);
|
||||||
|
print(ox2);
|
||||||
|
for (auto n = 0; n < 4; ++n)
|
||||||
|
p_controlPoints.push(hpr::translate(p_controlPoints[n], ox2 * p_lengths[2]));
|
||||||
|
|
||||||
|
/*p_controlPoints.push(vec3{p_lengths[0], p_lengths[1], 0});
|
||||||
|
p_controlPoints.push(vec3{p_lengths[0], 0, 0});
|
||||||
|
|
||||||
|
p_controlPoints.push(vec3{0, 0, p_lengths[2]});
|
||||||
|
p_controlPoints.push(vec3{0, p_lengths[1], p_lengths[2]});
|
||||||
|
p_controlPoints.push(vec3{p_lengths[0], p_lengths[1], p_lengths[2]});
|
||||||
|
p_controlPoints.push(vec3{p_lengths[0], 0, p_lengths[2]});
|
||||||
|
|
||||||
|
// central points on base faces
|
||||||
|
if (p_type == Type::BaseCentered || p_type == Type::FaceCentered)
|
||||||
|
{
|
||||||
|
for (int n = 0; n < 2; ++n)
|
||||||
|
{
|
||||||
|
vec3 center;
|
||||||
|
for (int k = 0; k < 4; ++k)
|
||||||
|
center += p_controlPoints[k + 4 * n];
|
||||||
|
p_controlPoints.push(center * 0.25);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// central point (center of mass)
|
||||||
|
if (p_type == Type::BodyCentered)
|
||||||
|
{
|
||||||
|
vec3 center;
|
||||||
|
for (const auto& point : p_controlPoints)
|
||||||
|
center += point;
|
||||||
|
p_controlPoints.push(center / p_controlPoints.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
// central points on side faces
|
||||||
|
if (p_type == Type::FaceCentered)
|
||||||
|
{
|
||||||
|
for (int n = 0; n < 3; ++n)
|
||||||
|
{
|
||||||
|
vec3 center;
|
||||||
|
for (int k = 0; k < 2; ++k)
|
||||||
|
{
|
||||||
|
center += p_controlPoints[n + k];
|
||||||
|
center += p_controlPoints[n + k + 4];
|
||||||
|
}
|
||||||
|
p_controlPoints.push(center * 0.25);
|
||||||
|
}
|
||||||
|
vec3 center;
|
||||||
|
for (int n = 0; n < 2; ++n)
|
||||||
|
{
|
||||||
|
center += p_controlPoints[n * 3];
|
||||||
|
center += p_controlPoints[4 + n * 3];
|
||||||
|
}
|
||||||
|
p_controlPoints.push(center * 0.25);
|
||||||
|
}
|
||||||
|
|
||||||
|
mat4 trans = mat4::identity();
|
||||||
|
vec3 ox {1, 0, 0};
|
||||||
|
vec3 oy {0, 1, 0};
|
||||||
|
vec3 oz {0, 0, 1};
|
||||||
|
int n = 0;
|
||||||
|
for (auto& point : p_controlPoints)
|
||||||
|
{
|
||||||
|
if (n == 0 || n == 3)
|
||||||
|
{
|
||||||
|
++n;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
trans.row(3, vec4(point, 0));
|
||||||
|
trans = hpr::rotate(trans, oz, -radians(90 - p_angles[2]));
|
||||||
|
if (n >= 4 && n <= 7)
|
||||||
|
{
|
||||||
|
trans = hpr::rotate(trans, ox, -radians(90 - p_angles[1]));
|
||||||
|
trans = hpr::rotate(trans, oy, -radians(90 - p_angles[0]));
|
||||||
|
}
|
||||||
|
point = vec3(trans.row(3)[0], trans.row(3)[1], trans.row(3)[2]);
|
||||||
|
++n;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
@ -144,6 +144,7 @@ public:
|
|||||||
lattice = lattice.scale({0, 0, 0}, 1e-2);
|
lattice = lattice.scale({0, 0, 0}, 1e-2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cout << (int)lattice.type() << std::endl;
|
||||||
return lattice;
|
return lattice;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,6 +201,7 @@ public:
|
|||||||
face.label("periodic-up");
|
face.label("periodic-up");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cout << (int)cell.type() << std::endl;
|
||||||
return cell;
|
return cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,12 +230,17 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#include "lattice.hpp"
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
Simple simple {0.01, {1., 0., 0.}};
|
/*Simple simple {0.01, {1., 0., 0.}};
|
||||||
simple.build();
|
simple.build();
|
||||||
|
|
||||||
//simple.dump("simpleTest.step", csg::Shape::Format::STEP);
|
std::cout << (int)simple.type() << std::endl;
|
||||||
|
std::cout << simple.volume() << std::endl;
|
||||||
|
*/
|
||||||
|
csg::Lattice lattice {{2, 2, 2}, {90, 90, 90}, 1, csg::Lattice::Type::Primitive};
|
||||||
|
lattice.dump("latticeTest.step", csg::Shape::Format::STEP);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -1,22 +1,37 @@
|
|||||||
|
|
||||||
include_directories(
|
project(
|
||||||
../hyporo/hyplib
|
hyporo
|
||||||
../hyporo/window_system
|
VERSION 0.1.0
|
||||||
../hyporo/gpu
|
LANGUAGES CXX
|
||||||
../hyporo/hmesh
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(hyporo
|
# Compiler options
|
||||||
# Source files
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
|
||||||
|
|
||||||
|
# Project options
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
|
|
||||||
|
add_executable(${PROJECT_NAME}
|
||||||
creator.cpp
|
creator.cpp
|
||||||
|
|
||||||
|
../hpr/window_system/window_system.cpp
|
||||||
|
../hpr/window_system/monitor.cpp
|
||||||
|
../hpr/window_system/window.cpp
|
||||||
|
../hpr/window_system/glfw/window_system.cpp
|
||||||
|
../hpr/window_system/glfw/monitor.cpp
|
||||||
|
../hpr/window_system/glfw/window.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(hyporo
|
include(${CMAKE_SOURCE_DIR}/cmake/imgui.cmake)
|
||||||
PUBLIC
|
message(STATUS "project name: ${PROJECT_NAME}")
|
||||||
hyporo-hyplib
|
target_link_libraries(${PROJECT_NAME}
|
||||||
hyporo-window-system
|
hpr::hpr
|
||||||
hyporo-gpu
|
|
||||||
hyporo-mesh
|
|
||||||
imgui
|
imgui
|
||||||
)
|
)
|
||||||
|
|
||||||
|
target_include_directories(${PROJECT_NAME}
|
||||||
|
PRIVATE
|
||||||
|
../
|
||||||
|
)
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
#include "../window_system/window_system.hpp"
|
#include "hpr/window_system/window_system.hpp"
|
||||||
#include "../window_system/glfw/window.hpp"
|
#include "hpr/window_system/glfw/window_system.hpp"
|
||||||
#include "../gpu/device.hpp"
|
#include "hpr/window_system/glfw/window.hpp"
|
||||||
#include "../gpu/opengl/device.hpp"
|
#include "hpr/gpu.hpp"
|
||||||
#include "../hmesh/mesh.hpp"
|
#include "hpr/math.hpp"
|
||||||
#include "../hyplib/matrix/matrix.hpp"
|
#include "hpr/mesh.hpp"
|
||||||
#include "../hyplib/vector/vector.hpp"
|
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include <imgui_impl_glfw.h>
|
#include <imgui_impl_glfw.h>
|
||||||
#include <imgui_impl_opengl3.h>
|
#include <imgui_impl_opengl3.h>
|
||||||
|
131
source/hpr/CMakeLists.txt
Normal file
131
source/hpr/CMakeLists.txt
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
|
||||||
|
project(
|
||||||
|
hpr
|
||||||
|
VERSION 0.10.0
|
||||||
|
LANGUAGES CXX
|
||||||
|
)
|
||||||
|
|
||||||
|
# Compiler options
|
||||||
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
|
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
|
||||||
|
|
||||||
|
add_definitions(-DPRECISION_DOUBLE)
|
||||||
|
|
||||||
|
# Project options
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
include(${CMAKE_SOURCE_DIR}/cmake/macros.cmake)
|
||||||
|
|
||||||
|
option(WITH_CSG "Build with CSG component" ON)
|
||||||
|
option(WITH_GPU "Build with graphics component" ON)
|
||||||
|
option(WITH_MESH "Build with mesh utils component" ON)
|
||||||
|
option(WITH_WS "Build with window system component" ON)
|
||||||
|
|
||||||
|
# containers
|
||||||
|
file(GLOB containers_hpp "containers.hpp" "containers/*.hpp" "containers/array/*.hpp")
|
||||||
|
file(GLOB containers_cpp "containers/*.cpp" "containers/array/*.cpp")
|
||||||
|
|
||||||
|
# math
|
||||||
|
file(GLOB math_hpp "math.hpp" "math/*.hpp" "math/scalar/*.hpp" "math/vector/*.hpp" "math/matrix/*.hpp")
|
||||||
|
file(GLOB math_cpp "math/*.cpp" "math/scalar/*.cpp" "math/vector/*.cpp" "math/matrix/*.cpp")
|
||||||
|
|
||||||
|
# io
|
||||||
|
file(GLOB io_hpp "io.hpp" "io/*.hpp")
|
||||||
|
file(GLOB io_cpp "io/*.cpp")
|
||||||
|
|
||||||
|
# csg
|
||||||
|
file(GLOB csg_hpp "csg.hpp" "csg/*.hpp")
|
||||||
|
file(GLOB csg_cpp "csg/*.cpp")
|
||||||
|
|
||||||
|
# gpu
|
||||||
|
file(GLOB gpu_hpp "gpu.hpp" "gpu/*.hpp")
|
||||||
|
file(GLOB gpu_cpp "gpu/*.cpp")
|
||||||
|
file(GLOB gpu_opengl_hpp "gpu/opengl/*.hpp")
|
||||||
|
file(GLOB gpu_opengl_cpp "gpu/opengl/*.cpp")
|
||||||
|
|
||||||
|
# mesh
|
||||||
|
file(GLOB mesh_hpp "mesh.hpp" "mesh/*.hpp")
|
||||||
|
file(GLOB mesh_cpp "mesh/*.cpp")
|
||||||
|
|
||||||
|
# window system
|
||||||
|
file(GLOB window_system_hpp "window_system.hpp" "window_system/*.hpp")
|
||||||
|
file(GLOB window_system_cpp "window_system/*.cpp")
|
||||||
|
file(GLOB window_system_glfw_hpp "window_system/glfw/*.hpp")
|
||||||
|
file(GLOB window_system_glfw_cpp "window_system/glfw/*.cpp")
|
||||||
|
|
||||||
|
#
|
||||||
|
list(APPEND hpr_INCLUDE
|
||||||
|
${containers_hpp}
|
||||||
|
${math_hpp}
|
||||||
|
${io_hpp}
|
||||||
|
)
|
||||||
|
list(APPEND hpr_SOURCES
|
||||||
|
${containers_cpp}
|
||||||
|
${math_cpp}
|
||||||
|
${io_cpp}
|
||||||
|
)
|
||||||
|
list(APPEND hpr_LIBRARIES "")
|
||||||
|
list(APPEND hpr_INCLUDE_DIRS "")
|
||||||
|
|
||||||
|
if (WITH_CSG)
|
||||||
|
include(${CMAKE_SOURCE_DIR}/cmake/occt.cmake)
|
||||||
|
|
||||||
|
list(APPEND hpr_INCLUDE ${csg_hpp})
|
||||||
|
list(APPEND hpr_SOURCES ${csg_cpp})
|
||||||
|
list(APPEND hpr_LIBRARIES ${OCCT_LIBRARIES})
|
||||||
|
|
||||||
|
list(APPEND hpr_INCLUDE_DIRS ${OCCT_INCLUDE_DIRS})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (WITH_GPU)
|
||||||
|
include(${CMAKE_SOURCE_DIR}/cmake/glad.cmake)
|
||||||
|
include(${CMAKE_SOURCE_DIR}/cmake/stb.cmake)
|
||||||
|
|
||||||
|
list(APPEND hpr_INCLUDE ${gpu_hpp} ${gpu_opengl_hpp})
|
||||||
|
list(APPEND hpr_SOURCES ${gpu_cpp} ${gpu_opengl_cpp})
|
||||||
|
list(APPEND hpr_LIBRARIES glad stb)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (WITH_WS)
|
||||||
|
list(APPEND hpr_INCLUDE ${window_system_hpp} ${window_system_glfw_hpp})
|
||||||
|
list(APPEND hpr_SOURCES ${window_system_cpp} ${window_system_glfw_cpp})
|
||||||
|
list(APPEND hpr_LIBRARIES glfw)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_library(${PROJECT_NAME} SHARED
|
||||||
|
hpr.cpp
|
||||||
|
${hpr_SOURCES}
|
||||||
|
)
|
||||||
|
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
|
||||||
|
|
||||||
|
target_link_libraries(${PROJECT_NAME}
|
||||||
|
${hpr_LIBRARIES}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(${PROJECT_NAME}
|
||||||
|
PUBLIC
|
||||||
|
${hpr_INCLUDE_DIRS}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Install library
|
||||||
|
|
||||||
|
install(
|
||||||
|
TARGETS ${PROJECT_NAME}
|
||||||
|
EXPORT ${PROJECT_NAME}Targets
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}
|
||||||
|
)
|
||||||
|
|
||||||
|
install(
|
||||||
|
EXPORT ${PROJECT_NAME}Targets
|
||||||
|
FILE ${PROJECT_NAME}Targets.cmake
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
|
||||||
|
)
|
||||||
|
|
||||||
|
include(CPack)
|
||||||
|
|
||||||
|
#
|
||||||
|
message(STATUS "Components:")
|
||||||
|
message(STATUS " Core: ON")
|
||||||
|
message(STATUS " CSG: ${WITH_CSG}")
|
||||||
|
message(STATUS " GPU: ${WITH_GPU}")
|
||||||
|
message(STATUS " Mesh: ${WITH_MESH}")
|
||||||
|
message(STATUS " WindowSystem: ${WITH_WS}")
|
3
source/hpr/containers.hpp
Normal file
3
source/hpr/containers.hpp
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "containers/array.hpp"
|
28
source/hpr/containers/CMakeLists.txt
Normal file
28
source/hpr/containers/CMakeLists.txt
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
|
||||||
|
set(COMPONENT_NAME containers)
|
||||||
|
|
||||||
|
add_component_library(${COMPONENT_NAME} INTERFACE ""
|
||||||
|
)
|
||||||
|
|
||||||
|
#target_sources(${COMPONENT_NAME} PUBLIC
|
||||||
|
# array/dynamic_array.hpp
|
||||||
|
# array.hpp
|
||||||
|
# array/iterator.hpp
|
||||||
|
# array/static_array.hpp
|
||||||
|
#)
|
||||||
|
|
||||||
|
install_component_headers(${COMPONENT_NAME})
|
||||||
|
install_component_source(${COMPONENT_NAME})
|
||||||
|
|
||||||
|
if (WITH_GTEST)
|
||||||
|
add_executable(${COMPONENT_NAME}-test
|
||||||
|
tests/${COMPONENT_NAME}-test.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(${COMPONENT_NAME}-test
|
||||||
|
${CMAKE_PROJECT_NAME}::${COMPONENT_NAME}
|
||||||
|
GTest::gtest_main
|
||||||
|
)
|
||||||
|
|
||||||
|
gtest_add_tests(TARGET ${COMPONENT_NAME}-test)
|
||||||
|
endif()
|
4
source/hpr/containers/array.hpp
Normal file
4
source/hpr/containers/array.hpp
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "array/dynamic_array.hpp"
|
||||||
|
#include "array/static_array.hpp"
|
@ -358,6 +358,7 @@ public:
|
|||||||
p_size = newSize;
|
p_size = newSize;
|
||||||
p_end = p_start + p_size;
|
p_end = p_start + p_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*virtual
|
/*virtual
|
||||||
void remove(const value_type& value)
|
void remove(const value_type& value)
|
||||||
{
|
{
|
||||||
@ -418,4 +419,9 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Aliases
|
||||||
|
|
||||||
|
template <typename Type>
|
||||||
|
using darray = DynamicArray<Type>;
|
||||||
|
|
||||||
}
|
}
|
@ -248,4 +248,9 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Aliases
|
||||||
|
|
||||||
|
template <typename Type, size_t Size>
|
||||||
|
using sarray = StaticArray<Type, Size>;
|
||||||
|
|
||||||
}
|
}
|
37
source/hpr/containers/tests/containers-test.cpp
Normal file
37
source/hpr/containers/tests/containers-test.cpp
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "../array.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
TEST(containers, StaticArray)
|
||||||
|
{
|
||||||
|
hpr::StaticArray<float, 3> arr {1, 3, 2};
|
||||||
|
hpr::StaticArray<float, 4> sarr {arr, 5};
|
||||||
|
hpr::StaticArray<float, 4> sarr2 {1, 3, 2, 5};
|
||||||
|
EXPECT_EQ(sarr, sarr2);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(containers, DynamicArray)
|
||||||
|
{
|
||||||
|
hpr::DynamicArray<float> arr {1, 3, 2};
|
||||||
|
hpr::DynamicArray<float> arr2 {1, 3, 2};
|
||||||
|
EXPECT_EQ(arr, arr2);
|
||||||
|
arr.remove(1);
|
||||||
|
EXPECT_EQ(arr, hpr::darray<float>({1, 2}));
|
||||||
|
auto iter = arr2.begin();
|
||||||
|
++iter;
|
||||||
|
arr2.remove(iter);
|
||||||
|
EXPECT_EQ(arr2, hpr::darray<float>({1, 2}));
|
||||||
|
|
||||||
|
hpr::DynamicArray<float> arr3 {1, 3, 0, 2, 9, 0, 5};
|
||||||
|
arr3.remove([](float num) { return num == 0; });
|
||||||
|
EXPECT_EQ(arr3, hpr::darray<float>({1, 3, 2, 9, 5}));
|
||||||
|
EXPECT_EQ(arr3.size(), 5);
|
||||||
|
|
||||||
|
hpr::DynamicArray<float*> arr4;
|
||||||
|
arr4.push(new float(5));
|
||||||
|
arr4.push(new float(7));
|
||||||
|
arr4.push(new float(9));
|
||||||
|
EXPECT_EQ(*arr4[0], 5.f);
|
||||||
|
EXPECT_EQ(*arr4[2], 9.f);
|
||||||
|
}
|
12
source/hpr/csg.hpp
Normal file
12
source/hpr/csg.hpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "csg/shape.hpp"
|
||||||
|
#include "csg/vertex.hpp"
|
||||||
|
#include "csg/edge.hpp"
|
||||||
|
#include "csg/wire.hpp"
|
||||||
|
#include "csg/face.hpp"
|
||||||
|
#include "csg/shell.hpp"
|
||||||
|
#include "csg/solid.hpp"
|
||||||
|
#include "csg/compound.hpp"
|
||||||
|
#include "csg/geometry.hpp"
|
||||||
|
#include "csg/surface.hpp"
|
35
source/hpr/csg/CMakeLists.txt
Normal file
35
source/hpr/csg/CMakeLists.txt
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
|
||||||
|
set(COMPONENT_NAME csg)
|
||||||
|
|
||||||
|
add_component_library(${COMPONENT_NAME} STATIC
|
||||||
|
shape.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
#target_sources(${COMPONENT_NAME} PUBLIC
|
||||||
|
|
||||||
|
#)
|
||||||
|
|
||||||
|
target_link_libraries(${COMPONENT_NAME}
|
||||||
|
${OCCT_LIBRARIES}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(${COMPONENT_NAME}
|
||||||
|
PUBLIC
|
||||||
|
${OCCT_INCLUDE_DIRS}
|
||||||
|
)
|
||||||
|
|
||||||
|
install_component_headers(${COMPONENT_NAME})
|
||||||
|
install_component_source(${COMPONENT_NAME})
|
||||||
|
|
||||||
|
if (0)
|
||||||
|
add_executable(${COMPONENT_NAME}-test
|
||||||
|
tests/${COMPONENT_NAME}-test.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(${COMPONENT_NAME}-test
|
||||||
|
${PROJECT_NAME}::${COMPONENT_NAME}
|
||||||
|
GTest::gtest_main
|
||||||
|
)
|
||||||
|
|
||||||
|
gtest_add_tests(TARGET ${COMPONENT_NAME}-test)
|
||||||
|
endif()
|
@ -1,7 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../hyplib/scalar/scalar.hpp"
|
#include "../containers/array.hpp"
|
||||||
#include "../hyplib/vector/vector.hpp"
|
#include "../math/scalar.hpp"
|
||||||
|
#include "../math/vector.hpp"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
@ -1,5 +1,5 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include "../csg.hpp"
|
#include "../../csg.hpp"
|
||||||
|
|
||||||
TEST(csgTest, Shape)
|
TEST(csgTest, Shape)
|
||||||
{
|
{
|
15
source/hpr/gpu.hpp
Normal file
15
source/hpr/gpu.hpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "gpu/context.hpp"
|
||||||
|
#include "gpu/shader.hpp"
|
||||||
|
#include "gpu/shader_program.hpp"
|
||||||
|
#include "gpu/buffer.hpp"
|
||||||
|
#include "gpu/device.hpp"
|
||||||
|
#include "gpu/texture.hpp"
|
||||||
|
|
||||||
|
#include "gpu/opengl/context.hpp"
|
||||||
|
#include "gpu/opengl/shader.hpp"
|
||||||
|
#include "gpu/opengl/shader_program.hpp"
|
||||||
|
#include "gpu/opengl/buffer.hpp"
|
||||||
|
#include "gpu/opengl/device.hpp"
|
||||||
|
#include "gpu/opengl/texture.hpp"
|
42
source/hpr/gpu/CMakeLists.txt
Normal file
42
source/hpr/gpu/CMakeLists.txt
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
|
||||||
|
set(COMPONENT_NAME gpu)
|
||||||
|
|
||||||
|
add_component_library(${COMPONENT_NAME} STATIC
|
||||||
|
buffer.cpp
|
||||||
|
context.cpp
|
||||||
|
device.cpp
|
||||||
|
shader.cpp
|
||||||
|
shader_program.cpp
|
||||||
|
texture.cpp
|
||||||
|
opengl/buffer.cpp
|
||||||
|
opengl/context.cpp
|
||||||
|
opengl/device.cpp
|
||||||
|
opengl/shader.cpp
|
||||||
|
opengl/shader_program.cpp
|
||||||
|
opengl/texture.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
#target_sources(${COMPONENT_NAME} PUBLIC
|
||||||
|
|
||||||
|
#)
|
||||||
|
|
||||||
|
target_link_libraries(${COMPONENT_NAME}
|
||||||
|
glad
|
||||||
|
stb
|
||||||
|
)
|
||||||
|
|
||||||
|
install_component_headers(${COMPONENT_NAME})
|
||||||
|
install_component_source(${COMPONENT_NAME})
|
||||||
|
|
||||||
|
if (0)
|
||||||
|
add_executable(${COMPONENT_NAME}-test
|
||||||
|
tests/${COMPONENT_NAME}-test.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(${COMPONENT_NAME}-test
|
||||||
|
${PROJECT_NAME}::${COMPONENT_NAME}
|
||||||
|
GTest::gtest_main
|
||||||
|
)
|
||||||
|
|
||||||
|
gtest_add_tests(TARGET ${COMPONENT_NAME}-test)
|
||||||
|
endif()
|
@ -7,7 +7,7 @@
|
|||||||
#include "texture.hpp"
|
#include "texture.hpp"
|
||||||
#include "render_target.hpp"
|
#include "render_target.hpp"
|
||||||
|
|
||||||
#include "../hyplib/array/array.hpp"
|
#include "../containers/array.hpp"
|
||||||
|
|
||||||
#include "../window_system/window_system.hpp"
|
#include "../window_system/window_system.hpp"
|
||||||
|
|
@ -6,7 +6,7 @@
|
|||||||
#include "texture.hpp"
|
#include "texture.hpp"
|
||||||
#include "render_target.hpp"
|
#include "render_target.hpp"
|
||||||
|
|
||||||
#include "io/io.hpp"
|
#include "../../io/file.hpp"
|
||||||
|
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
@ -121,7 +121,7 @@ void Device::createFramebufferRenderTarget(gpu::RenderTarget** target, int width
|
|||||||
*target = newTarget;
|
*target = newTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::createSubRenderTarget(gpu::RenderTarget** target, RenderTarget* parent, int x, int y, int width, int height)
|
void Device::createSubRenderTarget(gpu::RenderTarget** target, gpu::RenderTarget* parent, int x, int y, int width, int height)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
@ -49,30 +49,48 @@ public:
|
|||||||
|
|
||||||
// Buffers
|
// Buffers
|
||||||
|
|
||||||
void createVertexBuffer(Buffer **buffer, int size, char* data) override;
|
virtual
|
||||||
void createIndexBuffer(Buffer **buffer, int size, char* data) override;
|
void createVertexBuffer(Buffer **buffer, int size, char* data);
|
||||||
void createUniformBuffer(Buffer **buffer, int size, char* data) override;
|
virtual
|
||||||
void useVertexBuffer(Buffer* buffer, int stride, int offset) override;
|
void createIndexBuffer(Buffer **buffer, int size, char* data);
|
||||||
void useIndexBuffer(Buffer* buffer, int offset) override;
|
virtual
|
||||||
void useUniformBuffer(Buffer* buffer, int slot) override;
|
void createUniformBuffer(Buffer **buffer, int size, char* data);
|
||||||
void editBuffer(Buffer* buffer, char* data, int size, int offset) override;
|
virtual
|
||||||
void editBuffer(Buffer* buffer, char* data) override;
|
void useVertexBuffer(Buffer* buffer, int stride, int offset);
|
||||||
void destroyBuffer(Buffer*& buffer) override;
|
virtual
|
||||||
|
void useIndexBuffer(Buffer* buffer, int offset);
|
||||||
|
virtual
|
||||||
|
void useUniformBuffer(Buffer* buffer, int slot);
|
||||||
|
virtual
|
||||||
|
void editBuffer(Buffer* buffer, char* data, int size, int offset);
|
||||||
|
virtual
|
||||||
|
void editBuffer(Buffer* buffer, char* data);
|
||||||
|
virtual
|
||||||
|
void destroyBuffer(Buffer*& buffer);
|
||||||
|
|
||||||
// Shaders
|
// Shaders
|
||||||
|
|
||||||
void createVertexShader(Shader** shader, const std::string& filename, const std::string& label) override;
|
virtual
|
||||||
void createFragmentShader(Shader** shader, const std::string& filename, const std::string& label) override;
|
void createVertexShader(Shader** shader, const std::string& filename, const std::string& label);
|
||||||
void createGeometryShader(Shader** shader, const std::string& filename, const std::string& label) override;
|
virtual
|
||||||
void destroyShader(Shader* shader) override;
|
void createFragmentShader(Shader** shader, const std::string& filename, const std::string& label);
|
||||||
|
virtual
|
||||||
|
void createGeometryShader(Shader** shader, const std::string& filename, const std::string& label);
|
||||||
|
virtual
|
||||||
|
void destroyShader(Shader* shader);
|
||||||
|
|
||||||
// Shader programs
|
// Shader programs
|
||||||
|
|
||||||
void createShaderProgram(ShaderProgram** program) override;
|
virtual
|
||||||
void attachShader(ShaderProgram* program, Shader* shader) override;
|
void createShaderProgram(ShaderProgram** program);
|
||||||
void linkProgram(ShaderProgram* program) override;
|
virtual
|
||||||
void useShaderProgram(ShaderProgram* program) override;
|
void attachShader(ShaderProgram* program, Shader* shader);
|
||||||
void destroyShaderProgram(ShaderProgram*& program, bool withShaders) override;
|
virtual
|
||||||
|
void linkProgram(ShaderProgram* program);
|
||||||
|
virtual
|
||||||
|
void useShaderProgram(ShaderProgram* program);
|
||||||
|
virtual
|
||||||
|
void destroyShaderProgram(ShaderProgram*& program, bool withShaders);
|
||||||
|
|
||||||
// Textures
|
// Textures
|
||||||
|
|
@ -3,7 +3,7 @@
|
|||||||
#include "context.hpp"
|
#include "context.hpp"
|
||||||
#include "shader.hpp"
|
#include "shader.hpp"
|
||||||
|
|
||||||
#include "../hyplib/array/array.hpp"
|
#include "../containers/array.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace hpr::gpu
|
namespace hpr::gpu
|
1
source/hpr/hpr.cpp
Normal file
1
source/hpr/hpr.cpp
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "hpr.hpp"
|
49
source/hpr/hpr.hpp
Normal file
49
source/hpr/hpr.hpp
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
namespace hpr
|
||||||
|
{
|
||||||
|
/* Core */
|
||||||
|
// containers
|
||||||
|
// math
|
||||||
|
// io
|
||||||
|
|
||||||
|
/* Graphics */
|
||||||
|
namespace gpu
|
||||||
|
{
|
||||||
|
// gpu
|
||||||
|
// window_system
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Mesh */
|
||||||
|
namespace mesh
|
||||||
|
{
|
||||||
|
// mesh
|
||||||
|
}
|
||||||
|
|
||||||
|
/* CSG */
|
||||||
|
namespace csg
|
||||||
|
{
|
||||||
|
// csg
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "containers.hpp"
|
||||||
|
#include "math.hpp"
|
||||||
|
#include "io.hpp"
|
||||||
|
|
||||||
|
#if WITH_GPU
|
||||||
|
#include "gpu.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if WITH_WS
|
||||||
|
#include "window_system.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if WITH_MESH
|
||||||
|
#include "mesh.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if WITH_CSG
|
||||||
|
#include "csg.hpp"
|
||||||
|
#endif
|
3
source/hpr/io.hpp
Normal file
3
source/hpr/io.hpp
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "io/file.hpp"
|
27
source/hpr/io/CMakeLists.txt
Normal file
27
source/hpr/io/CMakeLists.txt
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
|
||||||
|
set(COMPONENT_NAME io)
|
||||||
|
|
||||||
|
add_component_library(${COMPONENT_NAME} STATIC
|
||||||
|
file.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
#target_sources(${COMPONENT_NAME} PUBLIC
|
||||||
|
# file.hpp
|
||||||
|
# logger.hpp
|
||||||
|
#)
|
||||||
|
|
||||||
|
install_component_headers(${COMPONENT_NAME})
|
||||||
|
install_component_source(${COMPONENT_NAME})
|
||||||
|
|
||||||
|
if(0)
|
||||||
|
add_executable(${COMPONENT_NAME}-test
|
||||||
|
tests/${COMPONENT_NAME}-test.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(${COMPONENT_NAME}-test
|
||||||
|
${CMAKE_PROJECT_NAME}::${COMPONENT_NAME}
|
||||||
|
GTest::gtest_main
|
||||||
|
)
|
||||||
|
|
||||||
|
gtest_add_tests(TARGET ${COMPONENT_NAME}-test)
|
||||||
|
endif()
|
5
source/hpr/math.hpp
Normal file
5
source/hpr/math.hpp
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "math/scalar.hpp"
|
||||||
|
#include "math/vector.hpp"
|
||||||
|
#include "math/matrix.hpp"
|
34
source/hpr/math/CMakeLists.txt
Normal file
34
source/hpr/math/CMakeLists.txt
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
|
||||||
|
set(COMPONENT_NAME math)
|
||||||
|
|
||||||
|
add_component_library(${COMPONENT_NAME} STATIC
|
||||||
|
vector/vector_space.cpp
|
||||||
|
matrix/matrix_space.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
#target_sources(${COMPONENT_NAME} PUBLIC
|
||||||
|
# matrix/clip_space.hpp
|
||||||
|
# matrix.hpp
|
||||||
|
# matrix/matrix_space.hpp
|
||||||
|
# matrix/transform.hpp
|
||||||
|
# scalar.hpp
|
||||||
|
# scalar/scalar.hpp
|
||||||
|
# vector.hpp
|
||||||
|
# vector/vector_space.hpp
|
||||||
|
#)
|
||||||
|
|
||||||
|
install_component_headers(${COMPONENT_NAME})
|
||||||
|
install_component_source(${COMPONENT_NAME})
|
||||||
|
|
||||||
|
if(WITH_GTESTS)
|
||||||
|
add_executable(${COMPONENT_NAME}-test
|
||||||
|
tests/${COMPONENT_NAME}-test.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(${COMPONENT_NAME}-test
|
||||||
|
${PROJECT_NAME}::${COMPONENT_NAME}
|
||||||
|
GTest::gtest_main
|
||||||
|
)
|
||||||
|
|
||||||
|
gtest_add_tests(TARGET ${COMPONENT_NAME}-test)
|
||||||
|
endif()
|
5
source/hpr/math/matrix.hpp
Normal file
5
source/hpr/math/matrix.hpp
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "matrix/matrix_space.hpp"
|
||||||
|
#include "matrix/transform.hpp"
|
||||||
|
#include "matrix/clip_space.hpp"
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "matrix.hpp"
|
#include "../matrix.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace hpr
|
namespace hpr
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../vector/vector.hpp"
|
#include "../vector.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace hpr
|
namespace hpr
|
||||||
{
|
{
|
||||||
@ -20,6 +21,7 @@ public:
|
|||||||
using pointer = Type*;
|
using pointer = Type*;
|
||||||
using reference = Type&;
|
using reference = Type&;
|
||||||
using iterator = Iterator<Type>;
|
using iterator = Iterator<Type>;
|
||||||
|
using const_reference = Type const&;
|
||||||
using const_iterator = Iterator<const Type>;
|
using const_iterator = Iterator<const Type>;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -47,7 +49,7 @@ public:
|
|||||||
p_cols {Cols}
|
p_cols {Cols}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
inline
|
inline explicit
|
||||||
MatrixSpace(const base& ms) :
|
MatrixSpace(const base& ms) :
|
||||||
base {ms},
|
base {ms},
|
||||||
p_rows {Rows},
|
p_rows {Rows},
|
||||||
@ -61,6 +63,13 @@ public:
|
|||||||
p_cols {Cols}
|
p_cols {Cols}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
inline
|
||||||
|
MatrixSpace& operator=(const MatrixSpace& ms)
|
||||||
|
{
|
||||||
|
base::operator=(ms);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
MatrixSpace(typename base::iterator start, typename base::iterator end) :
|
MatrixSpace(typename base::iterator start, typename base::iterator end) :
|
||||||
base {start, end},
|
base {start, end},
|
||||||
@ -104,6 +113,16 @@ public:
|
|||||||
return (*this)[col + p_rows * row];
|
return (*this)[col + p_rows * row];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
const_reference operator()(size_type row, size_type col) const
|
||||||
|
{
|
||||||
|
if (row >= p_rows || std::numeric_limits<size_type>::max() - p_rows < row)
|
||||||
|
throw std::out_of_range("Row index is out of range");
|
||||||
|
if (col >= p_cols || std::numeric_limits<size_type>::max() - p_cols < col)
|
||||||
|
throw std::out_of_range("Column index is out of range");
|
||||||
|
return (*this)[col + p_rows * row];
|
||||||
|
}
|
||||||
|
|
||||||
VectorSpace<value_type, Cols> row(size_type row)
|
VectorSpace<value_type, Cols> row(size_type row)
|
||||||
{
|
{
|
||||||
VectorSpace<value_type, Cols> vs;
|
VectorSpace<value_type, Cols> vs;
|
||||||
@ -112,6 +131,14 @@ public:
|
|||||||
return vs;
|
return vs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VectorSpace<value_type, Cols> row(size_type row) const
|
||||||
|
{
|
||||||
|
VectorSpace<value_type, Cols> vs;
|
||||||
|
for (auto n = 0; n < Cols; ++n)
|
||||||
|
vs[n] = (*this)(row, n);
|
||||||
|
return vs;
|
||||||
|
}
|
||||||
|
|
||||||
void row(size_type row, const VectorSpace<value_type, Cols>& vs)
|
void row(size_type row, const VectorSpace<value_type, Cols>& vs)
|
||||||
{
|
{
|
||||||
for (auto n = 0; n < Cols; ++n)
|
for (auto n = 0; n < Cols; ++n)
|
||||||
@ -198,7 +225,7 @@ public:
|
|||||||
inline
|
inline
|
||||||
MatrixSpace inv()
|
MatrixSpace inv()
|
||||||
{
|
{
|
||||||
return adj() / det();
|
return MatrixSpace(adj() / det());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Friend functions
|
// Friend functions
|
||||||
@ -225,6 +252,12 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
friend inline
|
||||||
|
VectorSpace<Type, Rows> operator*(const VectorSpace<Type, Rows>& vs, const MatrixSpace& ms)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
MatrixSpace& fill(value_type value)
|
MatrixSpace& fill(value_type value)
|
||||||
{
|
{
|
||||||
for (auto n = 0; n < this->size(); ++n)
|
for (auto n = 0; n < this->size(); ++n)
|
||||||
@ -245,5 +278,13 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Aliases
|
||||||
|
|
||||||
|
template <typename Type, size_t Row, size_t Col>
|
||||||
|
using mat = MatrixSpace<Type, Row, Col>;
|
||||||
|
|
||||||
|
using mat2 = MatrixSpace<scalar, 2, 2>;
|
||||||
|
using mat3 = MatrixSpace<scalar, 3, 3>;
|
||||||
|
using mat4 = MatrixSpace<scalar, 4, 4>;
|
||||||
|
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "matrix.hpp"
|
#include "../matrix.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace hpr
|
namespace hpr
|
||||||
@ -11,40 +11,62 @@ inline
|
|||||||
mat<Type, 4, 4> translate(const mat<Type, 4, 4>& ms, const vec<Type, 3>& vs)
|
mat<Type, 4, 4> translate(const mat<Type, 4, 4>& ms, const vec<Type, 3>& vs)
|
||||||
{
|
{
|
||||||
mat<Type, 4, 4> res {ms};
|
mat<Type, 4, 4> res {ms};
|
||||||
res.row(3, ms.row(0) * vs[0] + ms.row(1) * vs[1] + ms.row(2) * vs[2] + ms.row(3));
|
res.col(3, ms.row(0) * vs[0] + ms.row(1) * vs[1] + ms.row(2) * vs[2] + ms.row(3));
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Type>
|
||||||
|
inline
|
||||||
|
vec<Type, 3> translate(const vec<Type, 3>& vs1, const vec<Type, 3>& vs2)
|
||||||
|
{
|
||||||
|
mat<Type, 4, 4> res = mat<Type, 4, 4>::identity();
|
||||||
|
res.row(3, vec<Type, 4>(vs1, 0.));
|
||||||
|
res = translate(res, vs2);
|
||||||
|
|
||||||
|
return vec<Type, 3>(res.row(3));
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
inline
|
inline
|
||||||
mat<Type, 4, 4> rotate(const mat<Type, 4, 4>& ms, const vec<Type, 3>& vs, Type angle)
|
mat<Type, 4, 4> rotate(const mat<Type, 4, 4>& ms, const vec<Type, 3>& vs, Type angle)
|
||||||
{
|
{
|
||||||
const Type cos {cos(angle)};
|
const Type cosv = cos(angle);
|
||||||
const Type sin {sin(angle)};
|
const Type sinv = sin(angle);
|
||||||
vec<Type, 3> axis {normalize(vs)};
|
vec<Type, 3> axis {normalize(vs)};
|
||||||
vec<Type, 3> temp {(1. - cos) * axis};
|
vec<Type, 3> temp {(1. - cosv) * axis};
|
||||||
|
|
||||||
mat<Type, 4, 4> rot;
|
mat<Type, 4, 4> rot;
|
||||||
rot(0, 0) = cos + temp[0] * axis[0];
|
rot(0, 0) = cosv + temp[0] * axis[0];
|
||||||
rot(0, 1) = temp[0] * axis[1] + sin * axis[2];
|
rot(0, 1) = temp[0] * axis[1] + sinv * axis[2];
|
||||||
rot(0, 2) = temp[0] * axis[2] - sin * axis[1];
|
rot(0, 2) = temp[0] * axis[2] - sinv * axis[1];
|
||||||
rot(1, 0) = temp[1] * axis[0] - sin * axis[2];
|
rot(1, 0) = temp[1] * axis[0] - sinv * axis[2];
|
||||||
rot(1, 1) = cos + temp[1] * axis[1];
|
rot(1, 1) = cosv + temp[1] * axis[1];
|
||||||
rot(1, 2) = temp[1] * axis[2] + sin * axis[0];
|
rot(1, 2) = temp[1] * axis[2] + sinv * axis[0];
|
||||||
rot(2, 0) = temp[2] * axis[0] + sin * axis[1];
|
rot(2, 0) = temp[2] * axis[0] + sinv * axis[1];
|
||||||
rot(2, 1) = temp[2] * axis[1] - sin * axis[0];
|
rot(2, 1) = temp[2] * axis[1] - sinv * axis[0];
|
||||||
rot(2, 2) = cos + temp[2] * axis[2];
|
rot(2, 2) = cosv + temp[2] * axis[2];
|
||||||
|
|
||||||
mat<Type, 4, 4> res {ms};
|
mat<Type, 4, 4> res {ms};
|
||||||
res.row(0, ms.row(0) * rot(0, 0) + ms.row(1) * rot(0, 1) + ms.row(2) * rot(0, 2));
|
res.row(0, ms.row(0) * rot(0, 0) + ms.row(1) * rot(0, 1) + ms.row(2) * rot(0, 2));
|
||||||
res.row(0, ms.row(0) * rot(1, 0) + ms.row(1) * rot(1, 1) + ms.row(2) * rot(1, 2));
|
res.row(1, ms.row(0) * rot(1, 0) + ms.row(1) * rot(1, 1) + ms.row(2) * rot(1, 2));
|
||||||
res.row(0, ms.row(0) * rot(2, 0) + ms.row(1) * rot(2, 1) + ms.row(2) * rot(2, 2));
|
res.row(2, ms.row(0) * rot(2, 0) + ms.row(1) * rot(2, 1) + ms.row(2) * rot(2, 2));
|
||||||
res.row(3, ms.row(3));
|
res.row(3, ms.row(3));
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Type>
|
||||||
|
inline
|
||||||
|
vec<Type, 3> rotate(const vec<Type, 3>& vs1, const vec<Type, 3>& vs2, Type angle)
|
||||||
|
{
|
||||||
|
mat<Type, 4, 4> res = mat<Type, 4, 4>::identity();
|
||||||
|
res.row(3, vec<Type, 4>(vs1, 0.));
|
||||||
|
res = rotate(res, vs2, angle);
|
||||||
|
|
||||||
|
return vec<Type, 3>(res.row(3));
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
inline
|
inline
|
||||||
mat<Type, 4, 4> scale(const mat<Type, 4, 4>& ms, const vec<Type, 3>& vs)
|
mat<Type, 4, 4> scale(const mat<Type, 4, 4>& ms, const vec<Type, 3>& vs)
|
3
source/hpr/math/scalar.hpp
Normal file
3
source/hpr/math/scalar.hpp
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "scalar/scalar.hpp"
|
47
source/hpr/math/tests/math-test.cpp
Normal file
47
source/hpr/math/tests/math-test.cpp
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "../vector.hpp"
|
||||||
|
#include "../matrix.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
TEST(math, Vector)
|
||||||
|
{
|
||||||
|
hpr::vec3 v1 {1, 3, 2};
|
||||||
|
hpr::vec3 v2 {5, 7, -1};
|
||||||
|
hpr::vec2 v31 {13, -2};
|
||||||
|
hpr::vec3 v32 {v31, 9};
|
||||||
|
EXPECT_EQ((hpr::vec3(v2.begin(), v2.end())), v2);
|
||||||
|
EXPECT_EQ(v32, hpr::vec3(13, -2, 9));
|
||||||
|
EXPECT_EQ(-v1, hpr::vec3(-1, -3, -2));
|
||||||
|
EXPECT_EQ(v1 + v2, hpr::vec3(6, 10, 1));
|
||||||
|
EXPECT_EQ(v1 - v2, hpr::vec3(-4, -4, 3));
|
||||||
|
EXPECT_EQ((hpr::dot(v1, v2) ), 24);
|
||||||
|
EXPECT_EQ((hpr::cross(hpr::vec3(1, 0, 0), hpr::vec3(0, 1, 0))), hpr::vec3(0, 0, 1));
|
||||||
|
EXPECT_EQ((hpr::angle(hpr::vec3(1, 0, 0), hpr::vec3(0, 0, 1))), hpr::PI * 0.5);
|
||||||
|
EXPECT_EQ((hpr::normalize(hpr::vec3(1, 1, 1))), hpr::vec3(0.5773502691896258, 0.5773502691896258, 0.5773502691896258));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(math, Matrix)
|
||||||
|
{
|
||||||
|
hpr::mat2 m1;
|
||||||
|
hpr::vec4 v1;
|
||||||
|
EXPECT_FALSE(v1 == m1);
|
||||||
|
hpr::mat2 m2 {3, 2, 7, 4};
|
||||||
|
hpr::vec2 v2 {2, 4};
|
||||||
|
EXPECT_EQ(m2.col(1), v2);
|
||||||
|
hpr::vec2 v3 {13, 51};
|
||||||
|
m2.col(1, v3);
|
||||||
|
EXPECT_EQ(m2.col(1), v3);
|
||||||
|
hpr::mat3 m4 {1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||||
|
hpr::mat2 m41 {5, 6, 8, 9};
|
||||||
|
EXPECT_EQ(m41.minor(0, 0), 9);
|
||||||
|
hpr::mat2 m5 {1, 2, 3, 4};
|
||||||
|
|
||||||
|
EXPECT_EQ((m4.det()), 0);
|
||||||
|
EXPECT_EQ(hpr::mat3(-9, 23, 3, 5, 5, 6, 7, -3, 9).det(), -786);
|
||||||
|
|
||||||
|
hpr::mat2 m6 {2, 1, 7, 4};
|
||||||
|
EXPECT_EQ(m6.inv(), hpr::mat2(4, -1, -7, 2));
|
||||||
|
EXPECT_EQ(hpr::mat3(1, 0, 0, 0, 1, 0, 0, 0, 1).det(), 1.);
|
||||||
|
//EXPECT_EQ(m4.det(), 0);
|
||||||
|
}
|
4
source/hpr/math/vector.hpp
Normal file
4
source/hpr/math/vector.hpp
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "vector/vector_space.hpp"
|
||||||
|
|
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../scalar/scalar.hpp"
|
#include "../scalar.hpp"
|
||||||
#include "../array/array.hpp"
|
#include "../../containers/array/static_array.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace hpr
|
namespace hpr
|
||||||
@ -106,6 +106,14 @@ public:
|
|||||||
(*this)[subvs.size()] = v;
|
(*this)[subvs.size()] = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <size_type BiggerSize>
|
||||||
|
inline
|
||||||
|
VectorSpace(const VectorSpace<Type, BiggerSize>& vs) :
|
||||||
|
base {vs.begin(), vs.begin() + Size}
|
||||||
|
{
|
||||||
|
static_assert(BiggerSize > Size, "Size should be bigger");
|
||||||
|
}
|
||||||
|
|
||||||
// Member functions
|
// Member functions
|
||||||
|
|
||||||
// vector versus scalar (per element operations)
|
// vector versus scalar (per element operations)
|
||||||
@ -390,4 +398,13 @@ bool all(const VectorSpace<bool, Size>& vs)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Aliases
|
||||||
|
|
||||||
|
template <typename Type, size_t Size>
|
||||||
|
using vec = VectorSpace<Type, Size>;
|
||||||
|
|
||||||
|
using vec2 = VectorSpace<scalar, 2>;
|
||||||
|
using vec3 = VectorSpace<scalar, 3>;
|
||||||
|
using vec4 = VectorSpace<scalar, 4>;
|
||||||
|
|
||||||
}
|
}
|
3
source/hpr/mesh.hpp
Normal file
3
source/hpr/mesh.hpp
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "mesh/mesh.hpp"
|
26
source/hpr/mesh/CMakeLists.txt
Normal file
26
source/hpr/mesh/CMakeLists.txt
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
|
||||||
|
set(COMPONENT_NAME mesh)
|
||||||
|
|
||||||
|
add_component_library(${COMPONENT_NAME} STATIC
|
||||||
|
mesh.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
#target_sources(${COMPONENT_NAME} PUBLIC
|
||||||
|
|
||||||
|
#)
|
||||||
|
|
||||||
|
install_component_headers(${COMPONENT_NAME})
|
||||||
|
install_component_source(${COMPONENT_NAME})
|
||||||
|
|
||||||
|
if (0)
|
||||||
|
add_executable(${COMPONENT_NAME}-test
|
||||||
|
tests/${COMPONENT_NAME}-test.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(${COMPONENT_NAME}-test
|
||||||
|
${PROJECT_NAME}::${COMPONENT_NAME}
|
||||||
|
GTest::gtest_main
|
||||||
|
)
|
||||||
|
|
||||||
|
gtest_add_tests(TARGET ${COMPONENT_NAME}-test)
|
||||||
|
endif()
|
@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../hyplib/scalar/scalar.hpp"
|
#include "../containers/array.hpp"
|
||||||
#include "../hyplib/array/array.hpp"
|
#include "../math/scalar/scalar.hpp"
|
||||||
#include "../hyplib/vector/vector.hpp"
|
#include "../math/vector.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace hpr::mesh
|
namespace hpr::mesh
|
@ -1,8 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../hyplib/scalar/scalar.hpp"
|
#include "../containers/array.hpp"
|
||||||
#include "../hyplib/array/array.hpp"
|
#include "../math/scalar/scalar.hpp"
|
||||||
#include "../hyplib/vector/vector.hpp"
|
#include "../math/vector.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace hpr::mesh
|
namespace hpr::mesh
|
@ -1,8 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../hyplib/scalar/scalar.hpp"
|
#include "../containers/array.hpp"
|
||||||
#include "../hyplib/array/array.hpp"
|
#include "../math/scalar/scalar.hpp"
|
||||||
#include "../hyplib/vector/vector.hpp"
|
#include "../math/vector.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace hpr::mesh
|
namespace hpr::mesh
|
@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../hyplib/scalar/scalar.hpp"
|
#include "../containers/array.hpp"
|
||||||
#include "../hyplib/array/array.hpp"
|
#include "../math/scalar/scalar.hpp"
|
||||||
#include "../hyplib/vector/vector.hpp"
|
#include "../math/vector.hpp"
|
||||||
|
|
||||||
#include "vertex.hpp"
|
#include "vertex.hpp"
|
||||||
#include "edge.hpp"
|
#include "edge.hpp"
|
@ -1,8 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../hyplib/scalar/scalar.hpp"
|
#include "../containers/array.hpp"
|
||||||
#include "../hyplib/array/array.hpp"
|
#include "../math/scalar/scalar.hpp"
|
||||||
#include "../hyplib/vector/vector.hpp"
|
#include "../math/vector.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace hpr::mesh
|
namespace hpr::mesh
|
11
source/hpr/window_system.hpp
Normal file
11
source/hpr/window_system.hpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
#include "window_system/monitor.hpp"
|
||||||
|
#include "window_system/window_context.hpp"
|
||||||
|
#include "window_system/window.hpp"
|
||||||
|
#include "window_system/window_system.hpp"
|
||||||
|
|
||||||
|
#include "window_system/glfw/monitor.hpp"
|
||||||
|
#include "window_system/glfw/window.hpp"
|
||||||
|
#include "window_system/glfw/window_system.hpp"
|
35
source/hpr/window_system/CMakeLists.txt
Normal file
35
source/hpr/window_system/CMakeLists.txt
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
|
||||||
|
set(COMPONENT_NAME window_system)
|
||||||
|
|
||||||
|
add_component_library(${COMPONENT_NAME} OBJECT
|
||||||
|
window_system.cpp
|
||||||
|
monitor.cpp
|
||||||
|
window.cpp
|
||||||
|
glfw/window_system.cpp
|
||||||
|
glfw/monitor.cpp
|
||||||
|
glfw/window.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
#target_sources(${COMPONENT_NAME} PUBLIC
|
||||||
|
|
||||||
|
#)
|
||||||
|
|
||||||
|
target_link_libraries(${COMPONENT_NAME}
|
||||||
|
glfw
|
||||||
|
)
|
||||||
|
|
||||||
|
install_component_headers(${COMPONENT_NAME})
|
||||||
|
install_component_source(${COMPONENT_NAME})
|
||||||
|
|
||||||
|
if (0)
|
||||||
|
add_executable(${COMPONENT_NAME}-test
|
||||||
|
tests/${COMPONENT_NAME}-test.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(${COMPONENT_NAME}-test
|
||||||
|
${PROJECT_NAME}::${COMPONENT_NAME}
|
||||||
|
GTest::gtest_main
|
||||||
|
)
|
||||||
|
|
||||||
|
gtest_add_tests(TARGET ${COMPONENT_NAME}-test)
|
||||||
|
endif()
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "../monitor.hpp"
|
#include "../monitor.hpp"
|
||||||
|
|
||||||
#include "GLFW/glfw3.h"
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
|
||||||
namespace hpr::gpu::glfw
|
namespace hpr::gpu::glfw
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user