Skip to main content
GameDev.net gamedev.net
🔒 Locked

Help with 3D cube coordinates

Started by elendil67 Jan 4, 2003 at 8:48 PM 7 replies 1.4k views
Original Post
elendil67
elendil67
Hi there. I am making a cube from triangle lists (no indices yet), but I can't get it right or find the coordinates for a cube. Some faces show up unlit, but others show up strangely, and yet others don't show up at all. I am very confused. Do you know what I might be doing wrong? My custom vertex has the three X, Y, Z position floats followed by three X, Y, Z normal floats. You can find the whole source here.
      
vertex_t vertices[36] = 
{
    // Top face

    //  X      Y      Z      NX     NY     NZ

    { -1.0f,  1.0f, -1.0f,  0.0f,  1.0f,  0.0f },
    { -1.0f,  1.0f,  1.0f,  0.0f,  1.0f,  0.0f },
    {  1.0f,  1.0f,  1.0f,  0.0f,  1.0f,  0.0f },
    { -1.0f,  1.0f, -1.0f,  0.0f,  1.0f,  0.0f },
    {  1.0f,  1.0f,  1.0f,  0.0f,  1.0f,  0.0f },
    {  1.0f,  1.0f, -1.0f,  0.0f,  1.0f,  0.0f },

    // Front face

    //  X      Y      Z      NX     NY     NZ

    { -1.0f, -1.0f, -1.0f,  0.0f,  0.0f, -1.0f },
    { -1.0f,  1.0f, -1.0f,  0.0f,  0.0f, -1.0f },
    {  1.0f,  1.0f, -1.0f,  0.0f,  0.0f, -1.0f },
    { -1.0f, -1.0f, -1.0f,  0.0f,  0.0f, -1.0f },
    {  1.0f,  1.0f, -1.0f,  0.0f,  0.0f, -1.0f },
    {  1.0f, -1.0f, -1.0f,  0.0f,  0.0f, -1.0f },

    // Left face

    //  X      Y      Z      NX     NY     NZ

    { -1.0f, -1.0f,  1.0f, -1.0f,  0.0f,  0.0f },
    { -1.0f,  1.0f,  1.0f, -1.0f,  0.0f,  0.0f },
    { -1.0f,  1.0f, -1.0f, -1.0f,  0.0f,  0.0f },
    { -1.0f, -1.0f,  1.0f, -1.0f,  0.0f,  0.0f },
    { -1.0f,  1.0f, -1.0f, -1.0f,  0.0f,  0.0f },
    { -1.0f, -1.0f, -1.0f, -1.0f,  0.0f,  0.0f },

    // Right face

    //  X      Y      Z      NX     NY     NZ

    {  1.0f, -1.0f,  1.0f,  1.0f,  0.0f,  0.0f },
    {  1.0f,  1.0f,  1.0f,  1.0f,  0.0f,  0.0f },
    {  1.0f,  1.0f, -1.0f,  1.0f,  0.0f,  0.0f },
    {  1.0f, -1.0f,  1.0f,  1.0f,  0.0f,  0.0f },
    {  1.0f,  1.0f, -1.0f,  1.0f,  0.0f,  0.0f },
    {  1.0f, -1.0f, -1.0f,  1.0f,  0.0f,  0.0f },

    // Back face

    //  X      Y      Z      NX     NY     NZ

    { -1.0f, -1.0f,  1.0f,  0.0f,  0.0f,  1.0f },
    { -1.0f,  1.0f,  1.0f,  0.0f,  0.0f,  1.0f },
    {  1.0f,  1.0f,  1.0f,  0.0f,  0.0f,  1.0f },
    { -1.0f, -1.0f,  1.0f,  0.0f,  0.0f,  1.0f },
    {  1.0f,  1.0f,  1.0f,  0.0f,  0.0f,  1.0f },
    {  1.0f, -1.0f,  1.0f,  0.0f,  0.0f,  1.0f },

    // Bottom face

    //  X      Y      Z      NX     NY     NZ

    { -1.0f, -1.0f, -1.0f,  0.0f, -1.0f,  0.0f },
    { -1.0f, -1.0f,  1.0f,  0.0f, -1.0f,  0.0f },
    {  1.0f, -1.0f,  1.0f,  0.0f, -1.0f,  0.0f },
    { -1.0f, -1.0f, -1.0f,  0.0f, -1.0f,  0.0f },
    {  1.0f, -1.0f,  1.0f,  0.0f, -1.0f,  0.0f },
    {  1.0f, -1.0f, -1.0f,  0.0f, -1.0f,  0.0f },
};
    
[  c o d e  m a t r i x  ] [edited by - elendil67 on January 4, 2003 9:53:11 PM]
When you go homeTell them of us, and say:For your tomorrow,We gave our today.
Pipo DeClown
Pipo DeClown
Try swapping the ZNormals from the front and the back face.
So the fronts become positive and the backs negative.
Gladiator
Gladiator
Make sure you use one of the hand rules for defining the object''s vertices ( i.e. Left hand rule and Right hand rule ) and stick to it throughout.
Hoff
Hoff
It looks like your triangles aren''t consistently wound the same way. When viewed from the front, all vertices should go either clockwise or counter-clockwise.

-- John
elendil67
elendil67
Strange. I took a long time to try and wind them counter-clockwise. Do you know if I did anything wrong with winding them? Thanks.

[  c o d e  m a t r i x  ]
When you go homeTell them of us, and say:For your tomorrow,We gave our today.
elendil67
elendil67
Anyone? Wow, it''s like exactly 24 hours between posts... veird

[  c o d e  m a t r i x  ]
When you go homeTell them of us, and say:For your tomorrow,We gave our today.
luxitan
luxitan
try using this lpDXDev->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
so see if all your faces are beeing drawn, what this does is draw a face clockwise or counter-clockwise

then use this lpDXDev->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); to see if your trangle are well designed

hope it helps
To be considered a genius you just have to say what everybody knows in a way very few understand

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.