|
楼主 |
发表于 2009-11-4 09:40:27
|
显示全部楼层
不好意思,感冒了,昨天没上班,不过放心,肯定不会是H1N1的
关于第一个问题,1280*1024,应该不是设置的图形上下文吧,因为我设置这里的代码如下:
RECT rect;
::GetWindowRect(m_hWnd, &rect);
// Init the GraphicsContext Traits
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
// Init the Windata Variable that holds the handle for the Window to display OSG in.
osg::ref_ptr<osg::Referenced> windata = new osgViewer::GraphicsWindowWin32::WindowData(m_hWnd);
// Setup the traits parameters
traits->x = 0;
traits->y = 0;
traits->width = rect.right - rect.left;
traits->height = rect.bottom - rect.top;
traits->windowDecoration = false;
traits->doubleBuffer = true;
traits->sharedContext = 0;
traits->setInheritedWindowPixelFormat = true;
traits->inheritedWindowData = windata;
// Create the Graphics Context
osg::GraphicsContext* gc = osg::GraphicsContext::createGraphicsContext(traits.get());
// Init a new Camera (Master for this View)
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
// Assign Graphics Context to the Camera
camera->setGraphicsContext(gc);
// Set the viewport for the Camera
camera->setViewport(new osg::Viewport(traits->x, traits->y, traits->width, traits->height));
// Add the Camera to the Viewer
viewer_->addSlave(camera.get());
// Add the Camera Manipulator to the Viewer
viewer_->setCameraManipulator(keyswitch_.get());
// Set the Scene Data
viewer_->setSceneData(root_.get());
// Realize the Viewer
viewer_->realize();
// Correct aspect ratio
double fovy,aspectRatio,z1,z2;
viewer_->getCamera()->getProjectionMatrixAsPerspective(fovy,aspectRatio,z1,z2);
aspectRatio=double(traits->width)/double(traits->height);
viewer_->getCamera()->setProjectionMatrixAsPerspective(fovy,aspectRatio,z1,z2);
viewer_->setKeyEventSetsDone(0);
viewer_->addEventHandler(new SimpleTooltipHandler(viewer_));
然后我在跟踪的时候确实不是1280*1024的。
关于第2个问题,请问要如何设置,如何操作?
关于第3个问题,我在最简单的使用的时候,发现getX()和getY()的值不是-1到1之间的,代码如下:
class TooltipHandler : public GUIEventHandler
{
public:
virtual bool handle(const GUIEventAdapter& ea, GUIActionAdapter& aa)
{
if (ea.getEventType() != GUIEventAdapter::MOVE)
return false;
const float x = ea.getX();
const float y = ea.getY();
text_->setPosition(Vec3(x, y, -1));
char s[30];
sprintf(s, "%.f,%.f", x, y);
text_->setText(s);
return false;
}
public:
TooltipHandler(ref_ptr<osgText::Text>& text) : text_(text) {}
private:
ref_ptr<osgText::Text> text_;
};
int main()
{
ref_ptr<Geode> geode = new Geode;
ref_ptr<Geometry> pyramidGeometry = new Geometry;
geode->addDrawable(pyramidGeometry.get());
osg::Vec3Array* vertices = new osg::Vec3Array;
vertices->push_back( osg::Vec3( 0, 0, 0) ); // 左前
vertices->push_back( osg::Vec3(10, 0, 0) ); // 右前
vertices->push_back( osg::Vec3(10,10, 0) ); // 右后
vertices->push_back( osg::Vec3( 0,10, 0) ); // 左后
vertices->push_back( osg::Vec3( 5, 5,10) ); // 塔尖
pyramidGeometry->setVertexArray(vertices);
osg:rawElementsUInt* pyramidBase = new osg::DrawElementsUInt(osg:rimitiveSet:UADS, 0);
pyramidBase->push_back(3);
pyramidBase->push_back(2);
pyramidBase->push_back(1);
pyramidBase->push_back(0);
pyramidGeometry->addPrimitiveSet(pyramidBase);
osg::DrawElementsUInt* pyramidFaceOne = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0);
pyramidFaceOne->push_back(0);
pyramidFaceOne->push_back(1);
pyramidFaceOne->push_back(4);
pyramidGeometry->addPrimitiveSet(pyramidFaceOne);
osg::DrawElementsUInt* pyramidFaceTwo = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0);
pyramidFaceTwo->push_back(1);
pyramidFaceTwo->push_back(2);
pyramidFaceTwo->push_back(4);
pyramidGeometry->addPrimitiveSet(pyramidFaceTwo);
osg::DrawElementsUInt* pyramidFaceThree = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0);
pyramidFaceThree->push_back(2);
pyramidFaceThree->push_back(3);
pyramidFaceThree->push_back(4);
pyramidGeometry->addPrimitiveSet(pyramidFaceThree);
osg::DrawElementsUInt* pyramidFaceFour =
new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0);
pyramidFaceFour->push_back(3);
pyramidFaceFour->push_back(0);
pyramidFaceFour->push_back(4);
pyramidGeometry->addPrimitiveSet(pyramidFaceFour);
osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f) ); //索引0 红色
colors->push_back(osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f) ); //索引1 绿色
colors->push_back(osg::Vec4(0.0f, 0.0f, 1.0f, 1.0f) ); //索引2 蓝色
colors->push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f) ); //索引3 白色
osg::TemplateIndexArray
<unsigned int, osg::Array::UIntArrayType,4,4> *colorIndexArray;
colorIndexArray =
new osg::TemplateIndexArray<unsigned int, osg::Array::UIntArrayType,4,4>;
colorIndexArray->push_back(0); // vertex 0 assigned color array element 0
colorIndexArray->push_back(1); // vertex 1 assigned color array element 1
colorIndexArray->push_back(2); // vertex 2 assigned color array element 2
colorIndexArray->push_back(3); // vertex 3 assigned color array element 3
colorIndexArray->push_back(0); // vertex 4 assigned color array element 0
pyramidGeometry->setColorArray(colors);
pyramidGeometry->setColorIndices(colorIndexArray);
pyramidGeometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
ref_ptr<Group> root = new Group;
root->addChild(geode.get());
ref_ptr<rojection> projection = new Projection;
projection->setMatrix(Matrix:rtho2D(0, 1024, 0, 768));
root->addChild(projection.get());
ref_ptr<MatrixTransform> mv = new MatrixTransform;
mv->setMatrix(Matrix::identity());
mv->setReferenceFrame(Transform::ABSOLUTE_RF);
projection->addChild(mv.get());
ref_ptr<Geode> geo = new Geode;
mv->addChild(geo.get());
ref_ptr<StateSet> ss = geo->getOrCreateStateSet();
ss->setMode(GL_DEPTH_TEST, StateAttribute::OFF);
ss->setRenderingHint(StateSet::TRANSPARENT_BIN);
ss->setRenderBinDetails(11, "RenderBin");
ref_ptr<osgText::Text> text = new osgText::Text;
text->setText("Hello World!");
text->setAxisAlignment(osgText::Text::SCREEN);
text->setPosition(Vec3(50, 50, -1.5));
geo->addDrawable(text.get());
osgViewer::Viewer viewer;
viewer.setSceneData(root.get());
viewer.addEventHandler(new TooltipHandler(text));
viewer.run();
}
其中的图形就是从osg网站教程上抄下来的,那个金字塔的图形
请指教,谢谢 |
|