|
|
@ -11,11 +11,11 @@ void Bullet::setup(vector<Node>& _nodes){ |
|
|
|
camera.setPosition(camera_start_pos); |
|
|
|
camera.lookAt(ofVec3f(0, 0, 0), ofVec3f(0, -1, 0)); |
|
|
|
camera.enableOrtho(); |
|
|
|
camera.setScale(0.01); |
|
|
|
camera.setScale(0.05); |
|
|
|
camera.setNearClip(-10000); |
|
|
|
camera.setFarClip(10000); |
|
|
|
camera.disableMouseInput(); |
|
|
|
camera.removeAllInteractions(); |
|
|
|
// camera.disableMouseInput();
|
|
|
|
// camera.removeAllInteractions();
|
|
|
|
|
|
|
|
world.setup(); |
|
|
|
world.setCamera(&camera); |
|
|
@ -35,97 +35,97 @@ 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; |
|
|
|
// 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); |
|
|
|
// 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); |
|
|
|
} |
|
|
|
// 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(); |
|
|
|
// // 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; |
|
|
|
// // 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; |
|
|
|
} |
|
|
|
// // 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; |
|
|
|
// // 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; |
|
|
|
// 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); |
|
|
|
// 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; |
|
|
|
} |
|
|
|
// // 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); |
|
|
|
// // 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); |
|
|
|
// // Update position using velocity
|
|
|
|
// glm::vec3 new_position = current_pos + camera_velocity * deltaTime;
|
|
|
|
// camera.setPosition(new_position);
|
|
|
|
|
|
|
|
was_controller_active = is_controller_active; |
|
|
|
// was_controller_active = is_controller_active;
|
|
|
|
} |
|
|
|
|
|
|
|
void Bullet::draw(){ |
|
|
@ -138,14 +138,14 @@ void Bullet::draw(){ |
|
|
|
glEnable( GL_DEPTH_TEST ); |
|
|
|
|
|
|
|
ofSetLineWidth(10.f); |
|
|
|
ofDrawGrid(20, 100, true, false, false, true); |
|
|
|
//ofDrawGrid(100, 100, false, false, false, true);
|
|
|
|
|
|
|
|
ofNoFill(); |
|
|
|
ofSetColor(ofColor::yellow); |
|
|
|
|
|
|
|
ofNoFill(); |
|
|
|
|
|
|
|
ofSetColor(ofColor::orange); |
|
|
|
ofSetColor(ofColor::yellow); |
|
|
|
for(const auto& n : nodes){ |
|
|
|
if(checkNodeVisibility(n)){ |
|
|
|
ofPushMatrix(); |
|
|
@ -168,7 +168,7 @@ void Bullet::draw(){ |
|
|
|
ofPushMatrix(); |
|
|
|
shader.begin(); |
|
|
|
shader.setUniform1f("gridSize", gridSize); |
|
|
|
shader.setUniform2f("resolution", glm::vec2((1920.0 / 3) * 2, 960.0)); |
|
|
|
shader.setUniform2f("resolution", glm::vec2(1920.0, 960.0)); |
|
|
|
shader.setUniformTexture("tex0", n.tex, 0); |
|
|
|
n.collider->transformGL(); |
|
|
|
ofScale(n.scale); |
|
|
@ -205,7 +205,9 @@ void Bullet::addMesh(ofMesh _mesh, ofMesh _simple_mesh, Node& _node){ |
|
|
|
glm::vec3 random_szie(rand, rand, rand); |
|
|
|
_node.scale = random_szie; |
|
|
|
ofQuaternion startRot = ofQuaternion(0., 0., 0., PI); |
|
|
|
ofVec3f start_location = ofVec3f( ofRandom(-3000, 3000), ofRandom(-3000, 3000) -5 ); |
|
|
|
|
|
|
|
|
|
|
|
ofVec3f start_location = ofVec3f( ofRandom(_node.tsne_position.x - 50, _node.tsne_position.x + 50), ofRandom(_node.tsne_position.y - 50, _node.tsne_position.y + 50) -5 ); |
|
|
|
|
|
|
|
ofxBulletCustomShape* s = new ofxBulletCustomShape(); |
|
|
|
s->addMesh(_simple_mesh, _node.scale * 1.4, true); |
|
|
@ -224,7 +226,6 @@ void Bullet::addMesh(ofMesh _mesh, ofMesh _simple_mesh, Node& _node){ |
|
|
|
_node.collider = s; |
|
|
|
_node.mesh = _mesh; |
|
|
|
_node.col_mesh = _simple_mesh; |
|
|
|
// nodes.push_back(n);
|
|
|
|
} |
|
|
|
|
|
|
|
void Bullet::workerThreadFunction(int threadId) { |
|
|
|