1
0
forked from 0ad/0ad

Mouse wheel zoom, lack of it was irritating me.

This was SVN commit r264.
This commit is contained in:
MarkT 2004-05-25 22:02:57 +00:00
parent 3ae2db717d
commit 88e8a56487
2 changed files with 41 additions and 6 deletions

View File

@ -34,6 +34,7 @@
u32 game_ticks;
bool keys[SDLK_LAST];
bool mouseButtons[5];
#include <cmath>
@ -179,6 +180,16 @@ static bool handler(const SDL_Event& ev)
c = ev.key.keysym.sym;
keys[c] = false;
break;
case SDL_MOUSEBUTTONDOWN:
c = ev.button.button;
if( c < 5 )
mouseButtons[c] = true;
break;
case SDL_MOUSEBUTTONUP:
c = ev.button.button;
if( c < 5 )
mouseButtons[c] = false;
break;
}
return 0;
@ -346,6 +357,9 @@ void ParseArgs(int argc, char* argv[])
if( g_Gamma == 0.0f ) g_Gamma = 1.0f;
}
break;
case 'v':
g_VSync = true;
break;
case 'n':
if (strncmp(argv[i]+1,"novbo",5)==0) {
g_NoGLVBO=true;
@ -544,6 +558,9 @@ in_add_handler(terr_handler);
double time1 = get_time();
mouseButtons[SDL_BUTTON_WHEELUP] = false;
mouseButtons[SDL_BUTTON_WHEELDOWN] = false;
in_get_events();
UpdateWorld(float(time1-time0));
terr_update(float(time1-time0));

View File

@ -16,7 +16,7 @@ void InitResources ();
void RenderScene ();
extern bool keys[512]; // SDL also defines non-ascii keys; 512 should be enough
extern bool mouseButtons[5];
CMatrix3D g_WorldMat;
CRenderer g_Renderer;
@ -91,13 +91,30 @@ please put this code out of its misery :)
*/
float fov = g_Camera.GetFOV();
const float d = DEGTORAD(10.0f) * DeltaTime;
const float d_key = DEGTORAD(10.0f) * DeltaTime;
const float d_wheel = DEGTORAD( 50.0f ) * DeltaTime;
const float fov_max = DEGTORAD( 60.0f );
const float fov_min = DEGTORAD( 10.0f );
if(keys[SDLK_KP_MINUS])
if (fov < DEGTORAD(60.f))
fov += d;
if (fov < fov_max)
fov += d_key;
if(keys[SDLK_KP_PLUS])
if (fov-d > DEGTORAD(10))
fov -= d;
if (fov-d_key > fov_min)
fov -= d_key;
if( mouseButtons[SDL_BUTTON_WHEELUP] )
{
fov += d_wheel;
if( fov > fov_max )
fov = fov_max;
}
if( mouseButtons[SDL_BUTTON_WHEELDOWN] )
{
fov -= d_wheel;
if( fov < fov_min )
fov = fov_min;
}
ViewFOV = fov;
@ -118,6 +135,7 @@ bool terr_handler(const SDL_Event& ev)
mouse_x = ev.motion.x;
mouse_y = ev.motion.y;
break;
case SDL_KEYDOWN:
switch(ev.key.keysym.sym)