Added a bound for a start. Now the combination of mesh and renderer need to be tested.
This commit is contained in:
parent
d1e5b558b7
commit
841b0eeb46
8 changed files with 110 additions and 23 deletions
|
@ -1,5 +1,6 @@
|
|||
|
||||
set(hdrs
|
||||
include/pw/core/aabb.hpp
|
||||
include/pw/core/axisangle.hpp
|
||||
include/pw/core/color.hpp
|
||||
include/pw/core/core.hpp
|
||||
|
|
52
src/core/include/pw/core/aabb.hpp
Normal file
52
src/core/include/pw/core/aabb.hpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 1999-2019 Hartmut Seichter
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
#ifndef PW_CORE_AABB_HPP
|
||||
#define PW_CORE_AABB_HPP
|
||||
|
||||
#include <pw/core/vector.hpp>
|
||||
|
||||
namespace pw {
|
||||
|
||||
struct aabb {
|
||||
|
||||
vector3 min;
|
||||
vector3 max;
|
||||
|
||||
aabb(const vector3 min_vec,const vector3 max_vec)
|
||||
: min(min_vec)
|
||||
, max(max_vec)
|
||||
{}
|
||||
|
||||
aabb() {
|
||||
min.zero(); max.zero();
|
||||
}
|
||||
|
||||
vector3 dimension() const {
|
||||
return max - min;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include <pw/core/globals.hpp>
|
||||
#include <pw/core/vector.hpp>
|
||||
#include <pw/core/aabb.hpp>
|
||||
|
||||
namespace pw {
|
||||
|
||||
|
@ -32,6 +33,7 @@ class mesh {
|
|||
public:
|
||||
|
||||
typedef std::vector<int32_t> indexarray_t;
|
||||
typedef std::vector<real_t> valuearray_t;
|
||||
typedef std::vector<vector3> vertex3array_t;
|
||||
typedef std::vector<vector2> vertex2array_t;
|
||||
|
||||
|
@ -45,10 +47,12 @@ public:
|
|||
points
|
||||
};
|
||||
|
||||
void set_indices(const indexarray_t& v) { _indices = v; }
|
||||
void set_vertices(const vertex3array_t& v) { _vertices = v; }
|
||||
mesh();
|
||||
|
||||
void set_indices(const indexarray_t& v) { _indices = v; }
|
||||
const indexarray_t& indices() const { return _indices; }
|
||||
|
||||
void set_vertices(const vertex3array_t& v);
|
||||
const vertex3array_t& vertices() const { return _vertices; }
|
||||
|
||||
void set_topology(topology_type t) { _topology = t; }
|
||||
|
@ -56,12 +60,13 @@ public:
|
|||
|
||||
void apply(const matrix4x4& m);
|
||||
|
||||
void bounds() const;
|
||||
|
||||
void reset();
|
||||
|
||||
aabb aabb() const { return _aabb; }
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
topology_type _topology;
|
||||
|
||||
indexarray_t _indices; //!< indices according to topology type
|
||||
|
@ -71,7 +76,14 @@ protected:
|
|||
|
||||
std::vector<vertex2array_t> _uvs; //!< storing multiple UV sets
|
||||
|
||||
struct aabb _aabb;
|
||||
|
||||
// TODO add weights, tangents etc. pp.
|
||||
|
||||
private:
|
||||
|
||||
void compute_bounds();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,27 +1,48 @@
|
|||
#include "pw/core/mesh.hpp"
|
||||
|
||||
|
||||
namespace pw {
|
||||
|
||||
mesh::mesh()
|
||||
{
|
||||
}
|
||||
|
||||
void mesh::set_vertices(const mesh::vertex3array_t &v)
|
||||
{
|
||||
// first set vertices
|
||||
_vertices = v;
|
||||
|
||||
// update bounds
|
||||
compute_bounds();
|
||||
}
|
||||
|
||||
void mesh::apply(const matrix4x4 &m)
|
||||
{
|
||||
// apply transformation to all vertices
|
||||
for (auto &v : _vertices)
|
||||
v = vector4(m * v.homogenous()).project();
|
||||
|
||||
// recompute bounds
|
||||
compute_bounds();
|
||||
}
|
||||
|
||||
void mesh::bounds() const
|
||||
void mesh::compute_bounds()
|
||||
{
|
||||
vector3 max_vec = _vertices.front(),min_vec = _vertices.front();
|
||||
// compute the AABB
|
||||
// only do if there are vertices
|
||||
if (_vertices.size()) {
|
||||
|
||||
// reset
|
||||
_aabb.max = _aabb.min = _vertices.front();
|
||||
|
||||
// update
|
||||
for (auto const & v : _vertices) {
|
||||
max_vec.x() = std::max(v.x(),max_vec.x());
|
||||
max_vec.y() = std::max(v.y(),max_vec.y());
|
||||
max_vec.z() = std::max(v.z(),max_vec.z());
|
||||
min_vec.x() = std::min(v.x(),min_vec.x());
|
||||
min_vec.y() = std::min(v.y(),min_vec.y());
|
||||
min_vec.z() = std::min(v.z(),min_vec.z());
|
||||
_aabb.max.x() = std::max(v.x(),_aabb.max.x());
|
||||
_aabb.max.y() = std::max(v.y(),_aabb.max.y());
|
||||
_aabb.max.z() = std::max(v.z(),_aabb.max.z());
|
||||
_aabb.min.x() = std::min(v.x(),_aabb.min.x());
|
||||
_aabb.min.y() = std::min(v.y(),_aabb.min.y());
|
||||
_aabb.min.z() = std::min(v.z(),_aabb.min.z());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ class texture {
|
|||
};
|
||||
|
||||
enum texture_shape {
|
||||
shape_1d,
|
||||
shape_2d,
|
||||
shape_3d
|
||||
};
|
||||
|
@ -36,7 +37,6 @@ class texture {
|
|||
|
||||
texture(shared_ptr<image> i,texture_shape s,texture_type = color);
|
||||
|
||||
|
||||
void set_image(shared_ptr<image> i);
|
||||
shared_ptr<image> get() const { return _image; }
|
||||
|
||||
|
|
|
@ -15,12 +15,11 @@ public:
|
|||
|
||||
~vertex_array();
|
||||
|
||||
bool ready() const;
|
||||
|
||||
void create(const mesh &m);
|
||||
void destroy();
|
||||
|
||||
void draw();
|
||||
bool ready() const;
|
||||
|
||||
protected:
|
||||
|
||||
|
|
|
@ -120,8 +120,8 @@ struct triangle_renderer
|
|||
const char* vertex_shader_2 = R"(
|
||||
#version 400
|
||||
uniform mat4 model_mat;
|
||||
uniform mat4 view_mat = mat4
|
||||
in vec3 vertex_p;
|
||||
|
||||
void main() {
|
||||
gl_Position = model_mat * vec4(vertex_p, 1.0);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ struct texture::impl {
|
|||
|
||||
GLuint gl_shape() {
|
||||
switch (_host.shape()) {
|
||||
case pw::texture::shape_1d:
|
||||
return GL_TEXTURE_1D;
|
||||
case pw::texture::shape_2d:
|
||||
return GL_TEXTURE_2D;
|
||||
case pw::texture::shape_3d:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue