Example #1
0
std::vector<float> Laser::scan(double x, double y, double theta) {
    double current_angle = theta;
    updateAngle(current_angle, min_angle_);

    for (unsigned int r = 0; r < ranges_.size(); r++) {
        ranges_[r] = rayCast(x, y, current_angle);
        updateAngle(current_angle, resolution_angle_);
    }

    return ranges_;
}
Example #2
0
void AngleWidget::mouseReleaseEvent(QMouseEvent *e)
{
    updateAngle(e->pos());
    setCursor(Qt::ArrowCursor);
    m_dragging = false;
    e->accept();
}
Example #3
0
void AngleWidget::mousePressEvent(QMouseEvent *e)
{
    m_dragging = true;
    setCursor(Qt::ClosedHandCursor);
    updateAngle(e->pos());
    e->accept();
}
Example #4
0
void NumberAnimation::update()
{
	if (m_bRunning)
	{
		if (m_currentParam != "")
		{
			if (m_currentParam == "scale")
			{
				updateScale();
			}
			if (m_currentParam == "alpha")
			{
				updateAlpha();
			}
			if (m_currentParam == "angle")
			{
				updateAngle();
			}
			if (m_currentParam == "width")
			{
				updateWidth();
			}
		}
	}
}
Example #5
0
MediumPlane::MediumPlane() :Enemy(),
					  m_shootChance(10),
					  m_kMaxHealth(500),
					  m_goingUp(true),
					  m_goingRight(false),
					  m_pointsOnCombo(500),
					  m_explotionAnimationTime(1000),
					  m_explotionRemainingTime(0)
{
	m_tag = "Medium Plane";
	m_speed = Vector2D(1.4f, 1.75f);
	m_direction.setX(0);
	m_direction.setY(DIRECTION_DOWN);
	updateAngle();

	m_width = 80;// hardcodeado como valores iniciales antes de llamar a load
	m_height = 80;

	if (Random::getRange(-1, 1) >= 0)
		m_goingRight = true;

	generateBorderReturnOffset();
	frameC = 0;

	m_health= m_kMaxHealth;
	m_pointsOnCombo = 500;
	m_pointOnKill = 500;
	m_pointOnHit = 100;
	m_enemyWeapon = new EnemyBaseGun();
	setWeaponStats(4, 300, m_objectId, -1);

	m_shootingOffset = Vector2D(m_width/2, m_height/2);

}
Example #6
0
void AngleWidget::mouseMoveEvent(QMouseEvent *e)
{
    if (m_dragging)
    {
        updateAngle(e->pos());
        e->accept();
    }
}
Example #7
0
void Gear_ClusteredDither::internalInit()
{
  _clusterSize = CLAMP((int)_CLUSTER_SIZE_IN->type()->value(), 2, 512);
  _spotType = (eSpotType)CLAMP((int)_SPOT_TYPE_IN->type()->value(), (int)SQUARE, (int)LINE);
  _width = _clusterSize * 3;
  _sizeX = _sizeY = 0;
  _angle[0] = DEG2RAD(CLAMP((int)_ANGLE_RED_IN->type()->value(), 0, 360));
  _angle[1] = DEG2RAD(CLAMP((int)_ANGLE_GREEN_IN->type()->value(), 0, 360));
  _angle[2] = DEG2RAD(CLAMP((int)_ANGLE_BLUE_IN->type()->value(), 0, 360));
  updateThreshold();
  updatePolarCoordinates();
  updateAngle(0);
  updateAngle(1);
  updateAngle(2);
  ASSERT_WARNING(_threshold);
  ASSERT_WARNING(_order);
}
//------------------------------------------------------------------------------
void branch::update(float factor, float drawPctIn){
	
	if( drawPct < 0.2 && drawPctIn >= 0.2 ){
		if( lines.size() ){
			ofPoint tipPos = lines.back().getTip();
			globalSnd.play("BRANCH_GROWING", ofRandom(0.8, 0.9), 1.0, ofMap(tipPos.x, -(float)ofGetWidth()/2, (float)ofGetWidth()/2, -1, 1, true) );
		}
	}
		
	if( ourLeafState == LEAF_DYING && leafHealthPct > 0.01 ){
		leafHealthPct *= 0.98;
		if( leafHealthPct <= 0.01 ){
			leafHealthPct = 0.0;
		}
	}
	if( ourLeafState == LEAF_GROWING && leafHealthPct < 1.0 ){
		leafHealthPct += 0.03;
		if( leafHealthPct >= 1.0 ) leafHealthPct = 1.0;
		
		for(int i = 0; i < lines.size(); i++){
			for(int k = 0; k < lines[i].leafs.size(); k++){
				if( lines[i].leafs[k].visible == false ){
					lines[i].leafs[k].visible = true;
				}
				lines[i].leafs[k].shrink = ofLerp(lines[i].leafs[k].shrink, 1.0, 0.1); 
			}
		}
	}
	
	if( lines.size() && level == 0 && drawPctIn >= 1.0){
		if( leafHealthPct < 0.7 && ourLeafState == LEAF_DYING ){
							
			updateAngle(270);
			for(int i = 0; i < children.size(); i++){
				children[i].updateAngle(270);
			}
		}
	}
	
	drawPct = drawPctIn;
	
	for(int i = 0; i < lines.size(); i++){				
		lines[i].update(factor, leafHealthPct);
		lines[i].scale = powf(ofClamp(drawPct*4, 0, 1), 0.2);
		
		if( leafHealthPct > 0.3 && ourLeafState != LEAF_DYING ){
			lines[i].restoreAngleToTarget();
		}
	
	}
	for(int k = 0; k < children.size(); k++){
		children[k].update(factor, MAX(0, ofLerp(children[k].drawPct, drawPct-1.0, 0.1)) );
	}
	
}
	/**
	 * Start the motor to move according to the set registers.
	 **/
	void StepperMotor::startMovement(void){
		if(!poweredOn){
			throw MotorException("motor drivers are not powered on");
		}

		// Execute motion.
		waitTillReady();

		modbus->writeU16(motorIndex, CRD514KD::Registers::CMD_1, CRD514KD::CMD1Bits::EXCITEMENT_ON);
		modbus->writeU16(motorIndex, CRD514KD::Registers::CMD_1, CRD514KD::CMD1Bits::EXCITEMENT_ON | CRD514KD::CMD1Bits::START);
		modbus->writeU16(motorIndex, CRD514KD::Registers::CMD_1, CRD514KD::CMD1Bits::EXCITEMENT_ON);
		updateAngle();
	}
Example #10
0
// Estimate FPS, use for fixed interval timer driven animation
void intervalTimer (int i) { 
   glutTimerFunc(timerDelay, intervalTimer, 1);
   // compute frames / second
   intervalTimerCalls++;
   if (intervalTimerCalls * timerDelay >= 1000) { 
	  sprintf(message[0],"Level %s  %5d fps",levelName, frameCount);
      intervalTimerCalls = frameCount = 0; 
	  if (currentView == 0)
		sprintf(message[2], "Camera: Front");
	  else	
		sprintf(message[2], "Camera: Ship");
      sprintf(message[5], "Warbird");
	  sprintf(message[6],  "%4.1f %4.1f %4.1f", warbird->getX(), warbird->getY(), warbird->getZ());
	  sprintf(message[8], "U. Missile");
	  sprintf(message[9],  "%4.1f %4.1f %4.1f", planet[1]->getX(), planet[1]->getY(), planet[1]->getZ());
	  sprintf(message[11], "T. Missile");
	  sprintf(message[12],  "%4.1f %4.1f %4.1f", planet[9]->getX(), planet[9]->getY(), planet[9]->getZ());
      glutSetWindow(dataWindow);
      glutPostRedisplay(); 
    }
   if(keyMod[GLUT_ACTIVE_CTRL]){
	   if(keyDown[GLUT_KEY_UP]){
		   warbird->pitch(1.0);
	   }
	   if(keyDown[GLUT_KEY_DOWN]){
		   warbird->pitch(-1.0);
	   }
	   if(keyDown[GLUT_KEY_LEFT]){
		   warbird->roll(1.0);
	   }
	   if(keyDown[GLUT_KEY_RIGHT]){
		   warbird->roll(-1.0);
	   }
   }
   if(!keyMod[GLUT_ACTIVE_CTRL]){
	   if(keyDown[GLUT_KEY_UP]){
		   warbird->move(10.0);
	   }
	   if(keyDown[GLUT_KEY_DOWN]){
		   warbird->move(-10.0);
	   }
	   if(keyDown[GLUT_KEY_LEFT]){
		   warbird->yaw(1.0);
	   }
	   if(keyDown[GLUT_KEY_RIGHT]){
		   warbird->yaw(-1.0);
	   }
   }
			
	updateAngle();  // fixed interval timer
}
Example #11
0
Unit::Unit(string id)
: PI(GameConstants::PI),
m_speed(GameConstants::PLAYER_SPEED),
m_radius(GameConstants::PLAYER_RADIUS),
m_positionAngle(RandomFloat(0, 2 * PI)),
m_targetAngle(m_positionAngle),
m_state(UNIT_STATE::WAITING),
m_directionAngle(m_positionAngle),
m_currentWeapon(WeaponFactory::getInstance()->getNewWeapon(WeaponType::PISTOL)),
m_isSelected(false),
m_previousState(UNIT_STATE::WAITING),
m_rank(UNIT_RANK::A),
m_experience(0),
m_id(id),
m_anim("walingAssaltAnimation", Vector2D(-100, -100)),
m_selectAnimation("selectorAnimation", Vector2D(-100, -100)),
m_xpBar(m_position + Vector2D(-m_radius, 0), Vector2D(0.4f, 0.7f), 100, sf::Color(4, 254, 253, 255), sf::Color(17, 169, 169, 255)),
m_weaponUpgradeUI(m_position, Vector2D(100,100)),
m_light(new Light(m_id, m_position, Vector2D(0.19f, 0.19f), sf::Color(255, 205, 180, 185), Vector2D(0, 0), 0, "starLight"))
{
	m_positionAngle = RandomFloat(0, 2 * PI);
	m_directionAngle = m_positionAngle;
	m_targetAngle = m_positionAngle;

	m_anim.setFramesPerSecond(60);
	m_anim.setRadius(m_radius + 50);
	m_anim.SetLooping(false);
	m_selectAnimation.setFramesPerSecond(60);
	m_selectAnimation.setRadius(m_radius + 90);
	m_selectAnimation.SetLooping(false);
	updateAngle(m_positionAngle);
	m_currentWeapon.update(getPositionByAngle(m_positionAngle), m_directionAngle, 0);
	m_currentWeapon.setParentId(m_id);
	rankImg.setPosition(Vector2D(m_position + Vector2D(-m_radius + 30, 20)).toSFMLVector());
	rankImg.setSize(sf::Vector2f(12, 12));
	rankImg.setTexture(AssetLoader::getInstance()->findTextureByKey("RankA"));
	
	LightManager::getInstance()->AddLight(m_light);
}
void BasicPhysicsComponent::update(Uint32 dt){
	PhysicsComponent::update(dt);
	
	updateAngle(dt);
	updatePosition(dt);
}
Example #13
0
void stepNetwork(void)
{
    int i, k, pi, pi2, nbytes, newfd;
    char remoteIP[INET6_ADDRSTRLEN];
    struct sockaddr_storage remoteaddr;
    socklen_t addrlen;
    struct timeval tv;

    if(getDeathMessage(sendbuf))
    {
        for(k = 0; k < conf.maxPlayers; ++k)
        {
            if(connection[k].socket && !connection[k].bot)
            {
                snd(connection[k].socket, "\r\n");
                snd(connection[k].socket, sendbuf);
                snd(connection[k].socket, "\r\n> ");
            }
        }
    }

    tv.tv_sec = 0;
    tv.tv_usec = 1;
    readfds = master;
    if(select(fdmax + 1, &readfds, NULL, NULL, &tv) == -1)
    {
        print_error("select");
        exit(5);
    }

    for(i = 0; i <= fdmax; ++i)
    {
        if(FD_ISSET(i, &readfds))
        {
            if(i == listener)
            {
                addrlen = sizeof remoteaddr;
                newfd = accept(listener, (struct sockaddr *)&remoteaddr, &addrlen);
                if(newfd == -1)
                {
                    print_error("accept");
                }
                else
                {
                    getnameinfo((struct sockaddr *)&remoteaddr, addrlen, remoteIP, sizeof remoteIP, NULL, 0, NI_NUMERICHOST | NI_NUMERICSERV);
                    for(k = 0; k < conf.maxPlayers; ++k)
                    {
                        if(connection[k].socket == 0)
                        {
                            connection[k].socket = newfd;
                            playerJoin(k);
                            updateName(k, "Anonymous");
                            allSendPlayerPos(k);
                            break;
                        }
                    }
                    if(k == conf.maxPlayers)
                    {
                        close(newfd);
                        printf("new connection from %s on socket %d refused: max connections\n", remoteIP, newfd);
                    }
                    else
                    {
                        FD_SET(newfd, &master);
                        if(newfd > fdmax)
                        {
                            fdmax = newfd;
                        }
                        printf("new connection from %s on socket %d accepted\n", remoteIP, newfd);
                        snd(newfd, WELCOME);
                    }
                }
            }
            else
            {
                if((nbytes = recv(i, buf, sizeof buf, 0)) <= 0)
                {
                    if(nbytes == 0)
                    {
                        printf("socket %d hung up\n", i);
                    }
                    else
                    {
                        print_error("recv");
                    }
                    for(k = 0; k < conf.maxPlayers; ++k)
                    {
                        if(connection[k].socket == i)
                        {
                            disconnectPlayer(k);
                            allSendPlayerLeave(k);
                            break;
                        }
                    }
                    close(i);
                    FD_CLR(i, &master);
                }
                else
                {
                    pi = -1;
                    for(k = 0; k < conf.maxPlayers; ++k)
                    {
                        if(connection[k].socket == i)
                        {
                            pi = k;
                            break;
                        }
                    }
                    for(k = 0; k < nbytes && pi >= 0; ++k)
                    {
                        unsigned char c = buf[k];
                        if(c != '\r' && c != '\n')
                        {
                            if(isprint(c) && connection[pi].msgbufindex < 128 - 2)
                            {
                                connection[pi].msgbuf[connection[pi].msgbufindex++] = c;
                            }
                        }
                        else
                        {
                            if(connection[pi].msgbufindex == 0)
                            {
                                continue;
                            }
                            connection[pi].msgbuf[connection[pi].msgbufindex] = '\0';
                            connection[pi].msgbuf[connection[pi].msgbufindex + 1] = '\0';
                            connection[pi].msgbufindex = 0;
                            if(connection[pi].echo)
                            {
                                snd(i, connection[pi].msgbuf);
                                snd(i, "\r\n");
                            }
                            if(!overdrive)printf("%16s (%d): \"%s\"\n", getPlayer(pi)->name, pi, connection[pi].msgbuf);
                            switch(connection[pi].msgbuf[0])
                            {
                            case 'n':
                            {
                                updateName(pi, connection[pi].msgbuf + 2);
                                break;
                            }
                            case 'v':
                            {
                                updateVelocity(pi, atof(connection[pi].msgbuf + 2));
                                break;
                            }
                            case 'z':
                            {
                                updateZoom(atof(connection[pi].msgbuf + 2));
                                break;
                            }
                            case 'c':
                            {
                                clearTraces(pi);
                                break;
                            }
                            case 'o':
                            {
                                overdrive = !overdrive;
                                break;
                            }
                            case 'b':
                            {
                                connection[pi].bot = !connection[pi].bot;
                                if(connection[pi].bot)
                                {
                                    sendOwnId(i, pi);
                                    for(pi2 = 0; pi2 < conf.maxPlayers; ++pi2)
                                    {
                                        if(connection[pi2].socket)
                                        {
                                            sendPlayerPos(i, pi2);
                                        }
                                    }
                                }
                                break;
                            }
                            case 'f':
                            {
                                toggleFps();
                                break;
                            }
                            case 'i':
                            {
                                if(strcmp("init", connection[pi].msgbuf) == 0)
                                {
                                    reinitialize();
                                }
                                break;
                            }
                            case 'x':
                            {
                                if(strcmp("xit", connection[pi].msgbuf) == 0)
                                {
                                    exit(0);
                                }
                                break;
                            }
                            case 'e':
                            {
                                connection[pi].echo = !connection[pi].echo;
                                break;
                            }
                            case 'q':
                            {
                                disconnectPlayer(pi);
                                allSendPlayerLeave(pi);
                                break;
                            }
                            case 'r':
                            {
                                validateOld(pi);
                                break;
                            }
                            default:
                            {
                                updateAngle(pi, atof(connection[pi].msgbuf));
                                break;
                            }
                            }

                            if(connection[pi].socket && !connection[pi].bot)
                            {
                                snd(i, "> ");
                            }
                        }
                    }
                }
            }
        }
    }
    for(k = 0; k < conf.maxPlayers; ++k)
    {
        if(getPlayer(k)->active && getPlayer(k)->timeoutcnt > 2)
        {
            disconnectPlayer(k);
            allSendPlayerLeave(k);
        }
    }
}
Example #14
0
/* AngleControl::onAngleTextChanged
 * Called when the angle text box is changed
 *******************************************************************/
void AngleControl::onAngleTextChanged(wxCommandEvent& e)
{
	this->angle = text_angle->getNumber();
	updateAngle();
}
Example #15
0
/* AngleControl::setAngle
 * Sets the angle to display
 *******************************************************************/
void AngleControl::setAngle(int angle)
{
	this->angle = angle;
	text_angle->setNumber(angle);
	updateAngle();
}
Example #16
0
void knob::drawKnob( QPainter * _p )
{
	if( updateAngle() == false && !m_cache.isNull() )
	{
		_p->drawImage( 0, 0, m_cache );
		return;
	}

	m_cache = QImage( size(), QImage::Format_ARGB32 );
	m_cache.fill( qRgba( 0, 0, 0, 0 ) );

	QPainter p( &m_cache );

	QPoint mid;

	if( m_knobNum == knobStyled )
	{
		p.setRenderHint( QPainter::Antialiasing );

		// Perhaps this can move to setOuterRadius()
		if( m_outerColor )
		{
			QRadialGradient gradient( centerPoint(), outerRadius() );
			gradient.setColorAt(0.4, _p->pen().brush().color() );
			gradient.setColorAt(1, *m_outerColor );

			p.setPen( QPen( gradient, lineWidth(),
						Qt::SolidLine, Qt::RoundCap ) );
		}
		else {
			QPen pen = p.pen();
			pen.setWidth( (int) lineWidth() );
			pen.setCapStyle( Qt::RoundCap );

			p.setPen( pen );
		}

		p.drawLine( calculateLine( centerPoint(), outerRadius(),
							innerRadius() ) );
		p.end();
		_p->drawImage( 0, 0, m_cache );
		return;
	}


	// Old-skool knobs
	const float radius = m_knobPixmap->width() / 2.0f - 1;
	mid = QPoint( width() / 2, m_knobPixmap->height() / 2 );

	p.drawPixmap( static_cast<int>(
				width() / 2 - m_knobPixmap->width() / 2 ), 0,
				*m_knobPixmap );

	p.setRenderHint( QPainter::Antialiasing );

	const int centerAngle = angleFromValue( model()->centerValue(), model()->minValue(), model()->maxValue(), m_totalAngle );

	const int arcLineWidth = 2;
	const int arcRectSize = m_knobPixmap->width() - arcLineWidth;

	QColor col;
	if( m_knobNum == knobVintage_32 )
	{	col = QApplication::palette().color( QPalette::Active, QPalette::Shadow ); }
	else
	{	col = QApplication::palette().color( QPalette::Active, QPalette::WindowText ); }
	col.setAlpha( 70 );

	p.setPen( QPen( col, 2 ) );
	p.drawArc( mid.x() - arcRectSize/2, 1, arcRectSize, arcRectSize, 315*16, 16*m_totalAngle );

	switch( m_knobNum )
	{
		case knobSmall_17:
		{
			p.setPen( QPen( QApplication::palette().color( QPalette::Active,
							QPalette::WindowText ), 2 ) );
			p.drawLine( calculateLine( mid, radius-2 ) );
			break;
		}
		case knobBright_26:
		{
			p.setPen( QPen( QApplication::palette().color( QPalette::Active, QPalette::WindowText ), 2 ) );
			p.drawLine( calculateLine( mid, radius-5 ) );
			break;
		}
		case knobDark_28:
		{
			p.setPen( QPen( QApplication::palette().color( QPalette::Active, QPalette::WindowText ), 2 ) );
			const float rb = qMax<float>( ( radius - 10 ) / 3.0,
									0.0 );
			const float re = qMax<float>( ( radius - 4 ), 0.0 );
			QLineF ln = calculateLine( mid, re, rb );
			ln.translate( 1, 1 );
			p.drawLine( ln );
			break;
		}
		case knobGreen_17:
		{
			p.setPen( QPen( QApplication::palette().color( QPalette::Active,
							QPalette::BrightText), 2 ) );
			p.drawLine( calculateLine( mid, radius ) );
			break;
		}
		case knobVintage_32:
		{
			p.setPen( QPen( QApplication::palette().color( QPalette::Active,
							QPalette::Shadow), 2 ) );
			p.drawLine( calculateLine( mid, radius-2, 2 ) );
			break;
		}
	}

	p.drawArc( mid.x() - arcRectSize/2, 1, arcRectSize, arcRectSize, (90-centerAngle)*16, -16*(m_angle-centerAngle) );

	p.end();

	_p->drawImage( 0, 0, m_cache );
}
Example #17
0
void Routine::performLoop() {
  updateAngle();
  loop();
  STRIP->show();
}
Example #18
0
void MediumPlane::update()
{
	/*if (!m_dead)
	{
		if (m_exploting)
		{
			updateExplotionAnimation();
		}
	}

	m_enemyWeapon->update();

	if (!m_dead && !m_dying)
	{
		//Si esta en la parte de abajo de la pantalla, Sube
		if (m_position.getY() >= (Game::Instance()->getGameHeight()/3) - m_height)
		{
			m_direction.setX(0);
			m_direction.setY(DIRECTION_UP);
			m_goingUp = true;
		}
		else
		{
			m_goingUp = false;
		}

		//Si llega a un borde, invierta la dirección en X
		if ((!m_goingRight) && (m_position.getX() <= m_borderReturnOffset))
		{
			flip();
		}
		if ((m_goingRight) && (m_position.getX() >= m_borderReturnOffset))
		{
			flip();
		}

		//Si no esta subiendo, tiende a moverse hacia la derecha o izquierda, segun corresponda
		if (!m_goingUp)
		{
			if (m_goingRight)
			{
				m_direction.setX(DIRECTION_RIGHT);
				m_direction.m_y += Random::getFloatRange(-0.25f, 0.25f);
				m_direction.normalize();
			}
			else
			{
				m_direction.setX(DIRECTION_LEFT);
				m_direction.m_y += Random::getFloatRange(-0.25f, 0.25f);
				m_direction.normalize();
			}
		}

		if (m_position.getY() < 50)
		{
			m_direction.m_y = DIRECTION_DOWN;
		}


		//Analiza si debe disparar
		if (!m_goingUp)
		{
			int shootLuck = Random::getRange(0, 1000);
			if (shootLuck <= m_shootChance)
			{
				shoot();
			}
		}
	}

	//Actualiza la posición y comunica a los clientes
	Enemy::update();
*/

	/******************************Update Mati*************************************/
	if (!m_dead)
	{
		if (m_exploting)
		{
			updateExplotionAnimation();
		}
	}

	m_enemyWeapon->update();

	if (!m_dead && !m_dying)
	{
		m_direction.setX(0);
		m_direction.setY(DIRECTION_DOWN);
		frameC++;
		if(frameC>60 and 120>frameC)
		{
			m_direction.setY(7*sinf((360-frameC*6+270)*0.01745329251f));
			m_direction.setX(7*cosf((360-frameC*6+270)*0.01745329251f));
		}
		updateAngle();
		int shootLuck = Random::getRange(0, 1000);
		if (shootLuck <= m_shootChance)
		{
			shoot();
		}
	}
	Enemy::update();
	/********************************************************************************/
}
Example #19
0
void Gear_ClusteredDither::runVideo()
{
  _image = _VIDEO_IN->type();
  if (_image->isNull())
    return;

  _outImage = _VIDEO_OUT->type();
  _outImage->resize(_image->width(), _image->height());
  
  _data = _image->data();    
  _outData = _outImage->data();
  
  unsigned char *iterData = (unsigned char*)_data;
  unsigned char *iterOutData = (unsigned char*)_outData;

  int prevSizeX = _sizeX;
  int prevSizeY = _sizeY;
  _sizeX = _image->width();
  _sizeY = _image->height();
  
  NOTICE("Changing cluster");
  // If cluster size has changed, recompute threshold matrix.
  int prevClusterSize = _clusterSize;
  _clusterSize = CLAMP((int)_CLUSTER_SIZE_IN->type()->value(), 2, MAX((int)_image->height(),4));
  bool clusterChanged = (prevClusterSize != _clusterSize);
  if (clusterChanged)
    _width = _clusterSize * 3;
  
  // XXX computeThreshold deux fois!!!
  // Set spot type.
  eSpotType prevSpotType = _spotType;
  _spotType = (eSpotType)CLAMP((int)_SPOT_TYPE_IN->type()->value(), (int)SQUARE, (int)LINE);
  bool spotTypeChanged = (prevSpotType != _spotType);
  
  if (clusterChanged || spotTypeChanged)
    updateThreshold();
  NOTICE("...done");

  if (_sizeX != prevSizeX || _sizeY != prevSizeY)
  {
    NOTICE("Updating polar coordinates");
    updatePolarCoordinates();
    NOTICE("Changing angles");
    _angle[0] = DEG2RAD(CLAMP((int)_ANGLE_RED_IN->type()->value(), 0, 360));
    _angle[1] = DEG2RAD(CLAMP((int)_ANGLE_GREEN_IN->type()->value(), 0, 360));
    _angle[2] = DEG2RAD(CLAMP((int)_ANGLE_BLUE_IN->type()->value(), 0, 360));
    
    updateAngle(0);
    updateAngle(1);
    updateAngle(2);
    NOTICE("...done");
  }
  else
  {
    NOTICE("Changing angles");
    double angleR = _angle[0];
    _angle[0] = DEG2RAD(CLAMP((int)_ANGLE_RED_IN->type()->value(), 0, 360));
    double angleG = _angle[1];
    _angle[1] = DEG2RAD(CLAMP((int)_ANGLE_GREEN_IN->type()->value(), 0, 360));
    double angleB = _angle[2];
    _angle[2] = DEG2RAD(CLAMP((int)_ANGLE_BLUE_IN->type()->value(), 0, 360));

    if (clusterChanged || _angle[0] != angleR)
      updateAngle(0);
    
    if (clusterChanged || _angle[1] != angleG)
      updateAngle(1);
    
    if (clusterChanged || _angle[2] != angleB)
      updateAngle(2);
    NOTICE("...done");
  }
  
  iterData = (unsigned char*) _data;
  iterOutData = (unsigned char*) _outData;

  Array2DType<std::pair<int, int> >::iterator
    rIt = _rChannel[0].begin(),
    gIt = _rChannel[1].begin(),
    bIt = _rChannel[2].begin();
  
  for (int y=0; y<_sizeY; ++y)
  {
    for (int x=0; x<_sizeX; ++x, ++rIt, ++gIt, ++bIt)
    {
      *iterOutData++ = getValue(*iterData++, rIt->first, rIt->second);
      *iterOutData++ = getValue(*iterData++, gIt->first, gIt->second);
      *iterOutData++ = getValue(*iterData++, bIt->first, bIt->second);
      iterOutData++;
      iterData++;
    }
  }  

}
Example #20
0
void Unit::update(float dt)
{	
	m_weaponUpgradeUI.setPosition(m_position);
	m_weaponUpgradeUI.update(dt);
	m_weaponUpgradeUI.setCurrentWeapon(& m_currentWeapon);
	m_weaponUpgradeUI.setRank(m_rank);
	m_light->setPosition(m_position);
	m_xpBar.update();
	m_xpBar.setPosition(m_position + Vector2D(-20, 20));
	m_anim.update(dt);
	m_anim.setRotation((m_directionAngle - (PI )) * 180 / PI);
	m_anim.setPosition(m_position);
	rankImg.setPosition(Vector2D(m_position + Vector2D(-m_radius + 30, 20)).toSFMLVector());
	m_selectAnimation.update(dt);
	m_selectAnimation.setPosition(m_position);
	//if given a move order
	if (m_state == UNIT_STATE::MOVING)
	{
		//find direction to target
		int direction = getDirectionToTarget();

		//increment angle
		updateAngle(m_positionAngle + dt * m_speed * direction);

		m_directionAngle = m_positionAngle + PI / 2 * direction;
		

		//check if unit is at destination
		if (fabs(m_positionAngle - m_targetAngle) <= fabs(m_speed * dt))
		{
			//set state to waiting
			m_state = UNIT_STATE::WAITING;
		}
	}
	else if (m_state == UNIT_STATE::WAITING)
	{ 
		

	}
	else if (m_state == UNIT_STATE::FIRING)
	{
		fireWeapon();
	}

	if (isPlayer())
	{
		if (m_state == UNIT_STATE::MOVING)
		{
			if (SceneManager::getInstance()->playerColorIndex == 0)
			{
				m_anim.setFramesPerSecond(30);
				m_anim.changeAnimation("red");
				m_anim.SetLooping(true);
			}
			else if (SceneManager::getInstance()->playerColorIndex == 1)
			{
				m_anim.setFramesPerSecond(30);
				m_anim.changeAnimation("walingAssaltAnimation");
				m_anim.SetLooping(true);
			}
			else if (SceneManager::getInstance()->playerColorIndex == 2)
			{
				m_anim.setFramesPerSecond(30);
				m_anim.changeAnimation("yellow");
				m_anim.SetLooping(true);
			}
			else if (SceneManager::getInstance()->playerColorIndex == 3)
			{
				m_anim.setFramesPerSecond(30);
				m_anim.changeAnimation("white");
				m_anim.SetLooping(true);
			}
		}
		else if (m_state == UNIT_STATE::WAITING)
		{
			if (SceneManager::getInstance()->playerColorIndex == 0)
			{
				m_anim.setFramesPerSecond(30);
				m_anim.changeAnimation("red");
				m_anim.SetLooping(false);
			}
			else if (SceneManager::getInstance()->playerColorIndex == 1)
			{
				m_anim.setFramesPerSecond(30);
				m_anim.changeAnimation("walingAssaltAnimation");
				m_anim.SetLooping(false);
			}
			else if (SceneManager::getInstance()->playerColorIndex == 2)
			{
				m_anim.setFramesPerSecond(30);
				m_anim.changeAnimation("yellow");
				m_anim.SetLooping(false);
			}
			else if (SceneManager::getInstance()->playerColorIndex == 3)
			{
				m_anim.setFramesPerSecond(30);
				m_anim.changeAnimation("white");
				m_anim.SetLooping(false);
			}

		}
		else if (m_state == UNIT_STATE::FIRING)
		{
			if (SceneManager::getInstance()->playerColorIndex == 0)
			{
				m_anim.setFramesPerSecond(30);
				m_anim.changeAnimation("red");
				m_anim.SetLooping(true);
			}
			else if (SceneManager::getInstance()->playerColorIndex == 1)
			{
				m_anim.setFramesPerSecond(30);
				m_anim.changeAnimation("walingAssaltAnimation");
				m_anim.SetLooping(true);
			}
			else if (SceneManager::getInstance()->playerColorIndex == 2)
			{
				m_anim.setFramesPerSecond(30);
				m_anim.changeAnimation("yellow");
				m_anim.SetLooping(true);
			}
			else if (SceneManager::getInstance()->playerColorIndex == 3)
			{
				m_anim.setFramesPerSecond(30);
				m_anim.changeAnimation("white");
				m_anim.SetLooping(true);
			}
		}
	}
	else
	{
		if (m_state == UNIT_STATE::MOVING)
		{
			switch (m_unitType)
			{
			case UNIT_TYPE::ASSAULT:
				m_anim.setFramesPerSecond(120);
				m_anim.changeAnimation("scoutWalking");
				m_anim.SetLooping(true);
				break;
			case UNIT_TYPE::CQB:
				m_anim.setFramesPerSecond(120);
				m_anim.changeAnimation("tankWalking");
				m_anim.SetLooping(true);
				break;
			case UNIT_TYPE::SNIPER:
				m_anim.setFramesPerSecond(120);
				m_anim.changeAnimation("sniperWalking");
				m_anim.SetLooping(true);
				break;
			}
			
		}
		else if (m_state == UNIT_STATE::WAITING)
		{
			switch (m_unitType)
			{
			case UNIT_TYPE::ASSAULT:
				m_anim.setFramesPerSecond(120);
				m_anim.changeAnimation("scoutWalking");
				m_anim.SetLooping(true);
				break;
			case UNIT_TYPE::CQB:
				m_anim.setFramesPerSecond(120);
				m_anim.changeAnimation("tankWalking");
				m_anim.SetLooping(true);
				break;
			case UNIT_TYPE::SNIPER:
				m_anim.setFramesPerSecond(120);
				m_anim.changeAnimation("sniperWalking");
				m_anim.setPosition(m_position + Vector2D(10, 0));
				m_anim.SetLooping(true);
				break;
			}

		}
		else if (m_state == UNIT_STATE::FIRING)
		{
			switch (m_unitType)
			{
			case UNIT_TYPE::ASSAULT:
				m_anim.setFramesPerSecond(120);
				m_anim.changeAnimation("scoutShooting");
				m_anim.SetLooping(true);
				break;
			case UNIT_TYPE::CQB:
				m_anim.setFramesPerSecond(120);
				m_anim.changeAnimation("tankShooting");
				m_anim.SetLooping(true);
				break;
			case UNIT_TYPE::SNIPER:
				m_anim.setFramesPerSecond(120);
				m_anim.changeAnimation("sniperShooting");
				m_anim.SetLooping(true);
				break;
			}
		}
	}

	m_currentWeapon.update(getPositionByAngle(m_positionAngle), m_directionAngle, dt);

	if (m_isSelected)
	{
		m_selectAnimation.SetLooping(true);
		m_selectAnimation.setDoOnce(true);
	}
	else
	{
		m_selectAnimation.SetLooping(false);
		m_selectAnimation.reset();
	}

	if (m_experience > 600)
	{
		m_xpBar.setFGColor(sf::Color(60, 179, 113, 255));
	}
	
    if (m_rank == UNIT_RANK::A)
	{

	}
	else if (m_rank == UNIT_RANK::B)
	{
		rankImg.setTexture(AssetLoader::getInstance()->findTextureByKey("RankB"));
	}
	else if (m_rank == UNIT_RANK::C)
	{
		rankImg.setTexture(AssetLoader::getInstance()->findTextureByKey("RankC"));
	}
	else if (m_rank == UNIT_RANK::D)
	{
		rankImg.setTexture(AssetLoader::getInstance()->findTextureByKey("RankD"));
	}
	else if (m_rank == UNIT_RANK::E)
	{
		rankImg.setTexture(AssetLoader::getInstance()->findTextureByKey("RankE"));
	}
	else if (m_rank == UNIT_RANK::F)
	{
		rankImg.setTexture(AssetLoader::getInstance()->findTextureByKey("RankF"));
	}
	else if (m_rank == UNIT_RANK::G)
	{
		rankImg.setTexture(AssetLoader::getInstance()->findTextureByKey("RankG"));
	}
}