Exemplo n.º 1
0
// called after all nodes added. This function calculates the node velocities
void RNSpline::BuildSpline()
{
	if (NodeCount == 2)
	{
		Node[0].Velocity = GetStartVelocity(0);
		Node[NodeCount-1].Velocity = GetEndVelocity(NodeCount-1);
		return;
	}
	else if (NodeCount < 2)
		return;

	for (int i = 1; i < NodeCount-1; ++i)
	{
		CVector3D Next = Node[i+1].Position - Node[i].Position;
		CVector3D Previous = Node[i-1].Position - Node[i].Position;
		Next.Normalize();
		Previous.Normalize();

		// split the angle (figure 4)
		Node[i].Velocity = Next - Previous;
		Node[i].Velocity.Normalize();
	}
	// calculate start and end velocities
	Node[0].Velocity = GetStartVelocity(0);
	Node[NodeCount-1].Velocity = GetEndVelocity(NodeCount-1);
}
Exemplo n.º 2
0
// smoothing filter.
void SNSpline::Smooth()
{
	if (NodeCount < 3)
		return;

	CVector3D newVel;
	CVector3D oldVel = GetStartVelocity(0);
	for (int i = 1; i < NodeCount-1; ++i)
	{
		// Equation 12
		newVel = GetEndVelocity(i) * Node[i].Distance.ToFloat() + GetStartVelocity(i) * Node[i-1].Distance.ToFloat();
		newVel = newVel * (1 / (Node[i-1].Distance + Node[i].Distance).ToFloat());
		Node[i-1].Velocity = oldVel;
		oldVel = newVel;
	}
	Node[NodeCount-1].Velocity = GetEndVelocity(NodeCount-1);
	Node[NodeCount-2].Velocity = oldVel;
}
Exemplo n.º 3
0
BOOL KComplexPath::LoadComplexPath(
    const KPOSITION* pStart,  
    const KPOSITION* pEnd, 
    const KFLY_PATH_POINTS& cPoints, 
    KHero* pHero,
    KFLY_PATH_TYPE eEndPathType
)
{
    BOOL bResult    = false;
    BOOL bRetCode   = false;

    KPOSITION       cSubStart;
    KPOSITION       cSubEnd;
    int             nEndVelocity = 0;
    KFLY_PATH_POINTS::const_iterator itPoints;

    KGLOG_PROCESS_ERROR(pStart);
    // KGLOG_PROCESS_ERROR(pEnd);
    KGLOG_PROCESS_ERROR(pHero);
    
    bRetCode = m_cSubPaths.empty();
    KGLOG_PROCESS_ERROR(bRetCode);

    m_cStart = *pStart;
    cSubStart = *pStart;
    cSubEnd = cSubStart;

    for (itPoints = cPoints.begin(); itPoints != cPoints.end(); ++itPoints)
    {
        KPathPointInfo* pPointInfo = g_pSO3World->m_Settings.m_PathPointData.GetPointInfo(*itPoints);
        KGLOG_PROCESS_ERROR(pPointInfo);

        bRetCode = SetPointByPointInfo(cSubEnd, pPointInfo, pHero);
        KGLOG_PROCESS_ERROR(bRetCode);

        bRetCode = AddSubPathByType(
            pPointInfo->ePathType, 
            cSubStart, 
            cSubEnd, 
            pPointInfo->nGravity, 
            pPointInfo->nHeightOffset, 
            pPointInfo->nVelocity
        );
        KGLOG_PROCESS_ERROR(bRetCode);

        cSubStart = cSubEnd;
    }
    
    if (pEnd)
    {
        KBall* pBall = NULL;
        int nGravity = 0;

        KGLOG_PROCESS_ERROR(pHero->m_pScene);
        
        pBall = pHero->m_pScene->GetBall();
        KGLOG_PROCESS_ERROR(pBall);
        
        nGravity = pBall->GetCurrentGravity();
        KGLOG_PROCESS_ERROR(nGravity > 0);

        nEndVelocity = GetEndVelocity();
        KGLOG_PROCESS_ERROR(nEndVelocity > 0);

        bRetCode = AddSubPathByType(
            eEndPathType, 
            cSubEnd, 
            *pEnd, 
            nGravity, 
            CELL_LENGTH * 3, 
            nEndVelocity
        );
        KGLOG_PROCESS_ERROR(bRetCode);
        m_cEnd = *pEnd;
    }
    else
    {
        m_cEnd = cSubEnd;
    }
    
    bResult = true;
Exit0:
    return bResult;
}