how do I make the light always hit the front of the camera?

77 views
Skip to first unread message

newli...@gmail.com

unread,
Mar 9, 2021, 2:04:55 AM3/9/21
to OpenSceneGraph Users
Hello Community,

I am to ask you for some hints, tips for light. 

As in the photo below, I made the light appear in front of the eyepoint by adjusting the direction of the light.
I want to implement the rotation of the light 360 degrees along the heding in the current state. How do I do this?

In other words, how do I make the light always hit the front of the camera?

Thanks for the help!light.png

Robert Osfield

unread,
Mar 9, 2021, 3:12:42 AM3/9/21
to OpenSceneGraph Users, OpenSceneGraph Users
Hi ?

You don't say how you are rendering your present lights so providing guidance on how to adjust it isn't possible, you'll need to provide more information about your render system and what it relies upon for controlling the position and direction of the light.

Also it's hard to understand what you mean.  Rotating something by 360 degrees takes it full circle and back to where it was originally - so this bit makes no sense whatsoever.

The light in the scene looks to be a spot light pointing downwards, pointing that back towards the camera would be a 90 degree rotation, but pointing a spotlight at the camera would be pretty odd.  Could you mean something completely different from what you are saying?

Robert.

newli...@gmail.com

unread,
Mar 9, 2021, 7:23:30 PM3/9/21
to OpenSceneGraph Users
Hi, Robert .
First of all, thank you for your interest and answer.

I'm rendering using osg::Light and osg::LightSource with a spotlight pointing down.

The exact position is set using light->setPosition()

The direction of the light is set with the code below.

     osg::vec3d world =world + osg::Vec3d(0.0, 0.0, -0.6)
     light->setDirection(-world)

However, if the camera's heading is rotated in the current implementation, the light currently being rendered in front is stopped at the position and only the camera rotates.

I want to rotate the position of the light along with the heading of the camera.
However, if you adjust the Direction value to rotate the position of the light, the rendered position will be distorted without rotating as desired.

So, I tried various things using the code below, but I didn't get the desired result.

osg::PositionAttitudeTransform *_pat = new osg::PositionAttitudeTransform();
osg::Quat ori =  osg::Quat(osg::DegreesToRadians(0.0), osg::Vec3(0, 1, 0)) *
                            osg::Quat(osg::DegreesToRadians(0.0), osg::Vec3(1, 0, 0)) *
                            osg::Quat(osg::DegreesToRadians(heading_value), osg::Vec3(0, 0, 1));
_pat->setAttitude(ori);

Is there a good way to adjust the position of the light like a camera?

2021년 3월 9일 화요일 오후 5시 12분 42초 UTC+9에 robert....@gmail.com님이 작성:

Robert Osfield

unread,
Mar 10, 2021, 3:48:47 AM3/10/21
to OpenSceneGraph Users, OpenSceneGraph Users
If you want a light positioned relative to View's Camera then this is what the OSG provides by default.  You can probably just remove the LightSource from the scene graph and rely upon it's settings.  In include/osg/View you'll find:

       /** Options for controlling the global lighting used for the view.*/
        enum LightingMode
        {
            NO_LIGHT,
            HEADLIGHT,
            SKY_LIGHT
        };

        /** Set the global lighting to use for this view.
          * Defaults to headlight. */
        void setLightingMode(LightingMode lightingMode);

        /** Get the global lighting used for this view.*/
        LightingMode getLightingMode() const { return _lightingMode; }

        /** Get the global light.*/
        void setLight(osg::Light* light) { _light = light; }

        /** Get the global lighting if assigned.*/
        osg::Light* getLight() { return _light.get(); }

        /** Get the const global lighting if assigned.*/
        const osg::Light* getLight() const { return _light.get(); }

The vsgViewer::View class subclasses from osg::View, and osgViewer::Viewer subclasses from osgViewer::View, so all the above methods are also available via viewer.setLightingMode(..) etc.
Reply all
Reply to author
Forward
0 new messages