Browse Source

ref_soft: Triangle drawing

pull/2/head
mittorn 6 years ago
parent
commit
9ba39f65b3
  1. 1077
      adivtab.h
  2. 323
      r_aclip.c
  3. 34
      r_local.h
  4. 47
      r_main.c
  5. 16
      r_misc.c
  6. 1612
      r_polyse.c
  7. 229
      r_trialias.c

1077
adivtab.h

File diff suppressed because it is too large Load Diff

323
r_aclip.c

@ -0,0 +1,323 @@
/*
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// r_aclip.c: clip routines for drawing Alias models directly to the screen
#include "r_local.h"
static finalvert_t fv[2][8];
void R_AliasProjectAndClipTestFinalVert (finalvert_t *fv);
void R_Alias_clip_top (finalvert_t *pfv0, finalvert_t *pfv1,
finalvert_t *out);
void R_Alias_clip_bottom (finalvert_t *pfv0, finalvert_t *pfv1,
finalvert_t *out);
void R_Alias_clip_left (finalvert_t *pfv0, finalvert_t *pfv1,
finalvert_t *out);
void R_Alias_clip_right (finalvert_t *pfv0, finalvert_t *pfv1,
finalvert_t *out);
/*
================
R_Alias_clip_z
pfv0 is the unclipped vertex, pfv1 is the z-clipped vertex
================
*/
void R_Alias_clip_z (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
{
float scale;
scale = (ALIAS_Z_CLIP_PLANE - pfv0->xyz[2]) /
(pfv1->xyz[2] - pfv0->xyz[2]);
out->xyz[0] = pfv0->xyz[0] + (pfv1->xyz[0] - pfv0->xyz[0]) * scale;
out->xyz[1] = pfv0->xyz[1] + (pfv1->xyz[1] - pfv0->xyz[1]) * scale;
out->xyz[2] = ALIAS_Z_CLIP_PLANE;
out->s = pfv0->s + (pfv1->s - pfv0->s) * scale;
out->t = pfv0->t + (pfv1->t - pfv0->t) * scale;
out->l = pfv0->l + (pfv1->l - pfv0->l) * scale;
R_AliasProjectAndClipTestFinalVert (out);
}
#if !id386
void R_Alias_clip_left (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
{
float scale;
if (pfv0->v >= pfv1->v )
{
scale = (float)(RI.aliasvrect.x - pfv0->u) /
(pfv1->u - pfv0->u);
out->u = pfv0->u + ( pfv1->u - pfv0->u ) * scale + 0.5;
out->v = pfv0->v + ( pfv1->v - pfv0->v ) * scale + 0.5;
out->s = pfv0->s + ( pfv1->s - pfv0->s ) * scale + 0.5;
out->t = pfv0->t + ( pfv1->t - pfv0->t ) * scale + 0.5;
out->l = pfv0->l + ( pfv1->l - pfv0->l ) * scale + 0.5;
out->zi = pfv0->zi + ( pfv1->zi - pfv0->zi) * scale + 0.5;
}
else
{
scale = (float)(RI.aliasvrect.x - pfv1->u) /
(pfv0->u - pfv1->u);
out->u = pfv1->u + ( pfv0->u - pfv1->u ) * scale + 0.5;
out->v = pfv1->v + ( pfv0->v - pfv1->v ) * scale + 0.5;
out->s = pfv1->s + ( pfv0->s - pfv1->s ) * scale + 0.5;
out->t = pfv1->t + ( pfv0->t - pfv1->t ) * scale + 0.5;
out->l = pfv1->l + ( pfv0->l - pfv1->l ) * scale + 0.5;
out->zi = pfv1->zi + ( pfv0->zi - pfv1->zi) * scale + 0.5;
}
}
void R_Alias_clip_right (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
{
float scale;
if ( pfv0->v >= pfv1->v )
{
scale = (float)(RI.aliasvrectright - pfv0->u ) /
(pfv1->u - pfv0->u );
out->u = pfv0->u + ( pfv1->u - pfv0->u ) * scale + 0.5;
out->v = pfv0->v + ( pfv1->v - pfv0->v ) * scale + 0.5;
out->s = pfv0->s + ( pfv1->s - pfv0->s ) * scale + 0.5;
out->t = pfv0->t + ( pfv1->t - pfv0->t ) * scale + 0.5;
out->l = pfv0->l + ( pfv1->l - pfv0->l ) * scale + 0.5;
out->zi = pfv0->zi + ( pfv1->zi - pfv0->zi) * scale + 0.5;
}
else
{
scale = (float)(RI.aliasvrectright - pfv1->u ) /
(pfv0->u - pfv1->u );
out->u = pfv1->u + ( pfv0->u - pfv1->u ) * scale + 0.5;
out->v = pfv1->v + ( pfv0->v - pfv1->v ) * scale + 0.5;
out->s = pfv1->s + ( pfv0->s - pfv1->s ) * scale + 0.5;
out->t = pfv1->t + ( pfv0->t - pfv1->t ) * scale + 0.5;
out->l = pfv1->l + ( pfv0->l - pfv1->l ) * scale + 0.5;
out->zi = pfv1->zi + ( pfv0->zi - pfv1->zi) * scale + 0.5;
}
}
void R_Alias_clip_top (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
{
float scale;
if (pfv0->v >= pfv1->v)
{
scale = (float)(RI.aliasvrect.y - pfv0->v) /
(pfv1->v - pfv0->v);
out->u = pfv0->u + ( pfv1->u - pfv0->u ) * scale + 0.5;
out->v = pfv0->v + ( pfv1->v - pfv0->v ) * scale + 0.5;
out->s = pfv0->s + ( pfv1->s - pfv0->s ) * scale + 0.5;
out->t = pfv0->t + ( pfv1->t - pfv0->t ) * scale + 0.5;
out->l = pfv0->l + ( pfv1->l - pfv0->l ) * scale + 0.5;
out->zi = pfv0->zi + ( pfv1->zi - pfv0->zi) * scale + 0.5;
}
else
{
scale = (float)(RI.aliasvrect.y - pfv1->v) /
(pfv0->v - pfv1->v);
out->u = pfv1->u + ( pfv0->u - pfv1->u ) * scale + 0.5;
out->v = pfv1->v + ( pfv0->v - pfv1->v ) * scale + 0.5;
out->s = pfv1->s + ( pfv0->s - pfv1->s ) * scale + 0.5;
out->t = pfv1->t + ( pfv0->t - pfv1->t ) * scale + 0.5;
out->l = pfv1->l + ( pfv0->l - pfv1->l ) * scale + 0.5;
out->zi = pfv1->zi + ( pfv0->zi - pfv1->zi) * scale + 0.5;
}
}
void R_Alias_clip_bottom (finalvert_t *pfv0, finalvert_t *pfv1,
finalvert_t *out)
{
float scale;
if (pfv0->v >= pfv1->v)
{
scale = (float)(RI.aliasvrectbottom - pfv0->v) /
(pfv1->v - pfv0->v);
out->u = pfv0->u + ( pfv1->u - pfv0->u ) * scale + 0.5;
out->v = pfv0->v + ( pfv1->v - pfv0->v ) * scale + 0.5;
out->s = pfv0->s + ( pfv1->s - pfv0->s ) * scale + 0.5;
out->t = pfv0->t + ( pfv1->t - pfv0->t ) * scale + 0.5;
out->l = pfv0->l + ( pfv1->l - pfv0->l ) * scale + 0.5;
out->zi = pfv0->zi + ( pfv1->zi - pfv0->zi) * scale + 0.5;
}
else
{
scale = (float)(RI.aliasvrectbottom - pfv1->v) /
(pfv0->v - pfv1->v);
out->u = pfv1->u + ( pfv0->u - pfv1->u ) * scale + 0.5;
out->v = pfv1->v + ( pfv0->v - pfv1->v ) * scale + 0.5;
out->s = pfv1->s + ( pfv0->s - pfv1->s ) * scale + 0.5;
out->t = pfv1->t + ( pfv0->t - pfv1->t ) * scale + 0.5;
out->l = pfv1->l + ( pfv0->l - pfv1->l ) * scale + 0.5;
out->zi = pfv1->zi + ( pfv0->zi - pfv1->zi) * scale + 0.5;
}
}
#endif
int R_AliasClip (finalvert_t *in, finalvert_t *out, int flag, int count,
void(*clip)(finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out) )
{
int i,j,k;
int flags, oldflags;
j = count-1;
k = 0;
for (i=0 ; i<count ; j = i, i++)
{
oldflags = in[j].flags & flag;
flags = in[i].flags & flag;
if (flags && oldflags)
continue;
if (oldflags ^ flags)
{
clip (&in[j], &in[i], &out[k]);
out[k].flags = 0;
if (out[k].u < RI.aliasvrect.x)
out[k].flags |= ALIAS_LEFT_CLIP;
if (out[k].v < RI.aliasvrect.y)
out[k].flags |= ALIAS_TOP_CLIP;
if (out[k].u > RI.aliasvrectright)
out[k].flags |= ALIAS_RIGHT_CLIP;
if (out[k].v > RI.aliasvrectbottom)
out[k].flags |= ALIAS_BOTTOM_CLIP;
k++;
}
if (!flags)
{
out[k] = in[i];
k++;
}
}
return k;
}
/*
================
R_AliasClipTriangle
================
*/
void R_AliasClipTriangle (finalvert_t *index0, finalvert_t *index1, finalvert_t *index2)
{
int i, k, pingpong;
unsigned clipflags;
// copy vertexes and fix seam texture coordinates
fv[0][0] = *index0;
fv[0][1] = *index1;
fv[0][2] = *index2;
// clip
clipflags = fv[0][0].flags | fv[0][1].flags | fv[0][2].flags;
if (clipflags & ALIAS_Z_CLIP)
{
k = R_AliasClip (fv[0], fv[1], ALIAS_Z_CLIP, 3, R_Alias_clip_z);
if (k == 0)
return;
pingpong = 1;
clipflags = fv[1][0].flags | fv[1][1].flags | fv[1][2].flags;
}
else
{
pingpong = 0;
k = 3;
}
if (clipflags & ALIAS_LEFT_CLIP)
{
k = R_AliasClip (fv[pingpong], fv[pingpong ^ 1],
ALIAS_LEFT_CLIP, k, R_Alias_clip_left);
if (k == 0)
return;
pingpong ^= 1;
}
if (clipflags & ALIAS_RIGHT_CLIP)
{
k = R_AliasClip (fv[pingpong], fv[pingpong ^ 1],
ALIAS_RIGHT_CLIP, k, R_Alias_clip_right);
if (k == 0)
return;
pingpong ^= 1;
}
if (clipflags & ALIAS_BOTTOM_CLIP)
{
k = R_AliasClip (fv[pingpong], fv[pingpong ^ 1],
ALIAS_BOTTOM_CLIP, k, R_Alias_clip_bottom);
if (k == 0)
return;
pingpong ^= 1;
}
if (clipflags & ALIAS_TOP_CLIP)
{
k = R_AliasClip (fv[pingpong], fv[pingpong ^ 1],
ALIAS_TOP_CLIP, k, R_Alias_clip_top);
if (k == 0)
return;
pingpong ^= 1;
}
for (i=0 ; i<k ; i++)
{
if (fv[pingpong][i].u < RI.aliasvrect.x)
fv[pingpong][i].u = RI.aliasvrect.x;
else if (fv[pingpong][i].u > RI.aliasvrectright)
fv[pingpong][i].u = RI.aliasvrectright;
if (fv[pingpong][i].v < RI.aliasvrect.y)
fv[pingpong][i].v = RI.aliasvrect.y;
else if (fv[pingpong][i].v > RI.aliasvrectbottom)
fv[pingpong][i].v = RI.aliasvrectbottom;
fv[pingpong][i].flags = 0;
}
// draw triangles
for (i=1 ; i<k-1 ; i++)
{
aliastriangleparms.a = &fv[pingpong][0];
aliastriangleparms.b = &fv[pingpong][i];
aliastriangleparms.c = &fv[pingpong][i+1];
R_DrawTriangle();
}
}

34
r_local.h

@ -1243,6 +1243,29 @@ extern vec3_t r_entorigin;
extern int r_leafkeys[MAX_MAP_LEAFS]; extern int r_leafkeys[MAX_MAP_LEAFS];
#define LEAF_KEY(pleaf) r_leafkeys[(pleaf - WORLDMODEL->leafs)] #define LEAF_KEY(pleaf) r_leafkeys[(pleaf - WORLDMODEL->leafs)]
extern int ubasestep, errorterm, erroradjustup, erroradjustdown;
extern mvertex_t *r_pcurrentvertbase;
extern int r_maxvalidedgeoffset;
typedef struct
{
finalvert_t *a, *b, *c;
} aliastriangleparms_t;
extern aliastriangleparms_t aliastriangleparms;
extern int r_aliasblendcolor;
extern float aliasxscale, aliasyscale, aliasxcenter, aliasycenter;
void R_DrawTriangle( void );
//void R_DrawTriangle (finalvert_t *index0, finalvert_t *index1, finalvert_t *index2);
void R_AliasClipTriangle (finalvert_t *index0, finalvert_t *index1, finalvert_t *index2);
// //
// r_bsp.c // r_bsp.c
// //
@ -1294,9 +1317,14 @@ void TransformVector (vec3_t in, vec3_t out);
void R_RenderBmodelFace (bedge_t *pedges, msurface_t *psurf); void R_RenderBmodelFace (bedge_t *pedges, msurface_t *psurf);
void R_RenderFace (msurface_t *fa, int clipflags); void R_RenderFace (msurface_t *fa, int clipflags);
#if id386 //
#error aaa // r_main.c
#endif //
void R_ConcatTransforms (float in1[3][4], float in2[3][4], float out[3][4]);
void R_RenderTriangle( finalvert_t *pfv );
void R_SetupFinalVert( finalvert_t *fv, float x, float y, float z, int light, int s, int t );
// //
// engine callbacks // engine callbacks

47
r_main.c

@ -130,6 +130,7 @@ int r_clipflags;
byte r_warpbuffer[WARP_WIDTH * WARP_HEIGHT]; byte r_warpbuffer[WARP_WIDTH * WARP_HEIGHT];
int r_numallocatededges; int r_numallocatededges;
float r_aliasuvscale = 1.0;
/* /*
================ ================
@ -157,6 +158,39 @@ void R_ConcatRotations (float in1[3][3], float in2[3][3], float out[3][3])
out[2][2] = in1[2][0] * in2[0][2] + in1[2][1] * in2[1][2] + out[2][2] = in1[2][0] * in2[0][2] + in1[2][1] * in2[1][2] +
in1[2][2] * in2[2][2]; in1[2][2] * in2[2][2];
} }
/*
================
R_ConcatTransforms
================
*/
void R_ConcatTransforms (float in1[3][4], float in2[3][4], float out[3][4])
{
out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] +
in1[0][2] * in2[2][0];
out[0][1] = in1[0][0] * in2[0][1] + in1[0][1] * in2[1][1] +
in1[0][2] * in2[2][1];
out[0][2] = in1[0][0] * in2[0][2] + in1[0][1] * in2[1][2] +
in1[0][2] * in2[2][2];
out[0][3] = in1[0][0] * in2[0][3] + in1[0][1] * in2[1][3] +
in1[0][2] * in2[2][3] + in1[0][3];
out[1][0] = in1[1][0] * in2[0][0] + in1[1][1] * in2[1][0] +
in1[1][2] * in2[2][0];
out[1][1] = in1[1][0] * in2[0][1] + in1[1][1] * in2[1][1] +
in1[1][2] * in2[2][1];
out[1][2] = in1[1][0] * in2[0][2] + in1[1][1] * in2[1][2] +
in1[1][2] * in2[2][2];
out[1][3] = in1[1][0] * in2[0][3] + in1[1][1] * in2[1][3] +
in1[1][2] * in2[2][3] + in1[1][3];
out[2][0] = in1[2][0] * in2[0][0] + in1[2][1] * in2[1][0] +
in1[2][2] * in2[2][0];
out[2][1] = in1[2][0] * in2[0][1] + in1[2][1] * in2[1][1] +
in1[2][2] * in2[2][1];
out[2][2] = in1[2][0] * in2[0][2] + in1[2][1] * in2[1][2] +
in1[2][2] * in2[2][2];
out[2][3] = in1[2][0] * in2[0][3] + in1[2][1] * in2[1][3] +
in1[2][2] * in2[2][3] + in1[2][3];
}
@ -991,6 +1025,19 @@ void R_DrawEntitiesOnList( void )
break; break;
case mod_studio: case mod_studio:
//R_DrawStudioModel( RI.currententity ); //R_DrawStudioModel( RI.currententity );
{finalvert_t fv[3];
void R_AliasSetUpTransform (void);
extern void (*d_pdrawspans)(void *);
extern void R_PolysetFillSpans8 ( void * );
d_pdrawspans = R_PolysetFillSpans8;
//RI.currententity = gEngfuncs.GetEntityByIndex(0);
R_AliasSetUpTransform();
R_SetupFinalVert( &fv[0], -10, -10, 5, 0, 0, 0);
R_SetupFinalVert( &fv[1], -10, 10, 10, 0, 0, 0);
R_SetupFinalVert( &fv[2], 10, 10, -10, 0, 0, 0);
R_RenderTriangle( &fv );
}
break; break;
default: default:
break; break;

16
r_misc.c

@ -244,10 +244,10 @@ void R_ViewChanged (vrect_t *vr)
RI.fvrectbottom = (float)RI.vrectbottom; RI.fvrectbottom = (float)RI.vrectbottom;
RI.fvrectbottom_adj = (float)RI.vrectbottom - 0.5; RI.fvrectbottom_adj = (float)RI.vrectbottom - 0.5;
//RI.aliasvrect.x = (int)(RI.vrect.x * r_aliasuvscale); RI.aliasvrect.x = (int)(RI.vrect.x * r_aliasuvscale);
//RI.aliasvrect.y = (int)(RI.vrect.y * r_aliasuvscale); RI.aliasvrect.y = (int)(RI.vrect.y * r_aliasuvscale);
//RI.aliasvrect.width = (int)(RI.vrect.width * r_aliasuvscale); RI.aliasvrect.width = (int)(RI.vrect.width * r_aliasuvscale);
//RI.aliasvrect.height = (int)(RI.vrect.height * r_aliasuvscale); RI.aliasvrect.height = (int)(RI.vrect.height * r_aliasuvscale);
RI.aliasvrectright = RI.aliasvrect.x + RI.aliasvrectright = RI.aliasvrect.x +
RI.aliasvrect.width; RI.aliasvrect.width;
RI.aliasvrectbottom = RI.aliasvrect.y + RI.aliasvrectbottom = RI.aliasvrect.y +
@ -264,17 +264,17 @@ void R_ViewChanged (vrect_t *vr)
// buffer origin to get an exact edge to edge fill // buffer origin to get an exact edge to edge fill
xcenter = ((float)RI.vrect.width * XCENTERING) + xcenter = ((float)RI.vrect.width * XCENTERING) +
RI.vrect.x - 0.5; RI.vrect.x - 0.5;
//aliasxcenter = xcenter * r_aliasuvscale; aliasxcenter = xcenter * r_aliasuvscale;
ycenter = ((float)RI.vrect.height * YCENTERING) + ycenter = ((float)RI.vrect.height * YCENTERING) +
RI.vrect.y - 0.5; RI.vrect.y - 0.5;
// aliasycenter = ycenter * r_aliasuvscale; aliasycenter = ycenter * r_aliasuvscale;
xscale = RI.vrect.width / RI.horizontalFieldOfView; xscale = RI.vrect.width / RI.horizontalFieldOfView;
// aliasxscale = xscale * r_aliasuvscale; aliasxscale = xscale * r_aliasuvscale;
xscaleinv = 1.0 / xscale; xscaleinv = 1.0 / xscale;
yscale = xscale; yscale = xscale;
// aliasyscale = yscale * r_aliasuvscale; aliasyscale = yscale * r_aliasuvscale;
yscaleinv = 1.0 / yscale; yscaleinv = 1.0 / yscale;
xscaleshrink = (RI.vrect.width-6)/RI.horizontalFieldOfView; xscaleshrink = (RI.vrect.width-6)/RI.horizontalFieldOfView;
yscaleshrink = xscaleshrink; yscaleshrink = xscaleshrink;

1612
r_polyse.c

File diff suppressed because it is too large Load Diff

229
r_trialias.c

@ -0,0 +1,229 @@
#include "r_local.h"
// not really draw alias models here, but use this to draw triangles
int r_amodels_drawn;
affinetridesc_t r_affinetridesc;
vec3_t r_plightvec;
vec3_t r_lerped[1024];
vec3_t r_lerp_frontv, r_lerp_backv, r_lerp_move;
int r_ambientlight;
int r_aliasblendcolor;
float r_shadelight;
float aliastransform[3][4];
float aliasworldtransform[3][4];
float aliasoldworldtransform[3][4];
static float s_ziscale;
static vec3_t s_alias_forward, s_alias_right, s_alias_up;
#define NUMVERTEXNORMALS 162
float r_avertexnormals[NUMVERTEXNORMALS][3] = {
#include "anorms.h"
};
void R_AliasSetUpTransform (void);
void R_AliasTransformVector (vec3_t in, vec3_t out, float m[3][4] );
void R_AliasProjectAndClipTestFinalVert (finalvert_t *fv);
void R_AliasTransformFinalVerts( int numpoints, finalvert_t *fv, dtrivertx_t *oldv, dtrivertx_t *newv );
/*
================
R_AliasCheckBBox
================
*/
typedef struct {
int index0;
int index1;
} aedge_t;
static aedge_t aedges[12] = {
{0, 1}, {1, 2}, {2, 3}, {3, 0},
{4, 5}, {5, 6}, {6, 7}, {7, 4},
{0, 5}, {1, 4}, {2, 7}, {3, 6}
};
#define BBOX_TRIVIAL_ACCEPT 0
#define BBOX_MUST_CLIP_XY 1
#define BBOX_MUST_CLIP_Z 2
#define BBOX_TRIVIAL_REJECT 8
/*
================
R_AliasTransformVector
================
*/
void R_AliasTransformVector(vec3_t in, vec3_t out, float xf[3][4] )
{
out[0] = DotProduct(in, xf[0]) + xf[0][3];
out[1] = DotProduct(in, xf[1]) + xf[1][3];
out[2] = DotProduct(in, xf[2]) + xf[2][3];
}
void VectorInverse (vec3_t v)
{
v[0] = -v[0];
v[1] = -v[1];
v[2] = -v[2];
}
/*
================
R_AliasSetUpTransform
================
*/
void R_AliasSetUpTransform (void)
{
int i;
static float viewmatrix[3][4];
vec3_t angles;
// TODO: should really be stored with the entity instead of being reconstructed
// TODO: should use a look-up table
// TODO: could cache lazily, stored in the entity
//
s_ziscale = (float)0x8000 * (float)0x10000;
angles[ROLL] = RI.currententity->angles[ROLL];
angles[PITCH] = RI.currententity->angles[PITCH];
angles[YAW] = RI.currententity->angles[YAW];
AngleVectors( angles, s_alias_forward, s_alias_right, s_alias_up );
// TODO: can do this with simple matrix rearrangement
memset( aliasworldtransform, 0, sizeof( aliasworldtransform ) );
memset( aliasoldworldtransform, 0, sizeof( aliasworldtransform ) );
for (i=0 ; i<3 ; i++)
{
aliasoldworldtransform[i][0] = aliasworldtransform[i][0] = s_alias_forward[i];
aliasoldworldtransform[i][0] = aliasworldtransform[i][1] = -s_alias_right[i];
aliasoldworldtransform[i][0] = aliasworldtransform[i][2] = s_alias_up[i];
}
aliasworldtransform[0][3] = RI.currententity->origin[0]-r_origin[0];
aliasworldtransform[1][3] = RI.currententity->origin[1]-r_origin[1];
aliasworldtransform[2][3] = RI.currententity->origin[2]-r_origin[2];
//aliasoldworldtransform[0][3] = RI.currententity->oldorigin[0]-r_origin[0];
//aliasoldworldtransform[1][3] = RI.currententity->oldorigin[1]-r_origin[1];
//aliasoldworldtransform[2][3] = RI.currententity->oldorigin[2]-r_origin[2];
// FIXME: can do more efficiently than full concatenation
// memcpy( rotationmatrix, t2matrix, sizeof( rotationmatrix ) );
// R_ConcatTransforms (t2matrix, tmatrix, rotationmatrix);
// TODO: should be global, set when vright, etc., set
VectorCopy (vright, viewmatrix[0]);
VectorCopy (vup, viewmatrix[1]);
VectorInverse (viewmatrix[1]);
//VectorScale(viewmatrix[1], -1, viewmatrix[1]);
VectorCopy (vpn, viewmatrix[2]);
viewmatrix[0][3] = 0;
viewmatrix[1][3] = 0;
viewmatrix[2][3] = 0;
// memcpy( aliasworldtransform, rotationmatrix, sizeof( aliastransform ) );
R_ConcatTransforms (viewmatrix, aliasworldtransform, aliastransform);
aliasworldtransform[0][3] = RI.currententity->origin[0];
aliasworldtransform[1][3] = RI.currententity->origin[1];
aliasworldtransform[2][3] = RI.currententity->origin[2];
//aliasoldworldtransform[0][3] = RI.currententity->oldorigin[0];
//aliasoldworldtransform[1][3] = RI.currententity->oldorigin[1];
//aliasoldworldtransform[2][3] = RI.currententity->oldorigin[2];
}
/*
================
R_AliasProjectAndClipTestFinalVert
================
*/
void R_AliasProjectAndClipTestFinalVert( finalvert_t *fv )
{
float zi;
float x, y, z;
// project points
x = fv->xyz[0];
y = fv->xyz[1];
z = fv->xyz[2];
zi = 1.0 / z;
fv->zi = zi * s_ziscale;
fv->u = (x * aliasxscale * zi) + aliasxcenter;
fv->v = (y * aliasyscale * zi) + aliasycenter;
if (fv->u < RI.aliasvrect.x)
fv->flags |= ALIAS_LEFT_CLIP;
if (fv->v < RI.aliasvrect.y)
fv->flags |= ALIAS_TOP_CLIP;
if (fv->u > RI.aliasvrectright)
fv->flags |= ALIAS_RIGHT_CLIP;
if (fv->v > RI.aliasvrectbottom)
fv->flags |= ALIAS_BOTTOM_CLIP;
}
void R_SetupFinalVert( finalvert_t *fv, float x, float y, float z, int light, int s, int t )
{
vec3_t v = {x, y, z};
fv->xyz[0] = DotProduct(v, aliastransform[0]) + aliastransform[0][3];
fv->xyz[1] = DotProduct(v, aliastransform[1]) + aliastransform[1][3];
fv->xyz[2] = DotProduct(v, aliastransform[2]) + aliastransform[2][3];
fv->flags = 0;
fv->l = light;
if ( fv->xyz[2] < ALIAS_Z_CLIP_PLANE )
{
fv->flags |= ALIAS_Z_CLIP;
}
else
{
R_AliasProjectAndClipTestFinalVert( fv );
}
fv->s = s << 16;
fv->t = t << 16;
}
void R_RenderTriangle( finalvert_t *pfv )
{
if ( pfv[0].flags & pfv[1].flags & pfv[2].flags )
return ; // completely clipped
if ( ! (pfv[0].flags | pfv[1].flags | pfv[2].flags) )
{ // totally unclipped
aliastriangleparms.a = &pfv[0];
aliastriangleparms.b = &pfv[1];
aliastriangleparms.c = &pfv[2];
R_DrawTriangle();
}
else
{ // partially clipped
R_AliasClipTriangle (&pfv[0], &pfv[1], &pfv[2]);
}
}
Loading…
Cancel
Save