a/gpup/demo-2-springs.ccb/gpup/demo-2-springs.cc
-/// LSU EE 4702-1 (Fall 2017), GPU Programming
+/// LSU EE 4702-1 (Fall 2019), GPU Programming
//
/// Simple Demo of Point Masses and Springs
World::ball_setup_1()
// Desired distance between adjacent balls.
//
- pVect ball_separation(0, distance_relaxed, 0); // Points up.
+ pNorm ball_separation_1(1, distance_relaxed, 0);
+
+ pVect ball_separation = distance_relaxed * ball_separation_1;
for ( int i=0; i<chain_length; i++ )
{
World::time_step_cpu_easy(double delta_t)
// Spring Force from Neighbor Balls
//
- for ( int direction: { -1, +1 } )
+ for ( int direction: { -2, -1, +1, +2 } )
{
const int n_idx = i + direction; // Compute neighbor index.
// Skip this neighbor if neighbor doesn't exit.
//
if ( n_idx < 0 ) continue;
- if ( n_idx == chain_length ) continue;
+ if ( n_idx >= chain_length ) continue;
Ball* const neighbor_ball = &balls[n_idx];
World::time_step_cpu_easy(double delta_t)
// or compressed (negative value).
//
const float spring_stretch =
- distance_between_balls - distance_relaxed;
+ distance_between_balls - distance_relaxed * abs(direction);
// Add on the force due to the neighbor_ball.
//