Merged
Merge Request #12 · created by Jiaming Guo


some tests


From JACK into master

Merged by David Mayerich

2 participants

main.cu
... ... @@ -76,10 +76,6 @@ float radius = 3; //equals to radius
76 76 int adjoint_fac = 0;
77 77 int light_fac = 0;
78 78  
79   -//light position
80   -stim::vec3<float> l1(0.0, 0.0, 0.0);
81   -stim::vec3<float> l2(0.0, 0.0, 0.0);
82   -
83 79 //sets an OpenGL viewport taking up the entire window
84 80 void glut_render_single_projection(){
85 81  
... ... @@ -130,24 +126,31 @@ void glut_render_modelview(){
130 126 //draws the network(s)
131 127 void glut_render(void) {
132 128  
133   - // light
134 129 stim::vec3<float> eye = cam.getPosition(); //get the camera position (eye point)
  130 + stim::vec3<float> focus = cam.getLookAt(); //get the camera focal point
  131 + stim::vec3<float> up = cam.getUp(); //get the camera "up" orientation
  132 +
  133 + stim::vec3<float> v = focus - eye;
  134 + stim::vec3<float> v1 = v.cross(up);
  135 + stim::vec3<float> v2 = up.cross(v);
  136 + v1 = v1.norm();
  137 + v2 = v2.norm();
  138 + stim::vec3<float> l1 = v1 + up;
  139 + stim::vec3<float> l2 = v2 + -up;
135 140 stim::vec3<float> s = bb.size();
136   -
137   - l1[0] = eye[0] + s[0] / 2;
138   - l1[1] = eye[1] + s[1] / 2;
139   - l1[2] = eye[2] + s[2] / 2;
140   - l2[0] = eye[0] - s[0] / 2;
141   - l2[1] = eye[1] - s[1] / 2;
142   - l2[2] = eye[2] - s[2] / 2;
143   -
144   - GLfloat global_ambient[] = { 0.3, 0.3, 0.3, 1.0 };
  141 + float r = s.len();
  142 +
  143 + stim::vec3<float> p1 = focus + l1*r/10;
  144 + stim::vec3<float> p2 = focus + l2*r/10;
  145 +
  146 + // light
  147 + GLfloat global_ambient[] = { 0.5, 0.5, 0.5, 1.0 };
145 148 GLfloat ambient[] = { 0.0, 0.0, 0.0, 1.0 };
146   - GLfloat diffuse1[] = { 0.6, 0.6, 0.6, 1.0 };
  149 + GLfloat diffuse1[] = { 1.0, 1.0, 1.0, 1.0 };
147 150 GLfloat diffuse2[] = { 0.4, 0.4, 0.4, 1.0 };
148   - GLfloat specular[] = { 0.6, 0.6, 0.6, 1.0 };
149   - GLfloat position1[] = { l1[0], l1[1], 50, 0.0 }; // upper right light source
150   - GLfloat position2[] = { l2[0], l2[1], 0, 0.0 }; // lower left light source
  151 + GLfloat specular[] = { 1.0, 1.0, 1.0, 1.0 };
  152 + GLfloat position1[] = { p1[0], p1[1], p1[2], 1.0 }; // upper right light source
  153 + GLfloat position2[] = { p2[0], p2[1], p2[2], 1.0 }; // lower left light source
151 154  
152 155 glClearColor(0.0, 0.0, 0.0, 1.0);
153 156 glShadeModel(GL_SMOOTH);
... ... @@ -163,8 +166,6 @@ void glut_render(void) {
163 166 glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse2);
164 167 glLightfv(GL_LIGHT1, GL_SPECULAR, specular);
165 168 glLightfv(GL_LIGHT1, GL_POSITION, position2);
166   -
167   - glEnable(GL_COLOR_MATERIAL);
168 169  
169 170 //no mapping, just comparing
170 171 if (ind == 0) {
... ... @@ -229,11 +230,24 @@ void glut_render(void) {
229 230 glBindTexture(GL_TEXTURE_1D, cmap_tex); //bind the Brewer texture map
230 231  
231 232 glEnable(GL_DEPTH_TEST); //enable depth
  233 + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen
232 234 glut_render_left_projection(); //set up a projection for the left half of the window
233 235 glut_render_modelview(); //set up the modelview matrix using camera details
234   - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen
  236 +
  237 + glPushMatrix();
  238 + glTranslatef(p1[0], p1[1], p1[2]);
  239 + glColor3f(0.0, 1.0, 0.0);
  240 + glutSolidSphere(10, 10, 10);
  241 + glPopMatrix();
  242 + glPushMatrix();
  243 + glTranslatef(p2[0], p2[1], p2[2]);
  244 + glColor3f(0.0, 0.0, 1.0);
  245 + glutSolidSphere(10, 10, 10);
  246 + glPopMatrix();
  247 + glColor3f(1, 1, 1);
235 248  
236 249 _GT.glCylinder(sigma, radius); //render the GT network
  250 +
237 251 if (adjoint_fac == 1) {
238 252 glDisable(GL_TEXTURE_1D); //temporarily disable texture
239 253 glEnable(GL_BLEND); //enable color blend
... ... @@ -255,10 +269,11 @@ void glut_render(void) {
255 269 sigma = radius; //set sigma equal to radius
256 270 }
257 271 else {
  272 + glEnable(GL_COLOR_MATERIAL);
258 273 glEnable(GL_DEPTH_TEST); //enable depth
  274 + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen
259 275 glut_render_left_projection(); //set up a projection for the left half of the window
260 276 glut_render_modelview(); //set up the modelview matrix using camera details
261   - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen
262 277  
263 278 _GT.glRandColorCylinder(0, _gt_t, colormap, sigma, radius);
264 279  
... ...