Exemplo n.º 1
0
////////////////////////////////////////////////////////////////////////////////
// Setup                                                                      //
////////////////////////////////////////////////////////////////////////////////
void Bomb::AnimationInfo::setupFrames(const std::string &spriteName,
                                      int framesCount)
{
    //Load the texture.
    sprite.loadTexture(spriteName);

    //Get the Frame Properties.
    auto rect   = sprite.getSourceRectangle();
    auto frameW = rect.getWidth () / framesCount;
    auto frameH = rect.getHeight();

    //Create the Frames Rectangles.
    framesVec.reserve(framesCount);

    for(int i = 0; i < framesCount; ++i)
    {
        framesVec.push_back(
            Lore::Rectangle(i * frameW, 0,
                            frameW, frameH)
        );
    }

    frameIndex = 0;
    changeFrame(frameIndex);
}
Exemplo n.º 2
0
////////////////////////////////////////////////////////////////////////////////
// Bomb Animation Info                                                        //
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Animation Management                                                       //
////////////////////////////////////////////////////////////////////////////////
void Bomb::AnimationInfo::start()
{
    timer.start();
    auto gm = Lore::GameManager::instance();
    frameIndex = gm->getRandomNumber(0, framesVec.size()-1);
    changeFrame(frameIndex);
}
Exemplo n.º 3
0
/*!
  Get the region of interest clipped in the image and the information to know if it's a clipped point.
  
  \param cam : camera parameters.
  \param roi : image point corresponding to the region of interest with clipping information.
  \param cMo : pose.
*/
void
vpPolygon3D::getRoiClipped(const vpCameraParameters &cam, std::vector<std::pair<vpImagePoint,unsigned int> > &roi, const vpHomogeneousMatrix &cMo)
{
  changeFrame(cMo);
  computePolygonClipped(cam);
  getRoiClipped(cam, roi);
}
Exemplo n.º 4
0
void Object::update() {
	Screen &screen = *_vm->_screen;

	if (_visage.isLoaded()) {
		if (isMoving()) {
			uint32 currTime = _vm->_events->getFrameCounter();
			if (_walkStartFrame <= currTime) {
				int moveRate = 10;
				int frameInc = 60 / moveRate;
				_walkStartFrame = currTime + frameInc;
				move();
			}
		}
		
		if (_isAnimating) {
			if (_frame < _visage.getFrameCount())
				_frame = changeFrame();
			else
				_finished = true;
		}

		// Get the new frame
		ObjectSurface s;
		_visage.getFrame(s, _frame);

		// Display the frame
		_oldBounds = Common::Rect(_position.x, _position.y, _position.x + s.width(), _position.y + s.height());
		_oldBounds.translate(-s._centroid.x, -s._centroid.y);
		screen.SHtransBlitFrom(s, Common::Point(_oldBounds.left, _oldBounds.top));
	}
}
Exemplo n.º 5
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void FrameAnimationControl::setCurrentFrame(int frameIndex)
{
    if (frameIndex >= 0)
    {
        m_currentFrame = frameIndex;
        emit changeFrame(m_currentFrame);
    }
}
Exemplo n.º 6
0
/// class MatchReplayController
MatchReplayController::MatchReplayController(MatchRecording *const &recording) :
	recording(recording),
	ticks(0) {
	connect(this, SIGNAL(timeout()),
			this, SLOT(changeFrame()));
	this->start(10);
	setMode(Mode::REPLAY_PLAY); /// temp
}
/*
	updateSprite - To be called every frame of animation. This
    method advances the animation counter appropriately per
	the animation speed. It also updates the sprite location
	per the current velocity.
*/
void AnimatedSprite::updateSprite()
{
    unsigned int duration = spriteType->getDuration(currentState, frameIndex);
    animationCounter++;

    // WE ONLY CHANGE THE ANIMATION FRAME INDEX WHEN THE
    // ANIMATION COUNTER HAS REACHED THE DURATION
    if (animationCounter >= duration)
        changeFrame();
}
Exemplo n.º 8
0
// Mouse press event received
void ButtonSprite::mousePressEvent(QMouseEvent* /*event*/)
{
  if (mPushButton) 
  {
    mButtonPressed = !mButtonPressed;
    if (mButtonPressed) mSignal->emitSignal(number()|0x100);
    else mSignal->emitSignal(number());
  }
  changeFrame();
}
Exemplo n.º 9
0
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void FrameAnimationControl::slotTimerTriggered()
{
    // Update current frame according to settings
    if (m_forward)
    {
        if (m_currentFrame + 1 >= m_numFrames)
        {
            if (m_repeatFromStart)
            {
                m_currentFrame = 0;
            }
            else if (m_repeatFwdBwd)
            {
                setForward(false);
                m_currentFrame--;
            }
            else
            {
                m_timer->stop();
                m_currentFrame = m_numFrames - 1;
            }
        }
        else
        {
            m_currentFrame++;
        }
    }
    else
    {
        if (m_currentFrame - 1 < 0)
        {
            if (m_repeatFromStart)
            {
                m_currentFrame = m_numFrames - 1;
            }
            else if (m_repeatFwdBwd)
            {
                setForward(true);
                m_currentFrame++; // Ends up as 1 (second frame) makes 2 1 0 1 2 and not 2 1 0 0 1 2
            }
            else
            {
                m_timer->stop();
                m_currentFrame = 0;
            }
        }
        else
        {
            m_currentFrame--;
        }
    }

    // Emit signal with updated frame index
    emit changeFrame(m_currentFrame);
}
Exemplo n.º 10
0
// non destructive wrt. cP and p
void vpSphere::display(const vpImage<unsigned char> &I,
		       const vpHomogeneousMatrix &cMo,
		       const vpCameraParameters &cam,
		       const vpColor color)
{
  vpColVector _cP, _p ;
  changeFrame(cMo,_cP) ;
  projection(_cP,_p) ;
  vpFeatureDisplay::displayEllipse(_p[0],_p[1],_p[2],_p[3], _p[4],
				   cam, I, color) ;

}
Exemplo n.º 11
0
/*! 
  
  Compute the feature parameters in the camera frame (vpTracker::cP)
  and than compute the projection of these parameters in the image
  plane (vpTracker::p).

  \warning The feature parameters in the object frame
  (vpForwardProjection:oP) need to be set prior the use of this
  method. To initialize these parameters see setWorldCoordinates().
 
  \param cMo : The homogeneous matrix corresponding to the pose
  between the camera frame and the object frame.

*/
void
vpForwardProjection::project(const vpHomogeneousMatrix &cMo)
{
  try{
    changeFrame(cMo) ;
    projection() ;
  }
  catch(...)
  {
    vpERROR_TRACE("Error caught") ;
    throw ;
  }
}
Exemplo n.º 12
0
// Mouse release event received
void ButtonSprite::mouseReleaseEvent(QMouseEvent* event)
{
  QPointF p = mapFromScene (QPointF(event->pos()) );
  // qCDebug(KFOURINLINE_LOG) << "ButtonSprite::mouseReleaseEvent contains?"<< contains(p);
  if (!contains(p)) 
  {
    mHover = false;
    if (mPushButton) mButtonPressed = false;
  }
  else
  {
    if (!mPushButton)
    {
      mButtonPressed = !mButtonPressed;
      if (mButtonPressed) mSignal->emitSignal(number()|0x100);
      else mSignal->emitSignal(number());

    }
    else mButtonPressed = false;
  }
  changeFrame();
}
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
{
    ui = new Ui_MainWindow;
    ui->setupUi(this);

    putmark = false;

    ui->label->setFixedSize(800,450);

    openAction = new QAction(tr("&Open"),this);
    openAction->setStatusTip(tr("open an exited file"));
    openAction->setShortcut(QKeySequence::Open);
    connect(openAction,SIGNAL(triggered(bool)),this,SLOT(open()));

    captureAction = new QAction(tr("&capture"),this);
    captureAction->setStatusTip(tr("capture the video."));
    captureAction->setShortcut(QKeySequence::New);
    connect(captureAction,SIGNAL(triggered(bool)),this,SLOT(captureVideo()));

    aboutAction = new QAction(tr("aboutQt"),this);
    connect(aboutAction,SIGNAL(triggered(bool)),qApp,SLOT(aboutQt()));

    ui->menuFile->addAction(openAction);
    ui->menuFile->addAction(captureAction);
    ui->menuHelp->addAction(aboutAction);

    connect(ui->okButton,SIGNAL(clicked(bool)),this,SLOT(putWaterMark()));
    connect(ui->startButton,SIGNAL(clicked(bool)),this,SLOT(startSave()));
    connect(ui->stopButton,SIGNAL(clicked(bool)),this,SLOT(stopSave()));
    setEditEnable(false);

    timer = new QTimer ;
    connect(timer,SIGNAL(timeout()),this,SLOT(changeFrame()));

    save = STOP;
}
Exemplo n.º 14
0
/*!
  Check if the polygon is visible in the image and if the angle between the normal
  to the face and the line vector going from the optical center to the cog of the face is below
  the given threshold.
  To do that, the polygon is projected into the image thanks to the camera pose.

  \param cMo : The pose of the camera.
  \param alpha : Maximum angle to detect if the face is visible (in rad).
  \param modulo : Indicates if the test should also consider faces that are not oriented
  counter clockwise. If true, the orientation of the face is without importance.
  \param cam : Camera parameters (intrinsics parameters)
  \param I : Image used to consider level of detail.

  \return Return true if the polygon is visible.
*/
bool
vpMbtPolygon::isVisible(const vpHomogeneousMatrix &cMo, const double alpha, const bool &modulo,
      const vpCameraParameters &cam, const vpImage<unsigned char> &I)
{
  //   std::cout << "Computing angle from MBT Face (cMo, alpha)" << std::endl;

  changeFrame(cMo);

  if(nbpt <= 2) {
    //Level of detail (LOD)
    if(useLod) {
      vpCameraParameters c = cam;
      if(clippingFlag > 3) { // Contains at least one FOV constraint
        c.computeFov(I.getWidth(), I.getHeight());
      }
      computePolygonClipped(c);
      std::vector<vpImagePoint> roiImagePoints;
      getRoiClipped(c, roiImagePoints);

      if (roiImagePoints.size() == 2) {
        double x1 = roiImagePoints[0].get_u();
        double y1 = roiImagePoints[0].get_v();
        double x2 = roiImagePoints[1].get_u();
        double y2 = roiImagePoints[1].get_v();
        double length = std::sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
//          std::cout << "Index=" << index << " ; Line length=" << length << " ; clippingFlag=" << clippingFlag << std::endl;
//        vpTRACE("index=%d lenght=%f minLineLengthThresh=%f", index, length, minLineLengthThresh);

        if (length < minLineLengthThresh) {
          isvisible = false;
          isappearing = false;
          return false;
        }
      }
    }

    /* a line is always visible when LOD is not used */
    isvisible = true;
    isappearing = false;
    return  true ;
  }

  // If the polygon has no orientation, the angle check visibility is always valid.
  // Feature mainly used for cylinders.
  if(!hasOrientation)
  {
    isvisible = true;
    isappearing = false;
    return true;
  }

  //Check visibility from normal
  //Newell's Method for calculating the normal of an arbitrary 3D polygon
  //https://www.opengl.org/wiki/Calculating_a_Surface_Normal
  vpColVector faceNormal(3);
  vpColVector currentVertex, nextVertex;
  for(unsigned int  i = 0; i<nbpt; i++) {
    currentVertex = p[i].cP;
    nextVertex = p[(i+1) % nbpt].cP;

    faceNormal[0] += (currentVertex[1] - nextVertex[1]) * (currentVertex[2] + nextVertex[2]);
    faceNormal[1] += (currentVertex[2] - nextVertex[2]) * (currentVertex[0] + nextVertex[0]);
    faceNormal[2] += (currentVertex[0] - nextVertex[0]) * (currentVertex[1] + nextVertex[1]);
  }
  faceNormal.normalize();

  vpColVector e4(3) ;
  vpPoint pt;
  for (unsigned int i = 0; i < nbpt; i += 1){
    pt.set_X(pt.get_X() + p[i].get_X());
    pt.set_Y(pt.get_Y() + p[i].get_Y());
    pt.set_Z(pt.get_Z() + p[i].get_Z());
  }
  e4[0] = -pt.get_X() / (double)nbpt;
  e4[1] = -pt.get_Y() / (double)nbpt;
  e4[2] = -pt.get_Z() / (double)nbpt;
  e4.normalize();

  double angle = acos(vpColVector::dotProd(e4, faceNormal));

//  vpCTRACE << angle << "/" << vpMath::deg(angle) << "/" << vpMath::deg(alpha) << std::endl;

  if( angle < alpha || (modulo && (M_PI - angle) < alpha)) {
    isvisible = true;
    isappearing = false;

    if (useLod) {
      vpCameraParameters c = cam;
      if(clippingFlag > 3) { // Contains at least one FOV constraint
        c.computeFov(I.getWidth(), I.getHeight());
      }
      computePolygonClipped(c);
      std::vector<vpImagePoint> roiImagePoints;
      getRoiClipped(c, roiImagePoints);

      vpPolygon roiPolygon(roiImagePoints);
      double area = roiPolygon.getArea();
//      std::cout << "After normal test ; Index=" << index << " ; area=" << area << " ; clippingFlag="
//          << clippingFlag << std::endl;
      if (area < minPolygonAreaThresh) {
        isappearing = false;
        isvisible = false;
        return false;
      }
    }

    return true;
  }

  if (angle < alpha+vpMath::rad(1) ){
    isappearing = true;
  }
  else if (modulo && (M_PI - angle) < alpha+vpMath::rad(1) ){
    isappearing = true;
  }
  else {
    isappearing = false;
  }

  isvisible = false ;
  return false ;
}
Exemplo n.º 15
0
/*!
  Get the region of interest in the image.
  
  \param cam : camera parameters.
  \param cMo : pose.

  \return Image point corresponding to the region of interest.
*/
std::vector<vpImagePoint> 
vpPolygon3D::getRoi(const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo)
{
  changeFrame(cMo);
  return getRoi(cam);
}
Exemplo n.º 16
0
void game() {


	// Reset running motion in case user stops pressing arrow key 
	player.isRunning = 0;

	// Running/moving speed
	if (player.frameCount % 4 == 0) {
		changeFrame();
	}


	// Button Handling
	if (BUTTON_PRESSED(BUTTON_A)) {

		// Only jump if player is not already jumping
		if (canJump && checkCollision()) {
			canJump = 0;	
			player.isJumping = 1;
			jumpFrameCounter = 30;

			playSoundB(jumpSound, JUMPSOUNDLEN, JUMPSOUNDFREQ, 0);
			jump();
		}
		

	}

	if (BUTTON_PRESSED(BUTTON_B)) {
		vBlankCount = 100;
		prevSeason = season;

		playSoundB(warpSound, WARPSOUNDLEN, WARPSOUNDFREQ, 0);

		state = SEASONCHANGE;
	}

	if (BUTTON_PRESSED(BUTTON_START)) {
		REG_DISPCTL ^= BG0_ENABLE;

		pauseSound();

		state = PAUSE;
	}

	// Change to neutral season - CHEAT MODE
	if (BUTTON_HELD(BUTTON_R) && BUTTON_HELD(BUTTON_L) && BUTTON_HELD(BUTTON_SELECT)) {
		vBlankCount = 100;
		prevSeason = -1;

		playSoundB(warpSound, WARPSOUNDLEN, WARPSOUNDFREQ, 0);

		state = SEASONCHANGE;
	}

	if (BUTTON_HELD(BUTTON_RIGHT)) {
		player.isRunning = 1;
		player.facing = 0;
		player.deltaCol = 1;

		if (hOff < 272 && player.col >= 120 - player.height / 2) {
			hOff += player.deltaCol;
		}
		else if (player.col < 240 - player.width) {
			player.col += player.deltaCol;
		}

		
	}

	if (BUTTON_HELD(BUTTON_LEFT)) {
		player.isRunning = 1;
		player.facing = 1;
		player.deltaCol = -1;

		if (hOff > 0 && player.col < 120 - player.width / 2) {
			hOff += player.deltaCol;
		}
		else if (player.col > 0) {
			player.col += player.deltaCol;
		}

	}
	// End of button handling


	// Jump handling
	if (player.isJumping) {
		jump();
	}

	/*
	if (!canJump && hOff < 272) {
		player.col += player.deltaCol;
	} 
	*/


	// Gravity and Collision
	if (!checkCollision() || player.isJumping) {


		player.isRunning = 0; // Stop running animation

		/*if (vOff <= 96 && player.row >= 80 - player.height / 2) { */
			vOff += player.deltaRow;
		//}
		if (player.row < 160) {
			player.row += player.deltaRow;
		}
		else {
			state = LOSE;
		}
		
	}
	else {
		canJump = 1;
		player.deltaCol = 0;
	}


	// Gem collision detection - player wins current level
	if (checkWinCollision()) {
		playSoundB(winLevelSound, WINLEVELSOUNDLEN, WINLEVELSOUNDFREQ, 0);

		state = WINLEVEL;
	}
	

	// Standing still animation
	if (!player.isRunning) {
		player.currentFrame = 0;
	}

	// Running animation
	if (player.isRunning) {
		player.frameCount++;
	}

	// Seasonal BG1 Animations
	switch (season) {
		case FALL:
			bg1VOff--;
		break;

		case WINTER:
			bg1HOff--;
			bg1VOff--;
		break;
	}

}
Exemplo n.º 17
0
// Set the button status (on or off)
void ButtonSprite::setStatus(const bool status)
{
  mButtonPressed = status;
  changeFrame();
}
Exemplo n.º 18
0
////////////////////////////////////////////////////////////////////////////////
// Frame Management                                                           //
////////////////////////////////////////////////////////////////////////////////
void Bomb::AnimationInfo::incrementFrame()
{
    frameIndex = (frameIndex + 1) % framesVec.size();
    changeFrame(frameIndex);
}
Exemplo n.º 19
0
// Hover enter event received
void ButtonSprite::hoverEnterEvent(QMouseEvent* /*event*/)  
{
  mHover = true;
  changeFrame();
}
Exemplo n.º 20
0
 void Explosion::update(float dt){
	 ++ticks;
	 spawnTime -= dt;
	 changeFrame();
	 checkExplosion();
}
Exemplo n.º 21
0
// Hover leave event received
void ButtonSprite::hoverLeaveEvent(QMouseEvent* /*event*/)
{
  mHover = false;
  if (mPushButton) mButtonPressed = false;
  changeFrame();
}
Exemplo n.º 22
0
//! perspective projection of the circle
void
vpSphere::changeFrame(const vpHomogeneousMatrix &cMo)
{
  changeFrame(cMo,cP) ;
}
Exemplo n.º 23
0
void Paddle::AnimationInfo::resetFrame()
{
    changeFrame(0);
}
Exemplo n.º 24
0
void Paddle::AnimationInfo::increaseFrame()
{
    frameIndex = (frameIndex + 1) % kFramesCount;
    changeFrame(frameIndex);
}