Exemplo n.º 1
0
bool Viewport::HandleEvent(const SDL_Event& event)
{
    switch (event.type) {
    case SDL_VIDEORESIZE:
        m_Width  = event.resize.w;
        m_Height = event.resize.h;
        // TODO: Flag reset frustum
        SetFrustum( m_Width, m_Height );
        break;
    default: break;
    }
    return false;
}
Exemplo n.º 2
0
LUAMTA_FUNCTION(camera, SetFrustum)
{
	auto self = my->ToCameraPtr(1);

	self->SetFrustum(
		my->ToNumber(2, gEnv->pRenderer->GetWidth()),
		my->ToNumber(3, gEnv->pRenderer->GetHeight()), 
		my->ToNumber(4, DEFAULT_FOV), 
		my->ToNumber(5, DEFAULT_NEAR), 
		my->ToNumber(6, DEFAULT_FAR), 
		my->ToNumber(7, 1.0f)
	);

	return 0;
}
Exemplo n.º 3
0
Camera::Camera()
{
	aspect=640.0f/480.0f;
	pitch=0.0f;
	
	SetSpeed(5.0f,10000.0f,10000.0f,10000.0f);
	SetFrustum(0.1f, 100.0f, 67.0f);

	forward=vec4(0.0f,0.0f,-1.0f,0.0f);
	right=vec4(1.0f,0.0f,0.0f,0.0f);
	up=vec4(0.0f,1.0f,0.0f,0.0f);

	position=vec3(0.0f,0.0f,5.0f);

	CreateProjectionMat();
	CreateViewMat();

}
Exemplo n.º 4
0
Camera::Camera(int width, int height)
{
	aspect=(float)width/(float)height;
	pitch=0.0f;
	yaw=0.0f;
	roll=0.0f;

	SetSpeed(100.0f,10000.0f,10000.0f,10000.0f);
	SetFrustum(0.1f, 100.0f, 67.0f);

	forward=vec4(0.0f,0.0f,-1.0f,0.0f);
	right=vec4(1.0f,0.0f,0.0f,0.0f);
	up=vec4(0.0f,1.0f,0.0f,0.0f);

	position=vec3(0.0f,0.0f,0.0f);

	CreateProjectionMat();
	CreateViewMat();
}
Exemplo n.º 5
0
Camera::Camera()
{
	right = Vector3f(1, 0, 0);
	up = Vector3f(0, 1, 0);
	forward = Vector3f(0, 0, -1);
	position = Vector3f(0, 20, 3);

	float aspectRatio = 4.0/3.0f;
	fLeft = -1.0 * aspectRatio;;
	fRight = 1.0 * aspectRatio;;
	fBottom = -1.0;
	fTop = 1.0;
	fNear = 0.2f;
	fFar = 100.0f;

	yaw = 0.0f;
	pitch = 0.0f;

	SetFrustum(PI/4.0f, aspectRatio, fNear, fFar);
}
Exemplo n.º 6
0
// where is CCamera::SetFov(float fov)???
LUAMTA_FUNCTION(camera, SetFov)
{
	auto self = my->ToCameraPtr(1);

	int x = 0;
	int y = 0;
	int w = 0;
	int h = 0;

	self->GetViewPort(x, y, w, h);

	self->SetFrustum(
		my->ToNumber(1, h),
		my->ToNumber(2, w), 
		my->ToNumber(3, my->ToNumber(2)), 
		my->ToNumber(4, self->GetNearPlane()), 
		my->ToNumber(5, self->GetFarPlane()), 
		my->ToNumber(6, self->GetPixelAspectRatio())
	);

	return 0;
}
Exemplo n.º 7
0
//---------------------------------
//
//---------------------------------
void Matrix4::SetPerspective(float fovy, float aspect, float near, float far)
{
	float height = near   * static_cast<float>( DegTan( fovy / 2 ) );
	float width  = height * aspect;
	SetFrustum( -width, width, -height, height, near, far );
}
Exemplo n.º 8
0
void PickCallbackFunction(vtkObject* caller, long unsigned int vtkNotUsed(eventId),
	void* clientData, void* vtkNotUsed(callData))
{
	vtkAreaPicker *areaPicker = static_cast<vtkAreaPicker*>(caller);
	iARenderer *ren = static_cast<iARenderer*>(clientData);
	ren->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->RemoveActor(ren->selectedActor);

	auto extractSelection = vtkSmartPointer<vtkExtractSelectedFrustum>::New();
	extractSelection->SetInputData(0, ren->getRenderObserver()->GetImageData());
	extractSelection->PreserveTopologyOff();
	extractSelection->SetFrustum(areaPicker->GetFrustum());
	extractSelection->Update();

	if (!extractSelection->GetOutput()->GetNumberOfElements(vtkUnstructuredGrid::CELL))
	{
		ren->emitNoSelectedCells();
		return;
	}
	
	if (ren->GetInteractor()->GetControlKey() &&
		!ren->GetInteractor()->GetShiftKey())
	{
		// Adds cells to selection
		auto append = vtkSmartPointer<vtkAppendFilter>::New();
		append->AddInputData(ren->finalSelection);
		append->AddInputData(extractSelection->GetOutput());
		append->Update();
		ren->finalSelection->ShallowCopy(append->GetOutput());
	}
	else if (ren->GetInteractor()->GetControlKey() &&
		ren->GetInteractor()->GetShiftKey())
	{
		// Removes cells from selection 
		auto newfinalSel = vtkSmartPointer<vtkUnstructuredGrid>::New();
		newfinalSel->Allocate(1, 1);
		newfinalSel->SetPoints(ren->finalSelection->GetPoints());
		auto currSel = vtkSmartPointer<vtkUnstructuredGrid>::New();
		currSel->ShallowCopy(extractSelection->GetOutput());
		double f_Cell[DIM] = { 0,0,0 }, c_Cell[DIM] = { 0,0,0 };
		double* spacing = ren->getRenderObserver()->GetImageData()->GetSpacing();

		for (vtkIdType i = 0; i < ren->finalSelection->GetNumberOfCells(); ++i)
		{
			bool addCell = true;
			GetCellCenter(ren->finalSelection, i, f_Cell, spacing);
			for (vtkIdType j = 0; j < currSel->GetNumberOfCells(); ++j)
			{
				GetCellCenter(currSel, j, c_Cell, spacing);
				if (f_Cell[0] == c_Cell[0] &&
					f_Cell[1] == c_Cell[1] &&
					f_Cell[2] == c_Cell[2])
				{
					addCell = false;
					break;
				}
			}
			if (addCell)
				newfinalSel->InsertNextCell(ren->finalSelection->GetCell(i)->GetCellType(),
					ren->finalSelection->GetCell(i)->GetPointIds());
		}		
		ren->finalSelection->ShallowCopy(newfinalSel);
	}
	else
	{
		// New selection
		ren->finalSelection->ShallowCopy(extractSelection->GetOutput());
	}
	ren->selectedMapper->Update();
	ren->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->AddActor(ren->selectedActor);
	ren->emitSelectedCells(ren->finalSelection);
}
Exemplo n.º 9
0
Viewport::Viewport( int width, int height )
    : m_Width(width)
    , m_Height(height)
{
    SetFrustum( width, height );
}