コード例 #1
0
ファイル: daeWTransforms.cpp プロジェクト: IsemanTech/osg
void daeWriter::writeUpdateTransformElements(const osg::Vec3 &pos, const osg::Quat &q,    const osg::Vec3 &s)
{
    // Make a scale place element
    domScale *scale = daeSafeCast< domScale >( currentNode->add( COLLADA_ELEMENT_SCALE ) );
    scale->setSid("scale");
    scale->getValue().append3( s.x(), s.y(), s.z() );

    // Make a three rotate place elements for the euler angles
    // TODO decompose quaternion into three euler angles
    osg::Quat::value_type angle;
    osg::Vec3 axis;
    q.getRotate( angle, axis );

    domRotate *rot = daeSafeCast< domRotate >( currentNode->add( COLLADA_ELEMENT_ROTATE ) );
    rot->setSid("rotateZ");
    rot->getValue().append4( 0, 0, 1, osg::RadiansToDegrees(angle) );

    rot = daeSafeCast< domRotate >( currentNode->add( COLLADA_ELEMENT_ROTATE ) );
    rot->setSid("rotateY");
    rot->getValue().append4( 0, 1, 0, osg::RadiansToDegrees(angle) );

    rot = daeSafeCast< domRotate >( currentNode->add( COLLADA_ELEMENT_ROTATE ) );
    rot->setSid("rotateX");
    rot->getValue().append4( 1, 0, 0, osg::RadiansToDegrees(angle) );

    // Make a translate place element
    domTranslate *trans = daeSafeCast< domTranslate >( currentNode->add( COLLADA_ELEMENT_TRANSLATE ) );
    trans->setSid("translate");
    trans->getValue().append3( pos.x(), pos.y(), pos.z() );
}
コード例 #2
0
ファイル: Vehicle.cpp プロジェクト: HOUWEI/VirtualCity
osg::Vec3  CVehicle::calIntersectionPoint(const osg::Vec3& pa1,const osg::Vec3& pa2,const osg::Vec3& pb1,const osg::Vec3& pb2)
{
	osg::Vec3 intersectionPoint,pa12,pb12;
	double t;
	pa12 = pa2 - pa1;
	pb12 = pb2 - pb1;

	double temp =  (pa12.y() * pb12.x()) - (pb12.y() * pa12.x());
	if(temp < 0.001)
		return pa2;
	else
		t =( (pb1.y() - pa1.y()) * pb12.x() + (pa1.x() - pb1.x()) * pb12.y() ) / temp;

	double x,y,z;
	x = pa1.x() + pa12.x() * t;
	y = pa1.y() + pa12.y() * t;
	z = pa1.z() + pa12.z() * t;
	intersectionPoint.set(x,y,z);

	return intersectionPoint;



		



}
コード例 #3
0
/***************************************************************
* Function: setCenterPos()
***************************************************************/
void CAVEGroupReferencePlane::setCenterPos(const osg::Vec3 &center)
{
    /* snap 'center' vector with respect to mUnitGridSize */
    Vec3 centerRounded;
    float snapUnitX, snapUnitY, snapUnitZ;
    snapUnitX = snapUnitY = snapUnitZ = mUnitGridSize;
    if (center.x() < 0) snapUnitX = -mUnitGridSize;
    if (center.y() < 0) snapUnitY = -mUnitGridSize;
    if (center.z() < 0) snapUnitZ = -mUnitGridSize;
    int xSeg = (int)(abs((int)((center.x() + 0.5 * snapUnitX) / mUnitGridSize)));
    int ySeg = (int)(abs((int)((center.y() + 0.5 * snapUnitY) / mUnitGridSize)));
    int zSeg = (int)(abs((int)((center.z() + 0.5 * snapUnitZ) / mUnitGridSize)));
    centerRounded.x() = xSeg * snapUnitX;
    centerRounded.y() = ySeg * snapUnitY;
    centerRounded.z() = zSeg * snapUnitZ;

    /* set highlights of either XZ plane or YZ plane */
    Vec3 offset = centerRounded - mCenter;
    float offx = offset.x() * offset.x();
    float offy = offset.y() * offset.y();
    if (offx > offy) mYZPlaneGeode->setAlpha(1.0f);
    else mYZPlaneGeode->setAlpha(0.4f);
    if (offx < offy) mXZPlaneGeode->setAlpha(1.0f);
    else mXZPlaneGeode->setAlpha(0.4f);

    mCenter = centerRounded;
    Matrixf transMat;
    transMat.makeTranslate(mCenter);
    mMatrixTrans->setMatrix(transMat);
}
コード例 #4
0
ファイル: Particle.cpp プロジェクト: Kurdakov/emscripten_OSG
void osgParticle::Particle::render(osg::RenderInfo& renderInfo, const osg::Vec3& xpos, const osg::Vec3& xrot) const
{
#if defined(OSG_GL_MATRICES_AVAILABLE)
    if (_drawable.valid())
    {
        bool requiresRotation = (xrot.x()!=0.0f || xrot.y()!=0.0f || xrot.z()!=0.0f);
        glColor4f(_current_color.x(),
                  _current_color.y(),
                  _current_color.z(),
                  _current_color.w() * _current_alpha);
        glPushMatrix();
        glTranslatef(xpos.x(), xpos.y(), xpos.z());
        if (requiresRotation)
        {
            osg::Quat rotation(xrot.x(), osg::X_AXIS, xrot.y(), osg::Y_AXIS, xrot.z(), osg::Z_AXIS);
#if defined(OSG_GLES1_AVAILABLE)
            glMultMatrixf(osg::Matrixf(rotation).ptr());
#else
            glMultMatrixd(osg::Matrixd(rotation).ptr());
#endif
        }
        _drawable->draw(renderInfo);
        glPopMatrix();
    }
#else
    OSG_NOTICE<<"Warning: Particle::render(..) not supported for user-defined shape."<<std::endl;
#endif
}
コード例 #5
0
/***************************************************************
* Function: setInitPosition()
***************************************************************/
void CAVEGeodeSnapSolidshape::setInitPosition(const osg::Vec3 &initPos, bool snap)
{
    if (snap)
    {
        /* round intersected position to integer multiples of 'mSnappingUnitDist' */
        Vec3 initPosRounded;
        float snapUnitX, snapUnitY, snapUnitZ;
        snapUnitX = snapUnitY = snapUnitZ = mSnappingUnitDist;
        if (initPos.x() < 0) 
            snapUnitX = -mSnappingUnitDist;
        if (initPos.y() < 0) 
            snapUnitY = -mSnappingUnitDist;
        if (initPos.z() < 0) 
            snapUnitZ = -mSnappingUnitDist;

        int xSeg = (int)(abs((int)((initPos.x() + 0.5 * snapUnitX) / mSnappingUnitDist)));
        int ySeg = (int)(abs((int)((initPos.y() + 0.5 * snapUnitY) / mSnappingUnitDist)));
        int zSeg = (int)(abs((int)((initPos.z() + 0.5 * snapUnitZ) / mSnappingUnitDist)));

        initPosRounded.x() = xSeg * snapUnitX;
        initPosRounded.y() = ySeg * snapUnitY;
        initPosRounded.z() = zSeg * snapUnitZ;

        mInitPosition = initPosRounded;
    }
    else
    {
        mInitPosition = initPos;
    }
}
コード例 #6
0
ファイル: com.cpp プロジェクト: uji-ros-pkg/uwsim_osgbullet
osg::MatrixTransform* createOffOriginOSGBox( osg::Vec3 size )
{
    const osg::Vec3 dim( size * 2 );

    osg::Geode * geode = new osg::Geode;
    osg::Geometry * geom = new osg::Geometry;
    osg::Vec3Array * v = new osg::Vec3Array;

    v->resize( 8 );
    ( *v )[ 0 ] = osg::Vec3( 0, 0, 0 );
    ( *v )[ 1 ] = osg::Vec3( 0, dim.y(), 0 );
    ( *v )[ 2 ] = osg::Vec3( dim.x(), dim.y(), 0 );
    ( *v )[ 3 ] = osg::Vec3( dim.x(), 0, 0 );
    ( *v )[ 4 ] = osg::Vec3( 0, 0, dim.z() );
    ( *v )[ 5 ] = osg::Vec3( dim.x(), 0, dim.z() );
    ( *v )[ 6 ] = osg::Vec3( dim.x(), dim.y(), dim.z() );
    ( *v )[ 7 ] = osg::Vec3( 0, dim.y(), dim.z() );
    geom->setVertexArray( v );

    osg::Vec3Array * n = new osg::Vec3Array;
    n->resize( 6 );
    ( *n )[ 0 ] = osg::Vec3( 0, 0, -1 );
    ( *n )[ 1 ] = osg::Vec3( 0, 0, 1 );
    ( *n )[ 2 ] = osg::Vec3( -1, 0, 0 );
    ( *n )[ 3 ] = osg::Vec3( 1, 0, 0 );
    ( *n )[ 4 ] = osg::Vec3( 0, -1, 0 );
    ( *n )[ 5 ] = osg::Vec3( 0, 1, 0 );
    geom->setNormalArray( n );
    geom->setNormalBinding( osg::Geometry::BIND_PER_PRIMITIVE );

    osg::Vec4Array * c = new osg::Vec4Array;
    c->resize( 8 );
    ( *c )[ 0 ] = osg::Vec4( 1, 1, 1, 1 );
    ( *c )[ 1 ] = osg::Vec4( .6, 0, 0, 1 );
    ( *c )[ 2 ] = osg::Vec4( .6, 0, 0, 1 );
    ( *c )[ 3 ] = osg::Vec4( .6, 0, 0, 1 );
    ( *c )[ 4 ] = osg::Vec4( .6, 0, 0, 1 );
    ( *c )[ 5 ] = osg::Vec4( .6, 0, 0, 1 );
    ( *c )[ 6 ] = osg::Vec4( .6, 0, 0, 1 );
    ( *c )[ 7 ] = osg::Vec4( .6, 0, 0, 1 );
    geom->setColorArray( c );
    geom->setColorBinding( osg::Geometry::BIND_PER_VERTEX );

    GLushort indices[] =
    {
        0, 1, 2, 3,
        4, 5, 6, 7,
        0, 4, 7, 1,
        3, 2, 6, 5,
        0, 3, 5, 4,
        1, 7, 6, 2
    };
    geom->addPrimitiveSet( new osg::DrawElementsUShort( GL_QUADS, 24, indices ) );
    geode->addDrawable( geom );

    osg::MatrixTransform * mt = new osg::MatrixTransform();
    mt->addChild( geode );
    return( mt );
}
コード例 #7
0
void PanoDrawableLOD::setZoom(osg::Vec3 dir, float k)
{
    for(std::map<int,sph_model*>::iterator it = _pdi->modelMap.begin(); it!= _pdi->modelMap.end(); it++)
    {
	it->second->set_zoom(dir.x(),dir.y(),dir.z(),k);
    }

    for(std::map<int,sph_model*>::iterator it = _pdi->transitionModelMap.begin(); it!= _pdi->transitionModelMap.end(); it++)
    {
	it->second->set_zoom(dir.x(),dir.y(),dir.z(),k);
    }
}
コード例 #8
0
void AudioHandler::loadSound(int soundID, osg::Vec3 &dir, osg::Vec3 &pos)
{
    if (!_isConnected)
        return;

    uint8_t packet[256];
    int32_t size;

    float yaw, pitch, roll;

/*    yaw = acos(dir.x());
    if (dir.y() < 0) 
        yaw = M_PI * 2 - yaw;
    yaw += M_PI * 0.5;
    if (yaw > M_PI * 2) 
        yaw -= M_PI * 2;*/

    float val;
    if(dir.x() >= 0)
    {
        if(dir.y() >= 0)
        {
            val = acos( dir.x() );
        }
        else
        {
            val = 2*M_PI - acos( dir.x() );
        }
    }
    else
    {
        if(dir.y() >= 0)
        {
            val = M_PI - acos( -dir.x() );
        }
        else
        {
            val = M_PI + acos( -dir.x() );
        }
    }
    yaw = val;

    pitch = M_PI * 0.5 - atan(dir.z());
    roll = 0.0f;

    size = oscpack(packet, "/sc.elevators/pose", "iffffff", soundID, 
        pos.x() / 1000, pos.y() / 1000, pos.z() / 1000, yaw, pitch, roll);

    if (send(_sock, (char *) packet, size, 0))
    {
        //std::cerr << "AudioHandler  Viewer's info: " << viewPos.x() << " " << viewPos.y() << " " << viewPos.z() << std::endl;	
    }
}
コード例 #9
0
ファイル: TouchSensor.cpp プロジェクト: Arpic/robogen
TouchSensor::TouchSensor(dSpaceID odeSpace, dBodyID sensorBody, float mass,
		osg::Vec3 pos, float x, float y, float z, std::string label) :
		collideSpace_(odeSpace), label_(label) {
	// create own space to avoid physical collisions with other objects
	sensorSpace_ = dHashSpaceCreate(0);
	// create Sensor geom in this different space
	dMass massOde;
	dMassSetBoxTotal(&massOde, mass, x, y, z);
	dBodySetMass(sensorBody, &massOde);
	sensorGeometry_ = dCreateBox(sensorSpace_, x, y, z);
	dBodySetPosition(sensorBody, pos.x(), pos.y(), pos.z());
	dGeomSetPosition(sensorGeometry_, pos.x(), pos.y(), pos.z());
	dGeomSetBody(sensorGeometry_, sensorBody);
}
コード例 #10
0
ファイル: imageNode.cpp プロジェクト: SorinS/structured
osg::Vec2 calcCoordReprojTrans(const osg::Vec3 &vert,const osg::Matrix &trans,const osg::Matrix &viewProj,const osg::Vec2 &size,const osg::Vec4 &ratio){
    osg::Vec4 v(vert.x(),vert.y(),vert.z(),1.0);
    v=v*trans;
    v=v*viewProj;
    v.x() /= v.w();
    v.y() /= v.w();
    v.z() /= v.w();
    v.w() /= v.w();
    //std::cout << "Pre shift " << v << std::endl;
    v.x() /= size.x();;
    v.y() /= size.y();


    v.x() -= (ratio.x()/size.x());
    v.y() -= (ratio.y()/size.y());
    //std::cout << "Post shift " << v << std::endl;


    //  std::cout << "PP shift " << v << std::endl;


    osg::Vec2 tc(v.x(),v.y());
    tc.x() *= ratio.z();
    tc.y() *=ratio.w();
    //tc.x()*=ratio.x();
    //tc.y()*=ratio.y();
    tc.x()/=(ratio.z());
    tc.y()/=(ratio.w());


    return tc;

}
コード例 #11
0
    void addEdgePlane(const osg::Vec3& corner, const osg::Vec3& edge)
    {
        osg::Vec3 normal( edge.y(), -edge.x(), 0.0f);
        normal.normalize();

        add(osg::Plane(normal, corner));
    }
コード例 #12
0
bool HeightFieldLayer::getValue(unsigned int i, unsigned int j, osg::Vec3& value) const
{
    value.x() = _heightField->getHeight(i,j);
    value.y() = _defaultValue.y();
    value.z() = _defaultValue.z();
    return true;
}
コード例 #13
0
ファイル: FreeTypeFont.cpp プロジェクト: nsmoooose/osg
 void setMinMax(const osg::Vec3& pos)
 {
     _maxY = std::max(_maxY, (double) pos.y());
     _minY = std::min(_minY, (double) pos.y());
     _maxX = std::max(_maxX, (double) pos.x());
     _minX = std::min(_minX, (double) pos.x());
 }
コード例 #14
0
ファイル: ConfigManager.cpp プロジェクト: CalVR/calvr
osg::Vec3 ConfigManager::getVec3(std::string attributeX, std::string attributeY,
        std::string attributeZ, std::string path, osg::Vec3 def, bool * found)
{
    bool hasEntry = false;
    bool isFound;

    osg::Vec3 result;
    result.x() = getFloat(attributeX,path,def.x(),&isFound);
    if(isFound)
    {
        hasEntry = true;
    }
    result.y() = getFloat(attributeY,path,def.y(),&isFound);
    if(isFound)
    {
        hasEntry = true;
    }
    result.z() = getFloat(attributeZ,path,def.z(),&isFound);
    if(isFound)
    {
        hasEntry = true;
    }

    if(found)
    {
        *found = hasEntry;
    }
    return result;
}
コード例 #15
0
osg::Quat makeQuat(const osg::Vec3& radians, ERotationOrder fbxRotOrder)
{
    fbxDouble3 degrees(
        osg::RadiansToDegrees(radians.x()),
        osg::RadiansToDegrees(radians.y()),
        osg::RadiansToDegrees(radians.z()));
    return makeQuat(degrees, fbxRotOrder);
}
コード例 #16
0
ファイル: Program.cpp プロジェクト: nsmoooose/csp
void addRandomClouds(osg::Group* model, std::vector<Ref<CloudModel> >& clouds, osg::Vec3 dimensions, int count) {
	std::vector<Ref<CloudModel> >::size_type cloudIndex = 0;
	for(int i=0;i<count;++i, ++cloudIndex) {
		// Wrap around when there is no more clouds.
		if(cloudIndex >= clouds.size())
			cloudIndex = 0;

		float x = GenerateRandomNumber(0 - dimensions.x(), dimensions.x());
		float y = GenerateRandomNumber(0 - dimensions.y(), dimensions.y());
		float z = GenerateRandomNumber(0 - dimensions.z(), dimensions.z());

		osg::ref_ptr<osg::MatrixTransform> transformation = new osg::MatrixTransform();
		transformation->setMatrix(osg::Matrix::translate(x, y, z));
		transformation->addChild(clouds.at(cloudIndex)->getNode());
		model->addChild(transformation.get());
	}
}
コード例 #17
0
ファイル: VELOModel.cpp プロジェクト: albertgumi/tracking
void VELOModel::addTrack(osg::Vec3& v1, osg::Vec3& v2){
	float d = sqrt(pow(v2.x()-v1.x(), 2) + pow(v2.y()-v1.y(), 2) + pow(v2.z()-v1.z(), 2));
	
	osg::ref_ptr<osg::MatrixTransform> t2 = new osg::MatrixTransform;
	t2->setMatrix( osg::Matrix::scale(1.0f, 1.0f, d) );
	t2->addChild( _trackGeode.get() );
	
	osg::ref_ptr<osg::MatrixTransform> t3 = new osg::MatrixTransform;
	t3->setMatrix( osg::Matrix::rotate(osg::Vec3f(0.0f, 0.0f, 1.0f), v2 - v1) );
	t3->addChild( t2.get() );

	osg::ref_ptr<osg::MatrixTransform> t1 = new osg::MatrixTransform;
	t1->setMatrix( osg::Matrix::translate(osg::Vec3f(((v2.x() - v1.x()) / 2.0f) + v1.x(), ((v2.y() - v1.y()) / 2.0f) + v1.y(), ((v2.z() - v1.z()) / 2.0f) + v1.z())) );
	t1->addChild( t3.get() );

	tracks->addChild( t1.get() );
}
コード例 #18
0
ファイル: osgforest.cpp プロジェクト: yueying/osg
void ForestTechniqueManager::createTreeList(osg::Node* terrain,const osg::Vec3& origin, const osg::Vec3& size,unsigned int numTreesToCreate,TreeList& trees)
{

    float max_TreeHeight = sqrtf(size.length2()/(float)numTreesToCreate);
    float max_TreeWidth = max_TreeHeight*0.5f;

    float min_TreeHeight = max_TreeHeight*0.3f;
    float min_TreeWidth = min_TreeHeight*0.5f;

    trees.reserve(trees.size()+numTreesToCreate);


    for(unsigned int i=0;i<numTreesToCreate;++i)
    {
        Tree* tree = new Tree;
        tree->_position.set(random(origin.x(),origin.x()+size.x()),random(origin.y(),origin.y()+size.y()),origin.z());
        tree->_color.set(random(128,255),random(128,255),random(128,255),255);
        tree->_width = random(min_TreeWidth,max_TreeWidth);
        tree->_height = random(min_TreeHeight,max_TreeHeight);
        tree->_type = 0;

        if (terrain)
        {
            osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector =
                new osgUtil::LineSegmentIntersector(tree->_position,tree->_position+osg::Vec3(0.0f,0.0f,size.z()));

            osgUtil::IntersectionVisitor iv(intersector.get());

            terrain->accept(iv);

            if (intersector->containsIntersections())
            {
                osgUtil::LineSegmentIntersector::Intersections& intersections = intersector->getIntersections();
                for(osgUtil::LineSegmentIntersector::Intersections::iterator itr = intersections.begin();
                    itr != intersections.end();
                    ++itr)
                {
                    const osgUtil::LineSegmentIntersector::Intersection& intersection = *itr;
                    tree->_position = intersection.getWorldIntersectPoint();
                }
            }
        }

        trees.push_back(tree);
    }
}
コード例 #19
0
osg::Vec3 Particle_Viewer::fixPosition(osg::Vec3 position)
{
    osg::Vec3 fixPosition;
    fixPosition.x()=position.x();
    fixPosition.y()=position.z();
    fixPosition.z()=position.y();
    return fixPosition;
}
コード例 #20
0
ファイル: Uniform.cpp プロジェクト: aalex/osg
bool Uniform::getElement( unsigned int index, osg::Vec3& v3 ) const
{
    if( index>=getNumElements() || !isCompatibleType(FLOAT_VEC3) ) return false;
    unsigned int j = index * getTypeNumComponents(getType());
    v3.x() = (*_floatArray)[j];
    v3.y() = (*_floatArray)[j+1];
    v3.z() = (*_floatArray)[j+2];
    return true;
}
コード例 #21
0
float HfT_osg_Plugin01_ParametricSurface::abstand(osg::Vec3 startPickPos, int i)
{
    float x = (*mp_Points_Geom)[i].x() - startPickPos.x();
    float y = (*mp_Points_Geom)[i].y() - startPickPos.y();
    float z = (*mp_Points_Geom)[i].z() - startPickPos.z();

    float abst = (float)sqrt(x * x + y * y + z * z);
    return abst;
}
コード例 #22
0
ファイル: Cuboid.cpp プロジェクト: starjumper/Starjumper
TexturedCuboid::TexturedCuboid(const osg::Vec3 &from, const osg::Vec3 &size) :
    Cuboid(from, size)
{
    _textureDrawable = new osg::Geometry();

    osg::Vec3Array *pyramidVertices = new osg::Vec3Array();
    {
        pyramidVertices->push_back( from + osg::Vec3(0, 0, size.z()));
        pyramidVertices->push_back( from + osg::Vec3(size.x(), 0, size.z()));
        pyramidVertices->push_back( from + osg::Vec3(size.x(), size.y(), size.z()));
        pyramidVertices->push_back( from + osg::Vec3(0, size.y(), size.z()));
    }

    _textureDrawable->setVertexArray( pyramidVertices );

    osg::DrawElementsUInt *face = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
    face->push_back(0);
    face->push_back(1);
    face->push_back(2);
    face->push_back(3);
    
    _textureDrawable->addPrimitiveSet(face);
        
    osg::Vec2Array* texcoords = new osg::Vec2Array(4);
    {
        (*texcoords)[0].set(size.x(), 0.0f);
        (*texcoords)[1].set(0.0f, 0.0f);
        (*texcoords)[3].set(size.x(), size.y() / 3.0f);
        (*texcoords)[2].set(0.0f,  size.y() / 3.0f); 

        _textureDrawable->setTexCoordArray(0, texcoords);
    }
             
    _texture = new osg::Texture2D;
    _texture->setDataVariance(osg::Object::DYNAMIC); 
    _texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT); 
    _texture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);

    osg::StateSet* stateSet = _textureDrawable->getOrCreateStateSet();
    stateSet->setTextureAttributeAndModes(0, _texture, osg::StateAttribute::ON);
    
    _textureDrawable->setStateSet(stateSet);
    addDrawable(_textureDrawable);
}
コード例 #23
0
ファイル: HogBoxMaterial.cpp プロジェクト: crycrane/hogbox
//
// Set the lighting material attributes for this osgmaterial
//
void HogBoxMaterial::SetMaterial(osg::Vec3 ambi, osg::Vec3 diffuse, osg::Vec3 spec, double exp)
{
	//store the material values
	_ambientColour = ambi;
	osg::Vec4 ambi4 = osg::Vec4(ambi.x(), ambi.y(), ambi.z(), _alpha);
	_diffuseColor = diffuse;
	osg::Vec4 diffuse4 = osg::Vec4(diffuse.x(), diffuse.y(), diffuse.z(), _alpha);
	_specularColour = spec;
	osg::Vec4 spec4 = osg::Vec4(spec.x(), spec.y(), spec.z(), _alpha);
	_shininess = exp;

	//set the ambient colour
	_material->setAmbient(_lightFace, ambi4);
	//set the diffuse colour
	_material->setDiffuse(_lightFace, diffuse4);
	//set the specular colour
	_material->setSpecular(_lightFace, spec4);
	//set the shininess
	_material->setShininess(_lightFace, _shininess);

	_material->setColorMode(osg::Material::OFF);

	//apply the material to the stateset
#ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE
	_stateset->setAttributeAndModes(_material.get(), osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
	//normalise
	_stateset->setMode( GL_NORMALIZE, osg::StateAttribute::ON);
#endif
	
	this->SetTwoSidedLightingEnabled(_backFaceLit);


	
	//set hogbox material uniforms
	_ambientColourUni->set(_ambientColour);
	_diffuseColourUni->set(_diffuseColor);
	_specularColourUni->set(_specularColour);
	_specularExpUni->set((float)_shininess);
	
	_alphaUni->set((float)_alpha);
	
	_twoSidedUni->set((int)_backFaceLit);

}
コード例 #24
0
void DataOutputStream::writeVec3(const osg::Vec3& v){

//	std::cout << "write " << _ostream->tellp() << std::endl;

    writeFloat(v.x());
    writeFloat(v.y());
    writeFloat(v.z());

    if (_verboseOutput) std::cout<<"read/writeVec3() ["<<v<<"]"<<std::endl;
}
コード例 #25
0
ファイル: ReaderWriterOBJ.cpp プロジェクト: joevandyk/osg
inline osg::Vec3 ReaderWriterOBJ::transformNormal(const osg::Vec3& vec, const bool rotate) const
{
    if(rotate==true)
    {
        return osg::Vec3(vec.x(),-vec.z(),vec.y());
    }
    else
    {
        return vec;
    }
}
コード例 #26
0
bool ContourLayer::getValue(unsigned int i, unsigned int j, osg::Vec3& value) const
{
    if (!_tf) return false;

    const osg::Vec4& v = _tf->getPixelValue(i);
    value.x() = v.x();
    value.y() = v.y();
    value.z() = v.z();

    return true;
}
コード例 #27
0
void ComputeBoundingBoxByRotation(osg::BoundingBox & InOut,osg::Vec3 BBCenter,float BBSize,osg::Matrixd Rotation)
{
	osg::BoundingBox bb;
	bb.set(BBCenter.x()-BBSize,BBCenter.y()-BBSize,BBCenter.z()-BBSize,BBCenter.x()+BBSize,BBCenter.y()+BBSize,BBCenter.z()+BBSize);
    osg::BoundingBox Tbb;
	for(unsigned int i=0;i<8;i++)
    {
        Tbb.expandBy(Rotation.preMult(bb.corner(i)));
    }
	InOut.set(Tbb.xMin(),Tbb.yMin(),Tbb.zMin(),Tbb.xMax(),Tbb.yMax(),Tbb.zMax());
}
コード例 #28
0
ファイル: VELOModel.cpp プロジェクト: albertgumi/tracking
void VELOModel::addHit(osg::Vec3& coords){

	osg::ref_ptr<osg::MatrixTransform> t1 = new osg::MatrixTransform;
	t1->setMatrix( osg::Matrix::translate(
		coords.x() - HIT_RADIUS,
		coords.y(),
		coords.z()) );
	t1->addChild( _hitGeode.get() );

	hits->addChild( t1.get() );
}
コード例 #29
0
ファイル: Vehicle.cpp プロジェクト: HOUWEI/VirtualCity
double CVehicle::calculateAngle(osg::Vec3 vecA,osg::Vec3 vecB)
{
	double angle,angleA,angleB;

	angle = acos(vecA * vecB / (vecA.length() * vecB.length()));
	if( angle < 0.0001)
	{
		angle = 0.0;
		return angle;
	}

	//求得vecA vecB分别与x轴正向的夹角
	angleA =  acos( vecA.x() / vecA.length() );   
	if( vecA.y() >= 0 )
		angleA = angleA;
	if( vecA.y() < 0 )
		angleA = 2.0 * osg::PI - angleA;


	angleB =  acos( vecB.x() / vecB.length() );   
	if( vecB.y() >= 0 )
		angleB = angleB;
	if( vecB.y() < 0 )
		angleB = 2.0 * osg::PI - angleB;


	//得到两向量间的夹角,通过angleA angleB的关系来判断旋转的方向

	if( angleA > angleB && (angleA - angleB) <= osg::PI )
		angle = -1.0 * acos(vecA * vecB / (vecA.length() * vecB.length()));
	if( angleA > angleB && (angleA - angleB) > osg::PI)
		angle = acos(vecA * vecB / (vecA.length() * vecB.length())) ;


	if( angleA < angleB && (angleB - angleA) <= osg::PI )
		angle = acos(vecA * vecB / (vecA.length() * vecB.length()));
	if( angleA < angleB && (angleB - angleA) > osg::PI)
		angle = -1.0 *  acos(vecA * vecB / (vecA.length() * vecB.length()))  ;

	return angle;
}
コード例 #30
0
void PanoManipulator::JumpTo(osg::Vec3 NewSpatialPos)
{
PartialVertexDEM JumpLoc;
JumpLoc.Lat = NewSpatialPos.y();
JumpLoc.Lon = NewSpatialPos.x();
JumpLoc.Elev = NewSpatialPos.z();
MasterScene.DegToCart(JumpLoc);

_eye[0] = JumpLoc.XYZ[0];
_eye[1] = JumpLoc.XYZ[1];
_eye[2] = JumpLoc.XYZ[2];
} // PanoManipulator::JumpTo