3D Grid in OPENGL

Posted on 2005-05-03
Last Modified: 2013-12-06
Hi All,

I actually want to create a wall for  a room.So i wanted to make the wall the room using a grid.So that i can effiencently use the lighting effects.

So now i know the 4 edges of the grid , how can run the loop to create the grid automatically.

Question by:srihari1986
    LVL 17

    Accepted Solution

    Well, simple starting approach would be a function that takes your 2x2 wall and returns back a 3x3 wall -- subdivide each edge mid-way, and find the center-point as well (mid-point between corners or between two of the new mid-way points...).

    A more 'iterative' approach from there is pretty easy.  Decide how many subdivisions you want along a given dimension, get the distance vector between two edge points, and generate the iterative points along the line.  Repeat on all edges, then repeat along one dimension to generate the internal vertices to match the new internal edges...

    float v1[3], v2[3]; // assuming these come into the line subdivision function

    #define NUM_INT 3  // I'm hardcoding to subdivide into 3 new intermediate vertices
    float v[NUM_INT][3];
    int i,j;

    for (i=0; i<NUM_INT; i++)
      for (j=0; j<3; j++)
        v[i][j] = v1[j] + ( (i+1) * ( (v2[j]-v1[j]) / (NUM_INT+1) ) ); // NUM_INT+1 as we're doing the number of internal edges effectively...

    That will interpolate between two vertices and generate the intermediate points between the two.

    OF COURSE, THIS GENERALLY ASSUMES A CO-PLANAR SET OF START VERTICES.  It'll work to some degree even if not, just won't necessarily take into account a gradual 'bend' that might be desired.  You'd need a more complex interpolator than my linear function above.


    Author Comment

    Hi dave,

    Thanks for the support.After taking a look at your example i have come out a similiar one that can draw a 10 X 10 grid.I took me a day to understand ur method.Sorry for that i am new to opengl and not too good in maths.


    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Suggested Solutions

    Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
    Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now