more work on avatar touch, reachable radius, and hand states

This commit is contained in:
Jeffrey Ventrella 2013-05-06 18:29:20 -07:00
parent 9c1f163175
commit 22a0e39d6c
8 changed files with 116 additions and 76 deletions

View file

@ -34,10 +34,6 @@ const float BODY_ROLL_WHILE_TURNING = 0.1;
const float LIN_VEL_DECAY = 5.0;
const float MY_HAND_HOLDING_PULL = 0.2;
const float YOUR_HAND_HOLDING_PULL = 1.0;
//const float BODY_SPRING_DEFAULT_TIGHTNESS = 20.0f;
//const float BODY_SPRING_FORCE = 6.0f;
const float BODY_SPRING_DEFAULT_TIGHTNESS = 1500.0f;
const float BODY_SPRING_FORCE = 300.0f;
@ -144,14 +140,13 @@ Avatar::Avatar(bool isMine) {
_renderYaw = 0.0;
_renderPitch = 0.0;
_sphere = NULL;
//_interactingOther = NULL;
_handHoldingPosition = glm::vec3(0.0f, 0.0f, 0.0f);
_distanceToNearestAvatar = std::numeric_limits<float>::max();
_gravity = glm::vec3(0.0f, -1.0f, 0.0f); // default
initializeSkeleton();
_avatarTouch.setReachableRadius(0.4);
_avatarTouch.setReachableRadius(0.6);
if (iris_texture.size() == 0) {
switchToResourcesParentIfRequired();
@ -317,8 +312,8 @@ void Avatar::setLeanSideways(float dist){
_head.leanSideways = dist;
}
void Avatar::setMousePressed(bool d) {
_mousePressed = d;
void Avatar::setMousePressed( bool mousePressed ) {
_mousePressed = mousePressed;
}
bool Avatar::getIsNearInteractingOther() {
@ -435,7 +430,6 @@ void Avatar::simulate(float deltaTime) {
}
void Avatar::updateHandMovementAndTouching(float deltaTime) {
// reset hand and arm positions according to hand movement
@ -472,6 +466,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) {
if (_interactingOther) {
_avatarTouch.setYourBodyPosition(_interactingOther->_position);
_avatarTouch.setYourHandPosition(_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].springyPosition);
_avatarTouch.setYourHandState (_interactingOther->_handState);
}
}//if (_isMine)
@ -483,7 +478,12 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) {
if (_isMine) {
//Set the vector we send for hand position to other people to be our right hand
setHandPosition(_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position);
_handState = _mousePressed;
if ( _mousePressed ) {
_handState = 1;
} else {
_handState = 0;
}
_avatarTouch.setMyHandState(_handState);
@ -493,7 +493,6 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) {
}
}
void Avatar::updateHead(float deltaTime) {
//apply the head lean values to the springy position...
@ -753,7 +752,7 @@ void Avatar::setGravity(glm::vec3 gravity) {
}
void Avatar::render(bool lookingInMirror) {
void Avatar::render(bool lookingInMirror, glm::vec3 cameraPosition) {
// render a simple round on the ground projected down from the avatar's position
renderDiskShadow(_position, glm::vec3(0.0f, 1.0f, 0.0f ), 0.1f, 0.2f );
@ -788,7 +787,7 @@ void Avatar::render(bool lookingInMirror) {
// if this is my avatar, then render my interactions with the other avatar
if (_isMine ) {
_avatarTouch.render();
_avatarTouch.render(cameraPosition);
}
// Render the balls

View file

@ -101,13 +101,6 @@ public:
void setLeanForward(float dist);
void setLeanSideways(float dist);
void addLean(float x, float z);
/*
const glm::vec3& getHeadRightDirection() const { return _orientation.getRight(); };
const glm::vec3& getHeadUpDirection () const { return _orientation.getUp (); };
const glm::vec3& getHeadFrontDirection() const { return _orientation.getFront(); };
*/
const glm::vec3& getHeadPosition() const ;
const glm::vec3& getJointPosition(AvatarJointID j) const { return _joint[j].position; };
const glm::vec3& getBodyUpDirection() const { return _orientation.getUp(); };
@ -117,8 +110,8 @@ public:
AvatarMode getMode();
void setMousePressed( bool pressed );
void render(bool lookingInMirror);
void setMousePressed(bool pressed);
void render(bool lookingInMirrorm, glm::vec3 cameraPosition);
void renderBody();
void renderHead(bool lookingInMirror);
void simulate(float);
@ -241,7 +234,6 @@ private:
float _transmitterHz;
int _transmitterPackets;
glm::vec3 _transmitterInitialReading;
//Avatar* _interactingOther;
float _pelvisStandingHeight;
float _height;
Balls* _balls;

View file

@ -11,6 +11,19 @@
#include "AvatarRenderer.h"
#include "InterfaceConfig.h"
#include <glm/glm.hpp>
#include <vector>
#include <lodepng.h>
#include <SharedUtil.h>
#include "Avatar.h"
#include "Log.h"
#include "ui/TextRenderer.h"
#include <AgentList.h>
#include <AgentTypes.h>
#include <PacketHeaders.h>
AvatarRenderer::AvatarRenderer() {
}

View file

@ -10,6 +10,7 @@
#include <SharedUtil.h>
#include "AvatarTouch.h"
#include "InterfaceConfig.h"
#include "Util.h"
const float THREAD_RADIUS = 0.012;
@ -59,14 +60,16 @@ void AvatarTouch::setReachableRadius( float r ) {
_reachableRadius = r;
}
void AvatarTouch::render() {
void AvatarTouch::render(glm::vec3 cameraPosition) {
if (_canReachToOtherAvatar) {
glPushMatrix();
glTranslatef(_yourBodyPosition.x, _yourBodyPosition.y, _yourBodyPosition.z);
glColor4f( 0.3, 0.4, 0.5, 0.3 ); glutSolidSphere( _reachableRadius, 30.0f, 30.0f );
glPopMatrix();
glColor4f( 0.3, 0.4, 0.5, 0.5 );
glm::vec3 p(_yourBodyPosition);
p.y = 0.0005f;
renderCircle(p, _reachableRadius, glm::vec3(0.0f, 1.0f, 0.0f), 30);
// if your hand is grasping, show it...
if ( _yourHandState == 1 ) {
glPushMatrix();
@ -76,6 +79,27 @@ void AvatarTouch::render() {
glColor4f( 1.0, 1.0, 0.2, 0.1 ); glutSolidSphere( 0.030f, 10.0f, 10.0f );
glPopMatrix();
}
//show beam
glm::vec3 v1( _myHandPosition );
glm::vec3 v2( _yourHandPosition );
if (_handsCloseEnoughToGrasp) {
glLineWidth( 2.0 );
glColor4f( 0.7f, 0.4f, 0.1f, 0.3 );
glBegin( GL_LINE_STRIP );
glVertex3f( v1.x, v1.y, v1.z );
glVertex3f( v2.x, v2.y, v2.z );
glEnd();
glColor4f( 1.0f, 1.0f, 0.0f, 0.8 );
for (int p=0; p<NUM_POINTS; p++) {
glBegin(GL_POINTS);
glVertex3f(_point[p].x, _point[p].y, _point[p].z);
glEnd();
}
}
}
// if my hand is grasping, show it...
@ -87,31 +111,6 @@ void AvatarTouch::render() {
glColor4f( 1.0, 1.0, 0.2, 0.1 ); glutSolidSphere( 0.030f, 10.0f, 10.0f );
glPopMatrix();
}
/*
//show beam
glm::vec3 v1( _myHandPosition );
glm::vec3 v2( _yourHandPosition );
if (_handsCloseEnoughToGrasp) {
glLineWidth( 2.0 );
glColor4f( 0.7f, 0.4f, 0.1f, 0.3 );
glBegin( GL_LINE_STRIP );
glVertex3f( v1.x, v1.y, v1.z );
glVertex3f( v2.x, v2.y, v2.z );
glEnd();
glColor4f( 1.0f, 1.0f, 0.0f, 0.8 );
for (int p=0; p<NUM_POINTS; p++) {
glBegin(GL_POINTS);
glVertex3f(_point[p].x, _point[p].y, _point[p].z);
glEnd();
}
}
*/
}
@ -121,7 +120,7 @@ void AvatarTouch::simulate (float deltaTime) {
float distance = glm::length(v);
if (distance < _reachableRadius * 2.3f ) {
if (distance < _reachableRadius ) {
_canReachToOtherAvatar = true;
} else {
_canReachToOtherAvatar = false;

View file

@ -19,7 +19,7 @@ public:
AvatarTouch();
void simulate(float deltaTime);
void render();
void render(glm::vec3 cameraPosition);
void setMyHandPosition (glm::vec3 position);
void setYourHandPosition(glm::vec3 position);

View file

@ -185,9 +185,7 @@ void drawtext(int x, int y, float scale, float rotate, float thick, int mono,
}
void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, glm::vec3 vec,
float r, float g, float b)
{
void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, glm::vec3 vec, float r, float g, float b) {
//
// Draws text on screen as stroked so it can be resized
//
@ -202,18 +200,14 @@ void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, gl
glLineWidth(thick);
glScalef(scale, scale, 1.0);
len = (int) strlen(vectext);
for (i = 0; i < len; i++)
{
for (i = 0; i < len; i++) {
if (!mono) glutStrokeCharacter(GLUT_STROKE_ROMAN, int(vectext[i]));
else glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN, int(vectext[i]));
}
glPopMatrix();
}
void drawGroundPlaneGrid(float size)
{
void drawGroundPlaneGrid(float size) {
glColor3f( 0.4f, 0.5f, 0.3f );
glLineWidth(2.0);
@ -267,6 +261,51 @@ void renderDiskShadow(glm::vec3 position, glm::vec3 upDirection, float radius, f
}
void renderSphereOutline(glm::vec3 position, float radius, int numSides, glm::vec3 cameraPosition) {
glm::vec3 vectorToPosition(glm::normalize(position - cameraPosition));
glm::vec3 right = glm::cross(vectorToPosition, glm::vec3( 0.0f, 1.0f, 0.0f));
glm::vec3 up = glm::cross(right, vectorToPosition);
glBegin(GL_LINE_STRIP);
for (int i=0; i<numSides+1; i++) {
float r = ((float)i / (float)numSides) * PI * 2.0;
float s = radius * sin(r);
float c = radius * cos(r);
glVertex3f
(
position.x + right.x * s + up.x * c,
position.y + right.y * s + up.y * c,
position.z + right.z * s + up.z * c
);
}
glEnd();
}
void renderCircle(glm::vec3 position, float radius, glm::vec3 surfaceNormal, int numSides ) {
glm::vec3 perp1 = glm::vec3(surfaceNormal.y, surfaceNormal.z, surfaceNormal.x);
glm::vec3 perp2 = glm::vec3(surfaceNormal.z, surfaceNormal.x, surfaceNormal.y);
glBegin(GL_LINE_STRIP);
for (int i=0; i<numSides+1; i++) {
float r = ((float)i / (float)numSides) * PI * 2.0;
float s = radius * sin(r);
float c = radius * cos(r);
glVertex3f
(
position.x + perp1.x * s + perp2.x * c,
position.y + perp1.y * s + perp2.y * c,
position.z + perp1.z * s + perp2.z * c
);
}
glEnd();
}
void renderOrientationDirections( glm::vec3 position, Orientation orientation, float size ) {
glm::vec3 pRight = position + orientation.getRight() * size;
glm::vec3 pUp = position + orientation.getUp() * size;

View file

@ -48,6 +48,9 @@ void renderDiskShadow(glm::vec3 position, glm::vec3 upDirection, float radius, f
void renderOrientationDirections( glm::vec3 position, Orientation orientation, float size );
void renderSphereOutline(glm::vec3 position, float radius, int numSides, glm::vec3 cameraPosition);
void renderCircle(glm::vec3 position, float radius, glm::vec3 surfaceNormal, int numSides );
class oTestCase {
public:

View file

@ -711,7 +711,7 @@ void displaySide(Camera& whichCamera) {
for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) {
if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) {
Avatar *avatar = (Avatar *)agent->getLinkedData();
avatar->render(0);
avatar->render(0, ::myCamera.getPosition());
}
}
agentList->unlock();
@ -723,7 +723,7 @@ void displaySide(Camera& whichCamera) {
if (::frustumOn) renderViewFrustum(::viewFrustum);
//Render my own avatar
myAvatar.render(::lookingInMirror);
myAvatar.render(::lookingInMirror, ::myCamera.getPosition());
glPopMatrix();
}
@ -1671,15 +1671,10 @@ void idle(void) {
myAvatar.setHandMovementValues( handControl.getValues() );
// tell my avatar if the mouse is being pressed...
myAvatar.setMousePressed(mousePressed);
/*
if ( mousePressed == 1 ) {
myAvatar.setMousePressed( true );
} else {
myAvatar.setMousePressed( false );
}
*/
if ( mousePressed) {
myAvatar.setMousePressed(mousePressed);
}
// walking triggers the handControl to stop
if ( myAvatar.getMode() == AVATAR_MODE_WALKING ) {
handControl.stop();