Пример #1
0
  void App::Draw() {
	SetProjection(fieldWidth, fieldHeight);

	if (!progress.IsPaused()) {
	  shaker.ApplyMatrix();
	  asteroids.Draw();
	  spliceAsteroids.Draw();
	  stars.Draw();
	  for (int i = 0; i < maxPlayersCount; i++) {
		players[i].Draw();
	  }
	  DrawNumber(false,
				 fieldWidth - 5.0f,
				 fieldHeight - 10.0f,
				 1,
				 1.5,
				 progress.GetLevel());
	  DrawNumber(true,
				 5.0f,
				 fieldHeight - 10.0f,
				 1,
				 1.5,
				 scoreTotal);
	}

	SetTranslate(0, 0);
	progress.Draw();
  }
Пример #2
0
// ==============================================================================================================================================
//
void Orbit::CreateProjectionPlane(VECTOR3 normal, VECTOR3 zero)
{	
	Reset();

	myy = 1.327e20;
	ecc = 0;
	sma = AU;
	rad = AU;
	inc = 0;
	lan = 0;
	agp = 0;
	tra = 0;
	par = sma;
	mna = 0;
	mnm = MeanMotion();
	ang = sqrt(myy*par);
	lpe = 0;
	trl = 0;

	majv  = unit(crossp(crossp(normal,zero),normal));
	norv  = unit(normal);
	minv  = unit(crossp(norv,majv));
	Xmajv = majv * sma;
	Xminv = minv * sma;
	Xcv	  = _V(0,0,0);

	SetProjection(this);
}
Пример #3
0
Camera::Camera(
		glm::vec3& position, 
		glm::vec3& target, 
		glm::vec3& up, 
		GLfloat near, 
		GLfloat far, 
		GLfloat fieldOfView,
		unsigned int windowWidth, 
		unsigned int windowHeight,
		const char* cameraName)
	: m_vCameraPosition(position),
	m_vCameraTarget(target),
	m_vCameraUp(up),
	m_fNearClippingPlane(near),
	m_fFarClippingPlane(far),
	m_fFOV(fieldOfView)
{
	m_fHorizontalAngle = 0.0f;
	m_fVerticalAngle = 0.0f;

	CameraName = new char[strlen(cameraName) + 1];
	strcpy_s(CameraName, strlen(cameraName) + 1, cameraName);

	// Debug
	std::cout<<CameraName<<std::endl;

	SetView();
	SetProjection(m_fFOV, WINDOW_WIDTH, WINDOW_HEIGHT, m_fNearClippingPlane, m_fFarClippingPlane);

	// Set mouse position to the center of the screen
	glfwSetCursorPos(Core::Window, (double)WINDOW_WIDTH / 2, (double)WINDOW_HEIGHT / 2);
}
Camera2::Camera2(
	glm::vec3& position,
	glm::vec3& target,
	glm::vec3& up,
	GLfloat near,
	GLfloat far,
	GLfloat fieldOfView,
	const char* cameraName)
	: m_vCameraPosition(position),
	m_vCameraDirection(target),
	m_vCameraUp(up),
	m_fNearClippingPlane(near),
	m_fFarClippingPlane(far),
	m_fFOV(fieldOfView)
{
	m_bFirstUpdate = true;

	m_fYaw = -90.0f;
	m_fPitch = 0.0f;

	CameraName = new char[strlen(cameraName) + 1];
	strcpy_s(CameraName, strlen(cameraName) + 1, cameraName);

	LoadIndentity();
	SetProjection(m_fFOV, WINDOW_WIDTH, WINDOW_HEIGHT, m_fNearClippingPlane, m_fFarClippingPlane);
	SetOrthoProjection(0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f);
}
Пример #5
0
// ==============================================================================================================================================
//
void Orbit::Ecliptic()
{	
	if (EclipticPlane) return;
	EclipticPlane=true;

	Reset();

	myy = 1.327e20;
	ecc = 0;
	sma = AU;
	rad = AU;
	inc = 0;
	lan = 0;
	agp = 0;
	tra = 0;
	par = sma;
	mna = 0;
	mnm = MeanMotion();
	ang = sqrt(myy*par);
	lpe = 0;
	trl = 0;

	majv  = _V(1,0,0);
	minv  = _V(0,0,1);
	norv  = _V(0,-1,0);
	Xmajv = majv * sma;
	Xminv = minv * sma;
	Xcv	  = _V(0,0,0);

	SetProjection(this);
}
Пример #6
0
	void Reshape(GLuint vp_width, GLuint vp_height)
	{
		width = vp_width;
		height = vp_height;

		gl.Viewport(width, height);
		SetProjection();
	}
Пример #7
0
//*****************************************************************************
//		投影設定
//*****************************************************************************
void iexView::SetProjection( float FovY, float Near, float Far )
{
	if( Viewport.Width == 0 )
	{
		Viewport.Width  = iexSystem::ScreenWidth;
		Viewport.Height = iexSystem::ScreenHeight;
	}
	SetProjection( FovY, Near, Far, (float)Viewport.Width / (float)Viewport.Height );
}
Пример #8
0
void reViewport::OnViewMenuClick(wxMouseEvent& event){
	int viewMenuChoice = m_viewMenuText->GetPopupMenuSelectionFromUser(m_viewMenu);

	switch (viewMenuChoice)
	{
	case reVIEWPORT_MENU_PERSPECTIVE:
		SetProjection(rViewportType::rVIEWPORT_PERSP);
		break;

	case reVIEWPORT_MENU_ORTHOGRAPHIC:
		SetProjection(rViewportType::rVIEWPORT_ORTHO);
		break;

	case reVIEWPORT_MENU_USER:
		SetViewOrientation(reViewOrientation::User, false);
		break;

	case reVIEWPORT_MENU_TOP:
		SetViewOrientation(reViewOrientation::Top, false);
		break;

	case reVIEWPORT_MENU_BOTTOM:
		SetViewOrientation(reViewOrientation::Bottom, false);
		break;

	case reVIEWPORT_MENU_LEFT:
		SetViewOrientation(reViewOrientation::Left, false);
		break;

	case reVIEWPORT_MENU_RIGHT:
		SetViewOrientation(reViewOrientation::Right, false);
		break;

	case reVIEWPORT_MENU_FRONT:
		SetViewOrientation(reViewOrientation::Front, false);
		break;

	case reVIEWPORT_MENU_BACK:
		SetViewOrientation(reViewOrientation::Back, false);
		break;
	}
}
Пример #9
0
void CameraComponent::ProcessInput(const Event& event, float delta)
{
	if (event.type == Event::Resized)
	{
		glViewport(0, 0, event.size.width, event.size.height);

		float aspect = static_cast<float>(event.size.width) / static_cast<float>(event.size.height);

		SetProjection(Matrix4f().InitPerspective(ToRadians(70.0f), aspect, 0.1f, 1000.0f));
	}
}
void CGraphicsCamera::SetupViewVolume( )
{
	if( wglMakeCurrent( m_hDC, m_hGLRC ) )
	{
		glMatrixMode( GL_PROJECTION );
		glLoadIdentity( );
		SetProjection();
		glMatrixMode( GL_MODELVIEW );
		wglMakeCurrent( NULL, NULL );
	}

}
Пример #11
0
nInt32 CConsole::Paint()
{
	glDepthMask(false);

	glDisable(GL_LIGHTING);

	SetProjection();
	DrawBackGround();

	glTranslated(0.0, 0.0, 0.5);
	glTranslated(0.0, dy, 0.0);

	nInt32 i = 0;
	register POINT TempPos;

	TempPos.x = TempPos.y = initdata.param.topclear;

	while(this->console_string[i].unicode)
	{
		if(console_string[i].unicode == L'\n')
		{
			TempPos.x = initdata.param.leftclear;
			TempPos.y += initdata.param.newline;// + static_cast<long>(font->FTop);
		}
		if(console_string[i].unicode == L'\t')
			TempPos.x += initdata.param.tab;

		if(TempPos.x > initdata.screen.x - initdata.param.rightclear)
		{
			TempPos.x = initdata.param.leftclear;
			TempPos.y += initdata.param.newline;// + static_cast<long>(font->FTop);
		}
		if(TempPos.y > ypos - initdata.param.bottomclear)
		{
			ypos += initdata.param.newline ;//+ static_cast<long>(font->FTop);
			dy -= initdata.param.newline ;//+ font->FTop;
		}
		if(console_string[i].unicode != L'\n' && console_string[i].unicode != L'\t')
		{
			font->Draw(TempPos, console_string[i].color, console_string[i].unicode);
			TempPos.x += initdata.param.distance;
		}
		i++;
	}
//	font->PrintChar(124, TempPos, N_RGB(200, 30, 200));

	glDepthMask(true);

	return EXIT_OK;
}
Пример #12
0
float MtxProjection(matrix_t row, const float openAngle, const float fov,
				   const float aspectRatio, const float zFar)
{
  const float halfFov = 0.5f * fov;
  const float halfAngle = 0.5f * openAngle;
  const float cosOverSin = Cos(halfAngle) / Sin(halfAngle);
  const float zNear = halfFov * cosOverSin;
  const float w = cosOverSin;
  const float h = w * aspectRatio;
  const float q = zFar / (zFar - zNear);

  SetProjection(row, w, h, q, zNear);
  return zNear;
}
Пример #13
0
	void Use(void)
	{
		gl.ClearDepth(1.0f);
		gl.ClearColor(0.8f, 0.8f, 0.8f, 0.0f);

		gl.Enable(Capability::DepthTest);
		gl.Enable(Capability::CullFace);
		gl.CullFace(Face::Back);

		dfb.Bind(Framebuffer::Target::Draw);
		gl.Viewport(width, height);

		prog.Use();
		cube.Use();

		SetProjection();
	}
Пример #14
0
ScrollCamera::ScrollCamera(void)
{
	m_fSpeed = 500.0f;
	m_fZoomModifier = 1.0f;

	m_vMinBounds = Vector3( -4096.0f, -4096.0f ) * 2.0f;
	m_vMaxBounds = Vector3( 4096.0f, 4096.0f ) * 2.0f;

	Matrix matProjection;
	matProjection.BuildOrthoLH( (float)IRenderer::Get()->VGetScreenWidth(), (float)IRenderer::Get()->VGetScreenHeight(), -1.0f, 1.0f );
	SetProjection( matProjection );

	m_bMouseDrag = false;
	InputManager::Get()->AddKeyboardHandler( this );
	InputManager::Get()->AddMouseHandler( this );
	InputManager::Get()->AddTouchHandler( this );
}
Пример #15
0
bool ScrollCamera::VOnMouseWheel( const Vector3& vPosition, const Vector3& vDelta )
{
	Matrix matScale;
	if ( vDelta.y > 0.0f )
	{
		matScale.BuildScale( 2.0f, 2.0f, 2.0f );
		m_fZoomModifier *= 0.5f;
	}
	else
	{
		m_fZoomModifier *= 2.0f;
		matScale.BuildScale( 0.5f, 0.5f, 0.5f );
	}

	SetProjection( GetProjection() * matScale );

	return false;
}
Пример #16
0
void Camera::UpdateMatrices(float dt)
{
	// Update the mouse cursor position
	glfwGetCursorPos(Core::Window, &Input::X_MOUSEPOS, &Input::Y_MOUSEPOS);

	// Update the camera angles
	m_fHorizontalAngle += Core::MouseSpeed * dt * float(WINDOW_WIDTH / 2 - Input::X_MOUSEPOS);
	m_fVerticalAngle += Core::MouseSpeed * dt * float(WINDOW_HEIGHT / 2 - Input::Y_MOUSEPOS);

	// Debug - display camera angles
	//std::cout<<m_fHorizontalAngle<<std::endl;
	//std::cout<<m_fVerticalAngle<<std::endl;

	// Calculate the new direction, right and up vectors
	glm::vec3 direction(
		cos(m_fVerticalAngle) * sin(m_fHorizontalAngle),
		sin(m_fVerticalAngle),
		cos(m_fVerticalAngle) * cos(m_fHorizontalAngle));

	glm::vec3 right(
		sin(m_fHorizontalAngle - M_PI / 2),
		0.0f,
		cos(m_fHorizontalAngle - M_PI / 2));

	glm::vec3 up(glm::cross(right, direction));

	// Input update
	Input::Update(dt, m_vCameraPosition, direction, right);

	// Update the projection matrix
	SetProjection(m_fFOV, WINDOW_WIDTH, WINDOW_HEIGHT, m_fNearClippingPlane, m_fFarClippingPlane);

	// Update the view matrix
	m_vCameraTarget = m_vCameraPosition + direction;
	m_vCameraUp = up;

	if (m_fHorizontalAngle != 0.0f || m_fVerticalAngle != 0.0f || m_bChange)
	{
		SetView();

		m_bChange = false;
	}
}
Пример #17
0
//***Default camera***
// Position 0.0f, 0.0f, 0.0f
// Target   1.0f, 0.0f, 1.0f
// Up		0.0f, 1.0f, 0.0f
// NearClip 0.1f
// FarClip  3000.0f
// WindowWidth Default
// WindowHeight Default
Camera2::Camera2(const char* cameraName)
	: m_vCameraPosition(0.0f, 0.0f, 50.0f),
	m_vCameraDirection(0.0f, 0.0f, -1.0f),
	m_vCameraUp(0.0f, 1.0f, 0.0f),
	m_fNearClippingPlane(0.1f),
	m_fFarClippingPlane(3000.0f),
	m_fFOV(45.0f)
{
	m_bFirstUpdate = true;

	m_fYaw = -90.0f;
	m_fPitch = 0.0f;

	CameraName = new char[strlen(cameraName) + 1];
	strcpy_s(CameraName, strlen(cameraName) + 1, cameraName);

	LoadIndentity();
	SetProjection(m_fFOV, WINDOW_WIDTH, WINDOW_HEIGHT, m_fNearClippingPlane, m_fFarClippingPlane);
	SetOrthoProjection(0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f);
}
/*****************************************************************************************
* Function Name: SetupViewVolume( double width, double height )
*
* Description: Sets up the view volume with proper aspect ratio. We always set the view
*              volume at the origin with a default size of the model extents then use
*              gluLookAt for zooming, translation and rotation. 
*
******************************************************************************************/
void CGraphicsCamera::SetupViewVolume( double width, double height )
{
	m_ViewVolumeWidth = width;
	m_ViewVolumeHeight = height;

	if( wglMakeCurrent( m_hDC, m_hGLRC ) )
	{
		glMatrixMode( GL_PROJECTION );
		glLoadIdentity( );
		if( m_bPerspective )
			SetProjection();
		else{
			width = height*m_Aspect;
			glOrtho( -width, width, -height, height, Z_NEAR, Z_FAR );
		}
		glMatrixMode( GL_MODELVIEW );
		wglMakeCurrent( NULL, NULL );
	}

}
Пример #19
0
void UIDirect3D9View::SetViewPort(IDirect3DDevice9 *Device, const QRect &Rect, Projection Type)
{
    if (m_viewValid && Device)
    {
        if (Rect == m_viewport)
            return;

        m_viewport = Rect;

        D3DVIEWPORT9 viewport;
        viewport.X      = m_viewport.left();
        viewport.Y      = m_viewport.top();
        viewport.Width  = m_viewport.width();
        viewport.Height = m_viewport.height();
        viewport.MinZ   = 0.0f;
        viewport.MaxZ   = 1.0f;

        Device->SetViewport(&viewport);

        SetProjection(Type);
    }
}
Пример #20
0
void MtxProjection2(matrix_t row, const float openAngle,
					const float aspectRatio,
					const float zNear, const float zFar)
{
  const float halfAngle = 0.5f * openAngle;
  const float cosOverSin = Cos(halfAngle) / Sin(halfAngle);
  const float w = cosOverSin;
  const float h = w * aspectRatio;
  const float q = zFar / (zFar - zNear);

/*   row[0][0] = w; */
/*   row[1][1] = h; */
/*   row[2][2] = (zFar+zNear)/(zNear-zFar); */
/*   row[3][2] = 2*zFar*zNear/(zNear-zFar); */
/*   row[2][3] = -1.0f; */
/*   row[3][3] = 1.0f; */
/*   row[0][1] = row[0][2] = row[0][3] = */
/*     row[1][0] = row[1][2] = row[1][3] = */
/*     row[2][0] = row[2][1] = */
/*     row[3][0] = row[3][1] = 0.0f; */

  SetProjection(row, w, h, q, zNear);
}
Пример #21
0
//***Default camera***
// Position 0.0f, 0.0f, 0.0f
// Target   1.0f, 0.0f, 1.0f
// Up		0.0f, 1.0f, 0.0f
// NearClip 0.1f
// FarClip  3000.0f
// WindowWidth Default
// WindowHeight Default
Camera::Camera(const char* cameraName)
	: m_vCameraPosition(0.0f, 0.0f, -5.0f),
	m_vCameraTarget(1.0f, 0.0f, 0.0f),
	m_vCameraUp(0.0f, 1.0f, 0.0f),
	m_fNearClippingPlane(0.1f),
	m_fFarClippingPlane(3000.0f),
	m_fFOV(45.0f)
{
	m_fHorizontalAngle = 0.0f;
	m_fVerticalAngle = 0.0f;

	CameraName = new char[strlen(cameraName) + 1];
	strcpy_s(CameraName, strlen(cameraName) + 1, cameraName);

	// Debug
	std::cout<<CameraName<<std::endl;

	SetView();
	SetProjection(m_fFOV, WINDOW_WIDTH, WINDOW_HEIGHT, m_fNearClippingPlane, m_fFarClippingPlane);

	// Set mouse position to the center of the screen
	glfwSetCursorPos(Core::Window, (double)WINDOW_WIDTH / 2, (double)WINDOW_HEIGHT / 2);
}
Пример #22
0
bool Graphics::Init() {
	glewInit();

	if (!GLEW_VERSION_2_1) {
		printerr("At least OpenGL version 2.1+ is required. Version found on this computer: " + str(glGetString(GL_VERSION)));
		printerr("Try updating your video drivers.");
		return false;
	}

	glClearDepth(1.0);
	glClearColor(0.5f, 0.7f, 0.9f, 1.0f);
	glEnable(GL_DEPTH_TEST);

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glEnable(GL_CULL_FACE);
	glFrontFace(GL_CW);
	glCullFace(GL_BACK);

	SetProjection();

	return true;
}
hsBool plViewTransform::SetProjectionWorld(const hsBounds3& wBnd)
{
    hsBounds3Ext cBnd = wBnd;
    cBnd.Transform(&GetWorldToCamera());
    return SetProjection(cBnd);
}
Пример #24
0
void vtVegLayer::AddElementsFromLULC(vtLULCFile *pLULC)
{
	LULCSection *section;
	LULCPoly *poly;

	SetVegType(VLT_Density);

	//set projections
	vtProjection proj_new;
	proj_new.SetProjectionSimple(0, -1, EPSG_DATUM_WGS84);
	SetProjection(proj_new);

	// figure out the number of polygons in file
	uint size = 0;
	for (uint sec = 0; sec < pLULC->NumSections(); sec++)
	{
		section = pLULC->GetSection(sec);
		size = size + section->m_iNumPolys;
	}

	// Create density field
	m_field_density = m_pSet->AddField("Density", FT_Float);
	m_pSet->SetNumEntities(size);

	// get each poly from LULC file
	uint i, s, p, count = 0;
	float density=0;
	for (s = 0; s < pLULC->NumSections(); s++)
	{
		section = pLULC->GetSection(s);
		for (p = 0; p < section->m_iNumPolys; p++)
		{
			poly = section->m_pPoly + p;

			bool wild = false;
			switch (poly->Attribute)
			{
				case 42:	// forest
					wild = true;
					density = 1.0f;
					break;
				case 32:
				case 33:
					wild = true;
					density = 0.5;
					break;
				case 22:	// orchards
					wild = false;
					// no crops for now
					break;
				default:
					density = 0.0f;
					break;
			}
			DLine2 dline;
			dline.SetSize(poly->m_iCoords);

			// get Coords of LULCpoly and store as latlon, then save in VPoly
			for (i = 0; i < dline.GetSize(); i++)
				dline.SetAt(i, poly->m_p[i]);

			DPolygon2 dpoly;
			dpoly.push_back(dline);

			GetPS()->SetPolygon(count, dpoly);
			m_pSet->SetValue(count, m_field_density, density);

			count++;
		}
	}
}
Пример #25
0
/**
 * Extract data from a SHP/DBF file and intepret it as a vegetation layer.
 * This produces a single-valued polygonal coverage.
 *
 * 'iField' is the index of the field from which to pull the single value.
 * 'datatype' is either 0, 1, or 2 for whether the indicated field should be
 *		intepreted as a density value (double), the name of a biotype
 *		(string), or the ID of a biotype (int).
 */
bool vtVegLayer::AddElementsFromSHP_Polys(const wxString &filename,
										  const vtProjection &proj,
										  int iField, VegImportFieldType datatype)
{
	// When working with float field data, must use C locale
	ScopedLocale normal_numbers(LC_NUMERIC, "C");

	// SHPOpen doesn't yet support utf-8 or wide filenames, so convert
	vtString fname_local = UTF8ToLocal(filename.mb_str(wxConvUTF8));

	// Open the SHP File
	SHPHandle hSHP = SHPOpen(fname_local, "rb");
	if (hSHP == NULL)
		return false;

	// Get number of polys and type of data
	int		nElem;
	int		nShapeType;
	SHPGetInfo(hSHP, &nElem, &nShapeType, NULL, NULL);

	// Check Shape Type, Veg Layer should be Poly data
	if (nShapeType != SHPT_POLYGON)
		return false;

	// Open DBF File
	DBFHandle db = DBFOpen(fname_local, "rb");
	if (db == NULL)
		return false;

	// Check for field of poly id, current default field in dbf is Id
	int *pnWidth = 0, *pnDecimals = 0;
	char *pszFieldName = NULL;

	DBFFieldType fieldtype = DBFGetFieldInfo(db, iField,
		pszFieldName, pnWidth, pnDecimals );

	if (datatype == VIFT_Density)
	{
		if (fieldtype != FTDouble)
		{
			VTLOG(" Expected the DBF field '%s' to be of type 'Double', but found '%s' instead.\n",
				pszFieldName, DescribeFieldType(fieldtype));
			return false;
		}
	}
	if (datatype == VIFT_BiotypeName)
	{
		if (fieldtype != FTString)
		{
			VTLOG(" Expected the DBF field '%s' to be of type 'String', but found '%s' instead.\n",
				pszFieldName, DescribeFieldType(fieldtype));
			return false;
		}
	}
	if (datatype == VIFT_BiotypeID)
	{
		if (fieldtype != FTInteger)
		{
			VTLOG(" Expected the DBF field '%s' to be of type 'Integer', but found '%s' instead.\n",
				pszFieldName, DescribeFieldType(fieldtype));
			return false;
		}
	}

	// OK, ready to allocate our featureset
	if (datatype == VIFT_Density)
	{
		SetVegType(VLT_Density);
		m_field_density = m_pSet->AddField("Density", FT_Float);
	}
	if (datatype == VIFT_BiotypeName || datatype == VIFT_BiotypeID)
	{
		SetVegType(VLT_BioMap);
		m_field_biotype = m_pSet->AddField("Biotype", FT_Integer);
	}

	SetProjection(proj);

	// Read Polys from SHP into Veg Poly
	m_pSet->LoadGeomFromSHP(hSHP);
	SHPClose(hSHP);

	// Read fields
	int biotype_id;
	for (uint i = 0; i < (uint) nElem; i++)
	{
		int record = m_pSet->AddRecord();
		// Read DBF Attributes per poly
		if (datatype == VIFT_Density)
		{
			// density
			m_pSet->SetValue(record, m_field_density, (float) DBFReadDoubleAttribute(db, i, iField));
		}
		if (datatype == VIFT_BiotypeName)
		{
			const char *str = DBFReadStringAttribute(db, i, iField);
			biotype_id = g_bld->GetBioRegion()->FindBiotypeIdByName(str);
			m_pSet->SetValue(record, m_field_biotype, biotype_id);
		}
		if (datatype == VIFT_BiotypeID)
		{
			biotype_id = DBFReadIntegerAttribute(db, i, iField);
			m_pSet->SetValue(record, m_field_biotype, biotype_id);
		}
	}
	DBFClose(db);
	return true;
}
Пример #26
0
/**
 * Extract point data from a SHP/DBF file and intepret it as a vegetation
 * layer.  This produces a set of vegetation instances.
 *
 * The 'opt' parameter contains a description of how the fields in the
 * imported file are to be interpreted.
 */
bool vtVegLayer::AddElementsFromSHP_Points(const wxString &filename,
										   const vtProjection &proj,
										   VegPointOptions &opt)
{
	// We will be creating plant instances
	SetVegType(VLT_Instances);

	vtSpeciesList *pSpeciesList = g_bld->GetSpeciesList();
	vtBioRegion *pBioRegion = g_bld->GetBioRegion();
	GetPIA()->SetSpeciesList(pSpeciesList);

	// SHPOpen doesn't yet support utf-8 or wide filenames, so convert
	vtString fname_local = UTF8ToLocal(filename.mb_str(wxConvUTF8));

	// Open the SHP File
	SHPHandle hSHP = SHPOpen(fname_local, "rb");
	if (hSHP == NULL)
		return false;

	// Get number of points and type of data
	int		nElem;
	int		nShapeType;
	SHPGetInfo(hSHP, &nElem, &nShapeType, NULL, NULL);

	// Check Shape Type, Veg Layer should be Point data
	if (nShapeType != SHPT_POINT)
		return false;

	// Open DBF File
	DBFHandle db = DBFOpen(fname_local, "rb");
	if (db == NULL)
		return false;

	// Confirm that the field types are correct
	int *pnWidth = 0, *pnDecimals = 0;
	char pszFieldName[80];
	DBFFieldType fieldtype;

	if (!opt.bFixedSpecies)
	{
		// we're going to get species info from a field
		fieldtype = DBFGetFieldInfo(db, opt.iSpeciesFieldIndex, pszFieldName,
			pnWidth, pnDecimals);
		if (opt.iInterpretSpeciesField == 0 || opt.iInterpretSpeciesField == 3)
		{
			if ((fieldtype != FTInteger) && (fieldtype != FTDouble))
			{
				DisplayAndLog("Can't import field '%hs' as an integer, it is type %d.",
					pszFieldName, fieldtype);
				return false;
			}
		}
		else
		{
			if (fieldtype != FTString)
			{
				DisplayAndLog("Can't import field '%hs' as a string, it is type %d.",
					pszFieldName, fieldtype);
				return false;
			}
		}
	}

	// Set projection
	SetProjection(proj);

	// Initialize arrays
	m_pSet->Reserve(nElem);

	// Read Points from SHP and intepret fields
	SHPObject *psShape;
	const char *str;
	int biotype;
	vtBioType *pBioType;
	DPoint2 pos;

	int unfound = 0;

	for (int i = 0; i < nElem; i++)
	{
		// Get the i-th Point in the SHP file
		psShape = SHPReadObject(hSHP, i);
		pos.x = psShape->padfX[0];
		pos.y = psShape->padfY[0];
		SHPDestroyObject(psShape);

		// Read DBF Attributes per point
		int species_id = -1;
		if (opt.bFixedSpecies)
			species_id = pSpeciesList->GetSpeciesIdByName(opt.strFixedSpeciesName.mb_str(wxConvUTF8));
		else
		{
			switch (opt.iInterpretSpeciesField)
			{
			case 0:
				species_id = DBFReadIntegerAttribute(db, i, opt.iSpeciesFieldIndex);
				break;
			case 1:
				str = DBFReadStringAttribute(db, i, opt.iSpeciesFieldIndex);
				species_id = pSpeciesList->GetSpeciesIdByName(str);
				if (species_id == -1)
					unfound++;
				break;
			case 2:
				str = DBFReadStringAttribute(db, i, opt.iSpeciesFieldIndex);
				species_id = pSpeciesList->GetSpeciesIdByCommonName(str);
				if (species_id == -1)
					unfound++;
				break;
			case 3:
				biotype = DBFReadIntegerAttribute(db, i, opt.iSpeciesFieldIndex);
				pBioType = pBioRegion->GetBioType(biotype);
				if (pBioType)
					species_id = pBioType->GetWeightedRandomPlant();
				break;
			case 4:
				str = DBFReadStringAttribute(db, i, opt.iSpeciesFieldIndex);
				biotype = pBioRegion->FindBiotypeIdByName(str);
				pBioType = pBioRegion->GetBioType(biotype);
				if (pBioType)
					species_id = pBioType->GetWeightedRandomPlant();
				break;
			}
		}

		// Make sure we have a valid species
		if (species_id == -1)
			continue;
		vtPlantSpecies *pSpecies = pSpeciesList->GetSpecies(species_id);
		if (!pSpecies)
			continue;

		// Set height
		float size;
		if (opt.bHeightRandom)
			size = random(pSpecies->GetMaxHeight());
		else if (opt.iHeightFieldIndex != -1)
			size = (float) DBFReadDoubleAttribute(db, i, opt.iHeightFieldIndex);
		else
			// fixed height
			size = opt.fHeightFixed;

		// If we get here, there is a valid plant to append
		GetPIA()->AddPlant(pos, size, species_id);
	}
	if (unfound)
		DisplayAndLog("Couldn't find species for %d out of %d instances.", unfound, nElem);
	else
		DisplayAndLog("Imported %d plant instances.", nElem);

	DBFClose(db);
	SHPClose(hSHP);
	return true;
}
Пример #27
0
Camera::Camera()
{
	SetView(DirectX::XMFLOAT3(0.0f, 0.0f, 0.0f), DirectX::XMFLOAT3(0.0f, 0.0f, 1.0f), DirectX::XMFLOAT3(0.0f, 1.0f, 0.0f));
	SetProjection(DirectX::XM_PI / 4, 1.0f, 1.0f, 1000.0f);
	//SetProjection(1.570796327f, 800/(FLOAT)600, 0.01f, 1000.0f);
}
Пример #28
0
Camera::Camera( float fov, float aspectRatio, float nearplane, float farplane )
{
	SetProjection( fov, aspectRatio, nearplane, farplane );
}
Пример #29
0
Camera::Camera( float left, float right, float top, float bottom, float nearplane, float farplane )
{
	SetProjection( left, right, top, bottom, nearplane, farplane );
}
Пример #30
0
// ==============================================================================================================================================
//
void Orbit::Elements(VECTOR3 r, VECTOR3 v,double m,bool reset_proj)
{	
	Reset();

	if (fabs(r.x)<0.01) r.x=0;	if (fabs(r.y)<0.01) r.y=0;
	if (fabs(r.z)<0.01) r.z=0;	if (fabs(v.x)<0.01) v.x=0;
	if (fabs(v.y)<0.01) v.y=0;	if (fabs(v.z)<0.01) v.z=0;

	vv=v; rv=r;

	double vel2;
	VECTOR3 z; z.x=0; z.z=0; z.y=1.0;
   
	vel2 = dotp(v,v);
	vel  = sqrt(vel2);
	rad  = length(r);
	myy  = m;

	// Computer normal vector and vector pointing ascenting node
	norv	= crossp(r,v);
	ang		= length(norv);
	norv	= norv*(1.0/ang);

	VECTOR3 ANv = unit(crossp(z,norv));
    
	// Inclination
	inc = acos(-norv.y);
	par = ang*ang/myy; 
	majv =( r * (vel2-myy/rad) ) - (v * dotp(r,v));

	double ml=length(majv);

	ecc  = ml/myy;
	
	if (ecc<1e-6) ecc=0;
	if (inc<1e-6) inc=0;

	sma = par / (1.0-ecc*ecc);

	r=r*(1.0/rad);					// Make the radius vector to unit size, After computing ecc-vector

	if (inc==0) ANv=_V(1,0,0);		// Place ANv to vernal equinox
	if (ecc!=0) majv=majv*(1.0/ml); // Make the major vector to unit size	
	else majv=ANv;					// Place major vector to ascenting node
	
	// Longitude of ascenting node
	if (inc!=0) {
		double  x=ANv.x;
		if (x>=1) {
			lan=0;
		} else if (x<=-1) {
			lan=PI;
		} else {		
			lan=acos(x);		
			if (ANv.z<0) lan=PI2-lan;		
		}
	} else {
		lan=0.0;
	}
	
	// Argument of Periapsis
	if (inc!=0 && ecc!=0) {
		double x=dotp(ANv,majv);
		if (x>1) x=1; // Avoid some precision problems
		else if (x<-1) x=-1;
		agp=acos(x);
		if (majv.y<0) agp=PI2-agp;
	} else if (ecc!=0) {
		agp=acos(majv.x);
		if (majv.z<0) agp=PI2-agp;
	}
	else agp=0.0;

  // True anomaly
	if (ecc!=0) {
		double x=dotp(majv,r);
		if      (x>=1)  tra=0;
		else if (x<=-1) tra=PI;
		else {
			tra=acos(x);
			x=dotp(r,v);
			if (fabs(x)<1e-6) x=0; // Avoid some precision problems
			if (x<0) tra=PI2-tra;
		}
	} else if (inc!=0) {
		tra=acos(dotp(ANv,r));
		if (dotp(ANv,v)>0) tra=PI2-tra;
	} else {
		tra=acos(r.x);
		if (v.x>0) tra=PI2-tra;
	}

	lpe=limit(agp+lan);				// Longitude of Periapsis
	trl=limit(lpe+tra);				// True longitude
	minv=unit(crossp(norv,majv));	// Minor axis vector
	mna=tra2mna(tra,ecc);			// Mean anomaly
	mnm=MeanMotion();

	Xmajv = majv * sma;
	Xminv = minv * sqrt(fabs(sma*par));
	Xcv	  = majv * (sma*ecc);

	if (reset_proj) SetProjection(this);
}