double depthRed, depthGreen, depthBlue;
for( int distance = 0; distance <= 255; distance ++ )
{
if( distance <= 42.5 )
{
depthRed = 0.0;
depthGreen = 0.0;
depthBlue = distance * 6.0;
}else
if( distance > 42.5 && distance <= 85.0 )
{
depthRed = 0.0;
depthGreen = (distance - 42.5) * 6;
depthBlue = 255.0;
}else
if( distance > 85.0 && distance <= 127.5 )
{
depthRed = 0.0;
depthGreen = 255.0;
depthBlue = 255.0 - (distance - 85.0) * 6;
}else
if( distance > 127.5 && distance <= 170.0 )
{
depthRed = (distance - 127.5) * 6;
depthGreen = 255.0;
depthBlue = 0.0;
}else
if( distance > 170.0 && distance <= 212.5 )
{
depthRed = 255.0;
depthGreen = 255.0 - (distance - 170.0) * 6;
depthBlue = 0.0;
}else
if( distance > 212.5 )
{
depthRed = 255.0;
depthGreen = (distance - 212.5) * 5 ;
depthBlue = (distance - 212.5) * 5;
}
}
效果如下:
这里是另一种颜色变换方式:
http://www.pages.drexel.edu/~nk752/depthMapTut.html#Step%204