void CCube::Create(LPDIRECT3DDEVICE8 _pD3DDevice, D3DVECTOR *v1, D3DVECTOR *v2, D3DVECTOR *v3, D3DVECTOR *v4, D3DVECTOR *v5, D3DVECTOR *v6, D3DVECTOR *v7, D3DVECTOR *v8)
{
pD3DDevice = _pD3DDevice;
// Setup the vertex buffer
pD3DDevice->CreateVertexBuffer(sizeof(CTexturedVertex)*24, NULL, D3DFVF_CTexturedVertex, D3DPOOL_MANAGED, &pTexturedVertexBuffer);
// Lock the vertex buffer.
pTexturedVertexBuffer->Lock(0, 0, (BYTE **)&vtxCube, NULL);
// Set up cube vertices.
// FRONT
vtxCube[0].Create(v1->x, v1->y, v1->z, 1, 1, 1, 0, 1);
vtxCube[1].Create(v2->x, v2->y, v2->z, 1, 1, 1, 0, 0);
vtxCube[2].Create(v3->x, v3->y, v3->z, 1, 1, 1, 1, 1);
vtxCube[3].Create(v4->x, v4->y, v4->z, 1, 1, 1, 1, 0);
// RIGHT
vtxCube[4].Create(v4->x, v4->y, v4->z, 1, 1, 1, 0, 0);
vtxCube[5].Create(v5->x, v5->y, v5->z, 1, 1, 1, 1, 0);
vtxCube[6].Create(v3->x, v3->y, v3->z, 1, 1, 1, 0, 1);
vtxCube[7].Create(v6->x, v6->y, v6->z, 1, 1, 1, 1, 1);
// BACK
vtxCube[8].Create(v6->x, v6->y, v6->z, 1, 1, 1, 0, 1);
vtxCube[9].Create(v5->x, v5->y, v5->z, 1, 1, 1, 0, 0);
vtxCube[10].Create(v7->x, v7->y, v7->z, 1, 1, 1, 1, 1);
vtxCube[11].Create(v8->x, v8->y, v8->z, 1, 1, 1, 1, 0);
// LEFT
vtxCube[12].Create(v8->x, v8->y, v8->z, 1, 1, 1, 0, 0);
vtxCube[13].Create(v2->x, v2->y, v2->z, 1, 1, 1, 1, 0);
vtxCube[14].Create(v7->x, v7->y, v7->z, 1, 1, 1, 0, 1);
vtxCube[15].Create(v1->x, v1->y, v1->z, 1, 1, 1, 1, 1);
// BOTTOM
vtxCube[16].Create(v1->x, v1->y, v1->z, 1, 1, 1, 0, 1);
vtxCube[17].Create(v3->x, v3->y, v3->z, 1, 1, 1, 1, 1);
vtxCube[18].Create(v7->x, v7->y, v7->z, 1, 1, 1, 0, 0);
vtxCube[19].Create(v6->x, v6->y, v6->z, 1, 1, 1, 1, 0);
// TOP
vtxCube[20].Create(v2->x, v2->y, v2->z, 1, 1, 1, 0, 1);
vtxCube[21].Create(v8->x, v8->y, v8->z, 1, 1, 1, 0, 0);
vtxCube[22].Create(v4->x, v4->y, v4->z, 1, 1, 1, 1, 1);
vtxCube[23].Create(v5->x, v5->y, v5->z, 1, 1, 1, 1, 0);
// Unlock the vertex buffer.
pTexturedVertexBuffer->Unlock();
// Set up the Render state for texture.
// Setp to merge colours between vertex colour and texture colour.
pD3DDevice->SetTextureStageState(0,D3DTSS_COLOROP, D3DTOP_MODULATE);
pD3DDevice->SetTextureStageState(0,D3DTSS_COLORARG1, D3DTA_TEXTURE);
pD3DDevice->SetTextureStageState(0,D3DTSS_COLORARG2, D3DTA_DIFFUSE);
// Turn off the alpha channel since texture doesn''t have one.
pD3DDevice->SetTextureStageState(0,D3DTSS_ALPHAOP, D3DTOP_DISABLE);
}
Rendering a Cube using TRIANGLESTRIP...
Hey all,
I''m messing with D3D8 at the mo and have been creating a cube class. Currently, the cube is set up like so...
All looked well, until I added a function to make the cube translucent, at which point I noticed a rogue triangle within the cube running from the front top left vertex to the bottom back vertices. It is only visible from "behind" the cube, on account of backface culling.
How do I get rid of this and just render a hollow cube? I read somewhere on here that using triangle strips may be the problem. Do I need to use a triangle list instead? If I do stick with the triangle strip, have I got too many vertices?
Thanks for any help.
Rage_Matrix
Tron Software
-=Kicking Butt and Writing Code=-
What you''re doing now is fine. Just reorder the vertices of the rouge triangle.
John B
John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
I think the problem is to do with perhaps the triangle strip. and the rogue triangle maybe something with the order of vertices. Using triangle strips, its reasonably easy to do the sides of the cube using whichever rendering order you set for backface culling, but moving from the last cube "side" vertex to the top and bottom faces of the cube seems to be causing problems.
Drunken Hyena's cube program uses 36 vertices, but I'm assuming that the cube is totally hollow. Is it perhaps not possible to render a true hollow cube using 24 vertices with triangle strips?
Rage_Matrix
Tron Software
-=Kicking Butt and Writing Code=-
[edited by - RageMatrix on June 9, 2002 11:03:22 AM]
Drunken Hyena's cube program uses 36 vertices, but I'm assuming that the cube is totally hollow. Is it perhaps not possible to render a true hollow cube using 24 vertices with triangle strips?
Rage_Matrix
Tron Software
-=Kicking Butt and Writing Code=-
[edited by - RageMatrix on June 9, 2002 11:03:22 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement