Skip to content

Commit

Permalink
Plane rotation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dashodanger committed Oct 10, 2023
1 parent b641496 commit 0fde8d6
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ Bugs fixed
- Fixed region properties not working properly with a vertex sloped floor that rises above its sector's original floor height
- Fixed occasional sector glow thing link/unlink errors
- Fixed AJBSP using self-referencing linedefs that were perfectly vertical or horizontal for partitioning
- Fixed floor/ceiling rotation not working when using images that have a different width and height
12 changes: 12 additions & 0 deletions source_files/edge/m_math.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,17 @@ int M_PointInTri(vec2_t v1, vec2_t v2, vec2_t v3, vec2_t test)
return c;
}

void M_Vec2Rotate(vec2_t &vec, const angle_t &ang)
{
float s = M_Sin(ang);
float c = M_Cos(ang);

float ox = vec.x;
float oy = vec.y;

vec.x = ox * c - oy * s;
vec.y = oy * c + ox * s;
}

//--- editor settings ---
// vi:ts=4:sw=4:noexpandtab
1 change: 1 addition & 0 deletions source_files/edge/m_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ float M_Cos(angle_t ang) GCCATTR((const));
float M_Sin(angle_t ang) GCCATTR((const));
void M_Angle2Matrix(angle_t ang, vec2_t *x, vec2_t *y);
int M_PointInTri(vec2_t v1, vec2_t v2, vec2_t v3, vec2_t test);
void M_Vec2Rotate(vec2_t &vec, const angle_t &ang);


#endif //__M_MATH_H__
Expand Down
12 changes: 6 additions & 6 deletions source_files/edge/p_setup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1594,16 +1594,16 @@ static void LoadUDMFSectors()

// rotations
if (!AlmostEquals(rf, 0.0f))
M_Angle2Matrix(FLOAT_2_ANG(rf), &ss->floor.x_mat, &ss->floor.y_mat);
ss->floor.rotation = FLOAT_2_ANG(rf);

if (!AlmostEquals(rc, 0.0f))
M_Angle2Matrix(FLOAT_2_ANG(rc), &ss->ceil.x_mat, &ss->ceil.y_mat);
ss->ceil.rotation = FLOAT_2_ANG(rc);

// granular scaling
ss->floor.x_mat.x *= fx_sc;
ss->floor.y_mat.y *= fy_sc;
ss->ceil.x_mat.x *= cx_sc;
ss->ceil.y_mat.y *= cy_sc;
ss->floor.x_mat.x = fx_sc;
ss->floor.y_mat.y = fy_sc;
ss->ceil.x_mat.x = cx_sc;
ss->ceil.y_mat.y = cy_sc;

ss->floor.image = W_ImageLookup(floor_tex, INS_Flat);

Expand Down
4 changes: 2 additions & 2 deletions source_files/edge/p_spec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ static void P_SectorEffect(sector_t *target, line_t *source, const linetype_c *s
target->floor.offset.x += source->side[0]->bottom.offset.x;
target->floor.offset.y += source->side[0]->bottom.offset.y;
}
M_Angle2Matrix(angle, &target->floor.x_mat, &target->floor.y_mat);
target->floor.rotation = angle;
}
if (special->sector_effect & SECTFX_AlignCeiling)
{
Expand All @@ -955,7 +955,7 @@ static void P_SectorEffect(sector_t *target, line_t *source, const linetype_c *s
target->ceil.offset.x += source->side[0]->bottom.offset.x;
target->ceil.offset.y += source->side[0]->bottom.offset.y;
}
M_Angle2Matrix(angle, &target->ceil.x_mat, &target->ceil.y_mat);
target->ceil.rotation = angle;
}

// set texture scale
Expand Down
1 change: 1 addition & 0 deletions source_files/edge/r_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ typedef struct surface_s
// texturing matrix (usually identity)
vec2_t x_mat;
vec2_t y_mat;
angle_t rotation = 0;

// current offset and scrolling deltas (world coords)
vec2_t offset;
Expand Down
16 changes: 12 additions & 4 deletions source_files/edge/r_render.cc
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,8 @@ typedef struct
float bob_amount = 0;

slope_plane_t *slope;

angle_t rotation = 0;
}
plane_coord_data_t;

Expand All @@ -789,11 +791,16 @@ static void PlaneCoordFunc(void *d, int v_idx,
rgb[2] = data->B;
}

float rx = (data->tx0 + pos->x) / data->image_w;
float ry = (data->ty0 + pos->y) / data->image_h;
vec2_t rxy = {(data->tx0 + pos->x), (data->ty0 + pos->y)};

texc->x = rx * data->x_mat.x + ry * data->x_mat.y;
texc->y = rx * data->y_mat.x + ry * data->y_mat.y;
if (data->rotation)
M_Vec2Rotate(rxy, data->rotation);

rxy.x /= data->image_w;
rxy.y /= data->image_h;

texc->x = rxy.x * data->x_mat.x + rxy.y * data->x_mat.y;
texc->y = rxy.x * data->y_mat.x + rxy.y * data->y_mat.y;

if (swirl_pass > 0)
CalcTurbulentTexCoords(texc, pos);
Expand Down Expand Up @@ -2642,6 +2649,7 @@ static void RGL_DrawPlane(drawfloor_t *dfloor, float h,
data.blending = blending;
data.trans = trans;
data.slope = slope;
data.rotation = surf->rotation;

if (cur_sub->sector->props.special)
{
Expand Down

0 comments on commit 0fde8d6

Please sign in to comment.