Fixes stephen asked for - remove finger stuff

This commit is contained in:
Philip Rosedale 2013-04-11 17:53:57 -07:00
parent 27c032270c
commit 76e2ca301e
3 changed files with 1 additions and 258 deletions

View file

@ -1,201 +0,0 @@
//
// Finger.cpp
// interface
//
// Created by Philip on 1/21/13.
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
//
#include "Finger.h"
#ifdef _WIN32
float fminf( float x, float y )
{
return x < y ? x : y;
}
#endif
const int NUM_BEADS = 75;
const float RADIUS = 50; // Radius of beads around finger
const int NUM_PUCKS = 10;
Finger::Finger(int w, int h) {
width = w;
height = h;
pos.x = pos.y = 0;
vel.x = vel.y = 0;
target.x = target.y = 0;
m = 1;
pressure = 0;
start = true;
// Create surface beads
beads = new bead[NUM_BEADS];
pucks = new puck[NUM_PUCKS];
float alpha = 0;
for (int i = 0; i < NUM_BEADS; i++) {
beads[i].target.x = cosf(alpha)*RADIUS + 2.0f*(randFloat() - 0.5f);
beads[i].target.y = sinf(alpha)*RADIUS + 2.0f*(randFloat() - 0.5f);
beads[i].pos.x = beads[i].pos.y = 0.0;
beads[i].vel.x = beads[i].vel.y = 0.0;
alpha += 2.0f*PIf/NUM_BEADS;
beads[i].color[0] = randFloat()*0.05f; beads[i].color[1] = randFloat()*0.05f; beads[i].color[2] = 0.75f + randFloat()*0.25f;
beads[i].brightness = 0.0;
}
for (int i = 0; i < NUM_PUCKS; i++) {
pucks[i].pos.x = randFloat()*width;
pucks[i].pos.y = randFloat()*height;
pucks[i].radius = 5.0f + randFloat()*30.0f;
pucks[i].vel.x = pucks[i].vel.y = 0.0;
pucks[i].mass = pucks[i].radius*pucks[i].radius/25.0f;
}
}
const float SHADOW_COLOR[4] = {0.0, 0.0, 0.0, 0.75};
const float SHADOW_OFFSET = 2.5;
void Finger::render() {
glEnable(GL_POINT_SMOOTH);
glPointSize(30.0f);
glBegin(GL_POINTS);
glColor4fv(SHADOW_COLOR);
glVertex2f(pos.x + SHADOW_OFFSET, pos.y + SHADOW_OFFSET);
glColor4f(0.0, 0.0, 0.7f, 1.0);
glVertex2f(pos.x, pos.y);
glEnd();
// Render Pucks
for (int i = 0; i < NUM_PUCKS; i++) {
glColor4fv(SHADOW_COLOR);
glPointSize(pucks[i].radius*2.f);
glBegin(GL_POINTS);
glVertex2f(pucks[i].pos.x + SHADOW_OFFSET, pucks[i].pos.y + SHADOW_OFFSET);
glColor4f(1.0, 0.0, 0.0, 1.0);
glVertex2f(pucks[i].pos.x, pucks[i].pos.y);
glEnd();
}
// Render beads
glPointSize(5.0f);
glLineWidth(3.0);
glBegin(GL_POINTS);
for (int i = 0; i < NUM_BEADS; i++) {
glColor4fv(SHADOW_COLOR);
glVertex2f(beads[i].pos.x + SHADOW_OFFSET, beads[i].pos.y + SHADOW_OFFSET);
glColor3f(beads[i].color[0]+beads[i].brightness, beads[i].color[1]+beads[i].brightness, beads[i].color[2]+beads[i].brightness);
glVertex2f(beads[i].pos.x, beads[i].pos.y);
}
glEnd();
}
void Finger::setTarget(int x, int y) {
target.x = static_cast<float>(x);
target.y = static_cast<float>(y);
if (start) {
// On startup, set finger to first target location
pos.x = target.x;
pos.y = target.y;
vel.x = vel.y = 0.0;
start = false;
}
}
void Finger::simulate(float deltaTime) {
// Using the new target position x and y as where the mouse intends the finger to be, move the finger
if (!start) {
// Move the finger
float distance = glm::distance(pos, target);
//float spring_length = 0;
const float SPRING_FORCE = 1000.0;
if (distance > 0.1) {
vel += glm::normalize(target - pos)*deltaTime*SPRING_FORCE*distance;
}
// Decay Velocity (Drag)
vel *= 0.8;
//vel *= (1.f - CONSTANT_DAMPING*deltaTime);
// Update position
pos += vel*deltaTime;
// Update the beads
const float BEAD_SPRING_FORCE = 500.0;
const float BEAD_NEIGHBOR_FORCE = 200.0;
const float HARD_SPHERE_FORCE = 2500.0;
const float PRESSURE_FACTOR = 0.00;
float separation, contact;
float newPressure = 0;
int n1, n2;
float d1, d2;
for (int i = 0; i < NUM_BEADS; i++) {
distance = glm::distance(beads[i].pos, pos + beads[i].target * (1.f + pressure*PRESSURE_FACTOR));
if (distance > 0.1) {
beads[i].vel += glm::normalize((pos + (beads[i].target*(1.f + pressure*PRESSURE_FACTOR))) - beads[i].pos)*deltaTime*BEAD_SPRING_FORCE*distance;
}
// Add forces from 2 neighboring beads
if ((i-1)>=0) n1 = i - 1;
else n1 = NUM_PUCKS - 1;
if ((i+1)<NUM_PUCKS) n2 = i + 1;
else n2 = 0;
d1 = glm::distance(beads[i].pos, beads[n1].pos);
if (d1 > 0.01) beads[i].vel += glm::normalize(beads[n1].pos - beads[i].pos)*deltaTime*BEAD_NEIGHBOR_FORCE*distance;
d2 = glm::distance(beads[i].pos, beads[n2].pos);
if (d2 > 0.01) beads[i].vel += glm::normalize(beads[n2].pos - beads[i].pos)*deltaTime*BEAD_NEIGHBOR_FORCE*distance;
// Look for hard collision with pucks
for (int j = 0; j < NUM_PUCKS; j++) {
separation = glm::distance(beads[i].pos, pucks[j].pos);
contact = 2.5f + pucks[j].radius;
// Hard Sphere Scattering
if (separation < contact) {
beads[i].vel += glm::normalize(beads[i].pos - pucks[j].pos)*
deltaTime*HARD_SPHERE_FORCE*(contact - separation);
pucks[j].vel -= glm::normalize(beads[i].pos - pucks[j].pos)*
deltaTime*HARD_SPHERE_FORCE*(contact - separation)/pucks[j].mass;
if (beads[i].brightness < 0.5) beads[i].brightness = 0.5;
beads[i].brightness *= 1.1f;
} else {
beads[i].brightness *= 0.95f;
}
beads[i].brightness = fminf(beads[i].brightness, 1.f);
}
// Decay velocity, move beads
beads[i].vel *= 0.85;
beads[i].pos += beads[i].vel*deltaTime;
// Measure pressure for next run
newPressure += glm::distance(beads[i].pos, pos);
}
if (fabs(newPressure - NUM_BEADS*RADIUS) < 100.f) pressure = newPressure - (NUM_BEADS*RADIUS);
// Update the pucks for any pressure they have received
for (int j = 0; j < NUM_PUCKS; j++) {
pucks[j].vel *= 0.99;
if (pucks[j].radius < 25.0) pucks[j].pos += pucks[j].vel*deltaTime;
// wrap at edges
if (pucks[j].pos.x > width) pucks[j].pos.x = 0.0;
if (pucks[j].pos.x < 0) pucks[j].pos.x = static_cast<float>(width);
if (pucks[j].pos.y > height) pucks[j].pos.y = 0.0;
if (pucks[j].pos.y < 0) pucks[j].pos.y = static_cast<float>(height);
}
}
}

View file

@ -1,47 +0,0 @@
//
// Finger.h
// interface
//
// Created by Philip on 1/21/13.
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
//
#ifndef __interface__Finger__
#define __interface__Finger__
#include <glm/glm.hpp>
#include "Util.h"
#include "world.h"
#include "InterfaceConfig.h"
#include <iostream>
class Finger {
public:
Finger(int w, int h);
void simulate(float deltaTime);
void render();
void setTarget(int x, int y);
private:
int width, height; // Screen size in pixels
bool start;
glm::vec2 pos, vel; // Position and velocity of finger
float m; // Velocity of finger
float pressure; // Internal pressure of skin vessel as function of measured volume
glm::vec2 target; // Where the mouse is
// little beads used to render the dynamic skin surface
struct bead {
glm::vec2 target, pos, vel;
float color[3];
float brightness;
} *beads;
struct puck {
glm::vec2 pos, vel;
float brightness;
float radius;
float mass;
} *pucks;
};
#endif /* defined(__interface__finger__) */

View file

@ -69,7 +69,6 @@
#include <AgentList.h>
#include <AgentTypes.h>
#include "VoxelSystem.h"
#include "Finger.h"
#include "Oscilloscope.h"
#include "UDPSocket.h"
#include "SerialInterface.h"
@ -127,8 +126,6 @@ Cloud cloud(0, // Particles
);
VoxelSystem voxels;
Finger myFinger(WIDTH, HEIGHT);
Field field;
#ifndef _WIN32
@ -321,7 +318,6 @@ void init(void)
myAvatar.setPos(start_location );
myCamera.setPosition( start_location );
myFinger.setTarget(WIDTH/2, HEIGHT/2);
#ifdef MARKER_CAPTURE
if(marker_capture_enabled){
@ -864,8 +860,6 @@ void display(void)
gluOrtho2D(0, WIDTH, HEIGHT, 0);
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
myFinger.render();
#ifndef _WIN32
audio.render(WIDTH, HEIGHT);
@ -1279,7 +1273,6 @@ void idle(void)
myAvatar.simulate(1.f/FPS);
balls.simulate(1.f/FPS);
cloud.simulate(1.f/FPS);
myFinger.simulate(1.f/FPS);
glutPostRedisplay();
lastTimeIdle = check;
@ -1346,9 +1339,7 @@ void mouseoverFunc( int x, int y)
mouseX = x;
mouseY = y;
if (mousePressed == 0)
{
myFinger.setTarget(mouseX, mouseY);
}
{}
}
void attachNewHeadToAgent(Agent *newAgent) {