mirror of
https://github.com/overte-org/overte.git
synced 2025-04-23 18:13:29 +02:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
6a5f1ac73e
6 changed files with 116 additions and 263 deletions
|
@ -89,6 +89,10 @@ Head::Head()
|
|||
movedHandOffset = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
|
||||
sphere = NULL;
|
||||
|
||||
springForce = 6.0f;
|
||||
springToBodyTightness = 2.0f;
|
||||
springVelocityDecay = 5.0f;
|
||||
|
||||
hand = new Hand(glm::vec3(skinColor[0], skinColor[1], skinColor[2]));
|
||||
|
||||
|
@ -279,6 +283,12 @@ void Head::setLeanSideways(float dist){
|
|||
void Head::simulate(float deltaTime)
|
||||
{
|
||||
updateAvatarSkeleton();
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// update springy behavior:
|
||||
//------------------------------------------------------------------------
|
||||
updateAvatarSprings( deltaTime );
|
||||
|
||||
|
||||
/*
|
||||
glm::vec3 forward
|
||||
|
@ -303,32 +313,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().getX(), avatar.orientation.getFront().getY(), -avatar.orientation.getFront().getZ() );
|
||||
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().getX(), avatar.orientation.getFront().getY(), -avatar.orientation.getFront().getZ() );
|
||||
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().getX(), avatar.orientation.getRight().getY(), -avatar.orientation.getRight().getZ() );
|
||||
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().getX(), avatar.orientation.getRight().getY(), -avatar.orientation.getRight().getZ() );
|
||||
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().getX(), avatar.orientation.getUp().getY(), -avatar.orientation.getUp().getZ() );
|
||||
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().getX(), avatar.orientation.getUp().getY(), -avatar.orientation.getUp().getZ() );
|
||||
glm::vec3 up( avatar.orientation.getUp().x, avatar.orientation.getUp().y, -avatar.orientation.getUp().z );
|
||||
avatar.thrust -= up * THRUST_MAG;
|
||||
}
|
||||
|
||||
|
@ -851,12 +861,6 @@ void Head::updateAvatarSkeleton()
|
|||
avatar.bone[b].position += rotatedBoneVector;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// update springy behavior:
|
||||
//------------------------------------------------------------------------
|
||||
updateAvatarSprings();
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// reset hand and elbow position according to hand movement
|
||||
//------------------------------------------------------------------------
|
||||
|
@ -866,6 +870,7 @@ void Head::updateAvatarSkeleton()
|
|||
handBeingMoved = false;
|
||||
}
|
||||
|
||||
/*
|
||||
glm::dvec3 v( avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position );
|
||||
v -= avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position;
|
||||
|
||||
|
@ -874,53 +879,50 @@ void Head::updateAvatarSkeleton()
|
|||
{
|
||||
avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position += v * 0.2;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//------------------------------
|
||||
void Head::updateAvatarSprings()
|
||||
//-----------------------------------------------
|
||||
void Head::updateAvatarSprings( float deltaTime )
|
||||
{
|
||||
//printf( "listing bone parent springyPosition:\n" );
|
||||
|
||||
for (int b=0; b<NUM_AVATAR_BONES; b++)
|
||||
{
|
||||
/*
|
||||
printf
|
||||
(
|
||||
"bone %d: %f, %f, %f\n", b,
|
||||
avatar.bone[ avatar.bone[b].parent ].springyPosition.x,
|
||||
avatar.bone[ avatar.bone[b].parent ].springyPosition.y,
|
||||
avatar.bone[ avatar.bone[b].parent ].springyPosition.z
|
||||
);
|
||||
*/
|
||||
|
||||
glm::vec3 springVector( avatar.bone[b].springyPosition );
|
||||
|
||||
if ( avatar.bone[b].parent == AVATAR_BONE_NULL )
|
||||
{
|
||||
springVector -= avatar.position;
|
||||
}
|
||||
else if ( avatar.bone[b].parent == AVATAR_BONE_PELVIS_SPINE )
|
||||
{
|
||||
springVector -= avatar.position;
|
||||
}
|
||||
else
|
||||
{
|
||||
springVector -= avatar.bone[ avatar.bone[b].parent ].springyPosition;
|
||||
float length = glm::length( springVector );
|
||||
|
||||
if ( length > 0.0f )
|
||||
{
|
||||
glm::vec3 springDirection = springVector / length;
|
||||
|
||||
float force = ( length - avatar.bone[b].length ) * 0.01;
|
||||
|
||||
avatar.bone[ b ].springyVelocity -= springDirection * force;
|
||||
avatar.bone[ avatar.bone[b].parent ].springyVelocity += springDirection * force;
|
||||
}
|
||||
|
||||
avatar.bone[b].springyVelocity += ( avatar.bone[b].position - avatar.bone[b].springyPosition ) * 0.01f;
|
||||
avatar.bone[b].springyVelocity *= 0.8;
|
||||
avatar.bone[b].springyPosition += avatar.bone[b].springyVelocity;
|
||||
}
|
||||
|
||||
float length = glm::length( springVector );
|
||||
|
||||
if ( length > 0.0f )
|
||||
{
|
||||
glm::vec3 springDirection = springVector / length;
|
||||
|
||||
float force = ( length - avatar.bone[b].length ) * springForce * deltaTime;
|
||||
|
||||
avatar.bone[ b ].springyVelocity -= springDirection * force;
|
||||
avatar.bone[ avatar.bone[b].parent ].springyVelocity += springDirection * force;
|
||||
}
|
||||
|
||||
avatar.bone[b].springyVelocity += ( avatar.bone[b].position - avatar.bone[b].springyPosition ) * springToBodyTightness * deltaTime;
|
||||
avatar.bone[b].springyVelocity *= 0.8;
|
||||
|
||||
avatar.bone[b].springyVelocity *= ( 1.0 - springVelocityDecay * deltaTime );
|
||||
|
||||
avatar.bone[b].springyPosition += avatar.bone[b].springyVelocity;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -243,6 +243,10 @@ class Head : public AgentData {
|
|||
//glm::vec3 movedHandPosition;
|
||||
|
||||
int driveKeys[MAX_DRIVE_KEYS];
|
||||
|
||||
float springVelocityDecay;
|
||||
float springForce;
|
||||
float springToBodyTightness;
|
||||
|
||||
int eyeContact;
|
||||
eyeContactTargets eyeContactTarget;
|
||||
|
@ -252,7 +256,7 @@ class Head : public AgentData {
|
|||
|
||||
void initializeAvatar();
|
||||
void updateAvatarSkeleton();
|
||||
void updateAvatarSprings();
|
||||
void updateAvatarSprings( float deltaTime );
|
||||
void calculateBoneLengths();
|
||||
|
||||
void readSensors();
|
||||
|
|
|
@ -108,7 +108,7 @@ int MenuColumn::getLeftPosition() {
|
|||
return leftPosition;
|
||||
}
|
||||
|
||||
int MenuColumn::addRow(const char * rowName, MenuRowCallback callback) {
|
||||
int MenuColumn::addRow(const char* rowName, MenuRowCallback callback) {
|
||||
MenuRow* row;
|
||||
row = new MenuRow(rowName, callback);
|
||||
rows.push_back(*row);
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
int getLeftPosition();
|
||||
void render(int yOffset, int menuHeight, int lineHeight);
|
||||
void renderMouseOver(int yOffset);
|
||||
int addRow(const char * rowName, MenuRowCallback callback);
|
||||
int addRow(const char* rowName, MenuRowCallback callback);
|
||||
private:
|
||||
char columnName[MAX_COLUMN_NAME];
|
||||
int columnWidth;
|
||||
|
|
|
@ -1,232 +1,82 @@
|
|||
//-----------------------------------------------------------
|
||||
//
|
||||
// Created by Jeffrey Ventrella and added as a utility
|
||||
// class for High Fidelity Code base, April 2013
|
||||
//
|
||||
//-----------------------------------------------------------
|
||||
|
||||
#include "Orientation.h"
|
||||
#include "Vector3D.h"
|
||||
#include "Util.h"
|
||||
|
||||
//------------------------
|
||||
Orientation::Orientation()
|
||||
{
|
||||
right.setXYZ ( 1.0, 0.0, 0.0 );
|
||||
up.setXYZ ( 0.0, 1.0, 0.0 );
|
||||
front.setXYZ ( 0.0, 0.0, 1.0 );
|
||||
right = glm::vec3( 1.0, 0.0, 0.0 );
|
||||
up = glm::vec3( 0.0, 1.0, 0.0 );
|
||||
front = glm::vec3( 0.0, 0.0, 1.0 );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------
|
||||
//-------------------------------
|
||||
void Orientation::setToIdentity()
|
||||
{
|
||||
right.setXYZ ( 1.0, 0.0, 0.0 );
|
||||
up.setXYZ ( 0.0, 1.0, 0.0 );
|
||||
front.setXYZ ( 0.0, 0.0, 1.0 );
|
||||
right = glm::vec3( 1.0, 0.0, 0.0 );
|
||||
up = glm::vec3( 0.0, 1.0, 0.0 );
|
||||
front = glm::vec3( 0.0, 0.0, 1.0 );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------
|
||||
void Orientation::set( Orientation o )
|
||||
{
|
||||
right.set ( o.getRight() );
|
||||
up.set ( o.getUp () );
|
||||
front.set ( o.getFront() );
|
||||
right = o.getRight();
|
||||
up = o.getUp();
|
||||
front = o.getFront();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
void Orientation::forceAxisInDirection( int whichAxis, const Vector3D &direction, double forceAmount )
|
||||
{
|
||||
Vector3D diff;
|
||||
|
||||
if ( whichAxis == ORIENTATION_RIGHT_AXIS )
|
||||
{
|
||||
diff.setToDifference( direction, right );
|
||||
right.addScaled( diff, forceAmount );
|
||||
right.normalize();
|
||||
up.setToCross( front, right );
|
||||
up.normalize();
|
||||
front.setToCross( right, up );
|
||||
}
|
||||
else if ( whichAxis == ORIENTATION_UP_AXIS )
|
||||
{
|
||||
diff.setToDifference( direction, up );
|
||||
up.addScaled( diff, forceAmount );
|
||||
up.normalize();
|
||||
front.setToCross( right, up );
|
||||
front.normalize();
|
||||
right.setToCross( up, front );
|
||||
}
|
||||
else if ( whichAxis == ORIENTATION_FRONT_AXIS )
|
||||
{
|
||||
diff.setToDifference( direction, front );
|
||||
front.addScaled( diff, forceAmount );
|
||||
front.normalize();
|
||||
right.setToCross( up, front );
|
||||
right.normalize();
|
||||
up.setToCross( front, right );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------------------
|
||||
void Orientation::forceFrontInDirection( const Vector3D &direction, const Vector3D &upDirection, double forceAmount )
|
||||
{
|
||||
Vector3D diff;
|
||||
diff.setToDifference( direction, front );
|
||||
front.addScaled( diff, forceAmount );
|
||||
front.normalize();
|
||||
right.setToCross( upDirection, front );
|
||||
right.normalize();
|
||||
up.setToCross( front, right );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//---------------------------------------
|
||||
void Orientation::yaw( double angle )
|
||||
void Orientation::yaw( float angle )
|
||||
{
|
||||
float r = angle * PI_OVER_180;
|
||||
float s = sin( r );
|
||||
float c = cos( r );
|
||||
|
||||
glm::vec3 cosineFront = front * c;
|
||||
glm::vec3 cosineRight = right * c;
|
||||
glm::vec3 sineFront = front * s;
|
||||
glm::vec3 sineRight = right * s;
|
||||
|
||||
front = cosineFront + sineRight;
|
||||
right = cosineRight - sineFront;
|
||||
}
|
||||
|
||||
//---------------------------------------
|
||||
void Orientation::pitch( float angle )
|
||||
{
|
||||
float r = angle * PI_OVER_180;
|
||||
float s = sin( r );
|
||||
float c = cos( r );
|
||||
|
||||
glm::vec3 cosineUp = up * c;
|
||||
glm::vec3 cosineFront = front * c;
|
||||
glm::vec3 sineUp = up * s;
|
||||
glm::vec3 sineFront = front * s;
|
||||
|
||||
up = cosineUp + sineFront;
|
||||
front = cosineFront - sineUp;
|
||||
}
|
||||
|
||||
//---------------------------------------
|
||||
void Orientation::roll( float angle )
|
||||
{
|
||||
double r = angle * PI_OVER_180;
|
||||
double s = sin( r );
|
||||
double c = cos( r );
|
||||
|
||||
Vector3D cosineFront;
|
||||
Vector3D cosineRight;
|
||||
Vector3D sineFront;
|
||||
Vector3D sineRight;
|
||||
glm::vec3 cosineUp = up * c;
|
||||
glm::vec3 cosineRight = right * c;
|
||||
glm::vec3 sineUp = up * s;
|
||||
glm::vec3 sineRight = right * s;
|
||||
|
||||
cosineFront.setToScaled ( front, c );
|
||||
cosineRight.setToScaled ( right, c );
|
||||
sineFront.setToScaled ( front, s );
|
||||
sineRight.setToScaled ( right, s );
|
||||
|
||||
front.set( cosineFront );
|
||||
front.add( sineRight );
|
||||
|
||||
right.set( cosineRight );
|
||||
right.subtract( sineFront );
|
||||
up = cosineUp + sineRight;
|
||||
right = cosineRight - sineUp;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------
|
||||
void Orientation::pitch( double angle )
|
||||
//---------------------------------------------------------------------------------------------
|
||||
void Orientation::setRightUpFront( const glm::vec3 &r, const glm::vec3 &u, const glm::vec3 &f )
|
||||
{
|
||||
double r = angle * PI_OVER_180;
|
||||
double s = sin( r );
|
||||
double c = cos( r );
|
||||
|
||||
Vector3D cosineUp;
|
||||
Vector3D cosineFront;
|
||||
Vector3D sineUp;
|
||||
Vector3D sineFront;
|
||||
|
||||
cosineUp.setToScaled ( up, c );
|
||||
cosineFront.setToScaled ( front, c );
|
||||
sineUp.setToScaled ( up, s );
|
||||
sineFront.setToScaled ( front, s );
|
||||
|
||||
up.set( cosineUp );
|
||||
up.add( sineFront );
|
||||
|
||||
front.set( cosineFront );
|
||||
front.subtract( sineUp );
|
||||
right = r;
|
||||
up = u;
|
||||
front = f;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------
|
||||
void Orientation::roll( double angle )
|
||||
{
|
||||
double r = angle * PI_OVER_180;
|
||||
double s = sin( r );
|
||||
double c = cos( r );
|
||||
|
||||
Vector3D cosineUp;
|
||||
Vector3D cosineRight;
|
||||
Vector3D sineUp;
|
||||
Vector3D sineRight;
|
||||
|
||||
cosineUp.setToScaled ( up, c );
|
||||
cosineRight.setToScaled ( right, c );
|
||||
sineUp.setToScaled ( up, s );
|
||||
sineRight.setToScaled ( right, s );
|
||||
|
||||
up.set( cosineUp );
|
||||
up.add( sineRight );
|
||||
|
||||
right.set( cosineRight );
|
||||
right.subtract( sineUp );
|
||||
}
|
||||
|
||||
|
||||
Vector3D Orientation::getRight () { return right; }
|
||||
Vector3D Orientation::getUp () { return up; }
|
||||
Vector3D Orientation::getFront () { return front; }
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void Orientation::setRightUpFront( const Vector3D &r, const Vector3D &u, const Vector3D &f )
|
||||
{
|
||||
//verifyValidOrientation();
|
||||
|
||||
right.set (r);
|
||||
up.set (u);
|
||||
front.set (f);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void Orientation::verifyValidOrientation()
|
||||
{
|
||||
assert( right.getMagnitude () < 1.0 + CENTIMETER );
|
||||
assert( right.getMagnitude () > 1.0 - CENTIMETER );
|
||||
assert( up.getMagnitude () < 1.0 + CENTIMETER );
|
||||
assert( up.getMagnitude () > 1.0 - CENTIMETER );
|
||||
assert( front.getMagnitude () < 1.0 + CENTIMETER );
|
||||
assert( front.getMagnitude () > 1.0 - CENTIMETER );
|
||||
|
||||
if ( right.getMagnitude() > 1.0 + CENTIMETER )
|
||||
{
|
||||
printf( "oops: the magnitude of the 'right' part of the orientation is %f!\n", right.getMagnitude() );
|
||||
}
|
||||
else if ( right.getMagnitude() < 1.0 - CENTIMETER )
|
||||
{
|
||||
printf( "oops: the magnitude of the 'right' part of the orientation is %f!\n", right.getMagnitude() );
|
||||
}
|
||||
|
||||
|
||||
if ( up.getMagnitude() > 1.0 + CENTIMETER )
|
||||
{
|
||||
printf( "oops: the magnitude of the 'up' part of the orientation is %f!\n", up.getMagnitude() );
|
||||
}
|
||||
else if ( up.getMagnitude() < 1.0 - CENTIMETER )
|
||||
{
|
||||
printf( "oops: the magnitude of the 'up' part of the orientation is %f!\n", up.getMagnitude() );
|
||||
}
|
||||
|
||||
|
||||
if ( front.getMagnitude() > 1.0 + CENTIMETER )
|
||||
{
|
||||
printf( "oops: the magnitude of the 'front' part of the orientation is %f!\n", front.getMagnitude() );
|
||||
}
|
||||
else if ( front.getMagnitude() < 1.0 - CENTIMETER )
|
||||
{
|
||||
printf( "oops: the magnitude of the 'front' part of the orientation is %f!\n", front.getMagnitude() );
|
||||
}
|
||||
|
||||
if (( right.dotWith ( up ) > CENTIMETER )
|
||||
|| ( right.dotWith ( up ) < -CENTIMETER )) { printf( "oops: the 'right' and 'up' parts of the orientation are not perpendicular! The dot is: %f\n", right.dotWith ( up ) ); }
|
||||
|
||||
if (( right.dotWith ( front ) > CENTIMETER )
|
||||
|| ( right.dotWith ( front ) < -CENTIMETER )) { printf( "oops: the 'right' and 'front' parts of the orientation are not perpendicular! The dot is: %f\n", right.dotWith ( front ) ); }
|
||||
|
||||
if (( up.dotWith ( front ) > CENTIMETER )
|
||||
|| ( up.dotWith ( front ) < -CENTIMETER )) { printf( "oops: the 'up' and 'front' parts of the orientation are not perpendicular! The dot is: %f\n", up.dotWith ( front ) ); }
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#define __interface__orientation__
|
||||
|
||||
#include <cmath> // with this work? "Math.h"
|
||||
#include "Vector3D.h"
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
enum Axis
|
||||
{
|
||||
|
@ -22,30 +22,27 @@ class Orientation
|
|||
{
|
||||
private:
|
||||
|
||||
Vector3D right;
|
||||
Vector3D up;
|
||||
Vector3D front;
|
||||
glm::vec3 right;
|
||||
glm::vec3 up;
|
||||
glm::vec3 front;
|
||||
|
||||
void verifyValidOrientation();
|
||||
//void verifyValidOrientation();
|
||||
|
||||
public:
|
||||
Orientation();
|
||||
|
||||
void yaw ( double );
|
||||
void pitch ( double );
|
||||
void roll ( double );
|
||||
void yaw ( float );
|
||||
void pitch ( float );
|
||||
void roll ( float );
|
||||
|
||||
void set( Orientation );
|
||||
void setToIdentity();
|
||||
|
||||
void forceFrontInDirection( const Vector3D &, const Vector3D &, double );
|
||||
void forceAxisInDirection( int, const Vector3D &, double );
|
||||
|
||||
Vector3D getRight();
|
||||
Vector3D getUp();
|
||||
Vector3D getFront();
|
||||
glm::vec3 getRight() { return right; }
|
||||
glm::vec3 getUp() { return up; }
|
||||
glm::vec3 getFront() { return front; }
|
||||
|
||||
void setRightUpFront( const Vector3D &, const Vector3D &, const Vector3D & );
|
||||
void setRightUpFront( const glm::vec3 &, const glm::vec3 &, const glm::vec3 & );
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue