Skip to content

Commit 2b53d64

Browse files
author
Diego Jesus
committed
Basic viewer and gl renderer
1 parent 99a8b3e commit 2b53d64

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+5921
-99
lines changed

conanfile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def requirements(self):
4949
self.requires("magic_enum/0.9.5")
5050
self.requires("imgui/cci.20220621+1.88.docking")
5151
self.requires("glfw/3.3.8")
52+
self.requires("glew/2.2.0")
5253

5354

5455
def _configure_cmake(self):

src/bin/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ add_pagoda_executable(
33
SOURCES "pagoda.cpp"
44
DEPENDENCIES Boost::program_options
55
)
6+
7+
add_pagoda_executable(
8+
NAME pgeditor
9+
SOURCES "pgeditor.cpp"
10+
DEPENDENCIES pgframes Boost::program_options
11+
)

src/bin/pgeditor.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ class PagodaEditor {
2222
}
2323

2424
instance.LoadAllPlugins();
25+
#ifdef PAGODA_OS_MACOS
2526
m_platform = pgframes::PlatformWindow::Get("metal");
27+
#else
28+
m_platform = pgframes::PlatformWindow::Get("opengl3");
29+
#endif
2630
if (m_platform == nullptr) {
2731
LOG_ERROR("Unable to create platform window");
2832
return;
@@ -33,7 +37,8 @@ class PagodaEditor {
3337

3438
m_platform->Startup();
3539

36-
m_windowManager->CreateWindow("WindowBrowser");
40+
m_windowManager->CreateWindow("GraphEditor");
41+
m_windowManager->CreateWindow("ViewerWindow");
3742

3843
m_platform->RunMainLoop();
3944

@@ -48,11 +53,9 @@ class PagodaEditor {
4853
int main(int argc, char *argv[]) {
4954
PagodaEditor p;
5055
p.ProcessArgs(argc, argv);
51-
/*
5256
if (!p.Init()) {
5357
return 1;
5458
}
55-
*/
5659
p.Run();
5760
return 0;
5861
}

src/pagoda/scene/CMakeLists.txt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
set(SCENE_SRCS
22
"camera.cpp"
3-
"camera.h"
43
"lens.cpp"
5-
"lens.h"
64
"path.cpp"
7-
"path.h"
8-
"scene_graph.h"
5+
"render_target.cpp"
96
"scene_graph.cpp"
10-
"scene_node.h"
117
"scene_node.cpp"
128
"transformation.cpp"
13-
"transformation.h"
9+
"geometry.cpp"
10+
"mesh.cpp"
11+
"lines.cpp"
1412
)
1513

1614
add_pagoda_module(

src/pagoda/scene/camera.cpp

Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "transformation.h"
33

44
#include <pagoda/common/instrument/profiler.h>
5+
#include <pagoda/math/degrees.h>
56

67
#include <boost/qvm/gen/vec_operations2.hpp>
78
#include <boost/qvm/gen/vec_operations4.hpp>
@@ -20,39 +21,9 @@ using namespace pagoda::math;
2021

2122
using namespace boost;
2223

23-
namespace pagoda::scene
24-
{
25-
Camera::Camera()
26-
: m_position{0, 0, 0}, m_viewDirection{0, 0, -1}, m_viewMatrix(qvm::identity_mat<float, 4>()), m_viewMatrixDirty(true)
27-
{
28-
}
29-
30-
void Camera::SetPosition(const math::Vec3F &pos)
31-
{
32-
if (m_position != pos) {
33-
m_position = pos;
34-
m_viewMatrixDirty = true;
35-
}
36-
}
37-
38-
void Camera::SetViewDirection(const math::Vec3F &dir)
39-
{
40-
DBG_ASSERT(qvm::mag_sqr(dir) > 0);
41-
if (m_viewDirection != dir) {
42-
m_viewDirection = qvm::normalized(dir);
43-
m_viewMatrixDirty = true;
44-
}
45-
}
46-
47-
void Camera::SetTransformation(const Transformation &t)
48-
{
49-
SetPosition(t.GetPosition());
50-
SetViewDirection(t.GetFrontDirection());
51-
}
52-
53-
void Camera::SetLens(const Lens &lens) { m_lens = lens; }
54-
Lens &Camera::GetLens() { return m_lens; }
24+
namespace pagoda::scene {
5525

26+
namespace {
5627
template<typename T>
5728
qvm::mat<T, 4, 4> look_at(const qvm::vec<T, 3> &eye, const qvm::vec<T, 3> &target, const qvm::vec<T, 3> &upDirection)
5829
{
@@ -74,28 +45,54 @@ qvm::mat<T, 4, 4> look_at(const qvm::vec<T, 3> &eye, const qvm::vec<T, 3> &targe
7445

7546
return mat * translation_mat(-eye);
7647
}
48+
}
7749

78-
const math::Vec3F &Camera::GetPosition() const { return m_position; }
79-
80-
const math::Vec3F &Camera::GetViewDirection() const { return m_viewDirection; }
81-
math::Vec3F Camera::GetRightVector() const
50+
Camera::Camera()
8251
{
83-
return normalized(qvm::cross(Transformation::upVector, GetViewDirection()));
52+
m_viewMatrix = qvm::identity_mat<float, 4>();
8453
}
85-
math::Vec3F Camera::GetUpVector() const { return normalized(qvm::cross(GetViewDirection(), GetRightVector())); }
8654

87-
const math::Mat4x4F &Camera::GetViewMatrix()
55+
void Camera::SetPosition(const math::Vec3F &pos) {
56+
m_position = pos;
57+
}
58+
59+
void Camera::SetTarget(const math::Vec3F &target) {
60+
m_target = target;
61+
}
62+
63+
const math::Vec3F& Camera::GetTarget() const { return m_target; }
64+
65+
math::Vec3F Camera::GetViewDirection() const {
66+
return XYZ(row<2>(m_viewMatrix));
67+
}
68+
69+
math::Vec3F Camera::GetRightVector() const {
70+
return XYZ(row<0>(m_viewMatrix));
71+
}
72+
73+
math::Vec3F Camera::GetUpVector() const {
74+
return XYZ(row<1>(m_viewMatrix));
75+
}
76+
77+
void Camera::SetCameraView(const math::Vec3F& eye, const math::Vec3F& lookat)
8878
{
89-
START_PROFILE;
79+
m_position = eye;
80+
m_target = lookat;
81+
}
9082

91-
if (m_viewMatrixDirty) {
92-
math::Vec3F target = m_position + m_viewDirection;
93-
m_viewMatrix = look_at(m_position, target, Transformation::upVector);
94-
m_viewMatrixDirty = false;
95-
}
83+
void Camera::SetLens(const Lens &lens) { m_lens = lens; }
84+
Lens &Camera::GetLens() { return m_lens; }
85+
86+
math::Vec3F Camera::GetPosition() const {
87+
return m_position;
88+
}
89+
90+
math::Mat4x4F Camera::GetViewMatrix()
91+
{
92+
m_viewMatrix = look_at(m_position, m_target, Transformation::upVector);
9693
return m_viewMatrix;
9794
}
9895

9996
const math::Mat4x4F &Camera::GetProjectionMatrix() { return m_lens.GetProjectionMatrix(); }
10097

101-
} // namespace pagoda::scene
98+
} // namespace pagoda::scene

src/pagoda/scene/camera.h

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,54 @@
11
#pragma once
22

33
#include "lens.h"
4-
#include "transformation.h"
54

65
#include <pagoda/math/matrix_base.h>
76
#include <pagoda/math/vec_base.h>
87

98
namespace pagoda::scene
109
{
11-
class Camera final
10+
//! Represents a Camera in the 3D scene.
11+
class Camera
1212
{
13-
public:
14-
Camera();
15-
16-
void SetPosition(const boost::qvm::vec<float, 3> &pos);
17-
void SetViewDirection(const boost::qvm::vec<float, 3> &dir);
18-
void SetTransformation(const Transformation &t);
19-
20-
const math::Vec3F &GetPosition() const;
21-
const math::Vec3F &GetViewDirection() const;
22-
math::Vec3F GetRightVector() const;
23-
math::Vec3F GetUpVector() const;
24-
25-
const math::Mat4x4F &GetViewMatrix();
26-
const math::Mat4x4F &GetProjectionMatrix();
27-
28-
void SetLens(const Lens &lens);
29-
Lens &GetLens();
30-
31-
private:
32-
pagoda::math::Vec3F m_position;
33-
pagoda::math::Vec3F m_viewDirection;
34-
35-
pagoda::math::Mat4x4F m_viewMatrix;
36-
Lens m_lens;
37-
bool m_viewMatrixDirty;
13+
public:
14+
//! Constructs a camera in the origin of coordinates, looking towards
15+
//! the negative z-axis.
16+
Camera();
17+
18+
//! Sets the camera position.
19+
void SetPosition(const math::Vec3F &pos);
20+
//! Sets to where the camera is looking
21+
void SetTarget(const math::Vec3F &target);
22+
//! Returns the camera target.
23+
const math::Vec3F& GetTarget() const;
24+
25+
//! Returns the camera position.
26+
math::Vec3F GetPosition() const;
27+
//! Returns the camera view direction.
28+
math::Vec3F GetViewDirection() const;
29+
//! Returns the camera right direction.
30+
math::Vec3F GetRightVector() const;
31+
//! Returns the camera up direction.
32+
math::Vec3F GetUpVector() const;
33+
34+
void SetCameraView(const math::Vec3F& eye, const math::Vec3F& lookat);
35+
36+
//! Returns the view matrix.
37+
math::Mat4x4F GetViewMatrix();
38+
//! Returns the projection matrix which is provided by the Lens.
39+
const math::Mat4x4F &GetProjectionMatrix();
40+
41+
//! Sets the camera Lens.
42+
void SetLens(const Lens &lens);
43+
//! Returns the camera Lens.
44+
Lens &GetLens();
45+
46+
private:
47+
math::Vec3F m_position; //< The camera position.
48+
math::Vec3F m_target; //< Where the camera is looking at.
49+
math::Mat4x4F m_viewMatrix; //< The view matrix.
50+
Lens m_lens; //< The camera Lens.
3851
};
52+
53+
using CameraPtr = std::shared_ptr<Camera>;
3954
} // namespace pagoda::scene

src/pagoda/scene/geometry.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "geometry.h"
2+
3+
namespace pagoda::scene
4+
{
5+
Geometry::Geometry(const std::vector<math::Vec3F>& verts,
6+
const std::vector<uint32_t>& indices)
7+
: m_vertices{verts}
8+
, m_indices{indices}
9+
{
10+
}
11+
12+
const std::vector<math::Vec3F>& Geometry::GetVertices() const { return m_vertices; }
13+
const std::vector<uint32_t>& Geometry::GetIndices() const { return m_indices; }
14+
15+
void Geometry::SetVertexColors(const std::vector<math::Vec4F>& colors) { m_vertexColors = colors; }
16+
const std::vector<math::Vec4F>& Geometry::GetVertexColors() {
17+
if (m_vertexColors.empty()) {
18+
m_vertexColors.resize(m_vertices.size());
19+
std::fill(m_vertexColors.begin(), m_vertexColors.end(), math::Vec4F{0.18, 0.18, 0.18, 1.0});
20+
}
21+
return m_vertexColors;
22+
}
23+
}

src/pagoda/scene/geometry.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#pragma once
2+
3+
#include "pagoda/math/vec_base.h"
4+
#include "pagoda/scene/scene_node.h"
5+
6+
namespace pagoda::scene
7+
{
8+
class Geometry : public SceneNode {
9+
public:
10+
enum class PrimitiveType {
11+
Triangles,
12+
Lines,
13+
LineStrip,
14+
LineLoop
15+
};
16+
17+
Geometry(const std::vector<math::Vec3F>& verts,
18+
const std::vector<uint32_t>& indices);
19+
~Geometry() override = default;
20+
21+
const std::vector<math::Vec3F>& GetVertices() const;
22+
const std::vector<uint32_t>& GetIndices() const;
23+
24+
void SetVertexColors(const std::vector<math::Vec4F>& colors);
25+
const std::vector<math::Vec4F>& GetVertexColors();
26+
27+
virtual PrimitiveType GetPrimitiveType() const = 0;
28+
29+
protected:
30+
std::vector<math::Vec3F> m_vertices;
31+
std::vector<uint32_t> m_indices;
32+
std::vector<math::Vec4F> m_vertexColors;
33+
};
34+
}

src/pagoda/scene/lens.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "lens.h"
22

3+
#include "pagoda/math/degrees.h"
4+
#include "pagoda/math/radians.h"
35
#include <pagoda/math/vec_base.h>
46

57
#include <boost/qvm/map_mat_vec.hpp>
@@ -17,7 +19,10 @@ Lens::Lens() : m_projectionMatrix(qvm::diag_mat(boost::qvm::vec<float, 4>{1, 1,
1719

1820
void Lens::SetPerspective(float fovY, float aspect, float near, float far)
1921
{
20-
m_projectionMatrix = qvm::perspective_rh(fovY, aspect, near, far);
22+
const math::Degrees<float> fovInDegrees(fovY);
23+
const math::Radians<float> fovInRadians(fovInDegrees);
24+
m_projectionMatrix = qvm::perspective_rh(
25+
static_cast<float>(fovInRadians), aspect, near, far);
2126
}
2227

2328
void Lens::SetOrthogonal(float left, float right, float top, float bottom)

src/pagoda/scene/lines.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "lines.h"
2+
3+
namespace pagoda::scene {
4+
namespace {
5+
std::vector<uint32_t> computeIndices(const std::vector<math::Vec3F>& verts) {
6+
std::vector<uint32_t> indices;
7+
indices.reserve(verts.size());
8+
for (uint32_t i = 0; i < verts.size(); /**/) {
9+
indices.push_back(i++);
10+
indices.push_back(i++);
11+
}
12+
return indices;
13+
}
14+
}
15+
16+
Lines::Lines(const std::vector<math::Vec3F>& linePoints)
17+
: Geometry(linePoints, computeIndices(linePoints))
18+
{
19+
}
20+
}

src/pagoda/scene/lines.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
3+
#include "pagoda/math/vec_base.h"
4+
#include "pagoda/scene/geometry.h"
5+
6+
#include <vector>
7+
8+
namespace pagoda::scene {
9+
class Lines : public Geometry {
10+
public:
11+
Lines(const std::vector<math::Vec3F>& linePoints);
12+
13+
PrimitiveType GetPrimitiveType() const override { return PrimitiveType::Lines; }
14+
};
15+
}

src/pagoda/scene/mesh.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "mesh.h"
2+
3+
namespace pagoda::scene {
4+
5+
Mesh::Mesh(const std::vector<math::Vec3F>& verts, const std::vector<uint32_t>& indices)
6+
: Geometry(verts, indices)
7+
{
8+
}
9+
}

0 commit comments

Comments
 (0)