示例#1
0
文件: mesh.c 项目: bilboed/wine
static void D3DXIntersectTriTest(void)
{
    BOOL exp_res, got_res;
    D3DXVECTOR3 position, ray, vertex[3];
    FLOAT exp_dist, got_dist, exp_u, got_u, exp_v, got_v;

    vertex[0].x = 1.0f; vertex[0].y = 0.0f; vertex[0].z = 0.0f;
    vertex[1].x = 2.0f; vertex[1].y = 0.0f; vertex[1].z = 0.0f;
    vertex[2].x = 1.0f; vertex[2].y = 1.0f; vertex[2].z = 0.0f;

    position.x = -14.5f; position.y = -23.75f; position.z = -32.0f;

    ray.x = 2.0f; ray.y = 3.0f; ray.z = 4.0f;

    exp_res = TRUE; exp_u = 0.5f; exp_v = 0.25f; exp_dist = 8.0f;

    got_res = D3DXIntersectTri(&vertex[0],&vertex[1],&vertex[2],&position,&ray,&got_u,&got_v,&got_dist);
    ok( got_res == exp_res, "Expected result = %d, got %d\n",exp_res,got_res);
    ok( compare(exp_u,got_u), "Expected u = %f, got %f\n",exp_u,got_u);
    ok( compare(exp_v,got_v), "Expected v = %f, got %f\n",exp_v,got_v);
    ok( compare(exp_dist,got_dist), "Expected distance = %f, got %f\n",exp_dist,got_dist);

/*Only positive ray is taken in account*/

    vertex[0].x = 1.0f; vertex[0].y = 0.0f; vertex[0].z = 0.0f;
    vertex[1].x = 2.0f; vertex[1].y = 0.0f; vertex[1].z = 0.0f;
    vertex[2].x = 1.0f; vertex[2].y = 1.0f; vertex[2].z = 0.0f;

    position.x = 17.5f; position.y = 24.25f; position.z = 32.0f;

    ray.x = 2.0f; ray.y = 3.0f; ray.z = 4.0f;

    exp_res = FALSE;

    got_res = D3DXIntersectTri(&vertex[0],&vertex[1],&vertex[2],&position,&ray,&got_u,&got_v,&got_dist);
    ok( got_res == exp_res, "Expected result = %d, got %d\n",exp_res,got_res);

/*Intersection between ray and triangle in a same plane is considered as empty*/

    vertex[0].x = 4.0f; vertex[0].y = 0.0f; vertex[0].z = 0.0f;
    vertex[1].x = 6.0f; vertex[1].y = 0.0f; vertex[1].z = 0.0f;
    vertex[2].x = 4.0f; vertex[2].y = 2.0f; vertex[2].z = 0.0f;

    position.x = 1.0f; position.y = 1.0f; position.z = 0.0f;

    ray.x = 1.0f; ray.y = 0.0f; ray.z = 0.0f;

    exp_res = FALSE;

    got_res = D3DXIntersectTri(&vertex[0],&vertex[1],&vertex[2],&position,&ray,&got_u,&got_v,&got_dist);
    ok( got_res == exp_res, "Expected result = %d, got %d\n",exp_res,got_res);
}
bool Obj::GroundCheck(IN OUT D3DXVECTOR3& groundPos) const
{
	bool find = false;
	D3DXVECTOR3 rayStart(groundPos.x, 1000.0f, groundPos.z);
	D3DXVECTOR3 rayDirection(0, -1, 0);
	for (size_t i = 0; i < objGround.size(); i += 3)
	{
		float u, v, distance;
		find = D3DXIntersectTri(
			&objGround[i],
			&objGround[i + 1],
			&objGround[i + 2],
			&rayStart,
			&rayDirection,
			&u, &v,
			&distance) != 0;
		if (find == true)
		{
			groundPos.y = 1000.0f - distance;
			//groundPos = objGround[i] + ( ( objGround[i + 1] - objGround[i] ) * u ) + ( ( objGround[i + 2] - objGround[i] ) * v );
			break;
		}
	}
	return find;
}
示例#3
0
//-----------------------------------------------------------------------------
// Recursively checks the given ray against the scene's leaves and faces.
//----------------------------------------------------------------------------- 
void SceneManager::RecursiveSceneRayCheck( SceneLeaf *leaf, RayIntersectionResult *result, D3DXVECTOR3 rayPosition, D3DXVECTOR3 rayDirection, float *hitDistance )
{
    // Check against the ray against the scene leaf.
    if( D3DXBoxBoundProbe( &leaf->GetBoundingBox()->min, &leaf->GetBoundingBox()->max, &rayPosition, &rayDirection ) == false ) 
        return;

    // Recursively check the scene's children.
    for( char c = 0; c < 8; c++ )
        if( leaf->children[c] != NULL )
            RecursiveSceneRayCheck( leaf->children[c], result, rayPosition, rayDirection, hitDistance ); 

    // Check the faces in this leaf.
    for( unsigned long f = 0; f < leaf->totalFaces; f++ )
    {
        // Skip this face if its material is set to ignore rays.
        if( m_faces[leaf->faces[f]].renderCache->GetMaterial()->GetIgnoreRay() == true ) 
            continue;

        // Check the ray against this face.
        if( D3DXIntersectTri( (D3DXVECTOR3*)&m_vertices[m_faces[leaf->faces[f]].vertex0], (D3DXVECTOR3*)&m_vertices[m_faces[leaf->faces[f]].vertex1], (D3DXVECTOR3*)&m_vertices[m_faces[leaf->faces[f]].vertex2], &rayPosition, &rayDirection, NULL, NULL, hitDistance ) == TRUE ) 
        {
            if( *hitDistance < result->distance || result->material == NULL )
            {
                ( *result ).distance = *hitDistance;
                ( *result ).material = m_faces[leaf->faces[f]].renderCache->GetMaterial();
            }
        }
    }
}
示例#4
0
void FieldSector::generateHeights()
{
	if(m_heights)
		return;
	m_heights = new D3DXFLOAT16[g_grassSectorSize * g_grassSectorSize];
	TerrainVertex *terrainVertices = core.game->getWorld()->getTerrainManager()->m_vertices;
	int terrainWidth = core.game->getWorld()->getTerrainManager()->m_size;
	float coordinatesModifier = g_grassTileSize / core.game->getWorld()->getTerrainManager()->m_hmGeoStep;
	for(int y = 0; y < g_grassSectorSize; y++)
	{
		for(int x = 0; x < g_grassSectorSize; x++)
		{
			float terrainGrassProportion = g_grassTileSize / core.game->getWorld()->getTerrainManager()->m_hmGeoStep;
			//terrainGrassProportion = 0.5f;
			/// filling heightmap with data up
			D3DXPLANE plane;

			int X = x + m_posX;
			int Y = y + m_posY;
			Vec3 p1 = terrainVertices[(int)(Y*terrainGrassProportion)*terrainWidth+(int)(X*terrainGrassProportion)].pos;
			Vec3 p2 = terrainVertices[(int)((Y*terrainGrassProportion)+1)*terrainWidth+(int)(X*terrainGrassProportion)].pos;
			Vec3 p3 = terrainVertices[(int)(Y*terrainGrassProportion)*terrainWidth+(int)(X*terrainGrassProportion)+1].pos;
			Vec3 p4 = terrainVertices[(int)(Y*terrainGrassProportion+1)*terrainWidth+(int)(X*terrainGrassProportion)+1].pos;

			Vec3 resultPos;
			Vec3 upPoint = Vec3((X)*g_grassTileSize, 2000, (Y)*g_grassTileSize);
			Vec3 downPoint = Vec3((X)*g_grassTileSize, -2000, (Y)*g_grassTileSize);

			f32 pU, pV, pDist;

			if(D3DXIntersectTri(&p1, &p2, &p3, &upPoint, &Vec3(0,-1,0), &pU, &pV, &pDist))
				D3DXPlaneFromPoints(&plane, &p1, &p2, &p3);
			else if(D3DXIntersectTri(&p2, &p3, &p4, &upPoint, &Vec3(0,-1,0), &pU, &pV, &pDist))
				D3DXPlaneFromPoints(&plane, &p2, &p3, &p4);	

			D3DXPlaneIntersectLine(&resultPos, &plane, &upPoint, &downPoint);
			D3DXFloat32To16Array(&m_heights[y * g_grassSectorSize + x], &resultPos.y, 1);
		}
	}
}
示例#5
0
//////////////////////////////////////////////////////////////////////////
//	CheckSpearing
//////////////////////////////////////////////////////////////////////////
void ZClothEmblem::CheckSpearing( rvector& bullet_begin_, rvector& bullet_end_, float power_ )
{	
	if(mbIsInFrustrum)
	{
		if(!isInViewFrustum( &mAABB, RGetViewFrustum())) 
			mbIsInFrustrum =false;
	}
	else return;

	rvector dir = bullet_end_ - bullet_begin_;
	D3DXVec3Normalize( &dir, &dir );

	// test line vs AABB
	if( !D3DXBoxBoundProbe( &mAABB.vmin , &mAABB.vmax,	&bullet_begin_, &dir ) )
	{
		return;
	}

	// line vs triangle test and determine which particle get power
	int index[3], sIndex = -1;
	rvector uvt;
	rvector* v[3];

	for( int i = 0 ; i < mpMeshNode->m_face_num; ++i )
	{
        for( int j = 0 ; j < 3; ++j )
		{
			index[j]= mpMeshNode->m_face_list[i].m_point_index[j];
			v[j]	= &m_pX[index[j]];
		}

		if( D3DXIntersectTri( v[0], v[1], v[2], &bullet_begin_, &dir, &uvt.x, &uvt.y, &uvt.z ) ) 
		{
			if( uvt.x + uvt.y < 0.66 )
			{
				sIndex	= index[2];
			}
			else if( uvt.x > uvt.y )
			{
				sIndex	= index[0];
			}
			else
			{
				sIndex	= index[1];
			}

			m_pForce[sIndex]	+= dir * power_;
			break;
		}
	}	
}
示例#6
0
float DesertScenePlane::GetHeight( 
	cGameObject* target )
{
	const auto& groupRepo = static_cast<cObjRenderer*>( 
		m_owner->GetRenderer( ))->GetGroupRepo( );

	BOOL collised = FALSE;
	float hitDist = 0.f;

	for ( auto* groupElem : groupRepo )
	{
		const auto& vertices = groupElem->GetVertex( );
		
		for ( int i = 0; i < vertices.size( ); i += 3 )
		{
			const float rayYPos = 10000.f;
			D3DXVECTOR3 rayPos( target->GetPosition( ).x, rayYPos,
				target->GetPosition( ).z );

			D3DXVECTOR3 v1;
			D3DXVec3TransformCoord( &v1, &vertices[i].p, &m_owner->GetWorld( ));
			D3DXVECTOR3 v2;
			D3DXVec3TransformCoord( &v2, &vertices[i+1].p, &m_owner->GetWorld( ) );
			D3DXVECTOR3 v3;
			D3DXVec3TransformCoord( &v3, &vertices[i+2].p, &m_owner->GetWorld( ) );

			collised = D3DXIntersectTri(
				&v1,
				&v2,
				&v3,
				&rayPos,
				&D3DXVECTOR3( 0.f, -1.f, 0.f ),
				nullptr,
				nullptr,
				&hitDist
			);

			if ( collised == TRUE )
			{
				target->GetPosition( ).y = rayYPos - hitDist;
				return ( rayYPos-hitDist );
			}
		}
	}

	return 0.f;
}
示例#7
0
void cMainGame::CardCollideHandler(cCharacter* pCharacter, cCard* pCard){
	D3DXMATRIXA16 trans;
	D3DXMatrixTranslation(&trans, 
		pCard->GetTransform()->GetPosition().x
		, pCard->GetTransform()->GetPosition().y
		, pCard->GetTransform()->GetPosition().z);
	float fDist = 3000.0f;
	D3DXVECTOR3 a, b, c, startingPoint;
	startingPoint = { pCharacter->GetTransform()->GetPosition().x, fDist, pCharacter->GetTransform()->GetPosition().z };

	for (size_t j = 0; j < pCard->GetSurface().size(); j++){
		
		a = pCard->GetSurface()[j].p;
		D3DXVec3TransformCoord(&a, &a, &trans);
		j++;
		b = pCard->GetSurface()[j].p;
		D3DXVec3TransformCoord(&b, &b, &trans);
		j++;
		c = pCard->GetSurface()[j].p;
		D3DXVec3TransformCoord(&c, &c, &trans);

		float x, y, fDist;

		if (D3DXIntersectTri(&a, &b, &c, &startingPoint, &D3DXVECTOR3(0, -1.0f, 0), &x, &y, &fDist)){
			if (pCard->GetStepStatus() == false){
				pCard->SetStepStatus(true);
				m_vecSteppedCard.push_back(pCard);

				if (m_vecSteppedCard.size() == 2){
					if (m_vecSteppedCard[0]->GetCardType() == m_vecSteppedCard[1]->GetCardType()){
						m_vecSteppedCard[0]->SetMatchedStatus(true);
						m_vecSteppedCard[1]->SetMatchedStatus(true);
						m_nScore += 1;
						m_vecSteppedCard.clear();
					}
					else {
						m_vecSteppedCard[0]->SetStepStatus(false);
						m_vecSteppedCard[1]->SetStepStatus(false);
						m_vecSteppedCard.clear();
					}
				}
				return;
			}
		}
	}
}
示例#8
0
文件: iMap.cpp 项目: arkiny/Direct3D
float cObjMap::GetHeight(OUT bool& isLand, IN D3DXVECTOR3* pvPosition)
{
	D3DXVECTOR3 vPosition = (*pvPosition);
	vPosition.y = 1000.0f;

	float u, v, fDist;
	for (size_t i = 0; i < m_vecFaces.size(); i += 3)
	{
		if (D3DXIntersectTri(&m_vecFaces[i], &m_vecFaces[i + 1], &m_vecFaces[i + 2],
			&vPosition, &D3DXVECTOR3(0, -1, 0), &u, &v, &fDist))
		{
			isLand = true;
			return 1000.0f - fDist;
		}
	}
	isLand = false;
	return 0.0f;
}
示例#9
0
bool ComTerrain::GetHeight(float & height, const D3DXVECTOR3 & pos)
{
	D3DXVECTOR3 rayPos(pos.x, pos.y + m_rayDistance, pos.z);
	D3DXVECTOR3 rayDir(0, -1, 0);
	float distance = 0.0f;

	for (int i = 0; i < m_vecIndices.size(); i += 3)
	{
		D3DXVECTOR3 v1 = m_vecVertices[m_vecIndices[i]].p;
		D3DXVECTOR3 v2 = m_vecVertices[m_vecIndices[i + 1]].p;
		D3DXVECTOR3 v3 = m_vecVertices[m_vecIndices[i + 2]].p;

		if (D3DXIntersectTri(&v1, &v2, &v3, &rayPos, &rayDir, NULL, NULL, &distance))
		{
			height = rayPos.y - distance;
			return true;
		}
	}

	return false;
}
示例#10
0
bool HeightMap::OnTheGround(D3DXVECTOR3& pos, const D3DXVECTOR3& p0, const D3DXVECTOR3& p1, const D3DXVECTOR3& p2)
{
	bool find = false;

	D3DXVECTOR3 rayStart(pos.x, 1000.0f, pos.z);
	D3DXVECTOR3 rayDirection(0, -1, 0);

	float u, v, distance;
	find = D3DXIntersectTri(
		&p0, &p1, &p2,
		&rayStart, &rayDirection,
		&u, &v, &distance) != 0;

	if (find == true)
	{
		pos.y = 1000.0f - distance;

		//pos = p0 + (p1 - p0) * u + (p2 - p0) * v;
	}

	return find;
}
LRESULT Character_MouseMove::InputProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	LRESULT result = 0;
	switch (message)
	{
		case WM_LBUTTONDOWN:
			{
				POINT mousePoint;
				mousePoint.x = GET_X_LPARAM(lParam);
				mousePoint.y = GET_Y_LPARAM(lParam);
				Ray ray = Ray::CalcRayFromScreenPoint(mousePoint);
				char temp[256];
				sprintf_s(temp, 
					"direction : %.2f, %.2f, %.2f\n", 
					ray.direction.x, ray.direction.y, ray.direction.z);
				//OutputDebugStringA(temp);
				sprintf_s(temp, 
					"origin : %.2f, %.2f, %.2f\n", 
					ray.origin.x, ray.origin.y, ray.origin.z);
				//OutputDebugStringA(temp);

				if (grid)
				{
					const std::vector<D3DXVECTOR3>& groundVertex = 
						grid->GetGroundVertex();

					for (UINT32 i = 0; i < groundVertex.size(); i += 3)
					{
						float u, v, distance;
						if (D3DXIntersectTri(
							&groundVertex[i],
							&groundVertex[i + 1],
							&groundVertex[i + 2],
							&ray.origin,
							&ray.direction,
							&u, &v, &distance))
						{
							D3DXVECTOR3 target = ray.origin + ray.direction * distance;
							sprintf_s(temp,
								"target : %.2f, %.2f, %.2f\n",
								target.x, target.y, target.z);
							//OutputDebugStringA(temp);

							D3DXVECTOR3 targetLenght = target - position;
							float length = D3DXVec3Length(&targetLenght);

							SAFE_DELETE(action);
							ActionMove* move = new ActionMove;
							move->SetStart(position);
							move->SetGoal(target);
							move->SetTarget(this);
							move->SetDurationTime(0.1f*length);
							move->Start();
							SetAction(move);
						}
					}
					
				}
				result = WM_LBUTTONDOWN;
				
			}
			break;
	}
	return result;
}
示例#12
0
bool CModel::Intersected(D3DXVECTOR3 vDir,D3DXVECTOR3 vPos)
{
	float u,v,d;
	
	if 
	(
			D3DXIntersectTri(&vCorners[0],&vCorners[1],&vCorners[2],&vPos,&vDir,&u,&v,&d) 
		||	D3DXIntersectTri(&vCorners[0],&vCorners[2],&vCorners[3],&vPos,&vDir,&u,&v,&d) 
		||	D3DXIntersectTri(&vCorners[4],&vCorners[5],&vCorners[6],&vPos,&vDir,&u,&v,&d) 
		||	D3DXIntersectTri(&vCorners[4],&vCorners[6],&vCorners[7],&vPos,&vDir,&u,&v,&d) 
		||	D3DXIntersectTri(&vCorners[0],&vCorners[4],&vCorners[7],&vPos,&vDir,&u,&v,&d) 
		||	D3DXIntersectTri(&vCorners[0],&vCorners[7],&vCorners[3],&vPos,&vDir,&u,&v,&d) 
		||	D3DXIntersectTri(&vCorners[1],&vCorners[5],&vCorners[6],&vPos,&vDir,&u,&v,&d) 
		||	D3DXIntersectTri(&vCorners[1],&vCorners[2],&vCorners[6],&vPos,&vDir,&u,&v,&d) 
		||	D3DXIntersectTri(&vCorners[0],&vCorners[1],&vCorners[5],&vPos,&vDir,&u,&v,&d) 
		||	D3DXIntersectTri(&vCorners[0],&vCorners[5],&vCorners[4],&vPos,&vDir,&u,&v,&d) 
		||	D3DXIntersectTri(&vCorners[3],&vCorners[7],&vCorners[6],&vPos,&vDir,&u,&v,&d) 
		||	D3DXIntersectTri(&vCorners[3],&vCorners[2],&vCorners[6],&vPos,&vDir,&u,&v,&d) 
	)
		return true;

	return false;
}
示例#13
0
//-----------------------------------------------------------------------------
// Returns the result of a ray intersection with the scene and all its objects.
//-----------------------------------------------------------------------------
bool SceneManager::RayIntersectScene( RayIntersectionResult *result, D3DXVECTOR3 rayPosition, D3DXVECTOR3 rayDirection, bool checkScene, SceneObject *thisObject, bool checkObjects )
{
	float hitDistance = 0.0f;

	// Check if the ray needs to check for intersection with the scene.
	if( checkScene == true )
	{
		// Go through all the faces in the scene, check for intersection.
		for( unsigned long f = 0; f < m_totalFaces; f++ )
		{
			// Skip this face if its material is set to ignore rays.
			if( m_faces[f].renderCache->GetMaterial()->GetIgnoreRay() == true )
				continue;

			// Check the ray against this face.
			if( D3DXIntersectTri( (D3DXVECTOR3*)&m_vertices[m_faces[f].vertex0], (D3DXVECTOR3*)&m_vertices[m_faces[f].vertex1], (D3DXVECTOR3*)&m_vertices[m_faces[f].vertex2], &rayPosition, &rayDirection, NULL, NULL, &hitDistance ) == TRUE )
			{
				if( hitDistance < result->distance || result->material == NULL )
				{
					( *result ).distance = hitDistance;
					( *result ).material = m_faces[f].renderCache->GetMaterial();
				}
			}
		}
	}

	// Check if the ray needs to check for intersection with the objects.
	if( checkObjects == true )
	{
		// Stores the ray in model space.
		D3DXVECTOR3 rp, rd;

		// Iterate all the objects in the scene, check for intersection.
		SceneObject *object = m_dynamicObjects->GetFirst();
		while( object != NULL )
		{
			// Only check this object if it is enabled, has a mesh and is not
			// the calling object.
			if( object->GetEnabled() == true && object->GetMesh() != NULL && object != thisObject )
			{
				// Transform the ray into model space.
				D3DXMATRIX inverse;
				D3DXMatrixInverse( &inverse, NULL, object->GetWorldMatrix() );
				D3DXVec3TransformCoord( &rp, &rayPosition, &inverse );
				D3DXVec3TransformNormal( &rd, &rayDirection, &inverse );

				// Go through the list of frames in the object's mesh.
				LinkedList< Frame > *frames = object->GetMesh()->GetFrameList();
				frames->Iterate( true );
				while( frames->Iterate() != NULL )
				{
					// Ignore this frame if it has no mesh.
					if( frames->GetCurrent()->pMeshContainer == NULL )
						continue;

					// Check the ray against this frame's mesh.
					BOOL hit;
					D3DXIntersect( frames->GetCurrent()->pMeshContainer->MeshData.pMesh, &rp, &rd, &hit, NULL, NULL, NULL, &hitDistance, NULL, NULL );
					if( hit == TRUE && ( hitDistance < result->distance || result->material == NULL ) )
					{
						( *result ).distance = hitDistance;
						( *result ).material = object->GetMesh()->GetStaticMesh()->materials[0];
						( *result ).hitObject = object;
					}
				}
			}

			// Go to the next object.
			object = m_dynamicObjects->GetNext( object );
		}
	}

	// Return false if no intersection occured.
	if( result->material == NULL )
		return false;

	// Calculate the point of intersection.
	( *result ).point = rayPosition + rayDirection * result->distance;

	return true;
}
示例#14
0
bool CD3DBoundingBox::RayIntersect(const CD3DVector3& Point,const CD3DVector3& Dir,CD3DVector3& IntersectPoint,FLOAT& Distance,bool TestOnly)  const
{	
	CD3DVector3 p1,p2,p3;
	FLOAT U,V;
	FLOAT D;
	FLOAT Dis=3.4E+38f;
	bool IsIntersect=false;
	//顶面
	p1=CD3DVector3(m_Min.x,m_Max.y,m_Max.z);
	p2=CD3DVector3(m_Max.x,m_Max.y,m_Max.z);
	p3=CD3DVector3(m_Min.x,m_Max.y,m_Min.z);
	if(D3DXIntersectTri(&p1,&p2,&p3,&Point,&Dir,&U,&V,&D))
	{
		if(TestOnly)
			return true;
		if(D<Dis)
		{
			IsIntersect=true;
			Dis=D;
			IntersectPoint=p1+(p2-p1)*U+(p3-p1)*V;
			Distance=Dis;
		}
	}

	p1=CD3DVector3(m_Max.x,m_Max.y,m_Max.z);
	p2=CD3DVector3(m_Max.x,m_Max.y,m_Min.z);
	p3=CD3DVector3(m_Min.x,m_Max.y,m_Min.z);
	if(D3DXIntersectTri(&p1,&p2,&p3,&Point,&Dir,&U,&V,&D))
	{
		if(TestOnly)
			return true;
		if(D<Dis)
		{
			IsIntersect=true;
			Dis=D;
			IntersectPoint=p1+(p2-p1)*U+(p3-p1)*V;
			Distance=Dis;
		}
	}
	//底面
	p1=CD3DVector3(m_Min.x,m_Min.y,m_Max.z);
	p2=CD3DVector3(m_Max.x,m_Min.y,m_Max.z);
	p3=CD3DVector3(m_Min.x,m_Min.y,m_Min.z);
	if(D3DXIntersectTri(&p1,&p2,&p3,&Point,&Dir,&U,&V,&D))
	{
		if(TestOnly)
			return true;
		if(D<Dis)
		{
			IsIntersect=true;
			Dis=D;
			IntersectPoint=p1+(p2-p1)*U+(p3-p1)*V;
			Distance=Dis;
		}
	}

	p1=CD3DVector3(m_Max.x,m_Min.y,m_Max.z);
	p2=CD3DVector3(m_Max.x,m_Min.y,m_Min.z);
	p3=CD3DVector3(m_Min.x,m_Min.y,m_Min.z);
	if(D3DXIntersectTri(&p1,&p2,&p3,&Point,&Dir,&U,&V,&D))
	{
		if(TestOnly)
			return true;
		if(D<Dis)
		{
			IsIntersect=true;
			Dis=D;
			IntersectPoint=p1+(p2-p1)*U+(p3-p1)*V;
			Distance=Dis;
		}
	}
	//前面
	p1=CD3DVector3(m_Min.x,m_Max.y,m_Min.z);
	p2=CD3DVector3(m_Max.x,m_Max.y,m_Min.z);
	p3=CD3DVector3(m_Min.x,m_Min.y,m_Min.z);
	if(D3DXIntersectTri(&p1,&p2,&p3,&Point,&Dir,&U,&V,&D))
	{
		if(TestOnly)
			return true;
		if(D<Dis)
		{
			IsIntersect=true;
			Dis=D;
			IntersectPoint=p1+(p2-p1)*U+(p3-p1)*V;
			Distance=Dis;
		}
	}
	p1=CD3DVector3(m_Max.x,m_Max.y,m_Min.z);
	p2=CD3DVector3(m_Max.x,m_Min.y,m_Min.z);
	p3=CD3DVector3(m_Min.x,m_Min.y,m_Min.z);
	if(D3DXIntersectTri(&p1,&p2,&p3,&Point,&Dir,&U,&V,&D))
	{
		if(TestOnly)
			return true;
		if(D<Dis)
		{
			IsIntersect=true;
			Dis=D;
			IntersectPoint=p1+(p2-p1)*U+(p3-p1)*V;
			Distance=Dis;
		}
	}
	//后面
	p1=CD3DVector3(m_Min.x,m_Max.y,m_Max.z);
	p2=CD3DVector3(m_Max.x,m_Max.y,m_Max.z);
	p3=CD3DVector3(m_Min.x,m_Min.y,m_Max.z);
	if(D3DXIntersectTri(&p1,&p2,&p3,&Point,&Dir,&U,&V,&D))
	{
		if(TestOnly)
			return true;
		if(D<Dis)
		{
			IsIntersect=true;
			Dis=D;
			IntersectPoint=p1+(p2-p1)*U+(p3-p1)*V;
			Distance=Dis;
		}
	}
	p1=CD3DVector3(m_Max.x,m_Max.y,m_Max.z);
	p2=CD3DVector3(m_Max.x,m_Min.y,m_Max.z);
	p3=CD3DVector3(m_Min.x,m_Min.y,m_Max.z);
	if(D3DXIntersectTri(&p1,&p2,&p3,&Point,&Dir,&U,&V,&D))
	{
		if(TestOnly)
			return true;
		if(D<Dis)
		{
			IsIntersect=true;
			Dis=D;
			IntersectPoint=p1+(p2-p1)*U+(p3-p1)*V;
			Distance=Dis;
		}
	}
	//左面
	p1=CD3DVector3(m_Min.x,m_Max.y,m_Max.z);
	p2=CD3DVector3(m_Min.x,m_Max.y,m_Min.z);
	p3=CD3DVector3(m_Min.x,m_Min.y,m_Max.z);
	if(D3DXIntersectTri(&p1,&p2,&p3,&Point,&Dir,&U,&V,&D))
	{
		if(TestOnly)
			return true;
		if(D<Dis)
		{
			IsIntersect=true;
			Dis=D;
			IntersectPoint=p1+(p2-p1)*U+(p3-p1)*V;
			Distance=Dis;
		}
	}
	p1=CD3DVector3(m_Min.x,m_Max.y,m_Min.z);
	p2=CD3DVector3(m_Min.x,m_Min.y,m_Min.z);
	p3=CD3DVector3(m_Min.x,m_Min.y,m_Max.z);
	if(D3DXIntersectTri(&p1,&p2,&p3,&Point,&Dir,&U,&V,&D))
	{
		if(TestOnly)
			return true;
		if(D<Dis)
		{
			IsIntersect=true;
			Dis=D;
			IntersectPoint=p1+(p2-p1)*U+(p3-p1)*V;
			Distance=Dis;
		}
	}
	//右面
	p1=CD3DVector3(m_Max.x,m_Max.y,m_Max.z);
	p2=CD3DVector3(m_Max.x,m_Max.y,m_Min.z);
	p3=CD3DVector3(m_Max.x,m_Min.y,m_Max.z);
	if(D3DXIntersectTri(&p1,&p2,&p3,&Point,&Dir,&U,&V,&D))
	{
		if(TestOnly)
			return true;
		if(D<Dis)
		{
			IsIntersect=true;
			Dis=D;
			IntersectPoint=p1+(p2-p1)*U+(p3-p1)*V;
			Distance=Dis;
		}
	}
	p1=CD3DVector3(m_Max.x,m_Max.y,m_Min.z);
	p2=CD3DVector3(m_Max.x,m_Min.y,m_Min.z);
	p3=CD3DVector3(m_Max.x,m_Min.y,m_Max.z);
	if(D3DXIntersectTri(&p1,&p2,&p3,&Point,&Dir,&U,&V,&D))
	{
		if(TestOnly)
			return true;
		if(D<Dis)
		{
			IsIntersect=true;
			Dis=D;
			IntersectPoint=p1+(p2-p1)*U+(p3-p1)*V;
			Distance=Dis;
		}
	}
	return IsIntersect;
}
示例#15
0
//레이 충돌지점을 얻는다.
void cQuadTree::GetRayHits( vector<D3DXVECTOR3>* pHits,  const LPRay pRay )
{
	//나의 바운드와 충돌했니?
	if( PHYSICS_MGR->IsRayHitSphere( pRay, &m_CenterPos, this->m_Radius, NULL, NULL ) )
	{
		//자식이잇니?
		if( ( m_Corners[ CORNER_RT ] - m_Corners[ CORNER_LT ] ) > 1 )
		{
			//자식 재귀
			for( int i = 0 ; i < 4 ; i++ )
			{
				m_pChilds[i]->GetRayHits( pHits, pRay );
			}
		}

		//자식이 없는 맨마지막 노드니?
		else
		{
			//Tri 2개 얻는다.
			
			// lt-----rt
			//  |    /|
			//  |   / |
			//  |  /  |
			//  | /   |
			//  |/    |
			// lb-----rb

			
			//나의 폴리곤과 Ray 의 Hit 지점을 얻자
			float dist = 0.0f;
		


			D3DXVECTOR3 lt = this->m_pTerrainVertices[ m_Corners[CORNER_LT] ].pos;
			D3DXVECTOR3 rt = this->m_pTerrainVertices[ m_Corners[CORNER_RT] ].pos;
			D3DXVECTOR3 lb = this->m_pTerrainVertices[ m_Corners[CORNER_LB] ].pos;
			D3DXVECTOR3 rb = this->m_pTerrainVertices[ m_Corners[CORNER_RB] ].pos;

			//좌상단 폴리곤 체크
			if( D3DXIntersectTri( 
				&lt, &rt, &lb,			//폴리곤 정점 3 위치 ( 두루기 순서 주의 )
				&pRay->origin,		//레이 위치
				&pRay->direction,		//레이 방향
				NULL, NULL, 
				&dist			//히트가 되었다면 Origin 에서 부터 hit 위치까지의 거리가 나온다.
				) )
			{
				//히트지점
				D3DXVECTOR3 hitPos = pRay->origin + pRay->direction * dist;

				//푸쉬
				pHits->push_back( hitPos );

				return;
			}


			
			//우하단 폴리곤 체크
			if( D3DXIntersectTri( 
				&lb, &rt, &rb,			//폴리곤 정점 3 위치
				&pRay->origin,		//레이 위치
				&pRay->direction,		//레이 방향
				NULL, NULL, 
				&dist			//히트가 되었다면 Origin 에서 부터 hit 위치까지의 거리가 나온다.
				) )
			{
				//히트지점
				D3DXVECTOR3 hitPos = pRay->origin + pRay->direction * dist;

				//푸쉬
				pHits->push_back( hitPos );

				return;
			}
		}
	}
}