• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ VertexBufferAccessor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中VertexBufferAccessor的典型用法代码示例。如果您正苦于以下问题:C++ VertexBufferAccessor类的具体用法?C++ VertexBufferAccessor怎么用?C++ VertexBufferAccessor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了VertexBufferAccessor类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: Node

//----------------------------------------------------------------------------
Node* RoughPlaneSolidBox::CreateBox ()
{
    mBox = new0 Node();

    float xExtent = (float)mModule.XLocExt;
    float yExtent = (float)mModule.YLocExt;
    float zExtent = (float)mModule.ZLocExt;

    VertexFormat* vformat = VertexFormat::Create(2,
        VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
        VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT3, 0);

    StandardMesh sm(vformat);
    VertexColor3Effect* effect = new0 VertexColor3Effect();
    VertexBufferAccessor vba;
    Transform transform;
    TriMesh* face;
    int i;

    // +z face
    Float3 red(1.0f, 0.0f, 0.0f);
    transform.SetTranslate(APoint(0.0f, 0.0f, zExtent));
    sm.SetTransform(transform);
    face = sm.Rectangle(2, 2, xExtent, yExtent);
    vba.ApplyTo(face);
    for (i = 0; i < 4; ++i)
    {
        vba.Color<Float3>(0, 0) = red;
        vba.Color<Float3>(0, 1) = red;
        vba.Color<Float3>(0, 2) = red;
        vba.Color<Float3>(0, 3) = red;
    }
    face->SetEffectInstance(effect->CreateInstance());
    mBox->AttachChild(face);

    // -z face
    Float3 darkRed(0.5f, 0.0f, 0.0f);
    transform.SetTranslate(APoint(0.0f, 0.0f, -zExtent));
    transform.SetRotate(HMatrix(AVector::UNIT_Y, AVector::UNIT_X,
        -AVector::UNIT_Z, APoint::ORIGIN, true));
    sm.SetTransform(transform);
    face = sm.Rectangle(2, 2, yExtent, xExtent);
    vba.ApplyTo(face);
    for (i = 0; i < 4; ++i)
    {
        vba.Color<Float3>(0, 0) = darkRed;
        vba.Color<Float3>(0, 1) = darkRed;
        vba.Color<Float3>(0, 2) = darkRed;
        vba.Color<Float3>(0, 3) = darkRed;
    }
    face->SetEffectInstance(effect->CreateInstance());
    mBox->AttachChild(face);

    // +y face
    Float3 green(0.0f, 1.0f, 0.0f);
    transform.SetTranslate(APoint(0.0f, yExtent, 0.0f));
    transform.SetRotate(HMatrix(AVector::UNIT_Z, AVector::UNIT_X,
        AVector::UNIT_Y, APoint::ORIGIN, true));
    sm.SetTransform(transform);
    face = sm.Rectangle(2, 2, zExtent, xExtent);
    vba.ApplyTo(face);
    for (i = 0; i < 4; ++i)
    {
        vba.Color<Float3>(0, 0) = green;
        vba.Color<Float3>(0, 1) = green;
        vba.Color<Float3>(0, 2) = green;
        vba.Color<Float3>(0, 3) = green;
    }
    face->SetEffectInstance(effect->CreateInstance());
    mBox->AttachChild(face);

    // -y face
    Float3 darkGreen(0.0f, 1.0f, 0.0f);
    transform.SetTranslate(APoint(0.0f, -yExtent, 0.0f));
    transform.SetRotate(HMatrix(AVector::UNIT_X, AVector::UNIT_Z,
        -AVector::UNIT_Y, APoint::ORIGIN, true));
    sm.SetTransform(transform);
    face = sm.Rectangle(2, 2, xExtent, zExtent);
    vba.ApplyTo(face);
    for (i = 0; i < 4; ++i)
    {
        vba.Color<Float3>(0, 0) = darkGreen;
        vba.Color<Float3>(0, 1) = darkGreen;
        vba.Color<Float3>(0, 2) = darkGreen;
        vba.Color<Float3>(0, 3) = darkGreen;
    }
    face->SetEffectInstance(effect->CreateInstance());
    mBox->AttachChild(face);

    // +x face
    Float3 blue(0.0f, 0.0f, 1.0f);
    transform.SetTranslate(APoint(xExtent, 0.0f, 0.0f));
    transform.SetRotate(HMatrix(AVector::UNIT_Y, AVector::UNIT_Z,
        AVector::UNIT_X, APoint::ORIGIN, true));
    sm.SetTransform(transform);
    face = sm.Rectangle(2, 2, yExtent, zExtent);
    vba.ApplyTo(face);
    for (i = 0; i < 4; ++i)
    {
//.........这里部分代码省略.........
开发者ID:rasslingcats,项目名称:calico,代码行数:101,代码来源:RoughPlaneSolidBox.cpp


示例2: Node

//----------------------------------------------------------------------------
void CubeMaps::CreateScene ()
{
	// Create the root of the scene.
	mScene = new0 Node();
	mWireState = new0 WireState();
	mRenderer->SetOverrideWireState(mWireState);

	// Create the walls of the cube room.  Each of the six texture images is
	// RGBA 64-by-64.
	Node* room = new0 Node();
	mScene->AttachChild(room);

	// Index buffer shared by the room walls.
	IndexBuffer* ibuffer = new0 IndexBuffer(6, sizeof(int));
	int* indices = (int*)ibuffer->GetData();
	indices[0] = 0;
	indices[1] = 1;
	indices[2] = 3;
	indices[3] = 0;
	indices[4] = 3;
	indices[5] = 2;

	// The vertex format shared by the room walls.
	VertexFormat* vformat = VertexFormat::Create(2,
	                        VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
	                        VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT2, 0);
	int vstride = vformat->GetStride();
	VertexBufferAccessor vba;

	// The texture effect shared by the room walls.
	Texture2DEffect* effect = new0 Texture2DEffect(Shader::SF_LINEAR);

	VertexBuffer* vbuffer;
	TriMesh* wall;
	std::string textureName;

	// +x wall
	vbuffer = new0 VertexBuffer(4, vstride);
	vba.ApplyTo(vformat, vbuffer);
	vba.Position<Float3>(0) = Float3(+1.0f, -1.0f, -1.0f);
	vba.Position<Float3>(1) = Float3(+1.0f, -1.0f, +1.0f);
	vba.Position<Float3>(2) = Float3(+1.0f, +1.0f, -1.0f);
	vba.Position<Float3>(3) = Float3(+1.0f, +1.0f, +1.0f);
	vba.TCoord<Float2>(0, 0) = Float2(0.0f, 0.0f);
	vba.TCoord<Float2>(0, 1) = Float2(1.0f, 0.0f);
	vba.TCoord<Float2>(0, 2) = Float2(0.0f, 1.0f);
	vba.TCoord<Float2>(0, 3) = Float2(1.0f, 1.0f);
	wall = new0 TriMesh(vformat, vbuffer, ibuffer);
	room->AttachChild(wall);
	textureName = Environment::GetPathR("XpFace.wmtf");
	Texture2D* xpTexture = Texture2D::LoadWMTF(textureName);
	wall->SetEffectInstance(effect->CreateInstance(xpTexture));

	// -x wall
	vbuffer = new0 VertexBuffer(4, vstride);
	vba.ApplyTo(vformat, vbuffer);
	vba.Position<Float3>(0) = Float3(-1.0f, -1.0f, +1.0f);
	vba.Position<Float3>(1) = Float3(-1.0f, -1.0f, -1.0f);
	vba.Position<Float3>(2) = Float3(-1.0f, +1.0f, +1.0f);
	vba.Position<Float3>(3) = Float3(-1.0f, +1.0f, -1.0f);
	vba.TCoord<Float2>(0, 0) = Float2(0.0f, 0.0f);
	vba.TCoord<Float2>(0, 1) = Float2(1.0f, 0.0f);
	vba.TCoord<Float2>(0, 2) = Float2(0.0f, 1.0f);
	vba.TCoord<Float2>(0, 3) = Float2(1.0f, 1.0f);
	wall = new0 TriMesh(vformat, vbuffer, ibuffer);
	room->AttachChild(wall);
	textureName = Environment::GetPathR("XmFace.wmtf");
	Texture2D* xmTexture = Texture2D::LoadWMTF(textureName);
	wall->SetEffectInstance(effect->CreateInstance(xmTexture));

	// +y wall
	vbuffer = new0 VertexBuffer(4, vstride);
	vba.ApplyTo(vformat, vbuffer);
	vba.Position<Float3>(0) = Float3(+1.0f, +1.0f, +1.0f);
	vba.Position<Float3>(1) = Float3(-1.0f, +1.0f, +1.0f);
	vba.Position<Float3>(2) = Float3(+1.0f, +1.0f, -1.0f);
	vba.Position<Float3>(3) = Float3(-1.0f, +1.0f, -1.0f);
	vba.TCoord<Float2>(0, 0) = Float2(0.0f, 0.0f);
	vba.TCoord<Float2>(0, 1) = Float2(1.0f, 0.0f);
	vba.TCoord<Float2>(0, 2) = Float2(0.0f, 1.0f);
	vba.TCoord<Float2>(0, 3) = Float2(1.0f, 1.0f);
	wall = new0 TriMesh(vformat, vbuffer, ibuffer);
	room->AttachChild(wall);
	textureName = Environment::GetPathR("YpFace.wmtf");
	Texture2D* ypTexture = Texture2D::LoadWMTF(textureName);
	wall->SetEffectInstance(effect->CreateInstance(ypTexture));

	// -y wall
	vbuffer = new0 VertexBuffer(4, vstride);
	vba.ApplyTo(vformat, vbuffer);
	vba.Position<Float3>(0) = Float3(+1.0f, -1.0f, -1.0f);
	vba.Position<Float3>(1) = Float3(-1.0f, -1.0f, -1.0f);
	vba.Position<Float3>(2) = Float3(+1.0f, -1.0f, +1.0f);
	vba.Position<Float3>(3) = Float3(-1.0f, -1.0f, +1.0f);
	vba.TCoord<Float2>(0, 0) = Float2(0.0f, 0.0f);
	vba.TCoord<Float2>(0, 1) = Float2(1.0f, 0.0f);
	vba.TCoord<Float2>(0, 2) = Float2(0.0f, 1.0f);
	vba.TCoord<Float2>(0, 3) = Float2(1.0f, 1.0f);
	wall = new0 TriMesh(vformat, vbuffer, ibuffer);
//.........这里部分代码省略.........
开发者ID:bhlzlx,项目名称:WildMagic,代码行数:101,代码来源:CubeMaps.cpp


示例3: GetUV


//.........这里部分代码省略.........
	else if (FT_CAMERA == faceType)
	{
		Camera *camera = PX2_GR.GetCurUpdateCamera();
		if (!camera)
			return;

		const AVector &camUp = camera->GetUVector();
		const AVector &camRight = camera->GetRVector();

		float anchorWidth = mPivotPoint[0]*width;
		float anchorHeight = mPivotPoint[1]*height;

		APoint position;
		p0 = position 
			- camRight * anchorWidth
			- camUp * anchorHeight;

		p1 = position 
			+ camRight * (width-anchorWidth)
			- camUp * anchorHeight;

		p2 = position 
			- camRight * anchorWidth
			+ camUp * (height-anchorHeight);

		p3 = position 
			+ camRight * (width-anchorWidth)
			+ camUp * (height-anchorHeight);
	}
	else if (FT_SPEEDDIR==faceType || FT_FREE==faceType)
	{
		p0 = Float3(xPos,		0.0f,		zPos);
		p1 = Float3(xPos+width,	0.0f,		zPos);
		p2 = Float3(xPos,		0.0f,		zPos+height);
		p3 = Float3(xPos+width, 0.0f,		zPos+height);
	}

	//SetUseShareBuffers(true);
	if (!IsUseShareBuffers())
	{
		VertexBufferAccessor vba(this);
		vba.Position<Float3>(0) = p0;
		vba.Position<Float3>(1) = p1;
		vba.Position<Float3>(2) = p2;
		vba.Position<Float3>(3) = p3;

		vba.Color<Float4>(0, 0) = Float4(color[0], color[1], color[2], alpha);
		vba.Color<Float4>(0, 1) = Float4(color[0], color[1], color[2], alpha);
		vba.Color<Float4>(0, 2) = Float4(color[0], color[1], color[2], alpha);
		vba.Color<Float4>(0, 3) = Float4(color[0], color[1], color[2], alpha);
		vba.TCoord<Float2>(0, 0) = Float2(uBegin, vBegin);
		vba.TCoord<Float2>(0, 1) = Float2(uEnd, vBegin);
		vba.TCoord<Float2>(0, 2) = Float2(uBegin, vEnd);
		vba.TCoord<Float2>(0, 3) = Float2(uEnd, vEnd);

		if (!IsFixedBound())
			UpdateModelSpace(GU_MODEL_BOUND_ONLY);

		Renderer::UpdateAll(GetVertexBuffer());
	}
	else
	{
		mDBObject_V = PX2_DBM.AllocVertexBuffer(4);
		mDBObject_I = PX2_DBM.AllocIndexBuffer(6);

		SetShareDBObject_V(mDBObject_V);
		SetShareDBObject_I(mDBObject_I);

		VertexBufferAccessor vba;
		vba.ApplyTo(GetVertexFormat(), mDBObject_V->Buf);

		vba.Position<Float3>(mDBObject_V->Offset+0) = p0;
		vba.Position<Float3>(mDBObject_V->Offset+1) = p1;
		vba.Position<Float3>(mDBObject_V->Offset+2) = p2;
		vba.Position<Float3>(mDBObject_V->Offset+3) = p3;

		vba.Color<Float4>(0, mDBObject_V->Offset+0) = Float4(color[0], color[1], color[2], alpha);
		vba.Color<Float4>(0, mDBObject_V->Offset+1) = Float4(color[0], color[1], color[2], alpha);
		vba.Color<Float4>(0, mDBObject_V->Offset+2) = Float4(color[0], color[1], color[2], alpha);
		vba.Color<Float4>(0, mDBObject_V->Offset+3) = Float4(color[0], color[1], color[2], alpha);
		vba.TCoord<Float2>(0, mDBObject_V->Offset+0) = Float2(uBegin, vBegin);
		vba.TCoord<Float2>(0, mDBObject_V->Offset+1) = Float2(uEnd, vBegin);
		vba.TCoord<Float2>(0, mDBObject_V->Offset+2) = Float2(uBegin, vEnd);
		vba.TCoord<Float2>(0, mDBObject_V->Offset+3) = Float2(uEnd, vEnd);

		unsigned short *indices = (unsigned short*)mDBObject_I->Buf->GetData();
		indices += mDBObject_I->Offset;

		unsigned short v0 = (unsigned short)(mDBObject_V->Offset+0);
		unsigned short v1 = (unsigned short)(mDBObject_V->Offset+1);
		unsigned short v2 = (unsigned short)(mDBObject_V->Offset+2);
		unsigned short v3 = (unsigned short)(mDBObject_V->Offset+3);
		*indices++ = v0;
		*indices++ = v1;
		*indices++ = v2;
		*indices++ = v1;
		*indices++ = v3;
		*indices++ = v2;
	}
}
开发者ID:PhoenixSteam,项目名称:Phoenix3D,代码行数:101,代码来源:PX2Billboard.cpp


示例4: Node

//----------------------------------------------------------------------------
void BspNodes::CreateScene ()
{
	// Create the scene graph.
	//
	// 1. The rectangles represent the BSP planes of the BSP tree.  They
	//    share a VertexColor3Effect.  You can see a plane from either side
	//    (backface culling disabled).  The planes do not interfere with view
	//    of the solid objects (wirestate enabled).
	//
	// 2. The sphere, tetrahedron, and cube share a TextureEffect.  These
	//    objects are convex.  The backfacing triangles are discarded
	//    (backface culling enabled).  The front facing triangles are drawn
	//    correctly by convexity, so depthbuffer reads are disabled and
	//    depthbuffer writes are enabled.  The BSP-based sorting of objects
	//    guarantees that front faces of convex objects in the foreground
	//    are drawn after the front faces of convex objects in the background,
	//    which allows us to set the depthbuffer state as we have.  That is,
	//    BSPNode sorts from back to front.
	//
	// 3. The torus has backface culling enabled and depth buffering enabled.
	//    This is necessary, because the torus is not convex.
	//
	// 4. Generally, if all objects are opaque, then you want to draw from
	//    front to back with depth buffering fully enabled.  You need to
	//    reverse-order the elements of the visible set before drawing.  If
	//    any of the objects are semitransparent, then drawing back to front
	//    is the correct order to handle transparency.  However, you do not
	//    get the benefit of early z-rejection for opaque objects.  A better
	//    BSP sorter needs to be built to produce a visible set with opaque
	//    objects listed first (front-to-back order) and semitransparent
	//    objects listed last (back-to-front order).
	//
	// scene
	//     ground
	//     bsp0
	//         bsp1
	//             bsp3
	//                 torus
	//                 rectangle3
	//                 sphere
	//             rectangle1
	//             tetrahedron
	//         rectangle0
	//         bsp2
	//             cube
	//             rectangle2
	//             octahedron

	mScene = new0 Node();

	// Create the ground.  It covers a square with vertices (1,1,0), (1,-1,0),
	// (-1,1,0), and (-1,-1,0).  Multiply the texture coordinates by a factor
	// to enhance the wrap-around.
	VertexFormat* vformat = VertexFormat::Create(2,
	                        VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
	                        VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT2, 0);

	StandardMesh sm(vformat);
	VertexBufferAccessor vba;

	TriMesh* ground = sm.Rectangle(2, 2, 16.0f, 16.0f);
	vba.ApplyTo(ground);
	for (int i = 0; i < vba.GetNumVertices(); ++i)
	{
		Float2& tcoord = vba.TCoord<Float2>(0, i);
		tcoord[0] *= 128.0f;
		tcoord[1] *= 128.0f;
	}

	std::string path = Environment::GetPathR("Horizontal.wmtf");
	Texture2D* texture = Texture2D::LoadWMTF(path);
	ground->SetEffectInstance(Texture2DEffect::CreateUniqueInstance(texture,
	                          Shader::SF_LINEAR_LINEAR, Shader::SC_REPEAT, Shader::SC_REPEAT));
	mScene->AttachChild(ground);

	// Partition the region above the ground into 5 convex pieces.  Each plane
	// is perpendicular to the ground (not required generally).
	VertexColor3Effect* vceffect = new0 VertexColor3Effect();
	vceffect->GetCullState(0, 0)->Enabled = false;
	vceffect->GetWireState(0, 0)->Enabled = true;

	Vector2f v0(-1.0f, 1.0f);
	Vector2f v1(1.0f, -1.0f);
	Vector2f v2(-0.25f, 0.25f);
	Vector2f v3(-1.0f, -1.0f);
	Vector2f v4(0.0f, 0.0f);
	Vector2f v5(1.0f, 0.5f);
	Vector2f v6(-0.75f, -7.0f/12.0f);
	Vector2f v7(-0.75f, 0.75f);
	Vector2f v8(1.0f, 1.0f);

	BspNode* bsp0 = CreateNode(v0, v1, vceffect, Float3(1.0f, 0.0f, 0.0f));
	BspNode* bsp1 = CreateNode(v2, v3, vceffect, Float3(0.0f, 0.5f, 0.0f));
	BspNode* bsp2 = CreateNode(v4, v5, vceffect, Float3(0.0f, 0.0f, 1.0f));
	BspNode* bsp3 = CreateNode(v6, v7, vceffect, Float3(0.0f, 0.0f, 0.0f));

	bsp0->AttachPositiveChild(bsp1);
	bsp0->AttachNegativeChild(bsp2);
	bsp1->AttachPositiveChild(bsp3);
//.........这里部分代码省略.........
开发者ID:bhlzlx,项目名称:WildMagic,代码行数:101,代码来源:BspNodes.cpp


示例5: stdMesh

//----------------------------------------------------------------------------
PX2::Node *GeoObjFactory::CreateScaleCtrl_O()
{
	// node
	PX2::Node *node = new0 Node;
	node->LocalTransform.SetUniformScale(2.0f);
	node->SetName("Scale");

	VertexFormat *vf = PX2_GR.GetVertexFormat(GraphicsRoot::VFT_PC);
	StandardMesh stdMesh(vf);
	VertexBuffer *vBufferTemp = 0;
	VertexBufferAccessor vbaTemp;

	// x
	PX2::Node *nodeX = new0 Node;
	nodeX->SetName("Scale_X");

	VertexBuffer *vBufferX = new0 VertexBuffer(6, vf->GetStride());
	VertexBufferAccessor vbaX(vf, vBufferX);

	vbaX.Position<Float3>(0) = Float3(0.25f, 0.0f, 0.0f);
	vbaX.Position<Float3>(1) = Float3(1.125f, 0.0f, 0.0f);
	vbaX.Color<Float4>(0, 0) = Float4(1.0f, 0.0f, 0.0f, 1.0f);
	vbaX.Color<Float4>(0, 1) = Float4(1.0f, 0.0f, 0.0f, 1.0f);

	vbaX.Position<Float3>(2) = Float3(0.5f, 0.0f, 0.0f);
	vbaX.Position<Float3>(3) = Float3(0.5f, 0.5f, 0.0f);
	vbaX.Color<Float4>(0, 2) = Float4(0.0f, 1.0f, 0.0f, 1.0f);
	vbaX.Color<Float4>(0, 3) = Float4(0.0f, 1.0f, 0.0f, 1.0f);

	vbaX.Position<Float3>(4) = Float3(0.5f, 0.0f, 0.0f);
	vbaX.Position<Float3>(5) = Float3(0.5f, 0.0f, 0.5f);
	vbaX.Color<Float4>(0, 4) = Float4(0.0f, 0.0f, 1.0f, 1.0f);
	vbaX.Color<Float4>(0, 5) = Float4(0.0f, 0.0f, 1.0f, 1.0f);

	Polysegment *polysegmentX = new0 PX2::Polysegment(vf, vBufferX,
		false);
	polysegmentX->SetMaterialInstance(
		VertexColor4Material::CreateUniqueInstance());
	nodeX->AttachChild(polysegmentX);

	TriMesh *meshX = stdMesh.Box(0.06f, 0.06f, 0.06f);
	meshX->SetMaterialInstance(VertexColor4Material::CreateUniqueInstance());
	//meshX->GetMaterialInstance()->GetPass(0)->GetWireProperty()->Enabled = true;
	meshX->LocalTransform.SetTranslate(APoint(1.125f, 0.0f, 0.0f));
	vBufferTemp = meshX->GetVertexBuffer();
	vbaTemp.ApplyTo(vf, vBufferTemp);
	for (int i = 0; i < vBufferTemp->GetNumElements(); i++)
	{
		vbaTemp.Color<Float4>(0, i) = Float4(1.0f, 0.0f, 0.0f, 1.0f);
	}
	nodeX->AttachChild(meshX);

	// y
	PX2::Node *nodeY = new0 PX2::Node;
	nodeX->SetName("Scale_Y");

	VertexBuffer *vBufferY = new0 VertexBuffer(6, vf->GetStride());
	VertexBufferAccessor vbaY(vf, vBufferY);

	vbaY.Position<Float3>(0) = Float3(0.0f, 0.25f, 0.0f);
	vbaY.Position<Float3>(1) = Float3(0.0f, 1.125f, 0.0f);
	vbaY.Color<Float4>(0, 0) = Float4(0.0f, 1.0f, 0.0f, 1.0f);
	vbaY.Color<Float4>(0, 1) = Float4(0.0f, 1.0f, 0.0f, 1.0f);

	vbaY.Position<Float3>(2) = Float3(0.0f, 0.5f, 0.0f);
	vbaY.Position<Float3>(3) = Float3(0.5f, 0.5f, 0.0f);
	vbaY.Color<Float4>(0, 2) = Float4(1.0f, 0.0f, 0.0f, 1.0f);
	vbaY.Color<Float4>(0, 3) = Float4(1.0f, 0.0f, 0.0f, 1.0f);

	vbaY.Position<Float3>(4) = Float3(0.0f, 0.5f, 0.0f);
	vbaY.Position<Float3>(5) = Float3(0.0f, 0.5f, 0.5f);
	vbaY.Color<Float4>(0, 4) = Float4(0.0f, 0.0f, 1.0f, 1.0f);
	vbaY.Color<Float4>(0, 5) = Float4(0.0f, 0.0f, 1.0f, 1.0f);

	Polysegment *polysegmentY = new0 PX2::Polysegment(vf, vBufferY,
		false);
	polysegmentY->SetMaterialInstance(
		VertexColor4Material::CreateUniqueInstance());
	nodeY->AttachChild(polysegmentY);

	TriMesh *meshY = stdMesh.Box(0.06f, 0.06f, 0.06f);
	meshY->SetMaterialInstance(VertexColor4Material::CreateUniqueInstance());
	//meshY->GetMaterialInstance()->GetPass(0)->GetWireProperty()->Enabled = true;
	meshY->LocalTransform.SetTranslate(APoint(0.0f, 1.125f, 0.0f));
	vBufferTemp = meshY->GetVertexBuffer();
	vbaTemp.ApplyTo(vf, vBufferTemp);
	for (int i = 0; i < vBufferTemp->GetNumElements(); i++)
	{
		vbaTemp.Color<Float4>(0, i) = Float4(0.0f, 1.0f, 0.0f, 1.0f);
	}
	nodeY->AttachChild(meshY);

	// z
	PX2::Node *nodeZ = new0 PX2::Node();
	nodeX->SetName("Scale_Z");

	VertexBuffer *vBufferZ = new0 VertexBuffer(6, vf->GetStride());
	VertexBufferAccessor vbaZ(vf, vBufferZ);

//.........这里部分代码省略.........
开发者ID:JamShan,项目名称:Phoenix3D_2.1,代码行数:101,代码来源:PX2GeoObjFactory.cpp


示例6: Node

//----------------------------------------------------------------------------
void FreeFormDeformation::CreatePolylines ()
{
    // Generate the polylines that connect adjacent control points.
    mPolysegmentRoot = new0 Node();
    mTrnNode->AttachChild(mPolysegmentRoot);

    VertexColor3Effect* effect = new0 VertexColor3Effect();
    VertexFormat* vformat = VertexFormat::Create(2,
        VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
        VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT3, 0);
    int vstride = vformat->GetStride();

    VertexBufferAccessor vba;
    VertexBuffer* vbuffer;
    Polysegment* segment;

    int i0, i1, i2;
    for (i0 = 0; i0 < mQuantity; ++i0)
    {
        for (i1 = 0; i1 < mQuantity; ++i1)
        {
            for (i2 = 0; i2 < mQuantity-1; ++i2)
            {
                vbuffer = new0 VertexBuffer(2, vstride);
                vba.ApplyTo(vformat, vbuffer);
                vba.Position<Vector3f>(0) =
                    mVolume->GetControlPoint(i0, i1, i2);
                vba.Position<Vector3f>(1) =
                    mVolume->GetControlPoint(i0, i1, i2+1);
                vba.Color<Float3>(0, 0) = Float3(0.0f, 0.0f, 0.75f);
                vba.Color<Float3>(0, 1) = Float3(0.0f, 0.0f, 0.75f);
                segment = new0 Polysegment(vformat, vbuffer, true);
                segment->SetEffectInstance(effect->CreateInstance());
                mPolysegmentRoot->AttachChild(segment);
            }
        }

        for (i2 = 0; i2 < mQuantity; ++i2)
        {
            for (i1 = 0; i1 < mQuantity-1; ++i1)
            {
                vbuffer = new0 VertexBuffer(2, vstride);
                vba.ApplyTo(vformat, vbuffer);
                vba.Position<Vector3f>(0) =
                    mVolume->GetControlPoint(i0, i1, i2);
                vba.Position<Vector3f>(1) =
                    mVolume->GetControlPoint(i0, i1+1, i2);
                vba.Color<Float3>(0, 0) = Float3(0.0f, 0.75f, 0.0f);
                vba.Color<Float3>(0, 1) = Float3(0.0f, 0.75f, 0.0f);
                segment = new0 Polysegment(vformat, vbuffer, true);
                segment->SetEffectInstance(effect->CreateInstance());
                mPolysegmentRoot->AttachChild(segment);
            }
        }
    }

    for (i0 = 0; i0 < mQuantity-1; ++i0)
    {
        for (i1 = 0; i1 < mQuantity; ++i1)
        {
            for (i2 = 0; i2 < mQuantity; ++i2)
            {
                vbuffer = new0 VertexBuffer(2, vstride);
                vba.ApplyTo(vformat, vbuffer);
                vba.Position<Vector3f>(0) =
                    mVolume->GetControlPoint(i0, i1, i2);
                vba.Position<Vector3f>(1) =
                    mVolume->GetControlPoint(i0+1, i1, i2);
                vba.Color<Float3>(0,0) = Float3(0.75f, 0.0f, 0.0f);
                vba.Color<Float3>(0,1) = Float3(0.75f, 0.0f, 0.0f);
                segment = new0 Polysegment(vformat, vbuffer, true);
                segment->SetEffectInstance(effect->CreateInstance());
                mPolysegmentRoot->AttachChild(segment);
            }
        }
    }
}
开发者ID:vijaynerella,项目名称:GeometricTools,代码行数:78,代码来源:FreeFormDeformation.cpp


示例7: switch


//.........这里部分代码省略.........
            break;
        case 'S':
            trn = mTetras[1]->LocalTransform.GetTranslate();
            trn.X() += trnSpeed;
            mTetras[1]->LocalTransform.SetTranslate(trn);
            break;
        case 't':
            trn = mTetras[1]->LocalTransform.GetTranslate();
            trn.Y() -= trnSpeed;
            mTetras[1]->LocalTransform.SetTranslate(trn);
            break;
        case 'T':
            trn = mTetras[1]->LocalTransform.GetTranslate();
            trn.Y() += trnSpeed;
            mTetras[1]->LocalTransform.SetTranslate(trn);
            break;
        case 'u':
            trn = mTetras[1]->LocalTransform.GetTranslate();
            trn.Z() -= trnSpeed;
            mTetras[1]->LocalTransform.SetTranslate(trn);
            break;
        case 'U':
            trn = mTetras[1]->LocalTransform.GetTranslate();
            trn.Z() += trnSpeed;
            mTetras[1]->LocalTransform.SetTranslate(trn);
            break;
        case 'a':
            rot = mTetras[0]->LocalTransform.GetRotate();
            incr.MakeRotation(AVector::UNIT_Y, rotSpeed);
            mTetras[0]->LocalTransform.SetRotate(incr*rot);
            break;
        case 'A':
            rot = mTetras[0]->LocalTransform.GetRotate();
            incr.MakeRotation(AVector::UNIT_Y, -rotSpeed);
            mTetras[0]->LocalTransform.SetRotate(incr*rot);
            break;
        case 'b':
            rot = mTetras[1]->LocalTransform.GetRotate();
            incr.MakeRotation(AVector::UNIT_Z, rotSpeed);
            mTetras[1]->LocalTransform.SetRotate(incr*rot);
            break;
        case 'B':
            rot = mTetras[1]->LocalTransform.GetRotate();
            incr.MakeRotation(AVector::UNIT_Z, -rotSpeed);
            mTetras[1]->LocalTransform.SetRotate(incr*rot);
            break;
        case 'c':
            rot = mTetras[0]->LocalTransform.GetRotate();
            incr.MakeRotation(AVector::UNIT_X, 1.3f*rotSpeed);
            mTetras[0]->LocalTransform.SetRotate(incr*rot);
            rot = mTetras[1]->LocalTransform.GetRotate();
            incr.MakeRotation(AVector::UNIT_Z, -rotSpeed);
            mTetras[1]->LocalTransform.SetRotate(incr*rot);
            break;
        case 'C':
            rot = mTetras[0]->LocalTransform.GetRotate();
            incr.MakeRotation(AVector::UNIT_X, -1.3f*rotSpeed);
            mTetras[0]->LocalTransform.SetRotate(incr*rot);
            rot = mTetras[1]->LocalTransform.GetRotate();
            incr.MakeRotation(AVector::UNIT_Z, rotSpeed);
            mTetras[1]->LocalTransform.SetRotate(incr*rot);
            break;
        default:
            return false;
    }

    // Prevent solution point coordinates from being negative.  The polyhedron
    // distance calculator expects solution points to be in the first octant.
    // Vertices are offset by mOffsetMagnitude*Vector3f(1,1,1) in
    // UpdateSegments() before the call to the distance routine.  Here we make
    // sure that no translation of a polyhedron takes it so far into one of the
    // other 7 octants that the offset will not be sufficient to guarantee that
    // the solution points lie in the first octant.
    VertexBufferAccessor vba;
    float threshold = -mOffsetMagnitude + trnSpeed;
    for (int j = 0; j < 2; ++j)
    {
        const APoint& wTrn = mTetras[j]->WorldTransform.GetTranslate();
        const HMatrix& wRot = mTetras[j]->WorldTransform.GetRotate();
        vba.ApplyTo(mTetras[j]);
        for (int i = 0; i < 4; i++)
        {
            AVector relPosition = vba.Position<Float3>(i);
            APoint position = wTrn + wRot*relPosition;
            APoint trn = mTetras[j]->LocalTransform.GetTranslate();
            for (int k = 0; k < 3; ++k)
            {
                if (position[k] < threshold)
                {
                    trn[k] += trnSpeed;
                }
            }
            mTetras[j]->LocalTransform.SetTranslate(trn);
        }
    }

    mScene->Update();
    UpdateSegments();
    return true;
}
开发者ID:vijaynerella,项目名称:GeometricTools,代码行数:101,代码来源:PolyhedronDistance.cpp


示例8: UpdateSegments

//----------------------------------------------------------------------------
void PolyhedronDistance::UpdateSegments ()
{
    // Two segments make the line easier to see.
    Vector3f U[2][4];

    // Offset the polyhedra so far into the first octant that we are unlikely
    // to translate them out of that octant during a run.
    mOffsetMagnitude = 20.0f;
    Vector3f offset = mOffsetMagnitude*Vector3f::ONE;

    VertexBufferAccessor vba;
    int i;
    for (i = 0; i < 2; ++i)
    {
        const APoint& wTrn = mTetras[i]->WorldTransform.GetTranslate();
        const HMatrix& wRot = mTetras[i]->WorldTransform.GetRotate();
        vba.ApplyTo(mTetras[i]);
        for (int j = 0; j < 4; ++j)
        {
            AVector relPosition = vba.Position<Float3>(j);
            APoint position = wTrn + wRot*relPosition;
            U[i][j] = Vector3f(position[0] + offset[0],
                position[1] + offset[1], position[2] + offset[2]);
        }
    }

    vba.ApplyTo(mSegments[0]);
    Vector3f vertex[2] =
    {
        vba.Position<Vector3f>(0),
        vba.Position<Vector3f>(1)
    };

    int statusCode;

    LCPPolyDist3(4, U[0], 4, mFaces, 4, U[1], 4, mFaces, statusCode,
        mSeparation, vertex);

    vba.Position<Vector3f>(0) = vertex[0];
    vba.Position<Vector3f>(1) = vertex[1];

    if ((statusCode != LCPPolyDist3::SC_FOUND_SOLUTION &&
        statusCode != LCPPolyDist3::SC_TEST_POINTS_TEST_FAILED &&
        statusCode != LCPPolyDist3::SC_FOUND_TRIVIAL_SOLUTION) ||
        mSeparation < 0.0f)
    {
        // Do not draw the line joining nearest points if returns from
        // LCPPolyDist are not appropriate.
        for (i = 0; i < 2; ++i)
        {
            vba.Position<Vector3f>(i) = -offset;
        }
    }

    // Correct for the offset and set up endpoints for the segment.
    for (i = 0; i < 2; ++i)
    {
        vba.Position<Vector3f>(i) -= offset;

        // The adjustment with mSmall "centers" the endpoint tetra on the
        // solution points.
        Vector3f temp = vba.Position<Vector3f>(i) -
            (mSmall/3.0f)*Vector3f::ONE;
        mTetras[i + 2]->LocalTransform.SetTranslate(temp);
    }

    // Double-up the line for better visibility.
    vertex[0] = vba.Position<Vector3f>(0);
    vertex[1] = vba.Position<Vector3f>(1);
    vba.ApplyTo(mSegments[1]);
    const float epsilon = 0.002f;
    for (i = 0; i < 2; ++i)
    {
        vba.Position<Vector3f>(i) = vertex[i] + epsilon*Vector3f::ONE;
    }

    for (i = 0; i < 2; ++i)
    {
        mSegments[i]->UpdateModelSpace(Visual::GU_MODEL_BOUND_ONLY);
        mSegments[i]->Update();
        mRenderer->Update(mSegments[i]->GetVertexBuffer());
    }

    mScene->Update();
}
开发者ID:vijaynerella,项目名称:GeometricTools,代码行数:86,代码来源:PolyhedronDistance.cpp



注:本文中的VertexBufferAccessor类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ VertexBufferBinding类代码示例发布时间:2022-05-31
下一篇:
C++ VertexBuffer类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap