mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 17:03:58 +02:00
pull (Jeffrey)
Merge branch 'master' of github.com:worklist/hifi
This commit is contained in:
commit
81c4186179
4 changed files with 191 additions and 133 deletions
|
@ -18,8 +18,8 @@ Camera::Camera()
|
|||
roll = 0.0;
|
||||
up = 0.0;
|
||||
distance = 0.0;
|
||||
targetPosition = glm::dvec3( 0.0, 0.0, 0.0 );
|
||||
position = glm::dvec3( 0.0, 0.0, 0.0 );
|
||||
targetPosition = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
position = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
orientation.setToIdentity();
|
||||
}
|
||||
|
||||
|
@ -30,12 +30,11 @@ void Camera::update()
|
|||
{
|
||||
double radian = ( yaw / 180.0 ) * PIE;
|
||||
|
||||
double x = distance * sin( radian );
|
||||
double z = distance * -cos( radian );
|
||||
double y = -up;
|
||||
double x = distance * -sin( radian );
|
||||
double z = distance * cos( radian );
|
||||
double y = up;
|
||||
|
||||
position = glm::dvec3( targetPosition );
|
||||
position += glm::dvec3( x, y, z );
|
||||
position = targetPosition + glm::vec3( x, y, z );
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
//geterate the ortho-normals for the orientation based on the Euler angles
|
||||
|
|
|
@ -47,8 +47,8 @@ Head::Head()
|
|||
{
|
||||
initializeAvatar();
|
||||
|
||||
position = glm::vec3(0,0,0);
|
||||
velocity = glm::vec3(0,0,0);
|
||||
//position = glm::vec3(0,0,0);
|
||||
//velocity = glm::vec3(0,0,0);
|
||||
thrust = glm::vec3(0,0,0);
|
||||
|
||||
for (int i = 0; i < MAX_DRIVE_KEYS; i++) driveKeys[i] = false;
|
||||
|
@ -91,8 +91,8 @@ Head::Head()
|
|||
sphere = NULL;
|
||||
|
||||
springForce = 6.0f;
|
||||
springToBodyTightness = 2.0f;
|
||||
springVelocityDecay = 5.0f;
|
||||
springToBodyTightness = 4.0f;
|
||||
springVelocityDecay = 2.0f;
|
||||
|
||||
hand = new Hand(glm::vec3(skinColor[0], skinColor[1], skinColor[2]));
|
||||
|
||||
|
@ -114,7 +114,7 @@ Head::Head(const Head &otherHead)
|
|||
initializeAvatar();
|
||||
|
||||
position = otherHead.position;
|
||||
velocity = otherHead.velocity;
|
||||
//velocity = otherHead.velocity;
|
||||
thrust = otherHead.thrust;
|
||||
for (int i = 0; i < MAX_DRIVE_KEYS; i++) driveKeys[i] = otherHead.driveKeys[i];
|
||||
|
||||
|
@ -242,15 +242,6 @@ void Head::UpdatePos(float frametime, SerialInterface * serialInterface, int hea
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------
|
||||
void Head::setAvatarPosition( float x, float y, float z )
|
||||
{
|
||||
avatar.position = glm::vec3( x, y, z );
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------
|
||||
void Head::addLean(float x, float z) {
|
||||
// Add Body lean as impulse
|
||||
|
@ -288,23 +279,7 @@ void Head::simulate(float deltaTime)
|
|||
// update springy behavior:
|
||||
//------------------------------------------------------------------------
|
||||
updateAvatarSprings( deltaTime );
|
||||
|
||||
|
||||
/*
|
||||
glm::vec3 forward
|
||||
(
|
||||
-sin( avatar.yaw * PI_OVER_180 ),
|
||||
sin( avatar.pitch * PI_OVER_180 ),
|
||||
cos( avatar.roll * PI_OVER_180 )
|
||||
);
|
||||
|
||||
glm::vec3 forward(-sinf(getRenderYaw()*PI/180),
|
||||
sinf(getRenderPitch()*PI/180),
|
||||
cosf(getRenderYaw()*PI/180));
|
||||
|
||||
thrust = glm::vec3(0);
|
||||
*/
|
||||
|
||||
|
||||
const float THRUST_MAG = 10.0;
|
||||
const float YAW_MAG = 300.0;
|
||||
|
||||
|
@ -313,32 +288,32 @@ void Head::simulate(float deltaTime)
|
|||
//notice that the z values from avatar.orientation are flipped to accommodate different coordinate system
|
||||
if (driveKeys[FWD])
|
||||
{
|
||||
glm::vec3 front( avatar.orientation.getFront().x, avatar.orientation.getFront().y, -avatar.orientation.getFront().z );
|
||||
glm::vec3 front( avatar.orientation.getFront().x, avatar.orientation.getFront().y, avatar.orientation.getFront().z );
|
||||
avatar.thrust += front * THRUST_MAG;
|
||||
}
|
||||
if (driveKeys[BACK])
|
||||
{
|
||||
glm::vec3 front( avatar.orientation.getFront().x, avatar.orientation.getFront().y, -avatar.orientation.getFront().z );
|
||||
glm::vec3 front( avatar.orientation.getFront().x, avatar.orientation.getFront().y, avatar.orientation.getFront().z );
|
||||
avatar.thrust -= front * THRUST_MAG;
|
||||
}
|
||||
if (driveKeys[RIGHT])
|
||||
{
|
||||
glm::vec3 right( avatar.orientation.getRight().x, avatar.orientation.getRight().y, -avatar.orientation.getRight().z );
|
||||
glm::vec3 right( avatar.orientation.getRight().x, avatar.orientation.getRight().y, avatar.orientation.getRight().z );
|
||||
avatar.thrust += right * THRUST_MAG;
|
||||
}
|
||||
if (driveKeys[LEFT])
|
||||
{
|
||||
glm::vec3 right( avatar.orientation.getRight().x, avatar.orientation.getRight().y, -avatar.orientation.getRight().z );
|
||||
glm::vec3 right( avatar.orientation.getRight().x, avatar.orientation.getRight().y, avatar.orientation.getRight().z );
|
||||
avatar.thrust -= right * THRUST_MAG;
|
||||
}
|
||||
if (driveKeys[UP])
|
||||
{
|
||||
glm::vec3 up( avatar.orientation.getUp().x, avatar.orientation.getUp().y, -avatar.orientation.getUp().z );
|
||||
glm::vec3 up( avatar.orientation.getUp().x, avatar.orientation.getUp().y, avatar.orientation.getUp().z );
|
||||
avatar.thrust += up * THRUST_MAG;
|
||||
}
|
||||
if (driveKeys[DOWN])
|
||||
{
|
||||
glm::vec3 up( avatar.orientation.getUp().x, avatar.orientation.getUp().y, -avatar.orientation.getUp().z );
|
||||
glm::vec3 up( avatar.orientation.getUp().x, avatar.orientation.getUp().y, avatar.orientation.getUp().z );
|
||||
avatar.thrust -= up * THRUST_MAG;
|
||||
}
|
||||
|
||||
|
@ -358,11 +333,11 @@ void Head::simulate(float deltaTime)
|
|||
const float TEST_YAW_DECAY = 5.0;
|
||||
avatar.yawDelta *= ( 1.0 - TEST_YAW_DECAY * deltaTime );
|
||||
|
||||
//avatar.yawDelta *= 0.99;
|
||||
|
||||
avatar.velocity += glm::dvec3( avatar.thrust * deltaTime );
|
||||
|
||||
position += (glm::vec3)avatar.velocity * deltaTime;
|
||||
//avatar.position += (glm::vec3)avatar.velocity * deltaTime;
|
||||
//position = avatar.position;
|
||||
|
||||
//avatar.velocity *= 0.9;
|
||||
|
||||
|
@ -492,11 +467,46 @@ void Head::simulate(float deltaTime)
|
|||
//---------------------------------------------------
|
||||
void Head::render(int faceToFace, int isMine)
|
||||
{
|
||||
glPushMatrix();
|
||||
glTranslatef( position.x, position.y, position.z );
|
||||
glScalef( 0.03, 0.03, 0.03 );
|
||||
glutSolidSphere( 1, 10, 10 );
|
||||
glPopMatrix();
|
||||
|
||||
renderOrientationDirections(avatar.bone[ AVATAR_BONE_HEAD ].position, avatar.bone[ AVATAR_BONE_HEAD ].orientation, 0.2f );
|
||||
|
||||
renderBody();
|
||||
renderHead( faceToFace, isMine );
|
||||
}
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------
|
||||
void Head::renderOrientationDirections( glm::vec3 position, Orientation orientation, float size )
|
||||
{
|
||||
glm::vec3 pRight = position + orientation.getRight () * size;
|
||||
glm::vec3 pUp = position + orientation.getUp () * size;
|
||||
glm::vec3 pFront = position + orientation.getFront () * size;
|
||||
|
||||
glColor3f( 1.0f, 0.0f, 0.0f );
|
||||
glBegin( GL_LINE_STRIP );
|
||||
glVertex3f( avatar.bone[ AVATAR_BONE_HEAD ].position.x, avatar.bone[ AVATAR_BONE_HEAD ].position.y, avatar.bone[ AVATAR_BONE_HEAD ].position.z );
|
||||
glVertex3f( pRight.x, pRight.y, pRight.z );
|
||||
glEnd();
|
||||
|
||||
glColor3f( 0.0f, 1.0f, 0.0f );
|
||||
glBegin( GL_LINE_STRIP );
|
||||
glVertex3f( avatar.bone[ AVATAR_BONE_HEAD ].position.x, avatar.bone[ AVATAR_BONE_HEAD ].position.y, avatar.bone[ AVATAR_BONE_HEAD ].position.z );
|
||||
glVertex3f( pUp.x, pUp.y, pUp.z );
|
||||
glEnd();
|
||||
|
||||
glColor3f( 0.0f, 0.0f, 1.0f );
|
||||
glBegin( GL_LINE_STRIP );
|
||||
glVertex3f( avatar.bone[ AVATAR_BONE_HEAD ].position.x, avatar.bone[ AVATAR_BONE_HEAD ].position.y, avatar.bone[ AVATAR_BONE_HEAD ].position.z );
|
||||
glVertex3f( pFront.x, pFront.y, pFront.z );
|
||||
glEnd();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------
|
||||
|
@ -682,12 +692,12 @@ void Head::setHandMovement( glm::vec3 movement )
|
|||
//-----------------------------------------
|
||||
void Head::initializeAvatar()
|
||||
{
|
||||
avatar.position = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
//avatar.position = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
avatar.velocity = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
avatar.thrust = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
avatar.orientation.setToIdentity();
|
||||
|
||||
avatar.yaw = 90.0;
|
||||
avatar.yaw = -90.0;
|
||||
avatar.pitch = 0.0;
|
||||
avatar.roll = 0.0;
|
||||
|
||||
|
@ -812,24 +822,26 @@ void Head::updateAvatarSkeleton()
|
|||
// rotate...
|
||||
//------------------------------------------------------------------------
|
||||
avatar.orientation.setToIdentity();
|
||||
avatar.orientation.yaw( -avatar.yaw );
|
||||
avatar.orientation.yaw( avatar.yaw );
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// calculate positions of all bones by traversing the skeleton tree:
|
||||
//------------------------------------------------------------------------
|
||||
for (int b=0; b<NUM_AVATAR_BONES; b++)
|
||||
{
|
||||
{
|
||||
if ( avatar.bone[b].parent == AVATAR_BONE_NULL )
|
||||
{
|
||||
avatar.bone[b].orientation.set( avatar.orientation );
|
||||
avatar.bone[b].position = avatar.position;
|
||||
avatar.bone[b].position = position;
|
||||
}
|
||||
else
|
||||
{
|
||||
avatar.bone[b].orientation.set( avatar.bone[ avatar.bone[b].parent ].orientation );
|
||||
avatar.bone[b].position = avatar.bone[ avatar.bone[b].parent ].position;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
float xx = glm::dot( avatar.bone[b].defaultPosePosition.x, (float)avatar.bone[b].orientation.getRight ().x )
|
||||
+ glm::dot( avatar.bone[b].defaultPosePosition.y, (float)avatar.bone[b].orientation.getRight ().y )
|
||||
+ glm::dot( avatar.bone[b].defaultPosePosition.z, (float)avatar.bone[b].orientation.getRight ().z );
|
||||
|
@ -841,23 +853,17 @@ void Head::updateAvatarSkeleton()
|
|||
float zz = glm::dot( avatar.bone[b].defaultPosePosition.x, (float)avatar.bone[b].orientation.getFront ().x )
|
||||
+ glm::dot( avatar.bone[b].defaultPosePosition.y, (float)avatar.bone[b].orientation.getFront ().y )
|
||||
+ glm::dot( avatar.bone[b].defaultPosePosition.z, (float)avatar.bone[b].orientation.getFront ().z );
|
||||
|
||||
*/
|
||||
|
||||
float xx = glm::dot( avatar.bone[b].defaultPosePosition, avatar.bone[b].orientation.getRight () );
|
||||
float yy = glm::dot( avatar.bone[b].defaultPosePosition, avatar.bone[b].orientation.getUp () );
|
||||
float zz = -glm::dot( avatar.bone[b].defaultPosePosition, avatar.bone[b].orientation.getFront () );
|
||||
|
||||
//float xx = avatar.bone[b].defaultPosePosition.x;
|
||||
//float yy = avatar.bone[b].defaultPosePosition.y;
|
||||
//float zz = avatar.bone[b].defaultPosePosition.z;
|
||||
|
||||
glm::vec3 rotatedBoneVector( xx, yy, zz );
|
||||
|
||||
//rotatedBonePosition.x = avatar.bone[b].defaultPosePosition.x;// * avatar.bone[b].orientation.getFront().x;
|
||||
//rotatedBonePosition.y = avatar.bone[b].defaultPosePosition.y;// * avatar.bone[b].orientation.getFront().y;
|
||||
//rotatedBonePosition.z = avatar.bone[b].defaultPosePosition.z;// * avatar.bone[b].orientation.getFront().z;
|
||||
|
||||
|
||||
|
||||
//glm::dvec3 rotatedBoneVector( avatar.bone[b].defaultPosePosition );
|
||||
|
||||
//glm::dmat3x3 rotationMatrix ( glm::dvec3( 1.0, 0.0, 0.0 ), glm::dvec3( 0.0, 1.0, 0.0 ), glm::dvec3( 0.0, 0.0, 1.0 ) );
|
||||
//glm::dmat3x3 rotationMatrix;
|
||||
|
||||
//glm::dmat3x3 rotationMatrix = glm::eulerAngleYXZ( 0.0, 0.0, 0.0 );
|
||||
|
||||
|
||||
avatar.bone[b].position += rotatedBoneVector;
|
||||
}
|
||||
|
||||
|
@ -869,17 +875,6 @@ void Head::updateAvatarSkeleton()
|
|||
updateHandMovement();
|
||||
handBeingMoved = false;
|
||||
}
|
||||
|
||||
/*
|
||||
glm::dvec3 v( avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position );
|
||||
v -= avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position;
|
||||
|
||||
double distance = glm::length(v);
|
||||
if ( distance > avatar.maxArmLength )
|
||||
{
|
||||
avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position += v * 0.2;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
@ -894,11 +889,11 @@ void Head::updateAvatarSprings( float deltaTime )
|
|||
|
||||
if ( avatar.bone[b].parent == AVATAR_BONE_NULL )
|
||||
{
|
||||
springVector -= avatar.position;
|
||||
springVector -= position;
|
||||
}
|
||||
else if ( avatar.bone[b].parent == AVATAR_BONE_PELVIS_SPINE )
|
||||
{
|
||||
springVector -= avatar.position;
|
||||
springVector -= position;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -942,7 +937,7 @@ glm::vec3 Head::getHeadLookatDirection()
|
|||
(
|
||||
avatar.orientation.getFront().x,
|
||||
avatar.orientation.getFront().y,
|
||||
-avatar.orientation.getFront().z
|
||||
avatar.orientation.getFront().z
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -953,7 +948,7 @@ glm::vec3 Head::getHeadLookatDirectionUp()
|
|||
(
|
||||
avatar.orientation.getUp().x,
|
||||
avatar.orientation.getUp().y,
|
||||
-avatar.orientation.getUp().z
|
||||
avatar.orientation.getUp().z
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -964,7 +959,7 @@ glm::vec3 Head::getHeadLookatDirectionRight()
|
|||
(
|
||||
avatar.orientation.getRight().x,
|
||||
avatar.orientation.getRight().y,
|
||||
-avatar.orientation.getRight().z
|
||||
avatar.orientation.getRight().z
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1003,17 +998,17 @@ void Head::updateHandMovement()
|
|||
transformedHandMovement.x
|
||||
= glm::dot( movedHandOffset.x, -(float)avatar.orientation.getRight().x )
|
||||
+ glm::dot( movedHandOffset.y, -(float)avatar.orientation.getRight().y )
|
||||
+ glm::dot( movedHandOffset.z, (float)avatar.orientation.getRight().z );
|
||||
+ glm::dot( movedHandOffset.z, -(float)avatar.orientation.getRight().z );
|
||||
|
||||
transformedHandMovement.y
|
||||
= glm::dot( movedHandOffset.x, -(float)avatar.orientation.getUp().x )
|
||||
+ glm::dot( movedHandOffset.y, -(float)avatar.orientation.getUp().y )
|
||||
+ glm::dot( movedHandOffset.z, (float)avatar.orientation.getUp().z );
|
||||
+ glm::dot( movedHandOffset.z, -(float)avatar.orientation.getUp().z );
|
||||
|
||||
transformedHandMovement.z
|
||||
= glm::dot( movedHandOffset.x, -(float)avatar.orientation.getFront().x )
|
||||
+ glm::dot( movedHandOffset.y, -(float)avatar.orientation.getFront().y )
|
||||
+ glm::dot( movedHandOffset.z, (float)avatar.orientation.getFront().z );
|
||||
+ glm::dot( movedHandOffset.z, -(float)avatar.orientation.getFront().z );
|
||||
|
||||
avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position += transformedHandMovement;
|
||||
glm::vec3 armVector = avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position;
|
||||
|
@ -1093,7 +1088,7 @@ void Head::renderBody()
|
|||
for (int b=1; b<NUM_AVATAR_BONES; b++)
|
||||
{
|
||||
glBegin( GL_LINE_STRIP );
|
||||
glVertex3fv( &avatar.bone[ avatar.bone[ b ].parent ].position.x);
|
||||
glVertex3fv( &avatar.bone[ avatar.bone[ b ].parent ].position.x );
|
||||
glVertex3fv( &avatar.bone[ b ].position.x);
|
||||
glEnd();
|
||||
}
|
||||
|
@ -1107,8 +1102,8 @@ void Head::renderBody()
|
|||
for (int b=1; b<NUM_AVATAR_BONES; b++)
|
||||
{
|
||||
glBegin( GL_LINE_STRIP );
|
||||
glVertex3fv( &avatar.bone[ avatar.bone[ b ].parent ].springyPosition.x);
|
||||
glVertex3fv( &avatar.bone[ b ].springyPosition.x);
|
||||
glVertex3fv( &avatar.bone[ avatar.bone[ b ].parent ].springyPosition.x );
|
||||
glVertex3fv( &avatar.bone[ b ].springyPosition.x );
|
||||
glEnd();
|
||||
}
|
||||
|
||||
|
@ -1149,10 +1144,10 @@ void Head::renderBody()
|
|||
glVertex3fv(&avatar.bone[AVATAR_BONE_RIGHT_FOOT].position.x);
|
||||
glEnd();
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Transmit data to agents requesting it
|
||||
|
||||
//called on me just prior to sending data to others (continuasly called)
|
||||
|
|
|
@ -116,7 +116,7 @@ struct AvatarBone
|
|||
|
||||
struct Avatar
|
||||
{
|
||||
glm::vec3 position;
|
||||
//glm::vec3 position;
|
||||
glm::dvec3 velocity;
|
||||
glm::vec3 thrust;
|
||||
float yaw;
|
||||
|
@ -166,9 +166,10 @@ class Head : public AgentData {
|
|||
|
||||
void render(int faceToFace, int isMine);
|
||||
|
||||
void setAvatarPosition( float, float, float );
|
||||
//void setAvatarPosition( float, float, float );
|
||||
void renderBody();
|
||||
void renderHead( int faceToFace, int isMine );
|
||||
void renderOrientationDirections( glm::vec3 position, Orientation orientation, float size );
|
||||
|
||||
void simulate(float);
|
||||
|
||||
|
@ -235,7 +236,7 @@ class Head : public AgentData {
|
|||
float browAudioLift;
|
||||
|
||||
glm::vec3 position;
|
||||
glm::vec3 velocity;
|
||||
//glm::vec3 velocity;
|
||||
glm::vec3 thrust;
|
||||
|
||||
bool handBeingMoved;
|
||||
|
|
|
@ -110,7 +110,7 @@ int starsTiles = 20;
|
|||
double starsLod = 1.0;
|
||||
#endif
|
||||
|
||||
bool showingVoxels = false;
|
||||
bool showingVoxels = true;
|
||||
|
||||
glm::vec3 box(WORLD_SIZE,WORLD_SIZE,WORLD_SIZE);
|
||||
|
||||
|
@ -156,6 +156,7 @@ VoxelDetail paintingVoxel; // The voxel we're painting if we're painting
|
|||
unsigned char dominantColor = 0; // The dominant color of the voxel we're painting
|
||||
bool perfStatsOn = false; // Do we want to display perfStats?
|
||||
bool frustumOn = false; // Whether or not to display the debug view frustum
|
||||
bool cameraFrustum = false; // which frustum to look at
|
||||
|
||||
bool viewFrustumFromOffset=false; // Wether or not to offset the view of the frustum
|
||||
float viewFrustumOffsetYaw = -90.0;
|
||||
|
@ -413,12 +414,7 @@ void simulateHead(float frametime)
|
|||
//float measured_fwd_accel = serialPort.getRelativeValue(ACCEL_Z);
|
||||
|
||||
myAvatar.UpdatePos(frametime, &serialPort, headMirror, &gravity);
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
// set the position of the avatar
|
||||
//-------------------------------------------------------------------------------------
|
||||
myAvatar.setAvatarPosition( -myAvatar.getPos().x, -myAvatar.getPos().y, -myAvatar.getPos().z );
|
||||
|
||||
|
||||
// Update head_mouse model
|
||||
const float MIN_MOUSE_RATE = 30.0;
|
||||
const float MOUSE_SENSITIVITY = 0.1f;
|
||||
|
@ -533,11 +529,48 @@ void render_view_frustum() {
|
|||
// farHeight – the height of the far plane
|
||||
// farWidth – the width of the far plane
|
||||
|
||||
glm::vec3 viewFrustumPosition = myAvatar.getHeadPosition();
|
||||
glm::vec3 viewFrustumDirection = myAvatar.getHeadLookatDirection();
|
||||
glm::vec3 cameraPosition = ::myCamera.getPosition() * -1.0;
|
||||
glm::vec3 headPosition = ::myAvatar.getHeadPosition();
|
||||
printf("\nPosition:\n");
|
||||
printf("cameraPosition=%f, cameraPosition=%f, cameraPosition=%f\n",cameraPosition.x,cameraPosition.y,cameraPosition.z);
|
||||
printf("headPosition.x=%f, headPosition.y=%f, headPosition.z=%f\n",headPosition.x,headPosition.y,headPosition.z);
|
||||
|
||||
glm::vec3 cameraDirection = ::myCamera.getOrientation().getFront() * glm::vec3(-1,-1,1);
|
||||
glm::vec3 headDirection = myAvatar.getHeadLookatDirection();
|
||||
printf("\nDirection:\n");
|
||||
printf("cameraDirection.x=%f, cameraDirection.y=%f, cameraDirection.z=%f\n",cameraDirection.x,cameraDirection.y,cameraDirection.z);
|
||||
printf("headDirection.x=%f, headDirection.y=%f, headDirection.z=%f\n",headDirection.x,headDirection.y,headDirection.z);
|
||||
|
||||
glm::vec3 cameraUp = myCamera.getOrientation().getUp() * glm::vec3(1,1,-1);
|
||||
glm::vec3 headUp = myAvatar.getHeadLookatDirectionUp();
|
||||
printf("\nUp:\n");
|
||||
printf("cameraUp.x=%f, cameraUp.y=%f, cameraUp.z=%f\n",cameraUp.x,cameraUp.y,cameraUp.z);
|
||||
printf("headUp.x=%f, headUp.y=%f, headUp.z=%f\n",headUp.x,headUp.y,headUp.z);
|
||||
|
||||
glm::vec3 cameraRight = myCamera.getOrientation().getRight() * glm::vec3(1,-1,1);
|
||||
glm::vec3 headRight = myAvatar.getHeadLookatDirectionRight();
|
||||
printf("\nRight:\n");
|
||||
printf("cameraRight.x=%f, cameraRight.y=%f, cameraRight.z=%f\n",cameraRight.x,cameraRight.y,cameraRight.z);
|
||||
printf("headRight.x=%f, headRight.y=%f, headRight.z=%f\n",headRight.x,headRight.y,headRight.z);
|
||||
|
||||
glm::vec3 viewFrustumPosition;
|
||||
glm::vec3 viewFrustumDirection;
|
||||
glm::vec3 up;
|
||||
glm::vec3 right;
|
||||
|
||||
// Camera or Head?
|
||||
if (::cameraFrustum) {
|
||||
viewFrustumPosition = cameraPosition;
|
||||
viewFrustumDirection = cameraDirection;
|
||||
up = cameraUp;
|
||||
right = cameraRight;
|
||||
} else {
|
||||
viewFrustumPosition = headPosition;
|
||||
viewFrustumDirection = headDirection;
|
||||
up = headUp;
|
||||
right = headRight;
|
||||
}
|
||||
|
||||
glm::vec3 up = myAvatar.getHeadLookatDirectionUp();
|
||||
glm::vec3 right = myAvatar.getHeadLookatDirectionRight();
|
||||
|
||||
// what? this are negative?? GRRRR!!!
|
||||
float nearDist = -0.1;
|
||||
|
@ -569,9 +602,21 @@ void render_view_frustum() {
|
|||
// Get ready to draw some lines
|
||||
glDisable(GL_LIGHTING);
|
||||
glColor4f(1.0, 1.0, 1.0, 1.0);
|
||||
glLineWidth(1.0);
|
||||
glBegin(GL_LINES);
|
||||
|
||||
glLineWidth(3.0);
|
||||
glColor3f(1,1,1);
|
||||
glm::vec3 headLookingAt = headPosition+(headDirection*-2.0);
|
||||
glVertex3f(headPosition.x,headPosition.y,headPosition.z);
|
||||
glVertex3f(headLookingAt.x,headLookingAt.y,headLookingAt.z);
|
||||
|
||||
glColor3f(1,1,1);
|
||||
glm::vec3 cameraLookingAt = cameraPosition+(cameraDirection*-2.0);
|
||||
glVertex3f(cameraPosition.x,cameraPosition.y,cameraPosition.z);
|
||||
glVertex3f(cameraLookingAt.x,cameraLookingAt.y,cameraLookingAt.z);
|
||||
|
||||
// The remaining lines are skinny
|
||||
glLineWidth(1.0);
|
||||
// near plane - bottom edge
|
||||
glColor3f(1,0,0);
|
||||
glVertex3f(nearBottomLeft.x,nearBottomLeft.y,nearBottomLeft.z);
|
||||
|
@ -660,7 +705,7 @@ void display(void)
|
|||
//--------------------------------------------------------
|
||||
// camera settings
|
||||
//--------------------------------------------------------
|
||||
myCamera.setTargetPosition( myAvatar.getPos() );
|
||||
myCamera.setTargetPosition( myAvatar.getPos() );
|
||||
|
||||
if ( displayHead ) {
|
||||
//-----------------------------------------------
|
||||
|
@ -669,42 +714,59 @@ void display(void)
|
|||
myCamera.setYaw ( - myAvatar.getBodyYaw() );
|
||||
myCamera.setPitch ( 0.0 );
|
||||
myCamera.setRoll ( 0.0 );
|
||||
myCamera.setUp ( 0.4 );
|
||||
myCamera.setDistance( 0.5 );
|
||||
myCamera.setDistance( 0.08 );
|
||||
myCamera.setUp ( 0.4 );
|
||||
myCamera.setDistance( 0.03 );
|
||||
myCamera.update();
|
||||
} else {
|
||||
if (::viewFrustumFromOffset && ::frustumOn) {
|
||||
//----------------------------------------------------
|
||||
// set the camera to third-person view but offset so we can see the frustum
|
||||
//----------------------------------------------------
|
||||
myCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() + ::viewFrustumOffsetYaw );
|
||||
myCamera.setPitch ( 0.0 + ::viewFrustumOffsetPitch );
|
||||
myCamera.setRoll ( 0.0 + ::viewFrustumOffsetRoll );
|
||||
myCamera.setUp ( 0.2 + 0.2 );
|
||||
myCamera.setDistance( 0.5 + 0.2 );
|
||||
myCamera.update();
|
||||
} else {
|
||||
//----------------------------------------------------
|
||||
// set the camera to third-person view behind my av
|
||||
//----------------------------------------------------
|
||||
myCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() );
|
||||
myCamera.setPitch ( 0.0 );
|
||||
myCamera.setRoll ( 0.0 );
|
||||
myCamera.setUp ( 0.2 );
|
||||
myCamera.setDistance( 1.6 );
|
||||
myCamera.setDistance( 0.5 );
|
||||
myCamera.update();
|
||||
}
|
||||
//----------------------------------------------------
|
||||
// set the camera to third-person view behind my av
|
||||
//----------------------------------------------------
|
||||
myCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() );
|
||||
myCamera.setPitch ( 0.0 );
|
||||
myCamera.setRoll ( 0.0 );
|
||||
myCamera.setUp ( 0.2 );
|
||||
myCamera.setDistance( 1.6 );
|
||||
myCamera.setDistance( 0.5 );
|
||||
myCamera.update();
|
||||
}
|
||||
// Note: whichCamera is used to pick between the normal camera myCamera for our
|
||||
// main camera, vs, an alternate camera. The alternate camera we support right now
|
||||
// is the viewFrustumOffsetCamera. But theoretically, we could use this same mechanism
|
||||
// to add other cameras.
|
||||
//
|
||||
// Why have two cameras? Well, one reason is that because in the case of the render_view_frustum()
|
||||
// code, we want to keep the state of "myCamera" intact, so we can render what the view frustum of
|
||||
// myCamera is. But we also want to do meaningful camera transforms on OpenGL for the offset camera
|
||||
Camera whichCamera = myCamera;
|
||||
Camera viewFrustumOffsetCamera = myCamera;
|
||||
|
||||
if (::viewFrustumFromOffset && ::frustumOn) {
|
||||
//----------------------------------------------------
|
||||
// set the camera to third-person view but offset so we can see the frustum
|
||||
//----------------------------------------------------
|
||||
viewFrustumOffsetCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() + ::viewFrustumOffsetYaw );
|
||||
viewFrustumOffsetCamera.setPitch ( 0.0 + ::viewFrustumOffsetPitch );
|
||||
viewFrustumOffsetCamera.setRoll ( 0.0 + ::viewFrustumOffsetRoll );
|
||||
viewFrustumOffsetCamera.setUp ( 0.2 + 0.2 );
|
||||
viewFrustumOffsetCamera.setDistance( 0.5 + 0.2 );
|
||||
viewFrustumOffsetCamera.update();
|
||||
|
||||
whichCamera = viewFrustumOffsetCamera;
|
||||
}
|
||||
|
||||
//---------------------------------------------
|
||||
// transform view according to myCamera
|
||||
//---------------------------------------------
|
||||
glRotatef ( myCamera.getPitch(), 1, 0, 0 );
|
||||
glRotatef ( myCamera.getYaw(), 0, 1, 0 );
|
||||
glRotatef ( myCamera.getRoll(), 0, 0, 1 );
|
||||
glTranslatef( myCamera.getPosition().x, myCamera.getPosition().y, myCamera.getPosition().z );
|
||||
glTranslatef( -myCamera.getPosition().x, -myCamera.getPosition().y, -myCamera.getPosition().z );
|
||||
/*
|
||||
glRotatef ( whichCamera.getPitch(), 1, 0, 0 );
|
||||
glRotatef ( whichCamera.getYaw(), 0, 1, 0 );
|
||||
glRotatef ( whichCamera.getRoll(), 0, 0, 1 );
|
||||
glTranslatef( whichCamera.getPosition().x, whichCamera.getPosition().y, whichCamera.getPosition().z );
|
||||
*/
|
||||
|
||||
if (::starsOn) {
|
||||
// should be the first rendering pass - w/o depth buffer / lighting
|
||||
|
@ -1057,6 +1119,7 @@ void key(unsigned char k, int x, int y)
|
|||
if (k == '*') ::starsOn = !::starsOn; // toggle stars
|
||||
if (k == 'V') ::showingVoxels = !::showingVoxels; // toggle voxels
|
||||
if (k == 'F') ::frustumOn = !::frustumOn; // toggle view frustum debugging
|
||||
if (k == 'C') ::cameraFrustum = !::cameraFrustum; // toggle which frustum to look at
|
||||
if (k == 'G') ::viewFrustumFromOffset = !::viewFrustumFromOffset; // toggle view frustum from offset debugging
|
||||
|
||||
if (k == '[') ::viewFrustumOffsetYaw -= 0.5;
|
||||
|
|
Loading…
Reference in a new issue