Example #1
0
bool CSceneData::pickCell(int nCellX, int nCellY, const Vec3D& vRayPos, const Vec3D& vRayDir, Vec3D* pPos)const
{
	if (isCellIn(nCellX,nCellY))
	{
		const TerrainCell* cell = getCell(nCellX,nCellY);
		Vec3D v0((float)(nCellX),	cell->fHeight,					(float)(nCellY));
		Vec3D v1((float)(nCellX),	(cell+m_nWidth+1)->fHeight,		(float)(nCellY+1));
		Vec3D v2((float)(nCellX+1),	(cell+m_nWidth+1+1)->fHeight,	(float)(nCellY+1));
		Vec3D v3((float)(nCellX+1),	(cell+1)->fHeight,				(float)(nCellY));
		Vec3D vOut;
		if(IntersectTri(v1,v2,v0,vRayPos,vRayDir,vOut))
		{
			if (pPos)
			{
				*pPos = vOut;
			}
			return true;
		}
		else if (IntersectTri(v3,v0,v2,vRayPos,vRayDir,vOut))
		{
			if (pPos)
			{
				*pPos = vOut;
			}
			return true;
		}
	}
	return false;
}
Example #2
0
File: Ray.cpp Project: arajar/funk
	bool Ray::IntersectTri( v3 a_pt0, v3 a_pt1, v3 a_pt2, const matrix& a_mat )
	{
		v4 pt0 = a_mat * v4(a_pt0,1.0f);
		v4 pt1 = a_mat * v4(a_pt1,1.0f);
		v4 pt2 = a_mat * v4(a_pt2,1.0f);
		
		return IntersectTri(pt0.xyz(), pt1.xyz(), pt2.xyz() );
	}
Example #3
0
bool SubMeshIntersect(const CSubMesh& subMesh,const Vec3D& vRayPos , const Vec3D& vRayDir, Vec3D& vOut)
{
	size_t size=subMesh.m_setVertexIndex.size()/3;
	for(size_t i=0;i<size;++i)
	{
		if (IntersectTri(subMesh.pos[subMesh.m_setVertexIndex[i*3].p],subMesh.pos[subMesh.m_setVertexIndex[i*3+1].p],subMesh.pos[subMesh.m_setVertexIndex[i*3+2].p],vRayPos,vRayDir,vOut))
		{
			return true;
		}
	}
	return false;
}