From 4f26c9e0fad6248fcf1bdaa702291e4c68892a8f Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 6 Oct 2014 11:06:23 -0700 Subject: [PATCH] fix formatting and syntax issues --- interface/src/Application.cpp | 10 ++-- interface/src/BuckyBalls.cpp | 2 +- interface/src/Environment.cpp | 2 +- interface/src/avatar/Hand.cpp | 2 +- interface/src/avatar/SkeletonModel.cpp | 4 +- .../src/renderer/DeferredLightingEffect.cpp | 2 +- interface/src/renderer/GeometryCache.cpp | 47 ++++++++++--------- 7 files changed, 36 insertions(+), 33 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 0c892e68f0..215848b355 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -884,11 +884,11 @@ void Application::keyPressEvent(QKeyEvent* event) { case Qt::Key_W: if (isOption && !isShifted && !isMeta) { - Menu::getInstance()->triggerOption(MenuOption::Wireframe); + Menu::getInstance()->triggerOption(MenuOption::Wireframe); } else { - _myAvatar->setDriveKeys(FWD, 1.f); - } - break; + _myAvatar->setDriveKeys(FWD, 1.f); + } + break; case Qt::Key_S: if (isShifted && isMeta && !isOption) { @@ -2906,7 +2906,7 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) { // draw a red sphere float originSphereRadius = 0.05f; glColor3f(1,0,0); - _geometryCache.renderSphere(originSphereRadius, 15, 15); + _geometryCache.renderSphere(originSphereRadius, 15, 15); // draw the audio reflector overlay { diff --git a/interface/src/BuckyBalls.cpp b/interface/src/BuckyBalls.cpp index 893e74f083..0ea73556c5 100644 --- a/interface/src/BuckyBalls.cpp +++ b/interface/src/BuckyBalls.cpp @@ -172,7 +172,7 @@ void BuckyBalls::render() { } glPushMatrix(); glTranslatef(_bballPosition[i].x, _bballPosition[i].y, _bballPosition[i].z); - Application::getInstance()->getGeometryCache()->renderSphere(_bballRadius[i], 15, 15); + Application::getInstance()->getGeometryCache()->renderSphere(_bballRadius[i], 15, 15); glPopMatrix(); } } diff --git a/interface/src/Environment.cpp b/interface/src/Environment.cpp index 6eae464957..631e3da1cf 100644 --- a/interface/src/Environment.cpp +++ b/interface/src/Environment.cpp @@ -266,5 +266,5 @@ void Environment::renderAtmosphere(Camera& camera, const EnvironmentData& data) program->release(); - glPopMatrix(); + glPopMatrix(); } diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index 9bddcd1730..d29e7312ff 100644 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -114,7 +114,7 @@ void Hand::render(bool isMine, Model::RenderMode renderMode) { glPushMatrix(); glTranslatef(position.x, position.y, position.z); glColor3f(0.0f, 1.0f, 0.0f); - Application::getInstance()->getGeometryCache()->renderSphere(PALM_COLLISION_RADIUS * _owningAvatar->getScale(), 10, 10); + Application::getInstance()->getGeometryCache()->renderSphere(PALM_COLLISION_RADIUS * _owningAvatar->getScale(), 10, 10); glPopMatrix(); } } diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 61bee4b4c5..a791d01d53 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -899,7 +899,7 @@ void SkeletonModel::renderJointCollisionShapes(float alpha) { endPoint = endPoint - simulationTranslation; glTranslatef(endPoint.x, endPoint.y, endPoint.z); glColor4f(0.6f, 0.6f, 0.8f, alpha); - Application::getInstance()->getGeometryCache()->renderSphere(capsule->getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); + Application::getInstance()->getGeometryCache()->renderSphere(capsule->getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); // draw a yellow sphere at the capsule startpoint glm::vec3 startPoint; @@ -908,7 +908,7 @@ void SkeletonModel::renderJointCollisionShapes(float alpha) { glm::vec3 axis = endPoint - startPoint; glTranslatef(-axis.x, -axis.y, -axis.z); glColor4f(0.8f, 0.8f, 0.6f, alpha); - Application::getInstance()->getGeometryCache()->renderSphere(capsule->getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); + Application::getInstance()->getGeometryCache()->renderSphere(capsule->getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); // draw a green cylinder between the two points glm::vec3 origin(0.0f); diff --git a/interface/src/renderer/DeferredLightingEffect.cpp b/interface/src/renderer/DeferredLightingEffect.cpp index 46fb889c75..f1668629da 100644 --- a/interface/src/renderer/DeferredLightingEffect.cpp +++ b/interface/src/renderer/DeferredLightingEffect.cpp @@ -51,7 +51,7 @@ void DeferredLightingEffect::releaseSimpleProgram() { void DeferredLightingEffect::renderSolidSphere(float radius, int slices, int stacks) { bindSimpleProgram(); - Application::getInstance()->getGeometryCache()->renderSphere(radius, slices, stacks); + Application::getInstance()->getGeometryCache()->renderSphere(radius, slices, stacks); releaseSimpleProgram(); } diff --git a/interface/src/renderer/GeometryCache.cpp b/interface/src/renderer/GeometryCache.cpp index 1eecebcea2..54e4afb70a 100644 --- a/interface/src/renderer/GeometryCache.cpp +++ b/interface/src/renderer/GeometryCache.cpp @@ -114,17 +114,20 @@ void GeometryCache::renderHemisphere(int slices, int stacks) { void GeometryCache::renderSphere(float radius, int slices, int stacks) { VerticesIndices& vbo = _sphereVBOs[IntPair(slices, stacks)]; int vertices = slices * (stacks - 1) + 2; - int indices = slices * 2 * 3 * (stacks - 1) + slices * 2 * 3; - if (vbo.first == 0) { - GLfloat* vertexData = new GLfloat[vertices * 3]; + int numVerticesPerTriangle = 3; + int numTrianglesPerQuad = 2; + int indices = slices * numTrianglesPerQuad * numVerticesPerTriangle * (stacks - 1) + slices * numTrianglesPerQuad * numVerticesPerTriangle; + if (vbo.first == 0) { + int numCoordinatesPerVertex = 3; + GLfloat* vertexData = new GLfloat[vertices * numCoordinatesPerVertex]; GLfloat* vertex = vertexData; - - // south pole - *(vertex++) = 0.0f; + + // south pole + *(vertex++) = 0.0f; *(vertex++) = 0.0f; *(vertex++) = -1.0f; - //add stacks vertices climbing up Y axis + //add stacks vertices climbing up Y axis for (int i = 1; i < stacks; i++) { float phi = PI * (float)i / (float)(stacks) - PI_OVER_TWO; float z = sinf(phi), radius = cosf(phi); @@ -138,31 +141,31 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks) { } } - // north pole - *(vertex++) = 0.0f; + // north pole + *(vertex++) = 0.0f; *(vertex++) = 0.0f; *(vertex++) = 1.0f; glGenBuffers(1, &vbo.first); glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - const int BYTES_PER_VERTEX = 3 * sizeof(GLfloat); + const int BYTES_PER_VERTEX = numCoordinatesPerVertex * sizeof(GLfloat); glBufferData(GL_ARRAY_BUFFER, vertices * BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); delete[] vertexData; GLushort* indexData = new GLushort[indices]; GLushort* index = indexData; - - // South cap - GLushort bottom = 0; + + // South cap + GLushort bottom = 0; GLushort top = 1; for (int i = 0; i < slices; i++) { *(index++) = bottom; *(index++) = top + i; *(index++) = top + (i + 1) % slices; } - - // (stacks - 2) ribbons - for (int i = 0; i < stacks - 2; i++) { + + // (stacks - 2) ribbons + for (int i = 0; i < stacks - 2; i++) { bottom = i * slices + 1; top = bottom + slices; for (int j = 0; j < slices; j++) { @@ -178,8 +181,8 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks) { } } - // north cap - bottom = (stacks - 2) * slices + 1; + // north cap + bottom = (stacks - 2) * slices + 1; top = bottom + slices; for (int i = 0; i < slices; i++) { *(index++) = bottom + i; @@ -199,12 +202,12 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks) { } glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); - + glVertexPointer(3, GL_FLOAT, 0, 0); glNormalPointer(GL_FLOAT, 0, 0); - - glPushMatrix(); - glScalef(radius, radius, radius); + + glPushMatrix(); + glScalef(radius, radius, radius); glDrawRangeElementsEXT(GL_TRIANGLES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); glPopMatrix();