Showing the changes to interface/src/main.cpp (1 of 9 files). Show all
Unified · Split
| @@ -99,7 +99,7 @@ bool wantColorRandomizer = true; // for addSphere and load file · 98 unmodified lines | ||
| 99 | 99 | |
| 100 | 100 | Oscilloscope audioScope(256,200,true); |
| 101 | 101 | |
| 102 | −Head myHead; // The rendered head of oneself | |
| 102 | +Head myAvatar; // The rendered avatar of oneself | |
| 103 | 103 | Camera myCamera; // My view onto the world (sometimes on myself :) |
| 104 | 104 | |
| 105 | 105 | // Starfield information |
| @@ -123,7 +123,7 @@ ParticleSystem balls(0, · 17 unmodified lines | ||
| 123 | 123 | 0.0 // Gravity |
| 124 | 124 | ); |
| 125 | 125 | |
| 126 | −Cloud cloud(0, // Particles | |
| 126 | +Cloud cloud(0, // Particles | |
| 127 | 127 | box, // Bounding Box |
| 128 | 128 | false // Wrap |
| 129 | 129 | ); |
| @@ -135,7 +135,7 @@ Finger myFinger(WIDTH, HEIGHT); · 5 unmodified lines | ||
| 135 | 135 | Field field; |
| 136 | 136 | |
| 137 | 137 | #ifndef _WIN32 |
| 138 | −Audio audio(&audioScope, &myHead); | |
| 138 | +Audio audio(&audioScope, &myAvatar); | |
| 139 | 139 | #endif |
| 140 | 140 | |
| 141 | 141 | #define IDLE_SIMULATE_MSECS 8 // How often should call simulate and other stuff |
| @@ -157,6 +157,13 @@ bool paintOn = false; // Whether to paint voxels as you fly around · 15 unmodified lines | ||
| 157 | 157 | VoxelDetail paintingVoxel; // The voxel we're painting if we're painting |
| 158 | 158 | unsigned char dominantColor = 0; // The dominant color of the voxel we're painting |
| 159 | 159 | bool perfStatsOn = false; // Do we want to display perfStats? |
| 160 | +bool frustumOn = false; // Whether or not to display the debug view frustum | |
| 161 | + | |
| 162 | +bool viewFrustumFromOffset=false; // Wether or not to offset the view of the frustum | |
| 163 | +float viewFrustumOffsetYaw = -90.0; | |
| 164 | +float viewFrustumOffsetPitch = 7.5; | |
| 165 | +float viewFrustumOffsetRoll = 0.0; | |
| 166 | + | |
| 160 | 167 | int noiseOn = 0; // Whether to add random noise |
| 161 | 168 | float noise = 1.0; // Overall magnitude scaling for random noise levels |
| 162 | 169 | |
| @@ -182,10 +189,8 @@ SerialInterface serialPort; · 19 unmodified lines | ||
| 182 | 189 | int latency_display = 1; |
| 183 | 190 | |
| 184 | 191 | glm::vec3 gravity; |
| 185 | −int first_measurement = 1; | |
| 186 | −//int samplecount = 0; | |
| 187 | 192 | |
| 188 | −// Frame rate Measurement | |
| 193 | +// Frame Rate Measurement | |
| 189 | 194 | |
| 190 | 195 | int frameCount = 0; |
| 191 | 196 | float FPS = 120.f; |
| @@ -193,12 +198,6 @@ timeval timerStart, timerEnd; · 1 unmodified line | ||
| 193 | 198 | timeval lastTimeIdle; |
| 194 | 199 | double elapsedTime; |
| 195 | 200 | |
| 196 | −// Particles | |
| 197 | − | |
| 198 | − | |
| 199 | −float particle_attenuation_quadratic[] = { 0.0f, 0.0f, 2.0f }; // larger Z = smaller particles | |
| 200 | −float pointer_attenuation_quadratic[] = { 1.0f, 0.0f, 0.0f }; // for 2D view | |
| 201 | − | |
| 202 | 201 | #ifdef MARKER_CAPTURE |
| 203 | 202 | |
| 204 | 203 | /*** Marker Capture ***/ |
| @@ -250,11 +249,11 @@ void displayStats(void) · 45 unmodified lines | ||
| 250 | 249 | char legend2[] = "* - toggle stars, & - toggle paint mode, '-' - send erase all, '%' - send add scene"; |
| 251 | 250 | drawtext(10, statsVerticalOffset + 32, 0.10f, 0, 1.0, 0, legend2); |
| 252 | 251 | |
| 253 | − glm::vec3 headPos = myHead.getPos(); | |
| 252 | + glm::vec3 avatarPos = myAvatar.getPos(); | |
| 254 | 253 | |
| 255 | 254 | char stats[200]; |
| 256 | 255 | sprintf(stats, "FPS = %3.0f Pkts/s = %d Bytes/s = %d Head(x,y,z)=( %f , %f , %f )", |
| 257 | − FPS, packetsPerSecond, bytesPerSecond, headPos.x,headPos.y,headPos.z); | |
| 256 | + FPS, packetsPerSecond, bytesPerSecond, avatarPos.x,avatarPos.y,avatarPos.z); | |
| 258 | 257 | drawtext(10, statsVerticalOffset + 49, 0.10f, 0, 1.0, 0, stats); |
| 259 | 258 | if (serialPort.active) { |
| 260 | 259 | sprintf(stats, "ADC samples = %d, LED = %d", |
| @@ -262,14 +261,6 @@ void displayStats(void) · 1 unmodified line | ||
| 262 | 261 | drawtext(300, statsVerticalOffset + 30, 0.10f, 0, 1.0, 0, stats); |
| 263 | 262 | } |
| 264 | 263 | |
| 265 | − // Output the ping times to the various agents | |
| 266 | −// std::stringstream pingTimes; | |
| 267 | −// pingTimes << "Agent Pings, msecs:"; | |
| 268 | −// for (int i = 0; i < getAgentCount(); i++) { | |
| 269 | −// pingTimes << " " << getAgentAddress(i) << ": " << getAgentPing(i); | |
| 270 | −// } | |
| 271 | −// drawtext(10,50,0.10, 0, 1.0, 0, (char *)pingTimes.str().c_str()); | |
| 272 | − | |
| 273 | 264 | std::stringstream voxelStats; |
| 274 | 265 | voxelStats << "Voxels Rendered: " << voxels.getVoxelsRendered(); |
| 275 | 266 | drawtext(10, statsVerticalOffset + 70, 0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str()); |
| @@ -330,8 +321,8 @@ void initDisplay(void) · 54 unmodified lines | ||
| 330 | 321 | void init(void) |
| 331 | 322 | { |
| 332 | 323 | voxels.init(); |
| 333 | − voxels.setViewerHead(&myHead); | |
| 334 | − myHead.setRenderYaw(startYaw); | |
| 324 | + voxels.setViewerHead(&myAvatar); | |
| 325 | + myAvatar.setRenderYaw(startYaw); | |
| 335 | 326 | |
| 336 | 327 | headMouseX = WIDTH/2; |
| 337 | 328 | headMouseY = HEIGHT/2; |
| @@ -342,9 +333,9 @@ void init(void) · 4 unmodified lines | ||
| 342 | 333 | field = Field(); |
| 343 | 334 | |
| 344 | 335 | if (noiseOn) { |
| 345 | − myHead.setNoise(noise); | |
| 336 | + myAvatar.setNoise(noise); | |
| 346 | 337 | } |
| 347 | − myHead.setPos(start_location ); | |
| 338 | + myAvatar.setPos(start_location ); | |
| 348 | 339 | myCamera.setPosition( start_location ); |
| 349 | 340 | |
| 350 | 341 | #ifdef MARKER_CAPTURE |
| @@ -381,15 +372,15 @@ void reset_sensors() · 30 unmodified lines | ||
| 381 | 372 | // |
| 382 | 373 | // Reset serial I/O sensors |
| 383 | 374 | // |
| 384 | − myHead.setRenderYaw(startYaw); | |
| 375 | + myAvatar.setRenderYaw(startYaw); | |
| 385 | 376 | |
| 386 | 377 | yaw = renderYawRate = 0; |
| 387 | 378 | pitch = renderPitch = renderPitchRate = 0; |
| 388 | − myHead.setPos(start_location); | |
| 379 | + myAvatar.setPos(start_location); | |
| 389 | 380 | headMouseX = WIDTH/2; |
| 390 | 381 | headMouseY = HEIGHT/2; |
| 391 | 382 | |
| 392 | − myHead.reset(); | |
| 383 | + myAvatar.reset(); | |
| 393 | 384 | |
| 394 | 385 | if (serialPort.active) { |
| 395 | 386 | serialPort.resetTrailingAverages(); |
| @@ -405,7 +396,7 @@ void simulateHand(float deltaTime) { · 9 unmodified lines | ||
| 405 | 396 | float dx = mouseX - mouseStartX; |
| 406 | 397 | float dy = mouseY - mouseStartY; |
| 407 | 398 | glm::vec3 vel(dx*MOUSE_HAND_FORCE, -dy*MOUSE_HAND_FORCE*(WIDTH/HEIGHT), 0); |
| 408 | − myHead.hand->addVelocity(vel*deltaTime); | |
| 399 | + myAvatar.hand->addVelocity(vel*deltaTime); | |
| 409 | 400 | } |
| 410 | 401 | } |
| 411 | 402 | |
| @@ -421,12 +412,12 @@ void simulateHead(float frametime) · 9 unmodified lines | ||
| 421 | 412 | //float measured_lateral_accel = serialPort.getRelativeValue(ACCEL_X); |
| 422 | 413 | //float measured_fwd_accel = serialPort.getRelativeValue(ACCEL_Z); |
| 423 | 414 | |
| 424 | − myHead.UpdatePos(frametime, &serialPort, headMirror, &gravity); | |
| 415 | + myAvatar.UpdatePos(frametime, &serialPort, headMirror, &gravity); | |
| 425 | 416 | |
| 426 | 417 | //------------------------------------------------------------------------------------- |
| 427 | 418 | // set the position of the avatar |
| 428 | 419 | //------------------------------------------------------------------------------------- |
| 429 | − myHead.setAvatarPosition( -myHead.getPos().x, -myHead.getPos().y, -myHead.getPos().z ); | |
| 420 | + myAvatar.setAvatarPosition( -myAvatar.getPos().x, -myAvatar.getPos().y, -myAvatar.getPos().z ); | |
| 430 | 421 | |
| 431 | 422 | // Update head_mouse model |
| 432 | 423 | const float MIN_MOUSE_RATE = 30.0; |
| @@ -451,8 +442,8 @@ void simulateHead(float frametime) · 18 unmodified lines | ||
| 451 | 442 | |
| 452 | 443 | // Update render pitch and yaw rates based on keyPositions |
| 453 | 444 | const float KEY_YAW_SENSITIVITY = 2.0; |
| 454 | − if (myHead.getDriveKeys(ROT_LEFT)) renderYawRate -= KEY_YAW_SENSITIVITY*frametime; | |
| 455 | − if (myHead.getDriveKeys(ROT_RIGHT)) renderYawRate += KEY_YAW_SENSITIVITY*frametime; | |
| 445 | + if (myAvatar.getDriveKeys(ROT_LEFT)) renderYawRate -= KEY_YAW_SENSITIVITY*frametime; | |
| 446 | + if (myAvatar.getDriveKeys(ROT_RIGHT)) renderYawRate += KEY_YAW_SENSITIVITY*frametime; | |
| 456 | 447 | |
| 457 | 448 | if (fabs(measured_yaw_rate) > MIN_YAW_RATE) |
| 458 | 449 | { |
| @@ -479,32 +470,32 @@ void simulateHead(float frametime) · 20 unmodified lines | ||
| 479 | 470 | renderYawRate *= (1.f - 7.0*frametime); |
| 480 | 471 | |
| 481 | 472 | // Update own head data |
| 482 | − myHead.setRenderYaw(myHead.getRenderYaw() + renderYawRate); | |
| 483 | − myHead.setRenderPitch(renderPitch); | |
| 473 | + myAvatar.setRenderYaw(myAvatar.getRenderYaw() + renderYawRate); | |
| 474 | + myAvatar.setRenderPitch(renderPitch); | |
| 484 | 475 | |
| 485 | 476 | // Get audio loudness data from audio input device |
| 486 | 477 | float loudness, averageLoudness; |
| 487 | 478 | #ifndef _WIN32 |
| 488 | 479 | audio.getInputLoudness(&loudness, &averageLoudness); |
| 489 | − myHead.setLoudness(loudness); | |
| 490 | − myHead.setAverageLoudness(averageLoudness); | |
| 480 | + myAvatar.setLoudness(loudness); | |
| 481 | + myAvatar.setAverageLoudness(averageLoudness); | |
| 491 | 482 | #endif |
| 492 | 483 | |
| 493 | 484 | // Send my streaming head data to agents that are nearby and need to see it! |
| 494 | 485 | const int MAX_BROADCAST_STRING = 200; |
| 495 | 486 | char broadcast_string[MAX_BROADCAST_STRING]; |
| 496 | − int broadcast_bytes = myHead.getBroadcastData(broadcast_string); | |
| 487 | + int broadcast_bytes = myAvatar.getBroadcastData(broadcast_string); | |
| 497 | 488 | agentList.broadcastToAgents(broadcast_string, broadcast_bytes,AgentList::AGENTS_OF_TYPE_VOXEL_AND_INTERFACE); |
| 498 | 489 | |
| 499 | 490 | // If I'm in paint mode, send a voxel out to VOXEL server agents. |
| 500 | 491 | if (::paintOn) { |
| 501 | 492 | |
| 502 | − glm::vec3 headPos = myHead.getPos(); | |
| 493 | + glm::vec3 avatarPos = myAvatar.getPos(); | |
| 503 | 494 | |
| 504 | 495 | // For some reason, we don't want to flip X and Z here. |
| 505 | − ::paintingVoxel.x = headPos.x/-10.0; | |
| 506 | − ::paintingVoxel.y = headPos.y/-10.0; | |
| 507 | − ::paintingVoxel.z = headPos.z/-10.0; | |
| 496 | + ::paintingVoxel.x = avatarPos.x/-10.0; | |
| 497 | + ::paintingVoxel.y = avatarPos.y/-10.0; | |
| 498 | + ::paintingVoxel.z = avatarPos.z/-10.0; | |
| 508 | 499 | |
| 509 | 500 | unsigned char* bufferOut; |
| 510 | 501 | int sizeOut; |
| @@ -521,6 +512,9 @@ void simulateHead(float frametime) · 10 unmodified lines | ||
| 521 | 512 | } |
| 522 | 513 | } |
| 523 | 514 | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 524 | 518 | // XXXBHG - this code is not yet working. This is here to help Jeffery debug getAvatarHeadLookatDirection() |
| 525 | 519 | // The code will draw a yellow line from the avatar's position to the origin, |
| 526 | 520 | // It also attempts to draw a cyan line from the avatar to 2 meters in front of the avatar in the direction |
| @@ -538,117 +532,105 @@ void render_view_frustum() { · 11 unmodified lines | ||
| 538 | 532 | // farDist – the distance from the camera to the far plane |
| 539 | 533 | // farHeight – the height of the far plane |
| 540 | 534 | // farWidth – the width of the far plane |
| 541 | − | |
| 542 | − glm::vec3 cameraPosition = ::myHead.getPos()*-1.0; // We need to flip the sign to make this work. | |
| 543 | − glm::vec3 cameraDirection = ::myHead.getAvatarHeadLookatDirection()*-1.0; // gak! Not sure if this is correct! | |
| 544 | 535 | |
| 545 | − // this is a temporary test, create a vertice that's 2 meters in front of avatar in direction their looking | |
| 546 | − glm::vec3 lookingAt = cameraPosition+(cameraDirection*2.0); | |
| 547 | − | |
| 548 | − // Some debug lines. | |
| 549 | − glDisable(GL_LIGHTING); | |
| 550 | − glColor4f(1.0, 1.0, 1.0, 1.0); | |
| 551 | − glLineWidth(1.0); | |
| 552 | − glBegin(GL_LINES); | |
| 553 | − | |
| 554 | − // line from avatar to the origin -- this one is working. | |
| 555 | − glColor3f(1,1,0); | |
| 556 | − glVertex3f(cameraPosition.x,cameraPosition.y,cameraPosition.z); | |
| 557 | − glVertex3f(0,0,0); | |
| 558 | − | |
| 559 | − // line from avatar to 2 meters in front of avatar -- this is NOT working | |
| 560 | − glColor3f(0,1,1); | |
| 561 | − glVertex3f(cameraPosition.x,cameraPosition.y,cameraPosition.z); | |
| 562 | − glVertex3f(lookingAt.x,lookingAt.y,lookingAt.z); | |
| 563 | − | |
| 564 | − /* | |
| 565 | − // Not yet ready for this... | |
| 566 | − glm::vec3 up = glm::vec3(0.0,1.0,0.0); | |
| 567 | − glm::vec3 right = glm::vec3(1.0,0.0,0.0); | |
| 568 | − float nearDist = 0.1; | |
| 569 | − float farDist = 500.0; | |
| 570 | − float fov = (0.7854f*2.0); // 45 deg * 2 = 90 deg | |
| 536 | + glm::vec3 viewFrustumPosition = myAvatar.getHeadPosition(); | |
| 537 | + glm::vec3 viewFrustumDirection = myAvatar.getHeadLookatDirection(); | |
| 538 | + | |
| 539 | + glm::vec3 up = myAvatar.getHeadLookatDirectionUp(); | |
| 540 | + glm::vec3 right = myAvatar.getHeadLookatDirectionRight(); | |
| 541 | + | |
| 542 | + // what? this are negative?? GRRRR!!! | |
| 543 | + float nearDist = -0.1; | |
| 544 | + float farDist = -1.0; | |
| 571 | 545 | |
| 572 | − float screenWidth = 800.0; // hack! We need to make this eventually be the correct height/width | |
| 573 | − float screenHeight = 600.0; | |
| 546 | + float fovHalfAngle = 0.7854f; // 45 deg for half, so fov = 90 deg | |
| 547 | + | |
| 548 | + float screenWidth = ::WIDTH; // These values come from reshape() | |
| 549 | + float screenHeight = ::HEIGHT; | |
| 574 | 550 | float ratio = screenWidth/screenHeight; |
| 575 | − float nearHeight = 2 * tan(fov / 2) * nearDist; | |
| 551 | + | |
| 552 | + float nearHeight = 2 * tan(fovHalfAngle) * nearDist; | |
| 576 | 553 | float nearWidth = nearHeight * ratio; |
| 577 | − float farHeight = 2 * tan(fov / 2) * farDist; | |
| 554 | + float farHeight = 2 * tan(fovHalfAngle) * farDist; | |
| 578 | 555 | float farWidth = farHeight * ratio; |
| 579 | 556 | |
| 580 | − glm::vec3 farCenter = cameraPosition+cameraDirection*farDist; | |
| 557 | + glm::vec3 farCenter = viewFrustumPosition+viewFrustumDirection*farDist; | |
| 581 | 558 | glm::vec3 farTopLeft = farCenter + (up*farHeight*0.5) - (right*farWidth*0.5); |
| 582 | 559 | glm::vec3 farTopRight = farCenter + (up*farHeight*0.5) + (right*farWidth*0.5); |
| 583 | 560 | glm::vec3 farBottomLeft = farCenter - (up*farHeight*0.5) - (right*farWidth*0.5); |
| 584 | 561 | glm::vec3 farBottomRight = farCenter - (up*farHeight*0.5) + (right*farWidth*0.5); |
| 585 | 562 | |
| 586 | − glm::vec3 nearCenter = cameraPosition+cameraDirection*nearDist; | |
| 563 | + glm::vec3 nearCenter = viewFrustumPosition+viewFrustumDirection*nearDist; | |
| 587 | 564 | glm::vec3 nearTopLeft = nearCenter + (up*nearHeight*0.5) - (right*nearWidth*0.5); |
| 588 | 565 | glm::vec3 nearTopRight = nearCenter + (up*nearHeight*0.5) + (right*nearWidth*0.5); |
| 589 | 566 | glm::vec3 nearBottomLeft = nearCenter - (up*nearHeight*0.5) - (right*nearWidth*0.5); |
| 590 | 567 | glm::vec3 nearBottomRight = nearCenter - (up*nearHeight*0.5) + (right*nearWidth*0.5); |
| 591 | − */ | |
| 592 | − | |
| 593 | 568 | |
| 594 | −/* | |
| 595 | − glColor3f(1,1,1); | |
| 569 | + // Get ready to draw some lines | |
| 570 | + glDisable(GL_LIGHTING); | |
| 571 | + glColor4f(1.0, 1.0, 1.0, 1.0); | |
| 572 | + glLineWidth(1.0); | |
| 573 | + glBegin(GL_LINES); | |
| 596 | 574 | |
| 597 | 575 | // near plane - bottom edge |
| 598 | − glVertex3f(low.x,low.y,low.z); | |
| 599 | − glVertex3f(high.x,low.y,low.z); | |
| 576 | + glColor3f(1,0,0); | |
| 577 | + glVertex3f(nearBottomLeft.x,nearBottomLeft.y,nearBottomLeft.z); | |
| 578 | + glVertex3f(nearBottomRight.x,nearBottomRight.y,nearBottomRight.z); | |
| 600 | 579 | |
| 601 | 580 | // near plane - top edge |
| 602 | − glVertex3f(low.x,high.y,low.z); | |
| 603 | − glVertex3f(high.x,high.y,low.z); | |
| 581 | + glVertex3f(nearTopLeft.x,nearTopLeft.y,nearTopLeft.z); | |
| 582 | + glVertex3f(nearTopRight.x,nearTopRight.y,nearTopRight.z); | |
| 604 | 583 | |
| 605 | 584 | // near plane - right edge |
| 606 | − glVertex3f(low.x,high.y,low.z); | |
| 607 | − glVertex3f(low.x,low.y,low.z); | |
| 585 | + glVertex3f(nearBottomRight.x,nearBottomRight.y,nearBottomRight.z); | |
| 586 | + glVertex3f(nearTopRight.x,nearTopRight.y,nearTopRight.z); | |
| 608 | 587 | |
| 609 | 588 | // near plane - left edge |
| 610 | − glVertex3f(high.x,high.y,low.z); | |
| 611 | − glVertex3f(high.x,low.y,low.z); | |
| 589 | + glVertex3f(nearBottomLeft.x,nearBottomLeft.y,nearBottomLeft.z); | |
| 590 | + glVertex3f(nearTopLeft.x,nearTopLeft.y,nearTopLeft.z); | |
| 612 | 591 | |
| 613 | 592 | // far plane - bottom edge |
| 614 | − glVertex3f(low.x,low.y,high.z); | |
| 615 | − glVertex3f(high.x,low.y,high.z); | |
| 616 | − | |
| 593 | + glColor3f(0,1,0); // GREEN!!! | |
| 594 | + glVertex3f(farBottomLeft.x,farBottomLeft.y,farBottomLeft.z); | |
| 595 | + glVertex3f(farBottomRight.x,farBottomRight.y,farBottomRight.z); | |
| 596 | + | |
| 617 | 597 | // far plane - top edge |
| 618 | − glVertex3f(low.x,high.y,high.z); | |
| 619 | − glVertex3f(high.x,high.y,high.z); | |
| 598 | + glVertex3f(farTopLeft.x,farTopLeft.y,farTopLeft.z); | |
| 599 | + glVertex3f(farTopRight.x,farTopRight.y,farTopRight.z); | |
| 620 | 600 | |
| 621 | 601 | // far plane - right edge |
| 622 | − glVertex3f(low.x,high.y,high.z); | |
| 623 | − glVertex3f(low.x,low.y,high.z); | |
| 602 | + glVertex3f(farBottomRight.x,farBottomRight.y,farBottomRight.z); | |
| 603 | + glVertex3f(farTopRight.x,farTopRight.y,farTopRight.z); | |
| 624 | 604 | |
| 625 | 605 | // far plane - left edge |
| 626 | − glVertex3f(high.x,high.y,high.z); | |
| 627 | − glVertex3f(high.x,low.y,high.z); | |
| 606 | + glVertex3f(farBottomLeft.x,farBottomLeft.y,farBottomLeft.z); | |
| 607 | + glVertex3f(farTopLeft.x,farTopLeft.y,farTopLeft.z); | |
| 628 | 608 | |
| 629 | 609 | // right plane - bottom edge - near to distant |
| 630 | − glVertex3f(low.x,low.y,low.z); | |
| 631 | − glVertex3f(low.x,low.y,high.z); | |
| 610 | + glColor3f(0,0,1); | |
| 611 | + glVertex3f(nearBottomRight.x,nearBottomRight.y,nearBottomRight.z); | |
| 612 | + glVertex3f(farBottomRight.x,farBottomRight.y,farBottomRight.z); | |
| 632 | 613 | |
| 633 | 614 | // right plane - top edge - near to distant |
| 634 | − glVertex3f(low.x,high.y,low.z); | |
| 635 | − glVertex3f(low.x,high.y,high.z); | |
| 615 | + glVertex3f(nearTopRight.x,nearTopRight.y,nearTopRight.z); | |
| 616 | + glVertex3f(farTopRight.x,farTopRight.y,farTopRight.z); | |
| 636 | 617 | |
| 637 | 618 | // left plane - bottom edge - near to distant |
| 638 | − glVertex3f(high.x,low.y,low.z); | |
| 639 | − glVertex3f(high.x,low.y,high.z); | |
| 619 | + glColor3f(0,1,1); | |
| 620 | + glVertex3f(nearBottomLeft.x,nearBottomLeft.y,nearBottomLeft.z); | |
| 621 | + glVertex3f(farBottomLeft.x,farBottomLeft.y,farBottomLeft.z); | |
| 640 | 622 | |
| 641 | 623 | // left plane - top edge - near to distant |
| 642 | − glVertex3f(high.x,high.y,low.z); | |
| 643 | − glVertex3f(high.x,high.y,high.z); | |
| 644 | −*/ | |
| 624 | + glVertex3f(nearTopLeft.x,nearTopLeft.y,nearTopLeft.z); | |
| 625 | + glVertex3f(farTopLeft.x,farTopLeft.y,farTopLeft.z); | |
| 626 | + | |
| 645 | 627 | glEnd(); |
| 646 | 628 | } |
| 647 | 629 | |
| 648 | 630 | |
| 649 | 631 | void display(void) |
| 650 | 632 | { |
| 651 | − //printf( "avatar head lookat = %f, %f, %f\n", myHead.getAvatarHeadLookatDirection().x, myHead.getAvatarHeadLookatDirection().y, myHead.getAvatarHeadLookatDirection().z ); | |
| 633 | + //printf( "avatar head lookat = %f, %f, %f\n", myAvatar.getAvatarHeadLookatDirection().x, myAvatar.getAvatarHeadLookatDirection().y, myAvatar.getAvatarHeadLookatDirection().z ); | |
| 652 | 634 | |
| 653 | 635 | PerfStat("display"); |
| 654 | 636 | |
| @@ -678,33 +660,42 @@ void display(void) · 23 unmodified lines | ||
| 678 | 660 | //-------------------------------------------------------- |
| 679 | 661 | // camera settings |
| 680 | 662 | //-------------------------------------------------------- |
| 681 | − myCamera.setTargetPosition( myHead.getPos() ); | |
| 663 | + myCamera.setTargetPosition( myAvatar.getPos() ); | |
| 682 | 664 | |
| 683 | − if ( displayHead ) | |
| 684 | − { | |
| 665 | + if ( displayHead ) { | |
| 685 | 666 | //----------------------------------------------- |
| 686 | 667 | // set the camera to looking at my own face |
| 687 | 668 | //----------------------------------------------- |
| 688 | − myCamera.setYaw ( - myHead.getAvatarYaw() ); | |
| 669 | + myCamera.setYaw ( - myAvatar.getBodyYaw() ); | |
| 689 | 670 | myCamera.setPitch ( 0.0 ); |
| 690 | 671 | myCamera.setRoll ( 0.0 ); |
| 691 | 672 | myCamera.setUp ( 0.4 ); |
| 692 | 673 | myCamera.setDistance( 0.5 ); |
| 693 | 674 | myCamera.setDistance( 0.08 ); |
| 694 | 675 | myCamera.update(); |
| 695 | − } | |
| 696 | − else | |
| 697 | − { | |
| 698 | − //---------------------------------------------------- | |
| 699 | − // set the camera to third-person view behind my av | |
| 700 | − //---------------------------------------------------- | |
| 701 | − myCamera.setYaw ( 180.0 - myHead.getAvatarYaw() ); | |
| 702 | − myCamera.setPitch ( 0.0 ); | |
| 703 | − myCamera.setRoll ( 0.0 ); | |
| 704 | − myCamera.setUp ( 0.2 ); | |
| 705 | − myCamera.setDistance( 1.6 ); | |
| 706 | − myCamera.setDistance( 0.5 ); | |
| 707 | − myCamera.update(); | |
| 676 | + } else { | |
| 677 | + if (::viewFrustumFromOffset && ::frustumOn) { | |
| 678 | + //---------------------------------------------------- | |
| 679 | + // set the camera to third-person view but offset so we can see the frustum | |
| 680 | + //---------------------------------------------------- | |
| 681 | + myCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() + ::viewFrustumOffsetYaw ); | |
| 682 | + myCamera.setPitch ( 0.0 + ::viewFrustumOffsetPitch ); | |
| 683 | + myCamera.setRoll ( 0.0 + ::viewFrustumOffsetRoll ); | |
| 684 | + myCamera.setUp ( 0.2 + 0.2 ); | |
| 685 | + myCamera.setDistance( 0.5 + 0.2 ); | |
| 686 | + myCamera.update(); | |
| 687 | + } else { | |
| 688 | + //---------------------------------------------------- | |
| 689 | + // set the camera to third-person view behind my av | |
| 690 | + //---------------------------------------------------- | |
| 691 | + myCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() ); | |
| 692 | + myCamera.setPitch ( 0.0 ); | |
| 693 | + myCamera.setRoll ( 0.0 ); | |
| 694 | + myCamera.setUp ( 0.2 ); | |
| 695 | + myCamera.setDistance( 1.6 ); | |
| 696 | + myCamera.setDistance( 0.5 ); | |
| 697 | + myCamera.update(); | |
| 698 | + } | |
| 708 | 699 | } |
| 709 | 700 | |
| 710 | 701 | //--------------------------------------------- |
| @@ -737,7 +728,7 @@ void display(void) · 26 unmodified lines | ||
| 737 | 728 | //--------------------------------------------- |
| 738 | 729 | // draw a grid gound plane.... |
| 739 | 730 | //--------------------------------------------- |
| 740 | − //drawGroundPlaneGrid( 5.0f, 9 ); | |
| 731 | + drawGroundPlaneGrid( 5.0f, 9 ); | |
| 741 | 732 | |
| 742 | 733 | |
| 743 | 734 | // Draw cloud of dots |
| @@ -754,7 +745,7 @@ void display(void) · 10 unmodified lines | ||
| 754 | 745 | // Draw field vectors |
| 755 | 746 | if (displayField) field.render(); |
| 756 | 747 | |
| 757 | − // Render heads of other agents | |
| 748 | + // Render avatars of other agents | |
| 758 | 749 | for(std::vector<Agent>::iterator agent = agentList.getAgents().begin(); agent != agentList.getAgents().end(); agent++) |
| 759 | 750 | { |
| 760 | 751 | if (agent->getLinkedData() != NULL) |
| @@ -774,19 +765,19 @@ void display(void) · 13 unmodified lines | ||
| 774 | 765 | if (!displayHead && statsOn) render_world_box(); |
| 775 | 766 | |
| 776 | 767 | // brad's frustum for debugging |
| 777 | − render_view_frustum(); | |
| 768 | + if (::frustumOn) render_view_frustum(); | |
| 778 | 769 | |
| 779 | 770 | |
| 780 | 771 | //--------------------------------- |
| 781 | − // Render my own head | |
| 772 | + // Render my own avatar | |
| 782 | 773 | //--------------------------------- |
| 783 | − myHead.render( true, 1 ); | |
| 774 | + myAvatar.render( true, 1 ); | |
| 784 | 775 | |
| 785 | 776 | /* |
| 786 | 777 | glPushMatrix(); |
| 787 | 778 | glLoadIdentity(); |
| 788 | 779 | glTranslatef(0.f, 0.f, -7.f); |
| 789 | − myHead.render(displayHead, 1); | |
| 780 | + myAvatar.render(displayHead, 1); | |
| 790 | 781 | glPopMatrix(); |
| 791 | 782 | */ |
| 792 | 783 | |
| @@ -809,10 +800,6 @@ void display(void) · 16 unmodified lines | ||
| 809 | 800 | if (audioScope.getState()) audioScope.render(); |
| 810 | 801 | #endif |
| 811 | 802 | |
| 812 | − | |
| 813 | − //drawvec3(100, 100, 0.15, 0, 1.0, 0, myHead.getPos(), 0, 1, 0); | |
| 814 | − glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, pointer_attenuation_quadratic ); | |
| 815 | − | |
| 816 | 803 | if (displayHeadMouse && !displayHead && statsOn) |
| 817 | 804 | { |
| 818 | 805 | // Display small target box at center or head mouse target that can also be used to measure LOD |
| @@ -890,9 +877,9 @@ int MenuCallBack setField(int state) { · 71 unmodified lines | ||
| 890 | 877 | int MenuCallBack setNoise(int state) { |
| 891 | 878 | int iRet = setValue(state, &noiseOn); |
| 892 | 879 | if (noiseOn) { |
| 893 | − myHead.setNoise(noise); | |
| 880 | + myAvatar.setNoise(noise); | |
| 894 | 881 | } else { |
| 895 | − myHead.setNoise(0); | |
| 882 | + myAvatar.setNoise(0); | |
| 896 | 883 | } |
| 897 | 884 | return iRet; |
| 898 | 885 | } |
| @@ -966,11 +953,11 @@ void shiftPaintingColor() · 67 unmodified lines | ||
| 966 | 953 | |
| 967 | 954 | void setupPaintingVoxel() |
| 968 | 955 | { |
| 969 | − glm::vec3 headPos = myHead.getPos(); | |
| 956 | + glm::vec3 avatarPos = myAvatar.getPos(); | |
| 970 | 957 | |
| 971 | − ::paintingVoxel.x = headPos.z/-10.0; // voxel space x is negative z head space | |
| 972 | − ::paintingVoxel.y = headPos.y/-10.0; // voxel space y is negative y head space | |
| 973 | − ::paintingVoxel.z = headPos.x/-10.0; // voxel space z is negative x head space | |
| 958 | + ::paintingVoxel.x = avatarPos.z/-10.0; // voxel space x is negative z head space | |
| 959 | + ::paintingVoxel.y = avatarPos.y/-10.0; // voxel space y is negative y head space | |
| 960 | + ::paintingVoxel.z = avatarPos.x/-10.0; // voxel space z is negative x head space | |
| 974 | 961 | ::paintingVoxel.s = 1.0/256; |
| 975 | 962 | |
| 976 | 963 | shiftPaintingColor(); |
| @@ -1002,20 +989,20 @@ const float KEYBOARD_FLY_RATE = 0.08; · 25 unmodified lines | ||
| 1002 | 989 | |
| 1003 | 990 | void specialkeyUp(int k, int x, int y) { |
| 1004 | 991 | if (k == GLUT_KEY_UP) { |
| 1005 | − myHead.setDriveKeys(FWD, 0); | |
| 1006 | − myHead.setDriveKeys(UP, 0); | |
| 992 | + myAvatar.setDriveKeys(FWD, 0); | |
| 993 | + myAvatar.setDriveKeys(UP, 0); | |
| 1007 | 994 | } |
| 1008 | 995 | if (k == GLUT_KEY_DOWN) { |
| 1009 | − myHead.setDriveKeys(BACK, 0); | |
| 1010 | − myHead.setDriveKeys(DOWN, 0); | |
| 996 | + myAvatar.setDriveKeys(BACK, 0); | |
| 997 | + myAvatar.setDriveKeys(DOWN, 0); | |
| 1011 | 998 | } |
| 1012 | 999 | if (k == GLUT_KEY_LEFT) { |
| 1013 | − myHead.setDriveKeys(LEFT, 0); | |
| 1014 | − myHead.setDriveKeys(ROT_LEFT, 0); | |
| 1000 | + myAvatar.setDriveKeys(LEFT, 0); | |
| 1001 | + myAvatar.setDriveKeys(ROT_LEFT, 0); | |
| 1015 | 1002 | } |
| 1016 | 1003 | if (k == GLUT_KEY_RIGHT) { |
| 1017 | − myHead.setDriveKeys(RIGHT, 0); | |
| 1018 | − myHead.setDriveKeys(ROT_RIGHT, 0); | |
| 1004 | + myAvatar.setDriveKeys(RIGHT, 0); | |
| 1005 | + myAvatar.setDriveKeys(ROT_RIGHT, 0); | |
| 1019 | 1006 | } |
| 1020 | 1007 | |
| 1021 | 1008 | } |
| @@ -1024,20 +1011,20 @@ void specialkey(int k, int x, int y) · 2 unmodified lines | ||
| 1024 | 1011 | { |
| 1025 | 1012 | if (k == GLUT_KEY_UP || k == GLUT_KEY_DOWN || k == GLUT_KEY_LEFT || k == GLUT_KEY_RIGHT) { |
| 1026 | 1013 | if (k == GLUT_KEY_UP) { |
| 1027 | − if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) myHead.setDriveKeys(UP, 1); | |
| 1028 | − else myHead.setDriveKeys(FWD, 1); | |
| 1014 | + if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) myAvatar.setDriveKeys(UP, 1); | |
| 1015 | + else myAvatar.setDriveKeys(FWD, 1); | |
| 1029 | 1016 | } |
| 1030 | 1017 | if (k == GLUT_KEY_DOWN) { |
| 1031 | − if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) myHead.setDriveKeys(DOWN, 1); | |
| 1032 | − else myHead.setDriveKeys(BACK, 1); | |
| 1018 | + if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) myAvatar.setDriveKeys(DOWN, 1); | |
| 1019 | + else myAvatar.setDriveKeys(BACK, 1); | |
| 1033 | 1020 | } |
| 1034 | 1021 | if (k == GLUT_KEY_LEFT) { |
| 1035 | − if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) myHead.setDriveKeys(LEFT, 1); | |
| 1036 | − else myHead.setDriveKeys(ROT_LEFT, 1); | |
| 1022 | + if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) myAvatar.setDriveKeys(LEFT, 1); | |
| 1023 | + else myAvatar.setDriveKeys(ROT_LEFT, 1); | |
| 1037 | 1024 | } |
| 1038 | 1025 | if (k == GLUT_KEY_RIGHT) { |
| 1039 | − if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) myHead.setDriveKeys(RIGHT, 1); | |
| 1040 | − else myHead.setDriveKeys(ROT_RIGHT, 1); | |
| 1026 | + if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) myAvatar.setDriveKeys(RIGHT, 1); | |
| 1027 | + else myAvatar.setDriveKeys(ROT_RIGHT, 1); | |
| 1041 | 1028 | } |
| 1042 | 1029 | #ifndef _WIN32 |
| 1043 | 1030 | audio.setWalkingState(true); |
| @@ -1047,12 +1034,12 @@ void specialkey(int k, int x, int y) · 3 unmodified lines | ||
| 1047 | 1034 | |
| 1048 | 1035 | |
| 1049 | 1036 | void keyUp(unsigned char k, int x, int y) { |
| 1050 | − if (k == 'e') myHead.setDriveKeys(UP, 0); | |
| 1051 | − if (k == 'c') myHead.setDriveKeys(DOWN, 0); | |
| 1052 | − if (k == 'w') myHead.setDriveKeys(FWD, 0); | |
| 1053 | − if (k == 's') myHead.setDriveKeys(BACK, 0); | |
| 1054 | − if (k == 'a') myHead.setDriveKeys(ROT_LEFT, 0); | |
| 1055 | − if (k == 'd') myHead.setDriveKeys(ROT_RIGHT, 0); | |
| 1037 | + if (k == 'e') myAvatar.setDriveKeys(UP, 0); | |
| 1038 | + if (k == 'c') myAvatar.setDriveKeys(DOWN, 0); | |
| 1039 | + if (k == 'w') myAvatar.setDriveKeys(FWD, 0); | |
| 1040 | + if (k == 's') myAvatar.setDriveKeys(BACK, 0); | |
| 1041 | + if (k == 'a') myAvatar.setDriveKeys(ROT_LEFT, 0); | |
| 1042 | + if (k == 'd') myAvatar.setDriveKeys(ROT_RIGHT, 0); | |
| 1056 | 1043 | |
| 1057 | 1044 | } |
| 1058 | 1045 | |
| @@ -1064,6 +1051,16 @@ void key(unsigned char k, int x, int y) · 5 unmodified lines | ||
| 1064 | 1051 | if (k == '/') statsOn = !statsOn; // toggle stats |
| 1065 | 1052 | if (k == '*') ::starsOn = !::starsOn; // toggle stars |
| 1066 | 1053 | if (k == 'V') ::showingVoxels = !::showingVoxels; // toggle voxels |
| 1054 | + if (k == 'F') ::frustumOn = !::frustumOn; // toggle view frustum debugging | |
| 1055 | + if (k == 'G') ::viewFrustumFromOffset = !::viewFrustumFromOffset; // toggle view frustum from offset debugging | |
| 1056 | + | |
| 1057 | + if (k == '[') ::viewFrustumOffsetYaw -= 0.5; | |
| 1058 | + if (k == ']') ::viewFrustumOffsetYaw += 0.5; | |
| 1059 | + if (k == '{') ::viewFrustumOffsetPitch -= 0.5; | |
| 1060 | + if (k == '}') ::viewFrustumOffsetPitch += 0.5; | |
| 1061 | + if (k == '(') ::viewFrustumOffsetRoll -= 0.5; | |
| 1062 | + if (k == ')') ::viewFrustumOffsetRoll += 0.5; | |
| 1063 | + | |
| 1067 | 1064 | if (k == '&') { |
| 1068 | 1065 | ::paintOn = !::paintOn; // toggle paint |
| 1069 | 1066 | ::setupPaintingVoxel(); // also randomizes colors |
| @@ -1076,11 +1073,11 @@ void key(unsigned char k, int x, int y) · 6 unmodified lines | ||
| 1076 | 1073 | noiseOn = !noiseOn; // Toggle noise |
| 1077 | 1074 | if (noiseOn) |
| 1078 | 1075 | { |
| 1079 | − myHead.setNoise(noise); | |
| 1076 | + myAvatar.setNoise(noise); | |
| 1080 | 1077 | } |
| 1081 | 1078 | else |
| 1082 | 1079 | { |
| 1083 | − myHead.setNoise(0); | |
| 1080 | + myAvatar.setNoise(0); | |
| 1084 | 1081 | } |
| 1085 | 1082 | |
| 1086 | 1083 | } |
| @@ -1097,10 +1094,10 @@ void key(unsigned char k, int x, int y) · 10 unmodified lines | ||
| 1097 | 1094 | |
| 1098 | 1095 | if (k == 'f') displayField = !displayField; |
| 1099 | 1096 | if (k == 'l') displayLevels = !displayLevels; |
| 1100 | − if (k == 'e') myHead.setDriveKeys(UP, 1); | |
| 1101 | − if (k == 'c') myHead.setDriveKeys(DOWN, 1); | |
| 1102 | − if (k == 'w') myHead.setDriveKeys(FWD, 1); | |
| 1103 | − if (k == 's') myHead.setDriveKeys(BACK, 1); | |
| 1097 | + if (k == 'e') myAvatar.setDriveKeys(UP, 1); | |
| 1098 | + if (k == 'c') myAvatar.setDriveKeys(DOWN, 1); | |
| 1099 | + if (k == 'w') myAvatar.setDriveKeys(FWD, 1); | |
| 1100 | + if (k == 's') myAvatar.setDriveKeys(BACK, 1); | |
| 1104 | 1101 | if (k == ' ') reset_sensors(); |
| 1105 | 1102 | if (k == 't') renderPitchRate -= KEYBOARD_PITCH_RATE; |
| 1106 | 1103 | if (k == 'g') renderPitchRate += KEYBOARD_PITCH_RATE; |
| @@ -1111,8 +1108,8 @@ void key(unsigned char k, int x, int y) · 4 unmodified lines | ||
| 1111 | 1108 | if (k == 'k') if (starsLod > 0.01) starsLod = stars.changeLOD(0.99); |
| 1112 | 1109 | if (k == 'r') stars.readInput(starFile, 0); |
| 1113 | 1110 | #endif |
| 1114 | − if (k == 'a') myHead.setDriveKeys(ROT_LEFT, 1); | |
| 1115 | − if (k == 'd') myHead.setDriveKeys(ROT_RIGHT, 1); | |
| 1111 | + if (k == 'a') myAvatar.setDriveKeys(ROT_LEFT, 1); | |
| 1112 | + if (k == 'd') myAvatar.setDriveKeys(ROT_RIGHT, 1); | |
| 1116 | 1113 | |
| 1117 | 1114 | // press the . key to get a new random sphere of voxels added |
| 1118 | 1115 | if (k == '.') addRandomSphere(wantColorRandomizer); |
| @@ -1134,7 +1131,7 @@ void *networkReceive(void *args) · 15 unmodified lines | ||
| 1134 | 1131 | |
| 1135 | 1132 | if (incomingPacket[0] == PACKET_HEADER_TRANSMITTER_DATA) { |
| 1136 | 1133 | // Pass everything but transmitter data to the agent list |
| 1137 | − myHead.hand->processTransmitterData(incomingPacket, bytesReceived); | |
| 1134 | + myAvatar.hand->processTransmitterData(incomingPacket, bytesReceived); | |
| 1138 | 1135 | } else if (incomingPacket[0] == PACKET_HEADER_VOXEL_DATA || |
| 1139 | 1136 | incomingPacket[0] == PACKET_HEADER_Z_COMMAND || |
| 1140 | 1137 | incomingPacket[0] == PACKET_HEADER_ERASE_VOXEL) { |
| @@ -1166,12 +1163,12 @@ void idle(void) · 25 unmodified lines | ||
| 1166 | 1163 | float xOffset = ( mouseX - mouseStartX ) / (double)WIDTH; |
| 1167 | 1164 | float yOffset = ( mouseY - mouseStartY ) / (double)HEIGHT; |
| 1168 | 1165 | |
| 1169 | − float leftRight = xOffset; | |
| 1170 | − float downUp = yOffset; | |
| 1166 | + float leftRight = xOffset; | |
| 1167 | + float downUp = -yOffset; | |
| 1171 | 1168 | float backFront = 0.0; |
| 1172 | 1169 | |
| 1173 | 1170 | glm::vec3 handMovement( leftRight, downUp, backFront ); |
| 1174 | − myHead.setHandMovement( handMovement ); | |
| 1171 | + myAvatar.setHandMovement( handMovement ); | |
| 1175 | 1172 | } |
| 1176 | 1173 | |
| 1177 | 1174 | // Simulation |
| @@ -1194,7 +1191,7 @@ void idle(void) · 16 unmodified lines | ||
| 1194 | 1191 | simulateHand(1.f/FPS); |
| 1195 | 1192 | |
| 1196 | 1193 | field.simulate(1.f/FPS); |
| 1197 | − myHead.simulate(1.f/FPS); | |
| 1194 | + myAvatar.simulate(1.f/FPS); | |
| 1198 | 1195 | balls.simulate(1.f/FPS); |
| 1199 | 1196 | cloud.simulate(1.f/FPS); |
| 1200 | 1197 | lattice.simulate(1.f/FPS); |