History

Merge branch 'master' of https://github.com/worklist/hifi into render_voxels_optimization

ZappoMan committed 13 years ago

Commit c73d4dd2 parents f490f3e 3bb40b519 files · +712 −647Browse files

Showing the changes to interface/src/main.cpp (1 of 19 files). Show all

Unified · Split

interface/src/main.cpp+385−323
@@ -70,7 +70,6 @@ · 69 unmodified lines
7070 #include "Oscilloscope.h"
7171 #include "UDPSocket.h"
7272 #include "SerialInterface.h"
73−#include <SharedUtil.h>
7473 #include <PacketHeaders.h>
7574 #include <AvatarData.h>
7675 #include <PerfStat.h>
@@ -148,15 +147,15 @@ bool renderStarsOn = true; // Whether to display the stars · 71 unmodified lines
148147 bool renderAtmosphereOn = true; // Whether to display the atmosphere
149148 bool renderAvatarsOn = true; // Whether to render avatars
150149 bool paintOn = false; // Whether to paint voxels as you fly around
151−VoxelDetail paintingVoxel; // The voxel we're painting if we're painting
152−unsigned char dominantColor = 0; // The dominant color of the voxel we're painting
153−bool perfStatsOn = false; // Do we want to display perfStats?
150+VoxelDetail paintingVoxel; // The voxel we're painting if we're painting
151+unsigned char dominantColor = 0; // The dominant color of the voxel we're painting
152+bool perfStatsOn = false; // Do we want to display perfStats?
154153
155154 bool logOn = true; // Whether to show on-screen log
156155
157156 bool wantToKillLocalVoxels = false;
158157
159−int noiseOn = 0; // Whether to add random noise
158+int noiseOn = 0; // Whether to add random noise
160159 float noise = 1.0; // Overall magnitude scaling for random noise levels
161160
162161 bool gyroLook = true; // Whether to allow the gyro data from head to move your view
@@ -211,11 +210,11 @@ void Timer(int extra) { · 48 unmodified lines
211210 FPS = (float)frameCount / ((float)diffclock(&timerStart, &timerEnd) / 1000.f);
212211 packetsPerSecond = (float)packetCount / ((float)diffclock(&timerStart, &timerEnd) / 1000.f);
213212 bytesPerSecond = (float)bytesCount / ((float)diffclock(&timerStart, &timerEnd) / 1000.f);
214− frameCount = 0;
213+ frameCount = 0;
215214 packetCount = 0;
216215 bytesCount = 0;
217216
218− glutTimerFunc(1000,Timer,0);
217+ glutTimerFunc(1000,Timer,0);
219218 gettimeofday(&timerStart, NULL);
220219
221220 // if we haven't detected gyros, check for them now
@@ -240,27 +239,27 @@ void displayStats(void) { · 18 unmodified lines
240239 voxelStats << "Voxels Rendered: " << voxels.getVoxelsRendered() / 1000.f << "K Updated: " << voxels.getVoxelsUpdated()/1000.f << "K";
241240 drawtext(10, statsVerticalOffset + 230, 0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str());
242241
243− voxelStats.str("");
244− voxelStats << "Voxels Created: " << voxels.getVoxelsCreated() / 1000.f << "K (" << voxels.getVoxelsCreatedPerSecondAverage() / 1000.f
242+ voxelStats.str("");
243+ voxelStats << "Voxels Created: " << voxels.getVoxelsCreated() / 1000.f << "K (" << voxels.getVoxelsCreatedPerSecondAverage() / 1000.f
245244 << "Kps) ";
246245 drawtext(10, statsVerticalOffset + 250, 0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str());
247246
248− voxelStats.str("");
249− voxelStats << "Voxels Colored: " << voxels.getVoxelsColored() / 1000.f << "K (" << voxels.getVoxelsColoredPerSecondAverage() / 1000.f
247+ voxelStats.str("");
248+ voxelStats << "Voxels Colored: " << voxels.getVoxelsColored() / 1000.f << "K (" << voxels.getVoxelsColoredPerSecondAverage() / 1000.f
250249 << "Kps) ";
251250 drawtext(10, statsVerticalOffset + 270, 0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str());
252251
253− voxelStats.str("");
254− voxelStats << "Voxel Bits Read: " << voxels.getVoxelsBytesRead() * 8.f / 1000000.f
252+ voxelStats.str("");
253+ voxelStats << "Voxel Bits Read: " << voxels.getVoxelsBytesRead() * 8.f / 1000000.f
255254 << "M (" << voxels.getVoxelsBytesReadPerSecondAverage() * 8.f / 1000000.f << " Mbps)";
256255 drawtext(10, statsVerticalOffset + 290,0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str());
257256
258− voxelStats.str("");
259− float voxelsBytesPerColored = voxels.getVoxelsColored()
257+ voxelStats.str("");
258+ float voxelsBytesPerColored = voxels.getVoxelsColored()
260259 ? ((float) voxels.getVoxelsBytesRead() / voxels.getVoxelsColored())
261260 : 0;
262261
263− voxelStats << "Voxels Bits per Colored: " << voxelsBytesPerColored * 8;
262+ voxelStats << "Voxels Bits per Colored: " << voxelsBytesPerColored * 8;
264263 drawtext(10, statsVerticalOffset + 310, 0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str());
265264
266265 Agent *avatarMixer = AgentList::getInstance()->soloAgentOfType(AGENT_TYPE_AVATAR_MIXER);
@@ -276,19 +275,19 @@ void displayStats(void) { · 9 unmodified lines
276275
277276 drawtext(10, statsVerticalOffset + 330, 0.10f, 0, 1.0, 0, avatarMixerStats);
278277
279− if (::perfStatsOn) {
280− // Get the PerfStats group details. We need to allocate and array of char* long enough to hold 1+groups
281− char** perfStatLinesArray = new char*[PerfStat::getGroupCount()+1];
282− int lines = PerfStat::DumpStats(perfStatLinesArray);
283− int atZ = 150; // arbitrary place on screen that looks good
284− for (int line=0; line < lines; line++) {
285− drawtext(10, statsVerticalOffset + atZ, 0.10f, 0, 1.0, 0, perfStatLinesArray[line]);
286− delete perfStatLinesArray[line]; // we're responsible for cleanup
287− perfStatLinesArray[line]=NULL;
288− atZ+=20; // height of a line
289− }
290− delete []perfStatLinesArray; // we're responsible for cleanup
291− }
278+ if (::perfStatsOn) {
279+ // Get the PerfStats group details. We need to allocate and array of char* long enough to hold 1+groups
280+ char** perfStatLinesArray = new char*[PerfStat::getGroupCount()+1];
281+ int lines = PerfStat::DumpStats(perfStatLinesArray);
282+ int atZ = 150; // arbitrary place on screen that looks good
283+ for (int line=0; line < lines; line++) {
284+ drawtext(10, statsVerticalOffset + atZ, 0.10f, 0, 1.0, 0, perfStatLinesArray[line]);
285+ delete perfStatLinesArray[line]; // we're responsible for cleanup
286+ perfStatLinesArray[line]=NULL;
287+ atZ+=20; // height of a line
288+ }
289+ delete []perfStatLinesArray; // we're responsible for cleanup
290+ }
292291 }
293292
294293 void initDisplay(void) {
@@ -321,9 +320,9 @@ void init(void) { · 26 unmodified lines
321320 myAvatar.setNoise(noise);
322321 }
323322 myAvatar.setPosition(start_location);
324− myCamera.setPosition(start_location);
323+ myCamera.setPosition(start_location);
324+
325325
326−
327326 #ifdef MARKER_CAPTURE
328327 if(marker_capture_enabled){
329328 marker_capturer.position_updated(&position_updated);
@@ -472,25 +471,25 @@ void updateAvatar(float deltaTime) { · 142 unmodified lines
472471 // If I'm in paint mode, send a voxel out to VOXEL server agents.
473472 if (::paintOn) {
474473
475− glm::vec3 avatarPos = myAvatar.getPosition();
476−
477− // For some reason, we don't want to flip X and Z here.
478− ::paintingVoxel.x = avatarPos.x / 10.0;
479− ::paintingVoxel.y = avatarPos.y / 10.0;
480− ::paintingVoxel.z = avatarPos.z / 10.0;
481−
482− unsigned char* bufferOut;
483− int sizeOut;
484−
485− if (::paintingVoxel.x >= 0.0 && ::paintingVoxel.x <= 1.0 &&
486− ::paintingVoxel.y >= 0.0 && ::paintingVoxel.y <= 1.0 &&
487− ::paintingVoxel.z >= 0.0 && ::paintingVoxel.z <= 1.0) {
488−
489− if (createVoxelEditMessage(PACKET_HEADER_SET_VOXEL, 0, 1, &::paintingVoxel, bufferOut, sizeOut)){
474+ glm::vec3 avatarPos = myAvatar.getPosition();
475+
476+ // For some reason, we don't want to flip X and Z here.
477+ ::paintingVoxel.x = avatarPos.x / 10.0;
478+ ::paintingVoxel.y = avatarPos.y / 10.0;
479+ ::paintingVoxel.z = avatarPos.z / 10.0;
480+
481+ unsigned char* bufferOut;
482+ int sizeOut;
483+
484+ if (::paintingVoxel.x >= 0.0 && ::paintingVoxel.x <= 1.0 &&
485+ ::paintingVoxel.y >= 0.0 && ::paintingVoxel.y <= 1.0 &&
486+ ::paintingVoxel.z >= 0.0 && ::paintingVoxel.z <= 1.0) {
487+
488+ if (createVoxelEditMessage(PACKET_HEADER_SET_VOXEL, 0, 1, &::paintingVoxel, bufferOut, sizeOut)){
490489 AgentList::getInstance()->broadcastToAgents(bufferOut, sizeOut, &AGENT_TYPE_VOXEL, 1);
491− delete bufferOut;
492− }
493− }
490+ delete bufferOut;
491+ }
492+ }
494493 }
495494 }
496495
@@ -498,7 +497,7 @@ void updateAvatar(float deltaTime) { · 1 unmodified line
498497 // loadViewFrustum()
499498 //
500499 // Description: this will load the view frustum bounds for EITHER the head
501−// or the "myCamera".
500+// or the "myCamera".
502501 //
503502
504503 // These global scoped variables are used by our loadViewFrustum() and renderViewFrustum functions below, but are also
@@ -515,19 +514,19 @@ float viewFrustumOffsetDistance = 25.0; · 10 unmodified lines
515514 float viewFrustumOffsetUp = 0.0;
516515
517516 void loadViewFrustum(ViewFrustum& viewFrustum) {
518− // We will use these below, from either the camera or head vectors calculated above
519− glm::vec3 position;
520− glm::vec3 direction;
521− glm::vec3 up;
522− glm::vec3 right;
523− float fov, nearClip, farClip;
524−
525− // Camera or Head?
526− if (::cameraFrustum) {
527− position = ::myCamera.getPosition();
528− } else {
529− position = ::myAvatar.getHeadPosition();
530− }
517+ // We will use these below, from either the camera or head vectors calculated above
518+ glm::vec3 position;
519+ glm::vec3 direction;
520+ glm::vec3 up;
521+ glm::vec3 right;
522+ float fov, nearClip, farClip;
523+
524+ // Camera or Head?
525+ if (::cameraFrustum) {
526+ position = ::myCamera.getPosition();
527+ } else {
528+ position = ::myAvatar.getHeadPosition();
529+ }
531530
532531 fov = ::myCamera.getFieldOfView();
533532 nearClip = ::myCamera.getNearClip();
@@ -550,7 +549,7 @@ void loadViewFrustum(ViewFrustum& viewFrustum) { · 16 unmodified lines
550549 printf("farClip=%f\n", farClip);
551550 */
552551
553− // Set the viewFrustum up with the correct position and orientation of the camera
552+ // Set the viewFrustum up with the correct position and orientation of the camera
554553 viewFrustum.setPosition(position);
555554 viewFrustum.setOrientation(direction,up,right);
556555
@@ -567,7 +566,7 @@ void loadViewFrustum(ViewFrustum& viewFrustum) { · 10 unmodified lines
567566 // renderViewFrustum()
568567 //
569568 // Description: this will render the view frustum bounds for EITHER the head
570−// or the "myCamera".
569+// or the "myCamera".
571570 //
572571 // Frustum rendering mode. For debug purposes, we allow drawing the frustum in a couple of different ways.
573572 // We can draw it with each of these parts:
@@ -594,102 +593,102 @@ void renderViewFrustum(ViewFrustum& viewFrustum) { · 20 unmodified lines
594593
595594 // Load it with the latest details!
596595 loadViewFrustum(viewFrustum);
597−
596+
598597 glm::vec3 position = viewFrustum.getPosition();
599598 glm::vec3 direction = viewFrustum.getDirection();
600599 glm::vec3 up = viewFrustum.getUp();
601600 glm::vec3 right = viewFrustum.getRight();
602−
601+
603602 // Get ready to draw some lines
604603 glDisable(GL_LIGHTING);
605604 glColor4f(1.0, 1.0, 1.0, 1.0);
606605 glLineWidth(1.0);
607606 glBegin(GL_LINES);
608607
609− if (::frustumDrawingMode == FRUSTUM_DRAW_MODE_ALL || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_VECTORS) {
610− // Calculate the origin direction vectors
611− glm::vec3 lookingAt = position + (direction * 0.2f);
612− glm::vec3 lookingAtUp = position + (up * 0.2f);
613− glm::vec3 lookingAtRight = position + (right * 0.2f);
614−
615− // Looking At = white
616− glColor3f(1,1,1);
617− glVertex3f(position.x, position.y, position.z);
618− glVertex3f(lookingAt.x, lookingAt.y, lookingAt.z);
619−
620− // Looking At Up = purple
621− glColor3f(1,0,1);
622− glVertex3f(position.x, position.y, position.z);
623− glVertex3f(lookingAtUp.x, lookingAtUp.y, lookingAtUp.z);
624−
625− // Looking At Right = cyan
626− glColor3f(0,1,1);
627− glVertex3f(position.x, position.y, position.z);
628− glVertex3f(lookingAtRight.x, lookingAtRight.y, lookingAtRight.z);
629− }
630−
631− if (::frustumDrawingMode == FRUSTUM_DRAW_MODE_ALL || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_PLANES
632− || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_NEAR_PLANE) {
633− // Drawing the bounds of the frustum
634− // viewFrustum.getNear plane - bottom edge
635− glColor3f(1,0,0);
636− glVertex3f(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z);
637− glVertex3f(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z);
638−
639− // viewFrustum.getNear plane - top edge
640− glVertex3f(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z);
641− glVertex3f(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z);
642−
643− // viewFrustum.getNear plane - right edge
644− glVertex3f(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z);
645− glVertex3f(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z);
646−
647− // viewFrustum.getNear plane - left edge
648− glVertex3f(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z);
649− glVertex3f(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z);
650− }
651−
652− if (::frustumDrawingMode == FRUSTUM_DRAW_MODE_ALL || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_PLANES
653− || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_FAR_PLANE) {
654− // viewFrustum.getFar plane - bottom edge
655− glColor3f(0,1,0); // GREEN!!!
656− glVertex3f(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z);
657− glVertex3f(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z);
658−
659− // viewFrustum.getFar plane - top edge
660− glVertex3f(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z);
661− glVertex3f(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z);
662−
663− // viewFrustum.getFar plane - right edge
664− glVertex3f(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z);
665− glVertex3f(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z);
666−
667− // viewFrustum.getFar plane - left edge
668− glVertex3f(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z);
669− glVertex3f(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z);
670− }
671−
672− if (::frustumDrawingMode == FRUSTUM_DRAW_MODE_ALL || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_PLANES) {
673− // RIGHT PLANE IS CYAN
674− // right plane - bottom edge - viewFrustum.getNear to distant
675− glColor3f(0,1,1);
676− glVertex3f(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z);
677− glVertex3f(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z);
678−
679− // right plane - top edge - viewFrustum.getNear to distant
680− glVertex3f(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z);
681− glVertex3f(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z);
682−
683− // LEFT PLANE IS BLUE
684− // left plane - bottom edge - viewFrustum.getNear to distant
685− glColor3f(0,0,1);
686− glVertex3f(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z);
687− glVertex3f(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z);
688−
689− // left plane - top edge - viewFrustum.getNear to distant
690− glVertex3f(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z);
691− glVertex3f(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z);
692− }
608+ if (::frustumDrawingMode == FRUSTUM_DRAW_MODE_ALL || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_VECTORS) {
609+ // Calculate the origin direction vectors
610+ glm::vec3 lookingAt = position + (direction * 0.2f);
611+ glm::vec3 lookingAtUp = position + (up * 0.2f);
612+ glm::vec3 lookingAtRight = position + (right * 0.2f);
613+
614+ // Looking At = white
615+ glColor3f(1,1,1);
616+ glVertex3f(position.x, position.y, position.z);
617+ glVertex3f(lookingAt.x, lookingAt.y, lookingAt.z);
618+
619+ // Looking At Up = purple
620+ glColor3f(1,0,1);
621+ glVertex3f(position.x, position.y, position.z);
622+ glVertex3f(lookingAtUp.x, lookingAtUp.y, lookingAtUp.z);
623+
624+ // Looking At Right = cyan
625+ glColor3f(0,1,1);
626+ glVertex3f(position.x, position.y, position.z);
627+ glVertex3f(lookingAtRight.x, lookingAtRight.y, lookingAtRight.z);
628+ }
629+
630+ if (::frustumDrawingMode == FRUSTUM_DRAW_MODE_ALL || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_PLANES
631+ || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_NEAR_PLANE) {
632+ // Drawing the bounds of the frustum
633+ // viewFrustum.getNear plane - bottom edge
634+ glColor3f(1,0,0);
635+ glVertex3f(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z);
636+ glVertex3f(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z);
637+
638+ // viewFrustum.getNear plane - top edge
639+ glVertex3f(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z);
640+ glVertex3f(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z);
641+
642+ // viewFrustum.getNear plane - right edge
643+ glVertex3f(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z);
644+ glVertex3f(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z);
645+
646+ // viewFrustum.getNear plane - left edge
647+ glVertex3f(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z);
648+ glVertex3f(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z);
649+ }
650+
651+ if (::frustumDrawingMode == FRUSTUM_DRAW_MODE_ALL || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_PLANES
652+ || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_FAR_PLANE) {
653+ // viewFrustum.getFar plane - bottom edge
654+ glColor3f(0,1,0); // GREEN!!!
655+ glVertex3f(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z);
656+ glVertex3f(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z);
657+
658+ // viewFrustum.getFar plane - top edge
659+ glVertex3f(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z);
660+ glVertex3f(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z);
661+
662+ // viewFrustum.getFar plane - right edge
663+ glVertex3f(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z);
664+ glVertex3f(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z);
665+
666+ // viewFrustum.getFar plane - left edge
667+ glVertex3f(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z);
668+ glVertex3f(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z);
669+ }
670+
671+ if (::frustumDrawingMode == FRUSTUM_DRAW_MODE_ALL || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_PLANES) {
672+ // RIGHT PLANE IS CYAN
673+ // right plane - bottom edge - viewFrustum.getNear to distant
674+ glColor3f(0,1,1);
675+ glVertex3f(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z);
676+ glVertex3f(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z);
677+
678+ // right plane - top edge - viewFrustum.getNear to distant
679+ glVertex3f(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z);
680+ glVertex3f(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z);
681+
682+ // LEFT PLANE IS BLUE
683+ // left plane - bottom edge - viewFrustum.getNear to distant
684+ glColor3f(0,0,1);
685+ glVertex3f(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z);
686+ glVertex3f(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z);
687+
688+ // left plane - top edge - viewFrustum.getNear to distant
689+ glVertex3f(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z);
690+ glVertex3f(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z);
691+ }
693692
694693 glEnd();
695694 glEnable(GL_LIGHTING);
@@ -716,7 +715,7 @@ void displaySide(Camera& whichCamera) { · 20 unmodified lines
716715 }
717716
718717 // finally render the starfield
719− stars.render(whichCamera.getFieldOfView(), aspectRatio, whichCamera.getNearClip(), alpha);
718+ stars.render(whichCamera.getFieldOfView(), aspectRatio, whichCamera.getNearClip(), alpha);
720719 }
721720
722721 // draw the sky dome
@@ -727,8 +726,8 @@ void displaySide(Camera& whichCamera) { · 4 unmodified lines
727726 glEnable(GL_LIGHTING);
728727 glEnable(GL_DEPTH_TEST);
729728
730− // draw a red sphere
731− float sphereRadius = 0.25f;
729+ // draw a red sphere
730+ float sphereRadius = 0.25f;
732731 glColor3f(1,0,0);
733732 glPushMatrix();
734733 glutSolidSphere(sphereRadius, 15, 15);
@@ -736,12 +735,12 @@ void displaySide(Camera& whichCamera) { · 1 unmodified line
736735
737736 //draw a grid ground plane....
738737 drawGroundPlaneGrid(10.f);
739−
738+
740739 // Draw voxels
741740 if (renderVoxels) {
742741 voxels.render();
743742 }
744−
743+
745744 if (::renderAvatarsOn) {
746745 // Render avatars of other agents
747746 AgentList* agentList = AgentList::getInstance();
@@ -763,8 +762,8 @@ void displaySide(Camera& whichCamera) { · 15 unmodified lines
763762
764763 // brad's frustum for debugging
765764 if (::frustumOn) renderViewFrustum(::viewFrustum);
766−
767− glPopMatrix();
765+
766+ glPopMatrix();
768767 }
769768
770769 // this shader is an adaptation (HLSL -> GLSL, removed conditional) of the one in the Oculus sample
@@ -986,11 +985,11 @@ void displayOverlay() { · 215 unmodified lines
986985
987986 if (::paintOn) {
988987
989− char paintMessage[100];
990− sprintf(paintMessage,"Painting (%.3f,%.3f,%.3f/%.3f/%d,%d,%d)",
991− ::paintingVoxel.x,::paintingVoxel.y,::paintingVoxel.z,::paintingVoxel.s,
992− (unsigned int)::paintingVoxel.red,(unsigned int)::paintingVoxel.green,(unsigned int)::paintingVoxel.blue);
993− drawtext(WIDTH-350,50, 0.10, 0, 1.0, 0, paintMessage, 1, 1, 0);
988+ char paintMessage[100];
989+ sprintf(paintMessage,"Painting (%.3f,%.3f,%.3f/%.3f/%d,%d,%d)",
990+ ::paintingVoxel.x,::paintingVoxel.y,::paintingVoxel.z,::paintingVoxel.s,
991+ (unsigned int)::paintingVoxel.red,(unsigned int)::paintingVoxel.green,(unsigned int)::paintingVoxel.blue);
992+ drawtext(WIDTH-350,50, 0.10, 0, 1.0, 0, paintMessage, 1, 1, 0);
994993 }
995994
996995 glPopMatrix();
@@ -998,7 +997,7 @@ void displayOverlay() { · 1 unmodified line
998997
999998 void display(void)
1000999 {
1001− PerfStat("display");
1000+ PerfStat("display");
10021001
10031002 glEnable(GL_LINE_SMOOTH);
10041003 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -1007,22 +1006,6 @@ void display(void) · 2 unmodified lines
10071006 glPushMatrix(); {
10081007 glLoadIdentity();
10091008
1010− // Setup 3D lights
1011− glEnable(GL_COLOR_MATERIAL);
1012− glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
1013−
1014− GLfloat light_position0[] = { 1.0, 1.0, 0.0, 0.0 };
1015− glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
1016− GLfloat ambient_color[] = { 0.7, 0.7, 0.8 };
1017− glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_color);
1018− GLfloat diffuse_color[] = { 0.8, 0.7, 0.7 };
1019− glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_color);
1020− GLfloat specular_color[] = { 1.0, 1.0, 1.0, 1.0};
1021− glLightfv(GL_LIGHT0, GL_SPECULAR, specular_color);
1022−
1023− glMaterialfv(GL_FRONT, GL_SPECULAR, specular_color);
1024− glMateriali(GL_FRONT, GL_SHININESS, 96);
1025−
10261009 // camera settings
10271010 if (::lookingInMirror) {
10281011 // set the camera to looking at my own face
@@ -1030,10 +1013,10 @@ void display(void) · 1 unmodified line
10301013 myCamera.setTargetYaw (myAvatar.getBodyYaw() - 180.0f); // 180 degrees from body yaw
10311014 myCamera.setPitch (0.0);
10321015 myCamera.setRoll (0.0);
1033− myCamera.setUpShift (0.0);
1016+ myCamera.setUpShift (0.0);
10341017 myCamera.setDistance (0.2);
10351018 myCamera.setTightness (100.0f);
1036− } else {
1019+ } else {
10371020
10381021 //float firstPersonPitch = 20.0f;
10391022 //float firstPersonUpShift = 0.0f;
@@ -1063,7 +1046,7 @@ void display(void) · 23 unmodified lines
10631046 }
10641047 }
10651048
1066− myCamera.setPitch (thirdPersonPitch + ff * (firstPersonPitch - thirdPersonPitch ));
1049+ myCamera.setPitch (thirdPersonPitch + ff * (firstPersonPitch - thirdPersonPitch ));
10671050 myCamera.setUpShift (thirdPersonUpShift + ff * (firstPersonUpShift - thirdPersonUpShift ));
10681051 myCamera.setDistance (thirdPersonDistance + ff * (firstPersonDistance - thirdPersonDistance ));
10691052 myCamera.setTightness (thirdPersonTightness + ff * (firstPersonTightness - thirdPersonTightness));
@@ -1077,7 +1060,7 @@ void display(void) · 7 unmodified lines
10771060 }
10781061
10791062 //printf("myCamera.getModeShift() = %f\n", myCamera.getModeShift());
1080− myCamera.setPitch (thirdPersonPitch + myCamera.getModeShift() * (firstPersonPitch - thirdPersonPitch ));
1063+ myCamera.setPitch (thirdPersonPitch + myCamera.getModeShift() * (firstPersonPitch - thirdPersonPitch ));
10811064 myCamera.setUpShift (thirdPersonUpShift + myCamera.getModeShift() * (firstPersonUpShift - thirdPersonUpShift ));
10821065 myCamera.setDistance (thirdPersonDistance + myCamera.getModeShift() * (firstPersonDistance - thirdPersonDistance ));
10831066 myCamera.setTightness (thirdPersonTightness + myCamera.getModeShift() * (firstPersonTightness - thirdPersonTightness));
@@ -1087,7 +1070,7 @@ void display(void) · 3 unmodified lines
10871070 }
10881071
10891072 //printf("myCamera.getModeShift() = %f\n", myCamera.getModeShift());
1090− myCamera.setPitch (firstPersonPitch + myCamera.getModeShift() * (thirdPersonPitch - firstPersonPitch ));
1073+ myCamera.setPitch (firstPersonPitch + myCamera.getModeShift() * (thirdPersonPitch - firstPersonPitch ));
10911074 myCamera.setUpShift (firstPersonUpShift + myCamera.getModeShift() * (thirdPersonUpShift - firstPersonUpShift ));
10921075 myCamera.setDistance (firstPersonDistance + myCamera.getModeShift() * (thirdPersonDistance - firstPersonDistance ));
10931076 myCamera.setTightness (firstPersonTightness + myCamera.getModeShift() * (thirdPersonTightness - firstPersonTightness));
@@ -1104,7 +1087,7 @@ void display(void) · 10 unmodified lines
11041087 myCamera.setTargetPosition(myAvatar.getHeadPosition());
11051088 myCamera.setTargetYaw (myAvatar.getBodyYaw());
11061089 myCamera.setRoll (0.0);
1107− }
1090+ }
11081091
11091092 // important...
11101093
@@ -1120,19 +1103,19 @@ void display(void) · 9 unmodified lines
11201103 glPopMatrix();
11211104 */
11221105
1123−
1124− // Note: whichCamera is used to pick between the normal camera myCamera for our
1125− // main camera, vs, an alternate camera. The alternate camera we support right now
1126− // is the viewFrustumOffsetCamera. But theoretically, we could use this same mechanism
1127− // to add other cameras.
1128− //
1129− // Why have two cameras? Well, one reason is that because in the case of the renderViewFrustum()
1130− // code, we want to keep the state of "myCamera" intact, so we can render what the view frustum of
1131− // myCamera is. But we also want to do meaningful camera transforms on OpenGL for the offset camera
1132− Camera whichCamera = myCamera;
1133− Camera viewFrustumOffsetCamera = myCamera;
1134−
1135− if (::viewFrustumFromOffset && ::frustumOn) {
1106+
1107+ // Note: whichCamera is used to pick between the normal camera myCamera for our
1108+ // main camera, vs, an alternate camera. The alternate camera we support right now
1109+ // is the viewFrustumOffsetCamera. But theoretically, we could use this same mechanism
1110+ // to add other cameras.
1111+ //
1112+ // Why have two cameras? Well, one reason is that because in the case of the renderViewFrustum()
1113+ // code, we want to keep the state of "myCamera" intact, so we can render what the view frustum of
1114+ // myCamera is. But we also want to do meaningful camera transforms on OpenGL for the offset camera
1115+ Camera whichCamera = myCamera;
1116+ Camera viewFrustumOffsetCamera = myCamera;
1117+
1118+ if (::viewFrustumFromOffset && ::frustumOn) {
11361119
11371120 // set the camera to third-person view but offset so we can see the frustum
11381121 viewFrustumOffsetCamera.setTargetYaw(::viewFrustumOffsetYaw + myAvatar.getBodyYaw());
@@ -1142,19 +1125,35 @@ void display(void) · 3 unmodified lines
11421125 viewFrustumOffsetCamera.setDistance (::viewFrustumOffsetDistance);
11431126 viewFrustumOffsetCamera.update(1.f/FPS);
11441127 whichCamera = viewFrustumOffsetCamera;
1145− }
1128+ }
11461129
1147− // transform view according to whichCamera
1148− // could be myCamera (if in normal mode)
1149− // or could be viewFrustumOffsetCamera if in offset mode
1150− // I changed the ordering here - roll is FIRST (JJV)
1130+ // transform view according to whichCamera
1131+ // could be myCamera (if in normal mode)
1132+ // or could be viewFrustumOffsetCamera if in offset mode
1133+ // I changed the ordering here - roll is FIRST (JJV)
11511134
11521135 glRotatef ( whichCamera.getRoll(), IDENTITY_FRONT.x, IDENTITY_FRONT.y, IDENTITY_FRONT.z);
11531136 glRotatef ( whichCamera.getPitch(), IDENTITY_RIGHT.x, IDENTITY_RIGHT.y, IDENTITY_RIGHT.z);
1154− glRotatef (180.0 - whichCamera.getYaw(), IDENTITY_UP.x, IDENTITY_UP.y, IDENTITY_UP.z );
1137+ glRotatef (180.0 - whichCamera.getYaw(), IDENTITY_UP.x, IDENTITY_UP.y, IDENTITY_UP.z );
11551138
11561139 glTranslatef(-whichCamera.getPosition().x, -whichCamera.getPosition().y, -whichCamera.getPosition().z);
1157−
1140+
1141+ // Setup 3D lights (after the camera transform, so that they are positioned in world space)
1142+ glEnable(GL_COLOR_MATERIAL);
1143+ glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
1144+
1145+ GLfloat light_position0[] = { 1.0, 1.0, 0.0, 0.0 };
1146+ glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
1147+ GLfloat ambient_color[] = { 0.7, 0.7, 0.8 };
1148+ glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_color);
1149+ GLfloat diffuse_color[] = { 0.8, 0.7, 0.7 };
1150+ glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_color);
1151+ GLfloat specular_color[] = { 1.0, 1.0, 1.0, 1.0};
1152+ glLightfv(GL_LIGHT0, GL_SPECULAR, specular_color);
1153+
1154+ glMaterialfv(GL_FRONT, GL_SPECULAR, specular_color);
1155+ glMateriali(GL_FRONT, GL_SHININESS, 96);
1156+
11581157 if (::oculusOn) {
11591158 displayOculus(whichCamera);
11601159
@@ -1312,7 +1311,7 @@ int quitApp(int state) { · 151 unmodified lines
13121311
13131312 int setFrustumRenderMode(int state) {
13141313 if (state == MENU_ROW_PICKED) {
1315− ::frustumDrawingMode = (::frustumDrawingMode+1)%FRUSTUM_DRAW_MODE_COUNT;
1314+ ::frustumDrawingMode = (::frustumDrawingMode+1)%FRUSTUM_DRAW_MODE_COUNT;
13161315 }
13171316 return ::frustumDrawingMode;
13181317 }
@@ -1376,25 +1375,25 @@ const char* modeNear = " - Near "; · 57 unmodified lines
13761375 const char* modeFar = " - Far ";
13771376
13781377 const char* getFrustumRenderModeName(int state) {
1379− const char * mode;
1380− switch (state) {
1381− case FRUSTUM_DRAW_MODE_ALL:
1382− mode = modeAll;
1383− break;
1384− case FRUSTUM_DRAW_MODE_VECTORS:
1385− mode = modeVectors;
1386− break;
1387− case FRUSTUM_DRAW_MODE_PLANES:
1388− mode = modePlanes;
1389− break;
1390− case FRUSTUM_DRAW_MODE_NEAR_PLANE:
1391− mode = modeNear;
1392− break;
1393− case FRUSTUM_DRAW_MODE_FAR_PLANE:
1394− mode = modeFar;
1395− break;
1396− }
1397− return mode;
1378+ const char * mode;
1379+ switch (state) {
1380+ case FRUSTUM_DRAW_MODE_ALL:
1381+ mode = modeAll;
1382+ break;
1383+ case FRUSTUM_DRAW_MODE_VECTORS:
1384+ mode = modeVectors;
1385+ break;
1386+ case FRUSTUM_DRAW_MODE_PLANES:
1387+ mode = modePlanes;
1388+ break;
1389+ case FRUSTUM_DRAW_MODE_NEAR_PLANE:
1390+ mode = modeNear;
1391+ break;
1392+ case FRUSTUM_DRAW_MODE_FAR_PLANE:
1393+ mode = modeFar;
1394+ break;
1395+ }
1396+ return mode;
13981397 }
13991398
14001399 void initMenu() {
@@ -1441,55 +1440,117 @@ void initMenu() { · 40 unmodified lines
14411440 }
14421441
14431442 void testPointToVoxel() {
1444− float y=0;
1445− float z=0;
1446− float s=0.1;
1447− for (float x=0; x<=1; x+= 0.05) {
1448− printLog(" x=%f");
1449−
1450− unsigned char red = 200; //randomColorValue(65);
1451− unsigned char green = 200; //randomColorValue(65);
1452− unsigned char blue = 200; //randomColorValue(65);
1453−
1454− unsigned char* voxelCode = pointToVoxel(x, y, z, s,red,green,blue);
1455− printVoxelCode(voxelCode);
1456− delete voxelCode;
1457− printLog("\n");
1458− }
1443+ float y=0;
1444+ float z=0;
1445+ float s=0.1;
1446+ for (float x=0; x<=1; x+= 0.05) {
1447+ printLog(" x=%f");
1448+
1449+ unsigned char red = 200; //randomColorValue(65);
1450+ unsigned char green = 200; //randomColorValue(65);
1451+ unsigned char blue = 200; //randomColorValue(65);
1452+
1453+ unsigned char* voxelCode = pointToVoxel(x, y, z, s,red,green,blue);
1454+ printVoxelCode(voxelCode);
1455+ delete voxelCode;
1456+ printLog("\n");
1457+ }
14591458 }
14601459
14611460 void sendVoxelServerEraseAll() {
1462− char message[100];
1461+ char message[100];
14631462 sprintf(message,"%c%s",'Z',"erase all");
1464− int messageSize = strlen(message) + 1;
1465− AgentList::getInstance()->broadcastToAgents((unsigned char*) message, messageSize, &AGENT_TYPE_VOXEL, 1);
1463+ int messageSize = strlen(message) + 1;
1464+ AgentList::getInstance()->broadcastToAgents((unsigned char*) message, messageSize, &AGENT_TYPE_VOXEL, 1);
14661465 }
14671466
14681467 void sendVoxelServerAddScene() {
1469− char message[100];
1468+ char message[100];
14701469 sprintf(message,"%c%s",'Z',"add scene");
1471− int messageSize = strlen(message) + 1;
1472− AgentList::getInstance()->broadcastToAgents((unsigned char*)message, messageSize, &AGENT_TYPE_VOXEL, 1);
1470+ int messageSize = strlen(message) + 1;
1471+ AgentList::getInstance()->broadcastToAgents((unsigned char*)message, messageSize, &AGENT_TYPE_VOXEL, 1);
14731472 }
14741473
14751474 void shiftPaintingColor()
14761475 {
14771476 // About the color of the paintbrush... first determine the dominant color
14781477 ::dominantColor = (::dominantColor+1)%3; // 0=red,1=green,2=blue
1479− ::paintingVoxel.red = (::dominantColor==0)?randIntInRange(200,255):randIntInRange(40,100);
1480− ::paintingVoxel.green = (::dominantColor==1)?randIntInRange(200,255):randIntInRange(40,100);
1481− ::paintingVoxel.blue = (::dominantColor==2)?randIntInRange(200,255):randIntInRange(40,100);
1478+ ::paintingVoxel.red = (::dominantColor==0)?randIntInRange(200,255):randIntInRange(40,100);
1479+ ::paintingVoxel.green = (::dominantColor==1)?randIntInRange(200,255):randIntInRange(40,100);
1480+ ::paintingVoxel.blue = (::dominantColor==2)?randIntInRange(200,255):randIntInRange(40,100);
14821481 }
14831482
14841483 void setupPaintingVoxel() {
1485− glm::vec3 avatarPos = myAvatar.getPosition();
1486−
1487− ::paintingVoxel.x = avatarPos.z/-10.0; // voxel space x is negative z head space
1488− ::paintingVoxel.y = avatarPos.y/-10.0; // voxel space y is negative y head space
1489− ::paintingVoxel.z = avatarPos.x/-10.0; // voxel space z is negative x head space
1490− ::paintingVoxel.s = 1.0/256;
1491−
1492− shiftPaintingColor();
1484+ glm::vec3 avatarPos = myAvatar.getPosition();
1485+
1486+ ::paintingVoxel.x = avatarPos.z/-10.0; // voxel space x is negative z head space
1487+ ::paintingVoxel.y = avatarPos.y/-10.0; // voxel space y is negative y head space
1488+ ::paintingVoxel.z = avatarPos.x/-10.0; // voxel space z is negative x head space
1489+ ::paintingVoxel.s = 1.0/256;
1490+
1491+ shiftPaintingColor();
1492+}
1493+
1494+void addVoxelUnderCursor() {
1495+ glm::vec3 origin, direction;
1496+ viewFrustum.computePickRay(mouseX / (float)WIDTH, mouseY / (float)HEIGHT, origin, direction);
1497+
1498+ VoxelDetail detail;
1499+ float distance;
1500+ BoxFace face;
1501+ if (voxels.findRayIntersection(origin, direction, detail, distance, face)) {
1502+ // use the face to determine the side on which to create a neighbor
1503+ switch (face) {
1504+ case MIN_X_FACE:
1505+ detail.x -= detail.s;
1506+ break;
1507+
1508+ case MAX_X_FACE:
1509+ detail.x += detail.s;
1510+ break;
1511+
1512+ case MIN_Y_FACE:
1513+ detail.y -= detail.s;
1514+ break;
1515+
1516+ case MAX_Y_FACE:
1517+ detail.y += detail.s;
1518+ break;
1519+
1520+ case MIN_Z_FACE:
1521+ detail.z -= detail.s;
1522+ break;
1523+
1524+ case MAX_Z_FACE:
1525+ detail.z += detail.s;
1526+ break;
1527+ }
1528+ unsigned char* bufferOut;
1529+ int sizeOut;
1530+
1531+ if (createVoxelEditMessage(PACKET_HEADER_SET_VOXEL, 0, 1, &detail, bufferOut, sizeOut)){
1532+ AgentList::getInstance()->broadcastToAgents(bufferOut, sizeOut, &AGENT_TYPE_VOXEL, 1);
1533+ delete bufferOut;
1534+ }
1535+ }
1536+}
1537+
1538+void deleteVoxelUnderCursor() {
1539+ glm::vec3 origin, direction;
1540+ viewFrustum.computePickRay(mouseX / (float)WIDTH, mouseY / (float)HEIGHT, origin, direction);
1541+
1542+ VoxelDetail detail;
1543+ float distance;
1544+ BoxFace face;
1545+ if (voxels.findRayIntersection(origin, direction, detail, distance, face)) {
1546+ unsigned char* bufferOut;
1547+ int sizeOut;
1548+
1549+ if (createVoxelEditMessage(PACKET_HEADER_ERASE_VOXEL, 0, 1, &detail, bufferOut, sizeOut)){
1550+ AgentList::getInstance()->broadcastToAgents(bufferOut, sizeOut, &AGENT_TYPE_VOXEL, 1);
1551+ delete bufferOut;
1552+ }
1553+ }
14931554 }
14941555
14951556 const float KEYBOARD_YAW_RATE = 0.8;
@@ -1574,42 +1635,44 @@ void key(unsigned char k, int x, int y) { · 78 unmodified lines
15741635 return;
15751636 }
15761637
1577− // Process keypresses
1578− if (k == 'q' || k == 'Q') ::terminate();
1579− if (k == '/') ::renderStatsOn = !::renderStatsOn; // toggle stats
1580− if (k == '*') ::renderStarsOn = !::renderStarsOn; // toggle stars
1581− if (k == 'V' || k == 'v') ::renderVoxels = !::renderVoxels; // toggle voxels
1638+ // Process keypresses
1639+ if (k == 'q' || k == 'Q') ::terminate();
1640+ if (k == '/') ::renderStatsOn = !::renderStatsOn; // toggle stats
1641+ if (k == '*') ::renderStarsOn = !::renderStarsOn; // toggle stars
1642+ if (k == 'V' || k == 'v') ::renderVoxels = !::renderVoxels; // toggle voxels
15821643 if (k == 'A') ::renderAtmosphereOn = !::renderAtmosphereOn;
1583− if (k == 'F') ::frustumOn = !::frustumOn; // toggle view frustum debugging
1584− if (k == 'C') ::cameraFrustum = !::cameraFrustum; // toggle which frustum to look at
1644+ if (k == 'F') ::frustumOn = !::frustumOn; // toggle view frustum debugging
1645+ if (k == 'C') ::cameraFrustum = !::cameraFrustum; // toggle which frustum to look at
15851646 if (k == 'O' || k == 'G') setFrustumOffset(MENU_ROW_PICKED); // toggle view frustum offset debugging
15861647 if (k == 'f') setFullscreen(!::fullscreen);
15871648 if (k == 'o') setOculus(!::oculusOn);
15881649
1589− if (k == '[') ::viewFrustumOffsetYaw -= 0.5;
1590− if (k == ']') ::viewFrustumOffsetYaw += 0.5;
1591− if (k == '{') ::viewFrustumOffsetPitch -= 0.5;
1592− if (k == '}') ::viewFrustumOffsetPitch += 0.5;
1593− if (k == '(') ::viewFrustumOffsetRoll -= 0.5;
1594− if (k == ')') ::viewFrustumOffsetRoll += 0.5;
1595− if (k == '<') ::viewFrustumOffsetDistance -= 0.5;
1596− if (k == '>') ::viewFrustumOffsetDistance += 0.5;
1597− if (k == ',') ::viewFrustumOffsetUp -= 0.05;
1598− if (k == '.') ::viewFrustumOffsetUp += 0.05;
1650+ if (k == '[') ::viewFrustumOffsetYaw -= 0.5;
1651+ if (k == ']') ::viewFrustumOffsetYaw += 0.5;
1652+ if (k == '{') ::viewFrustumOffsetPitch -= 0.5;
1653+ if (k == '}') ::viewFrustumOffsetPitch += 0.5;
1654+ if (k == '(') ::viewFrustumOffsetRoll -= 0.5;
1655+ if (k == ')') ::viewFrustumOffsetRoll += 0.5;
1656+ if (k == '<') ::viewFrustumOffsetDistance -= 0.5;
1657+ if (k == '>') ::viewFrustumOffsetDistance += 0.5;
1658+ if (k == ',') ::viewFrustumOffsetUp -= 0.05;
1659+ if (k == '.') ::viewFrustumOffsetUp += 0.05;
15991660
1600−// if (k == '|') ViewFrustum::fovAngleAdust -= 0.05;
1601−// if (k == '\\') ViewFrustum::fovAngleAdust += 0.05;
1661+// if (k == '|') ViewFrustum::fovAngleAdust -= 0.05;
1662+// if (k == '\\') ViewFrustum::fovAngleAdust += 0.05;
16021663
1603− if (k == 'R') setFrustumRenderMode(MENU_ROW_PICKED);
1664+ if (k == 'R') setFrustumRenderMode(MENU_ROW_PICKED);
16041665
16051666 if (k == '&') {
1606− ::paintOn = !::paintOn; // toggle paint
1607− ::setupPaintingVoxel(); // also randomizes colors
1667+ ::paintOn = !::paintOn; // toggle paint
1668+ ::setupPaintingVoxel(); // also randomizes colors
16081669 }
1609− if (k == '^') ::shiftPaintingColor(); // shifts randomize color between R,G,B dominant
1610− if (k == '-') ::sendVoxelServerEraseAll(); // sends erase all command to voxel server
1611− if (k == '%') ::sendVoxelServerAddScene(); // sends add scene command to voxel server
1612− if (k == 'n' || k == 'N')
1670+ if (k == '^') ::shiftPaintingColor(); // shifts randomize color between R,G,B dominant
1671+ if (k == '-') ::sendVoxelServerEraseAll(); // sends erase all command to voxel server
1672+ if (k == '%') ::sendVoxelServerAddScene(); // sends add scene command to voxel server
1673+ if (k == '1') ::addVoxelUnderCursor();
1674+ if (k == '2') ::deleteVoxelUnderCursor();
1675+ if (k == 'n' || k == 'N')
16131676 {
16141677 noiseOn = !noiseOn; // Toggle noise
16151678 if (noiseOn)
@@ -1703,23 +1766,21 @@ void idle(void) { · 87 unmodified lines
17031766 // Only run simulation code if more than IDLE_SIMULATE_MSECS have passed since last time
17041767
17051768 if (diffclock(&lastTimeIdle, &check) > IDLE_SIMULATE_MSECS) {
1706−
1769+
17071770 float deltaTime = 1.f/FPS;
17081771
17091772 // update behaviors for avatar hand movement: handControl takes mouse values as input,
17101773 // and gives back 3D values modulated for smooth transitioning between interaction modes.
17111774 handControl.update(mouseX, mouseY);
1712− myAvatar.setHandMovementValues(handControl.getValues());
1775+ myAvatar.setHandMovementValues(handControl.getValues());
17131776
1714− // tell my avatar if the mouse is being pressed...
1715− if (mousePressed) {
1716− myAvatar.setMousePressed(mousePressed);
1717− }
1777+ // tell my avatar if the mouse is being pressed...
1778+ myAvatar.setMousePressed(mousePressed);
17181779
17191780 // walking triggers the handControl to stop
17201781 if (myAvatar.getMode() == AVATAR_MODE_WALKING) {
17211782 handControl.stop();
1722− }
1783+ }
17231784
17241785 // Read serial port interface devices
17251786 if (serialPort.active && USING_INVENSENSE_MPU9150) {
@@ -1732,8 +1793,8 @@ void idle(void) { · 6 unmodified lines
17321793 // read incoming packets from network
17331794 if (!enableNetworkThread) {
17341795 networkReceive(0);
1735− }
1736−
1796+ }
1797+
17371798 //loop through all the remote avatars and simulate them...
17381799 AgentList* agentList = AgentList::getInstance();
17391800 agentList->lock();
@@ -1834,29 +1895,30 @@ glm::vec3 getGravity(glm::vec3 pos) { · 94 unmodified lines
18341895 }
18351896
18361897 void mouseFunc(int button, int state, int x, int y) {
1837− if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
1838− if (state == GLUT_DOWN && !menu.mouseClick(x, y)) {
1839− mouseX = x;
1840− mouseY = y;
1841− mousePressed = 1;
1842− } else if (state == GLUT_UP) {
1898+ if ( !menu.mouseClick(x, y)) { // if a menu item was not clicked or unclicked...
1899+ if ( button == GLUT_LEFT_BUTTON ) {
18431900 mouseX = x;
18441901 mouseY = y;
1845− mousePressed = 0;
1902+ if (state == GLUT_DOWN ) {
1903+ mousePressed = 1;
1904+ } else if (state == GLUT_UP ) {
1905+ mousePressed = 0;
1906+ }
18461907 }
1847− }
1908+ }
18481909 }
18491910
1911+
18501912 void motionFunc(int x, int y) {
1851− mouseX = x;
1852− mouseY = y;
1913+ mouseX = x;
1914+ mouseY = y;
18531915 }
18541916
18551917 void mouseoverFunc(int x, int y){
18561918 menu.mouseOver(x, y);
18571919
1858− mouseX = x;
1859− mouseY = y;
1920+ mouseX = x;
1921+ mouseY = y;
18601922 }
18611923
18621924 void attachNewHeadToAgent(Agent *newAgent) {
@@ -1892,14 +1954,14 @@ int main(int argc, const char * argv[]) { · 29 unmodified lines
18921954 gettimeofday(&applicationStartupTime, NULL);
18931955 const char* domainIP = getCmdOption(argc, argv, "--domain");
18941956 if (domainIP) {
1895− strcpy(DOMAIN_IP,domainIP);
1896− }
1957+ strcpy(DOMAIN_IP,domainIP);
1958+ }
18971959
18981960 // Handle Local Domain testing with the --local command line
18991961 if (cmdOptionExists(argc, argv, "--local")) {
1900− printLog("Local Domain MODE!\n");
1901− int ip = getLocalAddress();
1902− sprintf(DOMAIN_IP,"%d.%d.%d.%d", (ip & 0xFF), ((ip >> 8) & 0xFF),((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF));
1962+ printLog("Local Domain MODE!\n");
1963+ int ip = getLocalAddress();
1964+ sprintf(DOMAIN_IP,"%d.%d.%d.%d", (ip & 0xFF), ((ip >> 8) & 0xFF),((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF));
19031965 }
19041966
19051967 // the callback for our instance of AgentList is attachNewHeadToAgent
@@ -1948,30 +2010,30 @@ int main(int argc, const char * argv[]) { · 42 unmodified lines
19482010
19492011 glutDisplayFunc(display);
19502012 glutReshapeFunc(reshape);
1951− glutKeyboardFunc(key);
2013+ glutKeyboardFunc(key);
19522014 glutKeyboardUpFunc(keyUp);
19532015 glutSpecialFunc(specialkey);
19542016 glutSpecialUpFunc(specialkeyUp);
1955− glutMotionFunc(motionFunc);
2017+ glutMotionFunc(motionFunc);
19562018 glutPassiveMotionFunc(mouseoverFunc);
1957− glutMouseFunc(mouseFunc);
2019+ glutMouseFunc(mouseFunc);
19582020 glutIdleFunc(idle);
1959−
2021+
19602022 init();
19612023 printLog( "Init() complete.\n" );
19622024
1963− // Check to see if the user passed in a command line option for randomizing colors
1964− if (cmdOptionExists(argc, argv, "--NoColorRandomizer")) {
1965− wantColorRandomizer = false;
1966− }
1967−
1968− // Check to see if the user passed in a command line option for loading a local
1969− // Voxel File. If so, load it now.
2025+ // Check to see if the user passed in a command line option for randomizing colors
2026+ if (cmdOptionExists(argc, argv, "--NoColorRandomizer")) {
2027+ wantColorRandomizer = false;
2028+ }
2029+
2030+ // Check to see if the user passed in a command line option for loading a local
2031+ // Voxel File. If so, load it now.
19702032 const char* voxelsFilename = getCmdOption(argc, argv, "-i");
19712033 if (voxelsFilename) {
1972− voxels.loadVoxelsFile(voxelsFilename,wantColorRandomizer);
2034+ voxels.loadVoxelsFile(voxelsFilename,wantColorRandomizer);
19732035 printLog("Local Voxel File loaded.\n");
1974− }
2036+ }
19752037
19762038 // create thread for receipt of data via UDP
19772039 if (enableNetworkThread) {