From dcacad3755aa364d0557b3df8cdae47314589109 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 12 Apr 2013 10:02:41 -0700 Subject: [PATCH 1/4] Removed unneeded GLenable cruft --- interface/src/Cloud.cpp | 5 +---- interface/src/main.cpp | 2 -- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/interface/src/Cloud.cpp b/interface/src/Cloud.cpp index 5d68ecba75..ea27b40d49 100644 --- a/interface/src/Cloud.cpp +++ b/interface/src/Cloud.cpp @@ -43,20 +43,17 @@ Cloud::Cloud(int num, } } - void Cloud::render() { - + float particleAttenuationQuadratic[] = { 0.0f, 0.0f, 2.0f }; glEnable( GL_TEXTURE_2D ); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - float maxSize = 0.0f; glGetFloatv( GL_POINT_SIZE_MAX_ARB, &maxSize ); glPointSize( maxSize ); - glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, particleAttenuationQuadratic ); glPointParameterfARB( GL_POINT_SIZE_MAX_ARB, maxSize ); glPointParameterfARB( GL_POINT_SIZE_MIN_ARB, 0.001f ); diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 5b11d9e34e..0a4f06cc06 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -810,8 +810,6 @@ void display(void) // Draw cloud of dots - glDisable( GL_POINT_SPRITE_ARB ); - glDisable( GL_TEXTURE_2D ); if (!displayHead) cloud.render(); // Draw voxels From 6d7f343be83392d110445f6b463c894a9b244e6c Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 12 Apr 2013 16:13:40 -0700 Subject: [PATCH 2/4] draw a test sphere around my hand in orldspace --- interface/src/main.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index e0b5ebcd15..909227a91f 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -796,6 +796,11 @@ void display(void) glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); + // Test - Draw a blue sphere around a body part of mine! + + glPushMatrix(); + //glTranslate3f(myAvatar.GetRight + glPopMatrix(); // draw a red sphere float sphereRadius = 0.25f; From 1d69acef56729be19f2267565a1206d815fe7b44 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 12 Apr 2013 21:01:01 -0700 Subject: [PATCH 3/4] Removed hand class files, relocated transmitter receiver function to Head.h --- interface/src/Hand.cpp | 225 ----------------------------------------- interface/src/Hand.h | 47 --------- interface/src/Head.cpp | 57 +++++++++-- interface/src/Head.h | 15 ++- interface/src/main.cpp | 20 ++-- 5 files changed, 72 insertions(+), 292 deletions(-) delete mode 100644 interface/src/Hand.cpp delete mode 100644 interface/src/Hand.h diff --git a/interface/src/Hand.cpp b/interface/src/Hand.cpp deleted file mode 100644 index 4cca3017dc..0000000000 --- a/interface/src/Hand.cpp +++ /dev/null @@ -1,225 +0,0 @@ -// -// Hand.cpp -// interface -// -// Created by Philip Rosedale on 10/13/12. -// Copyright (c) 2012 High Fidelity, Inc. All rights reserved. -// - -#include "Hand.h" - -#ifdef _WIN32 -#include "Systime.h" -#else -#include -#endif - -const float PHI = 1.618f; - -const float DEFAULT_X = 0; -const float DEFAULT_Y = -1.5; -const float DEFAULT_Z = 2.0; -const float DEFAULT_TRANSMITTER_HZ = 60.0; - -Hand::Hand(glm::vec3 initcolor) { - color = initcolor; - reset(); - noise = 0.0; //0.2; - scale.x = 0.07f; - scale.y = scale.x * 5.0f; - scale.z = scale.y * 1.0f; - renderPointer = true; -} - -Hand::Hand(const Hand &otherHand) { - color = otherHand.color; - noise = otherHand.noise; - scale = otherHand.scale; - position = otherHand.position; - target = otherHand.target; - velocity = otherHand.color; - pitch = otherHand.pitch; - yaw = otherHand.yaw; - roll = otherHand.roll; - pitchRate = otherHand.pitchRate; - yawRate = otherHand.yawRate; - rollRate = otherHand.rollRate; - transmitterTimer = otherHand.transmitterTimer; - transmitterHz = otherHand.transmitterHz; - transmitterPackets = otherHand.transmitterPackets; - renderPointer = otherHand.renderPointer; -} - -void Hand::reset() { - position.x = DEFAULT_X; - position.y = DEFAULT_Y; - position.z = DEFAULT_Z; - pitch = yaw = roll = 0; - pitchRate = yawRate = rollRate = 0; - setTarget(position); - velocity.x = velocity.y = velocity.z = 0; - transmitterPackets = 0; - transmitterHz = DEFAULT_TRANSMITTER_HZ; -} - -void Hand::render(int isMine) { - const float POINTER_LENGTH = 20.0; - glPushMatrix(); - glTranslatef(position.x, position.y, position.z); - glRotatef(yaw, 0, 1, 0); - glRotatef(pitch, 1, 0, 0); - glRotatef(roll, 0, 0, 1); - glColor3f(color.x, color.y, color.z); - glScalef(scale.x, scale.y, scale.z); - //glutSolidSphere(1.5, 20, 20); - glutSolidCube(1.0); - if (renderPointer) { - glBegin(GL_TRIANGLES); - glColor3f(1,0,0); - glNormal3f(0,-1,0); - glVertex3f(-0.4f,0,0); - glVertex3f(0.4f,0,0); - glVertex3f(0,0,-POINTER_LENGTH); - glEnd(); - glPushMatrix(); - glTranslatef(0,0,-POINTER_LENGTH); - glutSolidCube(1.0); - glPopMatrix(); - } - glPopMatrix(); -} - -void Hand::addAngularVelocity (float pRate, float yRate, float rRate) { - pitchRate += pRate; - yawRate += yRate; - rollRate += rRate; -} - -void Hand::processTransmitterData(char *packetData, int numBytes) { - // Read a packet from a transmitter app, process the data - float accX, accY, accZ, - graX, graY, graZ, - gyrX, gyrY, gyrZ, - linX, linY, linZ, - rot1, rot2, rot3, rot4; - sscanf((char *)packetData, "tacc %f %f %f gra %f %f %f gyr %f %f %f lin %f %f %f rot %f %f %f %f", - &accX, &accY, &accZ, - &graX, &graY, &graZ, - &gyrX, &gyrY, &gyrZ, - &linX, &linY, &linZ, - &rot1, &rot2, &rot3, &rot4); - - if (transmitterPackets++ == 0) { - gettimeofday(&transmitterTimer, NULL); - } - const int TRANSMITTER_COUNT = 100; - if (transmitterPackets % TRANSMITTER_COUNT == 0) { - // Every 100 packets, record the observed Hz of the transmitter data - timeval now; - gettimeofday(&now, NULL); - double msecsElapsed = diffclock(&transmitterTimer, &now); - transmitterHz = static_cast( (double)TRANSMITTER_COUNT/(msecsElapsed/1000.0) ); - //std::cout << "Transmitter Hz: " << (float)TRANSMITTER_COUNT/(msecsElapsed/1000.0) << "\n"; - //memcpy(&transmitterTimer, &now, sizeof(timeval)); - transmitterTimer = now; - } - // Add rotational forces to the hand - const float ANG_VEL_SENSITIVITY = 4.0; - const float ANG_VEL_THRESHOLD = 0.0; - float angVelScale = ANG_VEL_SENSITIVITY*(1.0f/getTransmitterHz()); - //addAngularVelocity(gyrX*angVelScale,gyrZ*angVelScale,-gyrY*angVelScale); - addAngularVelocity(fabs(gyrX*angVelScale)>ANG_VEL_THRESHOLD?gyrX*angVelScale:0, - fabs(gyrZ*angVelScale)>ANG_VEL_THRESHOLD?gyrZ*angVelScale:0, - fabs(-gyrY*angVelScale)>ANG_VEL_THRESHOLD?-gyrY*angVelScale:0); - - // Add linear forces to the hand - //const float LINEAR_VEL_SENSITIVITY = 50.0; - const float LINEAR_VEL_SENSITIVITY = 5.0; - float linVelScale = LINEAR_VEL_SENSITIVITY*(1.0f/getTransmitterHz()); - glm::vec3 linVel(linX*linVelScale, linZ*linVelScale, -linY*linVelScale); - addVelocity(linVel); - -} - -void Hand::simulate(float deltaTime) { - const float ANGULAR_SPRING_CONSTANT = 0.25; - const float ANGULAR_DAMPING_COEFFICIENT = 5*2.0f*powf(ANGULAR_SPRING_CONSTANT,0.5f); - const float LINEAR_SPRING_CONSTANT = 100; - const float LINEAR_DAMPING_COEFFICIENT = 2.0f*powf(LINEAR_SPRING_CONSTANT,0.5f); - - // If noise, add a bit of random velocity - const float RNOISE = 0.0; - const float VNOISE = 0.01f; - if (noise) { - - glm::vec3 nVel(randFloat() - 0.5f, randFloat() - 0.5f, randFloat() - 0.5f); - nVel *= VNOISE; - addVelocity(nVel); - - addAngularVelocity(RNOISE*(randFloat() - 0.5f), - RNOISE*(randFloat() - 0.5f), - RNOISE*(randFloat() - 0.5f)); - } - position += velocity*deltaTime; - - pitch += pitchRate; - yaw += yawRate; - roll += rollRate; - - // The spring method - if (0) { - // Use a linear spring to attempt to return the hand to the target position - glm::vec3 springForce = target - position; - springForce *= LINEAR_SPRING_CONSTANT; - addVelocity(springForce * deltaTime); - - // Critically damp the linear spring - glm::vec3 dampingForce(velocity); - dampingForce *= LINEAR_DAMPING_COEFFICIENT; - addVelocity(-dampingForce * deltaTime); - - // Use angular spring to return hand to target rotation (0,0,0) - addAngularVelocity(-pitch * ANGULAR_SPRING_CONSTANT * deltaTime, - -yaw * ANGULAR_SPRING_CONSTANT * deltaTime, - -roll * ANGULAR_SPRING_CONSTANT * deltaTime); - - // Critically damp angular spring - addAngularVelocity(-pitchRate*ANGULAR_DAMPING_COEFFICIENT*deltaTime, - -yawRate*ANGULAR_DAMPING_COEFFICIENT*deltaTime, - -rollRate*ANGULAR_DAMPING_COEFFICIENT*deltaTime); - } - - // The absolute limits method (no springs) - if (1) { - // Limit rotation - const float YAW_LIMIT = 20; - const float PITCH_LIMIT = 20; - - if (yaw > YAW_LIMIT) { yaw = YAW_LIMIT; yawRate = 0.0; } - if (yaw < -YAW_LIMIT) { yaw = -YAW_LIMIT; yawRate = 0.0; } - if (pitch > PITCH_LIMIT) { pitch = PITCH_LIMIT; pitchRate = 0.0; } - if (pitch < -PITCH_LIMIT) { pitch = -PITCH_LIMIT; pitchRate = 0.0; } - - // Damp Rotation Rates - yawRate *= 0.99f; - pitchRate *= 0.99f; - rollRate *= 0.99f; - - // Limit position - const float X_LIMIT = 1.0; - const float Y_LIMIT = 1.0; - const float Z_LIMIT = 1.0; - - if (position.x > DEFAULT_X + X_LIMIT) { position.x = DEFAULT_X + X_LIMIT; velocity.x = 0; } - if (position.x < DEFAULT_X - X_LIMIT) { position.x = DEFAULT_X - X_LIMIT; velocity.x = 0; } - if (position.y > DEFAULT_Y + Y_LIMIT) { position.y = DEFAULT_Y + Y_LIMIT; velocity.y = 0; } - if (position.y < DEFAULT_Y - Y_LIMIT) { position.y = DEFAULT_Y - Y_LIMIT; velocity.y = 0; } - if (position.z > DEFAULT_Z + Z_LIMIT) { position.z = DEFAULT_Z + Z_LIMIT; velocity.z = 0; } - if (position.z < DEFAULT_Z - Z_LIMIT) { position.z = DEFAULT_Z - Z_LIMIT; velocity.z = 0; } - - // Damp Velocity - velocity *= 0.99; - - } - -} \ No newline at end of file diff --git a/interface/src/Hand.h b/interface/src/Hand.h deleted file mode 100644 index cf887a897f..0000000000 --- a/interface/src/Hand.h +++ /dev/null @@ -1,47 +0,0 @@ -// -// Hand.h -// interface -// -// Created by Philip Rosedale on 10/13/12. -// Copyright (c) 2012 High Fidelity, Inc. All rights reserved. -// - -#ifndef __interface__Hand__ -#define __interface__Hand__ - -#include -#include -#include "Util.h" -#include "Field.h" -#include "world.h" -#include "InterfaceConfig.h" - -class Hand { -public: - Hand(glm::vec3 color); - Hand(const Hand &otherHand); - void simulate (float deltaTime); - void render (int isMine); - void reset (); - void setNoise (float mag) { noise = mag; }; - void addVelocity (glm::vec3 v) { velocity += v; }; - void addAngularVelocity (float pRate, float yRate, float rRate); - glm::vec3 getPos() { return position; }; - void setPos(glm::vec3 p) { position = p; }; - void setTarget(glm::vec3 t) { target = t; }; - void processTransmitterData(char * packetData, int numBytes); - float getTransmitterHz() { return transmitterHz; }; - void setRenderPointer(bool p) { renderPointer = p; }; -private: - glm::vec3 position, target, velocity, color, scale; - float pitch, yaw, roll, pitchRate, yawRate, rollRate; - float noise; - timeval transmitterTimer; - float transmitterHz; - int transmitterPackets; - bool renderPointer; - -}; - - -#endif diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 1a70ba9a13..e8ab9d6add 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -97,8 +97,6 @@ Head::Head() { springForce = 6.0f; springVelocityDecay = 16.0f; - hand = new Hand(glm::vec3(skinColor[0], skinColor[1], skinColor[2])); - if (iris_texture.size() == 0) { switchToResourcesIfRequired(); unsigned error = lodepng::decode(iris_texture, iris_texture_width, iris_texture_height, iris_texture_file); @@ -174,12 +172,8 @@ Head::Head(const Head &otherHead) { sphere = NULL; - Hand newHand = Hand(*otherHead.hand); - hand = &newHand; } - - Head::~Head() { if (sphere != NULL) { gluDeleteQuadric(sphere); @@ -1224,10 +1218,55 @@ void Head::parseData(void *data, int size) { handBeingMoved = true; } - - - void Head::SetNewHeadTarget(float pitch, float yaw) { PitchTarget = pitch; YawTarget = yaw; } + +void Head::processTransmitterData(char *packetData, int numBytes) { + // Read a packet from a transmitter app, process the data + float accX, accY, accZ, + graX, graY, graZ, + gyrX, gyrY, gyrZ, + linX, linY, linZ, + rot1, rot2, rot3, rot4; + sscanf((char *)packetData, "tacc %f %f %f gra %f %f %f gyr %f %f %f lin %f %f %f rot %f %f %f %f", + &accX, &accY, &accZ, + &graX, &graY, &graZ, + &gyrX, &gyrY, &gyrZ, + &linX, &linY, &linZ, + &rot1, &rot2, &rot3, &rot4); + + if (transmitterPackets++ == 0) { + gettimeofday(&transmitterTimer, NULL); + } + const int TRANSMITTER_COUNT = 100; + if (transmitterPackets % TRANSMITTER_COUNT == 0) { + // Every 100 packets, record the observed Hz of the transmitter data + timeval now; + gettimeofday(&now, NULL); + double msecsElapsed = diffclock(&transmitterTimer, &now); + transmitterHz = static_cast( (double)TRANSMITTER_COUNT/(msecsElapsed/1000.0) ); + transmitterTimer = now; + } + /* NOTE: PR: Will add back in when ready to animate avatar hand + + // Add rotational forces to the hand + const float ANG_VEL_SENSITIVITY = 4.0; + const float ANG_VEL_THRESHOLD = 0.0; + float angVelScale = ANG_VEL_SENSITIVITY*(1.0f/getTransmitterHz()); + + addAngularVelocity(fabs(gyrX*angVelScale)>ANG_VEL_THRESHOLD?gyrX*angVelScale:0, + fabs(gyrZ*angVelScale)>ANG_VEL_THRESHOLD?gyrZ*angVelScale:0, + fabs(-gyrY*angVelScale)>ANG_VEL_THRESHOLD?-gyrY*angVelScale:0); + + // Add linear forces to the hand + //const float LINEAR_VEL_SENSITIVITY = 50.0; + const float LINEAR_VEL_SENSITIVITY = 5.0; + float linVelScale = LINEAR_VEL_SENSITIVITY*(1.0f/getTransmitterHz()); + glm::vec3 linVel(linX*linVelScale, linZ*linVelScale, -linY*linVelScale); + addVelocity(linVel); + */ + +} + diff --git a/interface/src/Head.h b/interface/src/Head.h index eeaa4ebee0..5041133c29 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -13,7 +13,6 @@ #include "AgentData.h" #include "Field.h" #include "world.h" -#include "Hand.h" #include "Orientation.h" // added by Ventrella as a utility #include "InterfaceConfig.h" #include "SerialInterface.h" @@ -196,7 +195,12 @@ class Head : public AgentData { void addThrust(glm::vec3 newThrust) { avatar.thrust += newThrust; }; glm::vec3 getThrust() { return avatar.thrust; }; - Hand * hand; + // + // Related to getting transmitter UDP data used to animate the avatar hand + // + + void processTransmitterData(char * packetData, int numBytes); + float getTransmitterHz() { return transmitterHz; }; private: float noise; @@ -273,6 +277,13 @@ class Head : public AgentData { void readSensors(); float renderYaw, renderPitch; // Pitch from view frustum when this is own head. + // + // Related to getting transmitter UDP data used to animate the avatar hand + // + timeval transmitterTimer; + float transmitterHz; + int transmitterPackets; + }; #endif diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 909227a91f..8f254a8946 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -60,9 +60,8 @@ #include "MenuRow.h" #include "MenuColumn.h" #include "Menu.h" -#include "Head.h" -#include "Hand.h" #include "Camera.h" +#include "Head.h" #include "Particle.h" #include "Texture.h" #include "Cloud.h" @@ -372,12 +371,13 @@ void simulateHand(float deltaTime) { // If mouse is being dragged, send current force to the hand controller if (mousePressed == 1) { - // Add a velocity to the hand corresponding to the detected size of the drag vector + // NOTE--PER: Need to re-implement when ready for new avatar hand movements + const float MOUSE_HAND_FORCE = 1.5; float dx = mouseX - mouseStartX; float dy = mouseY - mouseStartY; glm::vec3 vel(dx*MOUSE_HAND_FORCE, -dy*MOUSE_HAND_FORCE*(WIDTH/HEIGHT), 0); - myAvatar.hand->addVelocity(vel*deltaTime); + //myAvatar.hand->addVelocity(vel*deltaTime); } } @@ -799,7 +799,12 @@ void display(void) // Test - Draw a blue sphere around a body part of mine! glPushMatrix(); - //glTranslate3f(myAvatar.GetRight + glColor4f(0,0,1, 0.7); + glTranslatef(myAvatar.getBonePosition(AVATAR_BONE_RIGHT_HAND).x, + myAvatar.getBonePosition(AVATAR_BONE_RIGHT_HAND).y, + myAvatar.getBonePosition(AVATAR_BONE_RIGHT_HAND).z); + glutSolidSphere(0.03, 10, 10); + glPopMatrix(); // draw a red sphere @@ -1208,7 +1213,7 @@ void *networkReceive(void *args) switch (incomingPacket[0]) { case PACKET_HEADER_TRANSMITTER_DATA: - myAvatar.hand->processTransmitterData(incomingPacket, bytesReceived); + myAvatar.processTransmitterData(incomingPacket, bytesReceived); break; case PACKET_HEADER_VOXEL_DATA: case PACKET_HEADER_Z_COMMAND: @@ -1405,7 +1410,6 @@ int main(int argc, const char * argv[]) initDisplay(); printf( "Initialized Display.\n" ); - glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(key); @@ -1417,11 +1421,9 @@ int main(int argc, const char * argv[]) glutMouseFunc(mouseFunc); glutIdleFunc(idle); - init(); printf( "Init() complete.\n" ); - // Check to see if the user passed in a command line option for randomizing colors if (cmdOptionExists(argc, argv, "--NoColorRandomizer")) { wantColorRandomizer = false; From 98c82281617024be851f916a3d2087be0fc2b7f6 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 12 Apr 2013 21:11:03 -0700 Subject: [PATCH 4/4] had to take out call to myAvatar.getBonePosition - unclear why it now isn't working. --- interface/src/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index ed9a9b4782..23c89824de 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -742,6 +742,8 @@ void display(void) glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); + + /* // Test - Draw a blue sphere around a body part of mine! glPushMatrix(); @@ -750,8 +752,8 @@ void display(void) myAvatar.getBonePosition(AVATAR_BONE_RIGHT_HAND).y, myAvatar.getBonePosition(AVATAR_BONE_RIGHT_HAND).z); glutSolidSphere(0.03, 10, 10); - glPopMatrix(); + */ // draw a red sphere float sphereRadius = 0.25f;