We will use the previous code and we will only add two new quads to our grass blades:
//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);
//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)
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:
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.
18.217.248.216