Exemple #1
0
bool glmRectangle::clip( glm::vec3& _p0, glm::vec3& _p1) const {
    
    glm::vec3 topLeft     = getTopLeft();
    glm::vec3 topRight    = getTopRight();
    glm::vec3 bottomRight = getBottomRight();
    glm::vec3 bottomLeft  = getBottomLeft();
    
    if (!inside(_p0)) {
        glm::vec3 r;
        if (LineSegmentIntersection(_p0, _p1, topLeft,     topRight,    r)){
            _p0 = r;
        } else if (LineSegmentIntersection(_p0, _p1, topRight,    bottomRight, r)){
            _p0 = r;
        } else if (LineSegmentIntersection(_p0, _p1, bottomRight, bottomLeft,  r)){
            _p0 = r;
        } else if (LineSegmentIntersection(_p0, _p1, bottomLeft,  topLeft,     r)){
            _p0 = r;
        }
    }
    
    if (!inside(_p1)) {
        glm::vec3 r;
        if (LineSegmentIntersection(_p1, _p0, topLeft,     topRight,    r)){
            _p1 = r;
        } else if (LineSegmentIntersection(_p1, _p0, topRight,    bottomRight, r)){
            _p1 = r;
        } else if (LineSegmentIntersection(_p1, _p0, bottomRight, bottomLeft,  r)){
            _p1 = r;
        } else if (LineSegmentIntersection(_p1, _p0, bottomLeft,  topLeft,     r)){
            _p1 = r;
        }
    }
}
double NavigationModel::getRange(const coordinate auvPosition, BottomModel& bottom)
{
    line sonarLine;
    line bottomLine;
    double minRange = maxRange;
    double currentRange = maxRange;
    double x = auvPosition.x;
    double intersectionX, intersectionY;

    for (int i = 0; i < numbSonarBeams; i++)
    {
        sonarLine = sonarBeams[i].getLine(auvPosition);
        while (x <= (auvPosition.x + maxRange))
        {

            bottomLine = bottom.getBottomLine(x);

            if (LineSegmentIntersection(sonarLine.x1, sonarLine.y1, sonarLine.x2, sonarLine.y2,
                    bottomLine.x1, bottomLine.y1, bottomLine.x2, bottomLine.y2, &intersectionX, &intersectionY))
            {
                currentRange = intersectionX - auvPosition.x;

                if (currentRange < minRange)
                {
                    minRange = currentRange;
                }
            }
            x++;
        }
        x = auvPosition.x;
    }
    return minRange;
}
Exemple #3
0
bool CMinotaur::RayCastForward(float& fHitTime)
{
	XMFLOAT3 start = *GetPosition();
	start.y = 75.0f;
	TRay tRay;
	tRay.f3Start = start;
	XMFLOAT3 f3ZAxis = *GetZAxis();
	tRay.f3Direction.x = f3ZAxis.x;
	tRay.f3Direction.y = f3ZAxis.y;
	tRay.f3Direction.z = f3ZAxis.z;

	tRay.fDistance = 25000.0f;


	std::vector<IObject*> vColliders = m_cpObjectManager->GetList(CObjectManager::Static);
	for (unsigned int i = 0; i < m_vDoors.size(); i++)
	{
		vColliders.push_back(m_vDoors[i]);
	}
	bool bOutput = true;
	if (LineSegmentIntersection(tRay, vColliders, fHitTime) == false)
	{
		bOutput = false;
	}
	return bOutput;
}
Exemple #4
0
std::vector<glmPolyline> glmPolyline::splitAtIntersection(const glmPolyline &_other, float _gap){
    std::vector<glmPolyline> RTA;
    
    if (size()>0 && _other.size()>0) {
        glmPolyline buffer;
        
        buffer.add(m_points[0]);
        for (int i = 0; i < m_points.size()-1; i++){
            for (int j = 0; j < _other.size()-1; j++){
                
                glm::vec3 intersection;
                if(LineSegmentIntersection(m_points[i],m_points[i+1],
                                           _other[j],_other[j+1],
                                           intersection)){
                    
                    glmPolarPoint polar = glmPolarPoint(m_points[i],m_points[i+1]);
                    glm::vec3 gap = glmPolarPoint(polar.a,_gap,m_points[i].z).getXY();
                    
                    buffer.add(intersection-gap);
                    RTA.push_back(buffer);
                    buffer.clear();
                    buffer.add(intersection+gap);
                }
            }
            buffer.add(m_points[i+1]);
        }
        RTA.push_back(buffer);
    }
    return RTA;
}
Exemple #5
0
//----------------------------------------------------------
bool glmRectangle::intersects(const glm::vec3& p0, const glm::vec3& p1) const {
    // check for a line intersection
    glm::vec3 p;
    
    glm::vec3 topLeft     = getTopLeft();
    glm::vec3 topRight    = getTopRight();
    glm::vec3 bottomRight = getBottomRight();
    glm::vec3 bottomLeft  = getBottomLeft();
    
    return inside(p0) || // check end inside
    inside(p1) || // check end inside
    LineSegmentIntersection(p0, p1, topLeft,     topRight,    p) || // cross top
    LineSegmentIntersection(p0, p1, topRight,    bottomRight, p) || // cross right
    LineSegmentIntersection(p0, p1, bottomRight, bottomLeft,  p) || // cross bottom
    LineSegmentIntersection(p0, p1, bottomLeft,  topLeft,     p);   // cross left
}
Exemple #6
0
bool CMinotaur::RayCastInfinite(float& fHitTime, XMFLOAT3& f3CollisionPoint)
{
	XMFLOAT3 start = *GetPosition();
	XMFLOAT3 end = *GetPlayer()->GetPosition();
	start.y = 75.0f;
	end.y = 75.0f;
	TRay tRay;
	tRay.f3Start = start;
	tRay.f3Direction.x = end.x - start.x;
	tRay.f3Direction.y = end.y - start.y;
	tRay.f3Direction.z = end.z - start.z;
	float fDist = sqrt(XMF3DotProduct(tRay.f3Direction, tRay.f3Direction));
	tRay.f3Direction.x /= fDist;
	tRay.f3Direction.y /= fDist;
	tRay.f3Direction.z /= fDist;

	tRay.fDistance = 25000.0f;

	float fMinX, fMaxX, fMinZ, fMaxZ;
	fMinX = min(start.x, end.x);
	fMaxX = max(start.x, end.x);
	fMinZ = min(start.z, end.z);
	fMaxZ = max(start.z, end.z);

	std::vector<IObject*> vColliders = m_cpObjectManager->GetList(CObjectManager::Static);
	for (unsigned int i = 0; i < m_vDoors.size(); i++)
	{
		vColliders.push_back(m_vDoors[i]);
	}
	bool bOutput = true;
	if (LineSegmentIntersection(tRay, vColliders, fHitTime) == false)
	{
		bOutput = false;
	}
	if (bOutput)
	{
		f3CollisionPoint.x = tRay.f3Start.x + tRay.f3Direction.x * fHitTime;
		f3CollisionPoint.y = tRay.f3Start.y + tRay.f3Direction.y * fHitTime;
		f3CollisionPoint.z = tRay.f3Start.z + tRay.f3Direction.z * fHitTime;
	}
	return bOutput;
}
Exemple #7
0
bool CMinotaur::RayCastToPlayer(float& fHitTime)
{
	XMFLOAT3 start = *GetPosition();
	XMFLOAT3 startL = start;
	XMFLOAT3 startR = start;

	startL.x += GetVelocity().x * 45;
	startR.x -= GetVelocity().x * 45;



	XMFLOAT3 end = *GetPlayer()->GetPosition();
	start.y = 75.0f;
	end.y = 75.0f;
	TRay tRay;
	tRay.f3Start = startL;
	tRay.f3Direction.x = end.x - startL.x;
	tRay.f3Direction.y = end.y - startL.y;
	tRay.f3Direction.z = end.z - startL.z;
	float fDist = sqrt(XMF3DotProduct(tRay.f3Direction, tRay.f3Direction));
	tRay.f3Direction.x /= fDist;
	tRay.f3Direction.y /= fDist;
	tRay.f3Direction.z /= fDist;

	tRay.fDistance = fDist - 46.0f;

	float fMinX, fMaxX, fMinZ, fMaxZ;
	fMinX = min(start.x, end.x);
	fMaxX = max(start.x, end.x);
	fMinZ = min(start.z, end.z);
	fMaxZ = max(start.z, end.z);

	std::vector<IObject*> vColliders = m_cpObjectManager->GetQuadTree()->GetNearbyObjects(fMinX, fMinZ, fMaxX, fMaxZ);
	for (unsigned int i = 0; i < m_vDoors.size(); i++)
	{
		vColliders.push_back(m_vDoors[i]);
	}
	bool bOutput = true;
	float tempHitTime = 0.0f;
	if (LineSegmentIntersection(tRay, vColliders, fHitTime) == false)
	{
		CCapsule* pCapsule = (CCapsule*)m_pvColliders[1]->GetBounds();
		float fRadius = pCapsule->GetRadius();
		tRay.f3Start.x += fRadius;
		tRay.fDistance = sqrt(XMF3DotProduct(tRay.f3Direction, tRay.f3Direction)) - 46.0f;
		if (LineSegmentIntersection(tRay, vColliders, fHitTime) == false)
		{
			tRay.f3Start.x -= fRadius * 2;
			tRay.fDistance = sqrt(XMF3DotProduct(tRay.f3Direction, tRay.f3Direction)) - 46.0f;

			if (LineSegmentIntersection(tRay, vColliders, fHitTime) == false)
			{
				tRay.f3Start.z += fRadius;
				tRay.f3Start.x += fRadius;
				tRay.fDistance = sqrt(XMF3DotProduct(tRay.f3Direction, tRay.f3Direction)) - 46.0f;

				if (LineSegmentIntersection(tRay, vColliders, fHitTime) == false)
				{

					tRay.f3Start.z -= fRadius*2.0f;
					tRay.f3Start.x += fRadius;
					tRay.fDistance = sqrt(XMF3DotProduct(tRay.f3Direction, tRay.f3Direction)) - 46.0f;

					if (LineSegmentIntersection(tRay, vColliders, fHitTime) == false)
					{
						bOutput = false;
					}
				}
			}
		}
	}
	return bOutput;
}