Exemple #1
0
//
// Mise a jour du level
//
void Level::update()
{
    computeFov(Engine::getInstance()->getPlayer().fov);

    //-> Mise à jour tour par tour
    if (Engine::getInstance()->getMainStatus() == GameStatus::NEW_TURN)
    {
        //mise a jour des PNJ
        for (EntityPnj *pnj: pnjs_)
            pnj->update();

        //mise a jour des items
        for (EntityItem *item: items_)
            item->update();

        //mise a jour des items fixe
        for (EntityFixedItem *itemFixed: fixedItems_)
            itemFixed->update();
    }

    //-> Mise à jour temps réel
    //mise a jour des PNJ
    for (EntityPnj *pnj: pnjs_)
        pnj->rtupdate();

    //mise a jour des items
    for (EntityItem *item: items_)
        item->rtupdate();

    //mise a jour des items fixe
    for (EntityFixedItem *itemFixed: fixedItems_)
        itemFixed->rtupdate();
}
void CameraMovementLogic::update() {
    // Check we have a camera, it is viewing a level, and that it's movable
    const Level* level = Engine::getInstance()->getLevel();
    if (!mCamera || !level || level->shouldFillCamera()) {
        return;
    }

    const QSet<Actor*>& actors = level->getActors(Actor::PlayerActor);
    for (Actor* actor : actors) {
        QPointF towedPoint = mTowedControlPoints[actor];
        QPointF position = actor->position();

        //TODO: Clamp towed points to stay within camera boundary
        towedPoint.setX(towedPoint.x() + (position.x() - towedPoint.x()) * mTowedXPullFactor);
        towedPoint.setY(towedPoint.y() + (position.y() - towedPoint.y()) * mTowedYPullFactor);

        mTowedControlPoints[actor] = towedPoint;
    }

    const QRectF actorsBBox = getExpandedBBoxOfPlayerActors();

    QPointF lookAt = computeLookAt(actorsBBox);
    float fov = computeFov(actorsBBox);

    boundCameraViewport(&lookAt, &fov);

    mCamera->setLookAt(lookAt);
    mCamera->setFov(fov);
}
Exemple #3
0
/*!
   Initialize the camera model without distorsion from the image dimension and the camera field of view.
   \param w : Image width.
   \param h : Image height.
   \param hfov : Camera horizontal field of view angle expressed in radians.
   \param vfov : Camera vertical field of view angle expressed in radians.

   The following sample code shows how to use this function:
   \code
#include <visp3/core/vpCameraParameters.h>
#include <visp3/core/vpImage.h>

int main()
{
  vpImage<unsigned char> I(480, 640);
  vpCameraParameters cam;
  double hfov = vpMath::rad(56);
  double vfov = vpMath::rad(43);
  cam.initFromFov(I.getWidth(), I.getHeight(), hfov, vfov);

  std::cout << cam << std::endl;
  std::cout << "Field of view (horizontal: " << vpMath::deg(cam.getHorizontalFovAngle())
            << " and vertical: " << vpMath::deg(cam.getVerticalFovAngle()) << " degrees)" << std::endl;
}
   \endcode
   It produces the following output:
   \code
Camera parameters for perspective projection without distortion:
  px = 601.832	 py = 609.275
  u0 = 320	 v0 = 240

Field of view (horizontal: 56 and vertical: 43 degrees)
   \endcode
 */
void
vpCameraParameters::initFromFov(const unsigned int &w, const unsigned int &h, const double &hfov, const double &vfov)
{
    projModel = vpCameraParameters::perspectiveProjWithoutDistortion;
    u0 = (double)w/2.;
    v0 = (double)h/2.;
    px = u0 / tan(hfov/2);
    py = v0 / tan(vfov/2);
    kud = 0;
    kdu = 0;
    inv_px = 1./px;
    inv_py = 1./py;
    computeFov(w, h);
}