-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLeaf.cpp
46 lines (38 loc) · 1.46 KB
/
Leaf.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "Leaf.h"
#include <iostream>
Leaf::Leaf(float segmentHeight, float pX, float pY, float pZ, float botR, float topR) {
baseWidth = 0.05f * segmentHeight;
curveWidth = 6.f * baseWidth;
height = segmentHeight / 6.f;
rotation = float(rand() % 360);
float hi = segmentHeight;
float lo = 0;
y = lo + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / (hi - lo)));
float r = botR + ((topR-botR) / segmentHeight)*y;
y += pY;
x = -r * sin((rotation / 360.f)*2.f*3.1415926f) + pX;
z = -r * cos((rotation / 360.f)*2.f*3.1415926f) + pZ;
hi = segmentHeight + (segmentHeight*0.35f);
lo = segmentHeight - (segmentHeight*0.35f);
length = lo + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / (hi - lo)));
}
Leaf::~Leaf() {
}
void Leaf::render() {
glPushMatrix();
glColor3f(69.f / 255.f, 139.f / 255.f, 0.f);
glTranslatef(x, y, z);
glRotatef(rotation, 0.f, 1.f, 0.f);
glBegin(GL_QUADS); //Begin quadrilateral coordinates
glVertex3f(-baseWidth / 2.f, 0.f, 0.f);
glVertex3f(baseWidth / 2.f, 0.f, 0.f);
glVertex3f(curveWidth / 2.f, height, -length / 4.f);
glVertex3f(-curveWidth / 2.f, height, -length / 4.f);
glEnd(); //End quadrilateral coordinates
glBegin(GL_TRIANGLES);
glVertex3f(-curveWidth / 2.f, height, -length / 4.f);
glVertex3f(curveWidth / 2.f, height, -length / 4.f);;
glVertex3f(0.f, height / 2.f, -length);
glEnd();
glPopMatrix();
}