示例#1
0
void MaxMatrix::init()
{
	pinMode(DataInPin, OUTPUT);
	pinMode(ClockPin, OUTPUT);
	pinMode(ChipSelectPin, OUTPUT);
	digitalWrite(ClockPin, HIGH); 

	setCommand(MAX7219_REG_SCAN_LIMIT_ADDRESS, MAX7219_REG_SCAN_LIMIT_DISPLAY_DIGIT_0_TO_7);    // display all digits  
	setCommand(MAX7219_REG_DECODE_MODE_ADDRESS, MAX7219_REG_DECODE_MODE_NO_DECODE);				// using an led matrix (not digits)
	setCommand(MAX7219_REG_SHUTDOWN_ADDRESS, MAX7219_REG_SHUTDOWN_MODE_NORMAL_OPERATION);		// not in shutdown mode
	setCommand(MAX7219_REG_DISPLAY_TEST_ADDRESS, MAX7219_REG_DISPLAY_TEST_NORMAL_OPERATION);	// no display test
	
	// empty registers, turn all LEDs off
	clear();
	
	setIntensity(0x04);    // the first 0x0f is the value you can set
}
void NormalMappingDelegate::onInit()
{
    scene = new Scene();
    this->move_forward=false;
    this->move_backward=false;
    this->move_left=false;
    this->move_right=false;
    this->move_up = false;
    this->move_down = false;
    scene->setRenderType (DEFERRED_SHADING);

    AmbientLight * ambient = scene->getAmbientLight ();
    ambient->setColor (QVector3D(1,1,1));
    ambient->setIntensity (0.5);

    auto sprite = new Sprite();
    sprite->setTexture (TexturePool::getInstance ()->createOrGetTexture ("./res/texture/mygame/fps/cross_hair.png"));
    sprite->setCamera (scene->guiCamera ());
    sprite->setPos (QVector3D(1024/2-sprite->texture ()->width ()/2,768/2-sprite->texture ()->height ()/2,0));
    scene->root ()->addChild (sprite);

    scene->setCamera (&camera);

    //set this scene as current scene
    scene->setAsCurrentScene();
    scene->root ()->addChild (&camera);

    //create a box
    auto the_box = new Entity("./res/model/box/box.obj");
    the_box->setShaderProgram (ShaderPool::getInstance ()->get ("deferred"));
    //set it's normal map
    the_box->getMesh (0)->getMaterial ()->setNormalMap (TexturePool::getInstance ()->createOrGetTexture ("./res/model/box/bricks_normal.jpg"));
    the_box->setCamera (&camera);
    scene->root ()->addChild (the_box);
    //this sample we don't use shadow
    the_box->setIsEnableShadow (false);
    the_box->onUpdate = [](Node* target){
        target->setRotation (target->rotation ()+QVector3D(0,0.1,0));
    };
    //then add  a Directional light
    auto directional_light = scene->getDirectionalLight ();
    directional_light->setIntensity (1);
    directional_light->setColor (QVector3D(1,1,1));
    directional_light->setDirection (QVector3D(0,0,-1));

}
示例#3
0
void GASignalMatrix::init()
{
        pinMode(data,  OUTPUT);
        pinMode(clock, OUTPUT);
        pinMode(load,  OUTPUT);
        digitalWrite(clock, HIGH);

        setCommand(max7219_reg_scanLimit, 0x07);
        setCommand(max7219_reg_decodeMode, 0x00);  // using an led matrix (not digits)
        setCommand(max7219_reg_shutdown, 0x01);    // not in shutdown mode
        setCommand(max7219_reg_displayTest, 0x00); // no display test

        // empty registers, turn all LEDs off
        clear();

        setIntensity(0x0f);    // the first 0x0f is the value you can set
}
示例#4
0
void RGBLED::cycleLights() {
	switch(cycleState_) {
		case blueToViolet:
			// Serial.println("Cycling blueToViolet");
			if (redValue_ < maxValue_) {
				setIntensity(red, redValue_ + 1);
			} else {
				cycleState_ = violetToRed;
			}
			break;
		case violetToRed:
			// Serial.println("Cycling violetToRed");
			if (blueValue_ > minValue_) {
				setIntensity(blue, blueValue_ - 1);
			} else {
				cycleState_ = redToYellow;
			}
			break;
		case redToYellow:
			// Serial.println("Cycling redToYellow");
			if (greenValue_ < maxValue_) {
				setIntensity(green, greenValue_ + 1);
			} else {
				cycleState_ = yellowToGreen;
			}
			break;
		case yellowToGreen:
			// Serial.println("Cycling yellowToGreen");
			if (redValue_ > minValue_) {
				setIntensity(red, redValue_ - 1);
			} else {
				cycleState_ = greenToTeal;
			}
			break;
		case greenToTeal:
			// Serial.println("Cycling greenToTeal");
			if (blueValue_ < maxValue_) {
				setIntensity(blue, blueValue_ + 1);
			} else {
				cycleState_ = tealToBlue;
			}
			break;
		case tealToBlue:
			// Serial.println("Cycling tealToBlue");
			if (greenValue_ > minValue_) {
				setIntensity(green, greenValue_ - 1);
			} else {
				cycleState_ = blueToViolet;
			}
			break;
	}
	return;
}
/** Returns the additional force being applied to the kart because of 
 *  slipstreaming.
 */
void SlipStream::updateSlipstreamPower()
{
    // Low level AIs should not do any slipstreaming.
    if(!m_kart->getController()->isPlayerController() &&
        race_manager->getDifficulty()==RaceManager::DIFFICULTY_EASY) return;

    // See if we are currently using accumulated slipstream credits:
    // -------------------------------------------------------------
    if(m_slipstream_mode==SS_USE)
    {
        setIntensity(2.0f, NULL);
        const KartProperties *kp=m_kart->getKartProperties();
        m_kart->increaseMaxSpeed(MaxSpeed::MS_INCREASE_SLIPSTREAM,
                                kp->getSlipstreamMaxSpeedIncrease(),
                                kp->getSlipstreamAddPower(),
                                kp->getSlipstreamDuration(),
                                kp->getSlipstreamFadeOutTime()       );
    }
}   // upateSlipstreamPower
LightSource::LightSource( GLfloat arg1, GLfloat arg2, GLfloat arg3 ) {
	for( int i = 0; i < GL_MAX_LIGHTS; i++ )
		if( lights_used[ i ] == false )
		{
			lights_used[ i ] = true;
			light_numb = GL_LIGHT0;//;translate( i );
			
			break;
		}
	
	/* Light is not attached to anything initially */
	mass = NULL;
	
	setAmbient( 0, 0, 0, 1 );
	setDiffuse( arg1, arg2, arg3, 1 );
	setIntensity( arg1, arg2, arg3, 1 );
	
	enable();
}
示例#7
0
/** Returns the additional force being applied to the kart because of
 *  slipstreaming.
 */
void SlipStream::updateSlipstreamPower()
{
    // See if we are currently using accumulated slipstream credits:
    // -------------------------------------------------------------
    if(m_slipstream_mode==SS_USE)
    {
        setIntensity(2.0f, NULL);
        const KartProperties *kp=m_kart->getKartProperties();
        m_kart->increaseMaxSpeed(MaxSpeed::MS_INCREASE_SLIPSTREAM,
                                kp->getSlipstreamMaxSpeedIncrease() *
                                m_kart->getPlayerDifficulty()->getSlipstreamMaxSpeedIncrease(),
                                kp->getSlipstreamAddPower() *
                                m_kart->getPlayerDifficulty()->getSlipstreamAddPower(),
                                kp->getSlipstreamDuration() *
                                m_kart->getPlayerDifficulty()->getSlipstreamDuration(),
                                kp->getSlipstreamFadeOutTime() *
                                m_kart->getPlayerDifficulty()->getSlipstreamFadeOutTime());
    }
}   // upateSlipstreamPower
/**----------------------------------------------------------------------------
 *      Thread  'Thread_angles': set Pitch and Roll display
 *---------------------------------------------------------------------------*/
	void Thread_LED(void const *argument) 
	{
		currentPin = GPIO_PIN_12;
		while(1){
			osSignalWait(1, osWaitForever);
			if (speed == 10)
			{	
				LED_PWM_Init();
				setIntensity(intensity);
			}
			else
			{
				LED_PWM_DeInit();
				LED_GPIO_Init();
				rotate();
				//LED_GPIO_DeInit();
				LED_PWM_Init();
			} 
			osSignalClear(tid_Thread_LED, 1);
		}
	}
示例#9
0
/***********************************************************************
     * Map
     * checkNeighbours

***********************************************************************/
void Map::checkNeighbours(MapTile *tile) {
	int x = tile->index.x;
	int y = tile->index.y;

	char intensity = tile->intensity - tile->absorb;
	if (intensity < 0) return;
	sf::Color color = reapplyIntensity(tile->light, tile->intensity, intensity);

	if (x > 0             ) setIntensity(&tiles[x-1][y], intensity, color);
	if (x < MAP_SIZE_X - 1) setIntensity(&tiles[x+1][y], intensity, color);
	if (y > 0             ) setIntensity(&tiles[x][y-1], intensity, color);
	if (y < MAP_SIZE_Y - 1) setIntensity(&tiles[x][y+1], intensity, color);


	color.r *= 0.9f;
	color.g *= 0.9f;
	color.b *= 0.9f;

	if (x > 0              && y < MAP_SIZE_Y - 1) setIntensity(&tiles[x-1][y+1], intensity, color);
	if (x < MAP_SIZE_X - 1 && y > 0             ) setIntensity(&tiles[x+1][y-1], intensity, color);
	if (y > 0              && x > 0             ) setIntensity(&tiles[x-1][y-1], intensity, color);
	if (y < MAP_SIZE_Y - 1 && x < MAP_SIZE_X - 1) setIntensity(&tiles[x+1][y+1], intensity, color);
}
示例#10
0
void SmokeSource::render(const glm::mat4& matrix)
{
  if (!visible)
  {
    particles = 0;
    return; // object was culled
  }

  if (Window::debug)
    bounding_sphere.render(matrix);

  ObjectCounter::count();

  configureArrayBuffer();

  glm::vec3 position = glm::vec3(matrix * glm::vec4(0, 0, 0, 1));
  float distance = glm::length(position);
  adjustLevelOfDetail(distance);

  animate();

  setShaderMatrix(matrix);
  float intensity = intensities[Window::active_measurement];
  if (intensity > 0.9f * FLT_MAX)
    return;
  setIntensity(intensity);
  
  glDisable(GL_DEPTH_TEST);
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  glDrawArraysInstanced(GL_QUADS, 0, 4 * FACES, particles);

  glDisable(GL_BLEND);
  glEnable(GL_DEPTH_TEST);

  glDisableVertexAttribArray(0);
  glDisableVertexAttribArray(1);
}
示例#11
0
void RenderableLightEntityItem::updateRenderItemFromEntity(LightPayload& lightPayload) {
    auto entity = this;

    lightPayload.setVisible(entity->getVisible());

    auto light = lightPayload.editLight();
    light->setPosition(entity->getPosition());
    light->setOrientation(entity->getRotation());

    bool success;
    lightPayload.editBound() = entity->getAABox(success);
    if (!success) {
        lightPayload.editBound() = render::Item::Bound();
    }

    glm::vec3 dimensions = entity->getDimensions();
    float largestDiameter = glm::compMax(dimensions);
    light->setMaximumRadius(largestDiameter / 2.0f);

    light->setColor(toGlm(entity->getXColor()));

    float intensity = entity->getIntensity();//* entity->getFadingRatio();
    light->setIntensity(intensity);

    light->setFalloffRadius(entity->getFalloffRadius());


    float exponent = entity->getExponent();
    float cutoff = glm::radians(entity->getCutoff());
    if (!entity->getIsSpotlight()) {
        light->setType(model::Light::POINT);
    } else {
        light->setType(model::Light::SPOT);

        light->setSpotAngle(cutoff);
        light->setSpotExponent(exponent);
    }

}
示例#12
0
/** Update Function; should be called every loop to set, animate and actuate the lamps **/
void LED::update()
{
	if( intensityAnim->isAnimating() )
	{
		setIntensity( intensityAnim->getValue(), false );
	}
	/* Here we actually actuate the light if autowrite is on */
	if( _autoWrite )
	{
		if ( hasNewValue() )
		{
			if ( _on )
			{
				analogWrite(_channel, _intensity);
			}
			else 
			{
				analogWrite(_channel, 0);
			}
		}
	}
}
void max7221::init()
{
	/*
	 * set the pin configuration and default values to initially turn on the chip.
	 * this function has to be called EXACTLY one time before any data is pushed to the chip.
	 * it is NOT a class constructor, because we will use multiple instances of this class
	 */
	pinMode( _pinCLK, OUTPUT );
	pinMode( _pinDATA, OUTPUT );
	pinMode( _pinLOAD, OUTPUT );

	for( int i = 0; i < _chipcount; i++ )
	{
		selectChip(i);

		setDecodeMode( 0x00 ); //use a custom matrix on all registers
		setIntensity( 0x0f ); //use maximum intensity
		setScanLimit( 0x07 ); //use all 8 available registers
		setShutdown( 0x01 ); //wake up
		setDisplayTest( 0x00 ); //no display test
	}
	selectChip(0);//reset to default first chip for backwards compatibility
}
示例#14
0
void RGBLED::decrementChannel(Channel channel) {
	switch(channel) {
		case red:
			if (redValue_ - increment_ >= minValue_)
				setIntensity(red, redValue_ - increment_);
			else
				setIntensity(red, minValue_);
			break;

		case green:
			if (greenValue_ - increment_ >= minValue_)
				setIntensity(green, greenValue_ - increment_);
			else
				setIntensity(green, minValue_);
			break;

		case blue:
			if (blueValue_ - increment_ >= minValue_)
				setIntensity(blue, blueValue_ - increment_);
			else
				setIntensity(blue, minValue_);
			break;
	}
}
示例#15
0
void //  set to output currents 21 mA = 3 + 6 + 12 mA; B0111xxxx
SAA1064::setBright( void ) {

  setIntensity( 7 );
  
} // SAA1064::setBright
示例#16
0
void // set to output currents 12 mA; B0100xxxx
SAA1064::setNormal( void ) {

  setIntensity( 4 );

} // SAA1064::setNormal
示例#17
0
void // set to output currents 3 mA; B0001xxxx
SAA1064::setDark( void ) {

  setIntensity( 1 );

} // SAA1064::setDark
示例#18
0
void RGBLed::on()
{
	setIntensity(1.f);
}
示例#19
0
// Default constructor.
HSIColor::HSIColor(void) {
  setHue(0);
  setSaturation(0);
  setIntensity(0);
}
示例#20
0
void CSMDelegate::onInit()
{
    scene = new Scene();
    this->move_forward=false;
    this->move_backward=false;
    this->move_left=false;
    this->move_right=false;
    this->move_up = false;
    this->move_down = false;

    AmbientLight * ambient = scene->getAmbientLight ();
    ambient->setColor (QVector3D(1,1,1));
    ambient->setIntensity (0.5);

    auto sprite = new Sprite();
    sprite->setTexture (TexturePool::getInstance ()->createOrGetTexture ("./res/texture/mygame/fps/cross_hair.png"));
    sprite->setCamera (scene->guiCamera ());
    sprite->setPos (QVector3D(1024/2-sprite->texture ()->width ()/2,768/2-sprite->texture ()->height ()/2,0));
    scene->root ()->addChild (sprite);

    scene->setCamera (&camera);

    SkyBox * sky_box = new SkyBox("./res/texture/sky_box/right.jpg",
                                  "./res/texture/sky_box/left.jpg",
                                  "./res/texture/sky_box/top.jpg",
                                  "./res/texture/sky_box/bottom.jpg",
                                  "./res/texture/sky_box/front.jpg",
                                  "./res/texture/sky_box/back.jpg");
    sky_box->setCamera(&camera);
    scene->setSkyBox(sky_box);

    //set this scene as current scene
    scene->setAsCurrentScene();
    scene->root ()->addChild (&camera);

    camera.setPos (QVector3D(0,15,0));
    camera.setRotation (QVector3D(-60,0,0));

    Terrain a("./res/model/terrain/terrain.jpg");
    auto terrain_model = new Entity();
    terrain_model->setName ("terrain");
    terrain_model->setCamera(&camera);
    terrain_model->setShaderProgram (ShaderPool::getInstance()->get ("deferred"));
    a.mesh ()->getMaterial ()->getDiffuse ()->texture= TexturePool::getInstance ()->createOrGetTexture ("./res/model/terrain/sand.jpg");
    terrain_model->addMesh(a.mesh ());
    terrain_model->scale (10,10,10);
    terrain_model->setPos (QVector3D(0,-1,0));
    scene->root ()->addChild (terrain_model);

    for(int i = 0; i< 5; i++)
    {
        auto flight = new Entity("./res/model/spaceship/phoenix_ugv.md2");
        flight->setCamera (&camera);
        flight->setShaderProgram (ShaderPool::getInstance()->get ("deferred"));
        flight->setScalling (QVector3D(0.05,0.05,0.05));

        scene->root ()->addChild (flight);
        //flight->setIsEnableShadow (false);
        flight->setPos (QVector3D((rand()%5)*2,3,-2*i));
    }


    /*
    auto spotLight = scene->createSpotLight ();
    spotLight->setIntensity (1);
    spotLight->setColor (QVector3D(0,1,1));
    spotLight->setDirection (QVector3D(-1,-1,0));
    spotLight->setPos (QVector3D(10,10,-4));
    spotLight->setOutterAngle (35);
    spotLight->setAngle (20);
    spotLight->setRange (40);
    */

    //then add  a Directional light
    auto directional_light = scene->getDirectionalLight ();
    directional_light->setIntensity (0.5);
    directional_light->setColor (QVector3D(1,1,1));
    directional_light->setDirection (QVector3D(-1,-1,0));

}
示例#21
0
/** Immediatily sets the intensity of the lamp (range 0 - 255). 
	Values are changed immediatily, but only actuated in the update() function.
	An ongoing intensity animation is stopped unless stopAnimation is set to false. 
**/
void LED::setBrightness( int intensity, bool stopAnimation )
{
	setIntensity(intensity, stopAnimation);
}
/** Update, called once per timestep.
 *  \param dt Time step size.
 */
void SlipStream::update(float dt)
{
    MovingTexture::update(dt);

    // Update this karts slipstream quad (even for low level AI which don't
    // use slipstream, since even then player karts can get slipstream, 
    // and so have to compare with the modified slipstream quad.
    m_slipstream_original_quad->transform(m_kart->getTrans(), 
                                          m_slipstream_quad);

    if(m_slipstream_mode==SS_USE)
    {
        m_slipstream_time -= dt;
        if(m_slipstream_time<0) m_slipstream_mode=SS_NONE;
    }

    updateSlipstreamPower();

    // If this kart is too slow for slipstreaming taking effect, do nothing
    // --------------------------------------------------------------------
    // Define this to get slipstream effect shown even when the karts are
    // not moving. This is useful for debugging the graphics of SS-ing.
#undef DISPLAY_SLIPSTREAM_WITH_0_SPEED_FOR_DEBUGGING
#ifndef DISPLAY_SLIPSTREAM_WITH_0_SPEED_FOR_DEBUGGING
    if(m_kart->getSpeed()<m_kart->getKartProperties()->getSlipstreamMinSpeed())
    {
        setIntensity(0, NULL);
        m_slipstream_mode = SS_NONE;
        if(UserConfigParams::m_slipstream_debug)
            setDebugColor(video::SColor(255, 0, 0, 0));
        return;
    }
#endif

    // Then test if this kart is in the slipstream range of another kart:
    // ------------------------------------------------------------------
    World *world           = World::getWorld();
    unsigned int num_karts = world->getNumKarts();
    bool is_sstreaming     = false;
    m_target_kart          = NULL;

    // Note that this loop can not be simply replaced with a shorter loop
    // using only the karts with a better position - since a kart might
    // be a lap behind
    for(unsigned int i=0; i<num_karts; i++)
    {
        m_target_kart= world->getKart(i);
        // Don't test for slipstream with itself, a kart that is being
        // rescued or exploding, or an eliminated kart
        if(m_target_kart==m_kart               || 
            m_target_kart->getKartAnimation()  ||
            m_target_kart->isEliminated()        ) continue;

        float diff = fabsf(m_target_kart->getXYZ().getY() 
                           - m_kart->getXYZ().getY()      );
        // If the kart is 'on top' of this kart (e.g. up on a bridge),
        // don't consider it for slipstreaming.

        if(diff>6.0f) continue;
        // If the kart we are testing against is too slow, no need to test
        // slipstreaming. Note: We compare the speed of the other kart 
        // against the minimum slipstream speed kart of this kart - not 
        // entirely sure if this makes sense, but it makes it easier to 
        // give karts different slipstream properties.
#ifndef DISPLAY_SLIPSTREAM_WITH_0_SPEED_FOR_DEBUGGING
        if(m_target_kart->getSpeed() <
            m_kart->getKartProperties()->getSlipstreamMinSpeed()) 
        {
            if(UserConfigParams::m_slipstream_debug &&
                m_kart->getController()->isPlayerController())
                m_target_kart->getSlipstream()
                              ->setDebugColor(video::SColor(255, 0, 0, 0));

            continue;
        }
#endif
        // Quick test: the kart must be not more than
        // slipstream length+0.5*kart_length()+0.5*target_kart_length
        // away from the other kart
        Vec3 delta = m_kart->getXYZ() - m_target_kart->getXYZ();
        float l    = m_target_kart->getKartProperties()->getSlipstreamLength() 
                   + 0.5f*( m_target_kart->getKartLength()
                           +m_kart->getKartLength()        );
        if(delta.length2_2d() > l*l) 
        {
            if(UserConfigParams::m_slipstream_debug &&
                m_kart->getController()->isPlayerController())
                m_target_kart->getSlipstream()
                             ->setDebugColor(video::SColor(255, 0, 0, 128));
            continue;
        }
        // Real test: if in slipstream quad of other kart
        if(m_target_kart->getSlipstream()->m_slipstream_quad
                                         ->pointInQuad(m_kart->getXYZ()))
        {
            is_sstreaming     = true;
            break;
        }
        if(UserConfigParams::m_slipstream_debug &&
            m_kart->getController()->isPlayerController())
            m_target_kart->getSlipstream()
                         ->setDebugColor(video::SColor(255, 0, 0, 255));
    }   // for i < num_karts

    if(!is_sstreaming)
    {
        if(UserConfigParams::m_slipstream_debug &&
            m_kart->getController()->isPlayerController())
            m_target_kart->getSlipstream()
                         ->setDebugColor(video::SColor(255, 255, 0, 0));

        if(isSlipstreamReady()) 
        {
            // The first time slipstream is ready after collecting
            // and you are leaving the slipstream area, you get a
            // zipper bonus. 
            if(m_slipstream_mode==SS_COLLECT)
            {
                m_slipstream_mode = SS_USE;
                m_kart->handleZipper();
                m_slipstream_time = 
                    m_kart->getKartProperties()->getSlipstreamCollectTime();
                return;
            }
        }
        m_slipstream_time -=dt;
        if(m_slipstream_time<0) m_slipstream_mode = SS_NONE;
        setIntensity(0, NULL);
        return;
    }   // if !is_sstreaming

    if(UserConfigParams::m_slipstream_debug &&
        m_kart->getController()->isPlayerController())
        m_target_kart->getSlipstream()->setDebugColor(video::SColor(255, 0, 255, 0));
    // Accumulate slipstream credits now
    m_slipstream_time = m_slipstream_mode==SS_NONE ? dt 
                                                   : m_slipstream_time+dt;
    if(isSlipstreamReady())
        m_kart->setSlipstreamEffect(9.0f);
    setIntensity(m_slipstream_time, m_target_kart);

    m_slipstream_mode = SS_COLLECT;
    if(m_slipstream_time>m_kart->getKartProperties()->getSlipstreamCollectTime())
    {
        setIntensity(1.0f, m_target_kart);
    }
    

return;
    core::vector3df pos = m_kart->getNode()->getPosition();
    pos.Y = m_kart->getHoT()+0.2f;
    m_node->setPosition(pos);
    core::vector3df f = core::vector3df(0, 0, 10) - f;
    core::vector3df r = f.getHorizontalAngle();
    m_node->setRotation(r);
    return;

    const core::quaternion new_rot(m_kart->getNode()->getRotation());
    const core::quaternion old_rot(m_node->getRotation()            );

    core::quaternion interpo;
    core::vector3df interp;
    new_rot.toEuler(interp);
    m_node->setRotation(interp);
}   // update
示例#23
0
EmbossFilter::EmbossFilter(float width, float height, float intensity) : Abstract3x3ConvolutionFilter(width, height, ofVec2f(1, 1)) {
    _name = "Emboss";
    setIntensity(intensity);
    _setupShader();
}
示例#24
0
void HSIColor::setHSI(float hue, float saturation, float intensity) {
  setHue(hue);
  setSaturation(saturation);
  setIntensity(intensity);
}
void NormalMappingDelegate::onInit()
{
    scene = new Scene();
    this->move_forward=false;
    this->move_backward=false;
    this->move_left=false;
    this->move_right=false;
    this->move_up = false;
    this->move_down = false;
    scene->setRenderType (DEFERRED_SHADING);

    AmbientLight * ambient = scene->getAmbientLight ();
    ambient->setColor (QVector3D(1,1,1));
    ambient->setIntensity (0.5);

    auto sprite = new Sprite();
    sprite->setTexture (TexturePool::getInstance ()->createOrGetTexture ("./res/texture/mygame/fps/cross_hair.png"));
    sprite->setCamera (scene->guiCamera ());
    sprite->setPos (QVector3D(1024/2-sprite->texture ()->width ()/2,768/2-sprite->texture ()->height ()/2,0));
    scene->root ()->addChild (sprite);

    scene->setCamera (&camera);

    //set this scene as current scene
    scene->setAsCurrentScene();
    scene->root ()->addChild (&camera);

    //create a box
    auto the_head = new Entity("./res/model/scan_head/Infinite-Level_02.obj",Entity::LoadPolicy::LoadFromLoader);
    the_head->setShaderProgram (ShaderPool::getInstance ()->get ("deferred"));
    the_head->scale (30,30,30);
    //set it's normal map
    auto material = the_head->getMesh (0)->getMaterial ();
    material->setNormalMap (TexturePool::getInstance ()->createOrGetTexture ("./res/model/scan_head/Infinite-Level_02_Tangent_SmoothUV.jpg"));
    the_head->setCamera (&camera);
    //this sample we don't use shadow
    the_head->setIsEnableShadow (false);

        //bob
        auto the_bob2 = new Entity("./res/model/bob/boblampclean.md5mesh",Entity::LoadPolicy::LoadFromLoader);
        the_bob2->setShaderProgram (ShaderPool::getInstance ()->get ("deferred"));
        the_bob2->setCamera (&camera);
        the_bob2->setPos (QVector3D(-2,0,-10));
        the_bob2->setRotation (QVector3D(-90,0,0));
        scene->root ()->addChild (the_bob2);
        the_bob2->setIsEnableShadow (false);
        the_bob2->scale (0.05,0.05,0.05);
        the_bob2->getSkeleton ()->getEntityNodeRoot ()->findNode ("lamp")->addChild (the_head);
        //this sample we don't use shadow
        the_bob2->setIsEnableShadow (false);
        the_bob2->onRender = [](Entity * self, float dt){
            self->playAnimate (0,self->animateTime ()+ 0.02);
        };



        auto the_orc = new Entity("./res/model/orc/orc.FBX",Entity::LoadPolicy::LoadFromLoader);
        the_orc->setShaderProgram (ShaderPool::getInstance ()->get ("deferred"));
        the_orc->setCamera (&camera);
        the_orc->setRotation (QVector3D(0,180,0));
        the_orc->setScalling (QVector3D(0.1,0.1,0.1));
        the_orc->setPos (QVector3D(0,0,-10));

        scene->root ()->addChild (the_orc);
        the_orc->onRender = [](Entity * self, float dt){
            self->playAnimate (0,self->animateTime () + 0.02);
        };

        auto the_orc_axe = new Entity("./res/model/orc/axe.FBX",Entity::LoadPolicy::LoadFromLoader);
        the_orc_axe->setShaderProgram (ShaderPool::getInstance ()->get ("deferred"));
        the_orc_axe->setCamera (&camera);
        the_orc->getSkeleton ()->getEntityNodeRoot ()->findNode ("Bip001 R Hand")->addChild (the_orc_axe);

        //then add  a Directional light
        auto directional_light = scene->getDirectionalLight ();
        directional_light->setIntensity (1);
        directional_light->setColor (QVector3D(1,1,1));
        directional_light->setDirection (QVector3D(0,0,-1));
}
示例#26
0
void RGBLed::off()
{
	setIntensity(0.f);
}
示例#27
0
//private
void PlatformDemoState::cacheMeshes()
{
    xy::CubeBuilder cb(100.f);
    m_meshRenderer.loadModel(MeshID::Cube, cb);

    xy::IQMBuilder ib("assets/models/mrfixit.iqm");
    m_meshRenderer.loadModel(MeshID::Fixit, ib);

    xy::IQMBuilder ib2("assets/models/platform_01.iqm");
    m_meshRenderer.loadModel(MeshID::Platform, ib2);

    xy::IQMBuilder ib3("assets/models/batcat.iqm");
    m_meshRenderer.loadModel(MeshID::Batcat, ib3);

    xy::QuadBuilder qb({ 1500.f, 550.f });
    m_meshRenderer.loadModel(MeshID::Quad, qb);

    xy::SphereBuilder sb(34.f, 6u);
    m_meshRenderer.loadModel(MeshID::Sphere, sb);

    auto& demoMaterial = m_meshRenderer.addMaterial(MatId::Demo, xy::Material::TexturedBumped, true);
    demoMaterial.addProperty({ "u_diffuseMap", m_textureResource.get("assets/images/platform/cube_diffuse.png") });
    demoMaterial.addProperty({ "u_normalMap", m_textureResource.get("assets/images/platform/cube_normal.png") });
    demoMaterial.addProperty({ "u_maskMap", m_textureResource.get("assets/images/platform/cube_mask.png") });
    demoMaterial.getRenderPass(xy::RenderPass::ID::ShadowMap)->setCullFace(xy::CullFace::Front);
  
    auto& fixitMaterialBody = m_meshRenderer.addMaterial(MatId::MrFixitBody, xy::Material::TexturedSkinnedBumped, true);
    fixitMaterialBody.addProperty({ "u_diffuseMap", m_textureResource.get("assets/images/fixit/fixitBody.png") });
    fixitMaterialBody.addProperty({ "u_normalMap", m_textureResource.get("assets/images/fixit/fixitBody_normal.png") });
    fixitMaterialBody.addProperty({ "u_maskMap", m_textureResource.get("assets/images/fixit/fixitBody_mask.tga") });
    fixitMaterialBody.getRenderPass(xy::RenderPass::ID::ShadowMap)->setCullFace(xy::CullFace::Front);

    auto& fixitMaterialHead = m_meshRenderer.addMaterial(MatId::MrFixitHead, xy::Material::TexturedSkinnedBumped, true);
    fixitMaterialHead.addProperty({ "u_diffuseMap", m_textureResource.get("assets/images/fixit/fixitHead.png") });
    fixitMaterialHead.addProperty({ "u_normalMap", m_textureResource.get("assets/images/fixit/fixitHead_normal.png") });
    fixitMaterialHead.addProperty({ "u_maskMap", m_textureResource.get("assets/images/fixit/fixitHead_mask.png") });
    fixitMaterialHead.getRenderPass(xy::RenderPass::ID::ShadowMap)->setCullFace(xy::CullFace::Front);

    auto& platformMaterial01 = m_meshRenderer.addMaterial(MatId::Platform01, xy::Material::Textured, true, true);
    platformMaterial01.addProperty({ "u_diffuseMap", m_textureResource.get("assets/images/platform/plat_01.png") });


    auto& platformMaterial04 = m_meshRenderer.addMaterial(MatId::Platform04, xy::Material::Textured, true, true);
    platformMaterial04.addProperty({ "u_diffuseMap", m_textureResource.get("assets/images/platform/plat_04.png") });

    auto& catMat = m_meshRenderer.addMaterial(MatId::BatcatMat, xy::Material::TexturedSkinnedBumped, true);
    auto& tex = m_textureResource.get("assets/images/platform/batcat_diffuse.png");
    tex.setRepeated(true);
    catMat.addProperty({ "u_diffuseMap", tex });
    auto& tex2 = m_textureResource.get("assets/images/platform/batcat_normal.png");
    tex2.setRepeated(true);
    catMat.addProperty({ "u_normalMap", tex2 });
    auto& tex3 = m_textureResource.get("assets/images/platform/batcat_mask.png");
    tex3.setRepeated(true);
    catMat.addProperty({ "u_maskMap", tex3 });
    catMat.getRenderPass(xy::RenderPass::ID::ShadowMap)->setCullFace(xy::CullFace::Front);


    m_textureResource.setFallbackColour(sf::Color(230, 120, 0));
    auto& sphereMat = m_meshRenderer.addMaterial(MatId::SphereTest, xy::Material::TexturedBumped, true);
    sphereMat.addProperty({ "u_diffuseMap", m_textureResource.get("assets/images/sphere_test.png") });
    sphereMat.addProperty({ "u_normalMap", m_textureResource.get("assets/images/sphere_normal.png") });
    sphereMat.addProperty({ "u_maskMap", m_textureResource.get("I don't want a mask texture!!") });
    sphereMat.getRenderPass(xy::RenderPass::ID::ShadowMap)->setCullFace(xy::CullFace::Front);

    auto& lightMaterial = m_meshRenderer.addMaterial(MatId::LightSource, xy::Material::Coloured);
    lightMaterial.addProperty({ "u_colour", sf::Color(135, 135, 80) });
    lightMaterial.addProperty({ "u_maskColour", sf::Color::Blue });

    auto light = xy::Component::create<xy::PointLight>(m_messageBus, 800.f, 500.f, sf::Color(255, 255, 100));
    light->setDepth(400.f);
    light->enableShadowCasting(true);

    auto model = m_meshRenderer.createModel(MeshID::Cube, m_messageBus);
    model->setPosition({ 0.f, 0.f, light->getWorldPosition().z });
    model->setSubMaterial(lightMaterial, 0);

    auto entity = xy::Entity::create(m_messageBus);
    entity->setPosition(xy::DefaultSceneSize / 2.f);
    entity->setScale(0.25f, 0.25f);
    entity->addComponent(light);
    entity->addComponent(model);
    m_scene.addEntity(entity, xy::Scene::Layer::FrontFront);


    //---------------
    light = xy::Component::create<xy::PointLight>(m_messageBus, 600.f, 500.f, sf::Color(255, 255, 100));
    light->setDepth(300.f);
    light->setIntensity(2.5f);
    light->enableShadowCasting(true);

    model = m_meshRenderer.createModel(MeshID::Cube, m_messageBus);
    model->setPosition({ 0.f, 0.f, light->getWorldPosition().z });
    model->setSubMaterial(lightMaterial, 0);

    entity = xy::Entity::create(m_messageBus);
    entity->setPosition(2000.f, 200.f);
    entity->setScale(0.35f, 0.35f);
    entity->addComponent(light);
    entity->addComponent(model);
    m_scene.addEntity(entity, xy::Scene::Layer::FrontFront);
}
示例#28
0
void MAX7219::begin(const MAX7219_Topology *topology, const byte length) {
    MAX7219_Topology *defaultTopo;
    
    if(topology) {
        _topology = topology;
        _elements = length;
    } else {
        //Yes, we are leaking memory here. Yet again, in embedded software
        //things usually get allocated at start and never die off as there's
        //no exit();
        defaultTopo = (MAX7219_Topology *)malloc(sizeof(MAX7219_Topology) * 
                                                 MAX7219_DEFAULT_LENGTH);
        MAX7219_DEFAULT_TOPOLOGY(defaultTopo);
        _topology = defaultTopo;
        _elements = MAX7219_DEFAULT_LENGTH;
    };
    
    _chips = 0;
    for(int i = 0; i < length; i++)
        if(_topology[i].chipTo > _chips) 
                _chips = _topology[i].chipTo;
    _chips++;
#if defined(MAX7219_DEBUG)
    Serial.print("Topology has ");
    Serial.print(_elements);
    Serial.print(" elements which span ");
    Serial.print(_chips);
    Serial.println(" chips in total.");
#endif
    SPI.begin();
    SPI.setBitOrder(MSBFIRST);
    SPI.setDataMode(SPI_MODE0);
    //1MHz suffices for doing 25fps to 625 chained chips driving 8x8 matrices,
    //2MHz (as you would get on the Uno/Mega) is twice that and if you find
    //yourself needing more, you shouldn't be using Arduino anyway
    SPI.setClockDivider(SPI_CLOCK_DIV8);
    
    //Since the MAX7219 does not have a RESET, we must enforce consistency
    noDisplayTest(MAX7219_CHIP_ALL);
    setScanLimit(0x07, MAX7219_CHIP_ALL);
    setIntensity(0x08, MAX7219_CHIP_ALL);
    writeRegister(MAX7219_REG_DECODEMODE, 
                  MAX7219_FLG_DIGIT0_RAW | MAX7219_FLG_DIGIT1_RAW | 
                  MAX7219_FLG_DIGIT2_RAW | MAX7219_FLG_DIGIT3_RAW | 
                  MAX7219_FLG_DIGIT4_RAW | MAX7219_FLG_DIGIT5_RAW | 
                  MAX7219_FLG_DIGIT6_RAW | MAX7219_FLG_DIGIT7_RAW,
                  MAX7219_CHIP_ALL);
    noShutdown(MAX7219_CHIP_ALL);
    
    for(int i = 0; i < _elements; i++) {
        if(_topology[i].elementType == MAX7219_MODE_NC) 
            setScanLimit(_topology[i].digitFrom - 1, _topology[i].chipFrom);
        if(_topology[i].elementType == MAX7219_MODE_7SEGMENT)
            for(int j = 0; j < _topology[i].chipTo - _topology[i].chipFrom +
                1; j++) {
                byte decodemask = 0;

                for(int k = (j == _topology[i].chipFrom ?
                             _topology[i].digitFrom : 0);
                     k <= (j == _topology[i].chipTo ? 
                          _topology[i].digitTo : 7); k++)
                    decodemask |= MAX7219_FLG_DIGIT0_CODEB << k;
                writeRegister(MAX7219_REG_DECODEMODE, decodemask, j);
            }
        clearDisplay(i);
    }
}
void MiniLed::setIntensityPct(int intensitePourcent)
{
	setIntensity( map(intensitePourcent,0,100,ledMin,ledMax) );
}