// it may be superfluous for such a small mesh.
namespace
{
-const int lonPoints = 5;
-const int latPoints = 5;
-
class OceanMesh {
public:
- OceanMesh():
+ OceanMesh(int latP, int lonP):
+ latPoints(latP),
+ lonPoints(lonP),
geoPoints(latPoints * lonPoints + 2 * (lonPoints + latPoints)),
geod_nodes(latPoints * lonPoints),
vl(new osg::Vec3Array(geoPoints)),
nlArray(*nl, lonPoints + 2, lonPoints, 1),
tlArray(*tl, lonPoints + 2, lonPoints, 1)
{
+ int numPoints = latPoints * lonPoints;
+ geod = new SGGeod[numPoints];
+ normals = new SGVec3f[numPoints];
+ rel = new SGVec3d[numPoints];
}
+
+ ~OceanMesh()
+ {
+ delete[] geod;
+ delete[] normals;
+ delete[] rel;
+ }
+
+ const int latPoints, lonPoints;
const int geoPoints;
- SGGeod geod[latPoints][lonPoints];
- SGVec3f normals[latPoints][lonPoints];
- SGVec3d rel[latPoints][lonPoints];
+ SGGeod* geod;
+ SGVec3f* normals;
+ SGVec3d* rel;
std::vector<SGGeod> geod_nodes;
for (int j = 0; j < latPoints; j++) {
double lat = startLat + j * latInc;
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] = orient.transform(cart - cartCenter);
- normals[j][i] = toVec3f(orient.transform(normalize(cart)));
+ int index = (j * lonPoints) + i;
+ geod[index] = SGGeod::fromDeg(startLon + i * longInc, lat);
+ SGVec3d cart = SGVec3d::fromGeod(geod[index]);
+ rel[index] = orient.transform(cart - cartCenter);
+ normals[index] = toVec3f(orient.transform(normalize(cart)));
}
}
VectorArrayAdapter<int_list> rectArray(rectangle, lonPoints);
for (int j = 0; j < latPoints; j++) {
for (int i = 0; i < lonPoints; i++) {
- geodNodesArray(j, i) = geod[j][i];
- rectArray(j, i) = j * 5 + i;
+ int index = (j * lonPoints) + i;
+ geodNodesArray(j, i) = geod[index];
+ rectArray(j, i) = index;
}
}
for (int j = 0; j < latPoints; j++) {
for (int i = 0; i < lonPoints; ++i) {
- vlArray(j, i) = toOsg(rel[j][i]);
- nlArray(j, i) = toOsg(normals[j][i]);
+ int index = (j * lonPoints) + i;
+ vlArray(j, i) = toOsg(rel[index]);
+ nlArray(j, i) = toOsg(normals[index]);
tlArray(j, i) = toOsg(texsArray(j, i));
}
}
}
}
-osg::Node* SGOceanTile(const SGBucket& b, SGMaterialLib *matlib)
+osg::Node* SGOceanTile(const SGBucket& b, SGMaterialLib *matlib, int latPoints, int lonPoints)
{
Effect *effect = 0;
} else {
SG_LOG( SG_TERRAIN, SG_ALERT, "Ack! unknown use material name = Ocean");
}
- OceanMesh grid;
+ OceanMesh grid(latPoints, lonPoints);
// Calculate center point
SGVec3d cartCenter = SGVec3d::fromGeod(b.get_center());
SGGeod geodPos = SGGeod::fromCart(cartCenter);