OSG SpotLight高度

问题描述 投票:0回答:1

我目前正在与OSGEarth合作,我想在海上创建一个带灯的浮标。

这个想法是使用OSG :: light创建一个简单的聚光灯。

然后,我可以根据地球的纬度和经度来设置它的位置,但是我不能设置光的高度/ z。光源始终处于z = 0位置。

    GeoPoint point(geosrs, 8.91879, 44.4039, 10, ALTMODE_ABSOLUTE);     
    point.toWorld(world);

    osg::Light* spot = new osg::Light(lightNum++);
    spot->setPosition(worldToVec4(world));
    spot->setAmbient(osg::Vec4(1, 0, 0, 1));
    spot->setDiffuse(osg::Vec4(1, 0, 0, 1));
    spot->setSpotCutoff(15);//20
    spot->setSpotExponent(10.0f);

    // point straight down at the map:
    world.normalize();
    spot->setDirection(-world);

    osg::LightSource* spotLS = new osg::LightSource();
    spotLS->setLight(spot);

    lights->addChild(spotLS);

where

osg::Vec4 worldToVec4(const osg::Vec3d& ecef){
osg::Vec4 result(0.0f, 0.0f, 0.0f, 1.0f);
osg::Vec3d d = ecef;
while (d.length() > 1e6)
{
    d *= 0.1;
    result.w() *= 0.1;
}
return osg::Vec4(d.x(), d.y(), d.z(), result.w());
}

我认为问题与从lat / lon / alt转换为Vec4有关。

感谢您的关注。

c++ light openscenegraph spotlight osgearth
1个回答
0
投票

此代码看起来(大部分)是从osgearth_lights示例中借来的。您如何确定光线始终在z = 0处?

© www.soinside.com 2019 - 2024. All rights reserved.