fixing stuff
This commit is contained in:
@@ -1,11 +1,8 @@
|
||||
#include <cstdint>
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
#include <string>
|
||||
#include <math.h>
|
||||
#include <iostream>
|
||||
#include "Color.h"
|
||||
#include "../lib/djstdlib/core.h"
|
||||
|
||||
auto hue_to_rgb(float p, float q, float t) -> float {
|
||||
real32 hue_to_rgb(float p, float q, float t) {
|
||||
if (t < 0) {
|
||||
t += 1;
|
||||
} else if (t > 1) {
|
||||
@@ -17,7 +14,7 @@ auto hue_to_rgb(float p, float q, float t) -> float {
|
||||
return p;
|
||||
};
|
||||
|
||||
auto hsl_to_hex(float h, float s, float l) -> glm::vec3 {
|
||||
glm::vec3 hsl_to_hex(real32 h, real32 s, real32 l) {
|
||||
h /= 360;
|
||||
s /= 100;
|
||||
l /= 100;
|
||||
@@ -34,7 +31,7 @@ auto hsl_to_hex(float h, float s, float l) -> glm::vec3 {
|
||||
return glm::vec3(r, g, b);
|
||||
}
|
||||
|
||||
auto Color::color_from_index(int index) -> glm::vec3 {
|
||||
glm::vec3 color_from_index(int index) {
|
||||
auto color_wheel_cycle = floorf(index / 6.0f);
|
||||
auto darkness_cycle = floorf(index / 12.0f);
|
||||
auto spacing = (360.0f / 6.0f);
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
|
||||
namespace Color {
|
||||
auto color_from_index(int index) -> glm::vec3;
|
||||
};
|
||||
glm::vec3 color_from_index(int index);
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
fn hue_to_rgb(p: f32, q: f32, t: f32) f32 {
|
||||
if (t < 0) {
|
||||
t += 1;
|
||||
} else if (t > 1) {
|
||||
t -= 1;
|
||||
}
|
||||
if (t < 1.0 / 6) return p + (q - p) * 6 * t;
|
||||
if (t < 1.0 / 2) return q;
|
||||
if (t < 2.0 / 3) return p + (q - p) * (2.0 / 3 - t) * 6;
|
||||
return p;
|
||||
}
|
||||
|
||||
fn hsl_to_hex(h: f32, s: f32, l: f32) @Vector(3, f32) {
|
||||
h /= 360;
|
||||
s /= 100;
|
||||
l /= 100;
|
||||
const r: f32;
|
||||
const g: f32;
|
||||
const b: f32;
|
||||
if (s == 0) {
|
||||
r = l;
|
||||
g = l;
|
||||
b = l;
|
||||
} else {
|
||||
const q = if (l < 0.5) l * (1 + s) else l + s - l * s;
|
||||
const p = 2 * l - q;
|
||||
r = hue_to_rgb(p, q, h + 1.0 / 3);
|
||||
g = hue_to_rgb(p, q, h);
|
||||
b = hue_to_rgb(p, q, h - 1.0 / 3);
|
||||
}
|
||||
return @Vector(3, f32){ r, g, b };
|
||||
}
|
||||
|
||||
pub fn color_from_index(index: i32) @Vector(3, f32) {
|
||||
const color_wheel_cycle = @floor(index / 6.0);
|
||||
const darkness_cycle = @floor(index / 12.0);
|
||||
const spacing = (360.0 / 6.0);
|
||||
const offset = if (color_wheel_cycle == 0) 0 else spacing / (color_wheel_cycle + 2);
|
||||
const hue = spacing * (index % 6) + offset;
|
||||
const saturation = 100.0f;
|
||||
const lightness = 1.0f / (2 + darkness_cycle) * 100;
|
||||
return hsl_to_hex(hue, saturation, lightness);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <iostream>
|
||||
#include "Mesh.h"
|
||||
#include "loaders/tinyobj.h"
|
||||
#include "../lib/loaders/tinyobj.h"
|
||||
|
||||
auto Mesh::init(const char* obj_file) -> void {
|
||||
auto reader = tinyobj::ObjReader();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef LEDDA_MESH_H
|
||||
#define LEDDA_MESH_H
|
||||
|
||||
#include "glad/glad.h"
|
||||
#include "../lib/glad/glad.h"
|
||||
#include "geometry.h"
|
||||
|
||||
struct Mesh {
|
||||
@@ -11,8 +11,8 @@ struct Mesh {
|
||||
unsigned int vbo_norm;
|
||||
unsigned int ebo;
|
||||
unsigned int num_indices;
|
||||
auto init(const char* obj_file) -> void;
|
||||
auto init(const LeddaGeometry::Shape* shape) -> void;
|
||||
void init(const char* obj_file);
|
||||
void init(const Shape* shape);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
const std = @import("std");
|
||||
const c = @import("../c.zig");
|
||||
const djleddaGeom = @import("djleddaGeom.zig");
|
||||
|
||||
pub const Mesh = struct {
|
||||
vao: c_uint,
|
||||
vbo_xyz: c_uint,
|
||||
vbo_uv: c_uint,
|
||||
vbo_norm: c_uint,
|
||||
ebo: c_uint,
|
||||
num_indices: c_uint,
|
||||
|
||||
pub fn from_shape(shape: *const djleddaGeom.Shape) void {
|
||||
const mesh = Mesh{};
|
||||
mesh.num_indices = shape.indices.len;
|
||||
c.glGenVertexArrays(1, &mesh.vao);
|
||||
c.glGenBuffers(1, &mesh.vbo_xyz);
|
||||
c.glGenBuffers(1, &mesh.vbo_uv);
|
||||
c.glGenBuffers(1, &mesh.ebo);
|
||||
|
||||
c.glBindVertexArray(mesh.vao);
|
||||
|
||||
c.glBindBuffer(c.GL_ARRAY_BUFFER, mesh.vbo_xyz);
|
||||
c.glBufferData(c.GL_ARRAY_BUFFER, shape.xyz.ptr * @sizeOf(float), shape.xyz, c.GL_STATIC_DRAW);
|
||||
c.glVertexAttribPointer(0, 3, c.GL_FLOAT, c.GL_FALSE, 3 * @sizeOf(f32), @as(*void, 0));
|
||||
c.glEnableVertexAttribArray(0);
|
||||
|
||||
c.glBindBuffer(c.GL_ARRAY_BUFFER, mesh.vbo_uv);
|
||||
c.glBufferData(c.GL_ARRAY_BUFFER, shape.uv.ptr * @sizeOf(f32), shape.uv, c.GL_STATIC_DRAW);
|
||||
c.glVertexAttribPointer(1, 2, c.GL_FLOAT, c.GL_FALSE, 2 * @sizeOf(f32), @as(*void, 0));
|
||||
c.glEnableVertexAttribArray(1);
|
||||
|
||||
c.glBindBuffer(c.GL_ELEMENT_ARRAY_BUFFER, mesh.ebo);
|
||||
c.glBufferData(c.GL_ELEMENT_ARRAY_BUFFER, shape.indices.len * @sizeOf(c_uint), shape.indices.ptr, c.GL_STATIC_DRAW);
|
||||
}
|
||||
|
||||
// pub fn init(obj_file: *[]const u8) void {
|
||||
// const reader = c.tinyobj.ObjReader();
|
||||
// const success = reader.ParseFromFile(obj_file);
|
||||
// std.debug.print("{}\n", .{reader.Error()});
|
||||
//
|
||||
// const attrib = reader.GetAttrib();
|
||||
//
|
||||
// const indices_t = reader.GetShapes().at(0).mesh.indices;
|
||||
// const indices = ArrayList(c_uint)(indices_t.size());
|
||||
//
|
||||
// const vertices = ArrayList()(3*indices_t.size());
|
||||
// const normals = ArrayList()(3*indices_t.size());
|
||||
// const texcoords = ArrayList()(2*indices_t.size());
|
||||
//
|
||||
// for (int i = 0; i < indices_t.size(); i++) {
|
||||
// const vertex_data = indices_t[i];
|
||||
// vertices[3*i] = attrib.vertices[3*vertex_data.vertex_index];
|
||||
// vertices[3*i+1] = attrib.vertices[3*vertex_data.vertex_index + 1];
|
||||
// vertices[3*i+2] = attrib.vertices[3*vertex_data.vertex_index + 2];
|
||||
//
|
||||
// normals[3*i] = attrib.normals[3*vertex_data.normal_index];
|
||||
// normals[3*i+1] = attrib.normals[3*vertex_data.normal_index + 1];
|
||||
// normals[3*i+2] = attrib.normals[3*vertex_data.normal_index + 2];
|
||||
//
|
||||
// texcoords[2*i] = attrib.texcoords[2*vertex_data.texcoord_index];
|
||||
// texcoords[2*i+1] = attrib.texcoords[2*vertex_data.texcoord_index + 1];
|
||||
//
|
||||
// indices[i] = i;
|
||||
// }
|
||||
//
|
||||
// num_indices = indices_t.size();
|
||||
// glGenVertexArrays(1, &vao);
|
||||
// glGenBuffers(1, &vbo_xyz);
|
||||
// glGenBuffers(1, &vbo_uv);
|
||||
// glGenBuffers(1, &vbo_norm);
|
||||
// //glGenBuffers(1, &ebo);
|
||||
//
|
||||
// glBindVertexArray(vao);
|
||||
//
|
||||
// glBindBuffer(GL_ARRAY_BUFFER, vbo_xyz);
|
||||
// glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(float), vertices.data(), GL_STATIC_DRAW);
|
||||
// glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
|
||||
// glEnableVertexAttribArray(0);
|
||||
//
|
||||
// glBindBuffer(GL_ARRAY_BUFFER, vbo_uv);
|
||||
// glBufferData(GL_ARRAY_BUFFER, texcoords.size() * sizeof(float), texcoords.data(), GL_STATIC_DRAW);
|
||||
// glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void*)0);
|
||||
// glEnableVertexAttribArray(1);
|
||||
//
|
||||
// glBindBuffer(GL_ARRAY_BUFFER, vbo_norm);
|
||||
// glBufferData(GL_ARRAY_BUFFER, normals.size() * sizeof(float), normals.data(), GL_STATIC_DRAW);
|
||||
// glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
|
||||
// glEnableVertexAttribArray(2);
|
||||
//
|
||||
// //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
|
||||
// //glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(unsigned int), indices.data(), GL_STATIC_DRAW);
|
||||
// }
|
||||
};
|
||||
@@ -1,81 +0,0 @@
|
||||
#ifndef ORBIT_CONTROLS_H
|
||||
#define ORBIT_CONTROLS_H
|
||||
|
||||
#include "glad/glad.h"
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include "loaders/stb_image.h"
|
||||
|
||||
constexpr auto ROTATION_FACTOR = 1.0f / 200.0f;
|
||||
|
||||
struct Point {
|
||||
float x;
|
||||
float y;
|
||||
};
|
||||
|
||||
class OrbitControls {
|
||||
private:
|
||||
bool dragging;
|
||||
bool hovered;
|
||||
bool scrolling;
|
||||
bool flyingEnabled;
|
||||
float lastX;
|
||||
float lastY;
|
||||
Point lastScroll1;
|
||||
Point lastScroll2;
|
||||
glm::vec3 y_axis;
|
||||
glm::vec3 x_axis;
|
||||
glm::vec3 start;
|
||||
Entity* orbited_object;
|
||||
|
||||
OrbitControls(Entity* orbited, Camera* camera) {
|
||||
camera = camera;
|
||||
orbited_object = orbited;
|
||||
y_axis = orbited_object.worldToLocal(camera.up);
|
||||
x_axis = orbited_object.position.sub(camera.position);
|
||||
x_axis /= sqrt(pow(x_axis.x) + pow(x_axis.y, 2) + pow(x_axis.z, 2));
|
||||
x_axis = glm::cross(x_axis, y_axis);
|
||||
start = orbited_object.rotation;
|
||||
|
||||
this.element.addEventListener('wheel', (ev) => this.handleScroll(ev));
|
||||
this.element.addEventListener('mouseover', () => this.hovered = true);
|
||||
this.element.addEventListener('mouseout', () => this.hovered = false);
|
||||
this.element.addEventListener('mousedown', (ev) => this.handleMouseDown(ev));
|
||||
window.addEventListener('mousemove', (ev) => this.handleMove(ev));
|
||||
window.addEventListener('mouseup', () => this.dragging = false);
|
||||
}
|
||||
|
||||
on_mouse_down(event) {
|
||||
if (event.button === 1) {
|
||||
this.object.setRotationFromEuler(this.start);
|
||||
}
|
||||
if (!this.dragging) {
|
||||
this.lastX = event.x;
|
||||
this.lastY = event.y;
|
||||
this.dragging = true;
|
||||
}
|
||||
}
|
||||
|
||||
on_mouse_move(event) {
|
||||
if (dragging) {
|
||||
auto x_diff = event.movementX * ROTATION_FACTOR;
|
||||
auto y_diff = event.movementY * ROTATION_FACTOR;
|
||||
glm::rotate(&orbited_object, x_diff, &y_axis);
|
||||
//rotate on world axis ???
|
||||
glm::rotate(&orbited_object, y_diff &x_axis);
|
||||
}
|
||||
}
|
||||
|
||||
on_scroll(event) {
|
||||
if (this.flyingEnabled && this.hovered) {
|
||||
for (const fliable of this.fliables) {
|
||||
const direction = event.deltaY / Math.abs(event.deltaY);
|
||||
fliable.flyBy(direction / 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,43 +1,42 @@
|
||||
#include "glad/glad.h"
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include "Shader.h"
|
||||
#include "../lib/djstdlib/core.h"
|
||||
#include "../lib/glad/glad.h"
|
||||
|
||||
enum ShaderType {
|
||||
fragment=GL_FRAGMENT_SHADER,
|
||||
vertex=GL_VERTEX_SHADER,
|
||||
};
|
||||
|
||||
auto create_shader(const char* file_path, ShaderType shader_type, char* info_log) -> unsigned int {
|
||||
uint32 create_shader(const char* file_path, ShaderType shader_type, char* info_log) {
|
||||
std::stringstream shader_stream;
|
||||
std::ifstream shader_file;
|
||||
shader_file.open(file_path);
|
||||
shader_stream << shader_file.rdbuf();
|
||||
shader_file.close();
|
||||
auto shader_string = shader_stream.str();
|
||||
const auto shader_code = shader_string.c_str();
|
||||
std::string string = shader_stream.str();
|
||||
const char *shader_code = string.c_str();
|
||||
|
||||
auto vertex_shader = glCreateShader(shader_type);
|
||||
GLuint vertex_shader = glCreateShader(shader_type);
|
||||
glShaderSource(vertex_shader, 1, &shader_code, NULL);
|
||||
glCompileShader(vertex_shader);
|
||||
int success;
|
||||
glGetShaderiv(vertex_shader, GL_COMPILE_STATUS, &success);
|
||||
if (!success) {
|
||||
glGetShaderInfoLog(vertex_shader, 512, NULL, info_log);
|
||||
auto shader_type_name = shader_type == ShaderType::fragment ? "FRAGMENT" : "VERTEX";
|
||||
const char* shader_type_name = shader_type == ShaderType::fragment ? "FRAGMENT" : "VERTEX";
|
||||
std::cout << "ERROR::SHADER::" << shader_type_name << "::COMPILATION_FAILED\n" << info_log << std::endl;
|
||||
}
|
||||
|
||||
return vertex_shader;
|
||||
}
|
||||
|
||||
auto Shader::init(const char* vertex_path, const char* fragment_path) -> void {
|
||||
auto info_log = std::array<char, 512>();
|
||||
auto vertex_shader = create_shader(vertex_path, ShaderType::vertex, info_log.data());
|
||||
auto fragment_shader = create_shader(fragment_path, ShaderType::fragment, info_log.data());
|
||||
void Shader::init(const char* vertex_path, const char* fragment_path) {
|
||||
char info_log[512] = {0};
|
||||
uint32 vertex_shader = create_shader(vertex_path, ShaderType::vertex, info_log);
|
||||
uint32 fragment_shader = create_shader(fragment_path, ShaderType::fragment, info_log);
|
||||
|
||||
prog_id = glCreateProgram();
|
||||
glAttachShader(prog_id, vertex_shader);
|
||||
@@ -47,8 +46,8 @@ auto Shader::init(const char* vertex_path, const char* fragment_path) -> void {
|
||||
int success;
|
||||
glGetProgramiv(prog_id, GL_LINK_STATUS, &success);
|
||||
if (!success) {
|
||||
glGetProgramInfoLog(prog_id, 512, NULL, info_log.data());
|
||||
std::cout << "ERROR::SHADER::PROGRAM::LINK_FAILED\n" << info_log.data() << std::endl;
|
||||
glGetProgramInfoLog(prog_id, 512, NULL, info_log);
|
||||
std::cout << "ERROR::SHADER::PROGRAM::LINK_FAILED\n" << info_log << std::endl;
|
||||
}
|
||||
|
||||
glDeleteShader(vertex_shader);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
struct Shader {
|
||||
unsigned int prog_id;
|
||||
auto init(const char* vertex_path, const char* fragment_path) -> void;
|
||||
void init(const char* vertex_path, const char* fragment_path);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
const c = @import("../c.zig");
|
||||
const std = @import("std");
|
||||
|
||||
const ShaderType = enum(u32) {
|
||||
fragment = c.GL_FRAGMENT_SHADER,
|
||||
vertex = c.GL_VERTEX_SHADER,
|
||||
};
|
||||
|
||||
fn create_shader(file_path: []const u8, shader_type: ShaderType, info_log: *[]const u8, allocator: *std.mem.Allocator) c_uint {
|
||||
const file = try std.fs.openFileAbsolute(file_path);
|
||||
|
||||
const file_reader = file.reader(file);
|
||||
const shader_code = std.ArrayList(u8);
|
||||
shader_code.initCapacity(allocator, 1024);
|
||||
defer allocator.free(shader_code);
|
||||
|
||||
file_reader.readAllArrayList(shader_code, 1024 * 1024);
|
||||
|
||||
const vertex_shader = c.glCreateShader(shader_type);
|
||||
c.glShaderSource(vertex_shader, 1, &shader_code.items, c.NULL);
|
||||
c.glCompileShader(vertex_shader);
|
||||
const success: i32 = undefined;
|
||||
c.glGetShaderiv(vertex_shader, c.GL_COMPILE_STATUS, &success);
|
||||
if (success != 0) {
|
||||
c.glGetShaderInfoLog(vertex_shader, 512, c.NULL, info_log);
|
||||
const shader_type_name = if (shader_type == ShaderType.fragment) "FRAGMENT" else "VERTEX";
|
||||
std.debug.print("ERROR::SHADER::{}::COMPILATION_FAILED\n{}\n", .{ shader_type_name, info_log });
|
||||
}
|
||||
|
||||
return vertex_shader;
|
||||
}
|
||||
|
||||
const Shader = struct {
|
||||
prog_id: c_uint,
|
||||
|
||||
pub fn init(self: Shader, vertex_path: *[]const u8, fragment_path: *[]const u8, allocator: *std.mem.Allocator) void {
|
||||
const info_log = [512]u8{};
|
||||
const vertex_shader = create_shader(vertex_path, ShaderType.vertex, &info_log, allocator);
|
||||
const fragment_shader = create_shader(fragment_path, ShaderType.fragment, &info_log, allocator);
|
||||
|
||||
self.prog_id = c.glCreateProgram();
|
||||
c.glAttachShader(self.prog_id, vertex_shader);
|
||||
c.glAttachShader(self.prog_id, fragment_shader);
|
||||
c.glLinkProgram(self.prog_id);
|
||||
|
||||
const success: c_uint = undefined;
|
||||
c.glGetProgramiv(self.prog_id, c.GL_LINK_STATUS, &success);
|
||||
if (!success) {
|
||||
c.glGetProgramInfoLog(self.prog_id, 512, c.NULL, &info_log);
|
||||
std.debug.print("ERROR::SHADER::PROGRAM::LINK_FAILED\n{}\n", .{info_log});
|
||||
}
|
||||
|
||||
c.glDeleteShader(vertex_shader);
|
||||
c.glDeleteShader(fragment_shader);
|
||||
}
|
||||
};
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "Texture.h"
|
||||
#include <iostream>
|
||||
#include "loaders/stb_image.h"
|
||||
#include "glad/glad.h"
|
||||
#include "../lib/loaders/stb_image.h"
|
||||
#include "../lib/glad/glad.h"
|
||||
|
||||
auto Texture::init(const char* source_path) -> void {
|
||||
void Texture::init(const char* source_path) {
|
||||
glGenTextures(1, &tex_id);
|
||||
glBindTexture(GL_TEXTURE_2D, tex_id);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
@@ -12,7 +12,7 @@ auto Texture::init(const char* source_path) -> void {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
int nr_channels;
|
||||
auto data = stbi_load(source_path, &width, &height, &nr_channels, 0);
|
||||
stbi_uc *data = stbi_load(source_path, &width, &height, &nr_channels, 0);
|
||||
if (data) {
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
|
||||
@@ -5,7 +5,7 @@ struct Texture {
|
||||
unsigned int tex_id;
|
||||
int width;
|
||||
int height;
|
||||
auto init(const char* source_path) -> void;
|
||||
void init(const char* source_path);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
// Buffer layout:
|
||||
// X, Y, Z, U, V
|
||||
|
||||
pub const Shape = struct {
|
||||
indices: []c_uint,
|
||||
uv: []f32,
|
||||
xyz: []f32,
|
||||
};
|
||||
|
||||
const triangle_vertices = []f32{
|
||||
-0.5, -0.5, 0.0, 1.0, 1.0,
|
||||
0.5, -0.5, 0.0, 0.5, 0.5,
|
||||
0.0, 0.5, 0.0, 0.0, 0.0,
|
||||
};
|
||||
|
||||
const triangle_indices = []c_uint{ 0, 1, 2 };
|
||||
|
||||
const cube_vertices = []f32{ -0.5, -0.5, -0.5, 0.0, 0.0, 0.5, -0.5, -0.5, 1.0, 0.0, 0.5, 0.5, -0.5, 1.0, 1.0, 0.5, 0.5, -0.5, 1.0, 1.0, -0.5, 0.5, -0.5, 0.0, 1.0, -0.5, -0.5, -0.5, 0.0, 0.0, -0.5, -0.5, 0.5, 0.0, 0.0, 0.5, -0.5, 0.5, 1.0, 0.0, 0.5, 0.5, 0.5, 1.0, 1.0, 0.5, 0.5, 0.5, 1.0, 1.0, -0.5, 0.5, 0.5, 0.0, 1.0, -0.5, -0.5, 0.5, 0.0, 0.0, -0.5, 0.5, 0.5, 1.0, 0.0, -0.5, 0.5, -0.5, 1.0, 1.0, -0.5, -0.5, -0.5, 0.0, 1.0, -0.5, -0.5, -0.5, 0.0, 1.0, -0.5, -0.5, 0.5, 0.0, 0.0, -0.5, 0.5, 0.5, 1.0, 0.0, 0.5, 0.5, 0.5, 1.0, 0.0, 0.5, 0.5, -0.5, 1.0, 1.0, 0.5, -0.5, -0.5, 0.0, 1.0, 0.5, -0.5, -0.5, 0.0, 1.0, 0.5, -0.5, 0.5, 0.0, 0.0, 0.5, 0.5, 0.5, 1.0, 0.0, -0.5, -0.5, -0.5, 0.0, 1.0, 0.5, -0.5, -0.5, 1.0, 1.0, 0.5, -0.5, 0.5, 1.0, 0.0, 0.5, -0.5, 0.5, 1.0, 0.0, -0.5, -0.5, 0.5, 0.0, 0.0, -0.5, -0.5, -0.5, 0.0, 1.0, -0.5, 0.5, -0.5, 0.0, 1.0, 0.5, 0.5, -0.5, 1.0, 1.0, 0.5, 0.5, 0.5, 1.0, 0.0, 0.5, 0.5, 0.5, 1.0, 0.0, -0.5, 0.5, 0.5, 0.0, 0.0, -0.5, 0.5, -0.5, 0.0, 1.0 };
|
||||
|
||||
const cube_indices = []c_uint{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 };
|
||||
|
||||
const square_xyz = []f32{
|
||||
0.5, 0.5, 0.0,
|
||||
0.5, -0.5, 0.0,
|
||||
-0.5, -0.5, 0.0,
|
||||
-0.5, 0.5, 0.0,
|
||||
};
|
||||
|
||||
const square_uv = []f32{
|
||||
1.0, 1.0,
|
||||
1.0, 0.0,
|
||||
0.0, 0.0,
|
||||
0.0, 1.0,
|
||||
};
|
||||
|
||||
const square_indices = []c_uint{
|
||||
0, 1, 3,
|
||||
1, 2, 3,
|
||||
};
|
||||
|
||||
pub const TRIANGLE = Shape{
|
||||
.indices = triangle_indices,
|
||||
.uv = triangle_vertices,
|
||||
.xyz = triangle_vertices,
|
||||
};
|
||||
|
||||
pub const SQUARE = Shape{
|
||||
.indices = square_indices,
|
||||
.uv = square_uv,
|
||||
.xyz = square_xyz,
|
||||
};
|
||||
|
||||
pub const CUBE = Shape{
|
||||
.indices = cube_indices,
|
||||
.uv = triangle_vertices,
|
||||
.xyz = triangle_vertices,
|
||||
};
|
||||
@@ -1,20 +1,20 @@
|
||||
#include <array>
|
||||
#include "geometry.h"
|
||||
#include "../lib/djstdlib/core.h"
|
||||
|
||||
// Buffer layout:
|
||||
// X, Y, Z, U, V
|
||||
|
||||
auto triangle_vertices = std::to_array<float>({
|
||||
real32 triangle_vertices[] = {
|
||||
-0.5f, -0.5f, 0.0f, 1.0f, 1.0f,
|
||||
0.5f, -0.5f, 0.0f, 0.5f, 0.5f,
|
||||
0.0f, 0.5f, 0.0f, 0.0f, 0.0f,
|
||||
});
|
||||
};
|
||||
|
||||
auto triangle_indices = std::to_array<unsigned int>({
|
||||
uint32 triangle_indices[] = {
|
||||
0, 1, 2
|
||||
});
|
||||
};
|
||||
|
||||
auto cube_vertices = std::to_array<float>({
|
||||
real32 cube_vertices[] = {
|
||||
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f,
|
||||
0.5f, -0.5f, -0.5f, 1.0f, 0.0f,
|
||||
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
|
||||
@@ -56,57 +56,55 @@ auto cube_vertices = std::to_array<float>({
|
||||
0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
|
||||
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f,
|
||||
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f
|
||||
});
|
||||
};
|
||||
|
||||
auto cube_indices = std::to_array<unsigned int>({
|
||||
uint32 cube_indices[] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
||||
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
|
||||
});
|
||||
};
|
||||
|
||||
auto square_xyz = std::to_array<float>({
|
||||
real32 square_xyz[] = {
|
||||
0.5f, 0.5f, 0.0f,
|
||||
0.5f, -0.5f, 0.0f,
|
||||
-0.5f, -0.5f, 0.0f,
|
||||
-0.5f, 0.5f, 0.0f,
|
||||
});
|
||||
};
|
||||
|
||||
auto square_uv = std::to_array<float>({
|
||||
real32 square_uv[] = {
|
||||
1.0f, 1.0f,
|
||||
1.0f, 0.0f,
|
||||
0.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
});
|
||||
};
|
||||
|
||||
auto square_indices = std::to_array<unsigned int>({
|
||||
uint32 square_indices[] = {
|
||||
0, 1, 3,
|
||||
1, 2, 3,
|
||||
});
|
||||
};
|
||||
|
||||
namespace LeddaGeometry {
|
||||
const Shape TRIANGLE = {
|
||||
.indices = triangle_indices.data(),
|
||||
.indices_size = sizeof(triangle_indices),
|
||||
.uv = triangle_vertices.data(),
|
||||
.uv_size = sizeof(triangle_vertices),
|
||||
.xyz = triangle_vertices.data(),
|
||||
.xyz_size = sizeof(triangle_vertices),
|
||||
};
|
||||
const Shape TRIANGLE = {
|
||||
.indices = triangle_indices,
|
||||
.indices_size = ArrayCount(triangle_indices),
|
||||
.uv = triangle_vertices,
|
||||
.uv_size = ArrayCount(triangle_vertices),
|
||||
.xyz = triangle_vertices,
|
||||
.xyz_size = ArrayCount(triangle_vertices),
|
||||
};
|
||||
|
||||
const Shape SQUARE = {
|
||||
.indices = square_indices.data(),
|
||||
.indices_size = square_indices.size(),
|
||||
.uv = square_uv.data(),
|
||||
.uv_size = square_uv.size(),
|
||||
.xyz = square_xyz.data(),
|
||||
.xyz_size = square_xyz.size(),
|
||||
};
|
||||
const Shape SQUARE = {
|
||||
.indices = square_indices,
|
||||
.indices_size = ArrayCount(square_indices),
|
||||
.uv = square_uv,
|
||||
.uv_size = ArrayCount(square_uv),
|
||||
.xyz = square_xyz,
|
||||
.xyz_size = ArrayCount(square_xyz),
|
||||
};
|
||||
|
||||
const Shape CUBE = {
|
||||
.indices = cube_indices.data(),
|
||||
.indices_size = cube_indices.size(),
|
||||
.uv = triangle_vertices.data(),
|
||||
.uv_size = triangle_vertices.size(),
|
||||
.xyz = triangle_vertices.data(),
|
||||
.xyz_size = triangle_vertices.size(),
|
||||
};
|
||||
}
|
||||
const Shape CUBE = {
|
||||
.indices = cube_indices,
|
||||
.indices_size = ArrayCount(cube_indices),
|
||||
.uv = triangle_vertices,
|
||||
.uv_size = ArrayCount(triangle_vertices),
|
||||
.xyz = triangle_vertices,
|
||||
.xyz_size = ArrayCount(triangle_vertices),
|
||||
};
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
#ifndef LEDDA_GEOMETRY_H
|
||||
#define LEDDA_GEOMETRY_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <stddef.h>
|
||||
|
||||
namespace LeddaGeometry {
|
||||
struct Shape {
|
||||
unsigned int* indices;
|
||||
size_t indices_size;
|
||||
float* uv;
|
||||
size_t uv_size;
|
||||
float* xyz;
|
||||
size_t xyz_size;
|
||||
};
|
||||
extern const Shape TRIANGLE;
|
||||
extern const Shape SQUARE;
|
||||
extern const Shape CUBE;
|
||||
}
|
||||
struct Shape {
|
||||
unsigned int* indices;
|
||||
size_t indices_size;
|
||||
float* uv;
|
||||
size_t uv_size;
|
||||
float* xyz;
|
||||
size_t xyz_size;
|
||||
};
|
||||
extern const Shape TRIANGLE;
|
||||
extern const Shape SQUARE;
|
||||
extern const Shape CUBE;
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user