|
@ -26,8 +26,6 @@ void Bullet::setup(vector<Node>& _nodes){ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
shader.load("shaders/vertex_snap"); |
|
|
shader.load("shaders/vertex_snap"); |
|
|
|
|
|
|
|
|
std::cout << workerThreads.size() << std::endl; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Bullet::update(bool& is_controller_active, Node& chosen_node) { |
|
|
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); |
|
|
cameraBounds = getCameraBounds(camera); |
|
|
world.update(); |
|
|
world.update(); |
|
|
|
|
|
|
|
|
// static bool was_controller_active = false;
|
|
|
updateRepulsionNode(); |
|
|
// static float transition_timer = 0.0f;
|
|
|
cameraBounds = getCameraBounds(camera); |
|
|
// static glm::vec3 start_pos;
|
|
|
world.update(); |
|
|
|
|
|
float d_time = ofGetLastFrameTime(); |
|
|
// glm::vec3 current_pos = camera.getPosition();
|
|
|
glm::vec3 target_pos = chosen_node.collider->getPosition(); |
|
|
// float deltaTime = ofGetLastFrameTime();
|
|
|
glm::vec3 current_pos = camera.getPosition(); |
|
|
|
|
|
glm::vec3 dir = current_pos - target_pos; |
|
|
// // Detect transition from controller to inactive
|
|
|
float dist = glm::length(dir); |
|
|
// if (is_controller_active != was_controller_active) {
|
|
|
glm::vec3 norm_dir = glm::normalize(dir); |
|
|
// if (!is_controller_active) {
|
|
|
|
|
|
// // Starting transition to new node
|
|
|
if (is_controller_active) { |
|
|
// transition_timer = 0.0f;
|
|
|
if (glm::length(camera_velocity) > 0.0f) { |
|
|
// start_pos = current_pos;
|
|
|
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 (!is_controller_active && &chosen_node != current_target_node) {
|
|
|
} |
|
|
// current_target_node = &chosen_node;
|
|
|
} |
|
|
// }
|
|
|
} else { |
|
|
|
|
|
float distance_factor = glm::min(dist / 50.0f, 1.0f); |
|
|
// // Update camera physics
|
|
|
float current_acceleration = ACCELERATION * distance_factor; |
|
|
// if (is_controller_active) {
|
|
|
|
|
|
// // Decelerate over 2 seconds
|
|
|
camera_velocity += -norm_dir * current_acceleration * d_time; |
|
|
// float deceleration_rate = 0.5f; // 1/2 = 2 seconds
|
|
|
|
|
|
// camera_velocity = camera_velocity * (1.0f - deceleration_rate * deltaTime);
|
|
|
if (dist < 5.0f) { |
|
|
|
|
|
float decel_factor = dist / 5.0f; |
|
|
// if (glm::length(camera_velocity) < 0.01f) {
|
|
|
camera_velocity *= (1.0f - (1.0f - decel_factor) * d_time * 10.0f); |
|
|
// camera_velocity = glm::vec3(0.0f);
|
|
|
} |
|
|
// }
|
|
|
|
|
|
|
|
|
float mag = glm::length(camera_velocity); |
|
|
// // Keep base zoom when controller is active
|
|
|
if (mag > MAX_VELOCITY) { |
|
|
// current_zoom = current_zoom + (0.03f - current_zoom) * deltaTime * 5.0f;
|
|
|
camera_velocity = glm::normalize(camera_velocity) * MAX_VELOCITY; |
|
|
// } else {
|
|
|
} |
|
|
// glm::vec3 target_position = current_target_node->collider->getPosition();
|
|
|
|
|
|
|
|
|
// Smoothed zoom based on velocity
|
|
|
// // Transition period (zooming out and in)
|
|
|
float vel_magnitude = glm::length(camera_velocity); |
|
|
// if (transition_timer < 10.0f) { // 2 second transition
|
|
|
static float current_zoom = 0.02f; // Store current zoom
|
|
|
// transition_timer += deltaTime;
|
|
|
float target_zoom = ofMap(vel_magnitude, 0, MAX_VELOCITY, 0.02, 0.3, true); |
|
|
// float progress = transition_timer / 2.0f;
|
|
|
|
|
|
|
|
|
// Smooth lerp to target zoom
|
|
|
// // Zoom curve (out and in)
|
|
|
current_zoom = current_zoom + (target_zoom - current_zoom) * 0.1f; |
|
|
// float zoomProgress;
|
|
|
camera.setScale(current_zoom); |
|
|
// if (progress < 0.5f) {
|
|
|
} |
|
|
// // Zoom out during first half
|
|
|
|
|
|
// zoomProgress = progress * 2.0f;
|
|
|
camera.setPosition(current_pos + camera_velocity * d_time); |
|
|
// float targetZoom = glm::mix(0.03f, 0.6f, zoomProgress);
|
|
|
|
|
|
// current_zoom = current_zoom + (targetZoom - current_zoom) * deltaTime * 5.0f;
|
|
|
if (glm::length(current_pos - target_pos) < 0.01f) { |
|
|
// } else {
|
|
|
camera.setPosition(target_pos); |
|
|
// // Zoom in during second half
|
|
|
camera_velocity = glm::vec3(0.0f); |
|
|
// 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;
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Bullet::draw(){ |
|
|
void Bullet::draw(){ |
|
@ -194,7 +152,7 @@ void Bullet::draw(){ |
|
|
ss << "Camera Position: " << camera.getPosition() << std::endl; |
|
|
ss << "Camera Position: " << camera.getPosition() << std::endl; |
|
|
ss << "Camera Scale: " << camera.getScale() << std::endl; |
|
|
ss << "Camera Scale: " << camera.getScale() << std::endl; |
|
|
ss << "Camera Bounds: " << cameraBounds.z << std::endl; |
|
|
ss << "Camera Bounds: " << cameraBounds.z << std::endl; |
|
|
ofSetColor(255, 255, 255); |
|
|
ofSetColor(ofColor::blue); |
|
|
ofDrawBitmapString(ss.str().c_str(), 20, 20); |
|
|
ofDrawBitmapString(ss.str().c_str(), 20, 20); |
|
|
now = false; |
|
|
now = false; |
|
|
} |
|
|
} |
|
@ -242,36 +200,6 @@ void Bullet::workerThreadFunction(int threadId) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Bullet::updateShapeBatch(size_t start, size_t end) { |
|
|
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) { |
|
|
for (size_t i = start; i < end; ++i) { |
|
|
std::lock_guard<std::mutex> lock(shapeMutex); |
|
|
std::lock_guard<std::mutex> lock(shapeMutex); |
|
|
|
|
|
|
|
|