#include <simgear/math/sg_geodesy.hxx>
#include <simgear/math/sg_types.hxx>
#include <simgear/misc/texcoord.hxx>
+#include <simgear/scene/material/Effect.hxx>
+#include <simgear/scene/material/EffectGeode.hxx>
#include <simgear/scene/material/mat.hxx>
#include <simgear/scene/material/matlib.hxx>
+
#include <simgear/scene/util/VectorArrayAdapter.hxx>
using namespace simgear;
SGVec3f normals[latPoints][lonPoints];
SGVec3d rel[latPoints][lonPoints];
- point_list geod_nodes;
+ std::vector<SGGeod> geod_nodes;
osg::Vec3Array* vl;
osg::Vec3Array* nl;
VectorArrayAdapter<osg::Vec3Array> nlArray;
VectorArrayAdapter<osg::Vec2Array> tlArray;
- void calcMesh(const SGVec3d& cartCenter, double clon, double clat,
+ void calcMesh(const SGVec3d& cartCenter, const SGQuatd& orient,
+ double clon, double clat,
double height, double width, double tex_width);
void calcApronPt(int latIdx, int lonIdx, int latInner, int lonInner,
int destIdx, double tex_width);
};
}
-void OceanMesh::calcMesh(const SGVec3d& cartCenter, double clon, double clat,
+void OceanMesh::calcMesh(const SGVec3d& cartCenter, const SGQuatd& orient,
+ double clon, double clat,
double height, double width, double tex_width)
{
// Calculate vertices. By splitting the tile up into 4 quads on a
for (int i = 0; i < lonPoints; i++) {
geod[j][i] = SGGeod::fromDeg(startLon + i * longInc, lat);
SGVec3d cart = SGVec3d::fromGeod(geod[j][i]);
- rel[j][i] = cart - cartCenter;
- normals[j][i] = toVec3f(normalize(cart));
+ rel[j][i] = orient.transform(cart - cartCenter);
+ normals[j][i] = toVec3f(orient.transform(normalize(cart)));
}
}
// Calculate texture coordinates
- point_list geod_nodes(latPoints * lonPoints);
- VectorArrayAdapter<point_list> geodNodesArray(geod_nodes, lonPoints);
+ typedef std::vector<SGGeod> GeodVector;
+
+ GeodVector geod_nodes(latPoints * lonPoints);
+ VectorArrayAdapter<GeodVector> geodNodesArray(geod_nodes, lonPoints);
int_list rectangle(latPoints * lonPoints);
VectorArrayAdapter<int_list> rectArray(rectangle, lonPoints);
for (int j = 0; j < latPoints; j++) {
for (int i = 0; i < lonPoints; i++) {
- geodNodesArray(j, i) = Point3D(geod[j][i].getLongitudeDeg(),
- geod[j][i].getLatitudeDeg(),
- geod[j][i].getElevationM());
+ geodNodesArray(j, i) = geod[j][i];
rectArray(j, i) = j * 5 + i;
}
}
- point_list texs = sgCalcTexCoords( clat, geod_nodes, rectangle,
+
+ typedef std::vector<SGVec2f> Vec2Array;
+ Vec2Array texs = sgCalcTexCoords( clat, geod_nodes, rectangle,
1000.0 / tex_width );
- VectorArrayAdapter<point_list> texsArray(texs, lonPoints);
+
+
+ VectorArrayAdapter<Vec2Array> texsArray(texs, lonPoints);
for (int j = 0; j < latPoints; j++) {
for (int i = 0; i < lonPoints; ++i) {
- vlArray(j, i) = rel[j][i].osg();
- nlArray(j, i) = normals[j][i].osg();
- tlArray(j, i) = texsArray(j, i).toSGVec2f().osg();
+ vlArray(j, i) = toOsg(rel[j][i]);
+ nlArray(j, i) = toOsg(normals[j][i]);
+ tlArray(j, i) = toOsg(texsArray(j, i));
}
}
osg::Node* SGOceanTile(const SGBucket& b, SGMaterialLib *matlib)
{
- osg::StateSet *stateSet = 0;
+ Effect *effect = 0;
double tex_width = 1000.0;
tex_width = mat->get_xsize();
// set OSG State
- stateSet = mat->get_state();
+ effect = mat->get_effect();
} else {
SG_LOG( SG_TERRAIN, SG_ALERT, "Ack! unknown use material name = Ocean");
}
OceanMesh grid;
// Calculate center point
SGVec3d cartCenter = SGVec3d::fromGeod(b.get_center());
-
+ SGGeod geodPos = SGGeod::fromCart(cartCenter);
+ SGQuatd hlOr = SGQuatd::fromLonLat(geodPos)*SGQuatd::fromEulerDeg(0, 0, 180);
+
double clon = b.get_center_lon();
double clat = b.get_center_lat();
double height = b.get_height();
double width = b.get_width();
- grid.calcMesh(cartCenter, clon, clat, height, width, tex_width);
+ grid.calcMesh(cartCenter, hlOr, clon, clat, height, width, tex_width);
grid.calcApronPts(tex_width);
osg::Vec4Array* cl = new osg::Vec4Array;
+ 2 * (latPoints - 1)));
fillDrawElementsWithApron(latPoints, lonPoints, drawElements->begin());
geometry->addPrimitiveSet(drawElements);
- geometry->setStateSet(stateSet);
- osg::Geode* geode = new osg::Geode;
+ EffectGeode* geode = new EffectGeode;
geode->setName("Ocean tile");
+ geode->setEffect(effect);
geode->addDrawable(geometry);
+ geode->runGenerators(geometry);
osg::MatrixTransform* transform = new osg::MatrixTransform;
transform->setName("Ocean");
- transform->setMatrix(osg::Matrix::translate(cartCenter.osg()));
+ transform->setMatrix(osg::Matrix::rotate(toOsg(hlOr))*
+ osg::Matrix::translate(toOsg(cartCenter)));
transform->addChild(geode);
return transform;