i implant this method into osg .   code is following:

class ocsSurfaceShape : public osg::Drawable{
public:
ocsSurfaceShape(){};
ocsSurfaceShape( const ocsSurfaceShape& copy,
                              const osg::CopyOp&
                              copyop=osg::CopyOp::SHALLOW_COPY )
                             : osg::Drawable(copy, copyop) {
}

void pushProjectionOffest(double offset) const ; 

void popProjectionOffest() const;
};


void ocs::ocsSurfaceShape::pushProjectionOffest
( double offset ) const
{
float* pm = new float[16];
glGetFloatv(GL_PROJECTION_MATRIX, pm);
pm[10] *= offset != 0 ? offset : 0.99; // TODO: See Lengyel 2 ed. Section 9.1.2 
to compute optimal offset

glPushAttrib(GL_TRANSFORM_BIT);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadMatrixf(pm);
}

void ocs::ocsSurfaceShape::popProjectionOffest() const
{
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glPopAttrib();
}

//sub class of  surface Shape

class lineDrawable : public ocsSurfaceShape{
public:
lineDrawable();
lineDrawable(ocs::ocsLine& line);
lineDrawable( const lineDrawable& copy,
const osg::CopyOp&
copyop=osg::CopyOp::SHALLOW_COPY )
: ocsSurfaceShape(copy, copyop) 
{
_line = copy._line;
}

META_Object( osg, lineDrawable);

virtual BoundingBox computeBound() const;

virtual void drawImplementation( RenderInfo& renderInfo ) const;

private:
mutable ocs::ocsLine _line;
};



void ocs::lineDrawable::drawImplementation( RenderInfo& renderInfo ) const
{
std::vector<ocs::Vec3> list = _line.getTesselatePoints();
ocsAttributes& attr = _line.getAttribute();
float color[4];
attr.getColor(color);
osg::GLBeginEndAdapter& gl =
renderInfo.getState()->getGLBeginEndAdapter();
gl.Color4f(color[0],color[1],color[2],color[3]);
pushProjectionOffest(0.95);                                    //change the 
project matrix here 
gl.Begin(GL_LINE_STRIP);
   for (unsigned int u = 0; u < list.size(); u++){
   gl.Vertex3f(list[u].x(),list[u].y(),list[u].z());    
   }
gl.End();
popProjectionOffest();                                            //restore it 
}

does it the best way?   it's wierd that sometims the line is  disappeared.   
other question is  the GL API 

glPushAttrib(GL_TRANSFORM_BIT);  in pushProjectionOffest is identical to 
calling 

osg::GLBeginEndAdapter& gl 's method ?




Shawl

发件人: wh_xiexing
发送时间: 2012-10-29 16:50
收件人: osg-users
主题: Re: [osg-users] how to change project matrix temporarily?;
hi Robert osifield
    i am writing an editor which can add polylines and polygons on the mesh 
model(mountains model).  the lines and polygons must follow the terrain .

so i tessellate the polylines into many parts .   because the mesh is irregular 
, unlike the GIS .   some part of the line segment is above the terrain .  
other 

other is under the terrain .    so i want to put the surface shapes (polylines  
polygons ) near to the camera .   worldwind give a method as the following 

code show.    but i don't know how to do that in the OSG.






Shawl

From: Robert Osfield
Date: 2012-10-29 16:30
To: OpenSceneGraph Users
Subject: Re: [osg-users] how to change project matrix temporarily?;
Hi Shawl,

Could you explain for what purpose you need to temporarily modify the
projection matrix, this has a huge baring on how you will want to go
about it.

The OSG has an osg::Projection node that allows you to override the
project matrix for the subgraph that you attach below the Projection
Node, and the osg::Camera node that allows you to modify the
projection and view matrices, and there there is slave Camera's at the
viewer level, and finally cull callbacks that you can use to modify
the modelview and projection matrices along with many other things.
As you see there are plenty of options, which to recommend I can't say
as you haven't yet given the context of the problem you are trying to
solve.

Robert.

On 29 October 2012 00:21, wh_xiexing <wh_xiex...@sina.com> wrote:
> i want to implement the same effect of the following code using open scene
> graph. can it be possiable?
>
> public void pushProjectionOffest(Double offset)
>     {
>         // Modify the projection transform to shift the depth values
> slightly toward the camera in order to
>         // ensure the lines are selected during depth buffering.
>         GL gl = this.getGL();
>
>         float[] pm = new float[16];
>         gl.glGetFloatv(GL.GL_PROJECTION_MATRIX, pm, 0);
>         pm[10] *= offset != null ? offset : 0.99; // TODO: See Lengyel 2 ed.
> Section 9.1.2 to compute optimal offset
>
>         gl.glPushAttrib(GL.GL_TRANSFORM_BIT);
>         gl.glMatrixMode(GL.GL_PROJECTION);
>         gl.glPushMatrix();
>         gl.glLoadMatrixf(pm, 0);
>     }
>
>  public void popProjectionOffest()
>     {
>         GL gl = this.getGL();
>
>         gl.glMatrixMode(GL.GL_PROJECTION);
>         gl.glPopMatrix();
>         gl.glPopAttrib();
>     }
>
> ________________________________
> Shawl
>
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to