inching slowly towards a renderer
This commit is contained in:
parent
4b695ecaf6
commit
c7c7d5af77
28 changed files with 613 additions and 59 deletions
src/geometry
29
src/geometry/CMakeLists.txt
Normal file
29
src/geometry/CMakeLists.txt
Normal file
|
@ -0,0 +1,29 @@
|
|||
|
||||
set(hdrs
|
||||
include/pw/geometry/primitives.hpp
|
||||
)
|
||||
|
||||
set(srcs
|
||||
src/primitives.cpp
|
||||
)
|
||||
|
||||
add_library(pwgeometry
|
||||
STATIC
|
||||
${hdrs}
|
||||
${srcs}
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
pwgeometry
|
||||
PUBLIC
|
||||
include
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
pwgeometry
|
||||
PUBLIC
|
||||
)
|
||||
|
||||
target_link_libraries(pwgeometry pwcore)
|
||||
|
||||
#add_subdirectory(tests)
|
21
src/geometry/include/pw/geometry/primitives.hpp
Normal file
21
src/geometry/include/pw/geometry/primitives.hpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef PW_GEOMETRY_PRIMITIVES_HPP
|
||||
#define PW_GEOMETRY_PRIMITIVES_HPP
|
||||
|
||||
#include <pw/core/mesh.hpp>
|
||||
|
||||
namespace pw {
|
||||
|
||||
struct primitives {
|
||||
|
||||
static mesh box(real_t size_x, real_t size_y, real_t size_z);
|
||||
|
||||
static mesh sphere(real_t radius,int divisions_latitude,int divisions_longitude);
|
||||
|
||||
static mesh cone();
|
||||
|
||||
static mesh pyramid();
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
0
src/geometry/src/CMakeLists.txt
Normal file
0
src/geometry/src/CMakeLists.txt
Normal file
87
src/geometry/src/primitives.cpp
Normal file
87
src/geometry/src/primitives.cpp
Normal file
|
@ -0,0 +1,87 @@
|
|||
#include "pw/geometry/primitives.hpp"
|
||||
|
||||
namespace pw {
|
||||
|
||||
mesh primitives::box(real_t size_x,real_t size_y, real_t size_z)
|
||||
{
|
||||
mesh m;
|
||||
|
||||
mesh::vertex3array_t vertices;
|
||||
|
||||
vertices.push_back(vector3(-size_x / 2,-size_y / 2, size_z / 2)); // 0
|
||||
vertices.push_back(vector3( size_x / 2,-size_y / 2, size_z / 2)); // 1
|
||||
vertices.push_back(vector3( size_x / 2, size_y / 2, size_z / 2)); // 2
|
||||
vertices.push_back(vector3(-size_x / 2, size_y / 2, size_z / 2)); // 3
|
||||
|
||||
vertices.push_back(vector3(-size_x / 2,-size_y / 2,-size_z / 2)); // 4
|
||||
vertices.push_back(vector3( size_x / 2,-size_y / 2,-size_z / 2)); // 5
|
||||
vertices.push_back(vector3( size_x / 2, size_y / 2,-size_z / 2)); // 6
|
||||
vertices.push_back(vector3(-size_x / 2, size_y / 2,-size_z / 2)); // 7
|
||||
|
||||
mesh::indexarray_t indices = {
|
||||
0, 1, 2, // 0
|
||||
2, 3, 0, // 1
|
||||
1, 5, 6, // 2
|
||||
6, 2, 1, // 3
|
||||
5, 4, 7, // 4
|
||||
7, 6, 5, // 5
|
||||
4, 0, 3, // 6
|
||||
3, 7, 4, // 7
|
||||
3, 2, 6, // 8
|
||||
6, 7, 3, // 9
|
||||
4, 5, 1, // 10
|
||||
1, 0, 4 // 11
|
||||
};
|
||||
|
||||
m.set_indices(indices);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
mesh primitives::sphere(real_t radius,int divisions_latitude,int divisions_longitude)
|
||||
{
|
||||
using std::cos;
|
||||
using std::sin;
|
||||
|
||||
const real_t _division_lat = real_t(360.0) / divisions_latitude;
|
||||
const real_t _division_lon = real_t(360.0) / divisions_longitude;
|
||||
|
||||
// res = new tpPrimitive(tpPrimitive::kTriangleStrip);
|
||||
|
||||
//res->setPrimitiveType(tpPrimitive::kLineStrip);
|
||||
|
||||
// real_t _latitude, _longitude;
|
||||
real_t dToR;
|
||||
real_t x, y, z;
|
||||
|
||||
for (real_t _latitude = 0; _latitude < 360; _latitude += _division_lat)
|
||||
{
|
||||
for (real_t _longitude = 0; _longitude < 360; _longitude += _division_lon)
|
||||
{
|
||||
x = sin ( deg_to_rad(_longitude) ) * cos ( (_latitude + _division_lat) );
|
||||
y = sin ( deg_to_rad(_latitude + _division_lat) );
|
||||
z = cos ( deg_to_rad(_longitude) * cos ( deg_to_rad(_latitude + _division_lat) ) );
|
||||
|
||||
// assign the second normal and vertex
|
||||
// res->addVertexNormal(tpVec3r(x * radius,y * radius,z * radius),
|
||||
// tpVec3r(x,y,z)
|
||||
// );
|
||||
|
||||
// calculate the coordinates
|
||||
x = sin ( deg_to_rad(_longitude) ) * cos (deg_to_rad(_latitude) );
|
||||
y = sin ( deg_to_rad(_latitude) );
|
||||
z = cos ( deg_to_rad(_longitude) ) * cos (deg_to_rad(_latitude) );
|
||||
|
||||
// assign a normal and a vertex
|
||||
// res->addVertexNormal(
|
||||
// tpVec3r(x * radius,y * radius,z * radius),
|
||||
// tpVec3r(x,y,z)
|
||||
// );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue