Exemplo n.º 1
0
  void Crate_State::perform_logic() {
    const Time_HQ current_time = get_Timer_HQ().get_time();
    float processing_time = float(current_time.get_seconds_since(time_passed));
    time_passed = current_time;

    /** Get forward and left vectors in the XY-plane **/
    const Vector3f forward = m_player.get_camera().get_forward().get_ij().normalized();
    const Vector3f left = m_player.get_camera().get_left().get_ij().normalized();

    /** Get velocity vector split into a number of axes **/
    const Vector3f velocity = (m_controls.forward - m_controls.back) * 50.0f * forward
                            + (m_controls.left - m_controls.right) * 50.0f * left;
    const Vector3f x_vel = velocity.get_i();
    const Vector3f y_vel = velocity.get_j();
    Vector3f z_vel = m_player.get_velocity().get_k();

    /** Bookkeeping for sound effects **/
    if(velocity.magnitude() != 0.0f)
      m_moved = true;

    /** Keep delays under control (if the program hangs for some time, we don't want to lose responsiveness) **/
    if(processing_time > 0.1f)
      processing_time = 0.1f;

    /** Physics processing loop**/
    for(float time_step = 0.05f;
        processing_time > 0.0f;
        processing_time -= time_step)
    {
      if(time_step > processing_time)
        time_step = processing_time;

      /** Gravity has its effect **/
      z_vel -= Vector3f(0.0f, 0.0f, 50.0f * time_step);
	  other_crate.applyGravity(time_step);


      /** Try to move on each axis **/
      partial_step(time_step, x_vel);
      partial_step(time_step, y_vel);
      partial_step(time_step, z_vel);

      /** Keep player above ground; Bookkeeping for jumping controls **/
      const Point3f &position = m_player.get_camera().position;
      if(position.z < 50.0f) {
        m_player.set_position(Point3f(position.x, position.y, 50.0f));
        m_player.set_on_ground(true);
      }
    }
  }
// ****************************************************************************
//  Method: avtIVPNIMRODIntegrator::vpstep
//
//  Purpose:
//      Take a step and return the result.
//
//  Programmer: Allen Sanderson
//  Creation:   October 24, 2009
//
// ****************************************************************************
avtIVPSolver::Result 
avtIVPNIMRODIntegrator::vpstep(const avtIVPField* field,
                              avtVector &yCur, double h, avtVector &yNew)
{
  avtIVPSolver::Result res;

  double xin[3], xout[3];

  xin[0] = yCur[0];
  xin[1] = yCur[1];
  xin[2] = yCur[2];

  if (res = partial_step(field,  xin, 0, 0.5*h, xout)) return res;
  if (res = partial_step(field, xout, 1, 0.5*h, xout)) return res;
  if (res = partial_step(field, xout, 2,     h, xout)) return res;
  if (res = partial_step(field, xout, 1, 0.5*h, xout)) return res;
  if (res = partial_step(field, xout, 0, 0.5*h, xout)) return res;

  yNew[0] = xout[0];
  yNew[1] = xout[1];
  yNew[2] = xout[2];

  return avtIVPSolver::OK;
}
Exemplo n.º 3
0
  void Level_1::perform_logic() {
    const Time_HQ current_time = get_Timer_HQ().get_time();
    float processing_time = float(current_time.get_seconds_since(time_passed));
    time_passed = current_time;

    /** Get forward and left vectors in the XY-plane **/
    const Vector3f forward = m_player.get_camera().get_forward().get_ij().normalized();
    const Vector3f left = m_player.get_camera().get_left().get_ij().normalized();

    /** Get velocity vector split into a number of axes **/
	int grav_dir = m_player.get_gravity_direction();
	Vector3f velocity;
	Vector3f x_vel, y_vel, z_vel;

    velocity = (m_controls.forward - m_controls.back) * 50.0f * forward
                            + (m_controls.left - m_controls.right) * 50.0f * left;
	x_vel = velocity.get_i();
      y_vel = velocity.get_j();
     z_vel = m_player.get_velocity().get_k();

	 if (m_fire)
	 {
		 m_fire = false;
		 m_bullets.push_back(m_player.fire());
	 }

	 //Move bullets forward and heck collision 
	for(list<Bullet *>::iterator it = m_bullets.begin(); it != m_bullets.end();)
	{
		(*it)->move_forward(processing_time * 200.0f);
		
		if (m_crate.get_body().intersects((*it)->get_body()))
		{
			m_crate.set_velocity(m_player.get_gravity_direction());
			delete *it;
			it = m_bullets.erase(it);
		}
		else
			++it;
	}

	m_crate.move(processing_time * 10.0f);

    /** Bookkeeping for sound effects **/
    if(velocity.magnitude() != 0.0f)
      m_moved = true;

    /** Keep delays under control (if the program hangs for some time, we don't want to lose responsiveness) **/
    if(processing_time > 0.1f)
      processing_time = 0.1f;

    /** Physics processing loop**/
    for(float time_step = 0.05f; processing_time > 0.0f; processing_time -= time_step)
    {
      if(time_step > processing_time)
        time_step = processing_time;

      /** Gravity has its effect **/
		z_vel -= Vector3f(0.0f, 0.0f, 50.0f * time_step);

		on_top = false;
      /** Try to move on each axis **/
      partial_step(time_step, x_vel);
      partial_step(time_step, y_vel);
      partial_step(time_step, z_vel);

	  if (m_crate.get_body().intersects(m_player.get_body()) && m_player.get_body().get_end_point_b().z > m_crate.get_body().get_point().z + m_crate.get_body().get_edge_c().k)
	  { //Currently only works for up/down movement while on crate
		  Point3f base_pos =  m_player.get_camera().position;
		  m_player.set_position(base_pos + m_crate.get_velocity());
	  }

      /** Keep player above ground; Bookkeeping for jumping controls **/
      const Point3f &position = m_player.get_camera().position;
      if(position.z < 50.0f) {
        m_player.set_position(Point3f(position.x, position.y, 50.0f));
        m_player.set_on_ground(true);
      }
    }

	if (m_crate2.get_body().intersects(m_player.get_body()))
	{
		//get_Game().pop_state();
		get_Game().push_state(new Crate_State());
	}
  }