00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "Frame.h"
00020
00021 namespace uvsim
00022 {
00023
00024 void FrameCallback::operator()(osg::Node *node, osg::NodeVisitor *nv)
00025 {
00026
00027
00028 }
00029
00030 Frame::Frame(float insize)
00031 {
00032 size = insize;
00033
00034 osg::Billboard* center = new osg::Billboard();
00035 center->setMode(osg::Billboard::POINT_ROT_EYE);
00036 center->addDrawable(
00037 createSquare(osg::Vec3(-size/10,0.0f,-size/10),osg::Vec3(size/5,0.0f,0.0f),osg::Vec3(0.0f,0.0f,size/5),osgDB::readImageFile(std::string(DATADIR)+="/textures/reflect.rgb")),
00038 osg::Vec3(0.0f,0.0f,0.0f));
00039
00040 osg::Billboard* x_arrow = new osg::Billboard();
00041 x_arrow->setMode(osg::Billboard::AXIAL_ROT);
00042 x_arrow->setAxis(osg::Vec3(1.0f,0.0f,0.0f));
00043 x_arrow->setNormal(osg::Vec3(0.0f,-1.0f,0.0f));
00044 x_arrow->addDrawable(
00045 createSquare(osg::Vec3(-size/10,0.0f,-size/10),osg::Vec3(size/5,0.0f,0.0f),osg::Vec3(0.0f,0.0f,size/5),osgDB::readImageFile(std::string(DATADIR)+="/images/posx.png")),
00046 osg::Vec3(size,0.0f,0.0f));
00047
00048 osg::Billboard* y_arrow = new osg::Billboard();
00049 y_arrow->setMode(osg::Billboard::AXIAL_ROT);
00050 y_arrow->setAxis(osg::Vec3(0.0f,1.0f,0.0f));
00051 y_arrow->setNormal(osg::Vec3(1.0f,0.0f,0.0f));
00052 y_arrow->addDrawable(
00053 createSquare(osg::Vec3(0.0f,-size/10,-size/10),osg::Vec3(0.0f,size/5,0.0f),osg::Vec3(0.0f,0.0f,size/5),osgDB::readImageFile(std::string(DATADIR)+="/images/posy.png")),
00054 osg::Vec3(0.0f,size,0.0f));
00055
00056 osg::Billboard* z_arrow = new osg::Billboard();
00057 z_arrow->setMode(osg::Billboard::AXIAL_ROT);
00058 z_arrow->setAxis(osg::Vec3(0.0f,0.0f,1.0f));
00059 z_arrow->setNormal(osg::Vec3(0.0f,-1.0f,0.0f));
00060 z_arrow->addDrawable(
00061 createSquare(osg::Vec3(-size/10,0.0f,-size/10),osg::Vec3(size/5,0.0f,0.0f),osg::Vec3(0.0f,0.0f,size/5),osgDB::readImageFile(std::string(DATADIR)+="/images/posz.png")),
00062 osg::Vec3(0.0f,0.0f,size));
00063
00064
00065
00066 osg::Geode* axis = new osg::Geode();
00067 axis->addDrawable(createAxis(osg::Vec3(0.0f,0.0f,0.0f),osg::Vec3(size,0.0f,0.0f),osg::Vec3(0.0f,size,0.0f),osg::Vec3(0.0f,0.0f,size)));
00068
00069
00070 root = new osg::PositionAttitudeTransform;
00071 callback = new FrameCallback;
00072 root->setUpdateCallback(callback);
00073 root->addChild(center);
00074 root->addChild(x_arrow);
00075 root->addChild(y_arrow);
00076 root->addChild(z_arrow);
00077 root->addChild(axis);
00078 }
00079
00081 osg::Drawable* Frame::createSquare(const osg::Vec3& corner,const osg::Vec3& width,const osg::Vec3& height, osg::Image* image)
00082 {
00083
00084 osg::Geometry* geom = new osg::Geometry;
00085
00086 osg::Vec3Array* coords = new osg::Vec3Array(4);
00087 (*coords)[0] = corner;
00088 (*coords)[1] = corner+width;
00089 (*coords)[2] = corner+width+height;
00090 (*coords)[3] = corner+height;
00091
00092
00093 geom->setVertexArray(coords);
00094
00095 osg::Vec3Array* norms = new osg::Vec3Array(1);
00096 (*norms)[0] = width^height;
00097 (*norms)[0].normalize();
00098
00099 geom->setNormalArray(norms);
00100 geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
00101
00102 osg::Vec2Array* tcoords = new osg::Vec2Array(4);
00103 (*tcoords)[0].set(0.0f,0.0f);
00104 (*tcoords)[1].set(1.0f,0.0f);
00105 (*tcoords)[2].set(1.0f,1.0f);
00106 (*tcoords)[3].set(0.0f,1.0f);
00107 geom->setTexCoordArray(0,tcoords);
00108
00109 geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4));
00110
00111 if (image)
00112 {
00113 osg::StateSet* stateset = new osg::StateSet;
00114 osg::Texture2D* texture = new osg::Texture2D;
00115 texture->setImage(image);
00116 stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
00117 geom->setStateSet(stateset);
00118 }
00119
00120 return geom;
00121 }
00122
00123 osg::Drawable* Frame::createAxis(const osg::Vec3& corner,const osg::Vec3& xdir,const osg::Vec3& ydir,const osg::Vec3& zdir)
00124 {
00125
00126 osg::Geometry* geom = new osg::Geometry;
00127
00128 osg::Vec3Array* coords = new osg::Vec3Array(6);
00129 (*coords)[0] = corner;
00130 (*coords)[1] = corner+xdir;
00131 (*coords)[2] = corner;
00132 (*coords)[3] = corner+ydir;
00133 (*coords)[4] = corner;
00134 (*coords)[5] = corner+zdir;
00135
00136 geom->setVertexArray(coords);
00137
00138 osg::Vec4 x_color(0.0f,1.0f,1.0f,1.0f);
00139 osg::Vec4 y_color(0.0f,1.0f,1.0f,1.0f);
00140 osg::Vec4 z_color(1.0f,0.0f,0.0f,1.0f);
00141
00142 osg::Vec4Array* color = new osg::Vec4Array(6);
00143 (*color)[0] = x_color;
00144 (*color)[1] = x_color;
00145 (*color)[2] = y_color;
00146 (*color)[3] = y_color;
00147 (*color)[4] = z_color;
00148 (*color)[5] = z_color;
00149
00150 geom->setColorArray(color);
00151 geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
00152
00153 geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,6));
00154
00155 osg::StateSet* stateset = new osg::StateSet;
00156 osg::LineWidth* linewidth = new osg::LineWidth();
00157 linewidth->setWidth(4.0f);
00158 stateset->setAttributeAndModes(linewidth,osg::StateAttribute::ON);
00159 stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
00160 geom->setStateSet(stateset);
00161
00162 return geom;
00163 }
00164
00165
00166
00167 }
00168
00169