コード例 #1
0
ファイル: clipping.cpp プロジェクト: 65apps/omim
void InsertCorners(vector<m2::PointD> const & corners,
                   m2::PointD const & p1, m2::PointD const & p2, m2::PointD const & p3,
                   AddPoligonPoint const & addPoligonPoint, int code1, int code2)
{
  int cornerInd = GetRectSideIndex(code1);
  int endCornerInd = GetRectSideIndex(code2);

  if (!IsPointInsideTriangle(corners[cornerInd], p1, p2, p3))
  {
    if (!IsPointInsideTriangle(corners[endCornerInd], p1, p2, p3))
      return;
    swap(cornerInd, endCornerInd);
  }

  while (cornerInd != endCornerInd)
  {
    addPoligonPoint(corners[cornerInd]);
    cornerInd = (cornerInd + 1) % 4;
  }
}
コード例 #2
0
ファイル: clipping.cpp プロジェクト: 65apps/omim
void ClipTriangleByRect(m2::RectD const & rect, m2::PointD const & p1,
                        m2::PointD const & p2, m2::PointD const & p3,
                        ClipTriangleByRectResultIt const & resultIterator)
{
  if (resultIterator == nullptr)
    return;

  if (rect.IsPointInside(p1) && rect.IsPointInside(p2) && rect.IsPointInside(p3))
  {
    resultIterator(p1, p2, p3);
    return;
  }

  const double kEps = 1e-8;
  vector<m2::PointD> poligon;
  auto const addPoligonPoint = [&poligon, kEps](m2::PointD const & pt)
  {
    if (poligon.empty() || !poligon.back().EqualDxDy(pt, kEps))
      poligon.push_back(pt);
  };

  vector<m2::PointD> const corners = { rect.LeftTop(), rect.RightTop(), rect.RightBottom(), rect.LeftBottom() };

  int firstClipCode[3];
  int lastClipCode[3];
  bool intersected[3];

  intersected[0] = IntersectEdge(rect, corners, p1, p2, p3, addPoligonPoint,
                                 0, 0, firstClipCode[0], lastClipCode[0]);

  intersected[1] = IntersectEdge(rect, corners, p2, p3, p1, addPoligonPoint,
                                 lastClipCode[0], 0, firstClipCode[1], lastClipCode[1]);

  intersected[2] = IntersectEdge(rect, corners, p3, p1, p2, addPoligonPoint,
                                 lastClipCode[1] != 0 ? lastClipCode[1] : lastClipCode[0],
                                 firstClipCode[0] != 0 ? firstClipCode[0] : firstClipCode[1],
                                 firstClipCode[2], lastClipCode[2]);

  int const intersectCount = intersected[0] + intersected[1] + intersected[2];
  if (intersectCount == 0)
  {
    if (IsPointInsideTriangle(rect.Center(), p1, p2, p3))
    {
      resultIterator(rect.LeftTop(), rect.RightTop(), rect.RightBottom());
      resultIterator(rect.RightBottom(), rect.LeftBottom(), rect.LeftTop());
    }
    return;
  }

  if (intersectCount == 1 && intersected[2])
    InsertCorners(corners, p1, p2, p3, addPoligonPoint, lastClipCode[2], firstClipCode[2]);

  if (!poligon.empty() && poligon.back().EqualDxDy(poligon[0], kEps))
    poligon.pop_back();

  if (poligon.size() < 3)
    return;

  for (size_t i = 0; i < poligon.size() - 2; ++i)
    resultIterator(poligon[0], poligon[i + 1], poligon[i + 2]);
}
コード例 #3
0
//-------------------------------------------------------------
//- GetMeshPointFromSecondTexCoord
//- Get real vertex position and normal from mesh according to TexCoord1
//-------------------------------------------------------------
bool CSGPModelMF1::GetMeshPointFromSecondTexCoord( Vector3D& position, Vector3D& normal, const Vector2D& uv, const Matrix4x4& modelMatrix  )
{
	for( uint32 i=0; i<m_Header.m_iNumMeshes; i++ )
	{
		if( !m_pLOD0Meshes[i].m_pTexCoords1 || (m_pLOD0Meshes[i].m_iNumUV1==0) )
			continue;

		jassert( m_pLOD0Meshes[i].m_iNumUV0 == m_pLOD0Meshes[i].m_iNumUV1 );


		for( uint32 j=0; j<m_pLOD0Meshes[i].m_iNumIndices; j += 3 )
		{
			Vector3D v0(
				m_pLOD0Meshes[i].m_pVertex[  m_pLOD0Meshes[i].m_pIndices[j  ]  ].vPos[0],
				m_pLOD0Meshes[i].m_pVertex[  m_pLOD0Meshes[i].m_pIndices[j  ]  ].vPos[1],
				m_pLOD0Meshes[i].m_pVertex[  m_pLOD0Meshes[i].m_pIndices[j  ]  ].vPos[2] );
			Vector3D v1(
				m_pLOD0Meshes[i].m_pVertex[  m_pLOD0Meshes[i].m_pIndices[j+1]  ].vPos[0],
				m_pLOD0Meshes[i].m_pVertex[  m_pLOD0Meshes[i].m_pIndices[j+1]  ].vPos[1],
				m_pLOD0Meshes[i].m_pVertex[  m_pLOD0Meshes[i].m_pIndices[j+1]  ].vPos[2] );
			Vector3D v2(
				m_pLOD0Meshes[i].m_pVertex[  m_pLOD0Meshes[i].m_pIndices[j+2]  ].vPos[0],
				m_pLOD0Meshes[i].m_pVertex[  m_pLOD0Meshes[i].m_pIndices[j+2]  ].vPos[1],
				m_pLOD0Meshes[i].m_pVertex[  m_pLOD0Meshes[i].m_pIndices[j+2]  ].vPos[2] );

			v0 = v0 * modelMatrix;
			v1 = v1 * modelMatrix;
			v2 = v2 * modelMatrix;

			Vector2D t0(m_pLOD0Meshes[i].m_pTexCoords1[  m_pLOD0Meshes[i].m_pIndices[j  ]  ].m_fTexCoord[0],
						m_pLOD0Meshes[i].m_pTexCoords1[  m_pLOD0Meshes[i].m_pIndices[j  ]  ].m_fTexCoord[1]	);
			Vector2D t1(m_pLOD0Meshes[i].m_pTexCoords1[  m_pLOD0Meshes[i].m_pIndices[j+1]  ].m_fTexCoord[0],
						m_pLOD0Meshes[i].m_pTexCoords1[  m_pLOD0Meshes[i].m_pIndices[j+1]  ].m_fTexCoord[1]	);
			Vector2D t2(m_pLOD0Meshes[i].m_pTexCoords1[  m_pLOD0Meshes[i].m_pIndices[j+2]  ].m_fTexCoord[0],
						m_pLOD0Meshes[i].m_pTexCoords1[  m_pLOD0Meshes[i].m_pIndices[j+2]  ].m_fTexCoord[1]	);

			Vector3D samplePos = TexcoordToPos( v0, v1, v2, t0, t1, t2, uv );
			if( !IsPointInsideTriangle(v0, v1, v2, samplePos, 0.1f) )
				continue;
			else
			{
				Vector4D n0(
					m_pLOD0Meshes[i].m_pVertex[  m_pLOD0Meshes[i].m_pIndices[j  ]  ].vNormal[0],
					m_pLOD0Meshes[i].m_pVertex[  m_pLOD0Meshes[i].m_pIndices[j  ]  ].vNormal[1],
					m_pLOD0Meshes[i].m_pVertex[  m_pLOD0Meshes[i].m_pIndices[j  ]  ].vNormal[2],
					0);
				Vector4D n1(
					m_pLOD0Meshes[i].m_pVertex[  m_pLOD0Meshes[i].m_pIndices[j+1]  ].vNormal[0],
					m_pLOD0Meshes[i].m_pVertex[  m_pLOD0Meshes[i].m_pIndices[j+1]  ].vNormal[1],
					m_pLOD0Meshes[i].m_pVertex[  m_pLOD0Meshes[i].m_pIndices[j+1]  ].vNormal[2],
					0);
				Vector4D n2(
					m_pLOD0Meshes[i].m_pVertex[  m_pLOD0Meshes[i].m_pIndices[j+2]  ].vNormal[0],
					m_pLOD0Meshes[i].m_pVertex[  m_pLOD0Meshes[i].m_pIndices[j+2]  ].vNormal[1],
					m_pLOD0Meshes[i].m_pVertex[  m_pLOD0Meshes[i].m_pIndices[j+2]  ].vNormal[2],
					0);


				n0 = n0 * modelMatrix;
				n1 = n1 * modelMatrix;
				n2 = n2 * modelMatrix;

				Vector3D nn0(n0.x, n0.y, n0.z);
				Vector3D nn1(n1.x, n1.y, n1.z);
				Vector3D nn2(n2.x, n2.y, n2.z);
				nn0.Normalize();
				nn1.Normalize();
				nn2.Normalize();

				normal = TexcoordToPos( nn0, nn1, nn2, t0, t1, t2, uv );
				normal.Normalize();
				position = samplePos;

				return true;
			}
		}
	}
	return false;
}