mirror of
https://github.com/Linloir/SceneEditor.git
synced 2025-12-18 16:08:11 +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" />
|
<ClInclude Include="shader.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<None Include="boundfragmentshader.glsl" />
|
||||||
|
<None Include="boundvertexshader.glsl" />
|
||||||
<None Include="fragmentshader.glsl">
|
<None Include="fragmentshader.glsl">
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
</ExcludedFromBuild>
|
</ExcludedFromBuild>
|
||||||
|
|||||||
@ -294,5 +294,11 @@
|
|||||||
<None Include="terrainvertexshader.glsl">
|
<None Include="terrainvertexshader.glsl">
|
||||||
<Filter>Resource Files</Filter>
|
<Filter>Resource Files</Filter>
|
||||||
</None>
|
</None>
|
||||||
|
<None Include="boundvertexshader.glsl">
|
||||||
|
<Filter>Resource Files</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="boundfragmentshader.glsl">
|
||||||
|
<Filter>Resource Files</Filter>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@ -1,6 +1,8 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "boundary.h"
|
#include "boundary.h"
|
||||||
|
#include "vao.h"
|
||||||
|
|
||||||
void Boundary::updateControlPoints(const glm::vec3 point) {
|
void Boundary::updateControlPoints(const glm::vec3 point) {
|
||||||
_bottomControlPoint.x = std::min(_bottomControlPoint.x, point.x);
|
_bottomControlPoint.x = std::min(_bottomControlPoint.x, point.x);
|
||||||
@ -41,3 +43,41 @@ bool Boundary::hit(const Ray& ray) const {
|
|||||||
|
|
||||||
return true;
|
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 <GLM/glm.hpp>
|
||||||
|
|
||||||
#include "ray.h"
|
#include "ray.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
class Boundary {
|
class Boundary {
|
||||||
private:
|
private:
|
||||||
@ -21,6 +22,8 @@ public:
|
|||||||
inline glm::vec3 bottomCenterPoint() const;
|
inline glm::vec3 bottomCenterPoint() const;
|
||||||
|
|
||||||
bool hit(const Ray& ray) const;
|
bool hit(const Ray& ray) const;
|
||||||
|
|
||||||
|
void render() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline glm::vec3 Boundary::bottomCenterPoint() 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>terrainfragmentshader.glsl</file>
|
||||||
<file>terrainvertexshader.glsl</file>
|
<file>terrainvertexshader.glsl</file>
|
||||||
<file>skyboxfragmentshader.glsl</file>
|
<file>skyboxfragmentshader.glsl</file>
|
||||||
|
<file>boundfragmentshader.glsl</file>
|
||||||
|
<file>boundvertexshader.glsl</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
<qresource prefix="/fonts">
|
<qresource prefix="/fonts">
|
||||||
<file>font_awesome_6_regular_free.otf</file>
|
<file>font_awesome_6_regular_free.otf</file>
|
||||||
|
|||||||
@ -45,6 +45,8 @@ public:
|
|||||||
bool hasLight() const { return _light != nullptr; }
|
bool hasLight() const { return _light != nullptr; }
|
||||||
void makeLight(); // create a light source in the object
|
void makeLight(); // create a light source in the object
|
||||||
|
|
||||||
|
const Boundary& boundary() const { return _boundary; }
|
||||||
|
|
||||||
inline glm::mat4 modelMatrix() const;
|
inline glm::mat4 modelMatrix() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user