26 #include <type_traits>
27 #include <glm/gtc/matrix_transform.hpp>
28 #include <glm/gtx/intersect.hpp>
30 #include "eng3d/primitive.hpp"
31 #include "eng3d/rectangle.hpp"
32 #include "eng3d/utils.hpp"
95 buffer.resize(positions.size());
96 for(
size_t i = 0; i < positions.size(); i++)
101 Eng3D::Sphere::Sphere(
float center_x,
float center_y,
float center_z,
float _radius,
int _resolution,
bool cw_winding)
103 resolution{ _resolution },
106 buffer.resize(6 * resolution * resolution);
107 glm::vec3 center_pos(center_x, center_y, center_z);
109 for(
int latitude = 0; latitude < resolution; latitude++) {
110 for(
int longitude = 0; longitude < resolution; longitude++) {
111 buffer[(longitude + latitude * resolution) * 6 + 0] = calc_pos(center_pos, longitude + 0, latitude + 0);
112 buffer[(longitude + latitude * resolution) * 6 + 1] = calc_pos(center_pos, longitude + cw_winding, latitude + !cw_winding);
113 buffer[(longitude + latitude * resolution) * 6 + 2] = calc_pos(center_pos, longitude + !cw_winding, latitude + cw_winding);
114 buffer[(longitude + latitude * resolution) * 6 + 3] = calc_pos(center_pos, longitude + !cw_winding, latitude + cw_winding);
115 buffer[(longitude + latitude * resolution) * 6 + 4] = calc_pos(center_pos, longitude + cw_winding, latitude + !cw_winding);
116 buffer[(longitude + latitude * resolution) * 6 + 5] = calc_pos(center_pos, longitude + 1, latitude + 1);
123 const float longitude_ratio = ((float)longitude) / resolution;
124 const float longitude_rad = longitude_ratio * 2 * glm::pi<float>();
125 const float latitude_ratio = ((float)latitude) / resolution;
126 const float latitude_rad = latitude_ratio * glm::pi<float>();
128 const float x = radius * glm::cos(longitude_rad) * glm::sin(latitude_rad);
129 const float y = radius * glm::sin(longitude_rad) * glm::sin(latitude_rad);
130 const float z = radius * glm::cos(latitude_rad);
132 glm::vec3 pos{ x, y, z };
134 glm::vec2 tex_coord(longitude_ratio, latitude_ratio);
Sphere(float x, float y, float z, float radius, int resolution, bool cw_winding=true)
Line(glm::vec2 start, glm::vec2 end)
Packed model - packs both vertices and texcoords into the same buffer.
virtual void upload() const
std::vector< DataType > buffer
A static mesh with fixed number of elements.
virtual void upload() const
std::array< DataType, vtc_size > buffer
Quad(glm::vec3 c1, glm::vec3 c2, glm::vec3 c3, glm::vec3 c4)
Square(float start_x, float start_y, float end_x, float end_y)
TriangleList(std::vector< glm::vec3 > &positions, std::vector< glm::vec2 > &tex_coords)