可把VSG 物体绘制分为5个步骤:
(1)状态设置,由vrState 类完成。主要代码为:
vrState *pState=new vrState;
vrAlphaBlend::Element alphaBlendElement;
alphaBlendElement.m_enable=true;
pState->setElement(vrAlphaBlend::Element::Id,&alphaBlendElement);
(2)物体的绘制,由vrGeometry 类完成。主要代码为:
vrGeometry *pRGrom=new vrGeometry;
vuVec4<float> *color=vuAllocArray<vuVec4<float> >::malloc(1);
color[0].set(1.0f,1.0f,0.0f,1.0f);
vuVec3<float> *vertex=vuAllocArray<vuVec3<float> >::malloc(4);
vertex[0].set(-0.5f,-0.5f,0.0f);
vertex[1].set(0.5f,-0.5f,0.0f);
vertex[2].set(-0.5f,-0.3f,0.0f);
vertex[3].set(0.5f,-0.3f,0.0f);
pRGrom->setPrimitive(vrGeometry::PRIMITIVE_LINE);
pRGrom->setNumPrimitives(2);
pRGrom->setColors(color,vrGeometry::BINDING_OVERALL);(www.daowen.com)
pRGrom->setVertices(vertex);
(3)用vsGeometry 包装vrGeometry。主要代码为:
vsGeometry *pSGeom=new vsGeometry;
pSGeom->setGeometry(pRGrom);
pSGeom->setState(pState);
(4)将vsGeometry 作为子物体加到vpTransform 中。主要代码为:
vpTransform *pTrans =new vpTransform();
pTrans->setTranslate(2360.000000,2490.000000,3.000000);
pTrans->setRotate(0.000000,0.000000,0.000000);
pTrans->setScale(10.000000,10.000000,10.000000);
pTrans->insert_child(pSGeom,pTrans->end_child());
pTrans->ref();
(5)vpTransform 作为孩子添加到场景中。主要代码为:
vpScene* Scene=(vpScene*)vpScene::find("myScene");
Scene->addChild(pTrans);
下一节将会详细展示VSG 绘图的完整过程。
免责声明:以上内容源自网络,版权归原作者所有,如有侵犯您的原创版权请告知,我们将尽快删除相关内容。