diff --git a/interface/src/avatar/Face.cpp b/interface/src/avatar/Face.cpp index 22ce3c0727..1949fa6c8c 100644 --- a/interface/src/avatar/Face.cpp +++ b/interface/src/avatar/Face.cpp @@ -63,7 +63,6 @@ void Face::setFrameFromWebcam() { _textureSize = webcam->getTextureSize(); _textureRect = webcam->getFaceRect(); _aspectRatio = webcam->getAspectRatio(); - } else { clearFrame(); } @@ -262,6 +261,11 @@ bool Face::render(float alpha) { xScale = FULL_FRAME_SCALE * _owningHead->getScale(); zScale = xScale * 0.3f; + glPushMatrix(); + glColor4f(1.0f, 1.0f, 1.0f, alpha); + glScalef(xScale / 12, xScale / (aspect * 3), zScale / 2); + Application::getInstance()->getGeometryCache()->renderHalfCylinder(25, 20); + glPopMatrix(); } else { aspect = _aspectRatio; xScale = BODY_BALL_RADIUS_HEAD_BASE * _owningHead->getScale(); @@ -308,7 +312,7 @@ bool Face::render(float alpha) { glGenBuffers(1, &_iboID); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iboID); int* indices = new int[INDEX_COUNT]; - int* indexPosition = indices; + int* indexPosition = indices; for (int i = 0; i < QUAD_HEIGHT; i++) { for (int j = 0; j < QUAD_WIDTH; j++) { *indexPosition++ = i * VERTEX_WIDTH + j; diff --git a/interface/src/avatar/Face.h b/interface/src/avatar/Face.h index f3e681ff72..1a68f8173e 100644 --- a/interface/src/avatar/Face.h +++ b/interface/src/avatar/Face.h @@ -61,7 +61,7 @@ private: cv::Size2f _textureSize; cv::RotatedRect _textureRect; float _aspectRatio; - + vpx_codec_ctx_t _colorCodec; vpx_codec_ctx_t _depthCodec; bool _lastFullFrame; diff --git a/interface/src/renderer/GeometryCache.cpp b/interface/src/renderer/GeometryCache.cpp index 8331a5deb9..adc4d98361 100644 --- a/interface/src/renderer/GeometryCache.cpp +++ b/interface/src/renderer/GeometryCache.cpp @@ -163,3 +163,77 @@ void GeometryCache::renderSquare(int xDivisions, int yDivisions) { glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } + +void GeometryCache::renderHalfCylinder(int slices, int stacks) { + VerticesIndices& vbo = _halfCylinderVBOs[IntPair(slices, stacks)]; + int vertices = (slices + 1) * stacks; + int indices = 2 * 3 * slices * (stacks - 1); + if (vbo.first == 0) { + GLfloat* vertexData = new GLfloat[vertices * 2 * 3]; + GLfloat* vertex = vertexData; + for (int i = 0; i <= (stacks - 1); i++) { + float y = (float)i / (stacks - 1); + + for (int j = 0; j <= slices; j++) { + float theta = 3 * PIf / 2 + PIf * j / slices; + + //normals + *(vertex++) = sinf(theta); + *(vertex++) = 0; + *(vertex++) = cosf(theta); + + // vertices + *(vertex++) = sinf(theta); + *(vertex++) = y; + *(vertex++) = cosf(theta); + } + } + + glGenBuffers(1, &vbo.first); + glBindBuffer(GL_ARRAY_BUFFER, vbo.first); + const int BYTES_PER_VERTEX = 3 * sizeof(GLfloat); + glBufferData(GL_ARRAY_BUFFER, 2 * vertices * BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); + delete[] vertexData; + + GLushort* indexData = new GLushort[indices]; + GLushort* index = indexData; + for (int i = 0; i < stacks - 1; i++) { + GLushort bottom = i * (slices + 1); + GLushort top = bottom + slices + 1; + for (int j = 0; j < slices; j++) { + int next = j + 1; + + *(index++) = bottom + j; + *(index++) = top + next; + *(index++) = top + j; + + *(index++) = bottom + j; + *(index++) = bottom + next; + *(index++) = top + next; + } + } + + glGenBuffers(1, &vbo.second); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); + const int BYTES_PER_INDEX = sizeof(GLushort); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); + delete[] indexData; + + } else { + glBindBuffer(GL_ARRAY_BUFFER, vbo.first); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); + } + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_NORMAL_ARRAY); + + glNormalPointer(GL_FLOAT, 6 * sizeof(float), 0); + glVertexPointer(3, GL_FLOAT, (6 * sizeof(float)), (const void *)(3 * sizeof(float))); + + glDrawRangeElementsEXT(GL_TRIANGLES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_NORMAL_ARRAY); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); +} \ No newline at end of file diff --git a/interface/src/renderer/GeometryCache.h b/interface/src/renderer/GeometryCache.h index bfce642554..f1e1ec4e34 100644 --- a/interface/src/renderer/GeometryCache.h +++ b/interface/src/renderer/GeometryCache.h @@ -20,6 +20,7 @@ public: void renderHemisphere(int slices, int stacks); void renderSquare(int xDivisions, int yDivisions); + void renderHalfCylinder(int slices, int stacks); private: @@ -28,6 +29,7 @@ private: QHash _hemisphereVBOs; QHash _squareVBOs; + QHash _halfCylinderVBOs; }; #endif /* defined(__interface__GeometryCache__) */