Guest User

Untitled

a guest
Jul 15th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.10 KB | None | 0 0
  1. Point* neighbour1 = &grid[y + yoffset[0]][x + xoffset[0]];
  2.                 Point* neighbour2 = &grid[y + yoffset[1]][x + xoffset[1]];
  3.                 Point* neighbour3 = &grid[y + yoffset[2]][x + xoffset[2]];
  4.                 Point* neighbour4 = &grid[y + yoffset[3]][x + xoffset[3]];
  5.  
  6.                 vector3 n1, n2, n3, n4;
  7.  
  8.                 n1 = neighbour1->pos - pointpos;
  9.                 n2 = neighbour2->pos - pointpos;
  10.                 n3 = neighbour3->pos - pointpos;
  11.                 n4 = neighbour4->pos - pointpos;
  12.  
  13.                 __m128 distance_x = _mm_set_ps( n1.x, n2.x, n3.x, n4.x );
  14.                 __m128 distance_y = _mm_set_ps( n1.y, n2.y, n3.y, n4.y );
  15.                 __m128 distance_z = _mm_set_ps( n1.z, n2.z, n3.z, n4.z );
  16.  
  17.                 distance_x = _mm_mul_ps( distance_x, distance_x );
  18.                 distance_y = _mm_mul_ps( distance_y, distance_y );
  19.                 distance_z = _mm_mul_ps( distance_z, distance_z );
  20.  
  21.                 __m128 distance = _mm_add_ps( distance_x, _mm_add_ps( distance_y, distance_z ) );
  22.                 __m128 restlen = _mm_set_ps( grid[y][x].restlength[0], grid[y][x].restlength[1], grid[y][x].restlength[2], grid[y][x].restlength[3] );
  23.                 distance = _mm_sqrt_ps( distance );
  24.                 __m128 cmp_distance = _mm_cmpgt_ps( distance, restlen );
  25.  
  26.                 int check = _mm_movemask_ps(cmp_distance);
  27.  
  28.                 cmp_distance = _mm_and_ps( cmp_distance, distance );
  29.  
  30.                 if ( check == 0 ) continue;
  31.  
  32.                 __m128 restlen_res = _mm_div_ps( distance, restlen );
  33.                 restlen_res = _mm_sub_ps( restlen_res, _mm_set_ps1( 1 ) );
  34.  
  35.                 float extra;
  36.                
  37.                 if ( cmp_distance.m128_f32[0] != 0 )
  38.                 {
  39.                     extra = (restlen_res.m128_f32[0]);
  40.                     pointpos += extra * n1 * 0.5f;
  41.                     neighbour1->pos -= extra * n1 * 0.5f;
  42.                 }
  43.  
  44.                 if ( cmp_distance.m128_f32[1] != 0 )
  45.                 {
  46.                     extra = (restlen_res.m128_f32[1]);
  47.                     pointpos += extra * n2 * 0.5f;
  48.                     neighbour2->pos -= extra * n2 * 0.5f;
  49.                 }
  50.                
  51.                 if ( cmp_distance.m128_f32[2] != 0 )
  52.                 {
  53.                     extra = (restlen_res.m128_f32[2]);
  54.                     pointpos += extra * n3 * 0.5f;
  55.                     neighbour3->pos -= extra * n3 * 0.5f;
  56.                 }
  57.  
  58.                 if ( cmp_distance.m128_f32[3] != 0 )
  59.                 {
  60.                     extra = (restlen_res.m128_f32[3]);
  61.                     pointpos += extra * n4 * 0.5f;
  62.                     neighbour4->pos -= extra * n4 * 0.5f;
  63.                 }
Add Comment
Please, Sign In to add comment