/usr/share/openscenegraph/examples/osgbillboard/osgbillboard.cpp is in openscenegraph-examples 3.2.0~rc1-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | /* OpenSceneGraph example, osgbillboard.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <osg/Node>
#include <osg/Geometry>
#include <osg/Notify>
#include <osg/MatrixTransform>
#include <osg/Texture2D>
#include <osg/Billboard>
#include <osg/LineWidth>
#include <osgGA/TrackballManipulator>
#include <osgGA/FlightManipulator>
#include <osgGA/DriveManipulator>
#include <osgDB/Registry>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
//
// A simple demo demonstrating different texturing modes,
// including using of texture extensions.
//
typedef std::vector< osg::ref_ptr<osg::Image> > ImageList;
/** create quad at specified position. */
osg::Drawable* createSquare(const osg::Vec3& corner,const osg::Vec3& width,const osg::Vec3& height, osg::Image* image=NULL)
{
// set up the Geometry.
osg::Geometry* geom = new osg::Geometry;
osg::Vec3Array* coords = new osg::Vec3Array(4);
(*coords)[0] = corner;
(*coords)[1] = corner+width;
(*coords)[2] = corner+width+height;
(*coords)[3] = corner+height;
geom->setVertexArray(coords);
osg::Vec3Array* norms = new osg::Vec3Array(1);
(*norms)[0] = width^height;
(*norms)[0].normalize();
geom->setNormalArray(norms, osg::Array::BIND_OVERALL);
osg::Vec2Array* tcoords = new osg::Vec2Array(4);
(*tcoords)[0].set(0.0f,0.0f);
(*tcoords)[1].set(1.0f,0.0f);
(*tcoords)[2].set(1.0f,1.0f);
(*tcoords)[3].set(0.0f,1.0f);
geom->setTexCoordArray(0,tcoords);
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4));
if (image)
{
osg::StateSet* stateset = new osg::StateSet;
osg::Texture2D* texture = new osg::Texture2D;
texture->setImage(image);
stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
geom->setStateSet(stateset);
}
return geom;
}
osg::Drawable* createAxis(const osg::Vec3& corner,const osg::Vec3& xdir,const osg::Vec3& ydir,const osg::Vec3& zdir)
{
// set up the Geometry.
osg::Geometry* geom = new osg::Geometry;
osg::Vec3Array* coords = new osg::Vec3Array(6);
(*coords)[0] = corner;
(*coords)[1] = corner+xdir;
(*coords)[2] = corner;
(*coords)[3] = corner+ydir;
(*coords)[4] = corner;
(*coords)[5] = corner+zdir;
geom->setVertexArray(coords);
osg::Vec4 x_color(0.0f,1.0f,1.0f,1.0f);
osg::Vec4 y_color(0.0f,1.0f,1.0f,1.0f);
osg::Vec4 z_color(1.0f,0.0f,0.0f,1.0f);
osg::Vec4Array* color = new osg::Vec4Array(6);
(*color)[0] = x_color;
(*color)[1] = x_color;
(*color)[2] = y_color;
(*color)[3] = y_color;
(*color)[4] = z_color;
(*color)[5] = z_color;
geom->setColorArray(color, osg::Array::BIND_PER_VERTEX);
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,6));
osg::StateSet* stateset = new osg::StateSet;
osg::LineWidth* linewidth = new osg::LineWidth();
linewidth->setWidth(4.0f);
stateset->setAttributeAndModes(linewidth,osg::StateAttribute::ON);
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
geom->setStateSet(stateset);
return geom;
}
osg::Node* createModel()
{
// create the root node which will hold the model.
osg::Group* root = new osg::Group();
// add the drawable into a single goede to be shared...
osg::Billboard* center = new osg::Billboard();
center->setMode(osg::Billboard::POINT_ROT_EYE);
center->addDrawable(
createSquare(osg::Vec3(-0.5f,0.0f,-0.5f),osg::Vec3(1.0f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readImageFile("Images/reflect.rgb")),
osg::Vec3(0.0f,0.0f,0.0f));
osg::Billboard* x_arrow = new osg::Billboard();
x_arrow->setMode(osg::Billboard::AXIAL_ROT);
x_arrow->setAxis(osg::Vec3(1.0f,0.0f,0.0f));
x_arrow->setNormal(osg::Vec3(0.0f,-1.0f,0.0f));
x_arrow->addDrawable(
createSquare(osg::Vec3(-0.5f,0.0f,-0.5f),osg::Vec3(1.0f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readImageFile("Cubemap_axis/posx.png")),
osg::Vec3(5.0f,0.0f,0.0f));
osg::Billboard* y_arrow = new osg::Billboard();
y_arrow->setMode(osg::Billboard::AXIAL_ROT);
y_arrow->setAxis(osg::Vec3(0.0f,1.0f,0.0f));
y_arrow->setNormal(osg::Vec3(1.0f,0.0f,0.0f));
y_arrow->addDrawable(
createSquare(osg::Vec3(0.0f,-0.5f,-0.5f),osg::Vec3(0.0f,1.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readImageFile("Cubemap_axis/posy.png")),
osg::Vec3(0.0f,5.0f,0.0f));
osg::Billboard* z_arrow = new osg::Billboard();
z_arrow->setMode(osg::Billboard::AXIAL_ROT);
z_arrow->setAxis(osg::Vec3(0.0f,0.0f,1.0f));
z_arrow->setNormal(osg::Vec3(0.0f,-1.0f,0.0f));
z_arrow->addDrawable(
createSquare(osg::Vec3(-0.5f,0.0f,-0.5f),osg::Vec3(1.0f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readImageFile("Cubemap_axis/posz.png")),
osg::Vec3(0.0f,0.0f,5.0f));
osg::Geode* axis = new osg::Geode();
axis->addDrawable(createAxis(osg::Vec3(0.0f,0.0f,0.0f),osg::Vec3(5.0f,0.0f,0.0f),osg::Vec3(0.0f,5.0f,0.0f),osg::Vec3(0.0f,0.0f,5.0f)));
root->addChild(center);
root->addChild(x_arrow);
root->addChild(y_arrow);
root->addChild(z_arrow);
root->addChild(axis);
return root;
}
int main(int, char**)
{
// construct the viewer
osgViewer::Viewer viewer;
// set the scene to render
viewer.setSceneData(createModel());
// run the viewers frame loop
return viewer.run();
}
|