Thank you~
在2008-04-16,Guy <[EMAIL PROTECTED]> 写道:
This is the osgdistortion code of osg1.2. I added the background image. I think
you can use it with my previous explanation to get the result you want.
Good luck,
Guy.
From:[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED]
Sent: Wednesday, April 16, 2008 3:06 PM
To:OpenSceneGraph Users
Subject: Re: [osg-users] Examples for using image as a background
Can you give a integrated example ?Thank you~
在2008-04-15,Guy <[EMAIL PROTECTED]> 写道:
Hello,
I can only give you my implementation for image background, but I use
it with a static image. I guess if you dig into the osgmovie example and
use it together with my implementation for static image you could get
what you ask for.
?
So here is how it's done: (it's pretty simple)
1. Add a camera and under the camera, add as a child the root of the
scene you want to see. (This is always what you do, but we have to start
somewhere).
2. Create background object. (this object will display the static image
or in your case the video):
2.1 create rectangular geometry that will be projected orthographically
onto the camera.
?
?????????????? bgGeometry = new osg::Geometry();
?????????????? bgGeometry->setName("CameraBackground");
?????????????? bgGeometry->setSupportsDisplayList(false);
??????????????
?????????????? float height = 2.0f;
?????????????? float width = 2.0f;
?????????????? int noSteps = 30;
?????????????? float l = -(width*0.5f);
?????????????? float b = -(height*0.5f);
?????????????? osg::Vec3 origin(l,b,dist);
?????????????? osg::Vec3 xAxis(1.0f,0.0f,0.0f);
?????????????? osg::Vec3 yAxis(0.0f,1.0f,0.0f);
?????????????? osg::Vec3 zAxis(0.0f,0.0f,1.0f);
?????????????? vertices = new osg::Vec3Array;
?????????????? osg::Vec2Array* texcoords = new osg::Vec2Array;
?????????????? osg::Vec4Array* colors = new osg::Vec4Array;
?
?????????????? osg::Vec3 bottom = origin;
?????????????? osg::Vec3 dx = xAxis*(width/((float)(noSteps-1)));
?????????????? osg::Vec3 dy = yAxis*(height/((float)(noSteps-1)));
?
?????????????? osg::Vec2 bottom_texcoord(0.0f,0.0f);
?????????????? osg::Vec2 dx_texcoord(1.0f/(float)(noSteps-1),0.0f);
?????????????? osg::Vec2 dy_texcoord(0.0f,1.0f/(float)(noSteps-1));
?
?????????????? osg::Vec3 cursor = bottom;
?????????????? osg::Vec2 texcoord = bottom_texcoord;
?????????????? int i,j;
?????????????? for(i=0;i<noSteps;++i)
?????????????? {
?????????????????????????????? osg::Vec3 cursor = bottom+dy*(float)i;
?????????????????????????????? osg::Vec2 texcoord =
bottom_texcoord+dy_texcoord*(float)i;
?????????????????????????????? for(j=0;j<noSteps;++j)
?????????????????????????????? {
????????????????????????????????????????????? vertices->push_back(cursor);
????????????????????????????????????????????? texcoords->push_back(texcoord);
??????????????
colors->push_back(osg::Vec4(0.0f,0.0f,0.0f,1.0f));
?
????????????????????????????????????????????? cursor += dx;
????????????????????????????????????????????? texcoord += dx_texcoord;
?????????????????????????????? }
?????????????? }
?
?????????????? // pass the created vertex array to the points geometry object.
?????????????? bgGeometry->setVertexArray(vertices.get());
?
?????????????? bgGeometry->setColorArray(colors);
?????????????? bgGeometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
?
?????????????? bgGeometry->setTexCoordArray(0,texcoords);
?
?
?????????????? for(i=0;i<noSteps-1;++i)
?????????????? {
?????????????????????????????? osg::DrawElementsUShort* elements = new
osg::DrawElementsUShort(osg::PrimitiveSet::QUAD_STRIP);
?????????????????????????????? for(j=0;j<noSteps;++j)
?????????????????????????????? {
?????????????????????????????????????????????
elements->push_back(j+(i+1)*noSteps);
?????????????????????????????????????????????
elements->push_back(j+(i)*noSteps);
?????????????????????????????? }
?????????????????????????????? bgGeometry->addPrimitiveSet(elements);
?????????????? }
?
2.2 Set the background object StateSet
?????????????? osg::StateSet* stateset = bgGeometry->getOrCreateStateSet();
?????????????? // set the blending mode to res = TEX;
?????????????? osg::TexEnv* te = new osg::TexEnv;
?????????????? te->setMode(osg::TexEnv::REPLACE);
?????????????? stateset->setTextureAttributeAndModes(0, te,
osg::StateAttribute::ON);
?
?????????????? stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
??????????????
2.3 make sure it rendered first
?????????????? // force it to be rendered first
?????????????? stateset->setRenderBinDetails(-10,"RenderBin");
?
2.4 make sure the background never wins ZBuffer tests
?
?????????????? // make the object update the depth buffer as the farthest in
the
?????????????? // scene with no regard to the vertices actual z value
?????????????? osg::Depth* depth = new osg::Depth;
?????????????? depth->setFunction(osg::Depth::ALWAYS);
?????????????? depth->setRange(1.0,1.0);??
?????????????? stateset->setAttributeAndModes(depth, osg::StateAttribute::ON );
?
2.5 add it to geode
?????????????? osg::Geode* geode = new osg::Geode();
?????????????? geode->addDrawable(bgGeometry.get());
2.6 make sure the background will occupy the whole camera view
?????????????? // create the hud.
?????????????? osg::MatrixTransform* modelview_abs = new osg::MatrixTransform;
?????????????? modelview_abs->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
?????????????? modelview_abs->setMatrix(osg::Matrix::identity());
?????????????? modelview_abs->addChild(geode);
?
?????????????? osg::Projection* projection = new osg::Projection;
??????????????
projection->setMatrix(osg::Matrix::ortho2D(l,l+width,b,b+height));
?????????????? projection->addChild(modelview_abs);
?
3. Add the object to the camera. The object is the variable "projection"
from 2.6
?
4. Set the background geometry texture
??????????????
bgGeometry->getOrCreateStateSet()->setTextureAttributeAndModes(0,
?????????????????????????????? tex.get(), osg::StateAttribute::ON);
?
Now, if you continuously change the texture of the background you can
get your movie.
?
Note that the variables "dist" "width" and "height" does affect the
vertices coordinates for fog calculations for example.
?
Hope it helps,
Guy.
?
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Thrall,
Bryan
Sent: Thursday, April 10, 2008 6:58 PM
To: OpenSceneGraph Users
Subject: Re: [osg-users] Examples for using image as a background
?
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of
> Judie Stanley?
>
> I have searched and see there is such a thing as a
> osg::ImageBackground object. However, I searched the osg solution
> (osg 2.0) and nothing was found has the name changed??
>
> http://www.opensg.org/doc-1.6.0/classosg_1_1ImageBackground.html
>
?
Note this is not the OpenSceneGraph website; it is for OpenSG. The
OpenSceneGraph documentation is at
http://www.openscenegraph.org/projects/osg/wiki/Support
?
--
Bryan Thrall
FlightSafety International
[EMAIL PROTECTED]
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or
g
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
蒙牛以领先责任创4年至高荣誉 权威数据为蒙牛加冕_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org