Browse Source

camer working w/ deactive nodes

master
cailean 2 months ago
parent
commit
a12dbe0261
  1. BIN
      bin/data/new_tree.bin
  2. 8
      bin/data/shaders/p_depth.vert
  3. BIN
      bin/image-to-mesh
  4. 46
      src/Bullet.cpp
  5. 29
      src/ofApp.cpp
  6. 4
      src/ofApp.h

BIN
bin/data/new_tree.bin

Binary file not shown.

8
bin/data/shaders/p_depth.vert

@ -16,9 +16,10 @@ void main()
{
tex_c = texcoord;
// vec4 t_sample = texture(tex0, tex_c);
//float depth = pow(texture(tex1, tex_c).r, 2);
float depth = pow(texture(tex1, tex_c).r, 2);
vec2 depthCoord = texcoord * vec2(1920.0/2.0, 960.0);
float depth = pow(texture(tex1, depthCoord).r, 2);
// Normalize the depth value between 0 and 1 based on min/max
float normalizedDepth = (depth) / threshold.y;
@ -27,9 +28,6 @@ void main()
displaced.z = normalizedDepth * 800.0;
//vec2 resolution = vec2(1280.0, 960.0);
// Transform the vertex position to clip space
vec4 clipPos = modelViewProjectionMatrix * displaced;

BIN
bin/image-to-mesh

Binary file not shown.

46
src/Bullet.cpp

@ -29,7 +29,7 @@ void Bullet::setup(vector<Node>& _nodes){
}
void Bullet::update(bool& is_controller_active, Node& chosen_node) {
//updateRepulsionNode();
cameraBounds = getCameraBounds(camera);
world.update();
@ -49,9 +49,9 @@ void Bullet::update(bool& is_controller_active, Node& chosen_node) {
if (glm::length(camera_velocity) > 0.0f) {
glm::vec3 decel_dir = -glm::normalize(camera_velocity);
camera_velocity += decel_dir * DECELERATION * d_time;
if (glm::length(camera_velocity) < 0.01f) {
camera_velocity = glm::vec3(0.0f);
}
// if (glm::length(camera_velocity) < 0.01f) {
// camera_velocity = glm::vec3(0.0f);
// }
}
} else {
float distance_factor = glm::min(dist / 50.0f, 1.0f);
@ -87,21 +87,23 @@ void Bullet::update(bool& is_controller_active, Node& chosen_node) {
// Final position update with safety check
glm::vec3 new_pos = current_pos + camera_velocity * d_time;
if(!std::isnan(new_pos.x) && !std::isnan(new_pos.y) && !std::isnan(new_pos.z)) {
camera.setPosition(new_pos);
// if(!std::isnan(new_pos.x) && !std::isnan(new_pos.y) && !std::isnan(new_pos.z)) {
// camera.setPosition(new_pos);
// }
}
}
}
// if (glm::length(current_pos - target_pos) < 1.0f) {
// camera.setPosition(target_pos);
// //camera_velocity = glm::vec3(0.0f);
// }
// Always update these regardless of camera movement
for(auto& node : nodes) {
updateNodeActivation(node);
}
// if (glm::length(current_pos - target_pos) < 0.01f) {
// camera.setPosition(target_pos);
// camera_velocity = glm::vec3(0.0f);
// }
}
void Bullet::draw(){
@ -192,7 +194,7 @@ void Bullet::addMesh(ofMesh _mesh, ofMesh _simple_mesh, Node& _node){
s->getRigidBody()->setDamping(btScalar(0.0), btScalar(0.0));
s->getRigidBody()->setLinearFactor(btVector3(1, 1, 0));
s->getRigidBody()->setRestitution(btScalar(0.5));
s->getRigidBody()->setFriction(btScalar(1.0));
s->getRigidBody()->setFriction(btScalar(0.0));
// Set how the col mesh is drawn!
_simple_mesh.setMode(OF_PRIMITIVE_LINES);
@ -224,9 +226,8 @@ void Bullet::updateShapeBatch(size_t start, size_t end) {
glm::vec3 direction = target_pos - pos;
float dist_sq = glm::length(direction);
glm::vec3 norm_dir = glm::normalize(direction);
nodes[i].collider->applyCentralForce(1.0f * norm_dir);
//updateNodeActivation(nodes[i]);
glm::vec3 rand_vel(ofRandom(-1, 1));
nodes[i].collider->applyCentralForce((1.0f * norm_dir) + rand_vel);
}
}
@ -290,19 +291,8 @@ void Bullet::updateNodeActivation(Node& node) {
body->activate(true);
body->setActivationState(ACTIVE_TAG);
} else if (!should_be_active && body->isActive()) {
body->setActivationState(ISLAND_SLEEPING);
body->setLinearVelocity(btVector3(0,0,0));
//body->setActivationState(ISLAND_SLEEPING);
//body->setLinearVelocity(btVector3(0,0,0));
}
// Force position check periodically
if(!should_be_active) {
// If node has drifted too far from target, reset it
glm::vec3 target_pos(node.tsne_position.x, node.tsne_position.y, -5);
float drift_distance = glm::length(node_pos - target_pos);
if(drift_distance > 400.0f) { // Adjust threshold as needed
btTransform transform = body->getWorldTransform();
transform.setOrigin(btVector3(target_pos.x, target_pos.y, target_pos.z));
body->setWorldTransform(transform);
}
}
}

29
src/ofApp.cpp

@ -283,16 +283,31 @@ void ofApp::drawPortrait(){
ofPopMatrix();
portrait_pre_fbo_alpha.end();
if(portrait_needs_update) {
float current_time = ofGetElapsedTimef();
if(portrait_needs_update || past_plane_size != plane_size) {
past_plane_size = plane_size;
depth_ready = false;
mesh_ready = false;
last_process_time = current_time;
ofPixels pix;
portrait_pre_fbo.readToPixels(pix);
model_image_portrait.setFromPixels(pix);
// Only run portrait model when needed
// Queue the depth processing
depth_portrait.update();
}
// Give the depth processing some time to complete (adjust timeout as needed)
const float PROCESS_TIMEOUT = 0.5; // half second timeout
if(!depth_ready && (current_time - last_process_time) > PROCESS_TIMEOUT) {
depth_onnx_portrait.SetPixels(model_portrait_out_fbo);
depth_ready = true;
}
/* create mesh */
// Only generate mesh once depth is ready
if(depth_ready && !mesh_ready) {
float planeScale = 1.0;
int planeWidth = portrait_pre_fbo_alpha.getWidth() * planeScale;
int planeHeight = portrait_pre_fbo_alpha.getHeight() * planeScale;
@ -303,7 +318,9 @@ void ofApp::drawPortrait(){
plane.set(planeWidth, planeHeight, planeColumns, planeRows, OF_PRIMITIVE_TRIANGLES);
plane.mapTexCoords(0, 0, planeWidth, planeHeight);
custom_mesh = createCustomPlane(planeWidth, planeHeight, planeColumns, planeRows);
// ofLog() << "new mesh";
ofLog() << "Generated new mesh at time: " << current_time;
mesh_ready = true;
}
}
@ -607,8 +624,8 @@ ofMesh ofApp::createCustomPlane(float width, float height, int numX, int numY) {
float cellWidth = width/numX;
float cellHeight = height/numY;
xPos += ofRandom(-cellWidth * 0.4, cellWidth * 0.4);
yPos += ofRandom(-cellHeight * 0.4, cellHeight * 0.4);
xPos += ofRandom(-cellWidth * 0.1, cellWidth * 0.1);
yPos += ofRandom(-cellHeight * 0.1, cellHeight * 0.1);
}
mesh.addVertex(glm::vec3(xPos, yPos, 0));

4
src/ofApp.h

@ -111,6 +111,7 @@ class ofApp : public ofBaseApp{
/* settings */
float g_size = 5;
float plane_size = 55;
float past_plane_size;
/* pi mapper */
ofxPiMapper mapper;
@ -125,4 +126,7 @@ class ofApp : public ofBaseApp{
Node last_chosen_node;
bool portrait_needs_update;
ofMesh custom_mesh;
bool depth_ready = false;
bool mesh_ready = false;
float last_process_time = 0;
};

Loading…
Cancel
Save