render obj file

This commit is contained in:
2026-02-18 23:07:53 -06:00
parent da1292d9e5
commit fec99fc737
31 changed files with 2138 additions and 170 deletions

View File

@@ -12,14 +12,16 @@ namespace Archimedes {
class Body : public Object {
public:
Body(RenderTarget rt, glm::mat4 t = glm::mat4(1.0f)) : mesh(rt), Object(t) {};
Body(RenderTarget rt, glm::mat4 t = glm::mat4(1.0f)) : Object(t), mesh(rt) {};
Body(VertexBuffer vb, IndexArray ia, VertexLayout vl, Shader s, glm::mat4 t = glm::mat4(1.0f))
: mesh(vb, ia, vl, s), Object(t) {}
: Object(t), mesh(vb, ia, vl, s) {}
Body() {}
Body() : Object(glm::mat4(1.0f)) {}
~Body() {};
RenderTarget& getMesh() { return mesh; }
private:

View File

@@ -12,7 +12,7 @@ namespace Archimedes {
class Camera : public Object {
public:
Camera() {}
Camera() : Object(glm::mat4(1.0f)) {}
Camera(glm::mat4 t)
: Object(t) {}

View File

@@ -13,22 +13,57 @@ namespace Archimedes {
public:
Object() {};
Object(glm::mat4 t)
: worldTransform(t) {}
~Object() {};
///scales an object absolutely
//void scaleTo() {}
void scaleRel(float scale) { worldTransform = glm::scale(worldTransform, glm::vec3(scale)); }
///scale factors less than zero do nothing
float scaleTo(float s) {
if(s > 0) {
worldTransform = glm::scale(worldTransform, glm::vec3(s / scale));
scale = s;
}
//void moveTo(glm::vec3 pos) { worldTransform = glm::translate(worldTransform, pos); }
void moveRel(glm::vec3 pos) { worldTransform = glm::translate(worldTransform, pos); }
return scale;
}
//void rotateTo() {}
void rotateRel(float radians, glm::vec3 axis) { worldTransform = glm::rotate(worldTransform, radians, axis); }
float scaleRel(float s) {
return scaleTo(scale * s);
}
float scaleAdd(float s) {
return scaleTo(scale + s);
}
glm::vec3 moveTo(glm::vec3 pos) {
worldTransform = glm::translate(worldTransform, pos - position);
position = pos;
return position;
}
glm::vec3 moveRel(glm::vec3 pos) {
return moveTo(pos + position);
}
glm::vec3 rotateTo(glm::vec3 angles) {
worldTransform = glm::rotate(worldTransform, angles.x - rotation.x, glm::vec3(1.0f, 0.0f, 0.0f));
worldTransform = glm::rotate(worldTransform, angles.y - rotation.y, glm::vec3(0.0f, 1.0f, 0.0f));
worldTransform = glm::rotate(worldTransform, angles.z - rotation.z, glm::vec3(0.0f, 0.0f, 1.0f));
rotation = angles;
return rotation;
}
glm::vec3 rotateRel(glm::vec3 angles) {
return rotateTo(angles + rotation);
}
glm::vec3& getPosition() { return position; }
glm::vec3& getRotation() { return rotation; }
float& getScale() { return scale; }
const glm::mat4& getTransform() { return worldTransform; }
@@ -36,6 +71,7 @@ namespace Archimedes {
glm::vec3 position = glm::vec3(0);
glm::vec3 rotation = glm::vec3(0);
float scale = 1.0f;
glm::mat4 worldTransform = glm::mat4(1.0f);

View File

@@ -41,20 +41,19 @@ namespace Archimedes {
class VertexBuffer {
public:
VertexBuffer(const void* data, size_t size) : data(data), size(size) {
VertexBuffer(const std::vector<float> data) : data(data) {
}
VertexBuffer() {}
~VertexBuffer() {}
const void* getData() const { return data; }
size_t getSize() const { return size; }
const void* getData() const { return data.data(); }
size_t getSize() const { return data.size() * sizeof(float); }
unsigned int id;
private:
const void* data;
size_t size;
std::vector<float> data;
};
class VertexArray {
@@ -73,20 +72,19 @@ namespace Archimedes {
class IndexArray {
public:
IndexArray(const unsigned int* indices, size_t count) : indices(indices), count(count) {
IndexArray(const std::vector<unsigned int> indices) : indices(indices) {
}
IndexArray() {}
~IndexArray() {}
const void* getIndicies() const { return indices; }
size_t getCount() const { return count; }
const void* getIndicies() const { return indices.data(); }
size_t getCount() const { return indices.size(); }
unsigned int id;
private:
const unsigned int* indices;
size_t count;
std::vector<unsigned int> indices;
};
class Shader {
@@ -156,9 +154,9 @@ namespace Archimedes {
class RenderTarget {
public:
RenderTarget(const void* data, size_t size, unsigned int* indices, size_t count, VertexLayout layout, const std::string& vs, const std::string& fs)
: vertexBuffer(data, size),
indexArray(indices, count),
RenderTarget(const std::vector<float> data, const std::vector<unsigned int> indices, VertexLayout layout, const std::string& vs, const std::string& fs)
: vertexBuffer(data),
indexArray(indices),
layout(layout),
shader(vs, fs, Shader::LoadType::FromFileSource) {
@@ -188,7 +186,6 @@ namespace Archimedes {
Shader shader;
glm::mat4 transform = glm::mat4(1.0f);
};
}

View File

@@ -50,7 +50,14 @@ namespace Archimedes {
virtual void freeRenderTarget(RenderTarget& rt) = 0;
virtual void draw(const RenderTarget& rt, glm::vec4 color = { 1.0f, 0.0f, 1.0f, 1.0f }, RenderMode mode = RenderMode::Triangles) = 0;
virtual void draw(
const RenderTarget& rt,
const glm::mat4 world = glm::mat4(1.0f),
const glm::mat4 view = glm::mat4(1.0f),
const glm::mat4 proj = glm::mat4(1.0f),
glm::vec4 color = { 1.0f, 0.0f, 1.0f, 1.0f },
RenderMode mode = RenderMode::Triangles
) = 0;
virtual Renderer* getRendererImpl() = 0;

View File

@@ -211,16 +211,25 @@ namespace Archimedes {
glDeleteBuffers(1, &rt.indexArray.id);
};
void draw(const RenderTarget& rt, glm::vec4 color = { 1.0f, 0.0f, 1.0f, 1.0f }, RenderMode mode = RenderMode::Triangles) override {
void draw(
const RenderTarget& rt,
const glm::mat4 world = glm::mat4(1.0f),
const glm::mat4 view = glm::mat4(1.0f),
const glm::mat4 proj = glm::mat4(1.0f),
glm::vec4 color = { 1.0f, 0.0f, 1.0f, 1.0f },
RenderMode mode = RenderMode::Triangles
) override {
glUseProgram(rt.shader.id);
unsigned int transformLoc = glGetUniformLocation(rt.shader.id, "model");
glUniformMatrix4fv(transformLoc, 1, GL_FALSE, glm::value_ptr(rt.transform));
unsigned int modelLoc = glGetUniformLocation(rt.shader.id, "model");
glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(world));
unsigned int viewLoc = glGetUniformLocation(rt.shader.id, "view");
glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));
unsigned int resLoc = glGetUniformLocation(rt.shader.id, "res");
glUniform2ui(resLoc, w, h);
unsigned int projLoc = glGetUniformLocation(rt.shader.id, "proj");
glUniformMatrix4fv(projLoc, 1, GL_FALSE, glm::value_ptr(proj));
unsigned int colorLoc = glGetUniformLocation(rt.shader.id, "color");
glUniform4f(colorLoc, color.r, color.g, color.b, color.a);

View File

@@ -1,21 +0,0 @@
#ifndef RENDERER_CONCEPTS
#define RENDERER_CONCEPTS
#include "pch.hpp"
namespace Archimedes {
class RendererOpenGL;
class RendererSDL3;
template <class RendererImpl>
concept allowed_renderers = requires (RendererImpl r) {
#ifndef CUSTOM_RENDERER
requires std::same_as<RendererImpl, RendererOpenGL>
|| std::same_as<RendererImpl, RendererSDL3>;
#endif
};
}
#endif

View File

@@ -1,25 +0,0 @@
#ifndef WINDOW_CONCEPTS
#define WINDOW_CONCEPTS
#include "pch.hpp"
#include "utils/Renderer/concepts.h"
namespace Archimedes {
template <class R>
class WindowGLFW;
template <class R>
class WindowSDL3;
template <class WindowImpl, class R>
concept allowed_windows = requires (WindowImpl a, R b) {
#ifndef CUSTOM_WINDOW
requires std::same_as<WindowImpl, WindowGLFW<R>>
|| std::same_as<WindowImpl, WindowSDL3<R>>;
#endif
};
}
#endif