|
@ -21,6 +21,7 @@ void Bullet::setup(){ |
|
|
world.setCamera(&camera); |
|
|
world.setCamera(&camera); |
|
|
world.setGravity( ofVec3f(0, 0, 0) ); |
|
|
world.setGravity( ofVec3f(0, 0, 0) ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < numThreads; ++i) { |
|
|
for (int i = 0; i < numThreads; ++i) { |
|
|
workerThreads.emplace_back(&Bullet::workerThreadFunction, this, i); |
|
|
workerThreads.emplace_back(&Bullet::workerThreadFunction, this, i); |
|
|
} |
|
|
} |
|
@ -35,12 +36,11 @@ void Bullet::update(bool& is_controller_active, Node& chosen_node, vector<Node*> |
|
|
|
|
|
|
|
|
nn_nodes = nn; |
|
|
nn_nodes = nn; |
|
|
|
|
|
|
|
|
float current_zoom = camera.getScale().x; |
|
|
static float blend_factor = 0.0f; |
|
|
const float MIN_ZOOM = 0.04f; |
|
|
const float MIN_ZOOM = 0.04f; |
|
|
const float MAX_ZOOM = 0.3f; |
|
|
const float MAX_ZOOM = 0.3f; |
|
|
const float ZOOM_OUT_START_TIME = 40.0f; |
|
|
const float ZOOM_OUT_START_TIME = 40.0f; |
|
|
float d_time = ofGetLastFrameTime(); |
|
|
float d_time = ofGetLastFrameTime(); |
|
|
float target_zoom = 0; |
|
|
|
|
|
|
|
|
|
|
|
contr_active = is_controller_active; |
|
|
contr_active = is_controller_active; |
|
|
|
|
|
|
|
@ -51,9 +51,9 @@ void Bullet::update(bool& is_controller_active, Node& chosen_node, vector<Node*> |
|
|
time_at_target = 0; |
|
|
time_at_target = 0; |
|
|
random_walk_time = 0; |
|
|
random_walk_time = 0; |
|
|
scale_out_factor = 0; |
|
|
scale_out_factor = 0; |
|
|
|
|
|
camera_velocity = glm::vec3(0.0f); |
|
|
} else { |
|
|
} else { |
|
|
new_chosen_node = false; |
|
|
new_chosen_node = false; |
|
|
time_at_target += d_time; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
cameraBounds = getCameraBounds(camera); |
|
|
cameraBounds = getCameraBounds(camera); |
|
@ -62,25 +62,93 @@ void Bullet::update(bool& is_controller_active, Node& chosen_node, vector<Node*> |
|
|
|
|
|
|
|
|
glm::vec3 target_pos = chosen_node.collider->getPosition(); |
|
|
glm::vec3 target_pos = chosen_node.collider->getPosition(); |
|
|
glm::vec3 current_pos = camera.getPosition(); |
|
|
glm::vec3 current_pos = camera.getPosition(); |
|
|
|
|
|
glm::vec3 dir = current_pos - target_pos; |
|
|
|
|
|
float dist = glm::length(dir); |
|
|
|
|
|
|
|
|
|
|
|
// Start counting if close to target
|
|
|
|
|
|
if(dist < TARGET_REACHED_DISTANCE) { |
|
|
|
|
|
time_at_target += d_time; |
|
|
// Start random walk after delay
|
|
|
// Start random walk after delay
|
|
|
if (time_at_target >= RANDOM_WALK_DELAY && !is_random_walking) { |
|
|
if (time_at_target >= RANDOM_WALK_DELAY && !is_random_walking) { |
|
|
is_random_walking = true; |
|
|
is_random_walking = true; |
|
|
|
|
|
random_target = generateRandomTarget(); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
time_at_target = 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Handle random walk mode
|
|
|
if(is_random_walking){ |
|
|
if (is_random_walking) { |
|
|
|
|
|
target_zoom = MAX_ZOOM; |
|
|
|
|
|
random_walk_time += d_time; |
|
|
random_walk_time += d_time; |
|
|
|
|
|
glm::vec3 to_random_target = random_target - current_pos; |
|
|
|
|
|
float random_dist = glm::length(to_random_target); |
|
|
|
|
|
|
|
|
|
|
|
// Smooth movement towards random target
|
|
|
|
|
|
if (random_dist > 0.0001f) { |
|
|
|
|
|
glm::vec3 random_dir = glm::normalize(to_random_target); |
|
|
|
|
|
camera_velocity = random_dir * RANDOM_WALK_SPEED * d_time; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Generate new random target when reached current one
|
|
|
|
|
|
if (random_dist < 10.0f) { |
|
|
|
|
|
random_target = generateRandomTarget(); |
|
|
|
|
|
} |
|
|
|
|
|
} else if(!std::isnan(dist) && dist >= 0.0001f){ |
|
|
|
|
|
glm::vec3 norm_dir = glm::normalize(dir); |
|
|
|
|
|
if(!glm::any(glm::isnan(camera.getPosition()))){ |
|
|
|
|
|
float distance_factor = glm::min(dist / 50.0f, 1.0f); |
|
|
|
|
|
float current_acceleration = ACCELERATION * distance_factor; |
|
|
|
|
|
glm::vec3 acceleration = -norm_dir * current_acceleration * d_time; |
|
|
|
|
|
|
|
|
|
|
|
if(!glm::any(glm::isnan(acceleration))) { |
|
|
|
|
|
camera_velocity += acceleration; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* decelerate if close to target */ |
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
/* cap 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; |
|
|
|
|
|
float target_zoom = ofMap(vel_magnitude, 0, MAX_VELOCITY, 0.02, 0.3, true); |
|
|
|
|
|
current_zoom = current_zoom + (target_zoom - current_zoom) * 0.05f; |
|
|
|
|
|
|
|
|
|
|
|
// Calculate scale-out factor if we're in random walk mode
|
|
|
|
|
|
if (random_walk_time > SCALE_OUT_START_TIME) { |
|
|
|
|
|
float scale_progress = (random_walk_time - SCALE_OUT_START_TIME) / SCALE_OUT_DURATION; |
|
|
|
|
|
scale_progress = ofClamp(scale_progress, 0.0f, 1.0f); |
|
|
|
|
|
|
|
|
|
|
|
// Smoother easing function (quintic ease in/out)
|
|
|
|
|
|
float t = scale_progress; |
|
|
|
|
|
if (t < 0.5f) { |
|
|
|
|
|
scale_out_factor = 16 * t * t * t * t * t; |
|
|
} else { |
|
|
} else { |
|
|
target_zoom = MIN_ZOOM; |
|
|
t = t - 1; |
|
|
|
|
|
scale_out_factor = 1 + 16 * t * t * t * t * t; |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Blend between velocity-based zoom and scale-out with smooth transitions both ways
|
|
|
|
|
|
float final_scale = current_zoom; |
|
|
|
|
|
|
|
|
current_zoom += (target_zoom - camera.getScale().x) * 0.005f; |
|
|
// Calculate target blend based on whether we're random walking
|
|
|
|
|
|
float target_blend = is_random_walking ? scale_out_factor : 0.0f; |
|
|
|
|
|
blend_factor += (target_blend - blend_factor) * 0.05f; // Smooth transition both ways
|
|
|
|
|
|
|
|
|
camera.setScale(current_zoom); |
|
|
if (blend_factor > 0.001f) { // Apply blended scale if we have any blend factor
|
|
|
|
|
|
final_scale = ofLerp(current_zoom, 0.3, blend_factor); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if(!glm::any(glm::isnan((target_pos)))){ |
|
|
if(!glm::any(glm::isnan((target_pos)))){ |
|
|
glm::vec3 new_pos = current_pos + (target_pos - current_pos) * 0.01f; |
|
|
glm::vec3 new_pos = current_pos + (target_pos - current_pos) * 0.01f; |
|
@ -92,14 +160,17 @@ void Bullet::update(bool& is_controller_active, Node& chosen_node, vector<Node*> |
|
|
camera.setPosition(0, 0, -40); |
|
|
camera.setPosition(0, 0, -40); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
camera.setScale(final_scale); |
|
|
|
|
|
|
|
|
|
|
|
glm::vec3 new_pos = current_pos + camera_velocity * d_time; |
|
|
|
|
|
|
|
|
|
|
|
camera.setPosition(new_pos); |
|
|
|
|
|
|
|
|
last_chosen_node = chosen_node; |
|
|
last_chosen_node = chosen_node; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Bullet::draw(){ |
|
|
void Bullet::draw(){ |
|
|
|
|
|
std::lock_guard<std::mutex> lock(shapeMutex); |
|
|
float shapes_drawn = 0; |
|
|
float shapes_drawn = 0; |
|
|
|
|
|
|
|
|
gridSize = calculateGridSize(camera.getScale().x); |
|
|
gridSize = calculateGridSize(camera.getScale().x); |
|
@ -206,6 +277,9 @@ void Bullet::addMesh(ofMesh _mesh, ofMesh _simple_mesh, Node& _node){ |
|
|
s->create( world.world, start_location, startRot, 3.); |
|
|
s->create( world.world, start_location, startRot, 3.); |
|
|
s->add(); |
|
|
s->add(); |
|
|
s->getRigidBody()->setActivationState(DISABLE_DEACTIVATION); |
|
|
s->getRigidBody()->setActivationState(DISABLE_DEACTIVATION); |
|
|
|
|
|
s->getRigidBody()->forceActivationState(DISABLE_DEACTIVATION); |
|
|
|
|
|
s->getRigidBody()->setSleepingThresholds(0.0f, 0.0f); |
|
|
|
|
|
s->getRigidBody()->setDeactivationTime(btScalar(BT_INFINITY)); // Never deactivate
|
|
|
s->getRigidBody()->setAngularFactor(btVector3(0, 0, 1)); |
|
|
s->getRigidBody()->setAngularFactor(btVector3(0, 0, 1)); |
|
|
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)); |
|
@ -242,8 +316,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); |
|
|
glm::vec3 rand_vel(ofRandom(-1, 1)); |
|
|
glm::vec3 rand_vel(ofRandom(-5, 5), ofRandom(-5, 5), 0); |
|
|
nodes[i].collider->applyCentralForce((1.0f * norm_dir)); |
|
|
nodes[i].collider->applyCentralForce((1.0f * norm_dir) + rand_vel); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -314,8 +388,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)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |