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
19 19
20#include "ui/Stats.h"20#include "ui/Stats.h"
21 21
22ApplicationOverlay::ApplicationOverlay() : _framebufferObject(NULL) {22ApplicationOverlay::ApplicationOverlay() : _framebufferObject(NULL),
23 _oculusAngle(65.0f * RADIANS_PER_DEGREE) {
23 24
24}25}
25 26
@@ -271,14 +272,21 @@ void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) { · 245 unmodified lines
271 MyAvatar* myAvatar = application->getAvatar();272 MyAvatar* myAvatar = application->getAvatar();
272 const glm::vec3& viewMatrixTranslation = application->getViewMatrixTranslation();273 const glm::vec3& viewMatrixTranslation = application->getViewMatrixTranslation();
273 274
274 // Calculates the world space width and height of the texture based on a desired FOV275 // Get vertical FoV of the displayed overlay texture
275 const float overlayFov = whichCamera.getFieldOfView() * PI / 180.0f;276 const float halfVerticalAngle = _oculusAngle / 2.0f;
276 const float overlayDistance = 1;277 const float overlayDistance = 1.0;
277 const float overlayAspectRatio = glWidget->width() / (float)glWidget->height();278 const float overlayAspectRatio = glWidget->width() / (float)glWidget->height();
278 const float overlayHeight = overlayDistance * tan(overlayFov);279 const float halfOverlayHeight = overlayDistance * tan(halfVerticalAngle);
279 const float overlayWidth = overlayHeight * overlayAspectRatio;280
280 const float halfOverlayWidth = overlayWidth / 2;281 // The more vertices, the better the curve
281 const float halfOverlayHeight = overlayHeight / 2;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;
282 290
283 glActiveTexture(GL_TEXTURE0);291 glActiveTexture(GL_TEXTURE0);
284 292
@@ -305,16 +313,29 @@ void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) { · 20 unmodified lines
305 glm::vec3 pos = whichCamera.getPosition();313 glm::vec3 pos = whichCamera.getPosition();
306 glm::quat rot = myAvatar->getOrientation();314 glm::quat rot = myAvatar->getOrientation();
307 glm::vec3 axis = glm::axis(rot);315 glm::vec3 axis = glm::axis(rot);
308 pos += rot * glm::vec3(0.0, 0.0, -overlayDistance);316
309
310 glTranslatef(pos.x, pos.y, pos.z);317 glTranslatef(pos.x, pos.y, pos.z);
311 glRotatef(glm::degrees(glm::angle(rot)), axis.x, axis.y, axis.z);318 glRotatef(glm::degrees(glm::angle(rot)), axis.x, axis.y, axis.z);
319
320 float leftX, rightX, leftZ, rightZ;
312 321
313 glBegin(GL_QUADS);322 glBegin(GL_QUADS);
314 glTexCoord2f(1, 0); glVertex3f(-halfOverlayWidth, halfOverlayHeight, 0);323
315 glTexCoord2f(0, 0); glVertex3f(halfOverlayWidth, halfOverlayHeight, 0);324 // Place the vertices in a semicircle curve around the camera
316 glTexCoord2f(0, 1); glVertex3f(halfOverlayWidth, -halfOverlayHeight, 0);325 for (int i = 0; i < numHorizontalVertices-1; i++) {
317 glTexCoord2f(1, 1); glVertex3f(-halfOverlayWidth, -halfOverlayHeight, 0);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
318 glEnd();339 glEnd();
319 340
320 glPopMatrix();341 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