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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $Workfile: $
// $Date: $
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "clientsideeffects.h"
#include "fx_staticline.h"
#include "materialsystem/imaterial.h"
#include "materialsystem/imesh.h"
#include "view.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
/*
==================================================
CFXStaticLine
==================================================
*/
CFXStaticLine::CFXStaticLine( const char *name, const Vector& start, const Vector& end, float scale, float life, const char *shader, unsigned int flags )
: CClientSideEffect( name )
{
assert( materials );
if ( materials == NULL )
return;
// Create a material...
m_pMaterial = materials->FindMaterial( shader, TEXTURE_GROUP_CLIENT_EFFECTS );
m_pMaterial->IncrementReferenceCount();
//Fill in the rest of the fields
m_vecStart = start;
m_vecEnd = end;
m_uiFlags = flags;
m_fLife = life;
m_fScale = scale * 0.5f;
}
CFXStaticLine::~CFXStaticLine( void )
{
Destroy();
}
//==================================================
// Purpose: Draw the primitive
// Input: frametime - the time, this frame
//==================================================
void CFXStaticLine::Draw( double frametime )
{
Vector lineDir, viewDir, cross;
Vector tmp;
// Update the effect
Update( frametime );
// Get the proper orientation for the line
VectorSubtract( m_vecEnd, m_vecStart, lineDir );
VectorSubtract( m_vecEnd, CurrentViewOrigin(), viewDir );
cross = lineDir.Cross( viewDir );
VectorNormalize( cross );
CMatRenderContextPtr pRenderContext( materials );
//Bind the material
IMesh* pMesh = pRenderContext->GetDynamicMesh( true, NULL, NULL, m_pMaterial );
CMeshBuilder meshBuilder;
meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );
bool flipVertical = (m_uiFlags & FXSTATICLINE_FLIP_VERTICAL) != 0;
bool flipHorizontal = (m_uiFlags & FXSTATICLINE_FLIP_HORIZONTAL ) != 0;
//Setup our points
VectorMA( m_vecStart, -m_fScale, cross, tmp );
meshBuilder.Position3fv( tmp.Base() );
meshBuilder.Normal3fv( cross.Base() );
if (flipHorizontal)
meshBuilder.TexCoord2f( 0, 0.0f, 1.0f );
else if (flipVertical)
meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
else
meshBuilder.TexCoord2f( 0, 1.0f, 1.0f );
meshBuilder.Color4ub( 255, 255, 255, 255 );
meshBuilder.AdvanceVertex();
VectorMA( m_vecStart, m_fScale, cross, tmp );
meshBuilder.Position3fv( tmp.Base() );
meshBuilder.Normal3fv( cross.Base() );
if (flipHorizontal)
meshBuilder.TexCoord2f( 0, 1.0f, 1.0f );
else if (flipVertical)
meshBuilder.TexCoord2f( 0, 1.0f, 0.0f );
else
meshBuilder.TexCoord2f( 0, 0.0f, 1.0f );
meshBuilder.Color4ub( 255, 255, 255, 255 );
meshBuilder.AdvanceVertex();
VectorMA( m_vecEnd, m_fScale, cross, tmp );
meshBuilder.Position3fv( tmp.Base() );
meshBuilder.Normal3fv( cross.Base() );
if (flipHorizontal)
meshBuilder.TexCoord2f( 0, 1.0f, 0.0f );
else if (flipVertical)
meshBuilder.TexCoord2f( 0, 1.0f, 1.0f );
else
meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
meshBuilder.Color4ub( 255, 255, 255, 255 );
meshBuilder.AdvanceVertex();
VectorMA( m_vecEnd, -m_fScale, cross, tmp );
meshBuilder.Position3fv( tmp.Base() );
meshBuilder.Normal3fv( cross.Base() );
if (flipHorizontal)
meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
else if (flipVertical)
meshBuilder.TexCoord2f( 0, 0.0f, 1.0f );
else
meshBuilder.TexCoord2f( 0, 1.0f, 0.0f );
meshBuilder.Color4ub( 255, 255, 255, 255 );
meshBuilder.AdvanceVertex();
meshBuilder.End();
pMesh->Draw();
}
//==================================================
// Purpose: Returns whether or not the effect is still active
// Output: true if active
//==================================================
bool CFXStaticLine::IsActive( void )
{
return ( m_fLife > 0.0 ) ? true : false;
}
//==================================================
// Purpose: Destroy the effect and its local resources
//==================================================
void CFXStaticLine::Destroy( void )
{
//Release the material
if ( m_pMaterial != NULL )
{
m_pMaterial->DecrementReferenceCount();
m_pMaterial = NULL;
}
}
//==================================================
// Purpose: Perform any necessary updates
// Input: frametime - the time, this frame
//==================================================
void CFXStaticLine::Update( double frametime )
{
m_fLife -= frametime;
}
|