Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
97ff44b
WIP
sebsjames Sep 16, 2025
9709db3
WIP: determines equivalent vertices
sebsjames Sep 17, 2025
6cd1ea0
Now I'm getting the edges
sebsjames Sep 17, 2025
7297f4d
WIP on the navigable mesh
sebsjames Sep 17, 2025
0745869
More work in progress
sebsjames Sep 17, 2025
1873b6d
a nearly working intersection algo
sebsjames Sep 19, 2025
df3ab93
Compensate for possibly anti-clockwise triangle vertices, to help wit…
sebsjames Sep 22, 2025
9eaa22b
Adds a draw_triangles example prog which demos intersection
sebsjames Sep 22, 2025
5dc8e2d
avoiding ifdefs
sebsjames Sep 22, 2025
7e6343c
In find_triangle_corssing, need bb in VisualModel frame, not scene frame
sebsjames Sep 22, 2025
e47b1fb
Getting ready to bundle triangle norm in triangles
sebsjames Sep 23, 2025
d3c6ffa
Bundles triangle normal up along with the indices
sebsjames Sep 23, 2025
ce4bf9b
static-casts
sebsjames Sep 23, 2025
3a2e9d6
Use structured binding
sebsjames Sep 23, 2025
6f7fbff
Trivial, collecting new includes together
sebsjames Sep 23, 2025
eb08fb1
Adds a function to get triangle vertices from indices
sebsjames Sep 24, 2025
e1c933e
Another function (get a triangle with two common indices)
sebsjames Sep 24, 2025
e98e3b3
Places VisualModel name into GLTF. Alss pre/postmult of viewmatrix in…
sebsjames Sep 25, 2025
5f53099
WIP
sebsjames Sep 25, 2025
2afc510
Completes the multi-coloured cube example
sebsjames Sep 25, 2025
371add7
Merge pull request #77 from sebsjames/dev/multicol_rhombo
sebsjames Sep 25, 2025
da56be4
Allow translations to be set with 4D vecs as well as 3D
sebsjames Sep 26, 2025
cc2190b
No longer feel the need to debug these normals
sebsjames Sep 30, 2025
6801f8f
New option for RodVisual
sebsjames Oct 2, 2025
1f3f57a
annotate cube
sebsjames Oct 3, 2025
5504eb2
Minor change to return object from ray_tri_intersection
sebsjames Oct 7, 2025
e2f376d
Adds a cube example to experiment with transform matrices
sebsjames Oct 9, 2025
d50a58d
Correct sequence (both Eigen and mat44) to 'get round the cube edge'
sebsjames Oct 9, 2025
3653b30
Minor - adds checks to tri_indices before using as indices
sebsjames Oct 9, 2025
eab3b38
Move and rename viewmatrix getter
sebsjames Oct 10, 2025
35064e6
A hack to raise a single corner of the Rhombo, was used for my debugging
sebsjames Oct 10, 2025
857ea9a
Adds optional negative axes and a size option for the sphere at the e…
sebsjames Oct 10, 2025
c792500
Another example, used to figure out matrix transforms (identified axi…
sebsjames Oct 10, 2025
017e87c
Oops, this needs to go in
sebsjames Oct 12, 2025
02e4c77
Detect Eigen3
sebsjames Oct 12, 2025
b521265
Removes an unfinished and unused function
sebsjames Oct 12, 2025
35e4fb4
Using maths from main
sebsjames Oct 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ include_directories(${PROJECT_SOURCE_DIR}/maths)
# Use packaged nlohmann json
find_package(nlohmann_json REQUIRED)

# For a test program (optional)
find_package (Eigen3 NO_MODULE)

# If Qt5 is present, then some optional Qt examples will be compiled
find_package(Qt5 QUIET COMPONENTS Gui Core Widgets)
if(Qt5_FOUND)
Expand Down
15 changes: 15 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ target_link_libraries(tri OpenGL::GL glfw Freetype::Freetype)
add_executable(draw_triangles draw_triangles.cpp)
target_link_libraries(draw_triangles OpenGL::GL glfw Freetype::Freetype)

add_executable(draw_triangles_intersections draw_triangles_intersections.cpp)
target_link_libraries(draw_triangles_intersections OpenGL::GL glfw Freetype::Freetype)

add_executable(voronoi_random voronoi_random.cpp)
target_link_libraries(voronoi_random OpenGL::GL glfw Freetype::Freetype)

Expand Down Expand Up @@ -413,6 +416,18 @@ target_link_libraries(rhombo_scene OpenGL::GL glfw Freetype::Freetype)
add_executable(rhombo_scene2 rhombo_scene2.cpp)
target_link_libraries(rhombo_scene2 OpenGL::GL glfw Freetype::Freetype)

add_executable(cube cube.cpp)
target_link_libraries(cube OpenGL::GL glfw Freetype::Freetype)

if(Eigen3_FOUND)
add_executable(cubetrans cubetrans.cpp)
target_include_directories (cubetrans BEFORE PRIVATE ${EIGEN3_INCLUDE_DIR})
target_link_libraries(cubetrans OpenGL::GL glfw Freetype::Freetype)
endif(Eigen3_FOUND)

add_executable(cubetrans2 cubetrans2.cpp)
target_link_libraries(cubetrans2 OpenGL::GL glfw Freetype::Freetype)

add_executable(quads quads.cpp)
target_link_libraries(quads OpenGL::GL glfw Freetype::Freetype)

Expand Down
34 changes: 34 additions & 0 deletions examples/cube.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Draw a cube with RhomboVisual

#include <sm/vec>
#include <mplot/compoundray/Visual.h>
#include <mplot/RhomboVisual.h>

int main()
{
// Create a scene
mplot::compoundray::Visual v(1024, 768, "A cube");
v.showCoordArrows (true);
v.lightingEffects();

// Parameters of the model
sm::vec<float, 3> offset = { 1, -0.5, -0.5 }; // a within-scene offset

sm::vec<float, 3> e1 = { 1, 0, 0 };
sm::vec<float, 3> e2 = { 0, 1, 0 };
sm::vec<float, 3> e3 = { 0, 0, 1 };

sm::vec<float, 3> colour1 = { 0.35, 0.76, 0.98 }; // RGB colour triplet

auto rv = std::make_unique<mplot::RhomboVisual<>> (offset, e1, e2, e3, colour1);
v.bindmodel (rv);
rv->name = "Cube.002";
rv->facecm = mplot::ColourMapType::Rainbow; // Try Rainbow, Batlow, Tofino
rv->annotate = true;
rv->finalize();
v.addVisualModel (rv);

v.keepOpen();

return 0;
}
189 changes: 189 additions & 0 deletions examples/cubetrans.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
// Draw a cube with RhomboVisual and then make up vectors to transform with mat44s

#include <iostream>

#include <sm/vec>
#include <sm/mat44>
#include <mplot/compoundray/Visual.h>
#include <mplot/RhomboVisual.h>
#include <mplot/VectorVisual.h>
#include <mplot/SphereVisual.h>

#include <Eigen/Dense>
#include <Eigen/Geometry>

int main()
{
// Create a scene
mplot::compoundray::Visual v(1024, 768, "A cube");
v.showCoordArrows (true);
v.coordArrowsInScene (true);
v.lightingEffects();

// Parameters of the model
sm::vec<float, 3> offset = { 0, 0, 0 }; // a within-scene offset

sm::vec<float, 3> e1 = { 1, 0, 0 };
sm::vec<float, 3> e2 = { 0, 1, 0 };
sm::vec<float, 3> e3 = { 0, 0, 1 };

sm::vec<float, 3> colour1 = { 0.35, 0.76, 0.98 }; // RGB colour triplet

auto rv = std::make_unique<mplot::RhomboVisual<>> (offset, e1, e2, e3, colour1);
v.bindmodel (rv);
rv->name = "Cube.002";
rv->facecm = mplot::ColourMapType::Rainbow; // Try Rainbow, Batlow, Tofino
rv->annotate = true;
rv->setAlpha (0.5f);
rv->finalize();

// Native locations/vectors
sm::vec<> l1 = { 0.8, 1, 0.5 }; // start location
sm::vec<> mv1 = { 0.2, 0, 0 }; // movement to edge
sm::vec<> mv2 = { 0.1, 0, 0 }; // movement past edge
sm::vec<> ra = { 0, 0, -1 }; // rotn axis
sm::vec<> d1_s = { 0, 0, 0 };
sm::vec<> d1_e = { 0.3, 0, 0 }; // Direction at l1 - our step length
sm::vec<> d1 = d1_e - d1_s;

auto rotang = sm::mathconst<float>::pi / 2;

// Eigen copies
Eigen::Vector3f el1 (l1[0], l1[1], l1[2]);
Eigen::Vector3f emv1 (mv1[0], mv1[1], mv1[2]);
Eigen::Vector3f emv2 (mv2[0], mv2[1], mv2[2]);
Eigen::Vector3f era (ra[0], ra[1], ra[2]);
Eigen::Vector3f ed1_s (d1_s[0], d1_s[1], d1_s[2]);
Eigen::Vector3f ed1_e (d1_e[0], d1_e[1], d1_e[2]);

// mat44 transformation
sm::mat44<float> m1t;
sm::mat44<float> m1tor;
sm::mat44<float> m1r;
sm::mat44<float> m1torb;
sm::mat44<float> m1t2;
// sequence:
m1t.translate (mv1);
m1tor.translate (-(l1 + mv1));
m1r.rotate (ra, rotang);
m1torb.translate (l1 + mv1);
m1t2.translate (m1r * mv2);
// Combine by multiplication:
sm::mat44<float> m1 = m1t2 * m1torb * m1r * m1tor * m1t;

// Eigen transformation
Eigen::Transform<float, 3, Eigen::TransformTraits::Affine> em1t;
Eigen::Transform<float, 3, Eigen::TransformTraits::Affine> em1tor;
Eigen::Transform<float, 3, Eigen::TransformTraits::Affine> em1r;
Eigen::Transform<float, 3, Eigen::TransformTraits::Affine> em1torb;
Eigen::Transform<float, 3, Eigen::TransformTraits::Affine> em1t2;
em1t.setIdentity();
em1tor.setIdentity();
em1r.setIdentity();
em1torb.setIdentity();
em1t2.setIdentity();
// sequence:
em1t.translate (emv1);
em1tor.translate (-(el1 + emv1));
em1r.rotate (Eigen::AngleAxisf(rotang, era));
em1torb.translate (el1 + emv1);
em1t2.translate (em1r * emv2);
// Combine by multiplication:
Eigen::Transform<float, 3, Eigen::TransformTraits::Affine> em1 = em1t2 * em1torb * em1r * em1tor * em1t;

//em1 = em1t * em1r; IS NOT EQUAL TO:
//em1.rotate (Eigen::AngleAxisf(rotang, era));
//em1.translate (emv1);

//em1 = em1t * em1r; IS NOT EQUAL TO:
//em1.translate (emv1);
//em1.prerotate (Eigen::AngleAxisf(rotang, era));

//em1 = em1t * em1r; IS NOT EQUAL TO:
//em1.prerotate (Eigen::AngleAxisf(rotang, era));
//em1.translate (emv1);

//em1 = em1t * em1r; IS NOT EQUAL TO:
//em1.prerotate (Eigen::AngleAxisf(rotang, era)).translate (emv1);

// This is quivalent to em1 = em1t * em1r;
//em1.translate (emv1);
//em1.rotate (Eigen::AngleAxisf(rotang, era));

/**
* IN EIGEN:
*
* The order in which you call translate() and rotate() is the left to right order in whcih the
* matrices get multiplied
*
* THe prefix 'pre' refers to the left to right order of multiplications NOT the order in which
* the transforms are applied.
*/

// Apply mat44
sm::vec<> l2 = (m1 * l1).less_one_dim();
sm::vec<> d2_s = (m1 * d1_s).less_one_dim();
sm::vec<> d2_e = (m1 * d1_e).less_one_dim();
sm::vec<> d2 = d2_e - d2_s;
// Apply Eigen
Eigen::Vector3f el2 = (em1 * el1);
Eigen::Vector3f ed2_s = em1 * ed1_s;
Eigen::Vector3f ed2_e = em1 * ed1_e;
Eigen::Vector3f ed2 = ed2_e - ed2_s;
// Convert Eigen vector results to sm::vec
sm::vec<> eig_l2 = { el2[0], el2[1], el2[2] };
sm::vec<> eig_d2 = { ed2[0], ed2[1], ed2[2] };


auto sv = std::make_unique<mplot::SphereVisual<>>(l1, 0.005, mplot::colour::magenta);
v.bindmodel (sv);
sv->finalize();
v.addVisualModel (sv);

auto vvm = std::make_unique<mplot::VectorVisual<float, 3>>(l1);
v.bindmodel (vvm);
vvm->thevec = d1;
vvm->vgoes = mplot::VectorGoes::FromOrigin;
vvm->thickness *= 0.02;
vvm->fixed_colour = true;
vvm->single_colour = mplot::colour::crimson;
vvm->finalize();
v.addVisualModel (vvm);

sv = std::make_unique<mplot::SphereVisual<>>(l2, 0.02, mplot::colour::goldenrod3);
v.bindmodel (sv);
sv->finalize();
v.addVisualModel (sv);

vvm = std::make_unique<mplot::VectorVisual<float, 3>>(l2);
v.bindmodel (vvm);
vvm->thevec = d2;
vvm->vgoes = mplot::VectorGoes::FromOrigin;
vvm->thickness *= 0.02;
vvm->fixed_colour = true;
vvm->single_colour = mplot::colour::blue;
vvm->finalize();
v.addVisualModel (vvm);

sv = std::make_unique<mplot::SphereVisual<>>(eig_l2, 0.01, mplot::colour::mediumpurple1);
v.bindmodel (sv);
sv->finalize();
v.addVisualModel (sv);

vvm = std::make_unique<mplot::VectorVisual<float, 3>>(eig_l2);
v.bindmodel (vvm);
vvm->thevec = eig_d2;
vvm->vgoes = mplot::VectorGoes::FromOrigin;
vvm->thickness *= 0.02;
vvm->fixed_colour = true;
vvm->single_colour = mplot::colour::cadetblue1;
vvm->finalize();
v.addVisualModel (vvm);


v.addVisualModel (rv); // Cube last (F7 to select) to ensure we see other vectors through it.

v.keepOpen();

return 0;
}
Loading