Пример #1
0
//直线和三角形相交的交点
Bool HawkRay2D::Intersect(const HawkTriangle2D& oTriangle,Vec2IntrResult* pResult) const
{
    //包围圆与对应直线的关系
    HawkVector2D vCenter = oTriangle.GetBoundCenter();
    Float        fRadius = oTriangle.GetBoundRadius();
    if (GetDistance(vCenter) > fRadius)
    {
        return false;
    }

    PtRelation eRel[3] = {PT_NONE};
    for (Int32 i=0; i<3; i++)
    {
        HawkVector2D oVec2 = oTriangle.GetPoint(i);
        eRel[i] = GetPtRelation(oVec2);
        if (eRel[i] == PT_ON)
        {
            if (pResult)
            {
                if(!HawkMath::IsZero(Direction.X))
                {
                    pResult->Factor = (oVec2.X-Point.X) / Direction.X;
                }
                else if(!HawkMath::IsZero(Direction.Y))
                {
                    pResult->Factor = (oVec2.Y-Point.Y) / Direction.Y;
                }
                else
                {
                    T_Exception("Direction Is Zero.");
                }

                pResult->Point  = oVec2;
            }
            return true;
        }
    }

    for (Int32 i=0; i<3; i++)
    {
        if (eRel[i] != eRel[(i+1)%3])
        {
            HawkSegment2D oSeg(oTriangle.GetPoint(i),oTriangle.GetPoint((i+1)%3));
            if(Intersect(oSeg,pResult))
                return true;
        }
    }

    return false;
}
Пример #2
0
HawkOctets& HawkOctets::Reserve(UInt32 iSize)
{
    if(iSize > m_iCap)
    {
        for(iSize--,m_iCap=2; iSize>>=1; m_iCap<<=1);
        iSize = (UInt32)((Char*)m_pHigh-(Char*)m_pBase);
        void* pBase = m_pBase;
        m_pBase = HawkRealloc(m_pBase,m_iCap);
        if (!m_pBase)
        {
            HawkFree(pBase);
            T_Exception("Octets Realloc Failed.");
        }
        else
        {
            m_pHigh = (Char*)m_pBase+iSize;
        }
    }
    return *this;
}
Пример #3
0
	HawkMarshalData* HawkMarshalData::Clone() const
	{
		T_Exception("HawkMarshalData::Clone Must Implement.");
		return 0;
	}
Пример #4
0
	HawkMarshalData& HawkMarshalData::operator = (const HawkMarshalData& rhs)
	{		
		T_Exception("HawkMarshalData::operator =  Must Implement.");
		return *this;
	}	
Пример #5
0
//直线和线段相交的交点
Bool HawkRay2D::Intersect(const HawkSegment2D& oSegment,Vec2IntrResult* pResult) const
{
    HawkVector2D  vDiff    = oSegment.Start - Point;
    HawkVector2D  vSegDir  = oSegment.GetDirection();

    Float fCross = Direction.CrossProduct(vSegDir);
    if (HawkMath::Abs<Float>(fCross) > HawkMath::FLOAT_DIFF)
    {
        Float fFactor0 = vDiff.CrossProduct(vSegDir) / fCross;
        Float fFactor1 = vDiff.CrossProduct(Direction) / fCross;

        //单点相交
        if (pResult)
        {
            pResult->Factor = fFactor0;
            pResult->Point  = Point + fFactor0*Direction;
        }
        return fFactor0 >= 0.0f && fFactor1 >= 0 && fFactor1 <= 1.0f;
    }

    //重合
    if (IsPointOnRay(oSegment.Start))
    {
        if (pResult)
        {
            if(!HawkMath::IsZero(Direction.X))
            {
                pResult->Factor = (oSegment.Start.X-Point.X) / Direction.X;
            }
            else if(!HawkMath::IsZero(Direction.Y))
            {
                pResult->Factor = (oSegment.Start.Y-Point.Y) / Direction.Y;
            }
            else
            {
                T_Exception("Direction Is Zero.");
            }
            pResult->Point  = oSegment.Start;
        }
        return true;
    }
    else if (IsPointOnRay(oSegment.End))
    {
        if (pResult)
        {
            if(!HawkMath::IsZero(Direction.X))
            {
                pResult->Factor = (oSegment.End.X-Point.X) / Direction.X;
            }
            else if(!HawkMath::IsZero(Direction.Y))
            {
                pResult->Factor = (oSegment.End.Y-Point.Y) / Direction.Y;
            }
            else
            {
                T_Exception("Direction Is Zero.");
            }
            pResult->Point  = oSegment.End;
        }
        return true;
    }

    //平行
    return false;
}
Пример #6
0
	HawkOctetsStream& HawkMarshal::Marshal(HawkOctetsStream& rhsOS)
	{
		T_Exception("HawkMarshal::Marshal Must Implement.");
		return rhsOS;
	}
Пример #7
0
	AString HawkDatabase::AmendString(const AString& sValue) const
	{
		T_Exception("HawkDatabase::AmendString Must Implement.");
		return sValue;
	}