mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-15 17:46:47 +02:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
b4184562e0
5 changed files with 65 additions and 92 deletions
|
@ -8,33 +8,29 @@
|
|||
|
||||
#include "Hand.h"
|
||||
|
||||
const float DEFAULT_X = 0.0;
|
||||
const float DEFAULT_Y = 0.0;
|
||||
const float DEFAULT_Z = -7.0;
|
||||
const float PHI = 1.618;
|
||||
|
||||
Hand::Hand(float initradius, glm::vec3 initcolor)
|
||||
const float DEFAULT_X = 0;
|
||||
const float DEFAULT_Y = -1.5;
|
||||
const float DEFAULT_Z = 2.0;
|
||||
|
||||
Hand::Hand(glm::vec3 initcolor)
|
||||
{
|
||||
color = initcolor;
|
||||
radius = initradius;
|
||||
reset();
|
||||
noise = 0;
|
||||
noise = 0.2;
|
||||
scale.x = 0.07;
|
||||
scale.y = scale.x * 5.0;
|
||||
scale.z = scale.y * 1.0;
|
||||
}
|
||||
|
||||
void Hand::render()
|
||||
{
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
if (isColliding) glColor3f(1,0,0);
|
||||
else glColor3f(color.x, color.y, color.z);
|
||||
glBegin(GL_LINES);
|
||||
glVertex3f(-0.05, -0.5, 0.0);
|
||||
glVertex3f(position.x, position.y, position.z);
|
||||
glVertex3f(0.05, -0.5, 0.0);
|
||||
glVertex3f(position.x, position.y, position.z);
|
||||
glEnd();
|
||||
glTranslatef(position.x, position.y, position.z);
|
||||
glutSolidSphere(radius, 15, 15);
|
||||
glColor3f(color.x, color.y, color.z);
|
||||
glScalef(scale.x, scale.y, scale.z);
|
||||
glutSolidSphere(1.5, 20, 20);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
|
@ -43,22 +39,17 @@ void Hand::reset()
|
|||
position.x = DEFAULT_X;
|
||||
position.y = DEFAULT_Y;
|
||||
position.z = DEFAULT_Z;
|
||||
setTarget(position);
|
||||
velocity.x = velocity.y = velocity.z = 0;
|
||||
isColliding = false;
|
||||
}
|
||||
|
||||
void Hand::simulate(float deltaTime)
|
||||
{
|
||||
position += velocity*deltaTime;
|
||||
|
||||
velocity *= (1.f - 4.0*deltaTime);
|
||||
|
||||
if ((noise) && (randFloat() < 0.1))
|
||||
{
|
||||
velocity.x += (randFloat() - 0.5)*noise;
|
||||
velocity.y += (randFloat() - 0.5)*noise;
|
||||
velocity.z += (randFloat() - 0.5)*noise;
|
||||
|
||||
// If noise, add wandering movement
|
||||
if (noise) {
|
||||
position += noise * 0.1f * glm::vec3(randFloat() - 0.5, randFloat() - 0.5, randFloat() - 0.5);
|
||||
}
|
||||
// Decay position of hand toward target
|
||||
position -= deltaTime*(position - target);
|
||||
|
||||
}
|
|
@ -16,26 +16,20 @@
|
|||
#include "world.h"
|
||||
#include "InterfaceConfig.h"
|
||||
|
||||
const float RADIUS_RANGE = 10.0;
|
||||
|
||||
class Hand {
|
||||
public:
|
||||
Hand(float initradius, glm::vec3 color);
|
||||
Hand(glm::vec3 color);
|
||||
void simulate (float deltaTime);
|
||||
void render ();
|
||||
void reset ();
|
||||
void setNoise (float mag) { noise = mag; };
|
||||
void addVel (glm::vec3 add) { velocity += add; };
|
||||
void addVel (glm::vec3 v) { velocity += v; };
|
||||
glm::vec3 getPos() { return position; };
|
||||
void setPos(glm::vec3 newpos) { position = newpos; };
|
||||
float getRadius() { return radius; };
|
||||
void setRadius(float newradius) { radius = newradius; };
|
||||
void setColliding(bool newcollide) { isColliding = newcollide; };
|
||||
void setPos(glm::vec3 p) { position = p; };
|
||||
void setTarget(glm::vec3 t) { target = t; };
|
||||
private:
|
||||
glm::vec3 position, velocity, color;
|
||||
glm::vec3 position, target, velocity, color, scale;
|
||||
float noise;
|
||||
float radius;
|
||||
bool isColliding;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@ Head::Head()
|
|||
renderYaw = 0.0;
|
||||
renderPitch = 0.0;
|
||||
setNoise(0);
|
||||
hand = new Hand(glm::vec3(skinColor[0], skinColor[1], skinColor[2]));
|
||||
}
|
||||
|
||||
Head::~Head() {
|
||||
|
@ -205,6 +206,7 @@ void Head::simulate(float deltaTime)
|
|||
}
|
||||
|
||||
}
|
||||
hand->simulate(deltaTime);
|
||||
|
||||
|
||||
}
|
||||
|
@ -216,27 +218,34 @@ void Head::render(int faceToFace, float * myLocation)
|
|||
glm::vec3 cameraHead(myLocation[0], myLocation[1], myLocation[2]);
|
||||
float distanceToCamera = glm::distance(cameraHead, position);
|
||||
|
||||
//std::cout << distanceToCamera << "\n";
|
||||
// Always render own hand, but don't render head unless showing face2face
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glPushMatrix();
|
||||
|
||||
glScalef(scale, scale, scale);
|
||||
glTranslatef(leanSideways, 0.f, leanForward);
|
||||
|
||||
glRotatef(Yaw, 0, 1, 0);
|
||||
|
||||
hand->render();
|
||||
|
||||
// Don't render a head if it is really close to your location, because that is your own head!
|
||||
if ((distanceToCamera > 1.0) || faceToFace) {
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glPushMatrix();
|
||||
|
||||
glScalef(scale, scale, scale);
|
||||
glTranslatef(leanSideways, 0.f, leanForward);
|
||||
|
||||
glRotatef(Yaw, 0, 1, 0);
|
||||
|
||||
glRotatef(Pitch, 1, 0, 0);
|
||||
glRotatef(Roll, 0, 0, 1);
|
||||
|
||||
|
||||
// Overall scale of head
|
||||
if (faceToFace) glScalef(1.5, 2.0, 2.0);
|
||||
else glScalef(0.75, 1.0, 1.0);
|
||||
glColor3fv(skinColor);
|
||||
|
||||
|
||||
|
||||
// Head
|
||||
glutSolidSphere(1, 30, 30);
|
||||
glutSolidSphere(1, 30, 30);
|
||||
|
||||
//std::cout << distanceToCamera << "\n";
|
||||
|
||||
// Ears
|
||||
glPushMatrix();
|
||||
|
@ -326,9 +335,9 @@ void Head::render(int faceToFace, float * myLocation)
|
|||
glutSolidSphere(PupilSize, 15, 15);
|
||||
glPopMatrix();
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
// Transmit data to agents requesting it
|
||||
|
@ -336,18 +345,23 @@ void Head::render(int faceToFace, float * myLocation)
|
|||
int Head::getBroadcastData(char* data)
|
||||
{
|
||||
// Copy data for transmission to the buffer, return length of data
|
||||
sprintf(data, "H%f,%f,%f,%f,%f,%f,%f,%f", getRenderPitch() + Pitch, -getRenderYaw() + 180 -Yaw, Roll,
|
||||
sprintf(data, "H%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f",
|
||||
getRenderPitch() + Pitch, -getRenderYaw() + 180 -Yaw, Roll,
|
||||
position.x + leanSideways, position.y, position.z + leanForward,
|
||||
loudness, averageLoudness);
|
||||
loudness, averageLoudness,
|
||||
hand->getPos().x, hand->getPos().y, hand->getPos().z);
|
||||
return strlen(data);
|
||||
}
|
||||
|
||||
void Head::parseData(void *data, int size) {
|
||||
// parse head data for this agent
|
||||
sscanf((char *)data, "H%f,%f,%f,%f,%f,%f,%f,%f",
|
||||
glm::vec3 handPos(0,0,0);
|
||||
sscanf((char *)data, "H%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f",
|
||||
&Pitch, &Yaw, &Roll,
|
||||
&position.x, &position.y, &position.z,
|
||||
&loudness, &averageLoudness);
|
||||
&loudness, &averageLoudness,
|
||||
&handPos.x, &handPos.y, &handPos.z);
|
||||
if (glm::length(handPos) > 0.0) hand->setPos(handPos);
|
||||
}
|
||||
|
||||
void Head::SetNewHeadTarget(float pitch, float yaw)
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
#include "AgentData.h"
|
||||
#include "Field.h"
|
||||
#include "world.h"
|
||||
#include "Head.h"
|
||||
#include "Hand.h"
|
||||
#include "InterfaceConfig.h"
|
||||
#include "SerialInterface.h"
|
||||
|
||||
|
@ -95,7 +97,9 @@ class Head : public AgentData {
|
|||
int eyeContact;
|
||||
eyeContactTargets eyeContactTarget;
|
||||
void readSensors();
|
||||
float renderYaw, renderPitch; // Pitch from view frustum when this is own head.
|
||||
float renderYaw, renderPitch; // Pitch from view frustum when this is own head.
|
||||
|
||||
Hand * hand;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -86,8 +86,6 @@ Oscilloscope audioScope(512,200,true);
|
|||
#define HAND_RADIUS 0.25 // Radius of in-world 'hand' of you
|
||||
Head myHead; // The rendered head of oneself
|
||||
|
||||
Hand myHand(HAND_RADIUS,
|
||||
glm::vec3(0,1,1)); // My hand (used to manipulate things in world)
|
||||
|
||||
glm::vec3 box(WORLD_SIZE,WORLD_SIZE,WORLD_SIZE);
|
||||
ParticleSystem balls(0,
|
||||
|
@ -140,7 +138,6 @@ float noise = 1.0; // Overall magnitude scaling for random noi
|
|||
int step_on = 0;
|
||||
int display_levels = 0;
|
||||
int display_head = 0;
|
||||
int display_hand = 0;
|
||||
int display_field = 0;
|
||||
|
||||
int display_head_mouse = 1; // Display sample mouse pointer controlled by head movement
|
||||
|
@ -334,7 +331,6 @@ void init(void)
|
|||
|
||||
if (noise_on)
|
||||
{
|
||||
myHand.setNoise(noise);
|
||||
myHead.setNoise(noise);
|
||||
}
|
||||
|
||||
|
@ -388,7 +384,6 @@ void reset_sensors()
|
|||
head_lean_y = HEIGHT/2;
|
||||
|
||||
myHead.reset();
|
||||
myHand.reset();
|
||||
|
||||
if (serialPort.active) {
|
||||
serialPort.resetTrailingAverages();
|
||||
|
@ -419,20 +414,6 @@ void update_pos(float frametime)
|
|||
head_mouse_y = max(head_mouse_y, 0);
|
||||
head_mouse_y = min(head_mouse_y, HEIGHT);
|
||||
|
||||
// Update hand/manipulator location for measured forces from serial channel
|
||||
/*
|
||||
const float MIN_HAND_ACCEL = 30.0;
|
||||
const float HAND_FORCE_SCALE = 0.5;
|
||||
glm::vec3 hand_accel(-(avg_adc_channels[6] - adc_channels[6]),
|
||||
-(avg_adc_channels[7] - adc_channels[7]),
|
||||
-(avg_adc_channels[5] - adc_channels[5]));
|
||||
|
||||
if (glm::length(hand_accel) > MIN_HAND_ACCEL)
|
||||
{
|
||||
myHand.addVel(frametime*hand_accel*HAND_FORCE_SCALE);
|
||||
}
|
||||
*/
|
||||
|
||||
// Update render direction (pitch/yaw) based on measured gyro rates
|
||||
const int MIN_YAW_RATE = 100;
|
||||
const float YAW_SENSITIVITY = 0.08;
|
||||
|
@ -510,9 +491,6 @@ void update_pos(float frametime)
|
|||
location[0] += fwd_vec[2]*-lateral_vel;
|
||||
location[2] += fwd_vec[0]*lateral_vel;
|
||||
|
||||
// Update manipulator objects with object with current location
|
||||
balls.updateHand(myHead.getPos() + myHand.getPos(), glm::vec3(0,0,0), myHand.getRadius());
|
||||
|
||||
// Update own head data
|
||||
myHead.setRenderYaw(myHead.getRenderYaw() + render_yaw_rate);
|
||||
myHead.setRenderPitch(render_pitch);
|
||||
|
@ -599,22 +577,18 @@ void display(void)
|
|||
}
|
||||
}
|
||||
|
||||
if (display_hand) myHand.render();
|
||||
|
||||
if (!display_head) balls.render();
|
||||
|
||||
// Render the world box
|
||||
if (!display_head && stats_on) render_world_box();
|
||||
|
||||
// Render my own head
|
||||
|
||||
if (display_head) {
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glTranslatef(0.f, 0.f, -7.f);
|
||||
myHead.render(1, &location[0]);
|
||||
glPopMatrix();
|
||||
}
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glTranslatef(0.f, 0.f, -7.f);
|
||||
myHead.render(display_head, &location[0]);
|
||||
glPopMatrix();
|
||||
|
||||
//glm::vec3 test(0.5, 0.5, 0.5);
|
||||
//render_vector(&test);
|
||||
|
||||
|
@ -720,18 +694,15 @@ void key(unsigned char k, int x, int y)
|
|||
noise_on = !noise_on; // Toggle noise
|
||||
if (noise_on)
|
||||
{
|
||||
myHand.setNoise(noise);
|
||||
myHead.setNoise(noise);
|
||||
}
|
||||
else
|
||||
{
|
||||
myHand.setNoise(0);
|
||||
myHead.setNoise(0);
|
||||
}
|
||||
|
||||
}
|
||||
if (k == 'h') display_head = !display_head;
|
||||
if (k == 'b') display_hand = !display_hand;
|
||||
if (k == 'm') head_mirror = !head_mirror;
|
||||
|
||||
if (k == 'f') display_field = !display_field;
|
||||
|
@ -794,7 +765,6 @@ void idle(void)
|
|||
if (simulate_on) {
|
||||
field.simulate(1.f/FPS);
|
||||
myHead.simulate(1.f/FPS);
|
||||
myHand.simulate(1.f/FPS);
|
||||
balls.simulate(1.f/FPS);
|
||||
cloud.simulate(1.f/FPS);
|
||||
lattice.simulate(1.f/FPS);
|
||||
|
|
Loading…
Reference in a new issue