Ejemplo n.º 1
0
void
plane::
extendBy ( const box3& box )
{
	if ( !box.isEmpty() )
	{
		vec3 a ( math::vec3::NoInit );
		vec3 b ( math::vec3::NoInit );
		box.get ( a, b );
		extendBy ( a );
		extendBy ( b );
	}
}
Ejemplo n.º 2
0
        //! Intersect with an axis aligned box, returning true if there is an intersection.
        bool intersect(const box3<Type>& b) const
        {
            // Arvo's algorithm.
            Type d = 0;

            //find the square of the distance from the sphere to the box
            for (unsigned int i = 0; i < 3; i++) {
                if (m_center[i] < b.getMin()[i]) {
                    Type s = m_center[i] - b.getMin()[i];
                    d += s * s;
                } else if (m_center[i] > b.getMax()[i]) {
                    Type s = m_center[i] - b.getMax()[i];
                    d += s * s;
                }
            }
            return d <= m_radius * m_radius;
        }
Ejemplo n.º 3
0
//collision move elipsoid with box
bool kgmCollision::collision(vec3& start, vec3& end, float rx, float ry, float rz,
                             box3& b, mtx4& btr)
{
  int i = 0;
  vec3 box_points[8];
  vec3 box_sides[6][4];
  b.points(box_points);

  for(i = 0; i < 8; i++)
    box_points[i] = btr * box_points[i];

  box_sides[0][0] = box_points[0];
  box_sides[0][1] = box_points[1];
  box_sides[0][2] = box_points[5];
  box_sides[0][3] = box_points[4];
  box_sides[1][0] = box_points[1];
  box_sides[1][1] = box_points[3];
  box_sides[1][2] = box_points[7];
  box_sides[1][3] = box_points[5];
  box_sides[2][0] = box_points[3];
  box_sides[2][1] = box_points[2];
  box_sides[2][2] = box_points[6];
  box_sides[2][3] = box_points[7];
  box_sides[3][0] = box_points[2];
  box_sides[3][1] = box_points[0];
  box_sides[3][2] = box_points[4];
  box_sides[3][3] = box_points[6];
  box_sides[4][0] = box_points[0];
  box_sides[4][1] = box_points[2];
  box_sides[4][2] = box_points[3];
  box_sides[4][3] = box_points[1];
  box_sides[5][0] = box_points[4];
  box_sides[5][1] = box_points[5];
  box_sides[5][2] = box_points[7];
  box_sides[5][3] = box_points[6];

  float dist = -1.0f;
  vec3  ptins;
  m_collision = false;

  for(i = 0; i < 6; i++)
  {
    plane	pln(box_sides[i][0], box_sides[i][1], box_sides[i][2]);
    float edist = pln.distance(end);

    if(collision(start, end, rx, ry, rz, box_sides[i], 4))
    {
      ptins = m_point;
      m_collision = true;

      if(edist > 0.0f)
        break;
    }
  }

  return m_collision;
}
Ejemplo n.º 4
0
        void extendBy(const box3<Type>& bb)
        {
            if (bb.isEmpty())
                return;

            if (box3<Type>::isEmpty()) {
                *this = bb;
                m_matrix.makeIdentity();
                m_invertedMatrix.makeIdentity();
                return;
            }
        }
Ejemplo n.º 5
0
bool kgmCollision::ob_collision(box3& s_box, vec3& s_start, vec3& s_end, box3& d_box,
                                vec3& d_start, vec3& d_end)
{
  vec3 s_dir = s_end - s_start;
  vec3 d_dir = d_end - d_start;
  vec3 s_nor = s_dir.normal();
  vec3 d_nor = d_dir.normal();

  //mtx4 s_rot;
  //mtx4 d_rot;

  f32  s_len = s_dir.length();
  f32  d_len = d_dir.length();

  vec3 s_pos = s_start + s_nor * s_len * 0.5;
  vec3 d_pos = d_start + d_nor * d_len * 0.5;

  vec3 s_dim = s_box.dimension();
  vec3 d_dim = d_box.dimension();

  s_dim.x += s_len;
  d_dim.x += d_len;

  //s_rot.rotate(0, s_nor);
  //d_rot.rotate(0, d_nor);

  if(s_nor.length() == 0.0)
    s_nor = vec3(1, 0, 0);

  if(d_nor.length() == 0.0)
    d_nor = vec3(1, 0, 0);

  kgmOBox3d<f32> s_obox(s_pos, s_nor, s_dim);
  kgmOBox3d<f32> d_obox(d_pos, d_nor, d_dim);

  if(s_obox.intersect(d_obox) && d_obox.intersect(s_obox))
    return true;

  return false;
}
Ejemplo n.º 6
0
void
sphere::
extendBy ( const box3& box )
{
	PNIMATHUNTESTED;

	if ( !box.isEmpty() )
	{
		sphere tmpsphere;
		tmpsphere.extendBy ( box.minPos );
		tmpsphere.extendBy ( box.maxPos );
		
		extendBy ( tmpsphere );
	}
}
Ejemplo n.º 7
0
 //! Make the sphere containing a given box
 void circumscribe(const box3<Type>& box)
 {
     m_center = box.getCenter();
     m_radius = (box.getMax() - m_center).length();
 }