FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
TF2-Source-Code/tf2_src/tier2/beamsegdraw.cpp at master · sr2echa/TF2-Source-Code · GitHub
sr2echa
/
TF2-Source-Code
Public
Notifications
You must be signed in to change notification settings
Fork
22
Star
81
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
TF2-Source-Code
/
tf2_src
/
tier2
/
beamsegdraw.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
235 lines (199 loc) · 7.06 KB
Breadcrumbs
TF2-Source-Code
/
tf2_src
/
tier2
/
beamsegdraw.cpp
Copy path
File metadata and controls
235 lines (199 loc) · 7.06 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
//
========= Copyright Valve Corporation, All rights reserved. ============//
//
//
Purpose:
//
//
$NoKeywords: $
//
===========================================================================//
#
include
"
tier2/beamsegdraw.h
"
#
include
"
materialsystem/imaterialvar.h
"
//
memdbgon must be the last include file in a .cpp file!!!
#
include
"
tier0/memdbgon.h
"
//
-----------------------------------------------------------------------------
//
//
CBeamSegDraw implementation.
//
//
-----------------------------------------------------------------------------
void
CBeamSegDraw::Start
( IMatRenderContext *pRenderContext,
int
nSegs, IMaterial *pMaterial, CMeshBuilder *pMeshBuilder,
int
nMeshVertCount )
{
m_pRenderContext = pRenderContext;
Assert
( nSegs >=
2
);
m_nSegsDrawn =
0
;
m_nTotalSegs = nSegs;
if
( pMeshBuilder )
{
m_pMeshBuilder = pMeshBuilder;
m_nMeshVertCount = nMeshVertCount;
}
else
{
m_pMeshBuilder =
NULL
;
m_nMeshVertCount =
0
;
IMesh *pMesh = m_pRenderContext->
GetDynamicMesh
(
true
,
NULL
,
NULL
, pMaterial );
m_Mesh.
Begin
( pMesh,
MATERIAL_TRIANGLE_STRIP
, (nSegs-
1
) *
2
);
}
}
inline
void
CBeamSegDraw::ComputeNormal
(
const
Vector &vecCameraPos,
const
Vector &vStartPos,
const
Vector &vNextPos, Vector *pNormal )
{
//
vTangentY = line vector for beam
Vector vTangentY;
VectorSubtract
( vStartPos, vNextPos, vTangentY );
//
vDirToBeam = vector from viewer origin to beam
Vector vDirToBeam;
VectorSubtract
( vStartPos, vecCameraPos, vDirToBeam );
//
Get a vector that is perpendicular to us and perpendicular to the beam.
//
This is used to fatten the beam.
CrossProduct
( vTangentY, vDirToBeam, *pNormal );
VectorNormalizeFast
( *pNormal );
}
inline
void
CBeamSegDraw::SpecifySeg
(
const
Vector &vecCameraPos,
const
Vector &vNormal )
{
//
SUCKY: Need to do a fair amount more work to get the tangent owing to the averaged normal
Vector vDirToBeam, vTangentY;
VectorSubtract
( m_Seg.
m_vPos
, vecCameraPos, vDirToBeam );
CrossProduct
( vDirToBeam, vNormal, vTangentY );
VectorNormalizeFast
( vTangentY );
//
Build the endpoints.
Vector vPoint1, vPoint2;
VectorMA
( m_Seg.
m_vPos
, m_Seg.
m_flWidth
*
0
.
5f
, vNormal, vPoint1 );
VectorMA
( m_Seg.
m_vPos
, -m_Seg.
m_flWidth
*
0
.
5f
, vNormal, vPoint2 );
if
( m_pMeshBuilder )
{
//
Specify the points.
m_pMeshBuilder->
Position3fv
( vPoint1.
Base
() );
m_pMeshBuilder->
Color4f
(
VectorExpand
( m_Seg.
m_vColor
), m_Seg.
m_flAlpha
);
m_pMeshBuilder->
TexCoord2f
(
0
,
0
, m_Seg.
m_flTexCoord
);
m_pMeshBuilder->
TexCoord2f
(
1
,
0
, m_Seg.
m_flTexCoord
);
m_pMeshBuilder->
TangentS3fv
( vNormal.
Base
() );
m_pMeshBuilder->
TangentT3fv
( vTangentY.
Base
() );
m_pMeshBuilder->
AdvanceVertex
();
m_pMeshBuilder->
Position3fv
( vPoint2.
Base
() );
m_pMeshBuilder->
Color4f
(
VectorExpand
( m_Seg.
m_vColor
), m_Seg.
m_flAlpha
);
m_pMeshBuilder->
TexCoord2f
(
0
,
1
, m_Seg.
m_flTexCoord
);
m_pMeshBuilder->
TexCoord2f
(
1
,
1
, m_Seg.
m_flTexCoord
);
m_pMeshBuilder->
TangentS3fv
( vNormal.
Base
() );
m_pMeshBuilder->
TangentT3fv
( vTangentY.
Base
() );
m_pMeshBuilder->
AdvanceVertex
();
if
( m_nSegsDrawn >
1
)
{
int
nBase = ( ( m_nSegsDrawn -
2
) *
2
) + m_nMeshVertCount;
m_pMeshBuilder->
FastIndex
( nBase );
m_pMeshBuilder->
FastIndex
( nBase +
1
);
m_pMeshBuilder->
FastIndex
( nBase +
2
);
m_pMeshBuilder->
FastIndex
( nBase +
1
);
m_pMeshBuilder->
FastIndex
( nBase +
3
);
m_pMeshBuilder->
FastIndex
( nBase +
2
);
}
}
else
{
//
Specify the points.
m_Mesh.
Position3fv
( vPoint1.
Base
() );
m_Mesh.
Color4f
(
VectorExpand
( m_Seg.
m_vColor
), m_Seg.
m_flAlpha
);
m_Mesh.
TexCoord2f
(
0
,
0
, m_Seg.
m_flTexCoord
);
m_Mesh.
TexCoord2f
(
1
,
0
, m_Seg.
m_flTexCoord
);
m_Mesh.
TangentS3fv
( vNormal.
Base
() );
m_Mesh.
TangentT3fv
( vTangentY.
Base
() );
m_Mesh.
AdvanceVertex
();
m_Mesh.
Position3fv
( vPoint2.
Base
() );
m_Mesh.
Color4f
(
VectorExpand
( m_Seg.
m_vColor
), m_Seg.
m_flAlpha
);
m_Mesh.
TexCoord2f
(
0
,
1
, m_Seg.
m_flTexCoord
);
m_Mesh.
TexCoord2f
(
1
,
1
, m_Seg.
m_flTexCoord
);
m_Mesh.
TangentS3fv
( vNormal.
Base
() );
m_Mesh.
TangentT3fv
( vTangentY.
Base
() );
m_Mesh.
AdvanceVertex
();
}
}
void
CBeamSegDraw::NextSeg
( BeamSeg_t *pSeg )
{
Vector vecCameraPos;
m_pRenderContext->
GetWorldSpaceCameraPosition
( &vecCameraPos );
if
( m_nSegsDrawn >
0
)
{
//
Get a vector that is perpendicular to us and perpendicular to the beam.
//
This is used to fatten the beam.
Vector vNormal, vAveNormal;
ComputeNormal
( vecCameraPos, m_Seg.
m_vPos
, pSeg->
m_vPos
, &vNormal );
if
( m_nSegsDrawn >
1
)
{
//
Average this with the previous normal
VectorAdd
( vNormal, m_vNormalLast, vAveNormal );
vAveNormal *=
0
.
5f
;
VectorNormalizeFast
( vAveNormal );
}
else
{
vAveNormal = vNormal;
}
m_vNormalLast = vNormal;
SpecifySeg
( vecCameraPos, vAveNormal );
}
m_Seg = *pSeg;
++m_nSegsDrawn;
if
( m_nSegsDrawn == m_nTotalSegs )
{
SpecifySeg
( vecCameraPos, m_vNormalLast );
}
}
void
CBeamSegDraw::End
()
{
if
( m_pMeshBuilder )
{
m_pMeshBuilder =
NULL
;
return
;
}
m_Mesh.
End
(
false
,
true
);
}
//
-----------------------------------------------------------------------------
//
Purpose:
//
-----------------------------------------------------------------------------
void
CBeamSegDrawArbitrary::SetNormal
(
const
Vector &normal )
{
m_vNormalLast = normal;
}
//
-----------------------------------------------------------------------------
//
Purpose:
//
-----------------------------------------------------------------------------
void
CBeamSegDrawArbitrary::NextSeg
( BeamSeg_t *pSeg )
{
if
( m_nSegsDrawn >
0
)
{
Vector segDir = ( m_PrevSeg.
m_vPos
- pSeg->
m_vPos
);
VectorNormalize
( segDir );
Vector normal =
CrossProduct
( segDir, m_vNormalLast );
SpecifySeg
( normal );
}
m_PrevSeg = m_Seg;
m_Seg = *pSeg;
++m_nSegsDrawn;
}
//
-----------------------------------------------------------------------------
//
Purpose:
//
Input : &vNextPos -
//
-----------------------------------------------------------------------------
void
CBeamSegDrawArbitrary::SpecifySeg
(
const
Vector &vNormal )
{
//
Build the endpoints.
Vector vPoint1, vPoint2;
Vector vDelta;
VectorMultiply
( vNormal, m_Seg.
m_flWidth
*
0
.
5f
, vDelta );
VectorAdd
( m_Seg.
m_vPos
, vDelta, vPoint1 );
VectorSubtract
( m_Seg.
m_vPos
, vDelta, vPoint2 );
//
Specify the points.
Assert
(
IsFinite
(m_Seg.
m_vColor
.
x
) &&
IsFinite
(m_Seg.
m_vColor
.
y
) &&
IsFinite
(m_Seg.
m_vColor
.
z
) &&
IsFinite
(m_Seg.
m_flAlpha
) );
Assert
( (m_Seg.
m_vColor
.
x
>=
0.0
) && (m_Seg.
m_vColor
.
y
>=
0.0
) && (m_Seg.
m_vColor
.
z
>=
0.0
) && (m_Seg.
m_flAlpha
>=
0.0
) );
Assert
( (m_Seg.
m_vColor
.
x
<=
1.0
) && (m_Seg.
m_vColor
.
y
<=
1.0
) && (m_Seg.
m_vColor
.
z
<=
1.0
) && (m_Seg.
m_flAlpha
<=
1.0
) );
unsigned
char
r =
FastFToC
( m_Seg.
m_vColor
.
x
);
unsigned
char
g =
FastFToC
( m_Seg.
m_vColor
.
y
);
unsigned
char
b =
FastFToC
( m_Seg.
m_vColor
.
z
);
unsigned
char
a =
FastFToC
( m_Seg.
m_flAlpha
);
m_Mesh.
Position3fv
( vPoint1.
Base
() );
m_Mesh.
Color4ub
( r, g, b, a );
m_Mesh.
TexCoord2f
(
0
,
0
, m_Seg.
m_flTexCoord
);
m_Mesh.
TexCoord2f
(
1
,
0
, m_Seg.
m_flTexCoord
);
m_Mesh.
AdvanceVertex
();
m_Mesh.
Position3fv
( vPoint2.
Base
() );
m_Mesh.
Color4ub
( r, g, b, a );
m_Mesh.
TexCoord2f
(
0
,
1
, m_Seg.
m_flTexCoord
);
m_Mesh.
TexCoord2f
(
1
,
1
, m_Seg.
m_flTexCoord
);
m_Mesh.
AdvanceVertex
();
}
Back
|
FazBrowse Home
|
New Git URL