feat: added the ability to render whole model
This commit is contained in:
48
renderer.hpp
48
renderer.hpp
@@ -3,6 +3,7 @@
|
||||
#define RENDERER_H
|
||||
|
||||
#include "fastmath.hpp"
|
||||
#include "model.hpp"
|
||||
#include "polygon.hpp"
|
||||
#include "rendertarget.hpp"
|
||||
#include <memory.h>
|
||||
@@ -15,26 +16,49 @@ class Renderer {
|
||||
bool clearTarget = true;
|
||||
Renderer() : clearTarget(false) {}
|
||||
|
||||
void render(polygon *p) {
|
||||
decimal widthScale = decimal(1.0) / decimal((float)target->width);
|
||||
decimal heightScale = decimal(1.0) / decimal((float)target->height);
|
||||
void toScreenSpace(polygon *p) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
p->points[i].x() =
|
||||
p->points[i].x() / p->points[i].z() * decimal(8.0) +
|
||||
decimal(8.0);
|
||||
p->points[i].y() =
|
||||
p->points[i].y() / p->points[i].z() * decimal(8.0) +
|
||||
decimal(8.0);
|
||||
p->points[i].z() = decimal(1.0);
|
||||
}
|
||||
}
|
||||
|
||||
void render(const model *model) {
|
||||
decimal widthScale = decimal(16.0) / decimal((float)target->width);
|
||||
decimal heightScale = decimal(16.0) / decimal((float)target->height);
|
||||
// std::cout << widthScale << std::endl;
|
||||
vec3 pos = vec3();
|
||||
|
||||
if (clearTarget) {
|
||||
memset((wchar_t *)target->pixels, 0,
|
||||
target->height * target->width * sizeof(target[0]));
|
||||
}
|
||||
|
||||
for (int x = 0; x < target->height; x++) {
|
||||
for (int y = 0; y < target->height; y++) {
|
||||
if (p->contains(pos)) {
|
||||
target->set(x, y, vec3(0.0, 255.0, 0.0));
|
||||
}
|
||||
pos.y() += heightScale;
|
||||
polygon testP;
|
||||
|
||||
for (int f = 0; f < model->faces.size(); f += 3) {
|
||||
for (int p = 0; p < 3; p++) {
|
||||
testP.points[p] = model->verts[model->faces[f + p]];
|
||||
}
|
||||
|
||||
toScreenSpace(&testP);
|
||||
|
||||
testP.calcDelta();
|
||||
vec3 pos = vec3();
|
||||
for (int x = 0; x < target->height; x++) {
|
||||
for (int y = 0; y < target->height; y++) {
|
||||
if (testP.contains(pos)) {
|
||||
target->set(x, y, vec3(0.0, 255.0, 0.0));
|
||||
}
|
||||
pos.y() += heightScale;
|
||||
}
|
||||
pos.y() = decimal(0);
|
||||
pos.x() += widthScale;
|
||||
}
|
||||
pos.y() = decimal(0);
|
||||
pos.x() += widthScale;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user