mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-29 07:22:05 +00:00
Add basic voxel drawing showing how to use the input data structures
This commit is contained in:
parent
2901e2d834
commit
100b80143a
2 changed files with 59 additions and 6 deletions
|
@ -54,20 +54,68 @@ namespace swrenderer
|
|||
double sprite_yscale = sprite->yscale;
|
||||
FVoxel *voxel = sprite->voxel;
|
||||
|
||||
// To do: calculate the mipmap level based on distance, sprite scale and voxel extents
|
||||
int miplevel = 0;//voxel->NumMips;
|
||||
|
||||
const FVoxelMipLevel &mip = voxel->Mips[miplevel];
|
||||
if (mip.SlabData == nullptr)
|
||||
return;
|
||||
|
||||
/*
|
||||
double spriteSin = sprite_angle.Sin();
|
||||
double spriteCos = sprite_angle.Cos();
|
||||
double pivotX = (mip.Pivot.X * spriteSin - mip.Pivot.Y * spriteCos);
|
||||
double pivotY = (mip.Pivot.X * spriteCos + mip.Pivot.Y * spriteSin);
|
||||
double pivotZ = -mip.Pivot.Z;
|
||||
*/
|
||||
|
||||
R_FillBox(sprite_origin, 5.0 * sprite_xscale, 5.0 * sprite_yscale, 16, cliptop, clipbottom, false, false);
|
||||
DVector2 dirX(spriteSin * sprite_xscale, -spriteCos * sprite_xscale);
|
||||
DVector2 dirY(spriteCos * sprite_xscale, spriteSin * sprite_xscale);
|
||||
float dirZ = -sprite_yscale;
|
||||
|
||||
DVector3 voxel_origin = sprite_origin;
|
||||
voxel_origin.X -= dirX.X * mip.Pivot.X + dirX.Y * mip.Pivot.Y;
|
||||
voxel_origin.Y -= dirY.X * mip.Pivot.X + dirY.Y * mip.Pivot.Y;
|
||||
voxel_origin.Z -= dirZ * mip.Pivot.Z;
|
||||
|
||||
// To do: do this loop sorted back to front:
|
||||
|
||||
for (int x = 0; x < mip.SizeX; x++)
|
||||
{
|
||||
for (int y = 0; y < mip.SizeY; y++)
|
||||
{
|
||||
kvxslab_t *slab_start = R_GetSlabStart(mip, x, y);
|
||||
kvxslab_t *slab_end = R_GetSlabEnd(mip, x, y);
|
||||
|
||||
for (kvxslab_t *slab = slab_start; slab != slab_end; slab = R_NextSlab(slab))
|
||||
{
|
||||
// To do: check slab->backfacecull
|
||||
|
||||
for (int i = 0; i < slab->zleng; i++)
|
||||
{
|
||||
int z = slab->ztop + i;
|
||||
uint8_t color = slab->col[i];
|
||||
|
||||
DVector3 voxel_pos = voxel_origin;
|
||||
voxel_pos.X += dirX.X * x + dirX.Y * y;
|
||||
voxel_pos.Y += dirY.X * x + dirY.Y * y;
|
||||
voxel_pos.Z += dirZ * z;
|
||||
|
||||
R_FillBox(voxel_pos, sprite_xscale, sprite_yscale, color, cliptop, clipbottom, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
kvxslab_t *R_GetSlabStart(const FVoxelMipLevel &mip, int x, int y)
|
||||
{
|
||||
return (kvxslab_t *)&mip.SlabData[mip.OffsetX[x] + (int)mip.OffsetXY[x * (mip.SizeY + 1) + y]];
|
||||
}
|
||||
|
||||
kvxslab_t *R_GetSlabEnd(const FVoxelMipLevel &mip, int x, int y)
|
||||
{
|
||||
return R_GetSlabStart(mip, x, y + 1);
|
||||
}
|
||||
|
||||
kvxslab_t *R_NextSlab(kvxslab_t *slab)
|
||||
{
|
||||
return (kvxslab_t*)(((uint8_t*)slab) + 3 + slab->zleng);
|
||||
}
|
||||
|
||||
void R_FillBox(DVector3 origin, double extentX, double extentY, int color, short *cliptop, short *clipbottom, bool viewspace, bool pixelstretch)
|
||||
|
|
|
@ -22,10 +22,15 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
struct kvxslab_t;
|
||||
|
||||
namespace swrenderer
|
||||
{
|
||||
struct vissprite_t;
|
||||
|
||||
void R_DrawVisVoxel(vissprite_t *sprite, int minZ, int maxZ, short *cliptop, short *clipbottom);
|
||||
void R_FillBox(DVector3 origin, double extentX, double extentY, int color, short *cliptop, short *clipbottom, bool viewspace, bool pixelstretch);
|
||||
kvxslab_t *R_GetSlabStart(const FVoxelMipLevel &mip, int x, int y);
|
||||
kvxslab_t *R_GetSlabEnd(const FVoxelMipLevel &mip, int x, int y);
|
||||
kvxslab_t *R_NextSlab(kvxslab_t *slab);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue