Help with rendering geometries

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
shurijo
Posts: 148
Joined: Sat Feb 21, 2004 3:04 am

Help with rendering geometries

Post by shurijo »

I took some code from the forums and tutorial and made the multi-colored triangle work/render fine, but when I tried to change it I couldn't get my shape to render (ps its a hexagon). I'm pretty sure the math is good, I think the issue is with the Indcies.push_back, I really have no idea what that does or how that works.

thanks,

Code: Select all

	
    video::SColor hexColor(255,0,255,255);
    float shortLength = sqrt(segmentLength*segmentLength/2);

    Vertices[0] = video::S3DVertex(centerMapX+shortLength,centerMapY+segmentLength/2,centerMapZ, 0,1,0, hexColor , 0, 1);
    Vertices[1] = video::S3DVertex(centerMapX+shortLength,centerMapY-segmentLength/2,centerMapZ, 0,1,0, hexColor , 0, 1);
    Vertices[2] = video::S3DVertex(centerMapX,centerMapY-segmentLength-shortLength,centerMapZ, 0,1,0, hexColor , 0, 1);
    Vertices[3] = video::S3DVertex(centerMapX-shortLength,centerMapY-segmentLength/2,centerMapZ, 0,1,0, hexColor , 0, 1);
    Vertices[4] = video::S3DVertex(centerMapX-shortLength,centerMapY+shortLength,centerMapZ, 0,1,0, hexColor , 0, 1);
    Vertices[5] = video::S3DVertex(centerMapX,centerMapY+segmentLength+shortLength,centerMapZ, 0,1,0, hexColor , 0, 1);

    core::aabbox3d<f32> Box; 
    Box.reset(Vertices[0].Pos); 
    for (s32 i=1; i<6; ++i) { 
        Box.addInternalPoint(Vertices[i].Pos); 
    } 

    for (s32 i=0; i<6; ++i) { 
        myMeshBuffer->Vertices.push_back(Vertices[i]);         
    } 

    for (s32 i=0; i<6; ++i) { 
        for (s32 j=0; j<6; ++j) { 
            if (i!=j)
                myMeshBuffer->Indices.push_back(j); 
         }
    } 

    myMeshBuffer->BoundingBox = Box; 

    video::SMaterial myMaterial;
    myMaterial.Wireframe = false;
    myMaterial.Lighting = false;

    myMeshBuffer->Material = myMaterial;
Moni

Post by Moni »

Hi shurijo

I'l explain in short what MeshBuffers are and what they are used for, this way you should be able to find the problem in your code yourselfe.

Basically MeshBuffers are used to hold vertices forming meshes. indices are used to define which vertices have to be rendered tougether as a triangle.
lets assume you have a square

0----3
| |
| |
1----2

then the engine will render a triangulation of that square. You'll have to provide that trinagulation for the engine if you create a mesh yourselfe. If you use a meshloader then the loader will take care of that.

let's build that meshbuffer for the square:

first,insert the vertices 0,1,2,3 in that order
mb->Vertices.push_back(vert0);
mb->Vertices.push_back(vert1);
mb->Vertices.push_back(vert2);
mb->Vertices.push_back(vert3);

then you insert the indices which will build the triangulation:
// create triangle 0-1-2
mb->Indices.push_back(0);
mb->Indices.push_back(1);
mb->Indices.push_back(2);
// create triangle 1-2-3
mb->Indices.push_back(1);
mb->Indices.push_back(2);
mb->Indices.push_back(3);

so, for that square you needed 4 vertices and 6 indices

hope that helps
Moni
deps
Posts: 115
Joined: Sat Jan 10, 2004 5:22 pm
Location: Tranås, Sweden

Post by deps »

// create triangle 0-1-2
mb->Indices.push_back(0);
mb->Indices.push_back(1);
mb->Indices.push_back(2);
// create triangle 1-2-3
mb->Indices.push_back(1);
mb->Indices.push_back(2);
mb->Indices.push_back(3);
Are you sure it isn't supposed to be like this?

// create triangle 0-1-2
mb->Indices.push_back(0);
mb->Indices.push_back(1);
mb->Indices.push_back(2);
// create triangle 0-2-3
mb->Indices.push_back(0);
mb->Indices.push_back(2);
mb->Indices.push_back(3);

Or am i wrong on this? Never tried this before in irrlicht.
shurijo
Posts: 148
Joined: Sat Feb 21, 2004 3:04 am

Post by shurijo »

Moni wrote:Hi shurijo

I'l explain in short what MeshBuffers are and what they are used for, this way you should be able to find the problem in your code yourselfe.

hope that helps
Moni
Thanks. I understand everything now. (First time working with meshes and didn't realize that you need to do it like triangles, etc.)

thanks,
-shur
Post Reply