From dea61e7fb984493fec46b771a74868f8baa54a8f Mon Sep 17 00:00:00 2001 From: Jiaming Guo Date: Thu, 26 Jan 2017 13:34:29 -0600 Subject: [PATCH] some tests --- main.cu | 59 +++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/main.cu b/main.cu index 1565528..25cd102 100644 --- a/main.cu +++ b/main.cu @@ -76,10 +76,6 @@ float radius = 3; //equals to radius int adjoint_fac = 0; int light_fac = 0; -//light position -stim::vec3 l1(0.0, 0.0, 0.0); -stim::vec3 l2(0.0, 0.0, 0.0); - //sets an OpenGL viewport taking up the entire window void glut_render_single_projection(){ @@ -130,24 +126,31 @@ void glut_render_modelview(){ //draws the network(s) void glut_render(void) { - // light stim::vec3 eye = cam.getPosition(); //get the camera position (eye point) + stim::vec3 focus = cam.getLookAt(); //get the camera focal point + stim::vec3 up = cam.getUp(); //get the camera "up" orientation + + stim::vec3 v = focus - eye; + stim::vec3 v1 = v.cross(up); + stim::vec3 v2 = up.cross(v); + v1 = v1.norm(); + v2 = v2.norm(); + stim::vec3 l1 = v1 + up; + stim::vec3 l2 = v2 + -up; stim::vec3 s = bb.size(); - - l1[0] = eye[0] + s[0] / 2; - l1[1] = eye[1] + s[1] / 2; - l1[2] = eye[2] + s[2] / 2; - l2[0] = eye[0] - s[0] / 2; - l2[1] = eye[1] - s[1] / 2; - l2[2] = eye[2] - s[2] / 2; - - GLfloat global_ambient[] = { 0.3, 0.3, 0.3, 1.0 }; + float r = s.len(); + + stim::vec3 p1 = focus + l1*r/10; + stim::vec3 p2 = focus + l2*r/10; + + // light + GLfloat global_ambient[] = { 0.5, 0.5, 0.5, 1.0 }; GLfloat ambient[] = { 0.0, 0.0, 0.0, 1.0 }; - GLfloat diffuse1[] = { 0.6, 0.6, 0.6, 1.0 }; + GLfloat diffuse1[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat diffuse2[] = { 0.4, 0.4, 0.4, 1.0 }; - GLfloat specular[] = { 0.6, 0.6, 0.6, 1.0 }; - GLfloat position1[] = { l1[0], l1[1], 50, 0.0 }; // upper right light source - GLfloat position2[] = { l2[0], l2[1], 0, 0.0 }; // lower left light source + GLfloat specular[] = { 1.0, 1.0, 1.0, 1.0 }; + GLfloat position1[] = { p1[0], p1[1], p1[2], 1.0 }; // upper right light source + GLfloat position2[] = { p2[0], p2[1], p2[2], 1.0 }; // lower left light source glClearColor(0.0, 0.0, 0.0, 1.0); glShadeModel(GL_SMOOTH); @@ -163,8 +166,6 @@ void glut_render(void) { glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse2); glLightfv(GL_LIGHT1, GL_SPECULAR, specular); glLightfv(GL_LIGHT1, GL_POSITION, position2); - - glEnable(GL_COLOR_MATERIAL); //no mapping, just comparing if (ind == 0) { @@ -229,11 +230,24 @@ void glut_render(void) { glBindTexture(GL_TEXTURE_1D, cmap_tex); //bind the Brewer texture map glEnable(GL_DEPTH_TEST); //enable depth + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen glut_render_left_projection(); //set up a projection for the left half of the window glut_render_modelview(); //set up the modelview matrix using camera details - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen + + glPushMatrix(); + glTranslatef(p1[0], p1[1], p1[2]); + glColor3f(0.0, 1.0, 0.0); + glutSolidSphere(10, 10, 10); + glPopMatrix(); + glPushMatrix(); + glTranslatef(p2[0], p2[1], p2[2]); + glColor3f(0.0, 0.0, 1.0); + glutSolidSphere(10, 10, 10); + glPopMatrix(); + glColor3f(1, 1, 1); _GT.glCylinder(sigma, radius); //render the GT network + if (adjoint_fac == 1) { glDisable(GL_TEXTURE_1D); //temporarily disable texture glEnable(GL_BLEND); //enable color blend @@ -255,10 +269,11 @@ void glut_render(void) { sigma = radius; //set sigma equal to radius } else { + glEnable(GL_COLOR_MATERIAL); glEnable(GL_DEPTH_TEST); //enable depth + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen glut_render_left_projection(); //set up a projection for the left half of the window glut_render_modelview(); //set up the modelview matrix using camera details - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen _GT.glRandColorCylinder(0, _gt_t, colormap, sigma, radius); -- libgit2 0.21.4