-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBud.cu
100 lines (84 loc) · 1.93 KB
/
Bud.cu
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "Bud.h"
#include <assert.h>
#include <vector>
#include <math.h>
#include "GL/glut.h"
#include "Config.h"
#include "util.h"
#include "Internode.h"
#include "common.h"
#include "space_col.h"
//struct OptVec optVecs[MAX_INTERNODES];
struct OptVec *optVecs;
struct OptVec *d_optVec;
float Bud::_specular[] = {158.f/255, 189.f/255, 25.f/255, 1};
//
static
float dot_product(float vec1[3], float vec2[3])
{
return vec1[0]*vec2[0] + vec1[1]*vec2[1] + vec1[2]*vec2[2];
}
static
float len(float vec[3])
{
return sqrt(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]);
}
static
void normalize(float vec[3])
{
float fLen = len(vec);
if(fLen > 0)
{
vec[0] /= fLen;
vec[1] /= fLen;
vec[2] /= fLen;
}
}
//
float Bud::getLightReceived(float budOrt[3], float sunVec[3])
{
float reversedSunVec[3] = {0};
reversedSunVec[0] = -sunVec[0];
reversedSunVec[1] = -sunVec[1];
reversedSunVec[2] = -sunVec[2];
normalize(reversedSunVec);
float cBudOrt[3] = {0};
cBudOrt[0] = budOrt[0];
cBudOrt[1] = budOrt[1];
cBudOrt[2] = budOrt[2];
normalize(cBudOrt);
//
return dot_product(cBudOrt, reversedSunVec);
}
//
void Bud::Render()
{
glPushMatrix();
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, _specular);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, _specular);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, _specular);
glTranslatef( pos.x(), pos.y(), pos.z());
glutSolidSphere(0.1, 10, 10);
glPopMatrix();
float myOptVec[3] = {0};
if(nId != -1) // Terminal Bud
{
memcpy(myOptVec, optVecs[nId].vec , sizeof(float) * 3);
}
else // Anxillary Bud
{
memcpy(myOptVec, ort, sizeof(float) * 3);
}
// display
//glDisable(GL_LIGHTING);
//glColor3f(1, 1, 1);
//const int factor = 1;
//glBegin(GL_LINES);
// glVertex3f(pos.x(), pos.y(), pos.z());
// glVertex3f( pos.x() + myOptVec[0] * factor,
// pos.y() + myOptVec[1] * factor,
// pos.z() + myOptVec[2] * factor);
//glEnd();
//glEnable(GL_LIGHTING);
//glLineWidth(1);
}