From 7bda2c058184297b6d8b27f3f07dfc71c3b18633 Mon Sep 17 00:00:00 2001 From: stojce Date: Wed, 27 Feb 2013 01:52:40 +0100 Subject: [PATCH] #19069 Add iris textures to avatar head, change lighting --- interface/src/Head.cpp | 64 ++++++++++++++++++++++++++++++--------- interface/src/Texture.cpp | 2 +- interface/src/main.cpp | 6 ++-- 3 files changed, 54 insertions(+), 18 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 6930d7a77a..eb5c294105 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -8,10 +8,13 @@ #include #include -#include #include "Head.h" -#include "Util.h" -#include "SerialInterface.h" +#include +#include +#include +#include + +using namespace std; float skinColor[] = {1.0, 0.84, 0.66}; float browColor[] = {210.0/255.0, 105.0/255.0, 30.0/255.0}; @@ -28,6 +31,12 @@ float browThickness = 0.16; const float DECAY = 0.1; +char iris_texture_file[] = "interface.app/Contents/Resources/images/green_eye.png"; + +static vector iris_texture; +unsigned int iris_texture_width = 512; +unsigned int iris_texture_height = 256; + Head::Head() { position.x = position.y = position.z = 0; @@ -58,6 +67,14 @@ Head::Head() renderPitch = 0.0; setNoise(0); hand = new Hand(glm::vec3(skinColor[0], skinColor[1], skinColor[2])); + + + if (iris_texture.size() == 0) { + unsigned error = lodepng::decode(iris_texture, iris_texture_width, iris_texture_height, iris_texture_file); + if (error != 0) { + std::cout << "error " << error << ": " << lodepng_error_text(error) << std::endl; + } + } } Head::~Head() { @@ -212,11 +229,11 @@ void Head::simulate(float deltaTime) { SetNewHeadTarget((randFloat()-0.5)*20.0, (randFloat()-0.5)*45.0); } - + if (0) { - - // Pick new target + + // Pick new target PitchTarget = (randFloat() - 0.5)*45; YawTarget = (randFloat() - 0.5)*22; } @@ -326,14 +343,27 @@ void Head::render(int faceToFace, float * myLocation) glutSolidSphere(0.25, 30, 30); } glPopMatrix(); + // Right Pupil + GLUquadric *sphere = gluNewQuadric(); + gluQuadricTexture(sphere, GL_TRUE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + gluQuadricOrientation(sphere, GLU_OUTSIDE); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, iris_texture_width, iris_texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, &iris_texture[0]); + glPushMatrix(); + { glRotatef(EyeballPitch[1], 1, 0, 0); glRotatef(EyeballYaw[1] + PupilConverge, 0, 1, 0); glTranslatef(0,0,.35); - if (!eyeContact) glColor3f(0,0,0); else glColor3f(0.3,0.3,0.3); - //glRotatef(90,0,1,0); - glutSolidSphere(PupilSize, 15, 15); + glRotatef(-75,1,0,0); + glScalef(1.0, 0.4, 1.0); + + glEnable(GL_TEXTURE_2D); + gluSphere(sphere, PupilSize, 15, 15); + glDisable(GL_TEXTURE_2D); + } glPopMatrix(); // Left Eye @@ -349,14 +379,20 @@ void Head::render(int faceToFace, float * myLocation) glPopMatrix(); // Left Pupil glPushMatrix(); + { glRotatef(EyeballPitch[0], 1, 0, 0); glRotatef(EyeballYaw[0] - PupilConverge, 0, 1, 0); - glTranslatef(0,0,.35); - if (!eyeContact) glColor3f(0,0,0); else glColor3f(0.3,0.3,0.3); - //glRotatef(90,0,1,0); - glutSolidSphere(PupilSize, 15, 15); - glPopMatrix(); + glTranslatef(0, 0, .35); + glRotatef(-75, 1, 0, 0); + glScalef(1.0, 0.4, 1.0); + + glEnable(GL_TEXTURE_2D); + gluSphere(sphere, PupilSize, 15, 15); + glDisable(GL_TEXTURE_2D); + } + gluDeleteQuadric(sphere); + glPopMatrix(); } glPopMatrix(); diff --git a/interface/src/Texture.cpp b/interface/src/Texture.cpp index d7fc2c9a26..e0671cc881 100644 --- a/interface/src/Texture.cpp +++ b/interface/src/Texture.cpp @@ -9,7 +9,7 @@ #include "Texture.h" #include "InterfaceConfig.h" -#include +#include #include #include diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 9b02250633..4692189cb6 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -531,7 +531,7 @@ void display(void) glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); - GLfloat light_position0[] = { 1.0, 1.0, 0.0, 0.0 }; + GLfloat light_position0[] = { 1.0, 1.0, 0.75, 0.0 }; glLightfv(GL_LIGHT0, GL_POSITION, light_position0); GLfloat ambient_color[] = { 0.125, 0.305, 0.5 }; glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_color); @@ -539,10 +539,10 @@ void display(void) glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_color); GLfloat specular_color[] = { 1.0, 1.0, 1.0, 1.0}; glLightfv(GL_LIGHT0, GL_SPECULAR, specular_color); - + glMaterialfv(GL_FRONT, GL_SPECULAR, specular_color); glMateriali(GL_FRONT, GL_SHININESS, 96); - + // Rotate, translate to camera location glRotatef(myHead.getRenderPitch(), 1, 0, 0); glRotatef(myHead.getRenderYaw(), 0, 1, 0);