History

Curved Oculus overlay around camera as a semicircle

barnold1953 committed 12 years ago

Commit 90754e31 parent 6f5d2ba5 files · +48 −16Browse files

Showing the changes to interface/src/ui/ApplicationOverlay.cpp (1 of 5 files). Show all

Unified · Split

interface/src/ui/ApplicationOverlay.cpp+35−14
@@ -19,7 +19,8 @@ · 18 unmodified lines
1919
2020 #include "ui/Stats.h"
2121
22−ApplicationOverlay::ApplicationOverlay() : _framebufferObject(NULL) {
22+ApplicationOverlay::ApplicationOverlay() : _framebufferObject(NULL),
23+ _oculusAngle(65.0f * RADIANS_PER_DEGREE) {
2324
2425 }
2526
@@ -271,14 +272,21 @@ void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) { · 245 unmodified lines
271272 MyAvatar* myAvatar = application->getAvatar();
272273 const glm::vec3& viewMatrixTranslation = application->getViewMatrixTranslation();
273274
274− // Calculates the world space width and height of the texture based on a desired FOV
275− const float overlayFov = whichCamera.getFieldOfView() * PI / 180.0f;
276− const float overlayDistance = 1;
275+ // Get vertical FoV of the displayed overlay texture
276+ const float halfVerticalAngle = _oculusAngle / 2.0f;
277+ const float overlayDistance = 1.0;
277278 const float overlayAspectRatio = glWidget->width() / (float)glWidget->height();
278− const float overlayHeight = overlayDistance * tan(overlayFov);
279− const float overlayWidth = overlayHeight * overlayAspectRatio;
280− const float halfOverlayWidth = overlayWidth / 2;
281− const float halfOverlayHeight = overlayHeight / 2;
279+ const float halfOverlayHeight = overlayDistance * tan(halfVerticalAngle);
280+
281+ // The more vertices, the better the curve
282+ const int numHorizontalVertices = 20;
283+ // U texture coordinate width at each quad
284+ const float quadTexWidth = 1.0f / (numHorizontalVertices - 1);
285+
286+ // Get horizontal angle and angle increment from vertical angle and aspect ratio
287+ const float horizontalAngle = halfVerticalAngle * 2.0f * overlayAspectRatio;
288+ const float angleIncrement = horizontalAngle / (numHorizontalVertices - 1);
289+ const float halfHorizontalAngle = horizontalAngle / 2;
282290
283291 glActiveTexture(GL_TEXTURE0);
284292
@@ -305,16 +313,29 @@ void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) { · 20 unmodified lines
305313 glm::vec3 pos = whichCamera.getPosition();
306314 glm::quat rot = myAvatar->getOrientation();
307315 glm::vec3 axis = glm::axis(rot);
308− pos += rot * glm::vec3(0.0, 0.0, -overlayDistance);
309−
316+
310317 glTranslatef(pos.x, pos.y, pos.z);
311318 glRotatef(glm::degrees(glm::angle(rot)), axis.x, axis.y, axis.z);
319+
320+ float leftX, rightX, leftZ, rightZ;
312321
313322 glBegin(GL_QUADS);
314− glTexCoord2f(1, 0); glVertex3f(-halfOverlayWidth, halfOverlayHeight, 0);
315− glTexCoord2f(0, 0); glVertex3f(halfOverlayWidth, halfOverlayHeight, 0);
316− glTexCoord2f(0, 1); glVertex3f(halfOverlayWidth, -halfOverlayHeight, 0);
317− glTexCoord2f(1, 1); glVertex3f(-halfOverlayWidth, -halfOverlayHeight, 0);
323+
324+ // Place the vertices in a semicircle curve around the camera
325+ for (int i = 0; i < numHorizontalVertices-1; i++) {
326+
327+ // Calculate the X and Z coordinates from the angles and radius from camera
328+ leftX = sin(angleIncrement * i - halfHorizontalAngle) * overlayDistance;
329+ rightX = sin(angleIncrement * (i + 1) - halfHorizontalAngle) * overlayDistance;
330+ leftZ = -cos(angleIncrement * i - halfHorizontalAngle) * overlayDistance;
331+ rightZ = -cos(angleIncrement * (i + 1) - halfHorizontalAngle) * overlayDistance;
332+
333+ glTexCoord2f(quadTexWidth * i, 1); glVertex3f(leftX, halfOverlayHeight, leftZ);
334+ glTexCoord2f(quadTexWidth * (i + 1), 1); glVertex3f(rightX, halfOverlayHeight, rightZ);
335+ glTexCoord2f(quadTexWidth * (i + 1), 0); glVertex3f(rightX, -halfOverlayHeight, rightZ);
336+ glTexCoord2f(quadTexWidth * i, 0); glVertex3f(leftX, -halfOverlayHeight, leftZ);
337+ }
338+
318339 glEnd();
319340
320341 glPopMatrix();

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t