Update of /cvsroot/csp/APPLICATIONS/CSPSim/Source
In directory sc8-pr-cvs1:/tmp/cvs-serv627/Source
Modified Files:
CSPSim.cpp Makefile.in ScreenInfo.cpp Sky.cpp
TerrainObject.cpp VirtualBattlefield.cpp
Log Message:
fixed moon billboard for high latitudes, restructured terrain node in scene in anticipation of shadow mapping
Index: CSPSim.cpp
===================================================================
RCS file: /cvsroot/csp/APPLICATIONS/CSPSim/Source/CSPSim.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** CSPSim.cpp 20 Feb 2003 09:53:47 -0000 1.7
--- CSPSim.cpp 21 Feb 2003 08:00:33 -0000 1.8
***************
*** 232,235 ****
--- 232,236 ----
//ao->AddSmoke();
+ /*
simdata::Pointer<DynamicObject> to = m_DataArchive->getObject("vehicles.aircraft.m2k");
assert(to.valid());
***************
*** 237,240 ****
--- 238,242 ----
to->addToScene(m_Battlefield);
m_Battlefield->addObject(to);
+ */
// create screens
Index: Makefile.in
===================================================================
RCS file: /cvsroot/csp/APPLICATIONS/CSPSim/Source/Makefile.in,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Makefile.in 19 Feb 2003 21:24:16 -0000 1.3
--- Makefile.in 21 Feb 2003 08:00:34 -0000 1.4
***************
*** 44,47 ****
--- 44,49 ----
ObjectRangeInfo.cpp \
Platform.cpp \
+ ScreenInfo.cpp \
+ ScreenInfoManager.cpp \
SimObject.cpp \
SimpleConfig.cpp \
Index: ScreenInfo.cpp
===================================================================
RCS file: /cvsroot/csp/APPLICATIONS/CSPSim/Source/ScreenInfo.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ScreenInfo.cpp 19 Feb 2003 23:02:59 -0000 1.1
--- ScreenInfo.cpp 21 Feb 2003 08:00:36 -0000 1.2
***************
*** 134,150 ****
ObjectStats::ObjectStats(int posx,int posy):ScreenInfo(posx,posy,"OBJECT STATS")
{
! simdata::Pointer<DynamicObject> activeObject = CSPSim::theSim->getActiveObject();
! if (!activeObject.isNull()) {
! std::vector<std::string> stringStats;
! activeObject->getStats(stringStats);
! for (unsigned short i = 0; i < stringStats.size(); ++i) {
! posy -= m_FontSize;
! osgText::Text* aStat = new osgText::Text(m_BitmapFont);
! aStat->setPosition(osg::Vec3(posx,posy,0));
! m_ObjectStats.push_back(aStat);
! addDrawable( aStat );
! }
! removeDrawable(m_Text);
}
};
--- 134,145 ----
ObjectStats::ObjectStats(int posx,int posy):ScreenInfo(posx,posy,"OBJECT STATS")
{
! for (unsigned short i = 0; i < 10; ++i) {
! posy -= m_FontSize;
! osgText::Text* aStat = new osgText::Text(m_BitmapFont);
! aStat->setPosition(osg::Vec3(posx,posy,0));
! m_ObjectStats.push_back(aStat);
! addDrawable( aStat );
}
+ removeDrawable(m_Text);
};
***************
*** 155,160 ****
std::vector<std::string> stringStats;
activeObject->getStats(stringStats);
! for (unsigned short i = 0; i < m_ObjectStats.size(); ++i)
! m_ObjectStats[i]->setText(stringStats[i]);
}
! }
\ No newline at end of file
--- 150,160 ----
std::vector<std::string> stringStats;
activeObject->getStats(stringStats);
! unsigned int n = m_ObjectStats.size();
! if (stringStats.size() < n) n = stringStats.size();
! for (unsigned short i = 0; i < n; ++i) {
! m_ObjectStats[i]->setText(stringStats[i]);
! // std::cout << stringStats[i] << std::endl;
! }
! // std::cout << stringStats.size() << std::endl;
}
! }
Index: Sky.cpp
===================================================================
RCS file: /cvsroot/csp/APPLICATIONS/CSPSim/Source/Sky.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Sky.cpp 21 Feb 2003 01:58:47 -0000 1.5
--- Sky.cpp 21 Feb 2003 08:00:38 -0000 1.6
***************
*** 351,361 ****
x = y*sin(A);
y *= cos(A);
! _updateLighting(x, y, z, color, intensity, background);
}
! void Sun::_updateLighting(float x, float y, float z, Color const &color, float intensity, float background) {
float specular_scale = 1.0;
float ambient = background;
if (ambient > 0.1) ambient = 0.1;
// ad-hoc additional darkening once the sun has set... the gl light
// representing the sun should not be as bright as the horizion.
--- 351,378 ----
x = y*sin(A);
y *= cos(A);
! _updateLighting(x, y, z, h, color, intensity, background);
}
! void Sun::_updateLighting(float x, float y, float z, float h, Color const &color, float intensity, float background) {
float specular_scale = 1.0;
float ambient = background;
if (ambient > 0.1) ambient = 0.1;
+
+ /* the first calculation of scale is somewhat physically based on
+ a plot of sunlight intensity versus angle in Preetham. the
+ ad-hoc one below seems better for compensating the limited
+ dynamic range of the monitor though, so this is currently
+ disabled. also, it has not been tested or tweaked.
+ float scale = 1.0;
+ {
+ // angle from zenith
+ float a = 1.0 - h / 0.5*G_PI;
+ a *= a;
+ scale = 1.0 - a*a;
+ float horizon_light = intensity*intensity * 25.0;
+ if (horizon_light > 1.0) horizon_light = 1.0;
+ if (horizon_light > scale) scale = horizon_light;
+ }
+ */
// ad-hoc additional darkening once the sun has set... the gl light
// representing the sun should not be as bright as the horizion.
***************
*** 461,474 ****
Vec3 to_eye(eye_local-pos_local);
Vec3 to_eye_projection = to_eye^_axis;
! float to_eye_projection_len = to_eye_projection.length();
! if (to_eye_projection_len != 0.0) {
! to_eye_projection /= to_eye_projection_len;
! Vec3 normal_projection(_normal^_axis);
! float normal_projection_len = normal_projection.length();
! if (normal_projection_len != 0.0f) {
! normal_projection /= normal_projection_len;
! float rotation_angle = acos(to_eye_projection*normal_projection);
! matrix.makeRotate(rotation_angle, normal_projection^to_eye_projection);
! }
}
matrix = _orient * matrix;
--- 478,485 ----
Vec3 to_eye(eye_local-pos_local);
Vec3 to_eye_projection = to_eye^_axis;
! if (to_eye_projection.normalize() > 0.0) {
! float rotation_angle = G_PI+acos(to_eye_projection*_onormal);
! Vec3 pivot = _onormal^to_eye_projection;
! matrix.makeRotate(rotation_angle, pivot);
}
matrix = _orient * matrix;
***************
*** 488,493 ****
_normal = up_ ^ (_normal ^ up_);
Vec3 rot = _axis ^ up_;
! _orient.makeRotate(-acos(up_*_axis), rot);
! _normal = _orient * _normal;
}
--- 499,509 ----
_normal = up_ ^ (_normal ^ up_);
Vec3 rot = _axis ^ up_;
! float angle = acos(up_*_axis);
! _orient.makeRotate(-angle, rot);
! Matrix inv;
! inv.makeRotate(angle, rot);
! _normal = inv * _normal;
! _onormal = _normal ^ _axis;
! _onormal.normalize();
}
***************
*** 495,500 ****
Moon::Moon(): AstronomicalBody() {
_radius = 1738000.0;
- // approximate distance for setting initial size
- //_distance = 384400000.0 - 6370000.0;
m_Latitude = -100.0;
m_DirtyImage = true;
--- 511,514 ----
***************
*** 507,511 ****
m_RenderDistance = 950000.0;
float x, y;
! x = y = 1.0; //_radius / _distance * m_RenderDistance;
m_Image = osgDB::readImageFile("moon.png");
assert(m_Image.valid());
--- 521,525 ----
m_RenderDistance = 950000.0;
float x, y;
! x = y = 1.0;
m_Image = osgDB::readImageFile("moon.png");
assert(m_Image.valid());
***************
*** 530,536 ****
bf->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA);
dstate->setAttributeAndModes(bf, osg::StateAttribute::ON);
- m_CM = new osg::ColorMatrix;
- m_CM->setMatrix(osg::Matrix(1.0,0,0,0,0,1.0,0,0,0,0,1.0,0,0,0,0,0.3));
- //dstate->setAttributeAndModes(m_CM.get(), osg::StateAttribute::OVERRIDE);
osg::Depth *depth = new osg::Depth;
depth->setFunction(osg::Depth::ALWAYS);
--- 544,547 ----
***************
*** 577,581 ****
m_Transform->setStateSet(dstate);
m_Transform->setCullingActive(false);
- //_maskPhase(0.785);
// moon->setStateSet(dstate);
}
--- 588,591 ----
Index: TerrainObject.cpp
===================================================================
RCS file: /cvsroot/csp/APPLICATIONS/CSPSim/Source/TerrainObject.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** TerrainObject.cpp 19 Feb 2003 12:25:23 -0000 1.6
--- TerrainObject.cpp 21 Feb 2003 08:00:39 -0000 1.7
***************
*** 179,183 ****
m_Battlefield = battlefield;
load();
- m_Battlefield->addNodeToScene(m_TerrainNode);
m_Battlefield->setActiveTerrain(this);
}
--- 179,182 ----
***************
*** 191,196 ****
if (m_Active) {
assert(m_Battlefield);
- m_Battlefield->removeNodeFromScene(m_TerrainNode);
- //m_Battlefield->removeNodeFromScene(m_TerrainLatticeNode.get());
m_Battlefield->setActiveTerrain(0);
m_Battlefield = NULL;
--- 190,193 ----
Index: VirtualBattlefield.cpp
===================================================================
RCS file: /cvsroot/csp/APPLICATIONS/CSPSim/Source/VirtualBattlefield.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** VirtualBattlefield.cpp 19 Feb 2003 23:00:32 -0000 1.7
--- VirtualBattlefield.cpp 21 Feb 2003 08:00:40 -0000 1.8
***************
*** 34,37 ****
--- 34,38 ----
#include <osgUtil/CullVisitor>
+ #include <osgUtil/DisplayListVisitor>
#include "Config.h"
***************
*** 43,46 ****
--- 44,48 ----
#include "Config.h"
#include "Platform.h"
+ #include "shadow.h"
#include <SimData/Types.h>
***************
*** 79,82 ****
--- 81,93 ----
float intensity_test = 0.0;
+ void setNVG(osg::ColorMatrix* cm) {
+ assert(cm);
+ // 0.212671*R + 0.71516*G + 0.072169*B;
+ cm->setMatrix(osg::Matrix(
+ 0.4*0.213, 1.0*0.213, 0.4*0.213, 0.0,
+ 0.4*0.715, 1.0*0.715, 0.4*0.715, 0.0,
+ 0.4*0.072, 1.0*0.072, 0.4*0.072, 0.0,
+ 0.0, 0.0, 0.0, 1.0));
+ }
void setCM(osg::ColorMatrix* cm, float intensity) {
***************
*** 246,250 ****
m_Sky = new Sky;
m_EyeTransform->addChild(m_Sky.get()); //makeSky()); // bin number -2 so drawn first.
- m_EyeTransform->addChild(makeBase()); // bin number -1 so draw second.
// add the transform to the earth sky.
--- 257,260 ----
***************
*** 284,288 ****
m_rpObjectRootNode->setStateSet(pFogState);
! m_rpRootNode->addChild(m_rpObjectRootNode.get());
// light group under EyeTransform for celestial bodies (sun, moon, etc)
--- 294,300 ----
m_rpObjectRootNode->setStateSet(pFogState);
! m_ShadowGroup = new osg::Group;
! m_ShadowGroup->addChild(m_rpObjectRootNode.get());
! m_rpRootNode->addChild(m_ShadowGroup.get());
// light group under EyeTransform for celestial bodies (sun, moon, etc)
***************
*** 297,305 ****
assert(globalStateSet);
-
osg::ColorMatrix* cm = new osg::ColorMatrix;
! setCM(cm, 0.0);
! //globalStateSet->setAttributeAndModes(cm, osg::StateAttribute::OVERRIDE);
! //m_pView->setGlobalStateSet(globalStateSet);
--- 309,317 ----
assert(globalStateSet);
osg::ColorMatrix* cm = new osg::ColorMatrix;
! //setNVG(cm);
! globalStateSet->setAttribute(cm);
! pFogState->setAttributeAndModes(cm, osg::StateAttribute::OVERRIDE);
! m_pView->setGlobalStateSet(globalStateSet);
***************
*** 341,349 ****
osgUtil::CullVisitor * pCullVisitor = m_pView->getCullVisitor();
! pCullVisitor->setComputeNearFarMode(osgUtil::CullVisitor::COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES);
! pCullVisitor->setCullingMode(osgUtil::CullVisitor::ENABLE_ALL_CULLING);
m_pView->setCullVisitor(pCullVisitor);
m_pView->update();
m_pView->cull();
m_pView->draw();
--- 353,364 ----
osgUtil::CullVisitor * pCullVisitor = m_pView->getCullVisitor();
! //pCullVisitor->setComputeNearFarMode(osgUtil::CullVisitor::COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES);
! //pCullVisitor->setCullingMode(osgUtil::CullVisitor::ENABLE_ALL_CULLING);
m_pView->setCullVisitor(pCullVisitor);
m_pView->update();
+ // segfaults... why?
+ //assert(pCullVisitor);
+ //m_TerrainNode->accept(*pCullVisitor);
m_pView->cull();
m_pView->draw();
***************
*** 390,396 ****
}
if (m_SpinTheWorld) m_Sky->spinTheWorld();
! //m_Sky->update(lat, lon, CSPSim::theSim->getCurrentTime());
// greenwich, england (for testing)
! m_Sky->update(0.8985, 0.0, CSPSim::theSim->getCurrentTime());
t+=1.0;
} else {
--- 405,411 ----
}
if (m_SpinTheWorld) m_Sky->spinTheWorld();
! m_Sky->update(lat, lon, CSPSim::theSim->getCurrentTime());
// greenwich, england (for testing)
! //m_Sky->update(0.8985, 0.0, CSPSim::theSim->getCurrentTime());
t+=1.0;
} else {
***************
*** 463,470 ****
pFogAttr->setStart(15000.0 + eyez + 15000.0*a);
pStateSet->setAttributeAndModes(pFogAttr ,osg::StateAttribute::ON);
! m_rpObjectRootNode->setStateSet(pStateSet);
}
! if (1)
{
static bool up = false;
--- 478,488 ----
pFogAttr->setStart(15000.0 + eyez + 15000.0*a);
pStateSet->setAttributeAndModes(pFogAttr ,osg::StateAttribute::ON);
! //osg::ColorMatrix* cm = (osg::ColorMatrix *) pStateSet->getAttribute(osg::StateAttribute::COLORMATRIX);
! //setNVG(cm);
! //pStateSet->setAttributeAndModes(cm ,osg::StateAttribute::OVERRIDE);
! m_ShadowGroup->setStateSet(pStateSet);
}
! if (0)
{
static bool up = false;
***************
*** 478,483 ****
osg::ColorMatrix* cm = (osg::ColorMatrix *) pStateSet->getAttribute(osg::StateAttribute::COLORMATRIX);
//setCM(cm, I*0.4);
! //pStateSet->setAttributeAndModes(cm ,osg::StateAttribute::OVERRIDE);
! //m_pView->setGlobalStateSet(pStateSet);
}
--- 496,502 ----
osg::ColorMatrix* cm = (osg::ColorMatrix *) pStateSet->getAttribute(osg::StateAttribute::COLORMATRIX);
//setCM(cm, I*0.4);
! setNVG(cm);
! pStateSet->setAttributeAndModes(cm ,osg::StateAttribute::OVERRIDE);
! m_pView->setGlobalStateSet(pStateSet);
}
***************
*** 524,533 ****
}
! void VirtualBattlefield::addNodeToScene( osg::Node * pNode)
{
CSP_LOG(CSP_APP, CSP_INFO, "VirtualBattlefield::addNodeToScene() - NodeName: " << pNode->getName() );
// osgUtil::Optimizer optimzer;
// optimzer.optimize(pNode, osgUtil::Optimizer::OptimizationOptions::ALL_OPTIMIZATIONS);
-
m_rpObjectRootNode->addChild(pNode);
}
--- 543,551 ----
}
! void VirtualBattlefield::addNodeToScene(osg::Node * pNode)
{
CSP_LOG(CSP_APP, CSP_INFO, "VirtualBattlefield::addNodeToScene() - NodeName: " << pNode->getName() );
// osgUtil::Optimizer optimzer;
// optimzer.optimize(pNode, osgUtil::Optimizer::OptimizationOptions::ALL_OPTIMIZATIONS);
m_rpObjectRootNode->addChild(pNode);
}
***************
*** 837,840 ****
--- 855,865 ----
void VirtualBattlefield::setActiveTerrain(TerrainObject *pTerrainObject)
{
+ if (pTerrainObject == 0) {
+ if (m_TerrainNode.valid()) {
+ m_ShadowGroup->removeChild(m_TerrainNode.get());
+ }
+ m_TerrainNode = NULL;
+ }
+
m_ActiveTerrainObject = pTerrainObject;
***************
*** 843,847 ****
if (!m_ActiveTerrainObject.isNull()) {
! m_ActiveTerrainObject->setCameraPosition( xPatch, yPatch, 1000);
}
--- 868,894 ----
if (!m_ActiveTerrainObject.isNull()) {
! m_ActiveTerrainObject->setCameraPosition(xPatch, yPatch, 1000);
! m_TerrainNode = m_ActiveTerrainObject->getNode();
! if (m_TerrainNode.valid()) {
! m_ShadowGroup->addChild(m_TerrainNode.get());
! #if 0
! osg::Group *g = new osg::Group;
! g->addChild(m_TerrainNode.get());
! m_ShadowGroup->addChild(g);
! //m_ShadowGroup->addChild(m_TerrainNode.get());
! osg::Vec4 ambientLightColor(0.9f,0.1f,0.1f,1.0f);
! int texture_unit = 2;
! ///osg::NodeCallback* cb = createCullCallback(m_rpObjectRootNode.get(),osg::Vec3(35000.0,51500.0,30000),ambientLightColor,texture_unit);
! ///g->setCullCallback(cb);
! /*
! g->setCullingActive(true);
! m_TerrainNode->setCullingActive(true);
! m_ShadowGroup->setCullingActive(true);
! m_rpRootNode->setCullingActive(true);
! */
! //printf("call=%p\n", cb);
! //printf("terr=%p, shad=%p, root=%p\n", m_TerrainNode.get(), m_ShadowGroup.get(), m_rpRootNode.get());
! #endif
! }
}
***************
*** 868,869 ****
--- 915,917 ----
return m_Sky->getSpin();
}
+
|