Time for action — using more triangles for volume

We will use the previous code and we will only add two new quads to our grass blades:

  1. After the first two triangles, add the third and fourth triangle for the second quad:
    //third triangle
    manual->position(2.5, 0.0, 4.3);
    manual->textureCoord(1,1);
    manual->position(-2.5, 10.0, -4.3);
    manual->textureCoord(0,0);
    manual->position(-2.0, 0.0, -4.3);
    manual->textureCoord(0,1);
    //fourth triangle
    manual->position(2.5, 0.0, 4.3);
    manual->textureCoord(1,1);
    manual->position(2.5, 10.0, 4.3);
    manual->textureCoord(1,0);
    manual->position(-2.5, 10.0, -4.3);
    manual->textureCoord(0,0);
    
  2. Add the fifth and sixth triangle for the third quad:
    //fifth triangle
    manual->position(2.5, 0.0, -4.3);
    manual->textureCoord(1,1);
    manual->position(-2.5, 10.0, 4.3);
    manual->textureCoord(0,0);
    manual->position(-2.0, 0.0, 4.3);
    manual->textureCoord(0,1);
    //sixth triangle
    manual->position(2.5, 0.0, -4.3);
    manual->textureCoord(1,1);
    manual->position(2.5, 10.0, -4.3);
    manual->textureCoord(1,0);
    manual->position(-2.5, 10.0, 4.3);
    manual->textureCoord(0,0)
    
  3. Compile and run the application, and then navigate around the blades of grass. With the previous examples, it was possible to see the blades of grass only as a small line; this is no longer the case.
    Time for action — using more triangles for volume

What just happened?

We fixed the problem where we could see that the blades of grass were only an image projected onto a quad. To fix this problem, we simply created two new quads, rotated them, and then stuck them into each other. It looks like the following diagram:

What just happened?

Each quad has the same length, so like the preceding picture, we can think of it as a circle divided into six parts. Between two quads, there is an angle of 60 degrees. Three quads intersecting each other at the center means we have six angles of 60 degrees, making a total of 360 degree. This diagram also answers the only interesting question the previous code could provoke. How did we calculate the new positions of the points for the other two quads? It's simple trigonometry. To calculate the y value, we use sines and for the x value, cosines. This technique that we used creates a plane and renders a texture onto it to simulate a more detailed model, this is a wildly used technique in video games called billboarding.

What just happened?
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.248.216