-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathPlayerModelView.cpp
More file actions
222 lines (182 loc) · 5.47 KB
/
Copy pathPlayerModelView.cpp
File metadata and controls
222 lines (182 loc) · 5.47 KB
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
/*
PlayerModelView.cpp -- player model view
Copyright (C) 2018 a1batross
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 3 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.
*/
#include "extdll_menu.h"
#include "BaseMenu.h"
#include "PlayerModelView.h"
CMenuPlayerModelView::CMenuPlayerModelView() : CMenuBaseItem()
{
memset( &refdef, 0, sizeof( refdef ) );
ent = NULL;
mouseYawControl = false;
prevCursorX = 0;
prevCursorY = 0;
hPlayerImage = 0;
eFocusAnimation = QM_HIGHLIGHTIFFOCUS;
eOverrideMode = PMV_DONTCARE;
refdef.fov_x = 40.0f;
bDrawAsPlayer = true;
}
void CMenuPlayerModelView::VidInit()
{
backgroundColor.SetDefault( uiColorHelp );
colorStroke.SetDefault( uiInputFgColor );
colorFocus.SetDefault( uiInputTextColor );
iStrokeWidth = uiStatic.outlineWidth;
CMenuBaseItem::VidInit();
refdef.viewport[0] = m_scPos.x;
refdef.viewport[1] = m_scPos.y;
refdef.viewport[2] = m_scSize.w;
refdef.viewport[3] = m_scSize.h;
CalcFov();
ent = EngFuncs::GetPlayerModel();
memset( ent, 0, sizeof( cl_entity_t ));
// adjust entity params
ent->index = 0;
ent->curstate.body = 0;
ent->curstate.number = 1; // IMPORTANT: always set playerindex to 1
ent->curstate.animtime = gpGlobals->time; // start animation
ent->curstate.sequence = 1;
ent->curstate.scale = 1.0f;
ent->curstate.frame = 0.0f;
ent->curstate.framerate = 1.0f;
ent->curstate.effects |= EF_FULLBRIGHT;
ent->curstate.controller[0] = 127;
ent->curstate.controller[1] = 127;
ent->curstate.controller[2] = 127;
ent->curstate.controller[3] = 127;
ent->latched.prevcontroller[0] = 127;
ent->latched.prevcontroller[1] = 127;
ent->latched.prevcontroller[2] = 127;
ent->latched.prevcontroller[3] = 127;
ent->origin[0] = ent->curstate.origin[0] = 45.0f / tan( DEG2RAD( refdef.fov_y / 2.0f ));
ent->origin[2] = ent->curstate.origin[2] = 2.0f;
ent->angles[1] = ent->curstate.angles[1] = 180.0f;
ent->player = bDrawAsPlayer; // yes, draw me as playermodel
}
bool CMenuPlayerModelView::KeyUp( int key )
{
if( !ent )
return true;
if( UI::Key::IsLeftMouse( key ) && mouseYawControl )
mouseYawControl = false;
return false;
}
bool CMenuPlayerModelView::KeyDown( int key )
{
if( !ent )
return true;
if( UI::Key::IsLeftMouse( key ) && UI_CursorInRect( m_scPos, m_scSize )
&& !mouseYawControl )
{
mouseYawControl = true;
prevCursorX = uiStatic.cursorX;
prevCursorY = uiStatic.cursorY;
}
float yaw = ent->angles[1];
if( UI::Key::IsLeftArrow( key ))
yaw -= 10.0f;
else if( UI::Key::IsRightArrow( key ))
yaw += 10.0f;
else if( UI::Key::IsEnter( key ))
ent->curstate.sequence++;
else return CMenuBaseItem::KeyDown( key );
if( yaw > 180.0f ) yaw -= 360.0f;
else if( yaw < -180.0f ) yaw += 360.0f;
ent->angles[1] = ent->curstate.angles[1] = yaw;
PlayLocalSound( uiStatic.sounds[SND_LAUNCH] );
return true;
}
void CMenuPlayerModelView::Draw()
{
// draw the background
UI_FillRect( m_scPos, m_scSize, backgroundColor );
// draw the rectangle
if( eFocusAnimation == QM_HIGHLIGHTIFFOCUS && IsCurrentSelected() )
UI_DrawRectangleExt( m_scPos, m_scSize, colorFocus, iStrokeWidth );
else
UI_DrawRectangleExt( m_scPos, m_scSize, colorStroke, iStrokeWidth );
if( ( eOverrideMode == PMV_DONTCARE && !ui_showmodels->value ) || // controlled by engine cvar
( eOverrideMode == PMV_SHOWIMAGE ) ) // controlled by menucode
{
if( hPlayerImage )
{
EngFuncs::PIC_Set( hPlayerImage, 255, 255, 255, 255 );
EngFuncs::PIC_DrawTrans( m_scPos, m_scSize );
}
else
{
UI_DrawString( font, m_scPos, m_scSize, L( "No preview" ), colorBase, m_scChSize, QM_CENTER, ETF_SHADOW );
}
}
else
{
EngFuncs::ClearScene();
if( bDrawAsPlayer )
ent->curstate.body = 0; // reset body, so it will be changed by cl_himodels setting
if( uiStatic.enableAlphaFactor )
{
ent->curstate.rendermode = kRenderTransTexture;
ent->curstate.renderamt = uiStatic.alphaFactor * 255;
}
else
{
ent->curstate.rendermode = kRenderNormal;
ent->curstate.renderamt = 255;
}
if( mouseYawControl )
{
float diffX = uiStatic.cursorX - prevCursorX;
if( diffX )
{
float yaw = ent->angles[1];
yaw += diffX / uiStatic.scaleX;
if( yaw > 180.0f )
yaw -= 360.0f;
else if( yaw < -180.0f )
yaw += 360.0f;
ent->angles[1] = ent->curstate.angles[1] = yaw;
}
prevCursorX = uiStatic.cursorX;
#if 0 // Disabled. Pitch changing is ugly
float diffY = uiStatic.cursorY - prevCursorY;
if( diffY )
{
float pitch = refdef.viewangles[2];
pitch += diffY / uiStatic.scaleY;
if( pitch > 180.0f )
pitch -= 360.0f;
else if( pitch < -180.0f )
pitch += 360.0f;
refdef.viewangles[2] = pitch;
ent->angles[2] = ent->curstate.angles[2] = -pitch;
}
#endif
prevCursorY = uiStatic.cursorY;
}
// draw the player model
EngFuncs::CL_CreateVisibleEntity( ET_NORMAL, ent );
EngFuncs::RenderScene( &refdef );
}
}
/*
=================
UI_PlayerSetup_CalcFov
assume refdef is valid
=================
*/
void CMenuPlayerModelView::CalcFov( )
{
float x = refdef.viewport[2] / tan( DEG2RAD( refdef.fov_x ) * 0.5f );
float half_fov_y = atan( refdef.viewport[3] / x );
refdef.fov_y = RAD2DEG( half_fov_y ) * 2;
}