查看: 1117|回复: 3

如何在屏幕靠右位置画一个矩形

[复制链接]

该用户从未签到

发表于 2013-10-30 14:35:05 | 显示全部楼层 |阅读模式
本帖最后由 tnyysnow 于 2013-10-30 17:32 编辑

初学者,求教各位大神一个问题
使用PositionAttitudeTransform后没有效果啊。

程序如下:

#include <Windows.h>
#include <osgViewer/Viewer>
#include <osg/Node>
#include <osg/Geode>
#include <osg/Group>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgUtil/Optimizer>
#include <osg/MatrixTransform>
#include <osg/ShapeDrawable>
#include <osg/PositionAttitudeTransform>

using namespace std;


int _tmain(int argc, char* argv[])
{
        osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer();
        osg::ref_ptr<osg::Group> root = new osg::Group();
        osg::ref_ptr<osg::Geode> geode = new osg::Geode();
        osg::ref_ptr<osg::Geometry> geom = new osg::Geometry();
        osg::ref_ptr<osg::Vec3Array> v = new osg::Vec3Array();
        v->push_back(osg::Vec3(0.0f, 0.0f, 0.0f));
        v->push_back(osg::Vec3(1.0f, 0.0f, 0.0f));
        v->push_back(osg::Vec3(1.0f, 0.0f, 1.0f));
        v->push_back(osg::Vec3(0.0f, 0.0f, 1.0f));
        geom->setVertexArray(v.get());

        //初始化位置变换节点
        osg:ositionAttitudeTransform* pc1 = new osg::PositionAttitudeTransform();

        // 初始化一个Vec3实例,用于改变模型在场景中的位置
        osg::Vec3 pyramidTwoPosition(15,0,0);
        pc1->setPosition( pyramidTwoPosition );

        geom->addPrimitiveSet(new osg:rawArrays(osg::PrimitiveSet:UADS,0,4));
        geode->addDrawable(geom.get());

        root->addChild(pc1);
        pc1->addChild(geode);

        osgUtil::Optimizer optimizer;
        optimizer.optimize(root.get());
        viewer->setSceneData(root.get());
        viewer->realize();
        viewer->run();
        return 0;

}

该用户从未签到

发表于 2013-10-31 20:29:59 | 显示全部楼层
帮顶!

该用户从未签到

发表于 2013-11-1 09:40:00 | 显示全部楼层
如果您想要以窗口坐标为基准去绘制矩形的话,建议在一个Projection和ViewMatrix都固定的HUDCamera下完成,这样更容易控制也不会因为主ViewMatrix的变化而变化

该用户从未签到

 楼主| 发表于 2013-11-4 09:32:21 | 显示全部楼层
array 发表于 2013-11-1 09:40
如果您想要以窗口坐标为基准去绘制矩形的话,建议在一个Projection和ViewMatrix都固定的HUDCamera下完成,这 ...

多谢大神提醒
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

联系我们

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