- // Create a matrix to place the object in the correct location, and then
- // apply the rotation matrix created above, with an additional random
- // heading rotation if appropriate.
- osg::Matrix mPos = osg::Matrix::translate(obj.position.osg());
- osg::MatrixTransform* position;
-
- if (obj.model->get_heading_type() == SGMatModel::HEADING_RANDOM) {
- // Rotate the object around the z axis.
- double hdg = mt_rand(&seed) * M_PI * 2;
- osg::Matrix rot(cos(hdg), -sin(hdg), 0, 0,
- sin(hdg), cos(hdg), 0, 0,
- 0, 0, 1, 0,
- 0, 0, 0, 1);
- position = new osg::MatrixTransform(rot * mAtt * mPos);
- } else {
- position = new osg::MatrixTransform(mAtt * mPos);
+ // Create a matrix to place the object in the correct
+ // location, and then apply the rotation matrix created
+ // above, with an additional random heading rotation if appropriate.
+ osg::Matrix transformMat;
+ transformMat = osg::Matrix::translate(obj.position.osg());
+ if (obj.model->get_heading_type() == SGMatModel::HEADING_RANDOM) {
+ // Rotate the object around the z axis.
+ double hdg = mt_rand(&seed) * M_PI * 2;
+ transformMat.preMult(osg::Matrix::rotate(hdg,
+ osg::Vec3d(0.0, 0.0, 1.0)));
+ }
+ osg::MatrixTransform* position =
+ new osg::MatrixTransform(transformMat);
+ position->addChild(node);
+ models.push_back(ModelLOD(position, obj.lod));