Ejemplo n.º 1
0
Renderer::Renderer(QWidget *parent)
    : QWidget(parent), _camera(0), _scene(0), _raytracerThread(0), _integrator(0)
{
    setImageSize(config->defaultImageWidth(), config->defaultImageHeight());
    QTimer* updator = new QTimer(this);
    connect(updator, SIGNAL(timeout()), SLOT(repaint()));
    connect(this, SIGNAL(renderingFinished()), SLOT(_onStop()));
    updator->start(1000/60);

    _stopThread = false;
    _isRendering = false;
    _isPaused = false;
}
Ejemplo n.º 2
0
void Player::onInitialize() {
    mController = new FPSPlayerComponent(2, "controller");
    mMesh = new dt::MeshComponent("player", "", "player_mesh");
    mStatus = new StatusComponent(100, 100);
    mCamera = new dt::CameraComponent("main_camera");
    mWalkingSound = new dt::SoundComponent("walk.wav", "player_walking_sound");
    mJumpingSound = new dt::SoundComponent("jump.wav", "player_jump_sound");

    const Weapon* weapon = mController->getWeaponInUse();

    //this->addComponent(mMesh);
    this->addComponent(mStatus);
    this->addComponent(mCamera);
    this->addComponent(mController);
    this->addComponent(mWalkingSound);
    this->addComponent(mJumpingSound);

    dt::GuiRootWindow& win = dt::GuiManager::get()->getRootWindow();
    mHUDAmmo = win.addChildWidget(new dt::GuiButton("HUD_ammo"));
    mHUDHealth = win.addChildWidget(new dt::GuiButton("HUD_health"));
    mHUDClip = win.addChildWidget(new dt::GuiButton("HUD_clip"));
    auto screen_rect = win.getMyGUIWidget()->getAbsoluteRect();

    mHUDHealth->setSize(100, 30);
    mHUDAmmo->setSize(100, 30);
    mHUDClip->setSize(100, 30);

    mHUDHealth->setPosition(10, screen_rect.height() - 50);
    mHUDAmmo->setPosition(screen_rect.width() - 110, screen_rect.height() - 90);
    mHUDClip->setPosition(screen_rect.width() - 110, screen_rect.height() - 50);

    dt::GuiManager::get()->setMouseCursorVisible(false);

    if(mIsControllable)
        mController->enable();
    else
        mController->disable();

    mWalkingSound->getSound().setLoop(true);
    mJumpingSound->setVolume(20);

    _refreshHealth(0, 100);
    if(weapon != nullptr) {
        _onWeaponChanged(weapon);
    }

    if(!QObject::connect(mController, SIGNAL(sWeaponChanged(const Weapon*)), 
                         this,        SLOT(_onWeaponChanged(const Weapon*)), Qt::DirectConnection)) {
            dt::Logger::get().debug(QString("Failed to connect the controller's sWeaponChanged") +
                QString("signal with the player's _OnWeaponChanged"));
    }

    if(!QObject::connect(mController, SIGNAL(sMove()),
                         this,        SLOT(_onWalk()), Qt::DirectConnection)) {
        dt::Logger::get().debug(QString("Failed to connect the controller's sMove with the player's _OnWalk"));
    }

    if(!QObject::connect(mController, SIGNAL(sStop()),
                         this,        SLOT(_onStop()), Qt::DirectConnection)) {
        dt::Logger::get().debug(QString("Failed to connect the controller's sStop with the player's _OnStop()"));
    }

    if(!QObject::connect(mController, SIGNAL(sJump()),
                         this,        SLOT(_onJump()), Qt::DirectConnection)) {
        dt::Logger::get().debug(QString("Failed to connect the controller's sStop with the player's _OnStop()"));
    }

    mController->setMouseSensitivity(1);
}