Lights following camera

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.

Lights following camera

Postby MaherGBR » Thu Jul 06, 2017 2:32 pm

Using EMF_LIGHTING = true, I'm trying to get the lights to move as the camera does, so there is always consistent lighting on my target. However, I can't for the life of me figure out why this isn't working: the lights remain constant to the scene, not the camera, so that any rotation around target produces a 'dark side' of shadow. Using the code:

cpp Code: Select all
irr::scene::ICameraSceneNode *cam = smgr->addCameraSceneNodeMaya(0, -1500.f, 200.f, 150.f, -1, 3.f, true);
// add lights
scene::ILightSceneNode* light1 =    smgr->addLightSceneNode(0, core::vector3df(100, 100, 100), video::SColorf(1.0f, 1.0f, 0.8f, 0.0f), 400.0f);
scene::ILightSceneNode* light2 =    smgr->addLightSceneNode(0, core::vector3df(100, 100, 100), video::SColorf(1.0f, 1.0f, 0.8f, 0.0f), 400.0f);
    if (device->isWindowActive())
        driver->beginScene(true, true, SColor(255, 100, 101, 140));        
        light1->setPosition(cam->getPosition() + core::vector3df(50, -50, 50)); //left side light
        light2->setPosition(cam->getPosition() + core::vector3df(-50, -50, 50)); //right side light

Any ideas what I'm doing wrong?

Posts: 2
Joined: Thu Jul 06, 2017 1:17 pm

Re: Lights following camera

Postby MartinVee » Thu Jul 06, 2017 3:19 pm

The first parameter of the addLightSceneNode is the parent node of the new node. By setting the parent node to 0, you're creating your light at the root node of the scene graph.

Just to be sure... Do you want the light to follow the model, or do you want the light to follow the camera? Note that if the camera follows the model at all time, these will have the same effect. Just change the first parameter of addLightSceneNode from 0 to cam or model. You may need to tweak the position as they're now relative to the parent's node.

If you're not familiar with the concept of a scene graph, you may want to read about it. Here's the wikipedia article and an article about it on GameDev.
User avatar
Posts: 126
Joined: Tue Aug 02, 2016 3:38 pm
Location: Québec, Canada

Re: Lights following camera

Postby CuteAlien » Tue Jul 11, 2017 11:03 am

Your light moves with the camera but doesn't rotate with it. You can calculate the rotation yourself (instead of a fixed vector like (50, -50, 50) you rotate that vector by the camera-rotation matrix) or you can do as MartinVee mentioned and use the scenegraph - set the camera as parent of the light and then you only have to call setPosition once with a relative distance to the camera and Irrlicht should update the rest.
IRC: #irrlicht on
Code snippets, patches&stuff:
Free racer created with Irrlicht:
User avatar
Posts: 8468
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Return to Beginners Help

Who is online

Users browsing this forum: Google [Bot] and 1 guest