查看: 2040|回复: 3

世界坐标投影到屏幕坐标。。camer节点上添加的是两个公告板

[复制链接]

该用户从未签到

发表于 2009-8-10 16:38:16 | 显示全部楼层 |阅读模式
执行这段代码之后屏幕上什么也没得 使用text文本测试 camera的设置时没问题的 请各位大大看看!!附上代码
#include <osg/Node>
#include <osg/Geometry>
#include <osg/Notify>
#include <osg/MatrixTransform>
#include <osg/Texture2D>
#include <osg/Billboard>
#include <osg/LineWidth>
#include <osgGA/TrackballManipulator>
#include <osgGA/FlightManipulator>
#include <osgGA/DriveManipulator>
#include <osgDB/Registry>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osg/Camera>
#include <osg/Material>
#include <osg/Depth>
#include <osgText/Text>
#include "South.h"
typedef std::vector< osg::ref_ptr<osg::Image> > ImageList;
osg:rawable* createSquare(const osg::Vec3& corner,const osg::Vec3& width,const osg::Vec3& height, osg::Image* image=NULL)
{
    osg::Geometry* geom = new osg::Geometry;
    osg::Vec3Array* coords = new osg::Vec3Array(4);
    (*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] = 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,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->addPrimitiveSet(new osg::DrawArrays(osg:rimitiveSet:UADS,0,4));
    if (image)
    {
        osg::StateSet* stateset = new osg::StateSet;
        osg::Texture2D* texture = new osg::Texture2D;
        texture->setImage(image);
        stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
        geom->setStateSet(stateset);
    }
    return geom;
}
osg::Camera* createModel()
{
    osg::Camera* camera = new osg::Camera;
    camera->setProjectionMatrix(osg::Matrix:rtho2D(0,1024,0,768));
    camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
    camera->setViewMatrix(osg::Matrix::identity());
    camera->setClearMask(GL_DEPTH_BUFFER_BIT);
    camera->setRenderOrder(osg::Camera::POST_RENDER);//设置渲染顺序放在最后渲染那
    camera->setAllowEventFocus(false);
  
osg::Group* root = new osg::Group();
   osg::Billboard* center = new osg::Billboard();
        center->setMode(osg::Billboard::POINT_ROT_WORLD);
    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("Images/clockface.JPG")),
      osg::Vec3(150.0f,500.0f,0.0f));
       
        osg::Billboard* center1 = new osg::Billboard();
        center1->setMode(osg::Billboard::POINT_ROT_EYE);
        center1->addDrawable(
        createSquare(osg::Vec3(0.0f,-0.00001f,0.0f),osg::Vec3(0.1f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,0.1f),osgDB::readImageFile("Images/north.png")),
       osg::Vec3(150.0f,500.0f,0.0f));
        root->addChild(center);
        root->addChild(center1);
        camera->addChild(root);

    return camera;
}
int main(int, char**)
{
    osgViewer::Viewer viewer;
        osg::Vec3d position,center,up;
    osg::Group* root = new osg::Group();
        root->addChild(createModel());
        root->addChild(osgDB::readNodeFile("cow.osg"));
        viewer.setSceneData(root);
        viewer.realize();
    return viewer.run();
}

该用户从未签到

发表于 2009-8-10 18:51:59 | 显示全部楼层
应该是你的正交矩阵设置不对~~~不清楚你究竟要实现什么,,,使用布告板又使用HUD~~~~~~

该用户从未签到

 楼主| 发表于 2009-8-11 09:18:16 | 显示全部楼层
是的 矩阵设置的不对。。。坐标也有问题。。。
   检查出来了 。。。
  要坐一个指南针。。图贴上去了 。。但是背景色没有被滤掉 怎么滤掉背景色、、

该用户从未签到

发表于 2009-8-11 11:43:49 | 显示全部楼层
camera->setClearMask(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表