Skip to content

Commit

Permalink
Different axis types: pointer, stick
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 11, 2004
1 parent 4478e32 commit 1fc23b2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
15 changes: 14 additions & 1 deletion doomsday/Src/con_bind.c
Expand Up @@ -178,13 +178,26 @@ void B_UpdateAxisControls(void)
for(i = 0, ab = axisBinds; i < numAxisBinds; i++, ab++)
{
axis = &ab->device->axes[ab->axis];

// Invert the axis position, if requested.
if(ab->invert)
pos = -axis->position;
else
pos = axis->position;

// Update the control state.
P_ControlSetAxis(P_LocalToConsole(ab->localPlayer), ab->control, pos);
switch(ab->device->axes[ab->axis].type)
{
case IDAT_STICK: // joysticks, gamepads
P_ControlSetAxis(P_LocalToConsole(ab->localPlayer),
ab->control, pos);
break;

case IDAT_POINTER: // mouse
P_ControlAxisDelta(P_LocalToConsole(ab->localPlayer),
ab->control, pos);
break;
}
}
}

Expand Down
23 changes: 14 additions & 9 deletions doomsday/Src/dd_input.c
Expand Up @@ -198,6 +198,8 @@ inputdevaxis_t *I_DeviceNewAxis(inputdev_t *dev, const char *name)
memset(axis, 0, sizeof(*axis));
strcpy(axis->name, name);

axis->type = IDAT_STICK;

// Set reasonable defaults. The user's settings will be restored
// later.
axis->scale = 1/10.0f;
Expand Down Expand Up @@ -229,8 +231,8 @@ void I_InitInputDevices(void)

// The wheel is translated to keys, so there is no need to
// create an axis for it.
I_DeviceNewAxis(dev, "x");
I_DeviceNewAxis(dev, "y");
I_DeviceNewAxis(dev, "x")->type = IDAT_POINTER;
I_DeviceNewAxis(dev, "y")->type = IDAT_POINTER;

if(I_MousePresent())
dev->flags = ID_ACTIVE;
Expand Down Expand Up @@ -350,15 +352,18 @@ void I_UpdateAxis(inputdev_t *dev, int axis, float pos)

// Apply scaling, deadzone and clamping.
pos *= a->scale;
if(fabs(pos) <= a->deadZone)
if(a->type == IDAT_STICK) // Pointer axes are exempt.
{
a->position = 0;
return;
if(fabs(pos) <= a->deadZone)
{
a->position = 0;
return;
}
pos += a->deadZone * (pos > 0? -1 : 1); // Remove the dead zone.
pos *= 1.0f/(1.0f - a->deadZone); // Normalize.
if(pos < -1.0f) pos = -1.0f;
if(pos > 1.0f) pos = 1.0f;
}
pos += a->deadZone * (pos > 0? -1 : 1); // Remove the dead zone.
pos *= 1.0f/(1.0f - a->deadZone); // Normalize.
if(pos < -1.0f) pos = -1.0f;
if(pos > 1.0f) pos = 1.0f;

if(a->flags & IDA_INVERT)
{
Expand Down

0 comments on commit 1fc23b2

Please sign in to comment.