示例#1
0
void GSphere::ExpandBoundBySphere( const GSphere &Src )
{
	// Method 1 = 대상구와의 거리 + 반지름을 한 길이가 더 길면, 그만큼 반지름을 확장한다.
	// Method 2 = Method-1의 체크가 TRUE이면, 두 구의 중심을 잇는 선의 중점에서 두 구와의 거리의 반을 반지름으로 하는
	//            구를 만들면 최적화된 구가 나온다.
	// 여기서는 Method-2를 쓴다.
	SVector vSub;
	vSub = Src.vecCenter - vecCenter;
	float fDistCenter = vSub.Size();

	if( fDistCenter+Src.fRadius > fRadius )
	{
		vecCenter = vecCenter + vSub/2.0f;
		fRadius = fDistCenter/2.0f;
	}
}
示例#2
0
void CCamera::Update(float ftDelta)
{
	SRotator  Rot = this->Location().Rotation;

	if(m_bImpact)
	{
		if(m_ftElapsedTime < m_ftImpactTime/2.0f)
		{
			m_vctTargetEye = m_vctTargetEye*m_ftElapsedTime + m_vctCurrentEye*(m_ftImpactTime/2.0f-m_ftElapsedTime);
			m_vctTargetEye *= m_ftImpactTime/2.0f;
		}
		else
		{
			m_vctTargetEye = m_vctTargetEye*(m_ftElapsedTime-m_ftImpactTime/2.0f) + m_vctCurrentEye*(m_ftImpactTime-m_ftElapsedTime);
			m_vctTargetEye *= m_ftImpactTime/2.0f;
		}
	}
	
	float ftVelocityEye = 10.0f;
	
	SVector vctDelta = m_vctTargetEye - m_vctCurrentEye;

	if(vctDelta.Size2D() < ftDelta * ftVelocityEye)
	{
		m_vctCurrentEye = m_vctTargetEye;
	}
	else
	{
		vctDelta.Normalize();
		m_vctCurrentEye = m_vctCurrentEye + vctDelta * ftDelta * ftVelocityEye;
	}

	m_vctCurrentEye = m_vctTargetEye;

	if(m_bJerk)
	{		
		// if(((int)(m_fFlashTime * 5.0f)) % 2 == 0)
		SVector vctDelta = m_vctCurrentEye - m_vctCurrentAt;
		m_vctCurrentAt.Y += float(rand()%10-5)/10.0f * m_ftJerk * vctDelta.Size() / 20.0f;
	}

	CreateLookAt(m_vctCurrentEye, m_vctCurrentAt, SVector(0.0f, 1.0f, 0.0f));
}
示例#3
0
void GSphere::SetSphere( const GBoxAA *pBox, bool bYIgnore )
{
	if( !pBox )
	{
		Init();
		return;
	}
	vecCenter = pBox->vecCenter;
	if( bYIgnore )
	{
		fRadius = appSqrt( appSquare(pBox->vecSize.X/2.0f) + appSquare(pBox->vecSize.Z/2.0f) );
	}
	else
	{
		SVector v = pBox->vecCenter - pBox->vecMax;
		fRadius = v.Size();
	}
	if( fRadius < pBox->vecSize.X/2.0f ) fRadius = pBox->vecSize.X/2.0f;
	if( !bYIgnore && fRadius < pBox->vecSize.Y/2.0f ) fRadius = pBox->vecSize.Y/2.0f;
	if( fRadius < pBox->vecSize.Z/2.0f ) fRadius = pBox->vecSize.Z/2.0f;
	fRadiusSq = appSquare(fRadius);
}
示例#4
0
文件: t_vector.cpp 项目: iley/intelib
int main()
{
    poc();
    try {
        TestSection("SVector");
        TestSubsection("Matrix");
        {
            SMatrix<5> matrix;
            matrix[1][2][1][0][1] = 123;
            matrix[2][1][0][1][4] = 777;

            TEST("matrix_1", matrix[1][2][1][0][1].GetInt(), 123);
            TEST("matrix_2", matrix[2][1][0][1][4].GetInt(), 777);
        }
        TestSubsection("Matrix_has_you");
        {
            SVector m;
            SVector m0;
            SVector m1;
            SVector m00;
            SVector m01;
            SVector m10;
            SVector m11;

            m10[1] = SReference(25);

            m0[0] = m00;
            m0[1] = m01;
            m1[0] = m10;
            m1[1] = m11;

            m[0]  = m0;
            m[1]  = m1;

            SMatrixRef<3> matr(m);

            TEST("matrix_has_you", matr[1][0][1].GetInt(), 25);
        }
        TestSubsection("resize");
        {
            SVector v;
            v[7] = 5;
            TEST("resize_1", v->Size(), 8);
            v[12] = 5;
            TEST("resize_2", v->Size(), 13);
            v[13] = 5;
            TEST("resize_3", v->Size(), 14);
        }
#if INTELIB_DEBUG_COUNTERS == 1
        TestSubsection("leaks");
        {
            int before = SExpression::object_counter;
            {
                SVector v;
                v[7] = 5;
                SVectorRef vr(v);
                SVectorRef vr2;
                vr2 = vr;
                SVectorRef vr3(vr2);
                for(int i=0; i<200; i++) vr3[vr3->Size()] = SReference(i);
            }
            TEST("no_leaks", SExpression::object_counter, before);
        }
#endif
        TestSubsection("TextRepresentation");
        {
            SVector v;
            for(int i=0; i<5; i++) v[i]=i;
            TEST("text_rep", v->TextRepresentation().c_str(),
                 "#~(0 1 2 3 4)");

        }
        TestSubsection("Range Copying");
        {
            SVector v;
            for(int i=0; i<15; i++) v[i]=i;

            SVectorRange r(v,5,3);
            TEST("range_copy", r.Copy()->TextRepresentation().c_str(),
                 "#~(5 6 7)");
            TESTB("copy_keeps_positive_resizeability",
                 r.Copy()->IsResizeable());

            SVector vn(5);
            for(int i=0; i<5; i++) vn[i]=i*100;
            SVectorRange rn(vn,1,2);
            TESTB("copy_keeps_negative_resizeability",
                 !rn.Copy()->IsResizeable());
            TESTB("copy_positive_resizeability",
                 rn.Copy(true)->IsResizeable());
            TESTB("copy_negative_resizeability",
                 !rn.Copy(false)->IsResizeable());

            SVectorRange r200(v,5,200);
            TEST("range_size_limited", r200.Copy()->Size(), 10);

        }
        TestSubsection("Range Erasing");
        {
            SVector v;
            for(int i=0; i<15; i++) v[i]=i;
            SVectorRange r(v,3,10);
            r.Erase();
            TEST("range_erase", v->TextRepresentation().c_str(),
                 "#~(0 1 2 13 14)");
            TEST("range_erase_size", v->Size(), 5);
            TEST("range_erase_range_len", r.Copy()->Size(), 0);

        }
        TestSubsection("Range Replacing");
        {
            SVector v, w;
            for(int i=0; i<15; i++) v[i]=i;
            for(int i=0; i<5; i++) w[i]=i*100;

            SVectorRange r(v,3,10);
            r.Replace(w);
            TEST("range_replace_less", v->TextRepresentation().c_str(),
                 "#~(0 1 2 0 100 200 300 400 13 14)");
            TEST("range_replace_less_size", v->Size(), 10);
            TEST("range_replace_less_range_len", r.Copy()->Size(), 5);
        }
        {
            SVector v, w;
            for(int i=0; i<10; i++) v[i]=i;
            for(int i=0; i<5; i++) w[i]=i*100;

            SVectorRange r(w,1,2);
            r.Replace(v);
            TEST("range_replace_more", w->TextRepresentation().c_str(),
                 "#~(0 0 1 2 3 4 5 6 7 8 9 300 400)");
            TEST("range_replace_more_size", w->Size(), 13);
            TEST("range_replace_more_range_len", r.Copy()->Size(), 10);
        }
        TestScore();
    }
    catch(const IntelibX &ex) {
        printf("Caught IntelibX: %s\n%s\n",
            ex.Description(),
            ex.Parameter().GetPtr() ?
                ex.Parameter()->TextRepresentation().c_str() : "");
    }
    catch(...) {
        printf("Something strange caught\n");
    }
    poc();
    return 0;
}