Minor cleanup of Stuart Buchanan's tree patch.
Separate random objects and random trees for real.
This commit is contained in:
@@ -22,7 +22,6 @@
|
|||||||
#include <osgDB/Registry>
|
#include <osgDB/Registry>
|
||||||
#include <osgDB/Input>
|
#include <osgDB/Input>
|
||||||
#include <osgDB/ParameterOutput>
|
#include <osgDB/ParameterOutput>
|
||||||
#include <simgear/screen/extensions.hxx>
|
|
||||||
|
|
||||||
#include "ShaderGeometry.hxx"
|
#include "ShaderGeometry.hxx"
|
||||||
|
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ osg::Geometry* createOrthQuads(float w, float h, int varieties, const osg::Matri
|
|||||||
"\n"
|
"\n"
|
||||||
"void main(void)\n"
|
"void main(void)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" texcoord = gl_MultiTexCoord0.st + vec2(textureIndex, 0.0);\n"
|
" texcoord = gl_MultiTexCoord0.st + vec2(textureIndex, 0.0);\n"
|
||||||
" vec3 position = gl_Vertex.xyz * gl_Color.w + gl_Color.xyz;\n"
|
" vec3 position = gl_Vertex.xyz * gl_Color.w + gl_Color.xyz;\n"
|
||||||
" gl_Position = gl_ModelViewProjectionMatrix * vec4(position,1.0);\n"
|
" gl_Position = gl_ModelViewProjectionMatrix * vec4(position,1.0);\n"
|
||||||
" vec3 ecPosition = vec3(gl_ModelViewMatrix * vec4(position, 1.0));\n"
|
" vec3 ecPosition = vec3(gl_ModelViewMatrix * vec4(position, 1.0));\n"
|
||||||
@@ -261,9 +261,9 @@ osg::Group* createForest(TreeBin& forest, const osg::Matrix& transform)
|
|||||||
// Don´t track vertex color
|
// Don´t track vertex color
|
||||||
material->setColorMode(Material::OFF);
|
material->setColorMode(Material::OFF);
|
||||||
material->setAmbient(Material::FRONT_AND_BACK,
|
material->setAmbient(Material::FRONT_AND_BACK,
|
||||||
Vec4(.6f, .6f, .6f, 1.0f));
|
Vec4(.8f, .8f, .8f, 1.0f));
|
||||||
material->setDiffuse(Material::FRONT_AND_BACK,
|
material->setDiffuse(Material::FRONT_AND_BACK,
|
||||||
Vec4(.4f, .4f, .4f, 1.0f));
|
Vec4(.2f, .2f, .2f, 1.0f));
|
||||||
}
|
}
|
||||||
stateset->setAttributeAndModes(alphaFunc.get());
|
stateset->setAttributeAndModes(alphaFunc.get());
|
||||||
stateset->setAttribute(program.get());
|
stateset->setAttribute(program.get());
|
||||||
|
|||||||
+35
-37
@@ -592,7 +592,7 @@ SGLoadBTG(const std::string& path, SGMaterialLib *matlib, bool calc_lights, bool
|
|||||||
if (node)
|
if (node)
|
||||||
terrainGroup->addChild(node);
|
terrainGroup->addChild(node);
|
||||||
|
|
||||||
if (use_random_objects) {
|
if (use_random_objects || use_random_vegetation) {
|
||||||
|
|
||||||
// Simple matrix for used for flipping models that have been oriented
|
// Simple matrix for used for flipping models that have been oriented
|
||||||
// with the center of the tile but upside down.
|
// with the center of the tile but upside down.
|
||||||
@@ -608,49 +608,47 @@ SGLoadBTG(const std::string& path, SGMaterialLib *matlib, bool calc_lights, bool
|
|||||||
osg::Matrix mAtt = flip * osg::Matrix::rotate(hlOr.osg());
|
osg::Matrix mAtt = flip * osg::Matrix::rotate(hlOr.osg());
|
||||||
// The inverse goes from world coordinates to Z up tile coordinates.
|
// The inverse goes from world coordinates to Z up tile coordinates.
|
||||||
osg::Matrix world2Tile(osg::Matrix(hlOr.osg().conj()) * flip);
|
osg::Matrix world2Tile(osg::Matrix(hlOr.osg().conj()) * flip);
|
||||||
|
|
||||||
tileGeometryBin.computeRandomObjects(matlib);
|
if (use_random_objects) {
|
||||||
|
tileGeometryBin.computeRandomObjects(matlib);
|
||||||
|
|
||||||
if (tileGeometryBin.randomModels.getNumModels() > 0) {
|
if (tileGeometryBin.randomModels.getNumModels() > 0) {
|
||||||
// Generate a repeatable random seed
|
// Generate a repeatable random seed
|
||||||
mt seed;
|
mt seed;
|
||||||
mt_init(&seed, unsigned(123));
|
mt_init(&seed, unsigned(123));
|
||||||
|
|
||||||
std::vector<ModelLOD> models;
|
std::vector<ModelLOD> models;
|
||||||
for (unsigned int i = 0; i < tileGeometryBin.randomModels.getNumModels(); i++) {
|
for (unsigned int i = 0;
|
||||||
SGMatModelBin::MatModel obj = tileGeometryBin.randomModels.getMatModel(i);
|
i < tileGeometryBin.randomModels.getNumModels(); i++) {
|
||||||
osg::Node* node = sgGetRandomModel(obj.model);
|
SGMatModelBin::MatModel obj
|
||||||
|
= tileGeometryBin.randomModels.getMatModel(i);
|
||||||
|
osg::Node* node = sgGetRandomModel(obj.model);
|
||||||
|
|
||||||
// Create a matrix to place the object in the correct location, and then
|
// Create a matrix to place the object in the correct
|
||||||
// apply the rotation matrix created above, with an additional random
|
// location, and then apply the rotation matrix created
|
||||||
// heading rotation if appropriate.
|
// above, with an additional random heading rotation if appropriate.
|
||||||
osg::Matrix mPos = osg::Matrix::translate(obj.position.osg());
|
osg::Matrix transformMat(mAtt);
|
||||||
osg::MatrixTransform* position;
|
transformMat.postMult(osg::Matrix::translate(obj.position.osg()));
|
||||||
|
if (obj.model->get_heading_type() == SGMatModel::HEADING_RANDOM) {
|
||||||
if (obj.model->get_heading_type() == SGMatModel::HEADING_RANDOM) {
|
// Rotate the object around the z axis.
|
||||||
// Rotate the object around the z axis.
|
double hdg = mt_rand(&seed) * M_PI * 2;
|
||||||
double hdg = mt_rand(&seed) * M_PI * 2;
|
transformMat.preMult(osg::Matrix::rotate(hdg,
|
||||||
osg::Matrix rot(cos(hdg), -sin(hdg), 0, 0,
|
osg::Vec3d(0.0, 0.0, 1.0)));
|
||||||
sin(hdg), cos(hdg), 0, 0,
|
}
|
||||||
0, 0, 1, 0,
|
osg::MatrixTransform* position =
|
||||||
0, 0, 0, 1);
|
new osg::MatrixTransform(transformMat);
|
||||||
position = new osg::MatrixTransform(rot * mAtt * mPos);
|
position->addChild(node);
|
||||||
} else {
|
models.push_back(ModelLOD(position, obj.lod));
|
||||||
position = new osg::MatrixTransform(mAtt * mPos);
|
|
||||||
}
|
}
|
||||||
|
RandomObjectsQuadtree quadtree((GetModelLODCoord(world2Tile)),
|
||||||
position->addChild(node);
|
(AddModelLOD()));
|
||||||
models.push_back(ModelLOD(position, obj.lod));
|
quadtree.buildQuadTree(models.begin(), models.end());
|
||||||
|
randomObjects = quadtree.getRoot();
|
||||||
|
randomObjects->setName("random objects");
|
||||||
}
|
}
|
||||||
RandomObjectsQuadtree quadtree((GetModelLODCoord(world2Tile)),
|
|
||||||
(AddModelLOD()));
|
|
||||||
quadtree.buildQuadTree(models.begin(), models.end());
|
|
||||||
randomObjects = quadtree.getRoot();
|
|
||||||
randomObjects->setName("random objects");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (use_random_vegetation)
|
if (use_random_vegetation) {
|
||||||
{
|
|
||||||
// Now add some random forest.
|
// Now add some random forest.
|
||||||
tileGeometryBin.computeRandomForest(matlib);
|
tileGeometryBin.computeRandomForest(matlib);
|
||||||
|
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ enum NodeMask {
|
|||||||
// Normal opaque objects are assigned bin 0.
|
// Normal opaque objects are assigned bin 0.
|
||||||
//
|
//
|
||||||
// Random objects like trees may have transparency, but there are too
|
// Random objects like trees may have transparency, but there are too
|
||||||
// many to depth sort. By drawing them after the terrain we can at
|
// many to depth sort individually. By drawing them after the terrain
|
||||||
// least keep the sky under the ground from poking through.
|
// we can at least keep the sky under the ground from poking through.
|
||||||
//
|
//
|
||||||
// Point lights blend with the terrain to simulate attenuation but
|
// Point lights blend with the terrain to simulate attenuation but
|
||||||
// should completely obscure any transparent geometry behind
|
// should completely obscure any transparent geometry behind
|
||||||
|
|||||||
Reference in New Issue
Block a user