|
From: <mk...@us...> - 2003-07-03 08:25:41
|
Update of /cvsroot/csp/APPLICATIONS/CSPSim/Source
In directory sc8-pr-cvs1:/tmp/cvs-serv29438
Modified Files:
Sky.cpp
Log Message:
Index: Sky.cpp
===================================================================
RCS file: /cvsroot/csp/APPLICATIONS/CSPSim/Source/Sky.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** Sky.cpp 30 Jun 2003 22:27:57 -0000 1.16
--- Sky.cpp 3 Jul 2003 08:25:37 -0000 1.17
***************
*** 83,87 ****
* be computed over multiple frames.
*/
! //#define TEXDOME
--- 83,87 ----
* be computed over multiple frames.
*/
! #define NO_TEXDOME
***************
*** 188,192 ****
// TODO reimplement this as an osg::Geometry using a vertex list PrimitiveSet
! // and GL_POINTS (osgSim::osgLightPoint?). the current routine is called infrequently (the stars are
// rendered from a display list between updates), but requires a few ms to
// update the stars one at a time
--- 188,192 ----
// TODO reimplement this as an osg::Geometry using a vertex list PrimitiveSet
! // and GL_POINTS. the current routine is called infrequently (the stars are
// rendered from a display list between updates), but requires a few ms to
// update the stars one at a time
***************
*** 1184,1189 ****
ii = ci = 0;
! for( i = 0; i < m_nlev; ++i ) {
! for( j = 0; j < m_nseg; ++j ) {
alpha = osg::DegreesToRadians(m_lev[i]);
theta = osg::DegreesToRadians((float)(j*360.0/m_nseg));
--- 1184,1189 ----
ii = ci = 0;
! for( i = 0; i < m_nlev; i++ ) {
! for( j = 0; j < m_nseg; j++ ) {
alpha = osg::DegreesToRadians(m_lev[i]);
theta = osg::DegreesToRadians((float)(j*360.0/m_nseg));
***************
*** 1202,1209 ****
colors[ci][3] = 1.0;
! tcoords[ci][0] = 0.5f + std::min(0.5f, (90.0f - m_lev[i]) / 180.0f) * cosf(theta);
! tcoords[ci][1] = 0.5f + std::min(0.5f, (90.0f - m_lev[i]) / 180.0f) * sinf(theta);
! ++ci;
}
}
--- 1202,1209 ----
colors[ci][3] = 1.0;
! tcoords[ci][0] = (float)j/(float)(m_nseg-1);
! tcoords[ci][1] = (float)i/(float)(m_nlev-1);
! ci++;
}
}
***************
*** 1211,1222 ****
DrawElementsUShort* drawElements = new DrawElementsUShort(PrimitiveSet::TRIANGLE_STRIP);
drawElements->reserve(m_nlev*(m_nseg+1)*2);
! for (i = 0; i < m_nlev-1; ++i) {
! for (j = 0; j <= m_nseg; ++j) {
! drawElements->push_back((i+1)*m_nseg+(j%m_nseg));
! drawElements->push_back((i+0)*m_nseg+(j%m_nseg));
}
}
! m_SkyDome->setSupportsDisplayList(false);
! m_SkyDome->setUseDisplayList(false);
m_SkyDome->addPrimitiveSet(drawElements);
m_SkyDome->setVertexArray( &coords );
--- 1211,1221 ----
DrawElementsUShort* drawElements = new DrawElementsUShort(PrimitiveSet::TRIANGLE_STRIP);
drawElements->reserve(m_nlev*(m_nseg+1)*2);
! for (i = 0; i < m_nlev-1; i++) {
! for (j = 0; j <= m_nseg; j++) {
! drawElements->push_back((i+1)*m_nseg+j%m_nseg);
! drawElements->push_back((i+0)*m_nseg+j%m_nseg);
}
}
!
m_SkyDome->addPrimitiveSet(drawElements);
m_SkyDome->setVertexArray( &coords );
***************
*** 1228,1242 ****
if (1) {
Image *image = new Image();
image->allocateImage(64, 64, 1, GL_RGB, GL_UNSIGNED_BYTE);
assert(image->data() != NULL);
! memset(image->data(), 255, 64*64*3);
// setting the internal texture format is required, but
// its not clear how to determine the correct value. the
// following is just what the png loader does, setting
// the format to the number of color bytes.
! image->setInternalTextureFormat(GL_RGB);
Texture2D *tex = new Texture2D;
- tex->setDataVariance(osg::Object::DYNAMIC);
tex->setImage(image);
tex->setWrap(Texture::WRAP_S, Texture::CLAMP);
--- 1227,1242 ----
if (1) {
+ StateSet *dome_state = m_SkyDome->getOrCreateStateSet();
+ #ifdef TEXDOME
Image *image = new Image();
image->allocateImage(64, 64, 1, GL_RGB, GL_UNSIGNED_BYTE);
assert(image->data() != NULL);
! memset(image->data(), 0, 64*64*3);
// setting the internal texture format is required, but
// its not clear how to determine the correct value. the
// following is just what the png loader does, setting
// the format to the number of color bytes.
! image->setInternalTextureFormat(3);
Texture2D *tex = new Texture2D;
tex->setImage(image);
tex->setWrap(Texture::WRAP_S, Texture::CLAMP);
***************
*** 1248,1257 ****
tex->setUseHardwareMipMapGeneration(false);
tex->setUnRefImageDataAfterApply(false);
- tex->setInternalFormatMode(osg::Texture::USE_IMAGE_DATA_FORMAT);
m_SkyDomeTextureImage = image;
m_SkyDomeTexture = tex;
- StateSet *dome_state = m_SkyDome->getOrCreateStateSet();
dome_state->setTextureAttributeAndModes(0, m_SkyDomeTexture.get(), StateAttribute::ON);
dome_state->setTextureAttributeAndModes(0, new TexEnv);
dome_state->setMode(GL_LIGHTING, StateAttribute::OFF);
dome_state->setMode(GL_CULL_FACE, StateAttribute::OFF);
--- 1248,1256 ----
tex->setUseHardwareMipMapGeneration(false);
tex->setUnRefImageDataAfterApply(false);
m_SkyDomeTextureImage = image;
m_SkyDomeTexture = tex;
dome_state->setTextureAttributeAndModes(0, m_SkyDomeTexture.get(), StateAttribute::ON);
dome_state->setTextureAttributeAndModes(0, new TexEnv);
+ #endif
dome_state->setMode(GL_LIGHTING, StateAttribute::OFF);
dome_state->setMode(GL_CULL_FACE, StateAttribute::OFF);
***************
*** 1313,1317 ****
// TODO
! // take altitude into account for turbidity
// relate night sky color to moon brighness (and altitude)
// maybe modify SkyColor it consider moon position:
--- 1312,1316 ----
// TODO
! // take altitide into account for turbidity
// relate night sky color to moon brighness (and altitude)
// maybe modify SkyColor it consider moon position:
***************
*** 1362,1371 ****
float dark = m_Moon.getApparentBrightness();
osg::Vec4 horizon_average;
! for (i = 0; i < m_nlev; ++i) {
double elev = m_lev[i] * D2R;
if (elev < 0.0) elev = 0.0; // sub horizon colors aren't correct
double azimuth = -sun_A - 0.5 * G_PI;
bool at_vertex = fabs(elev - sun_h) < min_a; // this is only a rough measure
! for (j = 0; j < m_nseg; ++j) {
float intensity;
// if the sun lines up very close to a vertex, the vertex will be
--- 1361,1370 ----
float dark = m_Moon.getApparentBrightness();
osg::Vec4 horizon_average;
! for (i = 0; i < m_nlev; i++) {
double elev = m_lev[i] * D2R;
if (elev < 0.0) elev = 0.0; // sub horizon colors aren't correct
double azimuth = -sun_A - 0.5 * G_PI;
bool at_vertex = fabs(elev - sun_h) < min_a; // this is only a rough measure
! for (j = 0; j < m_nseg; j++) {
float intensity;
// if the sun lines up very close to a vertex, the vertex will be
***************
*** 1387,1391 ****
horizon_average += colors[ci];
}
! ++ci;
m_AverageIntensity += intensity;
}
--- 1386,1390 ----
horizon_average += colors[ci];
}
! ci++;
m_AverageIntensity += intensity;
}
***************
*** 1400,1403 ****
--- 1399,1403 ----
void Sky::_updateShading(double sun_h, double sun_A) {
Vec2Array& tex = *(dynamic_cast<Vec2Array*>(m_SkyDome->getTexCoordArray(0)));
+ Vec4Array& col = *(dynamic_cast<Vec4Array*>(m_SkyDome->getColorArray()));
int i, j;
***************
*** 1411,1422 ****
unsigned char *shade = m_SkyDomeTextureImage->data();
assert(shade);
! static unsigned char k = 128;
! ++k;
! unsigned int n = 2;
! //memset(shade, k, 3);
! for (j = 0; j < 64; ++j) {
int idx = (j * 64 + 32) * 3;
double y = (j-32) / 30.0;
! for (i = 0; i < 32; ++i) {
double x = i / 30.0;
double elevation = (1.0 - sqrt(x*x+y*y)) * 0.5 * G_PI;
--- 1411,1418 ----
unsigned char *shade = m_SkyDomeTextureImage->data();
assert(shade);
! for (j = 0; j < 64; j++) {
int idx = (j * 64 + 32) * 3;
double y = (j-32) / 30.0;
! for (i = 0; i < 32; i++) {
double x = i / 30.0;
double elevation = (1.0 - sqrt(x*x+y*y)) * 0.5 * G_PI;
***************
*** 1428,1434 ****
int i0 = idx + i*3 - 1;
int i1 = idx - i*3 - 1;
! shade[++i0] = shade[++i1] = k;//static_cast<unsigned char>(c.getA() * 255.0);
! shade[++i0] = shade[++i1] = 0;//static_cast<unsigned char>(c.getB() * 255.0);
! shade[++i0] = shade[++i1] = 0;//static_cast<unsigned char>(c.getC() * 255.0);
m_AverageIntensity += intensity;
++n_average;
--- 1424,1430 ----
int i0 = idx + i*3 - 1;
int i1 = idx - i*3 - 1;
! shade[++i0] = shade[++i1] = static_cast<unsigned char>(c.getA() * 255.0);
! shade[++i0] = shade[++i1] = static_cast<unsigned char>(c.getB() * 255.0);
! shade[++i0] = shade[++i1] = static_cast<unsigned char>(c.getC() * 255.0);
m_AverageIntensity += intensity;
++n_average;
***************
*** 1436,1448 ****
}
}
- //for (int i = 0; i < 64*64*3; i++) shade[i] = static_cast<unsigned char>((i/3) %256);
-
- /*int n = 0;
- for (i=0; i < 64*64*3;i += 3)
- if (shade[i] == k && shade[i+1] == k && shade[i+2] == k)
- ++n;
- std::cout << "\n" << n << " values are equal to " << k << "\n\n";*/
}
-
{ // separate evaluation for horizon colors
--- 1432,1436 ----
***************
*** 1450,1454 ****
double da = 2.0 * G_PI / n;
double azimuth = -sun_A - 0.5 * G_PI;
! for (i = 0; i < n; ++i) {
float intensity;
Color c = m_SkyShader.SkyColor(0.0, azimuth, dark, intensity);
--- 1438,1442 ----
double da = 2.0 * G_PI / n;
double azimuth = -sun_A - 0.5 * G_PI;
! for (i = 0; i < n; i++) {
float intensity;
Color c = m_SkyShader.SkyColor(0.0, azimuth, dark, intensity);
***************
*** 1457,1480 ****
}
}
!
{ // update texture coordinates
int ci = 0;
double da = 2.0 * G_PI / (m_nseg);
! for (i = 0; i < m_nlev; ++i) {
double elev = m_lev[i] * D2R;
if (elev < 0.0) elev = 0.0; // sub horizon colors aren't correct
double azimuth = -sun_A - 0.5 * G_PI;
float factor = (1.0 - 2.0 * elev / G_PI) * 30.0 / 32.0;
! for (j = 0; j < m_nseg; ++j) {
float x = 0.5 * (1.0 + sin(azimuth) * factor) + 0.5 / 64.0;
float y = 0.5 * (1.0 + cos(azimuth) * factor) + 0.5 / 64.0;
tex[ci][0] = x;
tex[ci][1] = y;
! ++ci;
azimuth += da;
}
}
}
-
simdata::SimTime u = simdata::SimDate::getSystemTime();
--- 1445,1467 ----
}
}
!
{ // update texture coordinates
int ci = 0;
double da = 2.0 * G_PI / (m_nseg);
! for (i = 0; i < m_nlev; i++) {
double elev = m_lev[i] * D2R;
if (elev < 0.0) elev = 0.0; // sub horizon colors aren't correct
double azimuth = -sun_A - 0.5 * G_PI;
float factor = (1.0 - 2.0 * elev / G_PI) * 30.0 / 32.0;
! for (j = 0; j < m_nseg; j++) {
float x = 0.5 * (1.0 + sin(azimuth) * factor) + 0.5 / 64.0;
float y = 0.5 * (1.0 + cos(azimuth) * factor) + 0.5 / 64.0;
tex[ci][0] = x;
tex[ci][1] = y;
! ci++;
azimuth += da;
}
}
}
simdata::SimTime u = simdata::SimDate::getSystemTime();
***************
*** 1486,1491 ****
m_SkyDomeTextureImage->dirty();
m_SkyDomeTexture->dirtyTextureObject();
- m_SkyDomeTexture->dirtyTextureParameters();
m_SkyDomeTexture->setImage(m_SkyDomeTextureImage.get());
}
#endif
--- 1473,1478 ----
m_SkyDomeTextureImage->dirty();
m_SkyDomeTexture->dirtyTextureObject();
m_SkyDomeTexture->setImage(m_SkyDomeTextureImage.get());
+ m_SkyDome->dirtyDisplayList();
}
#endif
***************
*** 1506,1510 ****
_updateSun();
// do a full moon update every 300 seconds (orbital position and lighting)
! if (fabs(m_JD - m_LastMoonFullUpdate) > 0.0000578705) {// = 1.15741e-5 * 5.0 // 300.0) {
m_LastMoonFullUpdate = m_JD;
_updateMoon(false);
--- 1493,1497 ----
_updateSun();
// do a full moon update every 300 seconds (orbital position and lighting)
! if (fabs(m_JD - m_LastMoonFullUpdate) > 1.15741e-5 * 5.0) { // 300.0) {
m_LastMoonFullUpdate = m_JD;
_updateMoon(false);
***************
*** 1538,1542 ****
osg::Vec4 color;
color = (*m_HorizonColors)[(idx-avg)%n] * (1.0-da);
! for (int i = 1-avg; i <= avg; ++i) {
color += (*m_HorizonColors)[(idx+i)%n];
}
--- 1525,1529 ----
osg::Vec4 color;
color = (*m_HorizonColors)[(idx-avg)%n] * (1.0-da);
! for (int i = 1-avg; i <= avg; i++) {
color += (*m_HorizonColors)[(idx+i)%n];
}
|