WIP: bugfixing
This commit is contained in:
@@ -25,14 +25,14 @@ int main() {
|
||||
acidrain::texture_generator tg(256, 256);
|
||||
tg.brick(0, 50, 20, 4, glm::vec4(1), glm::vec4(0));
|
||||
|
||||
shared_ptr<mesh> affectedSphere = mesh_generator::sphere(50, 50);
|
||||
map_transform(affectedSphere, tg, 0, 0, 0.2f);
|
||||
calculate_normals(*affectedSphere.get());
|
||||
shared_ptr<mesh> affectedSphere = mesh_generator::sphere(10, 10);
|
||||
// map_transform(affectedSphere, tg, 0, 0, 1.2f);
|
||||
// calculate_normals(*affectedSphere.get());
|
||||
|
||||
affectedSphere = mesh_generator::cog(0.2, 0.5, 50, 4, 0.1, 0.2, 0.2, 0.1);
|
||||
// affectedSphere = mesh_generator::cog(0.2, 0.5, 50, 4, 0.1, 0.2, 0.2, 0.1);
|
||||
|
||||
demo_data::meshes.push_back(affectedSphere);
|
||||
demo_data::meshes.push_back(mesh_generator::sphere(50, 50));
|
||||
demo_data::meshes.push_back(mesh_generator::sphere(3, 3));
|
||||
demo_data::meshes.push_back(mesh_generator::grid(30, 30));
|
||||
demo_data::meshes.push_back(mesh_generator::cube());
|
||||
|
||||
@@ -45,11 +45,14 @@ int main() {
|
||||
mat->cast_shadows = true;
|
||||
|
||||
auto *textureGenerator1 = new texture_generator(256, 256);
|
||||
mat->textures[texture_role::diffuse] = textureGenerator1->checker_board(0, 20,
|
||||
colour(1, 1, 1, 1),
|
||||
colour(0, 0.5, 0.2, 1)).get_texture(0);
|
||||
// mat->textures[texture_role::diffuse] = textureGenerator1->brick(0, 50, 20, 4, colour(0.3, 0.1, 0, 1),
|
||||
// colour(1, 0.3, 0, 1)).get_texture(0);
|
||||
// mat->textures[texture_role::diffuse] = textureGenerator1->checker_board(0, 20,
|
||||
// colour(1, 1, 1, 1),
|
||||
// colour(0, 0.5, 0.2, 1)).get_texture(0);
|
||||
mat->textures[texture_role::diffuse] = textureGenerator1->brick(0,
|
||||
50, 20,
|
||||
4,
|
||||
colour(0.3, 0.1, 0, 1),
|
||||
colour(1, 0.3, 0, 1)).get_texture(0);
|
||||
|
||||
demo_data::materials.push_back(mat);
|
||||
|
||||
@@ -108,50 +111,50 @@ int main() {
|
||||
auto *scene1 = new scene();
|
||||
demoPartScene.scene_ = shared_ptr<scene>(scene1);
|
||||
|
||||
auto smallSphere = std::make_shared<mesh_node>();
|
||||
auto smallSphere = std::make_shared<mesh_node>("small sphere");
|
||||
smallSphere->mesh_ = demo_data::meshes[1];
|
||||
smallSphere->material_ = demo_data::materials[0];
|
||||
smallSphere->position = glm::vec3(0, 0, 0);
|
||||
smallSphere->scale = glm::vec3(0.5);
|
||||
// meshNode->rotation = glm::angleAxis(2.25f , glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
|
||||
auto ground_plane = std::make_shared<mesh_node>();
|
||||
auto ground_plane = std::make_shared<mesh_node>("ground_plane");
|
||||
ground_plane->mesh_ = demo_data::meshes[2];
|
||||
ground_plane->material_ = demo_data::materials[1];
|
||||
ground_plane->position = glm::vec3(0, 0, 0);
|
||||
ground_plane->scale = glm::vec3(10);
|
||||
ground_plane->rotation = glm::angleAxis(3.141529f / 2.0f, glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
|
||||
auto black_plane = std::make_shared<mesh_node>();
|
||||
auto black_plane = std::make_shared<mesh_node>("back plane");
|
||||
black_plane->mesh_ = demo_data::meshes[2];
|
||||
black_plane->material_ = demo_data::materials[1];
|
||||
black_plane->position = glm::vec3(0, 5, -5);
|
||||
black_plane->scale = glm::vec3(10);
|
||||
black_plane->rotation = angleAxis(3.141529f, glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
|
||||
auto left_plane = std::make_shared<mesh_node>();
|
||||
auto left_plane = std::make_shared<mesh_node>("left plane");
|
||||
left_plane->mesh_ = demo_data::meshes[2];
|
||||
left_plane->material_ = demo_data::materials[1];
|
||||
left_plane->position = glm::vec3(-5, 5, 0);
|
||||
left_plane->scale = glm::vec3(10);
|
||||
left_plane->rotation = angleAxis(-3.141529f / 2.0f, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
|
||||
auto right_plane = std::make_shared<mesh_node>();
|
||||
auto right_plane = std::make_shared<mesh_node>("right plane");
|
||||
right_plane->mesh_ = demo_data::meshes[2];
|
||||
right_plane->material_ = demo_data::materials[1];
|
||||
right_plane->position = glm::vec3(5, 5, 0);
|
||||
right_plane->scale = glm::vec3(10);
|
||||
right_plane->rotation = angleAxis(3.141529f / 2.0f, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
|
||||
auto bigSphere = make_shared<mesh_node>();
|
||||
auto bigSphere = make_shared<mesh_node>("big sphere");
|
||||
bigSphere->mesh_ = demo_data::meshes[0];
|
||||
bigSphere->material_ = demo_data::materials[4];
|
||||
bigSphere->material_ = demo_data::materials[1];
|
||||
bigSphere->position = glm::vec3(-2, 2, 0);
|
||||
bigSphere->scale = glm::vec3(0.8);
|
||||
bigSphere->rotation = glm::angleAxis(3.141529f / 2.0f, glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
|
||||
|
||||
auto lightMeshNode = std::make_shared<mesh_node>();
|
||||
auto lightMeshNode = std::make_shared<mesh_node>("light mesh");
|
||||
lightMeshNode->mesh_ = demo_data::meshes[0];
|
||||
lightMeshNode->material_ = demo_data::materials[3];
|
||||
lightMeshNode->position = glm::vec3(1, 2, 1);
|
||||
|
||||
+3
-2
@@ -43,8 +43,9 @@ void mesh::render(bool flat_shaded) {
|
||||
}
|
||||
|
||||
// fill in buffer
|
||||
int i = 0;
|
||||
for (auto &f: facets) {
|
||||
size_t i = 0;
|
||||
for (size_t face_index = 0; i < facets.size(); i++) {
|
||||
auto& f = facets[face_index];
|
||||
for (int j = 0; j < 3; j++) {
|
||||
vbo_data[i++] = vertices[f.vertices[j]].position.x;
|
||||
vbo_data[i++] = vertices[f.vertices[j]].position.y;
|
||||
|
||||
+15
-15
@@ -79,7 +79,7 @@ std::shared_ptr<mesh> mesh_generator::cube() {
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<mesh> mesh_generator::sphere(int lon_points, int lat_points) {
|
||||
std::shared_ptr<mesh> mesh_generator::sphere(size_t lon_points, size_t lat_points) {
|
||||
mesh *result = new mesh;
|
||||
|
||||
vertex v{};
|
||||
@@ -91,12 +91,12 @@ std::shared_ptr<mesh> mesh_generator::sphere(int lon_points, int lat_points) {
|
||||
double du = 1.0 / static_cast<double>(lon_points);
|
||||
double dv = 1.0 / static_cast<double>(lat_points + 1);
|
||||
|
||||
for (int j = 0; j < lat_points; j++) {
|
||||
for (size_t j = 0; j < lat_points; j++) {
|
||||
|
||||
y = 1.0 - (j + 1) * 2.0 / static_cast<double>(lat_points + 1);
|
||||
double current_circle_radius = sin(M_PI * (j + 1) / static_cast<double>(lat_points + 1));
|
||||
|
||||
for (int i = 0; i < lon_points; i++) {
|
||||
for (size_t i = 0; i < lon_points; i++) {
|
||||
|
||||
x = current_circle_radius * cos((i * 2.0 * M_PI) / static_cast<double>(lon_points));
|
||||
z = current_circle_radius * sin((i * 2.0 * M_PI) / static_cast<double>(lon_points));
|
||||
@@ -105,10 +105,10 @@ std::shared_ptr<mesh> mesh_generator::sphere(int lon_points, int lat_points) {
|
||||
result->vertices.push_back(v);
|
||||
|
||||
if (j > 0) {
|
||||
int current_vertex_index = j * lon_points + i;
|
||||
int new_vertex_index = j * lon_points + ((i + 1) % lon_points);
|
||||
int top_vertex_index = (j - 1) * lon_points + i;
|
||||
int top_next_vertex_index = (j - 1) * lon_points + ((i + 1) % lon_points);
|
||||
size_t current_vertex_index = j * lon_points + i;
|
||||
size_t new_vertex_index = j * lon_points + ((i + 1) % lon_points);
|
||||
size_t top_vertex_index = (j - 1) * lon_points + i;
|
||||
size_t top_next_vertex_index = (j - 1) * lon_points + ((i + 1) % lon_points);
|
||||
|
||||
glm::vec2 current_uv = glm::vec2(i * du, (j + 2) * dv);
|
||||
glm::vec2 next_uv = glm::vec2((i + 1) * du, (j + 2) * dv);
|
||||
@@ -150,11 +150,11 @@ std::shared_ptr<mesh> mesh_generator::sphere(int lon_points, int lat_points) {
|
||||
v.position = glm::vec3(0, 1.0, 0);
|
||||
result->vertices.push_back(v);
|
||||
|
||||
int top_vertex_index = lon_points * lat_points;
|
||||
for (int i = 0; i < lon_points; i++) {
|
||||
size_t top_vertex_index = lon_points * lat_points;
|
||||
for (size_t i = 0; i < lon_points; i++) {
|
||||
|
||||
int current_vertex_index = i;
|
||||
int new_vertex_index = (current_vertex_index + 1) % lon_points;
|
||||
size_t current_vertex_index = i;
|
||||
size_t new_vertex_index = (current_vertex_index + 1) % lon_points;
|
||||
|
||||
glm::vec2 current_uv = glm::vec2(i * du, dv);
|
||||
glm::vec2 next_uv = glm::vec2((i + 1) * du, dv);
|
||||
@@ -178,11 +178,11 @@ std::shared_ptr<mesh> mesh_generator::sphere(int lon_points, int lat_points) {
|
||||
v.position = glm::vec3(0, -1.0, 0);
|
||||
result->vertices.push_back(v);
|
||||
|
||||
int bottom_vertex_index = top_vertex_index + 1;
|
||||
for (int i = 0; i < lon_points; i++) {
|
||||
size_t bottom_vertex_index = top_vertex_index + 1;
|
||||
for (size_t i = 0; i < lon_points; i++) {
|
||||
|
||||
int current_vertex_index = i + (lat_points - 1) * lon_points;
|
||||
int next_vertex_index = (i + 1) % lon_points + (lat_points - 1) * lon_points;
|
||||
size_t current_vertex_index = i + (lat_points - 1) * lon_points;
|
||||
size_t next_vertex_index = (i + 1) % lon_points + (lat_points - 1) * lon_points;
|
||||
|
||||
glm::vec2 current_uv = glm::vec2(i * du, 1.0 - dv);
|
||||
glm::vec2 next_uv = glm::vec2((i + 1) * du, 1.0 - dv);
|
||||
|
||||
@@ -8,7 +8,7 @@ BEGIN_NAMESPACE
|
||||
struct mesh_generator {
|
||||
|
||||
static std::shared_ptr<mesh> cube();
|
||||
static std::shared_ptr<mesh> sphere(int lon_points, int lat_points);
|
||||
static std::shared_ptr<mesh> sphere(size_t lon_points, size_t lat_points);
|
||||
static std::shared_ptr<mesh> grid(int x_segments, int y_segments);
|
||||
static std::shared_ptr<mesh> cylinder(int x_segments, int y_segments, bool cap_top, bool cap_botton);
|
||||
static std::shared_ptr<mesh> revolve(const std::vector<glm::vec2> &contour, int rotation_steps);
|
||||
|
||||
@@ -6,4 +6,8 @@ mesh_node::mesh_node() {
|
||||
type = scene_node_type::mesh;
|
||||
}
|
||||
|
||||
mesh_node::mesh_node(std::string name_) {
|
||||
name = name_;
|
||||
}
|
||||
|
||||
END_NAMESPACE
|
||||
@@ -8,6 +8,7 @@ BEGIN_NAMESPACE
|
||||
|
||||
struct mesh_node : scene_node {
|
||||
mesh_node();
|
||||
mesh_node(std::string name);
|
||||
|
||||
std::shared_ptr<mesh> mesh_;
|
||||
std::shared_ptr<material> material_;
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <iostream>
|
||||
#include "demo_data.h"
|
||||
#include "defines.h"
|
||||
|
||||
BEGIN_NAMESPACE
|
||||
|
||||
static void error_callback(int error, const char* description) {
|
||||
std::cerr << "GLFW error callback. Error: " << error << ", " << description << std::endl;
|
||||
LOG(ERROR) << "glfw error callback: " << error << ", " << description;
|
||||
}
|
||||
|
||||
static void window_size_callback(GLFWwindow* window, int width, int height) {
|
||||
@@ -31,13 +32,13 @@ bool peripherals_glfw::init() {
|
||||
|
||||
window = glfwCreateWindow(demo_data::screen_width, demo_data::screen_height, "Demo", nullptr, nullptr);
|
||||
if (window == nullptr) {
|
||||
std::cerr << "Unable to create window!" << std::endl;
|
||||
LOG(FATAL) << "unable to create window!";
|
||||
return false;
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
if (window == nullptr) {
|
||||
std::cerr << "Unable to create window2!" << std::endl;
|
||||
LOG(FATAL) << "unable to make opengl context current!";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -45,10 +46,10 @@ bool peripherals_glfw::init() {
|
||||
glfwSetWindowSizeCallback(window, window_size_callback);
|
||||
|
||||
if (!gladLoadGL()) {
|
||||
std::cerr << "Unable to load OpenGL functions!" << std::endl;
|
||||
LOG(FATAL) << "unable to load opengl functions!";
|
||||
return false;
|
||||
} else {
|
||||
std::cout << "Successfully created window and loaded GL" << std::endl;
|
||||
LOG(INFO) << "created window and loaded opengl";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -188,11 +188,11 @@ texture_generator &texture_generator::brick(uint8_t layer,
|
||||
|
||||
auto *input = reinterpret_cast<uint32_t *>(layers[layer]);
|
||||
|
||||
uint32_t mortar = as_int(mortar_col);
|
||||
uint32_t brick = as_int(brick_col);
|
||||
uint32_t mortar_color = as_int(mortar_col);
|
||||
uint32_t brick_color = as_int(brick_col);
|
||||
|
||||
for (int i = 0; i < width * height; i++) {
|
||||
input[i] = brick;
|
||||
input[i] = brick_color;
|
||||
}
|
||||
|
||||
int y = 0;
|
||||
@@ -200,7 +200,7 @@ texture_generator &texture_generator::brick(uint8_t layer,
|
||||
for (int i = 0; i < gap_size; i++) {
|
||||
if ((y + i) < height) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
input[x + (y + i) * width] = mortar;
|
||||
input[x + (y + i) * width] = mortar_color;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -214,8 +214,10 @@ texture_generator &texture_generator::brick(uint8_t layer,
|
||||
int x = is_odd_row ? 0 : brick_width / 2;
|
||||
while (x < width) {
|
||||
for (int i = 0; i < gap_size; i++) {
|
||||
for (int current_brick_y = 0; current_brick_y < brick_height; current_brick_y++) {
|
||||
input[x + i + (current_brick_y + y) * width] = mortar;
|
||||
for (int current_brick_y = 0; current_brick_y < (brick_height - 1); current_brick_y++) {
|
||||
// if ((current_brick_y + y) < height) {
|
||||
input[x + i + (current_brick_y + y) * width] = mortar_color;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user