Changeset 1357


Ignore:
Timestamp:
May 9, 2012, 6:40:49 PM (11 years ago)
Author:
sam
Message:

orbital: clamp ship heading to full 45-degree orientations.

Location:
trunk/orbital
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/orbital/orbital.cpp

    r1354 r1357  
    1111#if defined _WIN32
    1212#   include <direct.h>
     13#endif
     14
     15#if defined _XBOX
     16#   define _USE_MATH_DEFINES /* for M_PI */
     17#   include <xtl.h>
     18#   undef near /* Fuck Microsoft */
     19#   undef far /* Fuck Microsoft again */
     20#elif defined _WIN32
     21#   define _USE_MATH_DEFINES /* for M_PI */
     22#   define WIN32_LEAN_AND_MEAN
     23#   include <windows.h>
     24#   undef near /* Fuck Microsoft */
     25#   undef far /* Fuck Microsoft again */
     26#else
     27#   include <cmath>
    1328#endif
    1429
  • trunk/orbital/player.h

    r1354 r1357  
    5353    {
    5454        if (m_stick)
    55             Ticker::Unref(m_stick);
     55            Input::UntrackStick();
    5656    }
    5757
     
    7474            rightleft += 1.f * m_stick->GetAxis(2);
    7575            updown += -1.f * m_stick->GetAxis(3);
     76        }
     77
     78        /* Clamp direction at 45-degree multiples */
     79        if (rightleft * rightleft + updown * updown > 0.2f)
     80        {
     81            float norm = sqrt(rightleft * rightleft + updown * updown);
     82            float angle = atan2(updown, rightleft);
     83            angle = (int)(angle / (M_PI / 4.f) + 8.5f) * (M_PI / 4.f);
     84            rightleft = cos(angle);
     85            updown = sin(angle);
     86        }
     87        else
     88        {
     89            rightleft = updown = 0.f;
    7690        }
    7791
Note: See TracChangeset for help on using the changeset viewer.