示例#1
0
static bool		areaLightInShadow(AreaLightClass *self,
                                          RayStruct *shadowRay)
{
  SceneClass		*scene;
  GeometricObjectClass	*obj;
  RayStruct		ray;
  double		d;
  double		t;
  int			i;
  Vector3D		tmp;

  tmp = areaLightGetSampleThreadsafe(self);
  ray = *shadowRay;
  vectOpMinus(&tmp, &shadowRay->origin);
  d = vectDotProduct(&tmp, &shadowRay->direction);
  i = 0;
  t = Infinity;
  scene = RenderingSceneGetSingletonPtr()->getCurrentScene();
  while (i < scene->mObjects->size(scene->mObjects))
  {
    obj = scene->mObjects->mPtrs[i];
    if (obj->hit(obj, &ray, &t) && t < (d - kEpsilon) && t > ShadowKEpsilon
        && obj->mId != PRIV(mObject)->mId)
      return (true);
    i++;
  }
  return (false);
}
示例#2
0
static Color		areaLightL(AreaLightClass *self,
                                   HitRecordStruct *hitRecord)
{
  Vector3D	normal;

  normal = PRIV(normal);
  vectInv(&normal);
  if (vectDotProduct(&normal, &PRIV(wi)) > 0.)
    return (EMISSIVE(PRIV(mMaterial))->getLe(EMISSIVE(PRIV(mMaterial))));
  return ((Color){0, 0, 0});
}
示例#3
0
static float		emissiveShade(EmissiveClass *self, HitRecordStruct *hitRecord,
                                   LightClass *currentLight)
{
  Vector3D	normal;

  normal = hitRecord->normal;
  vectInv(&normal);
  if (vectDotProduct(&normal, &hitRecord->ray.direction) > 0.)
    return (PRIV(mLs));
  return (0.);
}
示例#4
0
static float		areaLightG(AreaLightClass *self,
                                   HitRecordStruct *hitRecord)
{
  Vector3D		normal;
  Vector3D		samplePoint;
  float			nDotD;
  float			d2;

  normal = PRIV(normal);
  vectInv(&normal);
  nDotD = vectDotProduct(&normal, &PRIV(wi));
  d2 = vectDist(&samplePoint, &hitRecord->hitPoint);
  d2 *= d2;
  return (nDotD / d2);
}
示例#5
0
void Game::manageInputs() {
    // Player 1
    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
        _p1.setVelocity(_p1.velocity().x, -1);
    }

    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
        _p1.setVelocity(-1, _p1.velocity().y);
    }

    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
        _p1.setVelocity(1, _p1.velocity().y);
    }

    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
        _p1.setVelocity(_p1.velocity().x, 1);
    }

    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) {
        _p1.boost();
    } else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space) == false) {
        _p1.chargeBoost();
    }

    if(_nbPlayer == 2) {
        // Player 2
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::W)) {
            _p2.setVelocity(_p2.velocity().x, -1);
        }

        if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
            _p2.setVelocity(-1, _p2.velocity().y);
        }

        if(sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
            _p2.setVelocity(1, _p2.velocity().y);
        }

        if(sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
            _p2.setVelocity(_p2.velocity().x, 1);
        }

        if(sf::Keyboard::isKeyPressed(sf::Keyboard::LShift)) {
            _p2.boost();

        } else if(sf::Keyboard::isKeyPressed(sf::Keyboard::LShift) == false) {
            _p2.chargeBoost();
        }

    } else { // Sinon, c'est une ia

        if(_iaUpdateClock.getElapsedTime().asSeconds() >= 0.25f) {
            sf::Vector2f dep = _ball.extrapolatedPosition() - _p2.position();
            float dist = distance(_p2.position().x, _p2.position().y, _ball.extrapolatedPosition().x, _ball.extrapolatedPosition().y);

            dep/=dist;

            _p2.setVelocity(dep);
            _iaUpdateClock.restart();
            _oldDep = dep;

        } else {
            _p2.setVelocity(_oldDep);
        }

        sf::Vector2f p1_ball, p2_ball;

        p1_ball = _ball.position() - _p1.position();

        p2_ball = _ball.position() - _p2.position();

        if(vectDotProduct(_goal2.position() - _ball.position(), _ball.velocity()) > 0
           && _ball.position().x - 30 < _p2.position().x && _ball.position().x >= 50 && vectLength(_ball.velocity()) != 0) {
            _p2.setVelocity(vectNormalize(_goal2.position() - _p2.position()));
        } else if(_ball.position().x < 50) {
            _p2.setVelocity(_oldDep);
        }
        // ==========================================

        if(_p2.boostValue() > 0 && _boostP2 && distance(_p2.position(), _ball.position()) > 100)
            _p2.boost();
        else
            _p2.chargeBoost();

        if(_p2.boostValue() <= 0 && _boostP2) {
            _boostP2 = false;
        }

        if(_boostP2 == false && _p2.boostValue() == 100) {
            _boostP2 = true;
        }
    }
}