Showing the changes to interface/src/main.cpp (1 of 47 files). Show all
Unified · Split
| @@ -58,12 +58,15 @@ · 57 unmodified lines | ||
| 58 | 58 | #include "ui/MenuColumn.h" |
| 59 | 59 | #include "ui/Menu.h" |
| 60 | 60 | #include "ui/TextRenderer.h" |
| 61 | +#include "renderer/ProgramObject.h" | |
| 62 | +#include "renderer/ShaderObject.h" | |
| 61 | 63 | |
| 62 | 64 | #include "Camera.h" |
| 63 | 65 | #include "Avatar.h" |
| 64 | 66 | #include <AgentList.h> |
| 65 | 67 | #include <AgentTypes.h> |
| 66 | 68 | #include "VoxelSystem.h" |
| 69 | +#include "Environment.h" | |
| 67 | 70 | #include "Oscilloscope.h" |
| 68 | 71 | #include "UDPSocket.h" |
| 69 | 72 | #include "SerialInterface.h" |
| @@ -120,29 +123,32 @@ char starFile[] = "https://s3-us-west-1.amazonaws.com/highfidelity/stars.txt"; · 50 unmodified lines | ||
| 120 | 123 | char starCacheFile[] = "cachedStars.txt"; |
| 121 | 124 | Stars stars; |
| 122 | 125 | |
| 123 | −bool showingVoxels = true; | |
| 124 | − | |
| 125 | 126 | glm::vec3 box(WORLD_SIZE,WORLD_SIZE,WORLD_SIZE); |
| 126 | 127 | |
| 127 | 128 | VoxelSystem voxels; |
| 128 | 129 | |
| 129 | 130 | bool wantToKillLocalVoxels = false; |
| 130 | 131 | |
| 132 | +Environment environment; | |
| 133 | + | |
| 131 | 134 | |
| 132 | 135 | #ifndef _WIN32 |
| 133 | 136 | Audio audio(&audioScope, &myAvatar); |
| 134 | 137 | #endif |
| 135 | 138 | |
| 136 | 139 | #define IDLE_SIMULATE_MSECS 16 // How often should call simulate and other stuff |
| 137 | − // in the idle loop? | |
| 140 | + // in the idle loop? (60 FPS is default) | |
| 138 | 141 | |
| 139 | −// Where one's own agent begins in the world (needs to become a dynamic thing passed to the program) | |
| 140 | −glm::vec3 start_location(6.1f, 0, 1.4f); | |
| 141 | 142 | |
| 142 | −bool renderWarningsOn = false; // Whether to show render pipeline warnings | |
| 143 | +glm::vec3 start_location(6.1f, 0, 1.4f); // Where one's own agent begins in the world | |
| 144 | + // (will be overwritten if avatar data file is found) | |
| 143 | 145 | |
| 144 | −bool statsOn = false; // Whether to show onscreen text overlay with stats | |
| 145 | −bool starsOn = false; // Whether to display the stars | |
| 146 | +bool renderWarningsOn = false; // Whether to show render pipeline warnings | |
| 147 | +bool renderStatsOn = false; // Whether to show onscreen text overlay with stats | |
| 148 | +bool renderVoxels = true; // Whether to render voxels | |
| 149 | +bool renderStarsOn = true; // Whether to display the stars | |
| 150 | +bool renderAtmosphereOn = true; // Whether to display the atmosphere | |
| 151 | +bool renderAvatarsOn = true; // Whether to render avatars | |
| 146 | 152 | bool paintOn = false; // Whether to paint voxels as you fly around |
| 147 | 153 | VoxelDetail paintingVoxel; // The voxel we're painting if we're painting |
| 148 | 154 | unsigned char dominantColor = 0; // The dominant color of the voxel we're painting |
| @@ -177,7 +183,7 @@ bool chatEntryOn = false; // Whether to show the chat entry · 28 unmodified lines | ||
| 177 | 183 | |
| 178 | 184 | bool oculusOn = false; // Whether to configure the display for the Oculus Rift |
| 179 | 185 | GLuint oculusTextureID = 0; // The texture to which we render for Oculus distortion |
| 180 | −GLhandleARB oculusProgramID = 0; // The GLSL program containing the distortion shader | |
| 186 | +ProgramObject* oculusProgram = 0; // The GLSL program containing the distortion shader | |
| 181 | 187 | float oculusDistortionScale = 1.25; // Controls the Oculus field of view |
| 182 | 188 | |
| 183 | 189 | // |
| @@ -302,6 +308,8 @@ void init(void) { · 118 unmodified lines | ||
| 302 | 308 | voxels.setViewerAvatar(&myAvatar); |
| 303 | 309 | voxels.setCamera(&myCamera); |
| 304 | 310 | |
| 311 | + environment.init(); | |
| 312 | + | |
| 305 | 313 | handControl.setScreenDimensions(WIDTH, HEIGHT); |
| 306 | 314 | |
| 307 | 315 | headMouseX = WIDTH/2; |
| @@ -678,13 +686,31 @@ void renderViewFrustum(ViewFrustum& viewFrustum) { · 370 unmodified lines | ||
| 678 | 686 | void displaySide(Camera& whichCamera) { |
| 679 | 687 | glPushMatrix(); |
| 680 | 688 | |
| 681 | − if (::starsOn) { | |
| 689 | + if (::renderStarsOn) { | |
| 682 | 690 | // should be the first rendering pass - w/o depth buffer / lighting |
| 683 | 691 | |
| 692 | + // compute starfield alpha based on distance from atmosphere | |
| 693 | + float alpha = 1.0f; | |
| 694 | + if (::renderAtmosphereOn) { | |
| 695 | + float height = glm::distance(whichCamera.getPosition(), environment.getAtmosphereCenter()); | |
| 696 | + if (height < environment.getAtmosphereInnerRadius()) { | |
| 697 | + alpha = 0.0f; | |
| 698 | + | |
| 699 | + } else if (height < environment.getAtmosphereOuterRadius()) { | |
| 700 | + alpha = (height - environment.getAtmosphereInnerRadius()) / | |
| 701 | + (environment.getAtmosphereOuterRadius() - environment.getAtmosphereInnerRadius()); | |
| 702 | + } | |
| 703 | + } | |
| 704 | + | |
| 684 | 705 | // finally render the starfield |
| 685 | − stars.render(whichCamera.getFieldOfView(), aspectRatio, whichCamera.getNearClip()); | |
| 706 | + stars.render(whichCamera.getFieldOfView(), aspectRatio, whichCamera.getNearClip(), alpha); | |
| 686 | 707 | } |
| 687 | 708 | |
| 709 | + // draw the sky dome | |
| 710 | + if (::renderAtmosphereOn) { | |
| 711 | + environment.renderAtmosphere(whichCamera); | |
| 712 | + } | |
| 713 | + | |
| 688 | 714 | glEnable(GL_LIGHTING); |
| 689 | 715 | glEnable(GL_DEPTH_TEST); |
| 690 | 716 | |
| @@ -699,23 +725,28 @@ void displaySide(Camera& whichCamera) { · 8 unmodified lines | ||
| 699 | 725 | drawGroundPlaneGrid(10.f); |
| 700 | 726 | |
| 701 | 727 | // Draw voxels |
| 702 | − if (showingVoxels) { | |
| 728 | + if (renderVoxels) { | |
| 703 | 729 | voxels.render(); |
| 704 | 730 | } |
| 705 | 731 | |
| 706 | − // Render avatars of other agents | |
| 707 | − AgentList* agentList = AgentList::getInstance(); | |
| 708 | − agentList->lock(); | |
| 709 | − for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { | |
| 710 | − if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) { | |
| 711 | − Avatar *avatar = (Avatar *)agent->getLinkedData(); | |
| 712 | − avatar->render(0, ::myCamera.getPosition()); | |
| 732 | + if (::renderAvatarsOn) { | |
| 733 | + // Render avatars of other agents | |
| 734 | + AgentList* agentList = AgentList::getInstance(); | |
| 735 | + agentList->lock(); | |
| 736 | + for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { | |
| 737 | + if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) { | |
| 738 | + Avatar *avatar = (Avatar *)agent->getLinkedData(); | |
| 739 | + avatar->render(0, ::myCamera.getPosition()); | |
| 740 | + } | |
| 713 | 741 | } |
| 742 | + agentList->unlock(); | |
| 743 | + | |
| 744 | + // Render my own Avatar | |
| 745 | + myAvatar.render(::lookingInMirror, ::myCamera.getPosition()); | |
| 714 | 746 | } |
| 715 | − agentList->unlock(); | |
| 716 | 747 | |
| 717 | 748 | // Render the world box |
| 718 | − if (!::lookingInMirror && ::statsOn) { render_world_box(); } | |
| 749 | + if (!::lookingInMirror && ::renderStatsOn) { render_world_box(); } | |
| 719 | 750 | |
| 720 | 751 | // brad's frustum for debugging |
| 721 | 752 | if (::frustumOn) renderViewFrustum(::viewFrustum); |
| @@ -806,18 +837,16 @@ void displayOculus(Camera& whichCamera) { · 84 unmodified lines | ||
| 806 | 837 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, WIDTH, HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); |
| 807 | 838 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 808 | 839 | |
| 809 | − GLhandleARB shaderID = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB); | |
| 810 | − glShaderSourceARB(shaderID, 1, &DISTORTION_FRAGMENT_SHADER, 0); | |
| 811 | − glCompileShaderARB(shaderID); | |
| 812 | − ::oculusProgramID = glCreateProgramObjectARB(); | |
| 813 | − glAttachObjectARB(::oculusProgramID, shaderID); | |
| 814 | − glLinkProgramARB(::oculusProgramID); | |
| 815 | − textureLocation = glGetUniformLocationARB(::oculusProgramID, "texture"); | |
| 816 | − lensCenterLocation = glGetUniformLocationARB(::oculusProgramID, "lensCenter"); | |
| 817 | − screenCenterLocation = glGetUniformLocationARB(::oculusProgramID, "screenCenter"); | |
| 818 | − scaleLocation = glGetUniformLocationARB(::oculusProgramID, "scale"); | |
| 819 | − scaleInLocation = glGetUniformLocationARB(::oculusProgramID, "scaleIn"); | |
| 820 | − hmdWarpParamLocation = glGetUniformLocationARB(::oculusProgramID, "hmdWarpParam"); | |
| 840 | + ::oculusProgram = new ProgramObject(); | |
| 841 | + ::oculusProgram->attachFromSourceCode(GL_FRAGMENT_SHADER_ARB, DISTORTION_FRAGMENT_SHADER); | |
| 842 | + ::oculusProgram->link(); | |
| 843 | + | |
| 844 | + textureLocation = ::oculusProgram->getUniformLocation("texture"); | |
| 845 | + lensCenterLocation = ::oculusProgram->getUniformLocation("lensCenter"); | |
| 846 | + screenCenterLocation = ::oculusProgram->getUniformLocation("screenCenter"); | |
| 847 | + scaleLocation = ::oculusProgram->getUniformLocation("scale"); | |
| 848 | + scaleInLocation = ::oculusProgram->getUniformLocation("scaleIn"); | |
| 849 | + hmdWarpParamLocation = ::oculusProgram->getUniformLocation("hmdWarpParam"); | |
| 821 | 850 | |
| 822 | 851 | } else { |
| 823 | 852 | glBindTexture(GL_TEXTURE_2D, ::oculusTextureID); |
| @@ -837,13 +866,13 @@ void displayOculus(Camera& whichCamera) { · 13 unmodified lines | ||
| 837 | 866 | |
| 838 | 867 | glDisable(GL_BLEND); |
| 839 | 868 | glEnable(GL_TEXTURE_2D); |
| 840 | − glUseProgramObjectARB(::oculusProgramID); | |
| 841 | − glUniform1iARB(textureLocation, 0); | |
| 842 | − glUniform2fARB(lensCenterLocation, 0.287994, 0.5); // see SDK docs, p. 29 | |
| 843 | − glUniform2fARB(screenCenterLocation, 0.25, 0.5); | |
| 844 | − glUniform2fARB(scaleLocation, 0.25 * scaleFactor, 0.5 * scaleFactor * aspectRatio); | |
| 845 | − glUniform2fARB(scaleInLocation, 4, 2 / aspectRatio); | |
| 846 | − glUniform4fARB(hmdWarpParamLocation, 1.0, 0.22, 0.24, 0); | |
| 869 | + ::oculusProgram->bind(); | |
| 870 | + ::oculusProgram->setUniform(textureLocation, 0); | |
| 871 | + ::oculusProgram->setUniform(lensCenterLocation, 0.287994, 0.5); // see SDK docs, p. 29 | |
| 872 | + ::oculusProgram->setUniform(screenCenterLocation, 0.25, 0.5); | |
| 873 | + ::oculusProgram->setUniform(scaleLocation, 0.25 * scaleFactor, 0.5 * scaleFactor * aspectRatio); | |
| 874 | + ::oculusProgram->setUniform(scaleInLocation, 4, 2 / aspectRatio); | |
| 875 | + ::oculusProgram->setUniform(hmdWarpParamLocation, 1.0, 0.22, 0.24, 0); | |
| 847 | 876 | |
| 848 | 877 | glColor3f(1, 0, 1); |
| 849 | 878 | glBegin(GL_QUADS); |
| @@ -857,8 +886,8 @@ void displayOculus(Camera& whichCamera) { · 7 unmodified lines | ||
| 857 | 886 | glVertex2f(0, HEIGHT); |
| 858 | 887 | glEnd(); |
| 859 | 888 | |
| 860 | − glUniform2fARB(lensCenterLocation, 0.787994, 0.5); | |
| 861 | − glUniform2fARB(screenCenterLocation, 0.75, 0.5); | |
| 889 | + ::oculusProgram->setUniform(lensCenterLocation, 0.787994, 0.5); | |
| 890 | + ::oculusProgram->setUniform(screenCenterLocation, 0.75, 0.5); | |
| 862 | 891 | |
| 863 | 892 | glBegin(GL_QUADS); |
| 864 | 893 | glTexCoord2f(0.5, 0); |
| @@ -874,7 +903,7 @@ void displayOculus(Camera& whichCamera) { · 9 unmodified lines | ||
| 874 | 903 | glEnable(GL_BLEND); |
| 875 | 904 | glDisable(GL_TEXTURE_2D); |
| 876 | 905 | glBindTexture(GL_TEXTURE_2D, 0); |
| 877 | − glUseProgramObjectARB(0); | |
| 906 | + ::oculusProgram->release(); | |
| 878 | 907 | |
| 879 | 908 | glPopMatrix(); |
| 880 | 909 | } |
| @@ -895,7 +924,7 @@ void displayOverlay() { · 14 unmodified lines | ||
| 895 | 924 | |
| 896 | 925 | //noiseTest(WIDTH, HEIGHT); |
| 897 | 926 | |
| 898 | − if (displayHeadMouse && !::lookingInMirror && statsOn) { | |
| 927 | + if (displayHeadMouse && !::lookingInMirror && renderStatsOn) { | |
| 899 | 928 | // Display small target box at center or head mouse target that can also be used to measure LOD |
| 900 | 929 | glColor3f(1.0, 1.0, 1.0); |
| 901 | 930 | glDisable(GL_LINE_SMOOTH); |
| @@ -917,7 +946,7 @@ void displayOverlay() { · 15 unmodified lines | ||
| 917 | 946 | glLineWidth(1.0f); |
| 918 | 947 | glPointSize(1.0f); |
| 919 | 948 | |
| 920 | − if (::statsOn) { displayStats(); } | |
| 949 | + if (::renderStatsOn) { displayStats(); } | |
| 921 | 950 | if (::logOn) { logger.render(WIDTH, HEIGHT); } |
| 922 | 951 | |
| 923 | 952 | // Show menu |
| @@ -1202,13 +1231,23 @@ int setFullscreen(int state) { · 278 unmodified lines | ||
| 1202 | 1231 | } |
| 1203 | 1232 | |
| 1204 | 1233 | int setVoxels(int state) { |
| 1205 | − return setValue(state, &::showingVoxels); | |
| 1234 | + return setValue(state, &::renderVoxels); | |
| 1206 | 1235 | } |
| 1207 | 1236 | |
| 1208 | 1237 | int setStars(int state) { |
| 1209 | − return setValue(state, &::starsOn); | |
| 1238 | + return setValue(state, &::renderStarsOn); | |
| 1239 | +} | |
| 1240 | + | |
| 1241 | +int setAtmosphere(int state) { | |
| 1242 | + return setValue(state, &::renderAtmosphereOn); | |
| 1243 | +} | |
| 1244 | + | |
| 1245 | +int setRenderAvatars(int state) { | |
| 1246 | + return setValue(state, &::renderAvatarsOn); | |
| 1210 | 1247 | } |
| 1211 | 1248 | |
| 1249 | + | |
| 1250 | + | |
| 1212 | 1251 | int setOculus(int state) { |
| 1213 | 1252 | bool wasOn = ::oculusOn; |
| 1214 | 1253 | int value = setValue(state, &::oculusOn); |
| @@ -1219,7 +1258,7 @@ int setOculus(int state) { · 4 unmodified lines | ||
| 1219 | 1258 | } |
| 1220 | 1259 | |
| 1221 | 1260 | int setStats(int state) { |
| 1222 | − return setValue(state, &::statsOn); | |
| 1261 | + return setValue(state, &::renderStatsOn); | |
| 1223 | 1262 | } |
| 1224 | 1263 | |
| 1225 | 1264 | int setMenu(int state) { |
| @@ -1354,6 +1393,8 @@ void initMenu() { · 128 unmodified lines | ||
| 1354 | 1393 | menuColumnRender = menu.addColumn("Render"); |
| 1355 | 1394 | menuColumnRender->addRow("Voxels (V)", setVoxels); |
| 1356 | 1395 | menuColumnRender->addRow("Stars (*)", setStars); |
| 1396 | + menuColumnRender->addRow("Atmosphere (A)", setAtmosphere); | |
| 1397 | + menuColumnRender->addRow("Avatars", setRenderAvatars); | |
| 1357 | 1398 | menuColumnRender->addRow("Oculus (o)", setOculus); |
| 1358 | 1399 | |
| 1359 | 1400 | // Tools |
| @@ -1432,23 +1473,6 @@ void setupPaintingVoxel() { · 72 unmodified lines | ||
| 1432 | 1473 | shiftPaintingColor(); |
| 1433 | 1474 | } |
| 1434 | 1475 | |
| 1435 | −void addRandomSphere(bool wantColorRandomizer) { | |
| 1436 | − float r = randFloatInRange(0.05,0.1); | |
| 1437 | − float xc = randFloatInRange(r,(1-r)); | |
| 1438 | − float yc = randFloatInRange(r,(1-r)); | |
| 1439 | − float zc = randFloatInRange(r,(1-r)); | |
| 1440 | − float s = 0.001; // size of voxels to make up surface of sphere | |
| 1441 | − bool solid = false; | |
| 1442 | − | |
| 1443 | − printLog("random sphere\n"); | |
| 1444 | − printLog("radius=%f\n",r); | |
| 1445 | − printLog("xc=%f\n",xc); | |
| 1446 | − printLog("yc=%f\n",yc); | |
| 1447 | − printLog("zc=%f\n",zc); | |
| 1448 | − | |
| 1449 | − voxels.createSphere(r,xc,yc,zc,s,solid,wantColorRandomizer); | |
| 1450 | −} | |
| 1451 | − | |
| 1452 | 1476 | const float KEYBOARD_YAW_RATE = 0.8; |
| 1453 | 1477 | const float KEYBOARD_PITCH_RATE = 0.6; |
| 1454 | 1478 | const float KEYBOARD_STRAFE_RATE = 0.03; |
| @@ -1533,9 +1557,10 @@ void key(unsigned char k, int x, int y) { · 78 unmodified lines | ||
| 1533 | 1557 | |
| 1534 | 1558 | // Process keypresses |
| 1535 | 1559 | if (k == 'q' || k == 'Q') ::terminate(); |
| 1536 | − if (k == '/') ::statsOn = !::statsOn; // toggle stats | |
| 1537 | − if (k == '*') ::starsOn = !::starsOn; // toggle stars | |
| 1538 | − if (k == 'V' || k == 'v') ::showingVoxels = !::showingVoxels; // toggle voxels | |
| 1560 | + if (k == '/') ::renderStatsOn = !::renderStatsOn; // toggle stats | |
| 1561 | + if (k == '*') ::renderStarsOn = !::renderStarsOn; // toggle stars | |
| 1562 | + if (k == 'V' || k == 'v') ::renderVoxels = !::renderVoxels; // toggle voxels | |
| 1563 | + if (k == 'A') ::renderAtmosphereOn = !::renderAtmosphereOn; | |
| 1539 | 1564 | if (k == 'F') ::frustumOn = !::frustumOn; // toggle view frustum debugging |
| 1540 | 1565 | if (k == 'C') ::cameraFrustum = !::cameraFrustum; // toggle which frustum to look at |
| 1541 | 1566 | if (k == 'O' || k == 'G') setFrustumOffset(MENU_ROW_PICKED); // toggle view frustum offset debugging |
| @@ -1629,6 +1654,9 @@ void* networkReceive(void* args) { · 87 unmodified lines | ||
| 1629 | 1654 | case PACKET_HEADER_ERASE_VOXEL: |
| 1630 | 1655 | voxels.parseData(incomingPacket, bytesReceived); |
| 1631 | 1656 | break; |
| 1657 | + case PACKET_HEADER_ENVIRONMENT_DATA: | |
| 1658 | + environment.parseData(incomingPacket, bytesReceived); | |
| 1659 | + break; | |
| 1632 | 1660 | case PACKET_HEADER_BULK_AVATAR_DATA: |
| 1633 | 1661 | AgentList::getInstance()->processBulkAgentData(&senderAddress, |
| 1634 | 1662 | incomingPacket, |
| @@ -1674,6 +1702,7 @@ void idle(void) { · 39 unmodified lines | ||
| 1674 | 1702 | handControl.stop(); |
| 1675 | 1703 | } |
| 1676 | 1704 | |
| 1705 | + // Read serial port interface devices | |
| 1677 | 1706 | if (serialPort.active && USING_INVENSENSE_MPU9150) { |
| 1678 | 1707 | serialPort.readData(); |
| 1679 | 1708 | } |
| @@ -1699,7 +1728,11 @@ void idle(void) { · 19 unmodified lines | ||
| 1699 | 1728 | |
| 1700 | 1729 | myAvatar.setGravity(getGravity(myAvatar.getPosition())); |
| 1701 | 1730 | myAvatar.simulate(deltaTime); |
| 1702 | − | |
| 1731 | + | |
| 1732 | + // Update audio stats for procedural sounds | |
| 1733 | + audio.setLastAcceleration(myAvatar.getThrust()); | |
| 1734 | + audio.setLastVelocity(myAvatar.getVelocity()); | |
| 1735 | + | |
| 1703 | 1736 | glutPostRedisplay(); |
| 1704 | 1737 | lastTimeIdle = check; |
| 1705 | 1738 | } |
| @@ -1733,6 +1766,7 @@ void reshape(int width, int height) { · 27 unmodified lines | ||
| 1733 | 1766 | glBindTexture(GL_TEXTURE_2D, 0); |
| 1734 | 1767 | } |
| 1735 | 1768 | } else { |
| 1769 | + camera.setAspectRatio(aspectRatio); | |
| 1736 | 1770 | camera.setFieldOfView(fov = 60); |
| 1737 | 1771 | } |
| 1738 | 1772 | |