Showing the changes to interface/src/main.cpp (1 of 1 file). Show all
Unified · Split
| @@ -511,6 +511,151 @@ void simulateHead(float frametime) · 510 unmodified lines | ||
| 511 | 511 | } |
| 512 | 512 | } |
| 513 | 513 | |
| 514 | +// These handy operators should probably go somewhere else, I'm surprised they don't | |
| 515 | +// already exist somewhere in OpenGL. Maybe someone can point me to them if they do exist! | |
| 516 | +glm::vec3 operator* (float lhs, const glm::vec3& rhs) | |
| 517 | +{ | |
| 518 | + glm::vec3 result = rhs; | |
| 519 | + result.x *= lhs; | |
| 520 | + result.y *= lhs; | |
| 521 | + result.z *= lhs; | |
| 522 | + return result; | |
| 523 | +} | |
| 524 | + | |
| 525 | +glm::vec3 operator* (const glm::vec3& lhs, float rhs) | |
| 526 | +{ | |
| 527 | + glm::vec3 result = lhs; | |
| 528 | + result.x *= rhs; | |
| 529 | + result.y *= rhs; | |
| 530 | + result.z *= rhs; | |
| 531 | + return result; | |
| 532 | +} | |
| 533 | + | |
| 534 | +// XXXBHG - this code is not yet working. This is here to help Jeffery debug getAvatarHeadLookatDirection() | |
| 535 | +// The code will draw a yellow line from the avatar's position to the origin, | |
| 536 | +// It also attempts to draw a cyan line from the avatar to 2 meters in front of the avatar in the direction | |
| 537 | +// it's looking. But that's not working right now. | |
| 538 | +void render_view_frustum() { | |
| 539 | + | |
| 540 | + //printf("frustum low.x=%f, low.y=%f, low.z=%f, high.x=%f, high.y=%f, high.z=%f\n",low.x,low.y,low.z,high.x,high.y,high.z); | |
| 541 | + | |
| 542 | + | |
| 543 | + // p – the camera position | |
| 544 | + // d – a vector with the direction of the camera's view ray. In here it is assumed that this vector has been normalized | |
| 545 | + // nearDist – the distance from the camera to the near plane | |
| 546 | + // nearHeight – the height of the near plane | |
| 547 | + // nearWidth – the width of the near plane | |
| 548 | + // farDist – the distance from the camera to the far plane | |
| 549 | + // farHeight – the height of the far plane | |
| 550 | + // farWidth – the width of the far plane | |
| 551 | + | |
| 552 | + glm::vec3 cameraPosition = ::myHead.getPos()*-1.0; // We need to flip the sign to make this work. | |
| 553 | + glm::vec3 cameraDirection = ::myHead.getAvatarHeadLookatDirection()*-1.0; // gak! Not sure if this is correct! | |
| 554 | + | |
| 555 | + // this is a temporary test, create a vertice that's 2 meters in front of avatar in direction their looking | |
| 556 | + glm::vec3 lookingAt = cameraPosition+(cameraDirection*2.0); | |
| 557 | + | |
| 558 | + // Some debug lines. | |
| 559 | + glDisable(GL_LIGHTING); | |
| 560 | + glColor4f(1.0, 1.0, 1.0, 1.0); | |
| 561 | + glLineWidth(1.0); | |
| 562 | + glBegin(GL_LINES); | |
| 563 | + | |
| 564 | + // line from avatar to the origin -- this one is working. | |
| 565 | + glColor3f(1,1,0); | |
| 566 | + glVertex3f(cameraPosition.x,cameraPosition.y,cameraPosition.z); | |
| 567 | + glVertex3f(0,0,0); | |
| 568 | + | |
| 569 | + // line from avatar to 2 meters in front of avatar -- this is NOT working | |
| 570 | + glColor3f(0,1,1); | |
| 571 | + glVertex3f(cameraPosition.x,cameraPosition.y,cameraPosition.z); | |
| 572 | + glVertex3f(lookingAt.x,lookingAt.y,lookingAt.z); | |
| 573 | + | |
| 574 | + /* | |
| 575 | + // Not yet ready for this... | |
| 576 | + glm::vec3 up = glm::vec3(0.0,1.0,0.0); | |
| 577 | + glm::vec3 right = glm::vec3(1.0,0.0,0.0); | |
| 578 | + float nearDist = 0.1; | |
| 579 | + float farDist = 500.0; | |
| 580 | + float fov = (0.7854f*2.0); // 45 deg * 2 = 90 deg | |
| 581 | + | |
| 582 | + float screenWidth = 800.0; // hack! We need to make this eventually be the correct height/width | |
| 583 | + float screenHeight = 600.0; | |
| 584 | + float ratio = screenWidth/screenHeight; | |
| 585 | + float nearHeight = 2 * tan(fov / 2) * nearDist; | |
| 586 | + float nearWidth = nearHeight * ratio; | |
| 587 | + float farHeight = 2 * tan(fov / 2) * farDist; | |
| 588 | + float farWidth = farHeight * ratio; | |
| 589 | + | |
| 590 | + glm::vec3 farCenter = cameraPosition+cameraDirection*farDist; | |
| 591 | + glm::vec3 farTopLeft = farCenter + (up*farHeight*0.5) - (right*farWidth*0.5); | |
| 592 | + glm::vec3 farTopRight = farCenter + (up*farHeight*0.5) + (right*farWidth*0.5); | |
| 593 | + glm::vec3 farBottomLeft = farCenter - (up*farHeight*0.5) - (right*farWidth*0.5); | |
| 594 | + glm::vec3 farBottomRight = farCenter - (up*farHeight*0.5) + (right*farWidth*0.5); | |
| 595 | + | |
| 596 | + glm::vec3 nearCenter = cameraPosition+cameraDirection*nearDist; | |
| 597 | + glm::vec3 nearTopLeft = nearCenter + (up*nearHeight*0.5) - (right*nearWidth*0.5); | |
| 598 | + glm::vec3 nearTopRight = nearCenter + (up*nearHeight*0.5) + (right*nearWidth*0.5); | |
| 599 | + glm::vec3 nearBottomLeft = nearCenter - (up*nearHeight*0.5) - (right*nearWidth*0.5); | |
| 600 | + glm::vec3 nearBottomRight = nearCenter - (up*nearHeight*0.5) + (right*nearWidth*0.5); | |
| 601 | + */ | |
| 602 | + | |
| 603 | + | |
| 604 | +/* | |
| 605 | + glColor3f(1,1,1); | |
| 606 | + | |
| 607 | + // near plane - bottom edge | |
| 608 | + glVertex3f(low.x,low.y,low.z); | |
| 609 | + glVertex3f(high.x,low.y,low.z); | |
| 610 | + | |
| 611 | + // near plane - top edge | |
| 612 | + glVertex3f(low.x,high.y,low.z); | |
| 613 | + glVertex3f(high.x,high.y,low.z); | |
| 614 | + | |
| 615 | + // near plane - right edge | |
| 616 | + glVertex3f(low.x,high.y,low.z); | |
| 617 | + glVertex3f(low.x,low.y,low.z); | |
| 618 | + | |
| 619 | + // near plane - left edge | |
| 620 | + glVertex3f(high.x,high.y,low.z); | |
| 621 | + glVertex3f(high.x,low.y,low.z); | |
| 622 | + | |
| 623 | + // far plane - bottom edge | |
| 624 | + glVertex3f(low.x,low.y,high.z); | |
| 625 | + glVertex3f(high.x,low.y,high.z); | |
| 626 | + | |
| 627 | + // far plane - top edge | |
| 628 | + glVertex3f(low.x,high.y,high.z); | |
| 629 | + glVertex3f(high.x,high.y,high.z); | |
| 630 | + | |
| 631 | + // far plane - right edge | |
| 632 | + glVertex3f(low.x,high.y,high.z); | |
| 633 | + glVertex3f(low.x,low.y,high.z); | |
| 634 | + | |
| 635 | + // far plane - left edge | |
| 636 | + glVertex3f(high.x,high.y,high.z); | |
| 637 | + glVertex3f(high.x,low.y,high.z); | |
| 638 | + | |
| 639 | + // right plane - bottom edge - near to distant | |
| 640 | + glVertex3f(low.x,low.y,low.z); | |
| 641 | + glVertex3f(low.x,low.y,high.z); | |
| 642 | + | |
| 643 | + // right plane - top edge - near to distant | |
| 644 | + glVertex3f(low.x,high.y,low.z); | |
| 645 | + glVertex3f(low.x,high.y,high.z); | |
| 646 | + | |
| 647 | + // left plane - bottom edge - near to distant | |
| 648 | + glVertex3f(high.x,low.y,low.z); | |
| 649 | + glVertex3f(high.x,low.y,high.z); | |
| 650 | + | |
| 651 | + // left plane - top edge - near to distant | |
| 652 | + glVertex3f(high.x,high.y,low.z); | |
| 653 | + glVertex3f(high.x,high.y,high.z); | |
| 654 | +*/ | |
| 655 | + glEnd(); | |
| 656 | +} | |
| 657 | + | |
| 658 | + | |
| 514 | 659 | void display(void) |
| 515 | 660 | { |
| 516 | 661 | //printf( "avatar head lookat = %f, %f, %f\n", myHead.getAvatarHeadLookatDirection().x, myHead.getAvatarHeadLookatDirection().y, myHead.getAvatarHeadLookatDirection().z ); |
| @@ -637,6 +782,9 @@ void display(void) · 120 unmodified lines | ||
| 637 | 782 | |
| 638 | 783 | // Render the world box |
| 639 | 784 | if (!displayHead && statsOn) render_world_box(); |
| 785 | + | |
| 786 | + // brad's frustum for debugging | |
| 787 | + render_view_frustum(); | |
| 640 | 788 | |
| 641 | 789 | |
| 642 | 790 | //--------------------------------- |