|
|
@ -26,8 +26,6 @@ void Bullet::setup(vector<Node>& _nodes){ |
|
|
|
} |
|
|
|
|
|
|
|
shader.load("shaders/vertex_snap"); |
|
|
|
|
|
|
|
std::cout << workerThreads.size() << std::endl; |
|
|
|
} |
|
|
|
|
|
|
|
void Bullet::update(bool& is_controller_active, Node& chosen_node) { |
|
|
@ -35,97 +33,57 @@ void Bullet::update(bool& is_controller_active, Node& chosen_node) { |
|
|
|
cameraBounds = getCameraBounds(camera); |
|
|
|
world.update(); |
|
|
|
|
|
|
|
// static bool was_controller_active = false;
|
|
|
|
// static float transition_timer = 0.0f;
|
|
|
|
// static glm::vec3 start_pos;
|
|
|
|
|
|
|
|
// glm::vec3 current_pos = camera.getPosition();
|
|
|
|
// float deltaTime = ofGetLastFrameTime();
|
|
|
|
|
|
|
|
// // Detect transition from controller to inactive
|
|
|
|
// if (is_controller_active != was_controller_active) {
|
|
|
|
// if (!is_controller_active) {
|
|
|
|
// // Starting transition to new node
|
|
|
|
// transition_timer = 0.0f;
|
|
|
|
// start_pos = current_pos;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (!is_controller_active && &chosen_node != current_target_node) {
|
|
|
|
// current_target_node = &chosen_node;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // Update camera physics
|
|
|
|
// if (is_controller_active) {
|
|
|
|
// // Decelerate over 2 seconds
|
|
|
|
// float deceleration_rate = 0.5f; // 1/2 = 2 seconds
|
|
|
|
// camera_velocity = camera_velocity * (1.0f - deceleration_rate * deltaTime);
|
|
|
|
|
|
|
|
// if (glm::length(camera_velocity) < 0.01f) {
|
|
|
|
// camera_velocity = glm::vec3(0.0f);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // Keep base zoom when controller is active
|
|
|
|
// current_zoom = current_zoom + (0.03f - current_zoom) * deltaTime * 5.0f;
|
|
|
|
// } else {
|
|
|
|
// glm::vec3 target_position = current_target_node->collider->getPosition();
|
|
|
|
|
|
|
|
// // Transition period (zooming out and in)
|
|
|
|
// if (transition_timer < 10.0f) { // 2 second transition
|
|
|
|
// transition_timer += deltaTime;
|
|
|
|
// float progress = transition_timer / 2.0f;
|
|
|
|
|
|
|
|
// // Zoom curve (out and in)
|
|
|
|
// float zoomProgress;
|
|
|
|
// if (progress < 0.5f) {
|
|
|
|
// // Zoom out during first half
|
|
|
|
// zoomProgress = progress * 2.0f;
|
|
|
|
// float targetZoom = glm::mix(0.03f, 0.6f, zoomProgress);
|
|
|
|
// current_zoom = current_zoom + (targetZoom - current_zoom) * deltaTime * 5.0f;
|
|
|
|
// } else {
|
|
|
|
// // Zoom in during second half
|
|
|
|
// zoomProgress = (1.0f - progress) * 2.0f;
|
|
|
|
// float targetZoom = glm::mix(0.03f, 0.6f, zoomProgress);
|
|
|
|
// current_zoom = current_zoom + (targetZoom - current_zoom) * deltaTime * 5.0f;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // Move towards target during transition
|
|
|
|
// glm::vec3 ideal_pos = glm::mix(start_pos, target_position, progress);
|
|
|
|
// camera_velocity = (ideal_pos - current_pos) / deltaTime;
|
|
|
|
// } else {
|
|
|
|
// // After transition, follow node with spring physics
|
|
|
|
// float k = 2.0f;
|
|
|
|
// float damping = 3.0f;
|
|
|
|
|
|
|
|
// glm::vec3 displacement = target_position - current_pos;
|
|
|
|
// glm::vec3 spring_force = k * displacement;
|
|
|
|
|
|
|
|
// camera_velocity = camera_velocity + spring_force * deltaTime;
|
|
|
|
// camera_velocity = camera_velocity * (1.0f - damping * deltaTime);
|
|
|
|
|
|
|
|
// // Optional: Velocity-based zoom after transition
|
|
|
|
// float speed = glm::length(camera_velocity);
|
|
|
|
// float maxSpeed = 25.0f;
|
|
|
|
// float speedFactor = glm::min(speed / maxSpeed, 1.0f);
|
|
|
|
// float targetZoom = glm::mix(0.03f, 0.15f, speedFactor); // smaller zoom range for following
|
|
|
|
// current_zoom = current_zoom + (targetZoom - current_zoom) * deltaTime * 5.0f;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // Clamp velocity to maximum speed
|
|
|
|
// float maxSpeed = 25.0f;
|
|
|
|
// float currentSpeed = glm::length(camera_velocity);
|
|
|
|
// if (currentSpeed > maxSpeed) {
|
|
|
|
// camera_velocity = (camera_velocity / currentSpeed) * maxSpeed;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// camera.setScale(current_zoom);
|
|
|
|
|
|
|
|
// // Update position using velocity
|
|
|
|
// glm::vec3 new_position = current_pos + camera_velocity * deltaTime;
|
|
|
|
// camera.setPosition(new_position);
|
|
|
|
|
|
|
|
// was_controller_active = is_controller_active;
|
|
|
|
updateRepulsionNode(); |
|
|
|
cameraBounds = getCameraBounds(camera); |
|
|
|
world.update(); |
|
|
|
float d_time = ofGetLastFrameTime(); |
|
|
|
glm::vec3 target_pos = chosen_node.collider->getPosition(); |
|
|
|
glm::vec3 current_pos = camera.getPosition(); |
|
|
|
glm::vec3 dir = current_pos - target_pos; |
|
|
|
float dist = glm::length(dir); |
|
|
|
glm::vec3 norm_dir = glm::normalize(dir); |
|
|
|
|
|
|
|
if (is_controller_active) { |
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
float distance_factor = glm::min(dist / 50.0f, 1.0f); |
|
|
|
float current_acceleration = ACCELERATION * distance_factor; |
|
|
|
|
|
|
|
camera_velocity += -norm_dir * current_acceleration * d_time; |
|
|
|
|
|
|
|
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); |
|
|
|
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; // Store current zoom
|
|
|
|
float target_zoom = ofMap(vel_magnitude, 0, MAX_VELOCITY, 0.02, 0.3, true); |
|
|
|
|
|
|
|
// Smooth lerp to target zoom
|
|
|
|
current_zoom = current_zoom + (target_zoom - current_zoom) * 0.1f; |
|
|
|
camera.setScale(current_zoom); |
|
|
|
} |
|
|
|
|
|
|
|
camera.setPosition(current_pos + camera_velocity * d_time); |
|
|
|
|
|
|
|
if (glm::length(current_pos - target_pos) < 0.01f) { |
|
|
|
camera.setPosition(target_pos); |
|
|
|
camera_velocity = glm::vec3(0.0f); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void Bullet::draw(){ |
|
|
@ -194,7 +152,7 @@ void Bullet::draw(){ |
|
|
|
ss << "Camera Position: " << camera.getPosition() << std::endl; |
|
|
|
ss << "Camera Scale: " << camera.getScale() << std::endl; |
|
|
|
ss << "Camera Bounds: " << cameraBounds.z << std::endl; |
|
|
|
ofSetColor(255, 255, 255); |
|
|
|
ofSetColor(ofColor::blue); |
|
|
|
ofDrawBitmapString(ss.str().c_str(), 20, 20); |
|
|
|
now = false; |
|
|
|
} |
|
|
@ -242,36 +200,6 @@ void Bullet::workerThreadFunction(int threadId) { |
|
|
|
} |
|
|
|
|
|
|
|
void Bullet::updateShapeBatch(size_t start, size_t end) { |
|
|
|
// for (size_t i = start; i < end; ++i) {
|
|
|
|
// std::lock_guard<std::mutex> lock(shapeMutex);
|
|
|
|
// glm::vec3 pos = nodes[i].collider->getPosition();
|
|
|
|
// glm::vec3 direction = glm::vec3(0, 0, -5) - pos;
|
|
|
|
// float dist_sq = glm::length(direction);
|
|
|
|
// glm::vec3 norm_dir = glm::normalize(direction);
|
|
|
|
// nodes[i].collider->applyCentralForce(1.0 * norm_dir);
|
|
|
|
|
|
|
|
// if(now){
|
|
|
|
// std::lock_guard<std::mutex> lock(shapeMutex);
|
|
|
|
// nodes[i].collider->applyCentralForce(glm::vec3(ofRandom(-1, 1), ofRandom(-1, 1), ofRandom(-1, 1)));
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (dist_sq > FORCE_RADIUS_SQ){
|
|
|
|
// glm::vec3 norm_dir = glm::normalize(direction);
|
|
|
|
// std::lock_guard<std::mutex> lock(shapeMutex);
|
|
|
|
// nodes[i].collider->applyCentralForce(0.001 * direction);
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// btVector3 vel = nodes[i].collider->getRigidBody()->getLinearVelocity();
|
|
|
|
// float vel_mag = vel.length();
|
|
|
|
|
|
|
|
// if (vel_mag > 1.0f) { // Cap at magnitude 1
|
|
|
|
// vel.normalize(); // Normalize the velocity
|
|
|
|
// vel *= 1.0f; // Scale to cap
|
|
|
|
// nodes[i].collider->getRigidBody()->setLinearVelocity(vel); // Set the capped velocity
|
|
|
|
// }
|
|
|
|
|
|
|
|
//}
|
|
|
|
for (size_t i = start; i < end; ++i) { |
|
|
|
std::lock_guard<std::mutex> lock(shapeMutex); |
|
|
|
|
|
|
|