- Ja carrega els patch, pero les textures es veuen mal. Arreglant mil coses del motor que tenia a foc pintar textures de 64x64

This commit is contained in:
2026-02-27 08:05:24 +01:00
parent 8dbcd4fcb7
commit 8e46fa85b2
4 changed files with 58 additions and 20 deletions

View File

@@ -6,7 +6,7 @@
#include "draw.h"
#include "wad.h"
#define FOV 190
#define FOV 277
struct wall {
Uint16 v1, v2;
@@ -50,7 +50,7 @@ void createMap()
{
sector s;
s.floor_height = 32.0f;
s.ceiling_height = 128.0f;
s.ceiling_height = 96.0f;
s.verts.push_back({ 64.0f, 0.0f});
s.verts.push_back({256.0f, 0.0f});
@@ -75,7 +75,7 @@ void createMap()
{
sector s;
s.floor_height = 0.0f;
s.ceiling_height = 96.0f;
s.ceiling_height = 128.0f;
s.verts.push_back({256.0f, 0.0f});
s.verts.push_back({ 64.0f, 0.0f});
@@ -103,7 +103,8 @@ void createMap()
{
for (auto &w : s.walls )
{
w.u2 = distance(s.verts[w.v1], s.verts[w.v2]) / 64.0f;
w.u2 = distance(s.verts[w.v1], s.verts[w.v2]) / 8.0f;
//w.v2 = distance(s.verts[w.v1], s.verts[w.v2]) / 32.0f;
vec2 norm = { s.verts[w.v2].x - s.verts[w.v1].x, s.verts[w.v2].y - s.verts[w.v1].y};
normalize(&norm);
const float tmp = norm.x; norm.x = -norm.y; norm.y = tmp;
@@ -135,18 +136,18 @@ void drawColumn(sector &s, int screen_column, int start, int end, float a_inc, v
}
if (w)
{
const int tex_height = 64;
//const int tex_height = gif->h; //64;
const float sector_height = s.ceiling_height - s.floor_height;
draw::map::putp(result.x, result.y, 6);
float dist = stright_dist * SDL_cosf(a_inc*DEG_TO_RAD);
const vec2 AB = {s.verts[w->v2].x-s.verts[w->v1].x, s.verts[w->v2].y-s.verts[w->v1].y};
const vec2 AP = {result.x-s.verts[w->v1].x, result.y-s.verts[w->v1].y};
float v = dot(AP,AB) / dot(AB,AB); v *= w->u2; v = (v-int(v))*tex_height;
float v = dot(AP,AB) / dot(AB,AB); v *= w->u2; v = v*gif->w; //(v-int(v))*gif->w;
float wall_height = (sector_height*FOV)/dist; // [64=altura sector]
float wall_cut = 0.0f;
float dpix = tex_height/wall_height; // [64=crec que altura sector]
float dpix = sector_height/wall_height; // [64=crec que altura sector]
float cpix = 0;
float wall_start = 120-(wall_height/sector_height)*(sector_height-(height-s.floor_height)); // [64=els dos crec que altura sector]
if (wall_start<start) {
@@ -160,9 +161,9 @@ void drawColumn(sector &s, int screen_column, int start, int end, float a_inc, v
for (int y=start; y<wall_start-1; y++) {
float straight_dist = (FOV * (sector_height-(height-s.floor_height))) / (y - (240 >> 1));
float actual_dist = straight_dist / SDL_cosf(a_inc*DEG_TO_RAD);
int tx = SDL_abs(int(actual_dist * SDL_cosf(angle*DEG_TO_RAD) - position.x)) % tex_height;
int ty = SDL_abs(int(actual_dist * SDL_sinf(angle*DEG_TO_RAD) - position.y)) % tex_height;
draw::putpd(screen_column, y, gif->pixels[tx+ty*tex_height], -straight_dist);
int tx = SDL_abs(int(actual_dist * SDL_cosf(angle*DEG_TO_RAD) - position.x)) % gif->w;
int ty = SDL_abs(int(actual_dist * SDL_sinf(angle*DEG_TO_RAD) - position.y)) % gif->h;
draw::putpd(screen_column, y, gif->pixels[tx+ty*gif->w], -straight_dist);
}
@@ -171,7 +172,7 @@ void drawColumn(sector &s, int screen_column, int start, int end, float a_inc, v
// Pinta la pared
for (int i=0; i<wall_height; ++i) {
if (wall_start+i>=end) break;
draw::putpd(screen_column, wall_start+i, gif->pixels[(int(v)%tex_height)+int(cpix)*tex_height], stright_dist);
draw::putpd(screen_column, wall_start+i, gif->pixels[(int(v)%gif->w)+(int(cpix)%gif->h)*gif->w], stright_dist);
cpix += dpix;
}
} else {
@@ -185,7 +186,7 @@ void drawColumn(sector &s, int screen_column, int start, int end, float a_inc, v
// Pinta la pared
for (int i=0; i<upper_wall_height; ++i) {
if (wall_start+i>=end) break;
draw::putpd(screen_column, wall_start+i, gif->pixels[(int(v)%tex_height)+int(cpix)*tex_height], stright_dist);
draw::putpd(screen_column, wall_start+i, gif->pixels[(int(v)%gif->w)+(int(cpix)%gif->h)*gif->w], stright_dist);
cpix += dpix;
}
wall_start += upper_wall_height;
@@ -206,7 +207,7 @@ void drawColumn(sector &s, int screen_column, int start, int end, float a_inc, v
// Pinta la pared
for (int i=0; i<lower_wall_height; ++i) {
if (wall_end+i>=end) break;
draw::putpd(screen_column, wall_end+i, gif->pixels[(int(v)%tex_height)+int(cpix)*tex_height], stright_dist);
draw::putpd(screen_column, wall_end+i, gif->pixels[(int(v)%gif->w)+(int(cpix)%gif->h)*gif->w], stright_dist);
cpix += dpix;
}
//wall_start += upper_wall_height;
@@ -220,9 +221,9 @@ void drawColumn(sector &s, int screen_column, int start, int end, float a_inc, v
for (int y=paint_end+1; y<end-1; y++) {
float straight_dist = (FOV * (height-s.floor_height)) / (y - (240 >> 1));
float actual_dist = straight_dist / SDL_cosf(a_inc*DEG_TO_RAD);
int tx = SDL_abs(int(actual_dist * SDL_cosf(angle*DEG_TO_RAD) + position.x)) % tex_height;
int ty = SDL_abs(int(actual_dist * SDL_sinf(angle*DEG_TO_RAD) + position.y)) % tex_height;
draw::putpd(screen_column, y, gif->pixels[tx+ty*tex_height], straight_dist);
int tx = SDL_abs(int(actual_dist * SDL_cosf(angle*DEG_TO_RAD) + position.x)) % gif->w;
int ty = SDL_abs(int(actual_dist * SDL_sinf(angle*DEG_TO_RAD) + position.y)) % gif->h;
draw::putpd(screen_column, y, gif->pixels[tx+ty*gif->w], straight_dist);
}
//line(screen_column, 120-(wall_height), screen_column, 120+(wall_height), 5);
}
@@ -279,7 +280,10 @@ int main(int argc, char *argv[])
draw::init();
gif = wad::loadFlat("FLOOR4_8"); //draw::loadgif("walls.gif");
//gif = draw::loadgif("walls.gif");
//gif = wad::loadFlat("FLOOR4_8");
//gif = wad::loadTexture("COMPSPAN");
gif = wad::loadPatch("TTALL1_2");
//palette = draw::loadpal("walls.gif");
palette = wad::loadPalette(0);
draw::setpal(palette);