[osg-users] [Re: to draw landscapes beginning from a matrix]
aurora restivo
aurora_re at tiscali.it
Mon Mar 3 02:45:34 PST 2008
Hi!
if I use a ShapeDrawable I get a figure with an only color, because
"draw -> setColor (...)" it doesn't allow me to color every altitude
osg::Geode* geode= new osg::Geode();
osg::ShapeDrawable* draw= new osg::ShapeDrawable(hF);
double highColor=1.0;
double lowColor=0.2;
double R=0.0, G=0.0, B=0.0;
for(int i=0; i< 410; i++)
{
for(int j=0; j<296 ;j++)
{
float altitude = hF->getHeight(j,i);
R =(highColor - lowColor) * ((altitude - min) / max)
+ lowColor;
G =(highColor - lowColor) * ((altitude - min) / max)
+ lowColor;
B =(highColor - lowColor) * ((altitude - min) / max)
+ lowColor;
draw->setColor(osg::Vec4(R,G,B,1.0));
}
}
geode->addDrawable(draw);
if I draw a TerrainNode with GeometryTechnique and use
terrainNode - > setColorTransferFunction (0, tf.get());
I get a figure with an only color if I use "tf -> allocate (1);"
otherwise, if I use "tf -> allocate (2);" I get a colored figure to two
zones, etc...
osg::ref_ptr<osg::TransferFunction1D> tf = new osg::TransferFunction1D;
tf->setInputRange(min, max); //minAltitude = 0, maxAltitude = 1400
tf->allocate(1);
//or tf->allocate(2);
for(int i=0; i< 410; i++)
{
for(int j=0; j<296 ;j++)
{
float altitude = hF->getHeight(j,i);
R =(highColor - lowColor) * ((altitude - min) / max)
+ lowColor;
G =(highColor - lowColor) * ((altitude - min) / max)
+ lowColor;
B =(highColor - lowColor) * ((altitude - min) / max)
+ lowColor;
tf->setValue(0, osg::Vec4(R,G,B,1.0));
//tf->setValue(1, osg::Vec4(1.0,0.0,1.0,1.0));
terrainNode->setColorTransferFunction(0, tf.get());
}
}
how can I color every altitude with different color?
I apologize for the trouble
Thanks
Aurora
Vincent Bourdier ha scritto:
> Hi Aurora,
>
> With his proposition, you can create the color that you need.
> Setcolor(vec4) uses RGBA (Red, Green, Blue, Alpha) color (if i
> remember well) so put A to 1.0 (opacity) , and the RGB can be defined
> using the function he gives to you... you can use it for each
> component if you want a greyscale color (R=G=B) or only use it on one
> component... try it and you will see...
>
> for greyscale image, you can try :
>
> hightcolor = 1.0
> lowcolor = 0.0
>
> and then
>
> R =(highColor - lowColor) * ((altitude - minAltitude) / maxAltitude) +
> lowColor;
> G =(highColor - lowColor) * ((altitude - minAltitude) / maxAltitude) +
> lowColor;
> B =(highColor - lowColor) * ((altitude - minAltitude) / maxAltitude) +
> lowColor;
>
> this is just a simple example...
>
> Regards,
>
> Vincent.
>
> 2008/2/29, aurora restivo <aurora_re at tiscali.it
> <mailto:aurora_re at tiscali.it>>:
>
> The Sukender ha scritto:
>> Hum... I don't have a global solution, but you may set a color for each vertex with something lile :
>> color = (highColor - lowColor) * ((altitude - minAltitude) / maxAltitude) + lowColor;
>>
>
>
>
> I apologize but I am still inexperienced.
>
> I have a HeightField associated to shapeDrawable (this because if
> I use Locator and GeometryTechnique I succeed in visualizing the
> alone ground "GEOCENTRIC"),
> therefore if I use
>
> shapeDrawable - > setColor (Vec4);
>
> I don't know whether to plan the values of the Vec4 with the
> formula that you have sent me
>
> besides of what type it is color?
>
> Aurora
>
>
>
>> You can allso do it in HSL coordinates (instead of RGB).
>>
>> Sukender
>>
>> ----------------------------------------
>>
>>> Date: Fri, 29 Feb 2008 12:54:48 +0100
>>> From: aurora_re at tiscali.it <mailto:aurora_re at tiscali.it>
>>> To: osg-users at lists.openscenegraph.org <mailto:osg-users at lists.openscenegraph.org>
>>>
>>> Subject: Re: [osg-users] [Fwd: Re: to draw landscapes beginning from a matrix]
>>>
>>> Hi!
>>>
>>> does a way exists to color from the tallest altitude of a ground to the
>>> lowest with gradations of color?
>>>
>>> thanks
>>>
>>> Aurora
>>>
>>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080303/0c823392/attachment.html
More information about the osg-users
mailing list