Fixed the X and Y axis rotation billboards so that now rotate correctly.
Rewrote the osgbillboard demo so that it creates a point rotatated billbaord and X,Y and Z axis billboards to both test and demonstrate this types of billboards in action.
This commit is contained in:
parent
0c6991ea27
commit
392150521a
@ -46,8 +46,8 @@ echo osgparticle
|
||||
osgparticle
|
||||
more memleaks.log
|
||||
|
||||
echo osgbillboard lz.rgb
|
||||
osgbillboard lz.rgb
|
||||
echo osgbillboard
|
||||
osgbillboard
|
||||
more memleaks.log
|
||||
|
||||
echo osgcube
|
||||
|
@ -34,8 +34,8 @@ osgprerender dumptruck.osg
|
||||
echo osgparticle
|
||||
osgparticle
|
||||
|
||||
echo osgbillboard lz.rgb
|
||||
osgbillboard lz.rgb
|
||||
echo osgbillboard
|
||||
osgbillboard
|
||||
|
||||
echo osgcube
|
||||
osgcube
|
||||
|
@ -35,11 +35,16 @@ class SG_EXPORT Billboard : public Geode
|
||||
/** Get the billboard rotation mode. */
|
||||
inline const Mode getMode() const { return _mode; }
|
||||
|
||||
/** Set the axis about which all the billboard's drawable rotate. */
|
||||
/** Set the axis about which all the billboard's drawable rotate. Only utlized when mode==AXIAL_ROT*/
|
||||
void setAxis(const Vec3& axis);
|
||||
/** Get the axis about which all the billboard's drawable rotate. */
|
||||
inline const Vec3& getAxis() const { return _axis; }
|
||||
|
||||
/** Set the normal which defines the billboard's drawable front face, when unrotated. */
|
||||
void setNormal(const Vec3& normal);
|
||||
/** Get the normal of billboard's drawable front face. */
|
||||
inline const Vec3& getNormal() const { return _normal; }
|
||||
|
||||
|
||||
/** Set the position of specified drawable. */
|
||||
inline void setPos(int i,const Vec3& pos) { _positionList[i] = pos; }
|
||||
@ -117,20 +122,22 @@ class SG_EXPORT Billboard : public Geode
|
||||
{
|
||||
AXIAL_ROT_X_AXIS=AXIAL_ROT+1,
|
||||
AXIAL_ROT_Y_AXIS,
|
||||
AXIAL_ROT_Z_AXIS
|
||||
AXIAL_ROT_Z_AXIS,
|
||||
CACHE_DIRTY
|
||||
};
|
||||
|
||||
|
||||
Mode _mode;
|
||||
Vec3 _axis;
|
||||
Vec3 _normal;
|
||||
PositionList _positionList;
|
||||
ref_ptr<ComputeBillboardCallback> _computeBillboardCallback;
|
||||
|
||||
// used internally as cache of which what _axis is aligned to help
|
||||
// deicde which method of rotation to use.
|
||||
int _cachedMode;
|
||||
|
||||
void setCachedMode();
|
||||
int _cachedMode;
|
||||
Vec3 _side;
|
||||
void updateCache();
|
||||
|
||||
};
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <osg/MatrixTransform>
|
||||
#include <osg/Texture>
|
||||
#include <osg/Billboard>
|
||||
#include <osg/LineWidth>
|
||||
|
||||
#include <osgGA/TrackballManipulator>
|
||||
#include <osgGA/FlightManipulator>
|
||||
@ -24,359 +25,149 @@
|
||||
|
||||
typedef std::vector< osg::ref_ptr<osg::Image> > ImageList;
|
||||
|
||||
/**
|
||||
* Function to read several images files (typically one) as specified
|
||||
* on the command line, and return them in an ImageList
|
||||
*/
|
||||
ImageList getImagesFromFiles(std::vector<std::string>& commandLine)
|
||||
{
|
||||
|
||||
ImageList imageList;
|
||||
|
||||
for(std::vector<std::string>::iterator itr=commandLine.begin();
|
||||
itr!=commandLine.end();
|
||||
++itr)
|
||||
{
|
||||
if ((*itr)[0]!='-')
|
||||
{
|
||||
// not an option so assume string is a filename.
|
||||
osg::Image *image = osgDB::readImageFile( *itr );
|
||||
if (image)
|
||||
{
|
||||
imageList.push_back(image);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (imageList.size()==0)
|
||||
{
|
||||
osg::notify(osg::WARN) << "No image data loaded."<<std::endl;
|
||||
}
|
||||
|
||||
return imageList;
|
||||
}
|
||||
|
||||
/** create 2,2 square with center at 0,0,0 and aligned along the XZ plan */
|
||||
osg::Drawable* createSquare(float textureCoordMax=1.0f)
|
||||
/** 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].set(-1.0f,0.0f,1.0f);
|
||||
(*coords)[1].set(-1.0f,0.0f,-1.0f);
|
||||
(*coords)[2].set(1.0f,0.0f,-1.0f);
|
||||
(*coords)[3].set(1.0f,0.0f,1.0f);
|
||||
(*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].set(0.0f,-1.0f,0.0f);
|
||||
(*norms)[0] = width^height;
|
||||
(*norms)[0].normalize();
|
||||
|
||||
geom->setNormalArray(norms);
|
||||
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
|
||||
|
||||
osg::Vec2Array* tcoords = new osg::Vec2Array(4);
|
||||
(*tcoords)[0].set(0.0f,textureCoordMax);
|
||||
(*tcoords)[1].set(0.0f,0.0f);
|
||||
(*tcoords)[2].set(textureCoordMax,0.0f);
|
||||
(*tcoords)[3].set(textureCoordMax,textureCoordMax);
|
||||
(*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->addPrimitive(osgNew osg::DrawArrays(osg::Primitive::QUADS,0,4));
|
||||
|
||||
|
||||
if (image)
|
||||
{
|
||||
osg::StateSet* stateset = new osg::StateSet;
|
||||
osg::Texture* texture = new osg::Texture;
|
||||
texture->setImage(image);
|
||||
stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
|
||||
geom->setStateSet(stateset);
|
||||
}
|
||||
|
||||
return geom;
|
||||
}
|
||||
|
||||
osg::Node* createTexturedItem(const osg::Vec3& offset,osg::Texture* texture,osg::Node* geometry)
|
||||
osg::Drawable* createAxis(const osg::Vec3& corner,const osg::Vec3& xdir,const osg::Vec3& ydir,const osg::Vec3& zdir)
|
||||
{
|
||||
// create a tranform node to position each square in appropriate
|
||||
// place and also to add individual texture set to it, so that
|
||||
// that state is inherited down to its children.
|
||||
osg::MatrixTransform* local_transform = osgNew osg::MatrixTransform;
|
||||
local_transform->postMult(osg::Matrix::translate(offset));
|
||||
// set up the Geometry.
|
||||
osg::Geometry* geom = new osg::Geometry;
|
||||
|
||||
// create the StateSet to store the texture data
|
||||
osg::StateSet* stateset = osgNew osg::StateSet;
|
||||
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;
|
||||
|
||||
stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
|
||||
geom->setVertexArray(coords);
|
||||
|
||||
// turn the face culling off so you can see the texture from
|
||||
// all angles.
|
||||
stateset->setMode(GL_CULL_FACE,osg::StateAttribute::OFF);
|
||||
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);
|
||||
|
||||
// attach the setset to tranform node.
|
||||
local_transform->setStateSet(stateset);
|
||||
|
||||
// add the geode to the transform.
|
||||
local_transform->addChild(geometry);
|
||||
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;
|
||||
|
||||
return local_transform;
|
||||
geom->setColorArray(color);
|
||||
geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
|
||||
|
||||
geom->addPrimitive(osgNew osg::DrawArrays(osg::Primitive::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* createLayer(const osg::Vec3& offset,osg::Image* image,osg::Node* geometry,osg::Node* geometryRep)
|
||||
{
|
||||
if (image==NULL) return NULL;
|
||||
|
||||
osg::MatrixTransform* top_transform = osgNew osg::MatrixTransform;
|
||||
top_transform->postMult(osg::Matrix::translate(offset));
|
||||
|
||||
osg::Vec3 local_offset(0.0f,0.0f,0.0f);
|
||||
osg::Vec3 local_delta(3.0f,0.0f,0.0f);
|
||||
|
||||
// defaults mipmapped texturing.
|
||||
{
|
||||
// create the texture attribute
|
||||
osg::Texture* texture = osgNew osg::Texture;
|
||||
texture->setImage(image);
|
||||
|
||||
// add the transform node to root group node.
|
||||
top_transform->addChild(createTexturedItem(local_offset,texture,geometry));
|
||||
|
||||
local_offset += local_delta;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// bilinear
|
||||
{
|
||||
// create the texture attribute
|
||||
osg::Texture* texture = osgNew osg::Texture;
|
||||
texture->setImage(image);
|
||||
|
||||
// set up bilinear filtering.
|
||||
texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR_MIPMAP_NEAREST);
|
||||
texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
|
||||
|
||||
// add the transform node to root group node.
|
||||
top_transform->addChild(createTexturedItem(local_offset,texture,geometry));
|
||||
|
||||
local_offset += local_delta;
|
||||
|
||||
}
|
||||
|
||||
// trilinear
|
||||
{
|
||||
// create the texture attribute
|
||||
osg::Texture* texture = osgNew osg::Texture;
|
||||
texture->setImage(image);
|
||||
|
||||
// set up trilinear filtering.
|
||||
texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR_MIPMAP_LINEAR);
|
||||
texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
|
||||
|
||||
// add the transform node to root group node.
|
||||
top_transform->addChild(createTexturedItem(local_offset,texture,geometry));
|
||||
|
||||
local_offset += local_delta;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// anisotropic
|
||||
{
|
||||
// create the texture attribute
|
||||
osg::Texture* texture = osgNew osg::Texture;
|
||||
texture->setImage(image);
|
||||
|
||||
// set up anistropic filtering.
|
||||
texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR_MIPMAP_LINEAR);
|
||||
texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
|
||||
|
||||
texture->setMaxAnisotropy(2.0f);
|
||||
|
||||
// add the transform node to root group node.
|
||||
top_transform->addChild(createTexturedItem(local_offset,texture,geometry));
|
||||
|
||||
local_offset += local_delta;
|
||||
|
||||
}
|
||||
|
||||
// arb compression
|
||||
{
|
||||
// create the texture attribute
|
||||
osg::Texture* texture = osgNew osg::Texture;
|
||||
texture->setImage(image);
|
||||
|
||||
texture->setInternalFormatMode(osg::Texture::USE_ARB_COMPRESSION);
|
||||
|
||||
// add the transform node to root group node.
|
||||
top_transform->addChild(createTexturedItem(local_offset,texture,geometry));
|
||||
|
||||
local_offset += local_delta;
|
||||
|
||||
}
|
||||
|
||||
// s3tc_dxt1 compression
|
||||
{
|
||||
// create the texture attribute
|
||||
osg::Texture* texture = osgNew osg::Texture;
|
||||
texture->setImage(image);
|
||||
|
||||
texture->setInternalFormatMode(osg::Texture::USE_S3TC_DXT1_COMPRESSION);
|
||||
|
||||
// add the transform node to root group node.
|
||||
top_transform->addChild(createTexturedItem(local_offset,texture,geometry));
|
||||
|
||||
local_offset += local_delta;
|
||||
|
||||
}
|
||||
|
||||
// default wrap mode. (osg::Texture::CLAMP)
|
||||
{
|
||||
// create the texture attribute
|
||||
osg::Texture* texture = osgNew osg::Texture;
|
||||
texture->setImage(image);
|
||||
|
||||
// add the transform node to root group node.
|
||||
top_transform->addChild(createTexturedItem(local_offset,texture,geometryRep));
|
||||
|
||||
local_offset += local_delta;
|
||||
|
||||
}
|
||||
|
||||
// clamp-to-edge mode.
|
||||
{
|
||||
// create the texture attribute
|
||||
osg::Texture* texture = osgNew osg::Texture;
|
||||
texture->setImage(image);
|
||||
|
||||
texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE);
|
||||
texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE);
|
||||
|
||||
// add the transform node to root group node.
|
||||
top_transform->addChild(createTexturedItem(local_offset,texture,geometryRep));
|
||||
|
||||
local_offset += local_delta;
|
||||
|
||||
}
|
||||
|
||||
// repeat wrap mode.
|
||||
{
|
||||
// create the texture attribute
|
||||
osg::Texture* texture = osgNew osg::Texture;
|
||||
texture->setImage(image);
|
||||
|
||||
texture->setWrap(osg::Texture::WRAP_S,osg::Texture::REPEAT);
|
||||
texture->setWrap(osg::Texture::WRAP_T,osg::Texture::REPEAT);
|
||||
|
||||
// add the transform node to root group node.
|
||||
top_transform->addChild(createTexturedItem(local_offset,texture,geometryRep));
|
||||
|
||||
local_offset += local_delta;
|
||||
|
||||
}
|
||||
|
||||
// mirror wrap mode.
|
||||
{
|
||||
// create the texture attribute
|
||||
osg::Texture* texture = osgNew osg::Texture;
|
||||
texture->setImage(image);
|
||||
|
||||
texture->setWrap(osg::Texture::WRAP_S,osg::Texture::MIRROR);
|
||||
texture->setWrap(osg::Texture::WRAP_T,osg::Texture::MIRROR);
|
||||
|
||||
// add the transform node to root group node.
|
||||
top_transform->addChild(createTexturedItem(local_offset,texture,geometryRep));
|
||||
|
||||
local_offset += local_delta;
|
||||
|
||||
}
|
||||
|
||||
return top_transform;
|
||||
}
|
||||
|
||||
osg::Node* createModelFromImages(ImageList& imageList)
|
||||
osg::Node* createModel()
|
||||
{
|
||||
|
||||
if (imageList.empty()) return NULL;
|
||||
|
||||
// create the root node which will hold the model.
|
||||
osg::Group* root = osgNew osg::Group();
|
||||
|
||||
// create a single drawable to be shared by each texture instance.
|
||||
osg::Drawable* drawable_noTexCoodRep = createSquare(1.0f);
|
||||
|
||||
// add the drawable into a single goede to be shared...
|
||||
osg::Billboard* geode_noTexCoodRep = osgNew osg::Billboard();
|
||||
geode_noTexCoodRep->setMode(osg::Billboard::POINT_ROT_EYE);
|
||||
geode_noTexCoodRep->addDrawable(drawable_noTexCoodRep);
|
||||
geode_noTexCoodRep->setPos(0,osg::Vec3(0.0f,0.0f,0.0f));
|
||||
|
||||
|
||||
// create a single drawable to be shared by each texture instance.
|
||||
osg::Drawable* drawable_texCoodRep = createSquare(2.0f);
|
||||
|
||||
// add the drawable into a single goede to be shared...
|
||||
osg::Billboard* geode_texCoodRep = osgNew osg::Billboard();
|
||||
geode_texCoodRep->addDrawable(drawable_texCoodRep);
|
||||
geode_texCoodRep->setPos(0,osg::Vec3(0.0f,0.0f,0.0f));
|
||||
|
||||
osg::Vec3 offset(0.0f,0.0f,0.0f);
|
||||
osg::Vec3 delta(0.0f,0.0f,3.0f);
|
||||
|
||||
// step through the image list processing each image in turn.
|
||||
for(ImageList::iterator itr=imageList.begin();
|
||||
itr!=imageList.end();
|
||||
++itr)
|
||||
{
|
||||
|
||||
// add the transform node to root group node.
|
||||
root->addChild(createLayer(offset,itr->get(),geode_noTexCoodRep,geode_texCoodRep));
|
||||
osg::Billboard* center = osgNew 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("reflect.rgb")),
|
||||
osg::Vec3(0.0f,0.0f,0.0f));
|
||||
|
||||
offset += delta;
|
||||
|
||||
}
|
||||
|
||||
osg::Billboard* x_arrow = osgNew 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("osg_posx.png")),
|
||||
osg::Vec3(5.0f,0.0f,0.0f));
|
||||
|
||||
osg::Billboard* y_arrow = osgNew 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("osg_posy.png")),
|
||||
osg::Vec3(0.0f,5.0f,0.0f));
|
||||
|
||||
osg::Billboard* z_arrow = osgNew 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("osg_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;
|
||||
}
|
||||
|
||||
|
||||
void write_usage(std::ostream& out,const std::string& name)
|
||||
{
|
||||
out << std::endl;
|
||||
out <<"usage:"<< std::endl;
|
||||
out <<" "<<name<<" [options] image_infile1 [image_infile2 ...]"<< std::endl;
|
||||
out << std::endl;
|
||||
out <<"options:"<< std::endl;
|
||||
out <<" -l libraryName - load plugin of name libraryName"<< std::endl;
|
||||
out <<" i.e. -l osgdb_pfb"<< std::endl;
|
||||
out <<" Useful for loading reader/writers which can load"<< std::endl;
|
||||
out <<" other file formats in addition to its extension."<< std::endl;
|
||||
out <<" -e extensionName - load reader/wrter plugin for file extension"<< std::endl;
|
||||
out <<" i.e. -e pfb"<< std::endl;
|
||||
out <<" Useful short hand for specifying full library name as"<< std::endl;
|
||||
out <<" done with -l above, as it automatically expands to"<< std::endl;
|
||||
out <<" the full library name appropriate for each platform."<< std::endl;
|
||||
out <<std::endl;
|
||||
out <<" -stereo - switch on stereo rendering, using the default of,"<< std::endl;
|
||||
out <<" ANAGLYPHIC or the value set in the OSG_STEREO_MODE "<< std::endl;
|
||||
out <<" environmental variable. See doc/stereo.html for "<< std::endl;
|
||||
out <<" further details on setting up accurate stereo "<< std::endl;
|
||||
out <<" for your system. "<< std::endl;
|
||||
out <<" -stereo ANAGLYPHIC - switch on anaglyphic(red/cyan) stereo rendering."<< std::endl;
|
||||
out <<" -stereo QUAD_BUFFER - switch on quad buffered stereo rendering."<< std::endl;
|
||||
out <<std::endl;
|
||||
out <<" -stencil - use a visual with stencil buffer enabled, this "<< std::endl;
|
||||
out <<" also allows the depth complexity statistics mode"<< std::endl;
|
||||
out <<" to be used (press 'p' three times to cycle to it)."<< std::endl;
|
||||
out << std::endl;
|
||||
out<<"example:"<<std::endl;
|
||||
out<<" osgtexture lz.rgb"<<std::endl;
|
||||
out<<std::endl;
|
||||
}
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
|
||||
// initialize the GLUT
|
||||
glutInit( &argc, argv );
|
||||
|
||||
if (argc<2)
|
||||
{
|
||||
write_usage(osg::notify(osg::NOTICE),argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// create the commandline args.
|
||||
std::vector<std::string> commandLine;
|
||||
for(int i=1;i<argc;++i) commandLine.push_back(argv[i]);
|
||||
@ -394,38 +185,20 @@ int main( int argc, char **argv )
|
||||
// eat any parameters that have been matched.
|
||||
osgDB::readCommandLine(commandLine);
|
||||
|
||||
// load the images specified on command line
|
||||
ImageList imageList = getImagesFromFiles(commandLine);
|
||||
|
||||
|
||||
if (!imageList.empty())
|
||||
{
|
||||
// create a model from the images.
|
||||
osg::Node* rootNode = createModel();
|
||||
|
||||
// create a model from the images.
|
||||
osg::Node* rootNode = createModelFromImages(imageList);
|
||||
|
||||
// no longer need images reference by imageList so clear it.
|
||||
imageList.clear();
|
||||
// add model to viewer.
|
||||
viewer.addViewport( rootNode );
|
||||
|
||||
// add model to viewer.
|
||||
viewer.addViewport( rootNode );
|
||||
// register trackball, flight and drive.
|
||||
viewer.registerCameraManipulator(osgNew osgGA::TrackballManipulator);
|
||||
viewer.registerCameraManipulator(osgNew osgGA::FlightManipulator);
|
||||
viewer.registerCameraManipulator(osgNew osgGA::DriveManipulator);
|
||||
|
||||
// register trackball, flight and drive.
|
||||
viewer.registerCameraManipulator(osgNew osgGA::TrackballManipulator);
|
||||
viewer.registerCameraManipulator(osgNew osgGA::FlightManipulator);
|
||||
viewer.registerCameraManipulator(osgNew osgGA::DriveManipulator);
|
||||
viewer.open();
|
||||
|
||||
viewer.open();
|
||||
|
||||
viewer.run();
|
||||
}
|
||||
else
|
||||
{
|
||||
write_usage(osg::notify(osg::NOTICE),argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
viewer.run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -11,16 +11,19 @@ Billboard::Billboard()
|
||||
{
|
||||
_mode = AXIAL_ROT;
|
||||
_axis.set(0.0f,0.0f,1.0f);
|
||||
setCachedMode();
|
||||
_normal.set(0.0f,-1.0f,0.0f);
|
||||
updateCache();
|
||||
}
|
||||
|
||||
Billboard::Billboard(const Billboard& billboard,const CopyOp& copyop):
|
||||
Geode(billboard,copyop),
|
||||
_mode(billboard._mode),
|
||||
_axis(billboard._axis),
|
||||
_normal(billboard._normal),
|
||||
_positionList(billboard._positionList),
|
||||
_computeBillboardCallback(_computeBillboardCallback),
|
||||
_cachedMode(billboard._cachedMode) {}
|
||||
_cachedMode(billboard._cachedMode),
|
||||
_side(billboard._side) {}
|
||||
|
||||
Billboard::~Billboard()
|
||||
{
|
||||
@ -29,25 +32,37 @@ Billboard::~Billboard()
|
||||
void Billboard::setMode(const Mode mode)
|
||||
{
|
||||
_mode = mode;
|
||||
setCachedMode();
|
||||
_cachedMode = CACHE_DIRTY;
|
||||
updateCache();
|
||||
}
|
||||
|
||||
void Billboard::setAxis(const Vec3& axis)
|
||||
{
|
||||
_axis = axis;
|
||||
setCachedMode();
|
||||
_axis.normalize();
|
||||
updateCache();
|
||||
}
|
||||
|
||||
void Billboard::setCachedMode()
|
||||
void Billboard::setNormal(const Vec3& normal)
|
||||
{
|
||||
_normal = normal;
|
||||
_normal.normalize();
|
||||
updateCache();
|
||||
}
|
||||
|
||||
void Billboard::updateCache()
|
||||
{
|
||||
if (_mode==AXIAL_ROT)
|
||||
{
|
||||
if (_axis==osg::Vec3(1.0f,0.0,0.0f)) _cachedMode = AXIAL_ROT_X_AXIS;
|
||||
else if (_axis==osg::Vec3(0.0f,1.0,0.0f)) _cachedMode = AXIAL_ROT_Y_AXIS;
|
||||
else if (_axis==osg::Vec3(0.0f,0.0,1.0f)) _cachedMode = AXIAL_ROT_Z_AXIS;
|
||||
else _cachedMode = AXIAL_ROT;
|
||||
if (_axis==Vec3(1.0f,0.0,0.0f) && _normal==Vec3(0.0f,-1.0,0.0f)) _cachedMode = AXIAL_ROT_X_AXIS;
|
||||
else if (_axis==Vec3(0.0f,1.0,0.0f) && _normal==Vec3(1.0f, 0.0,0.0f)) _cachedMode = AXIAL_ROT_Y_AXIS;
|
||||
else if (_axis==Vec3(0.0f,0.0,1.0f) && _normal==Vec3(0.0f,-1.0,0.0f)) _cachedMode = AXIAL_ROT_Z_AXIS;
|
||||
else _cachedMode = AXIAL_ROT;
|
||||
}
|
||||
else _cachedMode = _mode;
|
||||
|
||||
_side = _axis^_normal;
|
||||
_side.normalize();
|
||||
}
|
||||
|
||||
const bool Billboard::addDrawable(Drawable *gset)
|
||||
@ -104,14 +119,12 @@ const bool Billboard::computeMatrix(Matrix& modelview, const Vec3& eye_local, co
|
||||
|
||||
Matrix matrix;
|
||||
|
||||
Vec3 ev(pos_local-eye_local);
|
||||
Vec3 ev(eye_local-pos_local);
|
||||
switch(_cachedMode)
|
||||
{
|
||||
case(AXIAL_ROT): // need to implement
|
||||
case(AXIAL_ROT_Z_AXIS): // need to implement
|
||||
case(AXIAL_ROT_Y_AXIS): // need to implement
|
||||
case(AXIAL_ROT_X_AXIS): // implemented correctly..
|
||||
{
|
||||
|
||||
ev.z() = 0.0f;
|
||||
float ev_length = ev.length();
|
||||
if (ev_length>0.0f)
|
||||
@ -121,16 +134,56 @@ const bool Billboard::computeMatrix(Matrix& modelview, const Vec3& eye_local, co
|
||||
//float rotation_zrotation_z = atan2f(ev.x(),ev.y());
|
||||
//mat.makeRotate(inRadians(rotation_z),0.0f,0.0f,1.0f);
|
||||
float inv = 1.0f/ev_length;
|
||||
float c = ev.y()*inv;
|
||||
float s = ev.x()*inv;
|
||||
float c = -ev.y()*inv;
|
||||
matrix(0,0) = c;
|
||||
matrix(0,1) = -s;
|
||||
matrix(1,0) = s;
|
||||
matrix(1,0) = -s;
|
||||
matrix(0,1) = s;
|
||||
matrix(1,1) = c;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case(AXIAL_ROT_Y_AXIS): // need to implement
|
||||
{
|
||||
ev.y() = 0.0f;
|
||||
float ev_length = ev.length();
|
||||
if (ev_length>0.0f)
|
||||
{
|
||||
|
||||
matrix.makeIdentity();
|
||||
//float rotation_zrotation_z = atan2f(ev.x(),ev.y());
|
||||
//mat.makeRotate(inRadians(rotation_z),0.0f,0.0f,1.0f);
|
||||
float inv = 1.0f/ev_length;
|
||||
float s = -ev.z()*inv;
|
||||
float c = ev.x()*inv;
|
||||
matrix(0,0) = c;
|
||||
matrix(2,0) = s;
|
||||
matrix(0,2) = -s;
|
||||
matrix(2,2) = c;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case(AXIAL_ROT_X_AXIS): // implemented correctly..
|
||||
{
|
||||
ev.x() = 0.0f;
|
||||
float ev_length = ev.length();
|
||||
if (ev_length>0.0f)
|
||||
{
|
||||
|
||||
matrix.makeIdentity();
|
||||
//float rotation_zrotation_z = atan2f(ev.x(),ev.y());
|
||||
//mat.makeRotate(inRadians(rotation_z),0.0f,0.0f,1.0f);
|
||||
float inv = 1.0f/ev_length;
|
||||
float s = -ev.z()*inv;
|
||||
float c = -ev.y()*inv;
|
||||
matrix(1,1) = c;
|
||||
matrix(2,1) = -s;
|
||||
matrix(1,2) = s;
|
||||
matrix(2,2) = c;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case(AXIAL_ROT): // need to implement
|
||||
case(POINT_ROT_WORLD):
|
||||
case(POINT_ROT_EYE):
|
||||
{
|
||||
@ -146,8 +199,8 @@ const bool Billboard::computeMatrix(Matrix& modelview, const Vec3& eye_local, co
|
||||
{
|
||||
ev /= ev_len;
|
||||
|
||||
Vec3 cp(ev^Vec3(0.0f,1.0f,0.0f));
|
||||
float dot = ev*Vec3(0.0f,1.0f,0.0f);
|
||||
Vec3 cp(ev^_normal);
|
||||
float dot = ev*_normal;
|
||||
|
||||
float cp_len = cp.length();
|
||||
if (cp_len != 0.0f)
|
||||
|
Loading…
Reference in New Issue
Block a user