コード例 #1
0
ファイル: radarmap.cpp プロジェクト: Ezio47/OSGEarth
void RadarMap::slotFrameViewport(const osg::Vec3d& pos)
{
	if (m_pGeodeCross == nullptr)
	{
		m_pGeodeCross = new osg::Geode;
		osg::ref_ptr<osg::Geometry> pGeometry = new osg::Geometry;
		// 使用VBO,每帧实时的修改数据
		pGeometry->setUseVertexBufferObjects(true);
		m_pVertexCross = new osg::Vec3dArray;
		pGeometry->setVertexArray(m_pVertexCross);
		osg::ref_ptr<osg::Vec3Array> normal = new osg::Vec3Array;
		normal->push_back(osg::Vec3(0, 0, 1));
		pGeometry->setNormalArray(normal, osg::Array::BIND_OVERALL);
		osg::ref_ptr<osg::Vec4Array> color = new osg::Vec4Array;
		color->push_back(osg::Vec4(0.8, 0.8, 0.8, 1));
		pGeometry->setColorArray(color, osg::Array::BIND_OVERALL);
		pGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, 4));

		m_pGeodeCross->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
		m_pGeodeCross->getOrCreateStateSet()->setAttribute(
			new osg::LineWidth(0.5), osg::StateAttribute::ON);
		m_pGeodeCross->addDrawable(pGeometry);
		m_pHUDCamera->addChild(m_pGeodeCross);
	}
	osg::Vec3d mapPos = getLonLat(pos);
	// 经纬度是-180~180,-90~90,保证算出的是0~360和0~180
	double x = (mapPos.x() + 180.0) * m_iWidth / 360.0;
	double y = (mapPos.y() + 90.0) * m_iHeight / 180.0;

	// 更新缓冲区数据
	m_pVertexCross->clear();
	m_pVertexCross->push_back(osg::Vec3d(x, y - 5, 0));
	m_pVertexCross->push_back(osg::Vec3d(x, y + 5, 0));
	m_pVertexCross->push_back(osg::Vec3d(x - 5, y, 0));
	m_pVertexCross->push_back(osg::Vec3d(x + 5, y, 0));
	m_pVertexCross->dirty();
}
コード例 #2
0
ファイル: ephemeris.c プロジェクト: arnaud85/DataProcessing
int main(int argc, char const *argv[])
{
	//Local variables
	SpiceDouble et_0;
	SpiceDouble et_end;
	SpiceDouble *t = NULL;
	SpiceDouble **pos_hci = NULL;
	SpiceDouble **pos_iau = NULL;
	SpiceDouble **pos_hee = NULL;
	SpiceDouble *lon_iau = NULL;
	SpiceDouble *lat_iau = NULL;
	SpiceDouble *lon_hci = NULL;
	SpiceDouble *lat_hci = NULL;
	SpiceDouble *distance = NULL;
	SpiceInt n;
	SpiceInt i;
	char START_DATE[50]; 
	char STOP_DATE[50]; 
	char text_filename[50];
	char nc_filename[50];


	//Load specific kernels : leap years, planets and satellites objects, planetary constants and specific heliospheric frame (to use HCI frame) 
	if (!loadKernels(KERNELS))
	{
		printf("[ERROR] \"%s\" kernel list : no such file\n", KERNELS);
		exit(EXIT_FAILURE);
	}

	//Configure boundaries
	strcpy(START_DATE, argv[4]);
	strcpy(STOP_DATE, argv[5]);
	n = getBoundaries(START_DATE, &et_0, STOP_DATE, &et_end);
	if (n <= 0)
	{
		printf("[ERROR] Enable to get a date interval to compute Earth ephemeris.\n");

		exit(EXIT_FAILURE);
	}

	//Memory allocation
	t = (SpiceDouble*) malloc(n*sizeof(SpiceDouble));
	pos_hci = (SpiceDouble**) malloc(n*sizeof(SpiceDouble*));
	pos_iau = (SpiceDouble**) malloc(n*sizeof(SpiceDouble*));
	pos_hee = (SpiceDouble**) malloc(n*sizeof(SpiceDouble*));
	distance = (SpiceDouble*) malloc(n*sizeof(SpiceDouble));
	lon_hci = (SpiceDouble*) malloc(n*sizeof(SpiceDouble));
	lat_hci = (SpiceDouble*) malloc(n*sizeof(SpiceDouble));
	lon_iau = (SpiceDouble*) malloc(n*sizeof(SpiceDouble));
	lat_iau = (SpiceDouble*) malloc(n*sizeof(SpiceDouble));

	if ((t == NULL) || (pos_hci == NULL) || (distance == NULL) || (lon_hci == NULL) || (lat_hci == NULL) || (lon_iau == NULL) || (lat_iau == NULL) )  
	{
		printf("[ERROR] Memory allocation has failed. Not enough memory.\n");

		exit(EXIT_FAILURE);
	}
	else
	{
		for (i = 0; i < n; i++)
		{
			
			pos_hci[i] = NULL;
			pos_hci[i] = (SpiceDouble*) malloc(3*sizeof(SpiceDouble));
			pos_iau[i] = NULL;
			pos_iau[i] = (SpiceDouble*) malloc(3*sizeof(SpiceDouble));
			pos_hee[i] = NULL;
			pos_hee[i] = (SpiceDouble*) malloc(3*sizeof(SpiceDouble));

			if ((pos_hci[i] == NULL) || (pos_iau[i] == NULL) || (pos_hee[i] == NULL))
			{
				printf("[ERROR] Position : Memory allocation has failed.\n");
			}
		}
	}
	
	//Compute n positions of the celestial body wanted starting from et_0 epoch with a STEP step
	getPositions(TARGET, et_0, STEP, n, FRAME1, ABCORR, OBSERVER, t, pos_hci);
	getPositions(TARGET, et_0, STEP, n, FRAME2, ABCORR, OBSERVER, t, pos_iau);
	getPositions(TARGET, et_0, STEP, n, FRAME3, ABCORR, OBSERVER, t, pos_hee);

	//Compute longitudes and latitudes
	getLonLat(pos_hci, lon_hci, lat_hci, n);
	getLonLat(pos_iau, lon_iau, lat_iau, n);

	//Compute n distances of the celestial body wanted relatively with the Sun
	getDistance(n, pos_hci, distance);

	//Print celestial body positions for the time interval
	//printPositions(t, pos);

	//Get files name
	//getFilesName(BODY_NAME, START_DATE, ".txt", text_filename);
	getFilesName(BODY_NAME, START_DATE, ".nc", nc_filename);

	//Write celestial body positions into "earth.txt" file
	//createTextFile(text_filename, n, t, pos_hci, pos_iau, pos_hee, lon_hci, lat_hci, lon_iau, lat_iau, distance);

	//Write celestial body positions into "earth.nc" file
	createNc(nc_filename, n, t, pos_hci, pos_iau, pos_hee, lon_hci, lat_hci, lon_iau, lat_iau, distance);

	//Free memory
	free(t);
	free(distance);
	for (i = 0; i < n; i++)
	{
		free(pos_hci[i]);
		pos_hci[i] = NULL;
		free(pos_iau[i]);
		pos_iau[i] = NULL;
		free(pos_hee[i]);
		pos_hee[i] = NULL;
	}
	free(pos_hci);
	pos_hci = NULL;
	free(pos_iau);
	pos_iau = NULL;
	free(pos_hee);
	pos_hee = NULL;

	free(lon_hci);
	lon_hci = NULL;

	free(lat_hci);
	lat_hci = NULL;

	free(lon_iau);
	lon_iau = NULL;

	free(lat_iau);
	lat_iau = NULL;

	return 0;
}