perfection

This commit is contained in:
Marc
2023-01-21 19:17:51 +01:00
parent 3a4dbbe9b8
commit 5c6b6513c3
9 changed files with 124 additions and 41 deletions
+13 -19
View File
@@ -13,30 +13,24 @@ static int compartSort(const SceneObject_t * a, const SceneObject_t * b) {
void scene_render(const Scene_t * scene) {
MonitorSize_t monitorSize = renderer_getMonitorSize();
int minScanX = scene->x - CAMERA_WIDTH;
int minScanY = scene->y - CAMERA_HEIGHT;
int maxScanX = scene->x + CAMERA_WIDTH;
int maxScanY = scene->y + CAMERA_HEIGHT;
for(int i = 0; i < scene->objectCount; i++) {
const SceneObject_t * object = &scene->objects[i];
if(object->x > minScanX && object->x < maxScanX && object->y > minScanY && object->y < maxScanY) {
float x = (object->x) / CAMERA_WIDTH;
float y = (object->y) / CAMERA_HEIGHT;
//the object is to be rendered
float x = (object->x - scene->x) / CAMERA_WIDTH;
float y = (object->y - scene->y) / CAMERA_HEIGHT;
//the object is to be rendered
SDL_Rect rect = {
round(x * monitorSize.width) ,
round(y * monitorSize.height),
round(object->renderObj.width * monitorSize.width),
round(object->renderObj.height * monitorSize.height)
};
SDL_Rect rect = {
round(x * monitorSize.width) ,
round(y * monitorSize.height),
round(object->renderObj.width * monitorSize.width),
round(object->renderObj.height * monitorSize.height)
};
int error = SDL_RenderCopyEx(renderer, object->cache, NULL, &rect, object->renderObj.angle_degre, NULL, SDL_FLIP_NONE);
if(error != 0) {
fprintf(stderr, "Render error in object %d with error %s\n", object->id, SDL_GetError());
exit(1);
}
int error = SDL_RenderCopyEx(renderer, object->cache, NULL, &rect, object->renderObj.angle_degre, NULL, SDL_FLIP_NONE);
if(error != 0) {
fprintf(stderr, "Render error in object %d with error %s\n", object->id, SDL_GetError());
exit(1);
}
}
}