Exemple #1
0
static void renderBlock(const Scene *scene, Sampler *sampler, ImageBlock &block) {
    const Camera *camera = scene->getCamera();
    const Integrator *integrator = scene->getIntegrator();

    Point2i offset = block.getOffset();
    Vector2i size  = block.getSize();

    /* Clear the block contents */
    block.clear();

    /* For each pixel and pixel sample sample */
    for (int y=0; y<size.y(); ++y) {
        for (int x=0; x<size.x(); ++x) {
            for (uint32_t i=0; i<sampler->getSampleCount(); ++i) {
                Point2f pixelSample = Point2f((float) (x + offset.x()), (float) (y + offset.y())) + sampler->next2D();
                Point2f apertureSample = sampler->next2D();

                /* Sample a ray from the camera */
                Ray3f ray;
                Color3f value = camera->sampleRay(ray, pixelSample, apertureSample);

                /* Compute the incident radiance */
                value *= integrator->Li(scene, sampler, ray);

                /* Store in the image block */
                block.put(pixelSample, value);
            }
        }
    }
}
Exemple #2
0
// Draw the weapon fire when firing
void Weapon::DrawWeaponFire()
{
  if (m_weapon_fire == NULL) return;
  Point2i hand;
  ActiveCharacter().GetHandPosition(hand);
  Point2i hole(hand +  hole_delta * Point2i(ActiveCharacter().GetDirection(),1));

  if (ActiveCharacter().GetDirection() == DIRECTION_RIGHT)
    hole = hole -  Point2i(0, m_weapon_fire->GetHeight()/2);
  else
    hole = hole +  Point2i(0, m_weapon_fire->GetHeight()/2);
  Double dst = hand.Distance(hole);
  Double angle = hand.ComputeAngle(hole);

  angle += ActiveCharacter().GetFiringAngle();

  if (ActiveCharacter().GetDirection() == DIRECTION_LEFT)
    angle -= PI;

  Point2i spr_pos =  hand + Point2i(static_cast<int>(dst * cos(angle)),
                                    static_cast<int>(dst * sin(angle)));

  m_weapon_fire->SetRotation_HotSpot(Point2i(0,0));
  m_weapon_fire->SetRotation_rad(ActiveCharacter().GetFiringAngle());
  m_weapon_fire->Draw(spr_pos);
}
Exemple #3
0
	bool Map::CanMove(const Direction & d1, const Point2i & pos) const
	{

		return (_cases[pos.x][pos.y].canDirection(d1)
			&& GetCase(pos.addDirection(d1)).canDirection(directionOpposee(d1))
			&& GetPracticable(pos.addDirection(d1)));

	}
void CircleDistance::setPosition(const Point2i& rPosition)
{
    Vector2f pointPFloat(float(rPosition.getX()), float(rPosition.getY()));
    Vector2f vecRaduis(pointPFloat - m_pointCenter);

    m_position = rPosition;
    m_distanceSquaredFromCenter = vecRaduis.getLengthSquared();
}
Exemple #5
0
float AIIdea::RateExplosion(const Character & shooter, const Point2i& position,
                            const ExplosiveWeaponConfig& config,
                            const float& expected_additional_distance)
{
  float rating = 0.0f;

  FOR_ALL_LIVING_CHARACTERS(team, character) {
    float distance = position.Distance(character->GetCenter());
    distance += expected_additional_distance;
    if (distance < 1.0f)
      distance = 1.0f;
    Double Dist = distance;
    float min_damage = GetDamageFromExplosion(config, Dist);
    float max_damage = min_damage;
    if (Dist <= config.blast_range) {
      float force = GetForceFromExplosion(config, Dist).tofloat();
      min_damage += MIN_DAMAGE_PER_FORCE_UNIT * force;
      max_damage += MAX_DAMAGE_PER_FORCE_UNIT * force;
    }
    bool is_friend = shooter.GetTeamIndex() == character->GetTeamIndex();
    if (is_friend) {
      rating -= RateDamageDoneToEnemy(min_damage, max_damage, *character);
    } else {
      rating += RateDamageDoneToEnemy(min_damage, max_damage, *character);
    }
  }
Exemple #6
0
const Point2i Weapon::GetGunHolePosition() const
{
  Point2i pos;
  ActiveCharacter().GetHandPosition(pos);
  Point2i hole(pos + hole_delta * Point2i(ActiveCharacter().GetDirection(),1));
  Double dst = pos.Distance(hole);
  Double angle = pos.ComputeAngle(hole);

  if (ActiveCharacter().GetDirection() == DIRECTION_RIGHT)
    angle += ActiveCharacter().GetFiringAngle();
  else
    angle += ActiveCharacter().GetFiringAngle() - PI;

  return pos + Point2i(static_cast<int>(dst * cos(angle)),
                       static_cast<int>(dst * sin(angle)));
}
Exemple #7
0
bool Weapon::Shoot()
{
  MSG_DEBUG("weapon.shoot", "Enough ammo ? %d", EnoughAmmo());
  MSG_DEBUG("weapon.shoot", "Enough ammo unit ? %d", EnoughAmmoUnit());
  MSG_DEBUG("weapon.shoot", "Use unit on 1st shoot ? %d", use_unit_on_first_shoot);

  if (!IsReady())
    return false;

  MSG_DEBUG("weapon.shoot", "Enough ammo");

  #ifdef DEBUG
  Point2i hand;
  ActiveCharacter().GetHandPosition(hand);
  MSG_DEBUG("weapon.shoot", "%s Shooting at position:%d,%d (hand: %d,%d)",
            ActiveCharacter().GetName().c_str(),
            ActiveCharacter().GetX(),
            ActiveCharacter().GetY(),
            hand.GetX(),
            hand.GetY());
  ActiveCharacter().body->DebugState();
  #endif
  if (!p_Shoot()) {
    MSG_DEBUG("weapon.shoot", "shoot has failed!!");
    return false;
  }
  m_last_fire_time = Time::GetInstance()->Read();

  MSG_DEBUG("weapon.shoot", "shoot!");

  // Is this the first shoot for this ammo use ?
  if (ActiveTeam().ReadNbUnits() == m_initial_nb_unit_per_ammo) {
    UseAmmo();
  }

  if (use_unit_on_first_shoot){
    UseAmmoUnit();
  }

  if (max_strength.IsNotZero())
    ActiveCharacter().previous_strength = m_strength;

  Game::GetInstance()->SetCharacterChosen(true);

  return true;
}
 /* Public */
 RubBrowserControls::RubBrowserControls(const Point2i &position, const Point2i &dimensions) :
     BrowserControls(position, dimensions)
 {
     int px = position.getX();
     int py = position.getY();
     int dx = dimensions.getX() - CONTROL_BAR_HEIGHT;
     int dy = dimensions.getY();
     
     bx = getSizef(dx);
     by = getSizef(dy);
     
     px += dx;
     dy = CONTROL_BAR_HEIGHT;
     
     exit = new ExitButton(Point2i(px, py), Point2i(dy, dy));
     exit->setClickedCallback(MakeDelegate(this, &RubBrowserControls::exit_Clicked));
     registerEventHandler(exit);
 }
Exemple #9
0
bool Window::isOver(Point2i p) const {
    if (!on) {
        return false;
    }
    /// @todo Shouldn't this be <tt>position.x() + border.size.width()</tt> (and
    /// <tt>position.x() + size.width() - 2 * borderSize.width()</tt>?
    if (p.x() < this->position.x() + this->border.size.width() ||
        p.x() > this->position.x() + 2 * this->border.size.width() + this->size.width()) {
        return false;
    }
    /// @todo Shouldn't this be <tt>position.y() + border.size.height()</tt> (and
    /// <tt>position.y() + size.height() - 2 * borderSize.height()</tt>?
    if (p.y() < this->position.y() + this->border.size.height() ||
        p.y() > this->position.y() + 2 * this->border.size.height() + this->size.height()) {
        return false;
    }
    return true;
}
	void ObjectMenu::initMenuItems(void)
	{
		unsigned int width = dimensions.getX();

		Point2i subMenuPos = position;

		if(mode == CREATE)
		{
			std::vector<OptionGrid::Option> options;
			options.push_back(OptionGrid::Option(PhysicsObject::CIRCLE, "Circle"));
			options.push_back(OptionGrid::Option(PhysicsObject::SQUARE, "Square"));
			options.push_back(OptionGrid::Option(PhysicsObject::TRIANGLE, "Triangle"));
			options.push_back(OptionGrid::Option(PhysicsObject::PARTICLES, "Particles"));
			options.push_back(OptionGrid::Option(PhysicsObject::BOMB, "Bomb"));
			options.push_back(OptionGrid::Option(PhysicsObject::WHEEL, "Wheel"));

			type = new OptionGrid(options, "Object Type", position, width);
			type->setSelectionChangedCallback(MakeDelegate(this, &ObjectMenu::type_SelectionChanged));
			addMenuItem(*type);

			subMenuPos = type->getPosition();
			subMenuPos.translateY(type->getDimensions().getY());
		}

		// child menus
		circleMenu			= new SimpleObjectMenu((SimpleObject *)new Circle(), subMenuPos, width, mode);
		particleEmitterMenu	= new ParticleEmitterMenu(new ParticleEmitter(), subMenuPos, width, mode);
		squareMenu			= new SimpleObjectMenu((SimpleObject *)new Square(), subMenuPos, width, mode);
		triangleMenu		= new SimpleObjectMenu((SimpleObject *)new Triangle(), subMenuPos, width, mode);
		bombMenu			= new BombMenu(new Bomb(), subMenuPos, width, mode);
		wheelMenu			= new WheelMenu(new Wheel(), subMenuPos, width, mode);

		circleMenu->setErasedCallback(MakeDelegate(this, &ObjectMenu::object_Erased));
		particleEmitterMenu->setErasedCallback(MakeDelegate(this, &ObjectMenu::object_Erased));
		squareMenu->setErasedCallback(MakeDelegate(this, &ObjectMenu::object_Erased));
		triangleMenu->setErasedCallback(MakeDelegate(this, &ObjectMenu::object_Erased));
		bombMenu->setErasedCallback(MakeDelegate(this, &ObjectMenu::object_Erased));
	}
Exemple #11
0
void toggleFullscreen(void)
{
	if(fullscreen)
	{
		glutReshapeWindow(savedWinDims.getX(), savedWinDims.getY());
		glutPositionWindow(savedWinPos.getX(), savedWinPos.getY());
	}
	else
	{
		unsigned int w = glutGet(GLUT_WINDOW_WIDTH);
		unsigned int h = glutGet(GLUT_WINDOW_HEIGHT);
		unsigned int x = glutGet(GLUT_WINDOW_X);
		unsigned int y = glutGet(GLUT_WINDOW_Y);
        
		savedWinDims.setX(w);
		savedWinDims.setY(h);
		savedWinPos.setX(x);
		savedWinPos.setY(y);
        
		glutFullScreen();
	}
    
	fullscreen = !fullscreen;
}
    /* Public */
    Camera::Camera(const Point2i &position, const Point2i &dimensions, const Point2i &frameDimensions, const Point2i &textureDimensions) :
        UIElement(position, dimensions)
    {
        this->frameDimensions = frameDimensions;
        
        int px = position.getX();
        int py = position.getY() + dimensions.getY() - CONTROL_BAR_HEIGHT;
        int dx = dimensions.getX() - 125;
        int dy = CONTROL_BAR_HEIGHT;
        
        controls = new CameraControls(Point2i(px, py), Point2i(dx, dy));
        controls->setClickedCallback(MakeDelegate(this, &Camera::controls_Clicked));
        registerEventHandler(controls);
        
        mode = new ModeToggle(Point2i(dx, py), Point2i(125, dy), "switch_slide.png", "switch_rub.png");
        mode->setClickedCallback(MakeDelegate(this, &Camera::mode_Clicked));
        registerEventHandler(mode);
        
        GLfloat data[12] =
		{
			0.0f, 0.0f, 0.0f,
			0.0f, 1.0f, 0.0f,
			1.0f, 0.0f, 0.0f,
			1.0f, 1.0f, 0.0f
		};

        float u0 = 0.0f;
        float u1 = (float)frameDimensions.getX() / (float)textureDimensions.getX();
        float v0 = 0.0f;// 
        float v1 = (float)frameDimensions.getY() / (float)textureDimensions.getY();
        GLfloat textureData[8] =
		{
			u0, v1,
			u1, v1,
			u0, v0,
			u1, v0
		};

        vbo = new GLVbo(GL_TRIANGLE_STRIP, GL_STATIC_DRAW, data, 4, textureData);
    }
Exemple #13
0
Point2i::Point2i(const Point2i &_p) 
    : x_(_p.x()), y_(_p.y()) {}
Exemple #14
0
void Weapon::Draw(){
  if (Game::GetInstance()->ReadState() != Game::PLAYING &&
      m_last_fire_time + 100 < Time::GetInstance()->Read())
    return;

#ifndef DEBUG_HOLE
  if (m_last_fire_time + m_fire_remanence_time > Time::GetInstance()->Read())
#endif
    DrawWeaponFire();

  DrawAmmoUnits();

  ASSERT(drawable || !ShouldBeDrawn());
  if (!(drawable && ShouldBeDrawn()))
    return;

  if (ActiveCharacter().IsGhost()
      || ActiveCharacter().IsDrowned()
      || ActiveCharacter().IsDead())
    return;

  // rotate weapon if needed
  if (!EqualsZero(min_angle - max_angle)) {
    if (ActiveCharacter().GetDirection() == DIRECTION_RIGHT)
      m_image->SetRotation_rad(ActiveCharacter().GetFiringAngle());
    else
      m_image->SetRotation_rad(ActiveCharacter().GetFiringAngle()-PI);
  } else {
    m_image->SetRotation_rad(ZERO);
  }

  // flip image if needed
  if (use_flipping) {
    m_image->SetFlipped(DIRECTION_LEFT == ActiveCharacter().GetDirection());
  }

  // Calculate position of the image
  int x,y;
  PosXY (x, y);

  // Animate the display of the weapon:
  if (m_time_anim_begin + ANIM_DISPLAY_TIME > Time::GetInstance()->Read()) {
    if (!EqualsZero(min_angle - max_angle)) {
      Double angle = m_image->GetRotation_rad();
      angle += sin(HALF_PI * Double(Time::GetInstance()->Read() - m_time_anim_begin) / ANIM_DISPLAY_TIME)
             * TWO_PI;
      m_image->SetRotation_rad(angle);
      m_image->Scale(ONE, ONE);
    }
    else {
      Double scale = sin((Double)1.5 * HALF_PI * Double(Time::GetInstance()->Read() - m_time_anim_begin) / ANIM_DISPLAY_TIME)
                   / sin((Double)1.5 * HALF_PI);
      if (scale.IsNotZero()) {
        m_image->Scale(scale, scale);
        m_image->SetFlipped(DIRECTION_LEFT == ActiveCharacter().GetDirection());
      }

      // Recompute position to get the icon centered over the skin
      if (origin == weapon_origin_OVER)
        PosXY(x,y);
    }
  } else
    m_image->Scale(ONE, ONE);

  if (m_image)
    m_image->Blit(GetMainWindow(), Point2i(x, y) - Camera::GetInstance()->GetPosition());

#ifdef DEBUG
  if (IsLOGGING("weapon")) {
    Point2i hand;
    ActiveCharacter().GetHandPosition(hand);
    Rectanglei rect(hand - 1 - Camera::GetInstance()->GetPosition(),
                    Point2i(3, 3));

    GetWorld().ToRedrawOnMap(rect);

    GetMainWindow().RectangleColor(rect, c_red);

    MSG_DEBUG("weapon.handposition", "Position: %d, %d - hand: %d, %d",
              ActiveCharacter().GetX(), ActiveCharacter().GetY(),
              hand.GetX(), hand.GetY());
  }
  if (IsLOGGING("weapon.hole")) {
    Rectanglei rect(GetGunHolePosition() - Camera::GetInstance()->GetPosition() - 1,
                    Point2i(3, 3));
  
    GetWorld().ToRedrawOnMap(rect);
    GetMainWindow().RectangleColor(rect, c_red);
  }
#endif
}