mirror of
https://github.com/overte-org/overte.git
synced 2025-07-14 12:36:33 +02:00
Merge pull request #806 from LionTurtle/master
Add renderHalfCylinder function and render a static half cylinder behind the face in full frame mode.
This commit is contained in:
commit
a8099c93c0
4 changed files with 83 additions and 3 deletions
|
@ -63,7 +63,6 @@ void Face::setFrameFromWebcam() {
|
||||||
_textureSize = webcam->getTextureSize();
|
_textureSize = webcam->getTextureSize();
|
||||||
_textureRect = webcam->getFaceRect();
|
_textureRect = webcam->getFaceRect();
|
||||||
_aspectRatio = webcam->getAspectRatio();
|
_aspectRatio = webcam->getAspectRatio();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
clearFrame();
|
clearFrame();
|
||||||
}
|
}
|
||||||
|
@ -262,6 +261,11 @@ bool Face::render(float alpha) {
|
||||||
xScale = FULL_FRAME_SCALE * _owningHead->getScale();
|
xScale = FULL_FRAME_SCALE * _owningHead->getScale();
|
||||||
zScale = xScale * 0.3f;
|
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 {
|
} else {
|
||||||
aspect = _aspectRatio;
|
aspect = _aspectRatio;
|
||||||
xScale = BODY_BALL_RADIUS_HEAD_BASE * _owningHead->getScale();
|
xScale = BODY_BALL_RADIUS_HEAD_BASE * _owningHead->getScale();
|
||||||
|
@ -308,7 +312,7 @@ bool Face::render(float alpha) {
|
||||||
glGenBuffers(1, &_iboID);
|
glGenBuffers(1, &_iboID);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iboID);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iboID);
|
||||||
int* indices = new int[INDEX_COUNT];
|
int* indices = new int[INDEX_COUNT];
|
||||||
int* indexPosition = indices;
|
int* indexPosition = indices;
|
||||||
for (int i = 0; i < QUAD_HEIGHT; i++) {
|
for (int i = 0; i < QUAD_HEIGHT; i++) {
|
||||||
for (int j = 0; j < QUAD_WIDTH; j++) {
|
for (int j = 0; j < QUAD_WIDTH; j++) {
|
||||||
*indexPosition++ = i * VERTEX_WIDTH + j;
|
*indexPosition++ = i * VERTEX_WIDTH + j;
|
||||||
|
|
|
@ -61,7 +61,7 @@ private:
|
||||||
cv::Size2f _textureSize;
|
cv::Size2f _textureSize;
|
||||||
cv::RotatedRect _textureRect;
|
cv::RotatedRect _textureRect;
|
||||||
float _aspectRatio;
|
float _aspectRatio;
|
||||||
|
|
||||||
vpx_codec_ctx_t _colorCodec;
|
vpx_codec_ctx_t _colorCodec;
|
||||||
vpx_codec_ctx_t _depthCodec;
|
vpx_codec_ctx_t _depthCodec;
|
||||||
bool _lastFullFrame;
|
bool _lastFullFrame;
|
||||||
|
|
|
@ -163,3 +163,77 @@ void GeometryCache::renderSquare(int xDivisions, int yDivisions) {
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
glBindBuffer(GL_ELEMENT_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);
|
||||||
|
}
|
|
@ -20,6 +20,7 @@ public:
|
||||||
|
|
||||||
void renderHemisphere(int slices, int stacks);
|
void renderHemisphere(int slices, int stacks);
|
||||||
void renderSquare(int xDivisions, int yDivisions);
|
void renderSquare(int xDivisions, int yDivisions);
|
||||||
|
void renderHalfCylinder(int slices, int stacks);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -28,6 +29,7 @@ private:
|
||||||
|
|
||||||
QHash<IntPair, VerticesIndices> _hemisphereVBOs;
|
QHash<IntPair, VerticesIndices> _hemisphereVBOs;
|
||||||
QHash<IntPair, VerticesIndices> _squareVBOs;
|
QHash<IntPair, VerticesIndices> _squareVBOs;
|
||||||
|
QHash<IntPair, VerticesIndices> _halfCylinderVBOs;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__interface__GeometryCache__) */
|
#endif /* defined(__interface__GeometryCache__) */
|
||||||
|
|
Loading…
Reference in a new issue