Exemplo n.º 1
0
//
// Precompute array of arclen deltas for lookahead ability.
// Changes current time!
//
void plAnimPath::ComputeArcLenDeltas(int32_t numSamples)
{
    if (fArcLenDeltas.GetCount() >= numSamples)
        return;     // already computed enough samples

    // compute arc len deltas
    fArcLenDeltas.Reset();
    fArcLenDeltas.SetCount(numSamples);
    float animLen = GetLength();
    float timeInc = animLen/(numSamples-1);  // use num-1 since we'll create the zeroth entry by hand
    float time=0;
    hsPoint3 p1, p2;

    int32_t cnt=0;

    // prime initial point
    SetCurTime(0, kCalcPosOnly);
    GetPosition(&p1);
    ArcLenDeltaInfo aldi(time, 0);
    fArcLenDeltas[cnt++]=aldi;
    time += timeInc;

    bool quit=false;
    while(!quit && time<animLen+timeInc)
    {
        if (time > animLen || cnt+1 == numSamples)
        {
            time = animLen;
            quit=true;
        }

        SetCurTime(time, kCalcPosOnly);
        GetPosition(&p2);

        ArcLenDeltaInfo aldi(time, hsVector3(&p2, &p1).Magnitude());
        fArcLenDeltas[cnt++]=aldi;

        time += timeInc;
        p1 = p2;
    }
    hsAssert(fArcLenDeltas.GetCount()==numSamples, "arcLenArray size wrong?");
    hsAssert(cnt==numSamples, "arcLenArray size wrong?");
}
Exemplo n.º 2
0
void plAnimPath::MakeDrawList(hsTArray<uint16_t>& idx, hsTArray<hsPoint3>& pos)
{
    hsMatrix44 resetL2W = GetLocalToWorld();
    hsMatrix44 resetW2L = GetWorldToLocal();

    hsMatrix44 ident;
    ident.Reset();
    SetTransform(ident, ident);

    float numSegs = fRadius; // crude estimate of arclength
    if (numSegs>100)
        numSegs=100;
    float animLen = GetLength();
    float timeInc = animLen/numSegs;
    float time=0;
    hsPoint3 p1, p2;

    SetCurTime(0, kCalcPosOnly);
    GetPosition(&p1);

    time += timeInc;
    bool quit=false;
    while(! quit && time < animLen+timeInc)
    {
        if (time > animLen)
        {
            time = animLen;
            quit=true;
        }

        SetCurTime(time, kCalcPosOnly);
        GetPosition(&p2);

        IMakeSegment(idx, pos, p1, p2);

        time += timeInc;

        p1 = p2;
    }

    SetTransform(resetL2W, resetW2L);
}
Exemplo n.º 3
0
bool CGpsSrc::_SetGpsTime( int v_Year, int v_Month, int v_Day, int v_Hour, int v_Minute, int v_Second )
{
//// 设置RTC时间时,用北京时间,不再使用格林威治时间
// 	bool bCarry = false; // 时间计算时的进位标志
// 	
// 	v_Hour += 8;
// 	if( v_Hour >= 24 )
// 	{
// 		v_Hour -= 24;
// 		bCarry = true;
// 	}
// 	
// 	v_Day += (bCarry ? 1 : 0);
// 	int nMaxDay = 31;
// 	if( 2 == v_Month )
// 	{
// 		if( 0 == v_Year % 400 
// 			|| (0 == v_Year % 4 && 0 != v_Year % 100) ) // 闰年
// 		{
// 			nMaxDay = 29;
// 		}
// 		else nMaxDay = 28;
// 	}
// 	else if( v_Month <= 7 )
// 	{
// 		if( 0 == v_Month % 2 ) nMaxDay = 30;
// 	}
// 	else
// 	{
// 		if( 1 == v_Month % 2 ) nMaxDay = 30;
// 	}
// 	if( v_Day > nMaxDay )
// 	{
// 		v_Day -= nMaxDay;
// 		bCarry = true;
// 	}
// 	else
// 	{
// 		bCarry = false;
// 	}
// 	
// 	v_Month += (bCarry ? 1 : 0);
// 	if( v_Month > 12 )
// 	{
// 		v_Month -= 12;
// 		bCarry = true;
// 	}
// 	else
// 	{
// 		bCarry = false;
// 	}
// 	
// 	v_Year += (bCarry ? 1 : 0);
//// 设置RTC时间时,用北京时间,不再使用格林威治时间


	struct tm objSetTime;
	objSetTime.tm_sec = v_Second;
	objSetTime.tm_min = v_Minute;
	objSetTime.tm_hour = v_Hour;
	objSetTime.tm_mday = v_Day;
	objSetTime.tm_mon = v_Month - 1;	//0~11
	objSetTime.tm_year = v_Year - 1900;

	if (false == m_bRtcTimeChecked)
	{
		if( true == _SetTimeToRtc(&objSetTime) )
		{
			m_bRtcTimeChecked = true;//简单使用,可不做互斥
		}
	}
	SetCurTime(&objSetTime);
	
	char sdata = 0;
	DataPush(&sdata, 1, DEV_GPS, DEV_UPDATE, LV1); //通知Update已经对过时

	return true;
}
Exemplo n.º 4
0
void plAnimPath::Reset()
{
    SetCurTime(0);
}
Exemplo n.º 5
0
//
// Returns time of point (at least) arcLength units away from point at startTime.
// Also sets strtSrchIdx for incremental searching.
//
float plAnimPath::GetLookAheadTime(float startTime, float arcLengthIn, bool bwd,
                                      int32_t* startSrchIdx)
{
    if (arcLengthIn==0)
        return startTime;   // default is no look ahead

    if (startTime==GetLength() && !bwd)
        return GetLength();

    if (startTime==0 && bwd)
        return 0;

    hsAssert(startSrchIdx, "nil var for startSrchIdx");

    float oldTime=fTime;

    ComputeArcLenDeltas();  // precompute first time only

    // save and change time if necessary
    if (fTime!=startTime)
        SetCurTime(startTime, kCalcPosOnly);

    // find nearest (forward) arcLen sample point, use starting srch index provided
    bool found=false;
    int32_t i;
    for(i=(*startSrchIdx); i<fArcLenDeltas.GetCount()-1; i++)
    {
        if (fArcLenDeltas[i].fT<=startTime && startTime<fArcLenDeltas[i+1].fT)
        {
            *startSrchIdx=i;
            found=true;
            break;
        }
    }

    if (!found)
    {
        // check if equal to last index
        if (startTime==fArcLenDeltas[fArcLenDeltas.GetCount()-1].fT)
        {
            *startSrchIdx=fArcLenDeltas.GetCount()-1;
            found=true;
        }
        else
        {
            for(i=0; i<*startSrchIdx; i++)
            {
                if (fArcLenDeltas[i].fT<=startTime && startTime<fArcLenDeltas[i+1].fT)
                {
                    *startSrchIdx=i;
                    found=true;
                    break;
                }
            }
        }
    }

    // find distance to nearest arcLen sample point
    int32_t nearestIdx = bwd ? *startSrchIdx : *startSrchIdx+1;
    hsAssert(found, "couldn't find arcLength sample");

    hsPoint3 pos;
    GetPosition(&pos);      // startTime position

    hsPoint3 pos2;
    float endTime = fArcLenDeltas[nearestIdx].fT; 
    SetCurTime(endTime, kCalcPosOnly);
    GetPosition(&pos2);     // position at nearest sample point

    float curArcLen = hsVector3(&pos2, &pos).Magnitude();
    float curTime=0;
    bool quit=false;
    float timeOut = 0;
    int32_t inc = bwd ? -1 : 1;
    // now sum distance deltas until we exceed the desired arcLen
    if (curArcLen<arcLengthIn)
    {
        for(i=bwd ? nearestIdx : nearestIdx+inc; i<fArcLenDeltas.GetCount() && i>=0; i+=inc)
        {
            if (curArcLen+fArcLenDeltas[i].fArcLenDelta>arcLengthIn)
            {
                // gone tooFar
                endTime = fArcLenDeltas[i].fT;
                curTime = fArcLenDeltas[i-1].fT;
                break;
            }
            curArcLen += fArcLenDeltas[i].fArcLenDelta;
        }   
        
        if ( (i==fArcLenDeltas.GetCount() && !bwd) || (i<0 && bwd) )
        {
            quit=true;
            timeOut = bwd ? 0 : GetLength();
        }       
    }
    else
    {
        curArcLen = 0;
        curTime = startTime;
    }

    if (!quit)
    {
        // interp remaining interval

        // 1. compute necessary distToGoal
        float distToGoal = arcLengthIn-curArcLen;
        hsAssert(distToGoal, "0 length distToGoal?");
        
        // 2. compute % of dist interval which gives distToGoal
        SetCurTime(curTime, kCalcPosOnly);
        GetPosition(&pos);

        SetCurTime(endTime, kCalcPosOnly);
        GetPosition(&pos2);

        float distInterval = hsVector3(&pos2, &pos).Magnitude();
        float percent = distToGoal/distInterval;
        hsAssert(percent>=0 && percent<=1, "illegal percent value"); 

        // 3. compute interpolated time value using percent
        if (!bwd)
            timeOut = curTime + (endTime-curTime)*percent;
        else
            timeOut = endTime - (endTime-curTime)*percent;
        hsAssert((timeOut>=curTime && timeOut<=endTime), "illegal interpolated time value");
        // hsAssert(!bwd || (timeOut<=curTime && timeOut>=endTime), "bwd: illegal interpolated time value");
    }

    // restore time
    if (fTime != oldTime)
        SetCurTime(oldTime);

    hsAssert(bwd || (timeOut>startTime && timeOut<=GetLength()), "fwd: illegal look ahead time");
    hsAssert(!bwd || (timeOut<startTime && timeOut>=0), "bwd: illegal look ahead time");

    return timeOut;
}