JacksEscape/render_bundle_draw.cpp

76 lines
1.8 KiB
C++
Raw Normal View History

2024-03-28 14:04:43 +08:00
#include "camera.h"
#include "render_bundle.h"
#include "app.h"
2024-03-30 18:55:43 +08:00
#include "render_util.h"
2024-03-28 14:04:43 +08:00
#include "util/vector.h"
#include <stdio.h>
#include <math.h>
#include <easyx.h>
2024-04-15 16:21:24 +08:00
#include <wingdi.h>
2024-03-28 14:04:43 +08:00
namespace {
vector_Vector *buff;
}
extern "C" void render_DrawPrimitiveW(App *app, render_Primitive *p, Vec2 offset) {
if (buff == NULL)
buff = vector_Create(sizeof(POINT));
vector_Clear(buff);
2024-03-30 21:25:39 +08:00
bool needDraw = false;
2024-03-28 14:04:43 +08:00
// Construct the points in screen space
for (int i = 0; i < vector_Size(p->points); i++) {
Vec2 realpos = vec2_Add(*((Vec2 *)vector_At(p->points, i)), offset);
Vec2 screenpos;
if (!app->camera) {
// Really weird
2024-04-15 16:21:24 +08:00
WARN("called without a Camera system");
2024-03-28 14:04:43 +08:00
screenpos = realpos;
2024-03-30 21:25:39 +08:00
needDraw = true;
} else {
2024-03-28 14:04:43 +08:00
screenpos = camera_TransformVec2(app->camera, realpos);
2024-03-30 21:25:39 +08:00
needDraw = needDraw || box2_Contains(app->camera->cam, realpos);
}
2024-03-28 14:04:43 +08:00
// Round the screen position to ints
POINT rounded;
rounded.x = (LONG)round(screenpos.x);
rounded.y = (LONG)round(screenpos.y);
vector_Push(buff, &rounded);
}
2024-03-30 21:25:39 +08:00
// See if any of the points are in the camera box
if (needDraw) {
// Set the colors
render_SetModes(p->mode, time_Now());
2024-03-28 14:04:43 +08:00
2024-03-30 21:25:39 +08:00
// Draw the converted primitive
switch (p->type) {
case render_Lines:
if (vector_Size(buff) % 2 != 0)
WARN("render_Lines drawed odd numbers of points", 0);
for (int i = 0; i < vector_Size(buff) - 1; i += 2) {
POINT p0 = *(POINT *)vector_At(buff, i);
POINT p1 = *(POINT *)vector_At(buff, i + 1);
line(p0.x, p0.y, p1.x, p1.y);
}
break;
case render_LineStrip:
for (int i = 0; i < vector_Size(buff) - 1; i++) {
POINT p0 = *(POINT *)vector_At(buff, i);
POINT p1 = *(POINT *)vector_At(buff, i + 1);
line(p0.x, p0.y, p1.x, p1.y);
}
break;
case render_Polygon:
fillpolygon((POINT *)vector_Data(buff), vector_Size(buff));
break;
}
2024-03-28 14:04:43 +08:00
}
}