示例#1
0
bool IsTriangleInCircle2D(const D3DXVECTOR3* pos,float r,TerrainVertex* v0, TerrainVertex* v1, TerrainVertex* v2)
{
	D3DXVECTOR2 center = D3DXVECTOR2(pos->x, pos->z);
	D3DXVECTOR2 v00 = center - D3DXVECTOR2(v0->m_pos.x, v0->m_pos.z);
	D3DXVECTOR2 v01 = center - D3DXVECTOR2(v1->m_pos.x, v1->m_pos.z);
	D3DXVECTOR2 v02 = center - D3DXVECTOR2(v2->m_pos.x, v2->m_pos.z);
	//未来可能放宽一点
	return 
		(D3DXVec2LengthSq(&v00) <= r*r) ||
		(D3DXVec2LengthSq(&v01) <= r*r) ||
		(D3DXVec2LengthSq(&v02) <= r*r);

}
示例#2
0
void XViewSpline::OnLButtonDown(UINT nFlags, CPoint point)
{
    m_vPrev = point;
    // TODO: 여기에 메시지 처리기 코드를 추가 및/또는 기본값을 호출합니다.
    m_idxSelected = -1;
    D3DXMATRIX mInv, mInvCenter;
    D3DXMATRIX mCenter;
    D3DXMatrixTranslation( &mCenter, vCenter.x, vCenter.y, 0 );
    D3DXMatrixInverse( &mInvCenter, nullptr, &mCenter );		// 원점의 역행렬
    for( int i = 0; i < MAX_JOINT; ++i )
    {
        JOINT *j = &m_listJoint[i];

        D3DXMATRIX mWorld = j->m_mWorld * mInvCenter;
        D3DXMatrixInverse( &mInv, nullptr, &mWorld );		// 월드행렬의 역행렬
        D3DXVECTOR2 vMouse( (float)point.x, (float)point.y );
        D3DXVECTOR2 vMouseLocal = vMouse - vCenter;		// 원점을 중심으로한 마우스 좌표
        D3DXVECTOR2 vT;
        D3DXVec2TransformCoord( &vT, &vMouseLocal, &mInv );		// 마우스좌표를 역회전시켜서 수평상태기준의 좌표가 됨
        D3DXVECTOR2 vDist = vT - D3DXVECTOR2( LEN_JOINT, 0 );			// 관절끝을 기준으로한 벡터

        if( D3DXVec2LengthSq( &vDist ) < 5.f * 5.f )		// 원의 반지름
        {
            m_idxSelected = i;
            break;
        }
    }
    Invalidate(0);
    __super::OnLButtonDown(nFlags, point);
}
示例#3
0
void Enemy::setPathHealing()
{
	vector<D3DXVECTOR3>().swap(mPath);//clean out vector
	//find new path to nearest healing spot
	float nearestSq = 1000000000000.0f;
	D3DXVECTOR2 nearestV = D3DXVECTOR2(0.0f, 0.0f);
	for (D3DXVECTOR2 V : gCurrentLevel->getHealPoints())
	{
		float distance = D3DXVec2LengthSq(&(V - D3DXVECTOR2(mPosition.x, mPosition.z)));
		if (distance < nearestSq)
		{
			nearestSq = distance;
			nearestV = V;
		}
	}
	if (nearestSq < 400)
	{
		bHealing = true;
		stop();
		return;
	}
	resetStartNode();
	mPath = gCurrentLevel->getPaths()->findPath(mStartNode, D3DXVECTOR3(nearestV.x, 50.0f, nearestV.y));
	//path just found
	mLastPathFound = 0.0f;
}
示例#4
0
//**関数***************************************************************************
//	概要	:	円判定
//*********************************************************************************
bool CCalc::IntersectCircle(CHitCircle circleA , CHitCircle circleB)
{
	D3DXVECTOR2	pointA = circleA.m_Point;
	D3DXVECTOR2 pointB = circleB.m_Point;

	float fDist = D3DXVec2LengthSq(&(pointA - pointB));
	float fRadi = powf(circleA.m_fRadius + circleB.m_fRadius , 2.0f);

	if(fRadi > fDist)
		return true;
	else
		return false;
}
示例#5
0
//find a random flee point and flee there
void Follower::setPathFlee()
{
	//find all the valid flee points
	vector<D3DXVECTOR2> validPoints;
	D3DXVECTOR2 choice;
	vector<D3DXVECTOR2> fleePoints = gCurrentLevel->getFleePoints();
	for (D3DXVECTOR2 FP : fleePoints)
	{
		//find distance of unit to flee point
		float enemyDistanceSq = D3DXVec2LengthSq(&(FP - D3DXVECTOR2(mPosition.x, mPosition.z)));
		//if it is too close, it is not ideal to flee to
		if (enemyDistanceSq < 90000)//<300
			continue;
		//find distance of player to flee point
		D3DXVECTOR3 playerPos = gPlayer->getPosition();
		float playerDistanceSq = D3DXVec2LengthSq(&(FP - D3DXVECTOR2(playerPos.x, playerPos.z)));
		//if distance from point is < 300, it is too close to flee to
		//if point is further from enemy than player, it is not ideal to flee to
		if (enemyDistanceSq < 90000 || enemyDistanceSq > playerDistanceSq)
			continue;
		validPoints.push_back(FP);
	}
	UINT size = validPoints.size();
	//if their is more than one valid point, choose one at random
	if (size > 1)
		choice = validPoints[rand() % size];
	//if there is one point, choose it
	else if (size == 1)
		choice = validPoints[0];
	//if there are no valid points, just choose one at random from all points
	else
		choice = fleePoints[rand() % fleePoints.size()];
	resetStartNode();
	mPath = gCurrentLevel->getPaths()->findPath(mPosition, D3DXVECTOR3(choice.x, 0.0f, choice.y));
	mLastPathFound = 0.0f;
}
示例#6
0
文件: Base.cpp 项目: edeksumo/carpg
float GetClosestPointOnLineSegment(const VEC2& A, const VEC2& B, const VEC2& P, VEC2& result)
{
	VEC2 AP = P - A;       //Vector from A to P   
	VEC2 AB = B - A;       //Vector from A to B  

	float magnitudeAB = D3DXVec2LengthSq(&AB); //Magnitude of AB vector (it's length squared)     
	float ABAPproduct = D3DXVec2Dot(&AP, &AB); //The DOT product of a_to_p and a_to_b     
	float distance = ABAPproduct / magnitudeAB; //The normalized "distance" from a to your closest point  

	if (distance < 0)     //Check if P projection is over vectorAB     
		result = A;
	else if (distance > 1)
		result = B;
	else
		result = A + AB * distance;
	
	return PointLineDistance(P.x, P.y, A.x, A.y, B.x, B.y);
}
示例#7
0
//**関数***************************************************************************
//	概要	:	拡大適応円判定
//*********************************************************************************
bool CCalc::IntersectCircleScale(CHitCircle circleA , D3DMATRIX matA , CHitCircle circleB , D3DXMATRIX matB)
{
	D3DXVECTOR2	pointA = circleA.m_Point;
	D3DXVECTOR2 pointB = circleB.m_Point;

	// ワールドマトリクスから拡大率取得
	D3DXVECTOR3 ScaleA = D3DXVECTOR3(0,0,0) , ScaleB = D3DXVECTOR3(0,0,0);
	ScaleA.x = D3DXVec3Length(&D3DXVECTOR3(matA._11 , matA._12 , matA._13));
	//ScaleA.y = D3DXVec3Length(&D3DXVECTOR3(matA._21 , matA._22 , matA._23));
	ScaleB.x = D3DXVec3Length(&D3DXVECTOR3(matB._11 , matB._12 , matB._13));
	//ScaleB.y = D3DXVec3Length(&D3DXVECTOR3(matB._21 , matB._22 , matB._23));

	float fDist = D3DXVec2LengthSq(&(pointA - pointB));
	float fRadi = powf(circleA.m_fRadius * ScaleA.x + circleB.m_fRadius * ScaleB.x , 2.0f);

	if(fRadi > fDist)
		return true;
	else
		return false;
}
void KWActionMoveOnTerrain::Update( float dt )
{
	D3DXVECTOR3 pos = m_pTarget->getPosition();
	D3DXVECTOR2 xzPos(pos.x, pos.z);
	D3DXVECTOR2 delta = m_targetPoint - xzPos;

	if (D3DXVec2LengthSq(&delta) < 1.0f)
	{
		m_bFinished = true;
		return;
	}

	D3DXVec2Normalize(&delta, &delta);
	delta *= m_velocity * dt;
	xzPos += delta;
	float y = m_terrain->GetHeight(xzPos.x, xzPos.y) + m_pTarget->GetWorldBoundingBox().GetHeight() / 2;
	pos.x = xzPos.x;
	pos.z = xzPos.y;
	pos.y = y;
	m_pTarget->SetTranslation(pos);
	//m_pTarget->SetRotationY(D3DX_PI+atan2f(delta.y, delta.x));
}
示例#9
0
const bool ColliderBoxAA2D::CheckCollisionSphere2D(ColliderSphere2D * const col)
{
	D3DXVECTOR2 pos = *col->GetPosition();
	float rad = col->GetRadius();

	D3DXVECTOR2 cls, closest;
	
	D3DXVec2Maximize(&cls, &pos, &m_min);
	D3DXVec2Minimize(&closest, &cls, &m_max);

	cls = closest - pos;
	float distance = D3DXVec2LengthSq(&cls);

	if (distance < rad * rad)
	{
		Collider::AssignTempColVec(D3DXVECTOR3(cls), D3DXVECTOR3(distance, 0.0f, 0.0f));
		return true;
	}
	else
	{
		return false;
	}
}
示例#10
0
文件: util.cpp 项目: olofn/db_public
float lengthSq(const Vec2 &v)
{
	return D3DXVec2LengthSq(&v);
}