v 0. Pasted by timai as cpp at 2008-01-13 19:01:58 MSK and set expiration to never.

Paste will expire never.

  1. vec2 land_quad_size(
  2.     math::aabbox_width( m_land_bbox ) / ( land_width - 1 ) ,
  3.     math::aabbox_depth( m_land_bbox ) / ( land_height - 1 ) );
  4.  
  5.  
  6. for( unsigned int g = 0 ; g < grass_count ; g++ ) {
  7.  
  8.     vec3 & grass_pos = positions[ g ];
  9.  
  10.     vec2 offset_pos( grass_pos.x - m_land_bbox.min.x, grass_pos.z - m_land_bbox.min.z );
  11.    
  12.     unsigned int quad_offset_x = ( unsigned int )floor( offset_pos.x / land_quad_size.x );
  13.     unsigned int quad_offset_y = ( unsigned int )floor( offset_pos.y / land_quad_size.y );
  14.  
  15.     unsigned int quad_index = ( quad_offset_y * ( land_width - 1 ) + quad_offset_x ) * 32;
  16.  
  17.     assert( quad_index < m_land_indices->size() );
  18.  
  19.     bool intersection;
  20.  
  21.  
  22.     intersection = math::triangle_intersect_ray(
  23.         vertices[ indices[ quad_index + 0 ] ],
  24.         vertices[ indices[ quad_index + 1 ] ],
  25.         vertices[ indices[ quad_index + 2 ] ],
  26.         grass_pos,
  27.         vec3( 0.f, 1.f, 0.f ),
  28.         grass_pos );
  29.  
  30.     if( !intersection ) {
  31.  
  32.         intersection = math::triangle_intersect_ray(
  33.             vertices[ indices[ quad_index + 3 ] ],
  34.             vertices[ indices[ quad_index + 4 ] ],
  35.             vertices[ indices[ quad_index + 5 ] ],
  36.             grass_pos,
  37.             vec3( 0.f, 1.f, 0.f ),
  38.             grass_pos );
  39.  
  40.         assert( intersection );
  41.  
  42.     }
  43.  
  44. }


Editing is locked.