[osg-users] ECEF Oriented Compass Implementation

Rambabu Repaka ramboram488 at gmail.com
Wed Nov 16 02:43:06 PST 2016


Hi,

class Compass : public osg::Camera
{
public:
	Compass();
	Compass( const Compass& copy, osg::CopyOp
	copyop=osg::CopyOp::SHALLOW_COPY );
	META_Node( osg, Compass );
	void setPlate( osg::MatrixTransform* plate ) {_plateTransform = plate; }
	void setNeedle( osg::MatrixTransform* needle ) {_needleTransform = needle; }
	void setMainCamera( osg::Camera* camera ) {_mainCamera = camera; }
	virtual void traverse( osg::NodeVisitor& nv );
protected:
	virtual ~Compass();
	osg::ref_ptr<osg::MatrixTransform> _plateTransform;
	osg::ref_ptr<osg::MatrixTransform> _needleTransform;
	osg::observer_ptr<osg::Camera> _mainCamera;
};

Compass::Compass( const Compass& copy, osg::CopyOp copyop ):osg::Camera(copy, copyop),
_plateTransform(copy._plateTransform),
_needleTransform(copy._needleTransform),
_mainCamera(copy._mainCamera)
{
}

void Compass::traverse( osg::NodeVisitor& nv )
{
	if ( _mainCamera.valid() &&nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR )
	{
		osg::Matrix matrix = _mainCamera->getViewMatrix();
		matrix.setTrans( osg::Vec3() );
		osg::Vec3 northVec = osg::Z_AXIS * matrix;
		northVec.z() = 0.0f;
		northVec.normalize();
		osg::Vec3 axis = osg::Y_AXIS ^ northVec;
		float angle = atan2(axis.length(), osg::Y_AXIS*northVec);axis.normalize();
		if ( _plateTransform.valid() )
		_plateTransform->setMatrix( osg::Matrix::rotate(angle, axis) );
	}	
	_plateTransform->accept( nv );
	_needleTransform->accept( nv );
	osg::Camera::traverse( nv );
}

compass class created but it is showing linker errors due to missing of library.How can i get that library file in osg.

... 

Thank you!

Cheers,
Rambabu

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=69390#69390








More information about the osg-users mailing list