This looks more like a case of bad indices/triangles. Matrices won’t affect single vertices, unless explicitly told too.

Please log in or register to post a reply.

I’d back up the idea of screwed data.

Your cube is in the centre of the screen and I presume the rest of it looks like it’s spinning around ? If so, it’s your vertex data for sure.

Sidenote: I’d recommend picking up a matrix and vector class and using that instead of rolling your own. Getting all the overloads sorted out (if you use C++ or other oop) so you end up with Vertex.Pos*=Matrix for applying a matrix to a vertex for example makes you code seriously readable and is less bug-prone.

We actually wrote our own, but with hindsight I wish we’d started from someone elses!

I thought I might as well post my vertex data. I don’t know if theres anything wrong here. The variable colour is 0xFFFFFFFF:

```
//Vertex data
vertices[0].X = 0.0f; vertices[0].Y = 0.0f; vertices[0].Z = 0.0f; vertices[0].NX = -1.0f; vertices[0].NY = -1.0f; vertices[0].NZ = -1.0f; vertices[0].diffuse = colour;
vertices[1].X = 1.0f; vertices[1].Y = 0.0f; vertices[1].Z = 0.0f; vertices[1].NX = 1.0f; vertices[1].NY = 1.0f; vertices[1].NZ = 1.0f; vertices[1].diffuse = colour;
vertices[2].X = 1.0f; vertices[2].Y = 1.0f; vertices[2].Z = 0.0f; vertices[2].NX = 1.0f; vertices[2].NY = 1.0f; vertices[2].NZ = -1.0f; vertices[2].diffuse = colour;
vertices[3].X = 0.0f; vertices[3].Y = 1.0f; vertices[3].Z = 0.0f; vertices[3].NX = -1.0f; vertices[3].NY = 1.0f; vertices[3].NZ = -1.0f; vertices[3].diffuse = colour;
vertices[4].X = 1.0f; vertices[4].Y = 0.0f; vertices[4].Z = 1.0f; vertices[4].NX = 1.0f; vertices[4].NY = -1.0f; vertices[4].NZ = 1.0f; vertices[4].diffuse = colour;
vertices[5].X = 1.0f; vertices[5].Y = 1.0f; vertices[5].Z = 1.0f; vertices[5].NX = 1.0f; vertices[5].NY = 1.0f; vertices[5].NZ = 1.0f; vertices[5].diffuse = colour;
vertices[6].X = 0.0f; vertices[6].Y = 1.0f; vertices[6].Z = 1.0f; vertices[6].NX = -1.0f; vertices[6].NY = 1.0f; vertices[6].NZ = 1.0f; vertices[6].diffuse = colour;
vertices[7].X = 0.0f; vertices[7].Y = 0.0f; vertices[7].Z = 1.0f; vertices[7].NX = -1.0f; vertices[7].NY = -1.0f; vertices[7].NZ = 1.0f; vertices[7].diffuse = colour;
vertices[8].X = 0.0f; vertices[8].Y = 1.0f; vertices[8].Z = 1.0f; vertices[8].NX = -1.0f; vertices[8].NY = 1.0f; vertices[8].NZ = 1.0f; vertices[8].diffuse = colour;
vertices[9].X = 0.0f; vertices[9].Y = 1.0f; vertices[9].Z = 0.0f; vertices[9].NX = -1.0f; vertices[9].NY = 1.0f; vertices[9].NZ = -1.0f; vertices[9].diffuse = colour;
vertices[10].X = 1.0f; vertices[10].Y = 0.0f; vertices[10].Z = 1.0f; vertices[10].NX = 1.0f; vertices[10].NY = -1.0f; vertices[10].NZ = 1.0f; vertices[10].diffuse = colour;
vertices[11].X = 1.0f; vertices[11].Y = 0.0f; vertices[11].Z = 0.0f; vertices[11].NX = 1.0f; vertices[11].NY = -1.0f; vertices[11].NZ = -1.0f; vertices[11].diffuse = colour;
```

Index data:

```
//Indices
indices[0] = 0; indices[3] = 0; indices[6] = 1; indices[9] = 1; indices[12] = 4; indices[15] = 4; indices[18] = 7; indices[21] = 7; indices[24] = 9; indices[27] = 9;
indices[1] = 2; indices[4] = 3; indices[7] = 5; indices[10] = 2; indices[13] = 6; indices[16] = 5; indices[19] = 3; indices[22] = 6; indices[25] = 5; indices[28] = 8;
indices[2] = 1; indices[5] = 2; indices[8] = 4; indices[11] = 5; indices[14] = 7; indices[17] = 6; indices[20] = 0; indices[23] = 3; indices[26] = 2; indices[29] = 5;
indices[30] = 0; indices[33] = 0;
indices[31] = 11; indices[34] = 10;
indices[32] = 10; indices[35] = 7;
```

It sure is. Now you need to re-arrange them so they are correct :)

Too make it easier on yourself, try and split up the cube to its individual faces, and fix one at a time.

OK I tried that. I made a cube in a 3D Modeller, exported it and took the vertex and index data straight from that. But it still doesn’t look right. Now it looks like a flattened L shape. :S

```
//Indices
indices[0] = 0; indices[3] = 3; indices[6] = 4; indices[9] = 7; indices[12] = 0; indices[15] = 5; indices[18] = 1; indices[21] = 7; indices[24] = 3; indices[27] = 6;
indices[1] = 2; indices[4] = 1; indices[7] = 5; indices[10] = 6; indices[13] = 1; indices[16] = 4; indices[19] = 3; indices[22] = 5; indices[25] = 2; indices[28] = 7;
indices[2] = 3; indices[5] = 0; indices[8] = 7; indices[11] = 4; indices[14] = 5; indices[17] = 0; indices[20] = 7; indices[23] = 1; indices[26] = 6; indices[29] = 3;
indices[30] = 2; indices[33] = 4;
indices[31] = 0; indices[34] = 6;
indices[32] = 4; indices[35] = 2;
//Vertex data
vertices[0].X = -0.5f; vertices[0].Y = 0.0f; vertices[0].Z = -0.5f; vertices[0].NX = 0.0f; vertices[0].NY = 1.0f; vertices[0].NZ = 0.0f; vertices[0].diffuse = colour;
vertices[1].X = 0.5f; vertices[1].Y = 0.0f; vertices[1].Z = -0.5f; vertices[1].NX = 0.0f; vertices[1].NY = -1.0f; vertices[1].NZ = -0.0f; vertices[1].diffuse = colour;
vertices[2].X = -0.5f; vertices[2].Y = 0.0f; vertices[2].Z = 0.5f; vertices[2].NX = 0.0f; vertices[2].NY = 0.0f; vertices[2].NZ = -1.0f; vertices[2].diffuse = colour;
vertices[3].X = 0.5f; vertices[3].Y = 0.0f; vertices[3].Z = 0.5f; vertices[3].NX = -0.0f; vertices[3].NY = 0.0f; vertices[3].NZ = 0.0f; vertices[3].diffuse = colour;
vertices[4].X = -0.5f; vertices[4].Y = -1.0f; vertices[4].Z = -0.5f; vertices[4].NX = 0.0f; vertices[4].NY = 0.0f; vertices[4].NZ = 1.0f; vertices[4].diffuse = colour;
vertices[5].X = 0.5f; vertices[5].Y = -1.0f; vertices[5].Z = -0.5f; vertices[5].NX = 1.0f; vertices[5].NY = 0.0f; vertices[5].NZ = 0.0f; vertices[5].diffuse = colour;
vertices[6].X = -0.5f; vertices[6].Y = -1.0f; vertices[6].Z = 0.5f; vertices[6].NX = 0.0f; vertices[6].NY = -0.0f; vertices[6].NZ = 1.0f; vertices[6].diffuse = colour;
vertices[7].X = 0.50f; vertices[7].Y = -1.0f; vertices[7].Z = 0.5f; vertices[7].NX = -1.0f; vertices[7].NY = 0.0f; vertices[7].NZ = 1.0f; vertices[7].diffuse = colour;
```

I’ll post a screenshot as soon as I work out why the triangles flicker if I turn off lighting.

Right I made a video showing what happens exactly. The camera is pulling away slowly and the “cube” is rotating on it’s Y-Axis:

Any help at all?

I can see exactly two triangles. And their indices aren’t correct. I don’t thinkt that you pass the wrong indices anymore. It must be something else, like the creation of the indes buffer maybe..

Check this please..

Here’s what I see (from a triangle point of view):

Heh, I know that diagram so well! :surrender

So often do I see it, I’ve even named it:

“Cats Ears” :wallbash:

I don’t use index or vertex buffers directly. I use DrawIndexedPrimitiveUP(). Could it be that it’s not interpretating my index data correctly? The index data I pass to it is an array of type unsigned long.

Here is my call to the D3D Function:

m_d3d9Device->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0,
rData->GetVertexCount(), rData->GetIndexCount() / 3,

(void *)indexData, D3DFMT_INDEX16, rData->GetVertexData(),
sizeof(Vertex_Diffuse));

Well I changed D3DFMT_INDEX16 to D3DFMT_INDEX32, which is the only other option, before but it still doesn’t make a cube. I get something weird like this:

That’s the object rotating slowly on it’s X-Axis. The camera is also at -35 on the Z Axis and 20 on the Y looking at 0,0,0. I also notice that as I pull away from the object the parts that are off camera just keep stretching. I can never get the whole thing on the screen at once.

No, I’m copying from a vector of unsigned longs to an unsigned long pointer.

```
unsigned long *indexData = new unsigned long[rData->GetIndexData(i).size()];
for(int y = 0; y < rData->GetIndexData(i).size(); y++)
{
indexData[y] = rData->GetIndexData(i).at(y);
}
```

1st: Stop using DrawIndexedPrimitiveUP. It’s inefficient and should be avoided anyways.

2nd: Browse the examples until you find a basic DirectX example that uses Index and Vertex Buffers (it’s somewhere in the tutorials - I’m sure about that).

3nd: Throw away everything you don’t need..

4th: Implement you cube using the new code as a boilerplate

Not to sound rude, but since you hadn’t hadn’t found this rather simple error on your own I don’t really trust in your problem solving skills when it comes to directx coding. Nothing to be ashamed on, we all have to start at one point, but it’s better to start from a new, stable codebase now.

Who knows what else lurks inside your code…

Btw, keeping dependencies inside one code is a good thing to do. I don’t know why everyone uses d3dx even for the most simple vector stuff these days..

That’s why I wrote my suggestion. You already sort by material and whatnot, but the very basics don’t work. A simple cube still does not render correctly.

Start simple, forget about your codebase for a while and get that damn cube on the screen first.

*Then* integrate your codebase step by step and test each feature inside out.

vertices[3] has a (0,0,0) normal which is probably being projected to infinity or something. I don’t see why that would happen unless your pixel shader is overcomplicated for this, but some general points even if this isn’t the answer. (As I don’t see why it should be tbh):

a) Triangles that never go away usually have a vertex at infinity.

b) I found some dodgy looking data in your example.

c) Vertices at inifinity are usually caused by NAN vertex or broken
shader - you can’t really put them there in code one individually unless
you try real hard as they get transformed elsewhere later.

d) You can get a NAN by normalising a NULL normal like the one at
vertices[3] then doing something with it.

e) Lighting might turn your tri invisible with NULL normals depending
on shader/RS settings

EDIT:Also vertices[7]’s normal isn’t actually normal.

- Upcoming Multiplatform Game Program...
- Our first game - looking for feedbacks
- Network Emulation Tool
- Trouble with accessing GLSL array
- Fiction
- Game Programming Patterns: Bytecode
- Interactive WebGL Water Demo
- Skeletal Animation Tutorial with GP...
- Unreal Engine 4
- Microsoft xbox one selling poorly

Hey all. I’m trying to get my world matrix for my engine working. I need to rotate the vertices on each axis then translate them. But when I try nothing is displayed. I think I must be creating a rotation matrix wrong. I thought I can create a rotation axis for X, Y and Z then multiply them together to make one rotation matrix. Is this correct or is there another way of doing this?

EDIT:

I have something that works as in it rotates:

But I think my projection or view matrices are screwed up because look at my “Cube”: