|
@ -29,7 +29,7 @@ void Bullet::setup(vector<Node>& _nodes){ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Bullet::update(bool& is_controller_active, Node& chosen_node) { |
|
|
void Bullet::update(bool& is_controller_active, Node& chosen_node) { |
|
|
//updateRepulsionNode();
|
|
|
|
|
|
cameraBounds = getCameraBounds(camera); |
|
|
cameraBounds = getCameraBounds(camera); |
|
|
world.update(); |
|
|
world.update(); |
|
|
|
|
|
|
|
@ -49,9 +49,9 @@ void Bullet::update(bool& is_controller_active, Node& chosen_node) { |
|
|
if (glm::length(camera_velocity) > 0.0f) { |
|
|
if (glm::length(camera_velocity) > 0.0f) { |
|
|
glm::vec3 decel_dir = -glm::normalize(camera_velocity); |
|
|
glm::vec3 decel_dir = -glm::normalize(camera_velocity); |
|
|
camera_velocity += decel_dir * DECELERATION * d_time; |
|
|
camera_velocity += decel_dir * DECELERATION * d_time; |
|
|
if (glm::length(camera_velocity) < 0.01f) { |
|
|
// if (glm::length(camera_velocity) < 0.01f) {
|
|
|
camera_velocity = glm::vec3(0.0f); |
|
|
// camera_velocity = glm::vec3(0.0f);
|
|
|
} |
|
|
// }
|
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
float distance_factor = glm::min(dist / 50.0f, 1.0f); |
|
|
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
|
|
|
// Final position update with safety check
|
|
|
glm::vec3 new_pos = current_pos + camera_velocity * d_time; |
|
|
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); |
|
|
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
|
|
|
// Always update these regardless of camera movement
|
|
|
for(auto& node : nodes) { |
|
|
for(auto& node : nodes) { |
|
|
updateNodeActivation(node); |
|
|
updateNodeActivation(node); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// if (glm::length(current_pos - target_pos) < 0.01f) {
|
|
|
|
|
|
// camera.setPosition(target_pos);
|
|
|
|
|
|
// camera_velocity = glm::vec3(0.0f);
|
|
|
|
|
|
// }
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Bullet::draw(){ |
|
|
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()->setDamping(btScalar(0.0), btScalar(0.0)); |
|
|
s->getRigidBody()->setLinearFactor(btVector3(1, 1, 0)); |
|
|
s->getRigidBody()->setLinearFactor(btVector3(1, 1, 0)); |
|
|
s->getRigidBody()->setRestitution(btScalar(0.5)); |
|
|
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!
|
|
|
// Set how the col mesh is drawn!
|
|
|
_simple_mesh.setMode(OF_PRIMITIVE_LINES); |
|
|
_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; |
|
|
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); |
|
|
nodes[i].collider->applyCentralForce(1.0f * norm_dir); |
|
|
glm::vec3 rand_vel(ofRandom(-1, 1)); |
|
|
|
|
|
nodes[i].collider->applyCentralForce((1.0f * norm_dir) + rand_vel); |
|
|
//updateNodeActivation(nodes[i]);
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -290,19 +291,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));
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 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); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |