I am using c++ with the openGL library

Asked

Viewed 117 times

0

I’m using c++ with the openGL library, I’m having a little trouble creating a method. I need to create some buildings randomly, but to not create one inside the other I need to compare the 4 points of the building. If anyone can help me.

string localizacaoPredio[150];
int ultimaPos = 0;
for (int i = 0; i < 150; i++){
    int x = rand() % 10 + 1;
    int z = rand() % 10 + 1;
    string coordenada = x + ";" + z;

    for (int j = 0; j < ultimaPos; j++){
        if (localizacaoPredio[j].compare(coordenada)){
            x = rand() % 10 + 1;
            z = rand() % 10 + 1;
            coordenada = x + ";" + z;
            j = -1;
        }
    }
    localizacaoPredio[ultimaPos] = coordenada;
    ultimaPos++;
}
int andares[150];
for (int i = 0; i < 150; i++){
    andares[i] = rand() % 10 + 1;
}
int numDivisoes[150];
for (int i = 0; i < 150; i++){
    numDivisoes[i] = rand() % 10 + 1;
}

for (int i = 0; i < 150; i++){

    Building b1(localizacaoPredio[i], y1, andares[i], numDivisoes[i], 1, 1);
    planos.push_back(b1.predio[0].plano);
    planos.push_back(b1.predio[1].plano);
    planos.push_back(b1.predio[2].plano);
    planos.push_back(b1.predio[3].plano);
    planos.push_back(b1.predio[4].plano);
    city.push_back(b1);
}
  • 1

    Hello, welcome to SOPT. A lot of people can help you. Just ask a question. Start with [tour], then read [Ask], and finally come back here and edit the question to actually ask something objective about your difficulty (is it about compilation? is it about randomness? is it about shape design? is it about detecting the inclusion of one building in the other? etc).

  • Hi there, Luiz. Here’s the thing, I need to create a vector or an array, for building, but so that none is on top of the other I need to compare with all the previous ones. I’m still a little confused by the question, I’m not very familiar with c++ and I’m hitting myself on this method.

  • I understood. But still your question is not clear enough. For example, the meaning informal "on top" may vary considering that this is a 3D application. For example, it may mean "within" (that is, the foundation of one building cannot match the foundation of another); or it may mean "in front" (that is, one building cannot obstruct the view of another from the camera;

  • I suppose you want something in the sense of first understanding (that is, you don’t want buildings to occupy the same physical space). Assuming that you already know how to design the building and that the buildings are all regular polygons, the problem would only be not allowing the foundations to overlap, right? Have you tried something comparing the x and y axis coordinates of each building pair? If yes, post your code.

  • When I create the buildings I leave the point x e y, but as the building is a polygon, it has the creation of another 3 points, and when I do the check if this overlapping, I can only verify in the first point I created.

  • I don’t know how to send the code pad here

  • Edit the question and put the code in it. See here how to format code: http://meta.pt.stackoverflow.com/questions/1599/formatr-c%C3%b3digo-nas-respostas-do-stack-overflow

  • Hello, I edited the code

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.