Player12
An open source football management simulator
Loading...
Searching...
No Matches
PlayerRig Namespace Reference

Classes

struct  ActionInput
 
struct  FootState
 
struct  GaitBands
 
struct  KickTiming
 
struct  StrideInput
 
struct  Swing
 
struct  TwoBone
 

Enumerations

enum class  Action : std::uint8_t {
  IDLE , WALK , JOG , RUN ,
  SPRINT , TURN , PASS , SHOT ,
  CROSS , HEADER , TACKLE , SLIDE ,
  KEEPER_SET , KEEPER_DIVE , KEEPER_HOLD , THROW_IN ,
  CELEBRATE , DEJECTED
}
 
enum class  Event : std::uint8_t {
  NONE , PASS , SHOT , CROSS ,
  HEADER , TACKLE , SLIDE , THROW
}
 
enum class  Mood : std::uint8_t { NONE , CELEBRATE , DEJECTED }
 

Functions

float smoothStep (float t)
 
float flatDistance (Vec3 a, Vec3 b)
 
TwoBone solveTwoBone (Vec3 root, Vec3 target, float upper, float lower, Vec3 pole)
 
float rollOntoToes (Vec3 &ankle, Vec3 hip, Vec3 footForward, float toeLength, float reach, float maxAngle)
 
Vec3 stanceSpot (const StrideInput &input, float share)
 
Vec3 stepFoot (FootState &foot, const StrideInput &input)
 
Action locomotionFor (float speed, const GaitBands &bands={})
 
Action selectAction (const ActionInput &input, const GaitBands &bands={})
 
float dutyFactor (float speed)
 
Swing followThroughFor (Event event)
 
Vec3 kickAnkle (Event event, float seconds, Vec3 contact, Vec3 direction, Vec3 across, const KickTiming &timing, float &weight)
 

Variables

constexpr Vec3 UP {0.0f, 0.0f, 1.0f}
 
constexpr float PI = std::numbers::pi_v<float>
 
constexpr float TWO_PI = 2.0f * PI
 

Detailed Description

Procedural skeleton helpers of the 3D match view: a two-bone IK solver for legs and arms, foot planting that pins a stance foot to the grass while the body moves over it, the action chosen from the engine state, and the timed kick and tackle curves. Pure math (no drawing), so it is unit tested on its own. Distances are metres, angles radians, times simulated seconds.

Enumeration Type Documentation

◆ Action

enum class PlayerRig::Action : std::uint8_t
strong

What a player's body is doing, in order of the gait speeds.

Enumerator
IDLE 
WALK 
JOG 
RUN 
SPRINT 
TURN 
PASS 
SHOT 
CROSS 
HEADER 
TACKLE 
SLIDE 
KEEPER_SET 
KEEPER_DIVE 
KEEPER_HOLD 
THROW_IN 
CELEBRATE 
DEJECTED 

◆ Event

enum class PlayerRig::Event : std::uint8_t
strong

A timed ball action (started by an engine event) still playing.

Enumerator
NONE 
PASS 
SHOT 
CROSS 
HEADER 
TACKLE 
SLIDE 
THROW 

◆ Mood

enum class PlayerRig::Mood : std::uint8_t
strong

Goal reaction of the player's side.

Enumerator
NONE 
CELEBRATE 
DEJECTED 

Function Documentation

◆ dutyFactor()

float PlayerRig::dutyFactor ( float  speed)
inline

Share of the gait cycle a foot is on the ground at this speed (m/s).

◆ flatDistance()

float PlayerRig::flatDistance ( Vec3  a,
Vec3  b 
)
inline

◆ followThroughFor()

Swing PlayerRig::followThroughFor ( Event  event)
inline

◆ kickAnkle()

Vec3 PlayerRig::kickAnkle ( Event  event,
float  seconds,
Vec3  contact,
Vec3  direction,
Vec3  across,
const KickTiming &  timing,
float &  weight 
)
inline

Where the kicking ankle goes seconds after the ball was struck: on the ball at contact, then through along direction and back to the gait. weight (0..1) is how much the curve owns the leg (it hands back to foot planting during the recovery).

◆ locomotionFor()

Action PlayerRig::locomotionFor ( float  speed,
const GaitBands &  bands = {} 
)
inline

◆ rollOntoToes()

float PlayerRig::rollOntoToes ( Vec3 &  ankle,
Vec3  hip,
Vec3  footForward,
float  toeLength,
float  reach,
float  maxAngle 
)
inline

A planted foot the hip can no longer reach rolls onto its toes: the heel lifts around the toe (toe = ankle + forward * toeLength) until the ankle is back within reach of the hip, so the toe never leaves its spot. Returns the heel angle; ankle is updated in place.

◆ selectAction()

Action PlayerRig::selectAction ( const ActionInput &  input,
const GaitBands &  bands = {} 
)
inline

Picks the action that owns the body this frame. Dives beat everything, then the timed ball actions, then holding the ball (throw-in, keeper), goal reactions, the keeper's set stance and finally the gait.

◆ smoothStep()

float PlayerRig::smoothStep ( float  t)
inline

◆ solveTwoBone()

TwoBone PlayerRig::solveTwoBone ( Vec3  root,
Vec3  target,
float  upper,
float  lower,
Vec3  pole 
)
inline

Places the middle joint of a two-segment limb so the end lands on the target, bending towards pole (knees forward, elbows back). Targets out of reach leave the limb straight towards them.

◆ stanceSpot()

Vec3 PlayerRig::stanceSpot ( const StrideInput &  input,
float  share 
)
inline

Ideal stance position for a stance progress share in [0, 1].

◆ stepFoot()

Vec3 PlayerRig::stepFoot ( FootState &  foot,
const StrideInput &  input 
)
inline

Advances one foot and returns its world position on (or above) the grass. In stance the foot keeps the exact spot it was put down on, so it never slides; in swing it travels from where it lifted off to the next landing spot on a low arc. Standing players keep both feet down and only step when the body has drifted away from them.

Variable Documentation

◆ PI

constexpr float PlayerRig::PI = std::numbers::pi_v<float>
inlineconstexpr

◆ TWO_PI

constexpr float PlayerRig::TWO_PI = 2.0f * PI
inlineconstexpr

◆ UP

constexpr Vec3 PlayerRig::UP {0.0f, 0.0f, 1.0f}
inlineconstexpr