Beispiel #1
0
int luaGetH(lua_State *L)
{
	float x=(float)lua_tonumber(L, 1);
	float z=(float)lua_tonumber(L, 2);
	BOOL hit;
	FLOAT dist;
	LPDIRECT3DVERTEXBUFFER8 pVB;
	LPDIRECT3DINDEXBUFFER8  pIB;
	WORD*            pIndices;
	D3DVERTEX*    pVertices;
	if(m_pLandMesh==NULL) {
		lua_pushnumber(L,-100000.0f);
		return 1;
	}
	m_pLandMesh->GetSysMemMesh()->GetVertexBuffer( &pVB );
	m_pLandMesh->GetSysMemMesh()->GetIndexBuffer( &pIB );
	pIB->Lock( 0, 0, (BYTE**)&pIndices, 0 );
	pVB->Lock( 0, 0, (BYTE**)&pVertices, 0 );
	D3DXVECTOR3 v1,v2;
	GVector dir2=GVector(0,-1,0);
	v1.x=x;v1.y=100000.0f;v1.z=z;
	v2.x=0;v2.y=-1;v2.z=0;
	D3DXIntersect(m_pLandMesh->GetSysMemMesh(),&v1,&v2,&hit,NULL,NULL,NULL,&dist,NULL,NULL);
	if(!hit) dist=-100000.0f;
	else dist=100000.0f-dist;
	lua_pushnumber(L,dist);
	return 1;

}
Beispiel #2
0
int luaSetView(lua_State *L)
{
	UserEyePos.x=(float)lua_tonumber(L, 1);
	UserEyePos.y=(float)lua_tonumber(L, 2);
	UserEyePos.z=(float)lua_tonumber(L, 3);
	UserRefPos.x=(float)lua_tonumber(L, 4);
	UserRefPos.y=(float)lua_tonumber(L, 5);
	UserRefPos.z=(float)lua_tonumber(L, 6);
	UserUpVec=GVector(0,1,0);
	GVector u=(UserRefPos-UserEyePos).cross(UserUpVec).cross(UserRefPos-UserEyePos).normalize2();
	if(u.abs()!=0) UserUpVec=u;
	else UserUpVec=GVector(0,0,-1);
	ViewType=-1;
	ViewUpdate=1;
	return 0;
}
Beispiel #3
0
int luaWind(lua_State *L)
{
	float x=(float)lua_tonumber(L, 1);
	float y=(float)lua_tonumber(L, 2);
	float z=(float)lua_tonumber(L, 3);

	AirSpeed=GVector(x,y,z);
	return 0;
}
Beispiel #4
0
int luaApplyForce(lua_State *L)
{
	int n=(int)lua_tonumber(L, 1);
	float x=(float)lua_tonumber(L, 2);
	float y=(float)lua_tonumber(L, 3);
	float z=(float)lua_tonumber(L, 4);
	if(n<0 || n>=World->ChipCount) return 0;
	if(World->Rigid[n]) {
		World->Rigid[n]->ApplyForce(GVector(x,y,z),World->Rigid[n]->X);
	}
	return 0;
}
Beispiel #5
0
int luaApplyForceObj(lua_State *L)
{
	int n=(int)lua_tonumber(L, 1);
	float x=(float)lua_tonumber(L, 2);
	float y=(float)lua_tonumber(L, 3);
	float z=(float)lua_tonumber(L, 4);
	if(n<0 || n>=GOBJMAX) return 0;
	if(World->Object[n]) {
		World->Object[n]->ApplyForce(GVector(x,y,z),World->Object[n]->X);
	}
	return 0;
}
Beispiel #6
0
	GLink() {
		RigidB=NULL;
		RigidB2=NULL;
		OffsetA.clear();
		OffsetB.clear();
		Axis=GVector(1,0,0);
		Angle=0.0f;
		Length=1.0f;
		SpringK=1.0f;
		DamperK=0.5f;
		FrictionK=0;
		DestroyK=0;
		PreDestroyRatio=0;
	}
Beispiel #7
0
int luaLoadLand(lua_State *L)
{
	char *str=(char*)lua_tostring(L, 1);
	int r=0;
	char st[_MAX_PATH];
	if(strcmp(szLandFileName0,str)!=0) {
		char *s=SearchFolder(CurrDataDir,str,st);
		if(s==NULL) {
			char *s=SearchFolder(DataDir,str,st);
			if(s==NULL) {
				s=SearchFolder(ResourceDir,str,st);
				if(s==NULL) {
					lua_pushnumber(L,0);
					return 1;
				}
			}
		}

  
		r=LoadLand(G3dDevice, s);
		if(r==0) {
			char szDrive[_MAX_DRIVE + 1];	// ドライブ名格納領域 
			char szPath [_MAX_PATH + 1];	// パス名格納領域 
			char szTitle[_MAX_FNAME + 1];	// ファイルタイトル格納領域 
			char szExt  [_MAX_EXT + 1];		// ファイル拡張子格納領域 

			// 絶対パスを分解 
			_splitpath ( str, 
						szDrive, szPath, 
						szTitle, szExt);
			lstrcpy(szLandFileName,str);
			lstrcpy(szLandFileName0,szTitle);
			lstrcat(szLandFileName0,szExt);
			GFloat y=World->Land->GetY(0,0);
			Chip[0]->CalcTotalCenter();
			Chip[0]->X=GVector(0,Chip[0]->Top->TotalRadius*2+2+y,0);
			Chip[0]->R=GMatrix33();
			World->RestoreLink(Chip[0],Chip[0]);
			if(Chip[0]->X.y<=-100000.0f)Chip[0]->X.y=0.0f;
			m_pLandMesh->InvalidateDeviceObjects();
			m_pLandMesh->RestoreDeviceObjects(G3dDevice);
		}
	}
	World->MainStepCount=-1;

	lua_pushnumber(L,r);
	return 1;
}
Beispiel #8
0
int luaWarpObj(lua_State *L)
{
	int n=(int)lua_tonumber(L, 1);
	float x=(float)lua_tonumber(L, 2);
	float y=(float)lua_tonumber(L, 3);
	float z=(float)lua_tonumber(L, 4);
	if(n<0 || n>=GOBJMAX) return 0;
	if(World->Object[n]) {
		GVector v=GVector(x,y,z)-World->Object[n]->X;
		World->Object[n]->TranslateWithChild(v);
		World->Object[n]->ResetXfWithChild();
		World->Object[n]->CalcTotalCenter();
		World->MainStepCount=-1;
	}
	return 0;
}
Beispiel #9
0
/***********************************************************************//**
 * @brief Returns parameter gradients of source model
 *
 * @param[in] srcDir True photon direction.
 * @param[in] srcEng True photon energy.
 * @param[in] srcTime True photon arrival time.
 *
 * This method returns the parameter gradients of the factorized source model
 * for a given true photon arrival direction, true photon energy and true
 * photon arrival time.
 ***************************************************************************/
GVector GModelSky::gradients(const GSkyDir& srcDir, const GEnergy& srcEng,
                             const GTime& srcTime)
{
    // Evaluate source model gradients
    if (m_spatial  != NULL) m_spatial->eval_gradients(srcDir);
    if (m_spectral != NULL) m_spectral->eval_gradients(srcEng);
    if (m_temporal != NULL) m_temporal->eval_gradients(srcTime);

    // Set vector of gradients
    GVector gradients;
    if (size() > 0) {
        gradients = GVector(size());
        for (int i = 0; i < size(); ++i) {
            gradients[i] = m_pars[i]->gradient();
        }
    }

    // Return gradients
    return gradients;
}
Beispiel #10
0
int luaAddChip(lua_State *L)
{
	int rn,an;
	int dirCode=0;
	GVector offA,offB,axis[3];
	GLink *link1=NULL,*link2=NULL;
	axis[1]=GVector(0,1,0);
	
	int parentNo=(int)lua_tonumber(L, 1);
	char *type=(char*)lua_tostring(L, 2);
	char *news=(char*)lua_tostring(L, 3);
	float angle=(float)lua_tonumber(L, 4);

	if(parentNo<0 || parentNo>=ChipCount) {
		lua_pushnumber(L,-1);
		return 1;
	}

	if(strcmp(news,"N")==0) {
		offA=GVector(0,0,-CHIPSIZE/2);
		offB=GVector(-0,0,CHIPSIZE/2);
		axis[0]=GVector(-1,0,0);
		axis[2]=GVector(0,0,1);
		rn=2;
		dirCode=0x01;
	}
	else if(strcmp(news,"E")==0) {
		offA=GVector(-CHIPSIZE/2,0,0);
		offB=GVector(CHIPSIZE/2,0,0);
		axis[0]=GVector(0,0,1);
		axis[2]=GVector(1,0,0);
		rn=3;
		dirCode=0x02;
	}
	else if(strcmp(news,"W")==0) {
		offA=GVector(CHIPSIZE/2,0,0);
		offB=GVector(-CHIPSIZE/2,0,0);
		axis[0]=GVector(0,0,-1);
		axis[2]=GVector(-1,0,0);
		rn=1;
		dirCode=0x04;
	}
	else  {	//"S"
		offA=GVector(0,0,CHIPSIZE/2);
		offB=GVector(0,0,-CHIPSIZE/2);
		axis[0]=GVector(1,0,0);
		axis[2]=GVector(0,0,-1);
		rn=0;
		dirCode=0x08;
	}

	int flag=0;
	if(strcmp(type,"CHIP")==0) {
		MakeChip(GT_CHIP,rn);
		an=0;
		flag=2;
	}
	else if(strcmp(type,"FRAME")==0) {
		MakeChip(GT_CHIP2,rn);
		an=0;
		flag=2;
	}
	else if(strcmp(type,"WEIGHT")==0) {
		MakeChip(GT_CHIPH,rn);
		an=0;
		flag=2;
	}
	else if(strcmp(type,"COWL")==0) {
		MakeChip(GT_COWL,rn);
		an=0;
		flag=2;
	}
	else if(strcmp(type,"RUDDER")==0) {
		MakeChip(GT_RUDDER,rn);
		an=1;
		flag=1;
	}
	else if(strcmp(type,"RUDDERF")==0) {
		MakeChip(GT_RUDDER2,rn);
		an=1;
		flag=1;
	}
	else if(strcmp(type,"TRIM")==0) {
		MakeChip(GT_TRIM,rn);
		an=2;
		flag=1;
	}
	else if(strcmp(type,"TRIMF")==0) {
		MakeChip(GT_TRIM2,rn);
		an=2;
		flag=1;
	}
	else if(strcmp(type,"JET")==0) {
		MakeChip(GT_JET,rn);
		an=0;
		flag=1;
	}
	else if(strcmp(type,"ARM")==0) {
		MakeChip(GT_ARM,rn);
		an=0;
		flag=1;
	}
	if(flag>0) {
		int cno=ChipCount;
		Chip[parentNo]->DirCode|=dirCode;
		if(flag==2) {
			if(dirCode==0x01) {
				Chip[cno]->CheckShape.PointN=6;
				Chip[cno]->CheckShape.Point[0]=Chip[cno]->Shape.Point[1];
				Chip[cno]->CheckShape.Point[1]=Chip[cno]->Shape.Point[0];
				Chip[cno]->CheckShape.Point[2]=Chip[cno]->Shape.Point[2];
				Chip[cno]->CheckShape.Point[3]=Chip[cno]->Shape.Point[5];
				Chip[cno]->CheckShape.Point[4]=Chip[cno]->Shape.Point[6];
				Chip[cno]->CheckShape.Point[5]=Chip[cno]->Shape.Point[8];
			}
			else if(dirCode==0x02) {
				Chip[cno]->CheckShape.PointN=6;
				Chip[cno]->CheckShape.Point[0]=Chip[cno]->Shape.Point[2];
				Chip[cno]->CheckShape.Point[1]=Chip[cno]->Shape.Point[1];
				Chip[cno]->CheckShape.Point[2]=Chip[cno]->Shape.Point[3];
				Chip[cno]->CheckShape.Point[3]=Chip[cno]->Shape.Point[6];
				Chip[cno]->CheckShape.Point[4]=Chip[cno]->Shape.Point[7];
				Chip[cno]->CheckShape.Point[5]=Chip[cno]->Shape.Point[8];
			}
			else if(dirCode==0x04) {
				Chip[cno]->CheckShape.PointN=6;
				Chip[cno]->CheckShape.Point[0]=Chip[cno]->Shape.Point[0];
				Chip[cno]->CheckShape.Point[1]=Chip[cno]->Shape.Point[3];
				Chip[cno]->CheckShape.Point[2]=Chip[cno]->Shape.Point[1];
				Chip[cno]->CheckShape.Point[3]=Chip[cno]->Shape.Point[4];
				Chip[cno]->CheckShape.Point[4]=Chip[cno]->Shape.Point[5];
				Chip[cno]->CheckShape.Point[5]=Chip[cno]->Shape.Point[8];
			}
			else if(dirCode==0x08) {
				Chip[cno]->CheckShape.PointN=6;
				Chip[cno]->CheckShape.Point[0]=Chip[cno]->Shape.Point[3];
				Chip[cno]->CheckShape.Point[1]=Chip[cno]->Shape.Point[2];
				Chip[cno]->CheckShape.Point[2]=Chip[cno]->Shape.Point[0];
				Chip[cno]->CheckShape.Point[3]=Chip[cno]->Shape.Point[4];
				Chip[cno]->CheckShape.Point[4]=Chip[cno]->Shape.Point[7];
				Chip[cno]->CheckShape.Point[5]=Chip[cno]->Shape.Point[8];
			}
			Chip[cno]->SaveShape=Chip[cno]->CheckShape;
		}
		else {
			Chip[cno]->CheckShape=Chip[cno]->Shape;
			Chip[cno]->SaveShape=Chip[cno]->Shape;
		}
		if(strcmp(type,"COWL")==0) link2=World->AddCowl(Chip[parentNo],offA,Chip[ChipCount],offB,axis[an],angle);
		else link2=World->AddHinge(Chip[parentNo],offA,Chip[ChipCount],offB,axis[an],angle,1,0.5);
		ChipCount++;if(ChipCount>=GCHIPMAX) ChipCount=GCHIPMAX-1;
	}
	else {
		if(strcmp(type,"WHEEL")==0) {
			int cno2=ChipCount;
			MakeChip(GT_DUMMY,rn);
			Chip[cno2]->CheckShape=Chip[cno2]->Shape;
			Chip[cno2]->SaveShape=Chip[cno2]->Shape;
			link2=World->AddHinge(Chip[parentNo],offA,Chip[cno2],offB,axis[0],angle,1.0,0.5);
			ChipCount++;if(ChipCount>=GCHIPMAX) ChipCount=GCHIPMAX-1;
			int cno=ChipCount;
			MakeChip(GT_WHEEL,rn);
			Chip[cno]->CheckShape=Chip[cno]->Shape;
			Chip[cno]->SaveShape=Chip[cno]->Shape;
			Chip[parentNo]->DirCode|=dirCode;
			link1=World->AddShaft(Chip[cno2],GVector(0,0,0),Chip[cno],GVector(0,0,0),axis[1],0);
			ChipCount++;if(ChipCount>=GCHIPMAX) ChipCount=GCHIPMAX-1;
			an=2;
		}
		else if(strcmp(type,"RLW")==0) {
			int cno2=ChipCount;
			MakeChip(GT_DUMMY,rn);
			Chip[cno2]->CheckShape=Chip[cno2]->Shape;
			Chip[cno2]->SaveShape=Chip[cno2]->Shape;
			link2=World->AddHinge(Chip[parentNo],offA,Chip[cno2],offB,axis[0],angle,1.0,0.5);
			ChipCount++;if(ChipCount>=GCHIPMAX) ChipCount=GCHIPMAX-1;
			int cno=ChipCount;
			MakeChip(GT_RLW,rn);
			Chip[cno]->CheckShape=Chip[cno]->Shape;
			Chip[cno]->SaveShape=Chip[cno]->Shape;
			Chip[parentNo]->DirCode|=dirCode;
			link1=World->AddShaft(Chip[cno2],GVector(0,0,0),Chip[cno],GVector(0,0,0),axis[1],0);
			ChipCount++;if(ChipCount>=GCHIPMAX) ChipCount=GCHIPMAX-1;
			an=2;
		}
	}
	//World->CalcLink(Chip[parentNo]);
	World->RestoreLink(Chip[0],Chip[0]);
	lua_pushnumber(L,ChipCount-1);
	return 1;
}
Beispiel #11
0
/***********************************************************************//**
 * @brief Test Cholesky decomposition
 ***************************************************************************/
void TestGMatrixSparse::matrix_cholesky(void)
{
    // Setup matrix for Cholesky decomposition
    GMatrixSparse chol_test(5,5);
    chol_test(0,0) = 1.0;
    chol_test(0,1) = 0.2;
    chol_test(0,2) = 0.2;
    chol_test(0,3) = 0.2;
    chol_test(0,4) = 0.2;
    chol_test(1,0) = 0.2;
    chol_test(2,0) = 0.2;
    chol_test(3,0) = 0.2;
    chol_test(4,0) = 0.2;
    chol_test(1,1) = 1.0;
    chol_test(2,2) = 1.0;
    chol_test(3,3) = 1.0;
    chol_test(4,4) = 1.0;

    // Try to solve now (should not work)
    test_try("Try Cholesky solver without factorisation");
    try {
        GVector vector(5);
        vector = chol_test.cholesky_solver(vector);
        test_try_failure("Expected GException::matrix_not_factorised exception.");
    }
    catch (GException::matrix_not_factorised &e) {
        test_try_success();
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Perform Cholesky decomposition
    GMatrixSparse cd = chol_test.cholesky_decompose();

    // Test Cholesky solver (first test)
    GVector e0(5);
    GVector a0(5);
    e0[0] = 1.0;
    a0[0] = 1.0;
    a0[1] = 0.2;
    a0[2] = 0.2;
    a0[3] = 0.2;
    a0[4] = 0.2;
    GVector s0 = cd.cholesky_solver(a0);
    double res = max(abs(s0-e0));
    test_value(res, 0.0, 1.0e-15, "Test cholesky_solver() method - 1");

    // Test Cholesky solver (second test)
	e0[0] = 0.0;
	e0[1] = 1.0;
	a0[0] = 0.2;
	a0[1] = 1.0;
	a0[2] = 0.0;
	a0[3] = 0.0;
	a0[4] = 0.0;
	s0    = cd.cholesky_solver(a0);
	res   = max(abs(s0-e0));
    test_value(res, 0.0, 1.0e-15, "Test cholesky_solver() method - 2");

    // Test Cholesky solver (third test)
	e0[1] = 0.0;
	e0[2] = 1.0;
	a0[1] = 0.0;
	a0[2] = 1.0;
	s0    = cd.cholesky_solver(a0);
	res   = max(abs(s0-e0));
    test_value(res, 0.0, 1.0e-15, "Test cholesky_solver() method - 3");

    // Test Cholesky solver (forth test)
	e0[2] = 0.0;
	e0[3] = 1.0;
	a0[2] = 0.0;
	a0[3] = 1.0;
	s0    = cd.cholesky_solver(a0);
	res   = max(abs(s0-e0));
    test_value(res, 0.0, 1.0e-15, "Test cholesky_solver() method - 4");

    // Test Cholesky solver (fifth test)
	e0[3] = 0.0;
	e0[4] = 1.0;
	a0[3] = 0.0;
	a0[4] = 1.0;
	s0    = cd.cholesky_solver(a0);
	res   = max(abs(s0-e0));
    test_value(res, 0.0, 1.0e-15, "Test cholesky_solver() method - 5");

	// Setup matrix for Cholesky decomposition with zero row/col
	GMatrixSparse chol_test_zero(6,6);
	chol_test_zero(0,0) = 1.0;
	chol_test_zero(0,1) = 0.2;
	chol_test_zero(0,2) = 0.2;
	chol_test_zero(0,4) = 0.2;
	chol_test_zero(0,5) = 0.2;
	chol_test_zero(1,0) = 0.2;
	chol_test_zero(2,0) = 0.2;
	chol_test_zero(4,0) = 0.2;
	chol_test_zero(5,0) = 0.2;
	chol_test_zero(1,1) = 1.0;
	chol_test_zero(2,2) = 1.0;
	chol_test_zero(4,4) = 1.0;
	chol_test_zero(5,5) = 1.0;

    // Test compressed Cholesky decomposition
	GMatrixSparse cd_zero = chol_test_zero.cholesky_decompose();

    // Test compressed Cholesky solver (first test)
	e0 = GVector(6);
	a0 = GVector(6);
	e0[0] = 1.0;
	a0[0] = 1.0;
	a0[1] = 0.2;
	a0[2] = 0.2;
	a0[4] = 0.2;
	a0[5] = 0.2;
	s0    = cd_zero.cholesky_solver(a0);
	res   = max(abs(s0-e0));
    test_value(res, 0.0, 1.0e-15, "Test compressed cholesky_solver() method - 1");

    // Test compressed Cholesky solver (second test)
	e0[0] = 0.0;
	e0[1] = 1.0;
	a0[0] = 0.2;
	a0[1] = 1.0;
	a0[2] = 0.0;
	a0[4] = 0.0;
	a0[5] = 0.0;
	s0    = cd_zero.cholesky_solver(a0);
	res   = max(abs(s0-e0));
    test_value(res, 0.0, 1.0e-15, "Test compressed cholesky_solver() method - 2");

    // Test compressed Cholesky solver (third test)
	e0[1] = 0.0;
	e0[2] = 1.0;
	a0[1] = 0.0;
	a0[2] = 1.0;
	s0    = cd_zero.cholesky_solver(a0);
	res   = max(abs(s0-e0));
    test_value(res, 0.0, 1.0e-15, "Test compressed cholesky_solver() method - 3");

    // Test compressed Cholesky solver (forth test)
	e0[2] = 0.0;
	e0[4] = 1.0;
	a0[2] = 0.0;
	a0[4] = 1.0;
	s0    = cd_zero.cholesky_solver(a0);
	res   = max(abs(s0-e0));
    test_value(res, 0.0, 1.0e-15, "Test compressed cholesky_solver() method - 4");

    // Test compressed Cholesky solver (fifth test)
	e0[4] = 0.0;
	e0[5] = 1.0;
	a0[4] = 0.0;
	a0[5] = 1.0;
	s0    = cd_zero.cholesky_solver(a0);
	res   = max(abs(s0-e0));
    test_value(res, 0.0, 1.0e-15, "Test compressed cholesky_solver() method - 5");

	// Setup matrix for Cholesky decomposition with zero row/col (unsymmetric case)
	GMatrixSparse chol_test_zero2(6,5);
	chol_test_zero2(0,0) = 1.0;
	chol_test_zero2(0,1) = 0.2;
	chol_test_zero2(0,2) = 0.2;
	chol_test_zero2(0,3) = 0.2;
	chol_test_zero2(0,4) = 0.2;
	chol_test_zero2(1,0) = 0.2;
	chol_test_zero2(2,0) = 0.2;
	chol_test_zero2(4,0) = 0.2;
	chol_test_zero2(5,0) = 0.2;
	chol_test_zero2(1,1) = 1.0;
	chol_test_zero2(2,2) = 1.0;
	chol_test_zero2(4,3) = 1.0;
	chol_test_zero2(5,4) = 1.0;

    // Test compressed Cholesky decomposition (unsymmetric case)
	GMatrixSparse cd_zero2 = chol_test_zero2.cholesky_decompose();

    // Test compressed Cholesky solver (unsymmetric case)
	e0 = GVector(5);
	a0 = GVector(6);
	e0[0] = 1.0;
	a0[0] = 1.0;
	a0[1] = 0.2;
	a0[2] = 0.2;
	a0[4] = 0.2;
	a0[5] = 0.2;
	s0    = cd_zero2.cholesky_solver(a0);
	res   = max(abs(s0-e0));
    test_value(res, 0.0, 1.0e-15, 
               "Test unsymmetric compressed cholesky_solver() method - 1");

    // Test compressed Cholesky solver (unsymmetric case)
	e0[0] = 0.0;
	e0[1] = 1.0;
	a0[0] = 0.2;
	a0[1] = 1.0;
	a0[2] = 0.0;
	a0[4] = 0.0;
	a0[5] = 0.0;
	s0    = cd_zero2.cholesky_solver(a0);
	res   = max(abs(s0-e0));
    test_value(res, 0.0, 1.0e-15, 
               "Test unsymmetric compressed cholesky_solver() method - 2");

    // Test compressed Cholesky solver (unsymmetric case)
	e0[1] = 0.0;
	e0[2] = 1.0;
	a0[1] = 0.0;
	a0[2] = 1.0;
	s0    = cd_zero2.cholesky_solver(a0);
	res   = max(abs(s0-e0));
    test_value(res, 0.0, 1.0e-15, 
               "Test unsymmetric compressed cholesky_solver() method - 3");

    // Test compressed Cholesky solver (unsymmetric case)
	e0[2] = 0.0;
	e0[3] = 1.0;
	a0[2] = 0.0;
	a0[4] = 1.0;
	s0    = cd_zero2.cholesky_solver(a0);
	res   = max(abs(s0-e0));
    test_value(res, 0.0, 1.0e-15, 
               "Test unsymmetric compressed cholesky_solver() method - 4");

    // Test compressed Cholesky solver (unsymmetric case)
	e0[3] = 0.0;
	e0[4] = 1.0;
	a0[4] = 0.0;
	a0[5] = 1.0;
	s0    = cd_zero2.cholesky_solver(a0);
	res   = max(abs(s0-e0));
    test_value(res, 0.0, 1.0e-15, 
               "Test unsymmetric compressed cholesky_solver() method - 5");

	// Test Cholesky inverter (inplace)
	GMatrixSparse unit(5,5);
	unit(0,0) = 1.0;
	unit(1,1) = 1.0;
	unit(2,2) = 1.0;
	unit(3,3) = 1.0;
	unit(4,4) = 1.0;
	GMatrixSparse chol_test_inv = chol_test.cholesky_invert();
    GMatrixSparse ci_product    = chol_test * chol_test_inv;
    GMatrixSparse ci_residuals  = ci_product - unit;
	res = (ci_residuals.abs()).max();
    test_value(res, 0.0, 1.0e-15, "Test Cholesky inverter");
            
	// Test Cholesky inverter
    /*
	chol_test_inv = chol_test.cholesky_invert();
    ci_product    = chol_test * chol_test_inv;
    ci_residuals  = ci_product - unit;
	res           = (ci_residuals.abs()).max();
    test_value(res, 0.0, 1.0e-15, "Test Cholesky inverter");
    */

    // Test Cholesky inverter for compressed matrix
    unit = GMatrixSparse(6,6);
    unit(0,0) = 1.0;
    unit(1,1) = 1.0;
    unit(2,2) = 1.0;
    unit(4,4) = 1.0;
    unit(5,5) = 1.0;
    GMatrixSparse chol_test_zero_inv = chol_test_zero.cholesky_invert();
    GMatrixSparse ciz_product        = chol_test_zero * chol_test_zero_inv;
    GMatrixSparse ciz_residuals      = ciz_product - unit;
    res = (ciz_residuals.abs()).max();
    test_value(res, 0.0, 1.0e-15, "Test compressed matrix Cholesky inverter");

    // Return
    return;
}
Beispiel #12
0
/***********************************************************************//**
 * @brief Test Cholesky decomposition
 ***************************************************************************/
void TestGSymMatrix::matrix_cholesky(void)
{
    // Test Cholesky decomposition
	GSymMatrix cd           = cholesky_decompose(m_test);
	GMatrix    cd_lower     = cd.extract_lower_triangle();
	GMatrix    cd_upper     = transpose(cd_lower);
	GMatrix    cd_product   = cd_lower * cd_upper;
	GMatrix    cd_residuals = GMatrix(m_test) - cd_product;
	double res = (abs(cd_residuals)).max();
    test_value(res, 0.0, 1.0e-15, "Test cholesky_decompose() method");

    // Test compressed Cholesky decomposition
    GSymMatrix test_zero         = set_matrix_zero();
	GSymMatrix cd_zero           = cholesky_decompose(test_zero);
	GMatrix    cd_zero_lower     = cd_zero.extract_lower_triangle();
	GMatrix    cd_zero_upper     = transpose(cd_zero_lower);
	GMatrix    cd_zero_product   = cd_zero_lower * cd_zero_upper;
	GMatrix    cd_zero_residuals = GMatrix(test_zero) - cd_zero_product;
	res = (abs(cd_zero_residuals)).max();
    test_value(res, 0.0, 1.0e-15, "Test compressed cholesky_decompose() method");

	// Test Cholesky inplace decomposition
	GSymMatrix test = m_test;
    test.cholesky_decompose();
	GMatrix cd_lower2 = test.extract_lower_triangle();
    test_assert((cd_lower2 == cd_lower), "Test inplace cholesky_decompose() method");

    // Test Cholesky solver (first test)
	GVector e0(g_rows);
	GVector a0(g_rows);
	e0[0] = 1.0;
	e0[1] = 0.0;
	e0[2] = 0.0;
	a0[0] = g_matrix[0];
	a0[1] = g_matrix[3];
	a0[2] = g_matrix[6];
	GVector s0 = cd.cholesky_solver(a0) - e0;
	res = max(abs(s0));
    test_value(res, 0.0, 1.0e-15, "Test cholesky_solver() method");

    // Test Cholesky solver (second test)
	e0[0] = 0.0;
	e0[1] = 1.0;
	e0[2] = 0.0;
	a0[0] = g_matrix[1];
	a0[1] = g_matrix[4];
	a0[2] = g_matrix[7];
	s0 = cd.cholesky_solver(a0) - e0;
	res = max(abs(s0));
    test_value(res, 0.0, 1.0e-15, "Test cholesky_solver() method");

    // Test Cholesky solver (third test)
	e0[0] = 0.0;
	e0[1] = 0.0;
	e0[2] = 1.0;
	a0[0] = g_matrix[2];
	a0[1] = g_matrix[5];
	a0[2] = g_matrix[8];
	s0 = cd.cholesky_solver(a0) - e0;
	res = max(abs(s0));
    test_value(res, 0.0, 1.0e-15, "Test cholesky_solver() method");

    // Test compressed Cholesky solver (first test)
	e0 = GVector(g_rows+1);
	a0 = GVector(g_rows+1);
	e0[0] = 1.0;
	e0[1] = 0.0;
	e0[2] = 0.0;
	e0[3] = 0.0;
	a0[0] = g_matrix[0];
	a0[1] = g_matrix[3];
	a0[2] = 0.0;
	a0[3] = g_matrix[6];
	s0    = cd_zero.cholesky_solver(a0) - e0;
	res   = max(abs(s0));
    test_value(res, 0.0, 1.0e-15, "Test compressed cholesky_solver() method");

    // Test compressed Cholesky solver (second test)
	e0[0] = 0.0;
	e0[1] = 1.0;
	e0[2] = 0.0;
	e0[3] = 0.0;
	a0[0] = g_matrix[1];
	a0[1] = g_matrix[4];
	a0[2] = 0.0;
	a0[3] = g_matrix[7];
	s0    = cd_zero.cholesky_solver(a0) - e0;
	res   = max(abs(s0));
    test_value(res, 0.0, 1.0e-15, "Test compressed cholesky_solver() method");

    // Test compressed Cholesky solver (third test)
	e0[0] = 0.0;
	e0[1] = 0.0;
	e0[2] = 0.0;
	e0[3] = 1.0;
	a0[0] = g_matrix[2];
	a0[1] = g_matrix[5];
	a0[2] = 0.0;
	a0[3] = g_matrix[8];
	s0    = cd_zero.cholesky_solver(a0) - e0;
	res   = max(abs(s0));
    test_value(res, 0.0, 1.0e-15, "Test compressed cholesky_solver() method");

	// Test Cholesky inverter
	GSymMatrix unit(g_rows,g_cols);
	unit(0,0) = unit(1,1) = unit(2,2) = 1.0;
	GSymMatrix test_inv = m_test;
	test_inv.cholesky_invert();
    GMatrix ci_product   = m_test * test_inv;
    GMatrix ci_residuals = ci_product - unit;
	res = (abs(ci_residuals)).max();
    test_value(res, 0.0, 1.0e-15, "Test cholesky_invert method");

	// Test Cholesky inverter for compressed matrix
	unit = GSymMatrix(4,4);
	unit(0,0) = unit(1,1) = unit(3,3) = 1.0;
	GSymMatrix test_zero_inv = test_zero;
	test_zero_inv.cholesky_invert();
    GMatrix ciz_product   = test_zero * test_zero_inv;
    GMatrix ciz_residuals = ciz_product - unit;
	res = (abs(ciz_residuals)).max();
    test_value(res, 0.0, 1.0e-15, "Test compressed cholesky_invert method");

    // Return
    return;
}
Beispiel #13
0
bool ServiceDB::GetStationInfo(uint32 stationID, uint32 *systemID, uint32 *constellationID, uint32 *regionID, GPoint *position, GPoint *dockPosition, GVector *dockOrientation) {
    if(       systemID == NULL
        && constellationID == NULL
        && regionID == NULL
        && position == NULL
        && dockPosition == NULL
        && dockOrientation == NULL
    )
        return true;

    DBQueryResult res;
    if(!DBcore::RunQuery(res,
        "SELECT"
        " solarSystemID,"
        " constellationID,"
        " regionID,"
        " x, y, z,"
        " dockEntryX, dockEntryY, dockEntryZ,"
        " dockOrientationX, dockOrientationY, dockOrientationZ"
        " FROM staStations"
        " LEFT JOIN staStationTypes USING (stationTypeID)"
        " WHERE stationID = %u",
        stationID))
    {
        _log(DATABASE__ERROR, "Failed to query info for station %u: %s.", stationID, res.error.c_str());
        return false;
    }

    DBResultRow row;
    if(!res.GetRow(row)) {
        _log(DATABASE__ERROR, "Failed to query info for station %u: Station not found.", stationID);
        return false;
    }

    if(systemID != NULL)
        *systemID = row.GetUInt(0);
    if(constellationID != NULL)
        *constellationID = row.GetUInt(1);
    if(regionID != NULL)
        *regionID = row.GetUInt(2);
    if(position != NULL)
        *position = GPoint(
            row.GetDouble(3),
            row.GetDouble(4),
            row.GetDouble(5)
        );
    if(dockPosition != NULL)
        *dockPosition = GPoint(
            row.GetDouble(3) + row.GetDouble(6),
            row.GetDouble(4) + row.GetDouble(7),
            row.GetDouble(5) + row.GetDouble(8)
        );
    if(dockOrientation != NULL) {
        *dockOrientation = GVector(
            row.GetDouble(9),
            row.GetDouble(10),
            row.GetDouble(11)
        );
        // as it's direction, it should be normalized
        //dockOrientation->normalize();
    }

    return true;
}
Beispiel #14
0
		GLight() {
			Pos=GVector(0,10,10);
			Target=GVector(0,0,0);
			Link=NULL;
		}
Beispiel #15
0
		GCamera() {
			Pos=GVector(0,10,10);
			Target=GVector(0,0,0);
			Link=NULL;
		}