コード例 #1
0
bool ckCdt::intersect(ckVec* pos, const Ray& ray, const Tri& tri)
{
    if (!checkTouch(ray.m_aabb, tri.m_aabb))
    {
        return false;
    }

    ckVec ray_dir = ray.m_to - ray.m_from;

    r32 dist;

    if (intersectTri(&dist, ray.m_from, ray_dir, tri) && dist <= 1.0f)
    {
        if (pos)
        {
            *pos = ray.m_from + ray_dir * dist;
        }

        return true;
    }
    else
    {
        return false;
    }
}
コード例 #2
0
 void SubdivPatch1Intersector1::subdivide_intersect1_bspline(const Precalculations& pre,
                                                             Ray& ray,
                                                             const BSplinePatch &patch,
                                                             const unsigned int geomID,
                                                             const unsigned int primID,
                                                             const Vec2f &s,
                                                             const Vec2f &t,
                                                             const unsigned int subdiv_level)
 {
   if (subdiv_level == 0)
   {
     Vec3fa vtx[4];
     vtx[0] = patch.eval(s[0],t[0]);
     
     vtx[1] = patch.eval(s[1],t[0]);
     vtx[2] = patch.eval(s[1],t[1]);
     vtx[3] = patch.eval(s[0],t[1]);
     intersectTri(vtx[0],
                  vtx[1],
                  vtx[2],
                  ray,
                  geomID,
                  primID,NULL); 
     
     intersectTri(vtx[2],
                  vtx[3],
                  vtx[0],
                  ray,
                  geomID,
                  primID,NULL); 
   }
   else
   {
     const float mid_s = 0.5f * (s[0]+s[1]);
     const float mid_t = 0.5f * (t[0]+t[1]);
     Vec2f s_left(s[0],mid_s);
     Vec2f s_right(mid_s,s[1]);
     Vec2f t_left(t[0],mid_t);
     Vec2f t_right(mid_t,t[1]);
     subdivide_intersect1_bspline(pre,ray,patch,geomID,primID,s_left ,t_left,subdiv_level - 1);
     subdivide_intersect1_bspline(pre,ray,patch,geomID,primID,s_right,t_left,subdiv_level - 1);
     subdivide_intersect1_bspline(pre,ray,patch,geomID,primID,s_right,t_right,subdiv_level - 1);
     subdivide_intersect1_bspline(pre,ray,patch,geomID,primID,s_left ,t_right,subdiv_level - 1);
   }
 }
コード例 #3
0
ファイル: Mesh.cpp プロジェクト: captainhead/Raygun
bool MeshShape::intersect(const Ray &r, float &t, Vector &p, Vector &n, float &u, float &v)
{
	return intersectTri(r, t, p, n, u, v);

	// Call intersection method for triangles or quads
//	if(vertsPerFace == 3)
//		return intersectTri(r, t, p, n, u, v);
//	else if(vertsPerFace == 4)
//		return intersectQuad(r, t, p, n, u, v);
//	return false;
}
コード例 #4
0
 void SubdivPatch1Intersector1::subdivide_intersect1(const Precalculations& pre,
                                                     Ray& ray,
                                                     const BSplinePatch &patch,
                                                     const unsigned int geomID,
                                                     const unsigned int primID,
                                                     const unsigned int subdiv_level)
 {
   if (subdiv_level == 0)
   {
     __aligned(64) FinalQuad finalQuad;
     patch.init( finalQuad );
     
     intersectTri(finalQuad.vtx[0],
                  finalQuad.vtx[1],
                  finalQuad.vtx[2],
                  ray,
                  geomID,
                  primID,NULL); 
     
     intersectTri(finalQuad.vtx[2],
                  finalQuad.vtx[3],
                  finalQuad.vtx[0],
                  ray,
                  geomID,
                  primID,NULL); 
   }
   else
   {
     BSplinePatch subpatches[4];
     patch.subdivide(subpatches);
     for (size_t i=0;i<4;i++)
       if (intersectBounds(pre,ray,subpatches[i].bounds()))
         subdivide_intersect1(pre,
                              ray,
                              subpatches[i],
                              geomID,
                              primID,
                              subdiv_level - 1);	    
     
   } 
 }
コード例 #5
0
void OgreMesh::intersect(Ogre::Node *node, const Ogre::Ray &ray, IntersectResult &rtn)
{
  rtn = IntersectResult();
  const Ogre::Vector3 &position = node->_getDerivedPosition();
  const Ogre::Quaternion &orient = node->_getDerivedOrientation();
  const Ogre::Vector3 &scale = node->_getDerivedScale();

  std::vector<Triangle>::iterator itr,itere=mTriangles.end();
  int i = 0;
  for (itr = mTriangles.begin(); itr != itere; itr++) {
    Triangle newt = *itr;
    newt.v1.coord = (orient * (newt.v1.coord * scale)) + position;
    newt.v2.coord = (orient * (newt.v2.coord * scale)) + position;
    newt.v3.coord = (orient * (newt.v3.coord * scale)) + position;
    intersectTri(ray, rtn, &newt, false);
    if (rtn.intersected) { rtn.tri = *itr; }
    //intersectTri(ray, rtn, &*itr);
/*    if (i < 10) {
      std::cout << "c1:"<<newt.v1.coord << " c2:"<<newt.v2.coord << " c3:"<<newt.v3.coord << " u:"<<newt.v2.u<<" v:"<<newt.v2.v<<std::endl
    }*/
  }
}