コード例 #1
0
ファイル: PoolCue.cpp プロジェクト: jason-amju/amju-scp
void PoolCue::Draw()
{
#ifdef CUE_DEBUG
  glLineWidth(2.0f);
  glBegin(GL_LINES);
  glVertex3f(m_v1.x, m_v1.y, m_v1.z);
  glVertex3f(m_v2.x, m_v2.y, m_v2.z);
  glEnd();
  return;
#endif 
 
  // Position cue - take into account
  // - ball pos
  // - Y-rot of player; i.e. the shot angle
  // - cue elevation; i.e. masse
  // - cue contact pos 

  // Find ball centre.
  Orientation o = *(GetBall()->GetOrientation());
  // Move the centre depending on draw/roll/english

  // Find player shot direction.
  float yr = Engine::Instance()->GetGameState()->GetCurrentPlayerInfo()->m_golfStroke.m_yRot;
  float elev = Engine::Instance()->GetGameState()->GetCurrentPlayerInfo()->m_golfStroke.m_cueElevationDegs;

#ifdef CUE_DEBUG
std::cout << "POOL CUE: Elev: " << elev << " degs\n";
#endif

  // If in birds eye mode, move the cue up a bit so it doesn't intersect
  // the table.
  if (EngineStatePoolBase::IsBirdsEye())
  {
    o.SetY(o.GetY() + 2.0f);
  }

  AmjuGL::PushMatrix();
  o.SetZRot(elev); 
  o.SetYRot(yr + 90.0f);
  o.Draw();
  // Set contact pos
  AmjuGL::Translate(0, m_y, m_x); 
  // Swing cue forward or back
  AmjuGL::Translate(m_swingPos, 0, 0); 
  m_pSolid->Draw();
  AmjuGL::PopMatrix();
}
コード例 #2
0
void EngineStatePoolShowShot::Update()
{
  if (m_time < m_maxTime)
  {
    // POOL_ONLINE:
    // DON'T call EngineStatePoolBase::Update();
    // If the timer expires, the shot will be started, but we DON'T want to update
    //  the shot in this state, for consistency with the other (user-controlled) client.

    // If a moving ball is outside of the view frustum, pull the camera back.
    ((PoolCamera*)s_pCamera.GetPtr())->SetPoolPullBackRequired(s_movingBallNotInFrustum);
    s_movingBallNotInFrustum = false;

    GetCamera()->Update();

    if (!IsBirdsEye())
    {
      // Update the camera so it is always above the ball
      float camY = GetCamera()->GetOrientation()->GetY();
      float ballY = GetBall()->GetOrientation()->GetY();
      ballY += 1.0f; // TODO CONFIG
      if (camY < ballY)
      {
        Orientation o = *(GetCamera()->GetOrientation());
        o.SetY(ballY);
        GetCamera()->SetOrientation(o);
      }
    }
    // May call TimerExpired.....
    EngineState::Update();

    if (m_time < m_maxTime)
    {
      Assert(m_pLevel.GetPtr());
////      GetEngine()->GetDayNightSky()->Update();
      m_pLevel->GetScene()->Update();
      UpdateGameObjects();
    }
  }
  else
  {
    // DON'T update game objects
    EngineState::Update();
  }
}
コード例 #3
0
void ThirdPersonCameraBase::Update()
{
  Camera::Update();

  float dt = Engine::Instance()->GetDeltaTime();

  // New for POOL 
  // Zoom in/out, (not using mouse)
  if (m_zoomVel != 0)
  {
#ifdef ZOOM_DEBUG
std::cout << "ZOOM: old zoom vel: " << m_zoomVel << "\n";
#endif

    // Decelerate to zero
    static const float ZOOM_DECEL = Engine::Instance()->GetConfigFloat(
      "pool_cam_zoom_decel");
    Assert(ZOOM_DECEL > 0); 
    if (m_zoomVel > 0)
    {
      m_zoomVel -= ZOOM_DECEL * dt;
      if (m_zoomVel < 0)
      {
        m_zoomVel = 0;
      }
    }
    else if (m_zoomVel < 0)
    {
      m_zoomVel += ZOOM_DECEL * dt;
      if (m_zoomVel > 0)
      {
        m_zoomVel = 0;
      }
    }

#ifdef ZOOM_DEBUG
std::cout << "ZOOM: new zoom vel: " << m_zoomVel << "\n";
#endif

    // Move away or towards the target, at the zoom vel.
    Vec3f v = m_orientation.GetVertex() - m_lookAtPos;
    v.Normalise();
    v *= m_zoomVel * dt;
#ifdef ZOOM_DEBUG
std::cout << "ZOOM add vec: " << ToString(v).c_str() << "\n";
#endif

    Vec3f v0 = m_orientation.GetVertex(); 
    v0 += v;
    m_orientation.SetVertex(v0);
  }

  static float prevRot = m_yRotVel;
  if (m_yRotVel != 0)
  {
    static const float MAX_Y_ROT_VEL = 360.0f;
    //static const float MIN_Y_ROT_VEL = 10.0f;
    m_yRotVel += dt * m_yRotAcc;
    if (fabs(m_yRotVel) > MAX_Y_ROT_VEL)
    {
      m_yRotVel = MAX_Y_ROT_VEL;
      m_yRotAcc = 0;
    }
    if (Sign(m_yRotVel) != Sign(prevRot) && prevRot != 0)
    {
      m_yRotVel = 0;
      m_yRotAcc = 0;
    }
    float yRot = m_yRotVel * dt;
    RotateCameraHoriz(yRot);
  }
  prevRot = m_yRotVel;

  static float prevUp = m_upVel;
  if (m_upVel != 0)
  {
//std::cout << "Up vel: " << m_upVel << " acc: " << m_upAcc;

    float y = GetOrientation()->GetY();
    m_upVel += dt * m_upAcc;
    if (Sign(m_upVel) != Sign(prevUp) && prevUp != 0)
    {
      m_upVel = 0;
      m_upAcc = 0;
    }
    y += m_upVel * dt;

//std::cout << "  new Up vel: " << m_upVel << "\n";

    Orientation o = *(GetOrientation());
    // Never exceed the absolute max camera height.
    if (y > m_maxAbsHeight)
    {
      y = m_maxAbsHeight;
    }
    o.SetY(y);
    SetOrientation(o);
  }
  prevUp = m_upVel;
}