Example #1
0
void Window::moveLight(SDLKey sdlKey)
{
    Vec4 p = getLightPos();
    switch (sdlKey) {
        case SDLK_LEFT:
            p[0] -= 0.1f;
            break;
        case SDLK_RIGHT:
            p[0] += 0.1f;
            break;
        case SDLK_UP:
            p[1] += 0.1f;
            break;
        case SDLK_DOWN:
            p[1] -= 0.1f;
            break;
        case SDLK_PAGEUP:
            p[2] += 0.1f;
            break;
        case SDLK_PAGEDOWN:
            p[2] -= 0.1f;
            break;
    }
    setLightPos(p);
    glLightfv(GL_LIGHT0, GL_POSITION, p.ptr());
    cout << "GL_LIGHT0 position: " << p << endl;
}
Example #2
0
EffectSpriteLamp::EffectSpriteLamp()
{
    if (ShaderTestDemo2::init()) {
        
        auto s = Director::getInstance()->getWinSize();
        _sprite = EffectSprite::create("Images/elephant1_Diffuse.png");
        //auto contentSize = _sprite->getContentSize();
        _sprite->setPosition(Vec2(s.width/2, s.height/2));
        addChild(_sprite);
        
        auto lampEffect = EffectNormalMapped::create("Images/elephant1_Normal.png");
        
        Vec3 pos(150,150, 50);
        _lightSprite = Sprite::create("Images/ball.png");
        this->addChild(_lightSprite);
        _lightSprite->setPosition(Vec2(pos.x, s.height- pos.y));
        Mat4 mat = _sprite->getNodeToWorldTransform();
        Point lightPosInLocalSpace=PointApplyAffineTransform(Vec2(pos.x, pos.y),_sprite->worldToNodeTransform());
        lampEffect->setLightColor(Color4F(1,1,1,1));
        lampEffect->setLightPos(Vec3(lightPosInLocalSpace.x, lightPosInLocalSpace.y, 50));
        lampEffect->setKBump(2);
        _sprite->setEffect(lampEffect);
        _effect = lampEffect;
        auto listerner = EventListenerTouchAllAtOnce::create();
        listerner->onTouchesBegan = CC_CALLBACK_2(EffectSpriteLamp::onTouchesBegan, this);
        listerner->onTouchesMoved = CC_CALLBACK_2(EffectSpriteLamp::onTouchesMoved, this);
        listerner->onTouchesEnded = CC_CALLBACK_2(EffectSpriteLamp::onTouchesEnded, this);
        _eventDispatcher->addEventListenerWithSceneGraphPriority(listerner, this);
    }
}
Example #3
0
void display(void)
{
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

  /* ビュー変換 */
  glLoadIdentity();
  glTranslatef(0.0, 0.0, viewxform_z);

  if ( trackballMove ){
    glPushMatrix();
    glLoadIdentity();
    glRotatef( angle, axis[0], axis[1], axis[2] );
    glMultMatrixf( (GLfloat*)trackballXform );
    glGetFloatv( GL_MODELVIEW_MATRIX, trackballXform );
    glPopMatrix();
  }

  glPushMatrix();
  glMultMatrixf( (GLfloat*)lightXform );
  setLightPos();
  glPopMatrix();
  glPushMatrix();

  glMultMatrixf( (GLfloat*)objectXform );
  colorcube();
  glPopMatrix();
  glutSwapBuffers();
}
void LightParameterWidget::connectRender( VolumeLightingRender* pRender )
{
	ui.sb_ambient->setValue(pRender->ka());
	ui.sb_diffuse->setValue(pRender->kd());
	ui.sb_specular->setValue(pRender->ks());
	ui.sb_shininess->setValue(pRender->shininess());
	Vector3f lp = pRender->lightPosition();
	ui.lp_x->setValue(lp.x);
	ui.lp_y->setValue(lp.y);
	ui.lp_z->setValue(lp.z);
	connect(ui.sb_ambient, SIGNAL(valueChanged(double)), pRender, SLOT(setKa(double)));
	connect(ui.sb_diffuse, SIGNAL(valueChanged(double)), pRender, SLOT(setKd(double)));
	connect(ui.sb_specular, SIGNAL(valueChanged(double)), pRender, SLOT(setKs(double)));
	connect(ui.sb_shininess, SIGNAL(valueChanged(double)), pRender, SLOT(setShininess(double)));
	connect(this, SIGNAL(lightPositionChanged(Vector3d)), pRender, SLOT(setLightPos(Vector3d)));
	connect(ui.cb_shader, SIGNAL(currentIndexChanged(int)), pRender, SLOT(setRenderMode(int)));
	connect(ui.cb_gradient, SIGNAL(currentIndexChanged(int)), pRender, SLOT(setGradientMode(int)));
}