Пример #1
0
void Animator::update(float elapsed)
{
	if (!_mode)
		return;

	if (_mode & 0x8000) {
		_trans_time += _trans_speed * elapsed;
		if (_trans_time < 1) {
			updateTrans();
			return;
		}
		_mode &= 0x7fff;
		if (!_mode || !_speed) {
			updateAnim();
			_mode = 0;
			return;
		}
	}

	//do anim...
	_time += _speed * elapsed;

	switch (_mode) {
	case ANIM_MODE_LOOP:
		_time = fmod(_time, _seq_len);
		if (_time < 0)
			_time += _seq_len;
		break;
	case ANIM_MODE_PINGPONG:
		_time = fmod(_time, _seq_len * 2);
		if (_time < 0)
			_time += _seq_len * 2;
		if (_time >= _seq_len) {
			_time  = _seq_len - (_time - _seq_len);
			_speed = -_speed;
		}
		break;
	case ANIM_MODE_ONESHOT:
		if (_time < 0) {
			_time = 0;
			_mode = 0;
		} else if (_time >= _seq_len) {
			_time = _seq_len;
			_mode = 0;
		}
		break;
	}

	updateAnim();
}
Пример #2
0
void AnimButtonWidget::setAnimInfo(int perLength, int milliseconds)
{
    m_perLength = perLength;
    m_timer = new QTimer(this);
    m_timer->setInterval(milliseconds);
    connect(m_timer, SIGNAL(timeout()), this, SLOT(updateAnim()));
}
Пример #3
0
void AsScene3010DeadBolt::update() {
	updateAnim();
	updatePosition();
	if (_countdown != 0 && (--_countdown == 0)) {
		stDisabled();
	}
}
Пример #4
0
void Animator::animate(int mode, float speed, int seq, float trans)
{
	if (!mode && !speed) {
		_mode = 0;
		return;
	}

	if (seq < 0 || seq >= _seqs.size())
		return;

	_seq     = seq;
	_mode    = mode;
	_seq_len = _seqs[_seq].frames;
	_speed   = speed;
	_time    = _speed >= 0 ? 0 : _seq_len;

	if (trans <= 0) {
		updateAnim();
		if (!_speed)
			_mode = 0;
		return;
	}

	_mode |= 0x8000;
	_trans_time  = 0;
	_trans_speed = 1 / trans;
	beginTrans();
}
Пример #5
0
void AsScene1907Symbol::update() {
	updateAnim();
	handleSpriteUpdate();
	updatePosition();
	if (_plugInFailed && _plugInTryCount == 0)
		_plugInFailed = false;
}
Пример #6
0
void play(void)
{
    updateAnim();

    printOpenGLError();
    glutPostRedisplay();
    printOpenGLError();
}
Пример #7
0
PsiContactListModel::PsiContactListModel(PsiContactList* contactList)
	: ContactListDragModel(contactList)
	, secondPhase_(false)
{
	animTimer_ = new QTimer(this);
	animTimer_->setInterval(300);
	connect(animTimer_, SIGNAL(timeout()), SLOT(updateAnim()));
}
Пример #8
0
void BaseAnimation::run(Output *output, uint32_t duration)
{
    stop();

    if (!output || duration == 0) {
        updateAnim(1.);
        done();
        return;
    }

    m_duration = duration;
    m_animation.ani.frame_counter = 0;

    wl_list_insert(&output->m_output->animation_list, &m_animation.ani.link);
    weston_output_schedule_repaint(output->m_output);

    updateAnim(0.);
}
void MoveAnimComponent::setAnim(AnimationSetup *anim, bool idle /*=false*/)
{
	//Do nothing if animation is already playing
	if( m_activeAnim == anim )
	{
		m_idle = idle;
		return;
	}

	//Stop last animation if still playing
	if( m_activeAnim != 0x0 )
	{
		GameEvent updateAnim(GameEvent::E_UPDATE_ANIM, &AnimationUpdate(m_activeAnim->JobID, GameEngineAnimParams::Duration, 0, 0), 0);
		if (m_owner->checkEvent(&updateAnim))
		{
			m_owner->executeEvent(&updateAnim);
			m_activeAnim = 0x0;
		}
	}

	//If there is no new animation, we have finished
	if( anim == 0x0 ) 
	{
		if (m_runAnim)
		{
			// Reset last speeds as we have resetted our current anim
			for(int j = 0; j < SPEED_HISTORY_SIZE; j++)
				m_lastSpeeds[j] = 0;
		}

		m_idle = idle;
		return;
	}

	//Play given animation
	GameEvent walk(GameEvent::E_PLAY_ANIM, anim, this);
	if (m_owner->checkEvent(&walk))
	{
		m_owner->executeEvent(&walk);
		m_activeAnim = anim;
		m_idle = idle;

		//Calculate time for playing next random idle animation
		if( idle )
		{
			m_idleTime = GameEngine::getAnimLength( m_owner->worldId(), m_activeAnim->Animation );
			m_idleTime *= 1.0f + (rand() % 4);
		}
	}
}
Пример #10
0
void BaseAnimation::tick(weston_output *output, uint32_t msecs)
{
    if (m_animation.ani.frame_counter <= 1) {
        m_timestamp = msecs;
    }

    uint32_t time = msecs - m_timestamp;
    if (time > m_duration) {
        updateAnim(1.);
        stop();
        weston_compositor_schedule_repaint(output->compositor);
        done();
        return;
    }

    double f = (double)time / (double)m_duration;
    if (m_curve) {
        f = m_curve->value(f);
    }
    updateAnim(f);

    weston_compositor_schedule_repaint(output->compositor);
}
Пример #11
0
void Player::move(sf::Vector2f d)
{
    coord += sf::Vector2f(d);
    rect.move(d);
    hitBox.move(d);
    float viewOrd = (scene->getCam()).y;
    if(coord.y < viewOrd - 150) {
		scene->setCam(scene->getCam()+(sf::Vector2f(0, (d.y < 0)?d.y:0)));
	}
    else if(coord.y > viewOrd+200)
    {
		if(viewOrd < scene->getHeight()-100) // TEST ME
			scene->setCam(scene->getCam()+(sf::Vector2f(0, (d.y > 0)?d.y:0)));
		else
			scene->setCam(sf::Vector2f(scene->getCam().x, 300));
    }
    isDead();

    //graphiques
    updateAnim(d);
}
Пример #12
0
void Animator::setAnimTime(float time, int seq)
{
	if (seq < 0 || seq > _seqs.size())
		return;

	_mode    = 0;
	_speed   = 0;
	_seq     = seq;
	_seq_len = _seqs[_seq].frames;

	//Ok, mod the anim time!
	_time = fmod(time, _seq_len);

	//if( time<0 || time>_seq_len ) time=fmod( time,_seq_len );
	//_time=time;

	if (_time < 0)
		_time += +_seq_len;

	updateAnim();
}
void MoveAnimComponent::update(float timeStep)
{
	if (timeStep > Math::Epsilon)
	{
		// Only calc next anim if LOD is low enough
		if (m_lod < m_LODToStopAnim)
		{
			//calculate translated distance and speed in x,z plane
			Vec3f dist = m_newPos - m_oldPos;
			dist.y = 0;
			float speed = m_speed * dist.length() / timeStep;
			static const float pi3rd = Math::Pi / 3;
		
			//if (m_runAnim)
			{
				// Currently the average speed is only used for the run animation
				m_lastSpeeds[m_currentSpeedIndex] = speed;
				m_currentSpeedIndex = (m_currentSpeedIndex + 1) % SPEED_HISTORY_SIZE;
				m_avgSpeed = 0;
				for (int i = 0; i < SPEED_HISTORY_SIZE; i++)
				{
					m_avgSpeed += m_lastSpeeds[i];
				}
				m_avgSpeed /= SPEED_HISTORY_SIZE;
			}

			// Object is moving
			if( m_avgSpeed >= m_moveThreshold && speed > 0)
			{
				AnimationSetup* nextAnim = 0x0;
				// Direction in radiants = angle of walking direction - (y-rotation of the object + rotation offset)
				float direction = atan2( -dist.x, -dist.z ) - (m_rotation.y + m_rotationOffset);
			
				// Normalize direction angle to [-PI, +PI]
				// To get less if cases
				if( direction > Math::Pi ) 
					direction = direction - Math::TwoPi;
				if( direction < -Math::Pi )
					direction = Math::TwoPi + direction;

				// Find the right move animation to play by the moving direction
				// If the exact animation is not specified, play the one for forward moving
				if (m_moveBackAnim != 0x0 && (direction >= 2*pi3rd || direction <= -2*pi3rd))
				{
					nextAnim = m_moveBackAnim;
				}
				else if (m_moveLeftAnim != 0x0 && (direction > pi3rd && direction < 2*pi3rd))
				{
					nextAnim = m_moveLeftAnim;
				}
				else if (m_moveRightAnim != 0x0 && (direction > -2*pi3rd && direction < -pi3rd))
				{
					nextAnim = m_moveRightAnim;
				}
				else if (m_runAnim != 0 && m_avgSpeed > m_runThreshold)
				{
					nextAnim = m_runAnim;
					// Reduce playback speed for run anim
					speed -= m_runThreshold - m_speed;
					//printf("Running speed: %.5f\n", speed);
				}
				else if (m_moveAnim != 0x0)
				{
					nextAnim = m_moveAnim;
				}
				// Set anim or reset everything if none found (nextAnim == 0x0)
				setAnim(nextAnim);
			}
			// Play idle animation if too slow and one is specified
			else if (m_idleAnimCount > 0)
			{
				// We weren't in idle state before or the animation time for the idle anim has passed
				if(!m_idle || m_idleTime < 0)
				{
					if(!m_randSeed)
					{
						// rand hasn't been seeded yet
						srand( (unsigned int) (100000 / timeStep) );
						m_randSeed = true;
					}
					// Choose and set new random idle animation
					int i = rand() % m_idleAnimCount; 
					setAnim( m_idleAnim[i], true );
				}
				else
				{
					// The current idle animation is still playing
					// So decrement timer
					m_idleTime -= timeStep;
				}
			}
			// We don't have an anim to play, so stop any currently playing 
			else
			{
				setAnim(0x0);
			}

			//update animation speed (only none idle animations)
			if( m_activeAnim != 0x0 && !m_idle)
			{
				GameEvent updateAnim(GameEvent::E_UPDATE_ANIM, &AnimationUpdate(m_activeAnim->JobID, GameEngineAnimParams::Speed, m_activeAnim->Speed * m_avgSpeed, 0), 0);
				if (m_owner->checkEvent(&updateAnim))
					m_owner->executeEvent(&updateAnim);
			}
		}
		// The LOD is above the critical value, so stop all current anims
		else
			setAnim(0x0);
	
		//update position
		m_oldPos = m_newPos;
	}
}
Пример #14
0
void AnimatedSprite::update() {
	updateAnim();
	handleSpriteUpdate();
	updatePosition();
}
Пример #15
0
void ofApp::update(){
    updateAnim();
}
Пример #16
0
void AsScene1907WaterHint::update() {
	updateAnim();
	updatePosition();
}
void MoveAnimComponent::changeMoveAnim(const std::string& tag, const std::string& name)
{
	AnimationSetup* animToDelete = 0x0;
	if (tag.compare("moveAnimation") == 0)
	{
		animToDelete = m_moveAnim;
		m_moveAnim = static_cast<AnimationSetup*>(AnimationSetup(name.c_str(), 10, 0, -1.0f, 1.0f, 0.0f).clone());		 
		m_moveAnim->Speed = GameEngine::getAnimSpeed(m_owner->worldId(), m_moveAnim->Animation);
	}
	else if (tag.compare("idleAnimation") == 0)
	{
		if (m_idleAnimCount > 0)
			animToDelete = m_idleAnim[0];
		else m_idleAnimCount++;
		m_idleAnim[0] = static_cast<AnimationSetup*>(AnimationSetup(name.c_str(), 10, 0, -1.0f, 0.0f, 0.0f).clone());
	}
	else if (tag.compare("idleAnimation2") == 0 && m_idleAnimCount > 0)
	{
		if (m_idleAnimCount > 1)
			animToDelete = m_idleAnim[1];
		else m_idleAnimCount++;
		m_idleAnim[1] = static_cast<AnimationSetup*>(AnimationSetup(name.c_str(), 10, 0, -1.0f, 0.0f, 0.0f).clone());
	}
	else if (tag.compare("idleAnimation3") == 0 && m_idleAnimCount > 1)
	{
		if (m_idleAnimCount > 2)
			animToDelete = m_idleAnim[2];
		else m_idleAnimCount++;
		m_idleAnim[2] = static_cast<AnimationSetup*>(AnimationSetup(name.c_str(), 10, 0, -1.0f, 0.0f, 0.0f).clone());
	}
	else if (tag.compare("idleAnimation4") == 0 && m_idleAnimCount > 2)
	{
		if (m_idleAnimCount > 3)
			animToDelete = m_idleAnim[3];
		else m_idleAnimCount++;
		m_idleAnim[3] = static_cast<AnimationSetup*>(AnimationSetup(name.c_str(), 10, 0, -1.0f, 0.0f, 0.0f).clone());
	}
	else if (tag.compare("idleAnimation5") == 0 && m_idleAnimCount > 3)
	{
		if (m_idleAnimCount > 4)
			animToDelete = m_idleAnim[4];
		else m_idleAnimCount++;
		m_idleAnim[4] = static_cast<AnimationSetup*>(AnimationSetup(name.c_str(), 10, 0, -1.0f, 0.0f, 0.0f).clone());
	}
	else if (tag.compare("moveBackAnimation") == 0)
	{
		animToDelete = m_moveBackAnim;
		m_moveBackAnim = static_cast<AnimationSetup*>(AnimationSetup(name.c_str(), 10, 0, -1.0f, 1.0f, 0.0f).clone());		 
		m_moveBackAnim->Speed = GameEngine::getAnimSpeed(m_owner->worldId(), m_moveBackAnim->Animation);
	}
	else if (tag.compare("moveLeftAnimation") == 0)
	{
		animToDelete = m_moveLeftAnim;
		m_moveLeftAnim = static_cast<AnimationSetup*>(AnimationSetup(name.c_str(), 10, 0, -1.0f, 1.0f, 0.0f).clone());		 
		m_moveLeftAnim->Speed = GameEngine::getAnimSpeed(m_owner->worldId(), m_moveLeftAnim->Animation);
	}
	else if (tag.compare("moveRightAnimation") == 0)
	{
		animToDelete = m_moveRightAnim;
		m_moveRightAnim = static_cast<AnimationSetup*>(AnimationSetup(name.c_str(), 10, 0, -1.0f, 1.0f, 0.0f).clone());		 
		m_moveRightAnim->Speed = GameEngine::getAnimSpeed(m_owner->worldId(), m_moveRightAnim->Animation);
	}
	else if (tag.compare("runAnimation") == 0)
	{
		animToDelete = m_runAnim;
		m_runAnim = static_cast<AnimationSetup*>(AnimationSetup(name.c_str(), 10, 0, -1.0f, 1.0f, 0.0f).clone());		 
		m_runAnim->Speed = GameEngine::getAnimSpeed(m_owner->worldId(), m_runAnim->Animation);
	}

	if (m_activeAnim != 0x0 && animToDelete == m_activeAnim)
	{
		// Stop active anim because it will be deleted
		GameEvent updateAnim(GameEvent::E_UPDATE_ANIM, &AnimationUpdate(m_activeAnim->JobID, GameEngineAnimParams::Duration, 0, 0), 0);
		if (m_owner->checkEvent(&updateAnim))
		{
			m_owner->executeEvent(&updateAnim);
			m_activeAnim = 0x0;
		}
	}
	// Reset idle state to reload changed idle animation
	m_idle = false;
	// Now the anim can be safely deleted
	delete animToDelete;
}