mitsuba-af602c6fd98a/src/shapes/deformable.cpp
/// Cast a normal (i.e. non-shadow) ray against a specific animated triangle
Cast a normal  ray against a specific animated triangle
Cast a normal ray against a specific animated triangle
inline bool intersect(const Ray &ray, IndexType index,
			Float mint, Float maxt, Float &t, void *tmp) const {
		IntersectionCache *cache = static_cast<IntersectionCache *>(tmp);
		IndexType shapeIndex = findShape(index);
		IndexType frameIndex = findFrame(ray.time);
		Float alpha = std::max((Float) 0.0f, std::min((Float) 1.0f,
			(ray.time - m_times[frameIndex])
			/ (m_times[frameIndex + 1] - m_times[frameIndex])));
		const Triangle &tri = m_meshes[0][shapeIndex]->getTriangles()[index];
		const Point *pos0 = m_meshes[frameIndex  ][shapeIndex]->getVertexPositions();
		const Point *pos1 = m_meshes[frameIndex+1][shapeIndex]->getVertexPositions();
		Point p[3];
		for (int i=0; i<3; ++i)
			p[i] = (1 - alpha) * pos0[tri.idx[i]] + alpha * pos1[tri.idx[i]];
		Float tempU, tempV, tempT;
		if (!Triangle::rayIntersect(p[0], p[1], p[2], ray, tempU, tempV, tempT))
			return false;
		if (tempT < mint || tempT > maxt)
			return false;
		t = tempT;
		cache->frameIndex = frameIndex;
		cache->alpha = alpha;
		cache->shapeIndex = shapeIndex;
		cache->primIndex = index;
		cache->u = tempU;
		cache->v = tempV;
		return true;
	}
inline bool intersect ( const Ray & ray , IndexType index , Float mint , Float maxt , Float & t , void * tmp ) const { IntersectionCache * cache = static_cast < IntersectionCache * > ( tmp ) ; IndexType shapeIndex = findShape ( index ) ; IndexType frameIndex = findFrame ( ray . time ) ; Float alpha = std :: max ( ( Float ) 0.0f , std :: min ( ( Float ) 1.0f , ( ray . time - m_times [ frameIndex ] ) / ( m_times [ frameIndex + 1 ] - m_times [ frameIndex ] ) ) ) ; const Triangle & tri = m_meshes [ 0 ] [ shapeIndex ] -> getTriangles ( ) [ index ] ; const Point * pos0 = m_meshes [ frameIndex ] [ shapeIndex ] -> getVertexPositions ( ) ; const Point * pos1 = m_meshes [ frameIndex + 1 ] [ shapeIndex ] -> getVertexPositions ( ) ; Point p [ 3 ] ; for ( int i = 0 ; i < 3 ; ++ i ) p [ i ] = ( 1 - alpha ) * pos0 [ tri . idx [ i ] ] + alpha * pos1 [ tri . idx [ i ] ] ; Float tempU , tempV , tempT ; if ( ! Triangle :: rayIntersect ( p [ 0 ] , p [ 1 ] , p [ 2 ] , ray , tempU , tempV , tempT ) ) return false ; if ( tempT < mint || tempT > maxt ) return false ; t = tempT ; cache -> frameIndex = frameIndex ; cache -> alpha = alpha ; cache -> shapeIndex = shapeIndex ; cache -> primIndex = index ; cache -> u = tempU ; cache -> v = tempV ; return true ; }
Cast a normal (i.e.
Cast a normal ( i . e .
/* Compute interpolated positions */