Vegastrike 0.5.1 rc1
1.0
Original sources for Vegastrike Evolved
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
loc_select.cpp
Go to the documentation of this file.
1
#include "
cmd/unit_generic.h
"
2
#include "
loc_select.h
"
3
#include "
gfxlib.h
"
4
#include "
in_kb.h
"
5
#include "
vs_globals.h
"
6
#include <stdio.h>
7
LocationSelect::LocationSelect
(
Vector
start
,
Vector
Plane1,
8
Vector
Plane2
/*, System * par */
) : LocSelAni(
"locationselect.ani"
, true, .5,
MIPMAP
, true )
9
, LocSelUpAni(
"locationselect_up.ani"
, true, .5,
MIPMAP
, false )
10
{
11
//parentScene = par;
12
CrosshairSize
= 2;
13
MoveLocation
( start, Plane1, Plane2 );
14
}
15
LocationSelect::LocationSelect
(
Vector
start
,
Vector
Plane1,
Vector
Plane2,
16
Vector
Plane3
/*, Scene* par */
) : LocSelAni(
"locationselect.ani"
, true, .5,
MIPMAP
, true )
17
, LocSelUpAni(
"locationselect_up.ani"
, true, .5,
MIPMAP
, false )
18
{
19
//parentScene=par;
20
CrosshairSize
= 2;
21
MoveLocation
( start, Plane1, Plane2, Plane3 );
22
}
23
extern
KBSTATE
keyState
[
LAST_MODIFIER
][
KEYMAP_SIZE
];
24
Vector
DeltaPosition
( 0, 0, 0 );
25
bool
changed
=
false
;
26
bool
vert
=
false
;
27
#define DELTA_MOVEMENT
28
29
void
LocationSelect::MouseMoveHandle
(
KBSTATE
kk,
int
x
,
int
y
,
int
delx
,
int
dely
,
int
mod )
30
{
31
if
(
keyState
[0][
'z'
] ==
DOWN
) {
32
#ifdef DELTA_MOVEMENT
33
if
(kk ==
PRESS
) {
34
DeltaPosition
.k =
dely
;
35
vert
=
true
;
36
}
37
if
(dely)
38
DeltaPosition
.k =
dely
;
39
#else
40
if
(kk ==
PRESS
) {
41
DeltaPosition
.k =
y
;
42
}
else
if
(delx || dely) {
43
DeltaPosition
.i =
x
;
44
DeltaPosition
.j =
y
;
45
vert
=
true
;
46
}
47
#endif
48
}
else
if
(delx || dely) {
49
DeltaPosition
.i =
x
;
50
DeltaPosition
.j =
y
;
51
changed
=
true
;
52
}
53
}
54
55
void
LocationSelect::SetPosition
(
float
x
,
float
y
,
float
z )
56
{
57
local_transformation
.
position
=
QVector
( x, y, z );
58
}
59
void
LocationSelect::SetPosition
(
const
Vector
&k )
60
{
61
local_transformation
.
position
= k.Cast();
62
}
63
void
LocationSelect::SetOrientation
(
const
Vector
&p,
const
Vector
&
q
,
const
Vector
&r )
64
{
65
local_transformation
.
orientation
=
Quaternion::from_vectors
( p, q, r );
66
}
67
68
QVector
&
LocationSelect::Position
()
69
{
70
return
local_transformation
.
position
;
71
}
72
73
void
LocationSelect::MoveLocation
(
Vector
start
,
Vector
Plane1,
Vector
Plane2 )
74
{
75
//BindKey (1,LocationSelect::MouseMoveHandle);
76
//UnbindMouse (getMouseDrawFunc()); //don't draw the mouse
77
//BindKey (']',::incConstant);
78
//BindKey ('[',::decConstant);
79
LocalPosition
=
QVector
( 0, 0, 0 );
80
MakeRVector
( Plane1, Plane2,
r
);
81
p
= Plane1;
82
q
= Plane2;
83
84
local_transformation
.
position
= start.Cast();
85
}
86
void
LocationSelect::MoveLocation
(
Vector
start
,
Vector
Plane1,
Vector
Plane2,
Vector
Plane3 )
87
{
88
//BindKey (1,::MouseMoveHandle);
89
//UnbindMouse (getMouseDrawFunc());
90
LocalPosition
=
QVector
( 0, 0, 0 );
91
r
= Plane3;
92
p
= Plane1;
93
q
= Plane2;
94
local_transformation
.
position
= start.Cast();
95
}
96
97
LocationSelect::~LocationSelect
()
98
{
99
UnbindMouse
( 1 );
100
}
101
102
#define POSITION_GFXVertex( x, y, z ) \
103
(GFXVertex3f( LocalPosition.i+CrosshairSize*(x), \
104
LocalPosition.j+CrosshairSize*(y), \
105
LocalPosition.k+CrosshairSize*(z) ) \
106
)
107
108
void
LocationSelect::Draw
()
109
{
110
Matrix
transformation;
111
local_transformation
.
to_matrix
( transformation );
112
113
GFXLoadIdentity
(
MODEL
);
114
GFXMultMatrixModel
( transformation );
115
/*
116
* GFXEnable(DEPTHWRITE);
117
* GFXEnable(DEPTHTEST);
118
* GFXDisable(TEXTURE0);
119
* GFXDisable(TEXTURE1);
120
* GFXDisable(LIGHTING);
121
* GFXPushBlendMode();
122
* // GFXBlendMode(SRCALPHA,INVSRCALPHA);
123
* //GFXColor4f (parentScene->HUDColor.r, parentScene->HUDColor.g, parentScene->HUDColor.b, parentScene->HUDColor.a);
124
*
125
* GFXColor4f (0,.5,0,.3);
126
*/
127
#ifdef DELTA_MOVEMENT
128
if
(
vert
)
129
LocalPosition
.k = 0;
130
vert
=
false
;
131
if
(
DeltaPosition
.k) {
132
LocalPosition
.k -=
DeltaPosition
.k*.3;
133
DeltaPosition
.k = 0;
134
}
135
#endif
136
if
(
changed
||
vert
) {
137
Matrix
t, m;
138
Matrix
v
;
139
140
GFXGetMatrixView
( v );
141
142
GFXGetMatrixModel
( m );
143
MultMatrix
( t, v, m );
144
145
//following translates 'z'...not sure it's necessary
146
//Translate (v,0,0,LocalPosition.k);
147
//MultMatrix (m,t,v);
148
149
//the location in camera coordinates of the beginning of the location select
150
Vector
tLocation( t.
p
.Cast() );
151
Vector
tP( t.
getP
() );
//the p vector of the plane being selected on
152
Vector
tQ( t.
getQ
() );
//the q vector of the plane being selected on
154
//VSFileSystem::Fprintf (stderr,"<%f,%f,%f>",t[0],t[1],t[2]);
155
//VSFileSystem::Fprintf (stderr,"<%f,%f,%f>",t[4],t[5],t[6]);
156
//VSFileSystem::Fprintf (stderr,"<%f,%f,%f>",t[8],t[9],t[10]);
157
#ifdef DELTA_MOVEMENT
158
float
zvalueXY = tLocation.k+
LocalPosition
.i*tP.k+
LocalPosition
.j*tQ.k;
//z val of the parallelogram
159
#else
160
float
zvalueXY = tLocation.k+
LocalPosition
.i*tP.k+
LocalPosition
.j*tQ.k+
LocalPosition
.k*tR.k;
//zvalue of the cursor
161
#endif
162
if
(
changed
&& !
vert
) {
163
//planar movement
164
if
(zvalueXY > 1000)
165
zvalueXY = 1000;
166
if
(zvalueXY < -1000)
167
zvalueXY = -1000;
168
LocalPosition
.i = fabs( zvalueXY )
169
*( ( (2*
DeltaPosition
.i/
g_game
.
x_resolution
170
-1)*
g_game
.
MouseSensitivityX
*
GFXGetXInvPerspective
()
171
*tP.i )
172
-(1
173
-(2*
DeltaPosition
.j
174
/
g_game
.
y_resolution
)*
g_game
.
MouseSensitivityY
*
GFXGetYInvPerspective
()*tP.j) );
175
LocalPosition
.j = fabs( zvalueXY )
176
*( ( (2*
DeltaPosition
.i/
g_game
.
x_resolution
177
-1)*
g_game
.
MouseSensitivityX
*
GFXGetXInvPerspective
()
178
*tQ.i )
179
-( 1
180
-(2*
DeltaPosition
.j
181
/
g_game
.
y_resolution
)*tQ.j*
g_game
.
MouseSensitivityY
*
GFXGetYInvPerspective
() ) );
182
DeltaPosition
=
Vector
( 0, 0, 0 );
183
//Vector TransPQR (t[0]*i+t[4]*LocalPosition.j+t[8]*LocalPosition.k+t[12],t[1]*LocalPosition.i+t[5]*LocalPosition.j+t[9]*LocalPosition.k+t[13],t[2]*LocalPosition.i+t[6]*LocalPosition.j+t[10]*LocalPosition.k+t[14]);
184
changed
=
false
;
185
}
186
#ifndef DELTA_MOVEMENT
187
else
{
188
//vertical movement
189
if
(zvalueXY > 1000)
190
zvalueXY = 1000;
191
if
(zvalueXY < -1000)
192
zvalueXY = -1000;
193
LocalPosition
.k = fabs( zvalueXY )
194
*( ( (2*
DeltaPosition
.i/
g_game
.
x_resolution
195
-1)*
g_game
.
MouseSensitivityX
*
GFXGetXInvPerspective
()
196
*tR.i )
197
-( (2*
DeltaPosition
.j/
g_game
.
y_resolution
198
-1)*
g_game
.
MouseSensitivityY
*
GFXGetYInvPerspective
()*tR.j ) );
199
if
(
DeltaPosition
.k) {
200
LocalPosition
.k = 0;
201
DeltaPosition
.k = 0;
202
}
203
vert
=
false
;
204
changed
=
false
;
205
}
206
#endif
207
}
208
//draw the animation
209
LocSelUpAni
.
SetPosition
(
QVector
(
LocalPosition
.i,
LocalPosition
.j, 0 ) );
210
LocSelUpAni
.
Draw
();
211
LocSelAni
.
SetPosition
(
LocalPosition
);
212
LocSelAni
.
Draw
();
213
214
/*
215
* GFXBegin(TRIANGLES);
216
* if (fabs(LocalPosition.k-CrosshairSize)>CrosshairSize) {
217
* int tmp;
218
* if (LocalPosition.k>=0)
219
* tmp =1;
220
* else
221
* tmp =-1;
222
* GFXVertex3f (LocalPosition.i,LocalPosition.j,LocalPosition.k-tmp*CrosshairSize);
223
* GFXVertex3f (LocalPosition.i,LocalPosition.j+CrosshairSize*.125,0);
224
* GFXVertex3f (LocalPosition.i,LocalPosition.j-CrosshairSize*.125,0);
225
*
226
* GFXVertex3f (LocalPosition.i,LocalPosition.j-CrosshairSize*.125,0);
227
* GFXVertex3f (LocalPosition.i,LocalPosition.j+CrosshairSize*.125,0);
228
* GFXVertex3f (LocalPosition.i,LocalPosition.j,LocalPosition.k-tmp*CrosshairSize);
229
*
230
* GFXVertex3f (LocalPosition.i,LocalPosition.j,LocalPosition.k-tmp*CrosshairSize);
231
* GFXVertex3f (LocalPosition.i+.125*CrosshairSize,LocalPosition.j,0);
232
* GFXVertex3f (LocalPosition.i-CrosshairSize*.125,LocalPosition.j,0);
233
*
234
* GFXVertex3f (LocalPosition.i-CrosshairSize*.125,LocalPosition.j,0);
235
* GFXVertex3f (LocalPosition.i+CrosshairSize*.125,LocalPosition.j,0);
236
* GFXVertex3f (LocalPosition.i,LocalPosition.j,LocalPosition.k-tmp*CrosshairSize);
237
* }
238
* if (fabs(LocalPosition.i)+fabs(LocalPosition.j)>CrosshairSize) {
239
* GFXVertex3f (0,0,0);
240
* GFXVertex3f (LocalPosition.i,LocalPosition.j,CrosshairSize*.125);
241
* GFXVertex3f (LocalPosition.i,LocalPosition.j,CrosshairSize*-.125);
242
*
243
* GFXVertex3f (LocalPosition.i,LocalPosition.j,CrosshairSize*-.125);
244
* GFXVertex3f (LocalPosition.i,LocalPosition.j,CrosshairSize*.125);
245
* GFXVertex3f (0,0,0);
246
* }
247
* POSITION_GFXVertex (0,0,0);
248
* POSITION_GFXVertex (1,.1,.1);
249
* POSITION_GFXVertex (1,.1,-.1);
250
* POSITION_GFXVertex (0,0,0);
251
* POSITION_GFXVertex (1,-.1,-.1);
252
* POSITION_GFXVertex (1,-.1,.1);
253
* POSITION_GFXVertex (0,0,0);
254
* POSITION_GFXVertex (1,-.1,.1);
255
* POSITION_GFXVertex (1,.1,.1);
256
* POSITION_GFXVertex (0,0,0);
257
* POSITION_GFXVertex (1,.1,-.1);
258
* POSITION_GFXVertex (1,-.1,-.1);//one of the arrows to point
259
* POSITION_GFXVertex (0,0,0);
260
* POSITION_GFXVertex (-1,.1,-.1);
261
* POSITION_GFXVertex (-1,.1,.1);
262
* POSITION_GFXVertex (0,0,0);
263
* POSITION_GFXVertex (-1,-.1,.1);
264
* POSITION_GFXVertex (-1,-.1,-.1);
265
* POSITION_GFXVertex (0,0,0);
266
* POSITION_GFXVertex (-1,.1,.1);
267
* POSITION_GFXVertex (-1,-.1,.1);
268
* POSITION_GFXVertex (0,0,0);
269
* POSITION_GFXVertex (-1,-.1,-.1);
270
* POSITION_GFXVertex (-1,.1,-.1);//one of the arrows to point
271
*
272
* //vertical
273
* POSITION_GFXVertex (0,0,0);
274
* POSITION_GFXVertex (.1,.1,1);
275
* POSITION_GFXVertex (.1,-.1,1);
276
* POSITION_GFXVertex (0,0,0);
277
* POSITION_GFXVertex (-.1,-.1,1);
278
* POSITION_GFXVertex (-.1,.1,1);
279
* POSITION_GFXVertex (0,0,0);
280
* POSITION_GFXVertex (-.1,.1,1);
281
* POSITION_GFXVertex (.1,.1,1);
282
* POSITION_GFXVertex (0,0,0);
283
* POSITION_GFXVertex (.1,-.1,1);
284
* POSITION_GFXVertex(-.1,-.1,1);//one of the arrows to point
285
* POSITION_GFXVertex (0,0,0);
286
* POSITION_GFXVertex (.1,-.1,-1);
287
* POSITION_GFXVertex (.1,.1,-1);
288
* POSITION_GFXVertex (0,0,0);
289
* POSITION_GFXVertex (-.1,.1,-1);
290
* POSITION_GFXVertex (-.1,-.1,-1);
291
* POSITION_GFXVertex (0,0,0);
292
* POSITION_GFXVertex (.1,.1,-1);
293
* POSITION_GFXVertex (-.1,.1,-1);
294
* POSITION_GFXVertex (0,0,0);
295
* POSITION_GFXVertex (-.1,-.1,-1);
296
* POSITION_GFXVertex (.1,-.1,-1);//one of the arrows to point
297
*
298
*
299
* POSITION_GFXVertex (0,0,0);
300
* POSITION_GFXVertex (.1,-1,.1);
301
* POSITION_GFXVertex (.1,-1,-.1);
302
* POSITION_GFXVertex (0,0,0);
303
* POSITION_GFXVertex (-.1,-1,-.1);
304
* POSITION_GFXVertex (-.1,-1,.1);
305
* POSITION_GFXVertex (0,0,0);
306
* POSITION_GFXVertex (-.1,-1,.1);
307
* POSITION_GFXVertex (.1,-1,.1);
308
* POSITION_GFXVertex (0,0,0);
309
* POSITION_GFXVertex (.1,-1,-.1);
310
* POSITION_GFXVertex (-.1,-1,-.1);//one of the arrows to point
311
* POSITION_GFXVertex (0,0,0);
312
* POSITION_GFXVertex (.1,1,-.1);
313
* POSITION_GFXVertex (.1,1,.1);
314
* POSITION_GFXVertex (0,0,0);
315
* POSITION_GFXVertex (-.1,1,.1);
316
* POSITION_GFXVertex (-.1,1,-.1);
317
* POSITION_GFXVertex (0,0,0);
318
* POSITION_GFXVertex (.1,1,.1);
319
* POSITION_GFXVertex (-.1,1,.1);
320
* POSITION_GFXVertex (0,0,0);
321
* POSITION_GFXVertex (-.1,1,-.1);
322
* POSITION_GFXVertex (.1,1,-.1);//one of the arrows to point
323
*
324
*
325
* GFXEnd();
326
* GFXBegin (QUADS);
327
* //GFXColor4f (parentScene->HUDColor.r, parentScene->HUDColor.g, parentScene->HUDColor.b, 1.5*parentScene->HUDColor.a);
328
*
329
* GFXVertex3f(.5*CrosshairSize +LocalPosition.i,LocalPosition.j,0);
330
* GFXVertex3f(LocalPosition.i,.5*CrosshairSize+LocalPosition.j,0);
331
* GFXVertex3f(-.5*CrosshairSize +LocalPosition.i,LocalPosition.j,0);
332
* GFXVertex3f(LocalPosition.i,-.5*CrosshairSize+LocalPosition.j,0);
333
*
334
* GFXVertex3f(LocalPosition.i,-.5*CrosshairSize+LocalPosition.j,0);
335
* GFXVertex3f(-.5*CrosshairSize +LocalPosition.i,LocalPosition.j,0);
336
* GFXVertex3f(LocalPosition.i,.5*CrosshairSize+LocalPosition.j,0);
337
* GFXVertex3f(.5*CrosshairSize +LocalPosition.i,LocalPosition.j,0);
338
*
339
* GFXColor4f (0,.5,0,.5);
340
* POSITION_GFXVertex (1,.1,.1); //cap
341
* POSITION_GFXVertex (1,-.1,.1);
342
* POSITION_GFXVertex (1,-.1,-.1);
343
* POSITION_GFXVertex (1,.1,-.1);
344
*
345
* POSITION_GFXVertex (-1,.1,-.1);
346
* POSITION_GFXVertex (-1,-.1,-.1);
347
* POSITION_GFXVertex (-1,-.1,.1);
348
* POSITION_GFXVertex (-1,.1,.1); //cap
349
*
350
*
351
* POSITION_GFXVertex (.1,-1,.1); //cap
352
* POSITION_GFXVertex (-.1,-1,.1);
353
* POSITION_GFXVertex (-.1,-1,-.1);
354
* POSITION_GFXVertex (.1,-1,-.1);
355
*
356
* POSITION_GFXVertex (.1,1,-.1);
357
* POSITION_GFXVertex (-.1,1,-.1);
358
* POSITION_GFXVertex (-.1,1,.1);
359
* POSITION_GFXVertex (.1,1,.1); //cap
360
*
361
*
362
* POSITION_GFXVertex (.1,.1,1); //cap
363
* POSITION_GFXVertex (-.1,.1,1);
364
* POSITION_GFXVertex (-.1,-.1,1);
365
* POSITION_GFXVertex (.1,-.1,1);
366
*
367
* POSITION_GFXVertex (.1,-.1,-1);
368
* POSITION_GFXVertex (-.1,-.1,-1);
369
* POSITION_GFXVertex (-.1,.1,-1);
370
* POSITION_GFXVertex (.1,.1,-1); //cap
371
*
372
*
373
*
374
* GFXEnd();
375
*/
376
377
GFXPopBlendMode
();
378
}
379
380
#undef POSITION_GFXVertex
381
src
gfx
loc_select.cpp
Generated on Fri May 29 2015 23:07:24 for Vegastrike 0.5.1 rc1 by
1.8.4