mirror of
https://github.com/Linloir/SceneEditor.git
synced 2025-12-16 23:18:12 +08:00
[CORE][ADD] Bounding box display
- Add render API in bounding box - Add getter API in renderer to get bounding box
This commit is contained in:
parent
9d95220073
commit
7321455581
@ -172,6 +172,8 @@
|
||||
<ClInclude Include="shader.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="boundfragmentshader.glsl" />
|
||||
<None Include="boundvertexshader.glsl" />
|
||||
<None Include="fragmentshader.glsl">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
</ExcludedFromBuild>
|
||||
|
||||
@ -294,5 +294,11 @@
|
||||
<None Include="terrainvertexshader.glsl">
|
||||
<Filter>Resource Files</Filter>
|
||||
</None>
|
||||
<None Include="boundvertexshader.glsl">
|
||||
<Filter>Resource Files</Filter>
|
||||
</None>
|
||||
<None Include="boundfragmentshader.glsl">
|
||||
<Filter>Resource Files</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@ -1,6 +1,8 @@
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
#include "boundary.h"
|
||||
#include "vao.h"
|
||||
|
||||
void Boundary::updateControlPoints(const glm::vec3 point) {
|
||||
_bottomControlPoint.x = std::min(_bottomControlPoint.x, point.x);
|
||||
@ -40,4 +42,42 @@ bool Boundary::hit(const Ray& ray) const {
|
||||
if ((tmin > tzmax) || (tzmin > tmax)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void Boundary::render() const {
|
||||
// Generate vertices
|
||||
std::vector<Vertex> vertices;
|
||||
vertices.push_back(Vertex(glm::vec3(_bottomControlPoint.x, _bottomControlPoint.y, _bottomControlPoint.z)));
|
||||
vertices.push_back(Vertex(glm::vec3(_topControlPoint.x, _bottomControlPoint.y, _bottomControlPoint.z)));
|
||||
vertices.push_back(Vertex(glm::vec3(_topControlPoint.x, _topControlPoint.y, _bottomControlPoint.z)));
|
||||
vertices.push_back(Vertex(glm::vec3(_bottomControlPoint.x, _topControlPoint.y, _bottomControlPoint.z)));
|
||||
vertices.push_back(Vertex(glm::vec3(_bottomControlPoint.x, _bottomControlPoint.y, _topControlPoint.z)));
|
||||
vertices.push_back(Vertex(glm::vec3(_topControlPoint.x, _bottomControlPoint.y, _topControlPoint.z)));
|
||||
vertices.push_back(Vertex(glm::vec3(_topControlPoint.x, _topControlPoint.y, _topControlPoint.z)));
|
||||
vertices.push_back(Vertex(glm::vec3(_bottomControlPoint.x, _topControlPoint.y, _topControlPoint.z)));
|
||||
// Generate indices
|
||||
std::vector<unsigned int> indices;
|
||||
indices.push_back(0); indices.push_back(1); indices.push_back(2); indices.push_back(3); // bottom
|
||||
indices.push_back(4); indices.push_back(5); indices.push_back(6); indices.push_back(7); // top
|
||||
indices.push_back(0); indices.push_back(1); indices.push_back(5); indices.push_back(4); // left
|
||||
indices.push_back(3); indices.push_back(2); indices.push_back(6); indices.push_back(7); // right
|
||||
indices.push_back(0); indices.push_back(3); indices.push_back(7); indices.push_back(4); // back
|
||||
indices.push_back(1); indices.push_back(2); indices.push_back(6); indices.push_back(5); // front
|
||||
// Generate VBO
|
||||
VertexBufferObject vbo(vertices);
|
||||
// Generate EBO
|
||||
ElementBufferObject ebo(indices);
|
||||
// Generate VAO
|
||||
VertexArrayObject vao(vbo, ebo);
|
||||
vao.setVertexAttributePointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)0);
|
||||
// Draw
|
||||
vao.bind();
|
||||
OPENGL_EXTRA_FUNCTIONS->glDrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_INT, (void*)(0 * sizeof(unsigned int)));
|
||||
OPENGL_EXTRA_FUNCTIONS->glDrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_INT, (void*)(4 * sizeof(unsigned int)));
|
||||
OPENGL_EXTRA_FUNCTIONS->glDrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_INT, (void*)(8 * sizeof(unsigned int)));
|
||||
OPENGL_EXTRA_FUNCTIONS->glDrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_INT, (void*)(12 * sizeof(unsigned int)));
|
||||
vao.unbind();
|
||||
// Delete VBO and VAO
|
||||
vbo.dispose();
|
||||
vao.dispose();
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
#include <GLM/glm.hpp>
|
||||
|
||||
#include "ray.h"
|
||||
#include "utils.h"
|
||||
|
||||
class Boundary {
|
||||
private:
|
||||
@ -21,6 +22,8 @@ public:
|
||||
inline glm::vec3 bottomCenterPoint() const;
|
||||
|
||||
bool hit(const Ray& ray) const;
|
||||
|
||||
void render() const;
|
||||
};
|
||||
|
||||
inline glm::vec3 Boundary::bottomCenterPoint() const {
|
||||
|
||||
7
FinalProject/boundfragmentshader.glsl
Normal file
7
FinalProject/boundfragmentshader.glsl
Normal file
@ -0,0 +1,7 @@
|
||||
#version 430 core
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
void main() {
|
||||
FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);
|
||||
}
|
||||
10
FinalProject/boundvertexshader.glsl
Normal file
10
FinalProject/boundvertexshader.glsl
Normal file
@ -0,0 +1,10 @@
|
||||
#version 430 core
|
||||
|
||||
layout(location = 0) in vec3 position;
|
||||
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
void main() {
|
||||
gl_Position = projection * view * vec4(position, 1.0);
|
||||
}
|
||||
@ -6,6 +6,8 @@
|
||||
<file>terrainfragmentshader.glsl</file>
|
||||
<file>terrainvertexshader.glsl</file>
|
||||
<file>skyboxfragmentshader.glsl</file>
|
||||
<file>boundfragmentshader.glsl</file>
|
||||
<file>boundvertexshader.glsl</file>
|
||||
</qresource>
|
||||
<qresource prefix="/fonts">
|
||||
<file>font_awesome_6_regular_free.otf</file>
|
||||
|
||||
@ -44,6 +44,8 @@ public:
|
||||
ScopedLight* originalLight() const; // pass out the light object to scene manager to set light attributes
|
||||
bool hasLight() const { return _light != nullptr; }
|
||||
void makeLight(); // create a light source in the object
|
||||
|
||||
const Boundary& boundary() const { return _boundary; }
|
||||
|
||||
inline glm::mat4 modelMatrix() const;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user