summaryrefslogtreecommitdiff
path: root/source/sw_sprite.c
blob: e3d15721d85b03403c16b9575cc44c72ba7c16c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
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_sprite.c
#include "sw_local.h"

extern polydesc_t r_polydesc;

void R_BuildPolygonFromSurface(mface_t *fa);
void R_PolygonCalculateGradients (void);

extern void R_PolyChooseSpanletRoutine( float alpha, qboolean isturbulent );

extern vec5_t r_clip_verts[2][MAXWORKINGVERTS+2];

extern void R_ClipAndDrawPoly( float alpha, qboolean isturbulent, qboolean textured );

/*
** R_DrawSprite
**
** Draw currententity / currentmodel as a single texture
** mapped polygon
*/
void R_DrawSprite (void)
{
    vec5_t      *pverts;
    vec3_t      left, up, right, down;
    mspriteframe_t  *frame;

    frame = &currentmodel->spriteframes[
        currententity->frame % currentmodel->numframes];

    r_polydesc.pixels       = frame->image->pixels[0];
    r_polydesc.pixel_width  = frame->width;
    r_polydesc.pixel_height = frame->height;
    r_polydesc.dist         = 0;

    // generate the sprite's axes, completely parallel to the viewplane.
    VectorCopy (vup, r_polydesc.vup);
    VectorCopy (vright, r_polydesc.vright);
    VectorCopy (vpn, r_polydesc.vpn);

// build the sprite poster in worldspace
    VectorScale (r_polydesc.vright, 
        frame->width - frame->origin_x, right);
    VectorScale (r_polydesc.vup, 
        frame->height - frame->origin_y, up);
    VectorScale (r_polydesc.vright,
        -frame->origin_x, left);
    VectorScale (r_polydesc.vup,
        -frame->origin_y, down);

    // invert UP vector for sprites
    VectorNegate( r_polydesc.vup, r_polydesc.vup );

    pverts = r_clip_verts[0];

    pverts[0][0] = r_entorigin[0] + up[0] + left[0];
    pverts[0][1] = r_entorigin[1] + up[1] + left[1];
    pverts[0][2] = r_entorigin[2] + up[2] + left[2];
    pverts[0][3] = 0;
    pverts[0][4] = 0;

    pverts[1][0] = r_entorigin[0] + up[0] + right[0];
    pverts[1][1] = r_entorigin[1] + up[1] + right[1];
    pverts[1][2] = r_entorigin[2] + up[2] + right[2];
    pverts[1][3] = frame->width;
    pverts[1][4] = 0;

    pverts[2][0] = r_entorigin[0] + down[0] + right[0];
    pverts[2][1] = r_entorigin[1] + down[1] + right[1];
    pverts[2][2] = r_entorigin[2] + down[2] + right[2];
    pverts[2][3] = frame->width;
    pverts[2][4] = frame->height;

    pverts[3][0] = r_entorigin[0] + down[0] + left[0];
    pverts[3][1] = r_entorigin[1] + down[1] + left[1];
    pverts[3][2] = r_entorigin[2] + down[2] + left[2];
    pverts[3][3] = 0;
    pverts[3][4] = frame->height;

    r_polydesc.nump = 4;
    r_polydesc.s_offset = ( r_polydesc.pixel_width  >> 1);
    r_polydesc.t_offset = ( r_polydesc.pixel_height >> 1);
    VectorCopy( modelorg, r_polydesc.viewer_position );

    r_polydesc.stipple_parity = 1;
    if ( currententity->flags & RF_TRANSLUCENT )
        R_ClipAndDrawPoly ( currententity->alpha, qfalse, qtrue );
    else
        R_ClipAndDrawPoly ( 1.0F, qfalse, qtrue );
    r_polydesc.stipple_parity = 0;
}