Browse Source

camera & island sleep fixed

master
cailean 1 month ago
parent
commit
ba2ae1ef5a
  1. 8
      bin/data/camera_angles.txt
  2. BIN
      bin/data/new_tree.bin
  3. 8
      bin/data/ofxpimapper.xml
  4. BIN
      bin/image-to-mesh
  5. 106
      src/Bullet.cpp
  6. 13
      src/network/Server.cpp
  7. 3
      src/network/Server.h
  8. 12
      src/ofApp.cpp

8
bin/data/camera_angles.txt

@ -1,8 +0,0 @@
-131.228, 502.624, 706.1 : 0.898726, -0.436474, -0.0351978, -0.0170607 : 0.313542, 0.313542, 0.313542
ortho:
-13.9031, -573.818, 730.531 : 0.902208, 0.429743, 0.029696, -0.0140357 : 0.313542, 0.313542, 0.313542
-209.623, -505.192, 609.98 : 0.881811, 0.44688, -0.133594, 0.0678069 : 0.313542, 0.313542, 0.313542

BIN
bin/data/new_tree.bin

Binary file not shown.

8
bin/data/ofxpimapper.xml

@ -182,19 +182,19 @@
<surface type="1"> <surface type="1">
<vertices> <vertices>
<vertex> <vertex>
<x>1868.000000000</x> <x>1867.000000000</x>
<y>2.000000000</y> <y>2.000000000</y>
</vertex> </vertex>
<vertex> <vertex>
<x>1923.000000000</x> <x>1922.000000000</x>
<y>5.000000000</y> <y>5.000000000</y>
</vertex> </vertex>
<vertex> <vertex>
<x>1928.000000000</x> <x>1927.000000000</x>
<y>1075.000000000</y> <y>1075.000000000</y>
</vertex> </vertex>
<vertex> <vertex>
<x>1893.000000000</x> <x>1892.000000000</x>
<y>1079.000000000</y> <y>1079.000000000</y>
</vertex> </vertex>
</vertices> </vertices>

BIN
bin/image-to-mesh

Binary file not shown.

106
src/Bullet.cpp

@ -21,6 +21,7 @@ void Bullet::setup(){
world.setCamera(&camera); world.setCamera(&camera);
world.setGravity( ofVec3f(0, 0, 0) ); world.setGravity( ofVec3f(0, 0, 0) );
for (int i = 0; i < numThreads; ++i) { for (int i = 0; i < numThreads; ++i) {
workerThreads.emplace_back(&Bullet::workerThreadFunction, this, i); workerThreads.emplace_back(&Bullet::workerThreadFunction, this, i);
} }
@ -35,12 +36,11 @@ void Bullet::update(bool& is_controller_active, Node& chosen_node, vector<Node*>
nn_nodes = nn; nn_nodes = nn;
float current_zoom = camera.getScale().x; static float blend_factor = 0.0f;
const float MIN_ZOOM = 0.04f; const float MIN_ZOOM = 0.04f;
const float MAX_ZOOM = 0.3f; const float MAX_ZOOM = 0.3f;
const float ZOOM_OUT_START_TIME = 40.0f; const float ZOOM_OUT_START_TIME = 40.0f;
float d_time = ofGetLastFrameTime(); float d_time = ofGetLastFrameTime();
float target_zoom = 0;
contr_active = is_controller_active; contr_active = is_controller_active;
@ -51,9 +51,9 @@ void Bullet::update(bool& is_controller_active, Node& chosen_node, vector<Node*>
time_at_target = 0; time_at_target = 0;
random_walk_time = 0; random_walk_time = 0;
scale_out_factor = 0; scale_out_factor = 0;
camera_velocity = glm::vec3(0.0f);
} else { } else {
new_chosen_node = false; new_chosen_node = false;
time_at_target += d_time;
} }
cameraBounds = getCameraBounds(camera); cameraBounds = getCameraBounds(camera);
@ -62,25 +62,93 @@ void Bullet::update(bool& is_controller_active, Node& chosen_node, vector<Node*>
glm::vec3 target_pos = chosen_node.collider->getPosition(); glm::vec3 target_pos = chosen_node.collider->getPosition();
glm::vec3 current_pos = camera.getPosition(); glm::vec3 current_pos = camera.getPosition();
glm::vec3 dir = current_pos - target_pos;
float dist = glm::length(dir);
// Start counting if close to target
if(dist < TARGET_REACHED_DISTANCE) {
time_at_target += d_time;
// Start random walk after delay // Start random walk after delay
if (time_at_target >= RANDOM_WALK_DELAY && !is_random_walking) { if (time_at_target >= RANDOM_WALK_DELAY && !is_random_walking) {
is_random_walking = true; is_random_walking = true;
random_target = generateRandomTarget();
}
} else {
time_at_target = 0;
} }
// Handle random walk mode if(is_random_walking){
if (is_random_walking) {
target_zoom = MAX_ZOOM;
random_walk_time += d_time; random_walk_time += d_time;
glm::vec3 to_random_target = random_target - current_pos;
float random_dist = glm::length(to_random_target);
// Smooth movement towards random target
if (random_dist > 0.0001f) {
glm::vec3 random_dir = glm::normalize(to_random_target);
camera_velocity = random_dir * RANDOM_WALK_SPEED * d_time;
}
// Generate new random target when reached current one
if (random_dist < 10.0f) {
random_target = generateRandomTarget();
}
} else if(!std::isnan(dist) && dist >= 0.0001f){
glm::vec3 norm_dir = glm::normalize(dir);
if(!glm::any(glm::isnan(camera.getPosition()))){
float distance_factor = glm::min(dist / 50.0f, 1.0f);
float current_acceleration = ACCELERATION * distance_factor;
glm::vec3 acceleration = -norm_dir * current_acceleration * d_time;
if(!glm::any(glm::isnan(acceleration))) {
camera_velocity += acceleration;
}
/* decelerate if close to target */
if (dist < 5.0f) {
float decel_factor = dist / 5.0f;
camera_velocity *= (1.0f - (1.0f - decel_factor) * d_time * 10.0f);
}
float mag = glm::length(camera_velocity);
/* cap velocity */
if (mag > MAX_VELOCITY) {
camera_velocity = glm::normalize(camera_velocity) * MAX_VELOCITY;
}
}
}
// Smoothed zoom based on velocity
float vel_magnitude = glm::length(camera_velocity);
static float current_zoom = 0.02f;
float target_zoom = ofMap(vel_magnitude, 0, MAX_VELOCITY, 0.02, 0.3, true);
current_zoom = current_zoom + (target_zoom - current_zoom) * 0.05f;
// Calculate scale-out factor if we're in random walk mode
if (random_walk_time > SCALE_OUT_START_TIME) {
float scale_progress = (random_walk_time - SCALE_OUT_START_TIME) / SCALE_OUT_DURATION;
scale_progress = ofClamp(scale_progress, 0.0f, 1.0f);
// Smoother easing function (quintic ease in/out)
float t = scale_progress;
if (t < 0.5f) {
scale_out_factor = 16 * t * t * t * t * t;
} else { } else {
target_zoom = MIN_ZOOM; t = t - 1;
scale_out_factor = 1 + 16 * t * t * t * t * t;
} }
}
// Blend between velocity-based zoom and scale-out with smooth transitions both ways
float final_scale = current_zoom;
current_zoom += (target_zoom - camera.getScale().x) * 0.005f; // Calculate target blend based on whether we're random walking
float target_blend = is_random_walking ? scale_out_factor : 0.0f;
blend_factor += (target_blend - blend_factor) * 0.05f; // Smooth transition both ways
camera.setScale(current_zoom); if (blend_factor > 0.001f) { // Apply blended scale if we have any blend factor
final_scale = ofLerp(current_zoom, 0.3, blend_factor);
}
if(!glm::any(glm::isnan((target_pos)))){ if(!glm::any(glm::isnan((target_pos)))){
glm::vec3 new_pos = current_pos + (target_pos - current_pos) * 0.01f; glm::vec3 new_pos = current_pos + (target_pos - current_pos) * 0.01f;
@ -92,14 +160,17 @@ void Bullet::update(bool& is_controller_active, Node& chosen_node, vector<Node*>
camera.setPosition(0, 0, -40); camera.setPosition(0, 0, -40);
} }
camera.setScale(final_scale);
glm::vec3 new_pos = current_pos + camera_velocity * d_time;
camera.setPosition(new_pos);
last_chosen_node = chosen_node; last_chosen_node = chosen_node;
} }
void Bullet::draw(){ void Bullet::draw(){
std::lock_guard<std::mutex> lock(shapeMutex);
float shapes_drawn = 0; float shapes_drawn = 0;
gridSize = calculateGridSize(camera.getScale().x); gridSize = calculateGridSize(camera.getScale().x);
@ -206,6 +277,9 @@ void Bullet::addMesh(ofMesh _mesh, ofMesh _simple_mesh, Node& _node){
s->create( world.world, start_location, startRot, 3.); s->create( world.world, start_location, startRot, 3.);
s->add(); s->add();
s->getRigidBody()->setActivationState(DISABLE_DEACTIVATION); s->getRigidBody()->setActivationState(DISABLE_DEACTIVATION);
s->getRigidBody()->forceActivationState(DISABLE_DEACTIVATION);
s->getRigidBody()->setSleepingThresholds(0.0f, 0.0f);
s->getRigidBody()->setDeactivationTime(btScalar(BT_INFINITY)); // Never deactivate
s->getRigidBody()->setAngularFactor(btVector3(0, 0, 1)); s->getRigidBody()->setAngularFactor(btVector3(0, 0, 1));
s->getRigidBody()->setDamping(btScalar(0.0), btScalar(0.0)); s->getRigidBody()->setDamping(btScalar(0.0), btScalar(0.0));
s->getRigidBody()->setLinearFactor(btVector3(1, 1, 0)); s->getRigidBody()->setLinearFactor(btVector3(1, 1, 0));
@ -242,8 +316,8 @@ void Bullet::updateShapeBatch(size_t start, size_t end) {
glm::vec3 direction = target_pos - pos; glm::vec3 direction = target_pos - pos;
float dist_sq = glm::length(direction); float dist_sq = glm::length(direction);
glm::vec3 norm_dir = glm::normalize(direction); glm::vec3 norm_dir = glm::normalize(direction);
glm::vec3 rand_vel(ofRandom(-1, 1)); glm::vec3 rand_vel(ofRandom(-5, 5), ofRandom(-5, 5), 0);
nodes[i].collider->applyCentralForce((1.0f * norm_dir)); nodes[i].collider->applyCentralForce((1.0f * norm_dir) + rand_vel);
} }
} }
@ -314,8 +388,8 @@ void Bullet::updateNodeActivation(Node& node) {
body->activate(true); body->activate(true);
body->setActivationState(ACTIVE_TAG); body->setActivationState(ACTIVE_TAG);
} else if (!should_be_active && body->isActive()) { } else if (!should_be_active && body->isActive()) {
//body->setActivationState(ISLAND_SLEEPING); body->setActivationState(ISLAND_SLEEPING);
//body->setLinearVelocity(btVector3(0,0,0)); body->setLinearVelocity(btVector3(0,0,0));
} }
} }

13
src/network/Server.cpp

@ -71,7 +71,9 @@ void Server::update(ofFbo& esp_comp){
sendImagesToClients(extractedImages); sendImagesToClients(extractedImages);
if(!m_RanomdEmbed){
updateEmbedding(); updateEmbedding();
}
/* check if inactive -> query vptree -> move camera */ /* check if inactive -> query vptree -> move camera */
checkActivity(); checkActivity();
@ -108,6 +110,17 @@ void Server::updateEmbedding() {
} }
} }
void Server::randomEmbedding(){
std::vector<std::string> emotionNames = {
"happy", "sad", "angry", "neutral"
};
for (const auto& c : emotionNames){
float r = ofRandom(100.0);
embedding.emotions[c] = r;
}
}
void Server::printClients(){ void Server::printClients(){
for( const auto& c : clients){ for( const auto& c : clients){
int id = c.first; int id = c.first;

3
src/network/Server.h

@ -36,6 +36,7 @@ class Server{
void disconnectAllClients(); void disconnectAllClients();
void help(ofFbo& esp_comp); void help(ofFbo& esp_comp);
void close(); void close();
void randomEmbedding();
std::vector<std::vector<double>> generateRandomVectors(int count, int dimension); std::vector<std::vector<double>> generateRandomVectors(int count, int dimension);
/* getters */ /* getters */
@ -74,6 +75,8 @@ class Server{
std::chrono::steady_clock::time_point lastUpdateTime; std::chrono::steady_clock::time_point lastUpdateTime;
const std::chrono::milliseconds updateInterval{1000}; // 1 second interval const std::chrono::milliseconds updateInterval{1000}; // 1 second interval
bool m_RanomdEmbed = true;
int regions[4][4] = { int regions[4][4] = {
{0, 0, 128, 168}, // Top-left {0, 0, 128, 168}, // Top-left
{128, 0, 128, 168}, // Top-right {128, 0, 128, 168}, // Top-right

12
src/ofApp.cpp

@ -109,7 +109,6 @@ void ofApp::setup(){
cp.scale = 0.313542; cp.scale = 0.313542;
cp.mode =CameraMode::PERSP; cp.mode =CameraMode::PERSP;
cp.depth_mult = 600; cp.depth_mult = 600;
//cam_positions.push_back(cp);
/* settings */ /* settings */
portrait_camera.enableOrtho(); portrait_camera.enableOrtho();
@ -202,10 +201,10 @@ void ofApp::update(){
mapper.update(); mapper.update();
bullet.update(server->is_active, n, nn_nodes); bullet.update(server->is_active, n, nn_nodes);
if(tsne_update_complete) { // if(tsne_update_complete) {
tsne_update_complete = false; // Reset flag // tsne_update_complete = false; // Reset flag
onTSNEUpdateComplete(); // Call your main thread function // onTSNEUpdateComplete(); // Call your main thread function
} // }
// if(ofGetElapsedTimef() > tsne_start_time + TNSE_DURATION){ // if(ofGetElapsedTimef() > tsne_start_time + TNSE_DURATION){
// tsne_iter_idx = (tsne_iter_idx + 1) % 3; // tsne_iter_idx = (tsne_iter_idx + 1) % 3;
@ -726,6 +725,9 @@ void ofApp::keyPressed(int key) {
case 'v': case 'v':
ofToggleFullscreen(); ofToggleFullscreen();
break; break;
case '9':
server->randomEmbedding();
break;
} }
mapper.keyPressed(key); mapper.keyPressed(key);
} }

Loading…
Cancel
Save