Beispiel #1
0
//! renvoie la transformation associee a une camera perspective (Projection).
Transform Perspective( float fov, float aspect, float znear, float zfar )
{
#if 0
    // Perform projective divide, pbrt version
    float inv_denom = 1.f / ( zfar - znear );
    Matrix4x4 persp( 
        1, 0,           0,              0,
        0, 1,           0,              0,
        0, 0, zfar*inv_denom, -zfar*znear*inv_denom,
        0, 0,           1,              0 
    );
    
    // Scale to canonical viewing volume
    float invTanAng = 1.f / tanf( Radians( fov ) / 2.f );
    return Scale( invTanAng, invTanAng, 1 ) * Transform( persp );

#else
    // perspective, openGL version
    const float inv_tan= 1.f / tanf(Radians(fov) * 0.5f);
    const float inv_denom= 1.f / (znear - zfar);
    Matrix4x4 persp( 
        inv_tan/aspect,       0,                    0,                      0,
                     0, inv_tan,                    0,                      0,
                     0,       0, (zfar+znear)*inv_denom, 2.f*zfar*znear*inv_denom,
                     0,       0,                   -1,                      0
    );

    return Transform(persp);
#endif
}
Beispiel #2
0
void CamerasExporter::operator()(Object *ob, Scene *sce)
{
    // TODO: shiftx, shifty, YF_dofdist
    Camera *cam = (Camera*)ob->data;
    std::string cam_id(get_camera_id(ob));
    std::string cam_name(id_name(cam));

    switch (cam->type) {
    case CAM_PANO:
    case CAM_PERSP: {
        COLLADASW::PerspectiveOptic persp(mSW);
        persp.setXFov(RAD2DEGF(focallength_to_fov(cam->lens, cam->sensor_x)), "xfov");
        persp.setAspectRatio((float)(sce->r.xsch)/(float)(sce->r.ysch), false, "aspect_ratio");
        persp.setZFar(cam->clipend, false, "zfar");
        persp.setZNear(cam->clipsta, false, "znear");
        COLLADASW::Camera ccam(mSW, &persp, cam_id, cam_name);
        addCamera(ccam);
        break;
    }
    case CAM_ORTHO:
    default:
    {
        COLLADASW::OrthographicOptic ortho(mSW);
        ortho.setXMag(cam->ortho_scale, "xmag");
        ortho.setAspectRatio((float)(sce->r.xsch)/(float)(sce->r.ysch), false, "aspect_ratio");
        ortho.setZFar(cam->clipend, false, "zfar");
        ortho.setZNear(cam->clipsta, false, "znear");
        COLLADASW::Camera ccam(mSW, &ortho, cam_id, cam_name);
        addCamera(ccam);
        break;
    }
    }
}
Beispiel #3
0
// Render onto tt (using renderer) sitting @ cameraPos,
// facing cameraDir, an object with radiusWorldUnits.
void ATheHUD::RenderScreen( USceneCaptureComponent2D* renderer, FVector lookPos, float radiusWorldUnits, FVector cameraDir )
{
  UTextureRenderTarget2D* tt = renderer->TextureTarget;
  // http://stackoverflow.com/questions/3717226/
  // radiusOnScreenPX = radiusWorldUnits*SW/(tan(fov / 2) * Z);
  // ZBack = radiusWorldUnits*SW/(tan( fovy / 2 )*radiusOnScreenPX)
  // Calculate Z distance back for a given pixel radius
  // Set particular render properties & render the screen
  // to texture in w.
  float D = GetZDistance( radiusWorldUnits, tt->GetSurfaceWidth(), tt->GetSurfaceHeight(), renderer->FOVAngle );
  FVector eyePos = lookPos - cameraDir * D;
  FQuat quat = cameraDir.Rotation().Quaternion();
  renderer->SetRelativeLocationAndRotation( eyePos, quat );
  
  FVector2D screenSize = ui->gameChrome->gameCanvas->Size;
  screenSize.X -= ui->gameChrome->rightPanel->Size.X;

  FVector up = renderer->GetUpVector();
  FLookAtMatrix lookAt( eyePos, lookPos, up );
  FPerspectiveMatrix persp( rendererMinimap->FOVAngle/2.f, 1.f, 1.f, 0.5f );
  FMatrix mvp1 = lookAt * persp;

  vector<Ray> rays = Game->pc->GetFrustumRays( FBox2DU( 0.f, 0.f, screenSize.X, screenSize.Y ) );
  float zValue = lookPos.Z;
  FPlane plane( FVector(0.f, 0.f, 1.f), zValue );
  vector<FVector> pts;
  for( int i = 0; i < rays.size(); i++ )
  {
    FVector pt = FMath::LinePlaneIntersection( rays[i].start, rays[i].end, plane );
    //Game->flycam->DrawDebug( pt, 25.f, FLinearColor::White, .25f );
    pts.push_back( pt );
  }

  //FLinearColor Cyan(0,1,1,1);
  //for( int i = 0; i < pts.size() - 1; i++ )
  //{
  //  Game->flycam->DrawDebug( pts[i], pts[i+1], 25.f, Cyan, .25f );
  //}
  //if( pts.size() > 1 )
  //{
  //  Game->flycam->DrawDebug( pts[pts.size()-1], pts[0], 25.f, Cyan, .25f );
  //}

  ui->gameChrome->rightPanel->minimap->pts.clear();
  FVector2D minimapSize = ui->gameChrome->rightPanel->minimap->Size;
  for( int i = 0; i < pts.size(); i++ )
  {
    FVector4 transformedPt = mvp1.TransformPosition( pts[i] );
    float div = transformedPt.W;
    transformedPt /= FVector4( div, div, div, div );
    FVector2D p( transformedPt.X, transformedPt.Y ); // between [-1,1]
    p *= 4.f/3.f; //!! Multiplying P by 4./3 req'd.. double-check
    p *= minimapSize/2.f;
    p.Y *= -1.f;
    p += minimapSize/2.f;

    p += ui->gameChrome->rightPanel->minimap->GetAbsPos();
    ui->gameChrome->rightPanel->minimap->pts.push_back( p );
  }
}
Beispiel #4
0
PGL_USING_NAMESPACE
TOOLS_USING_NAMESPACE

/* ----------------------------------------------------------------------- */
ViewCameraMenu::ViewCameraMenu(ViewCameraGL * camera,QWidget * parent, const char * name):
  QMenu(parent)
{
  if(name)setObjectName(name);

  QPixmap home(ViewerIcon::getPixmap(ViewerIcon::home));
  QPixmap read(ViewerIcon::getPixmap(ViewerIcon::fileopen));
  QPixmap save(ViewerIcon::getPixmap(ViewerIcon::filefloppy));
  QPixmap persp(ViewerIcon::getPixmap(ViewerIcon::perspective));
  QPixmap ortho(ViewerIcon::getPixmap(ViewerIcon::orthographic));
  QPixmap linked(ViewerIcon::getPixmap(ViewerIcon::linked));
  QPixmap eyef(ViewerIcon::getPixmap(ViewerIcon::eyef));

  QAction * action = addAction(home,tr("Home"),      camera,SLOT(home()), Qt::CTRL+Qt::Key_I);

  addAction(tr("&Front View (YZ)"),camera,SLOT(YZView()));
  addAction(tr("&Right View (XZ)"),camera,SLOT(XZView()));
  addAction(tr("&Top View (XY)"),  camera,SLOT(XYView()));
  addSeparator();
  QMenu * __coordMenu = new QMenu(this);
  idGEOMcoord = __coordMenu->addAction(tr("GEOM System"),   camera,SLOT(setGEOMCoordSys()));
  idGLcoord   = __coordMenu->addAction(tr("GL System"),     camera,SLOT(setGLCoordSys()));
  __coordMenu->addSeparator();
  __coordMenu->addAction(tr("&Change"),       camera,SLOT(changeCoordSys()));
  idGEOMcoord->setCheckable(true);
  idGLcoord->setCheckable(true);
  setCoordSys(camera->getCoordSys());
  __coordMenu->setTitle(tr("Coordinates System"));
  addMenu(__coordMenu);
  addSeparator();
  QMenu * __projectionMenu = new QMenu(this);
  idPerspective = __projectionMenu->addAction(persp,tr("&Perspective"),  camera,SLOT(setPerspectiveMode()));
  idOrtho       = __projectionMenu->addAction(ortho,tr("Ort&hographic"), camera,SLOT(setOrthographicMode()));
  __projectionMenu->addSeparator();
  __projectionMenu->addAction(tr("&Change"),       camera,SLOT(changeCameraMode()),Qt::CTRL+Qt::Key_D);
  idPerspective->setCheckable(true);
  idOrtho->setCheckable(true);
  __projectionMenu->setTitle(tr("Projection"));
  addMenu(__projectionMenu);

  setProjectionMode(camera->getProjectionMode());
  QObject::connect(camera,SIGNAL(projectionChanged(bool)),this,SLOT(setProjectionMode(bool)));
  QObject::connect(camera,SIGNAL(coordSysChanged(int)),this,SLOT(setCoordSys(int)));
  addSeparator();
  addAction(save,tr("&Save"),       camera,SLOT(save()));
  addAction(read,tr("&Read"),       camera,SLOT(read()));
  addSeparator();
  QAction * idLock = addAction(linked,tr("&Auto Fit to Window"),       camera,SLOT(lockDim()));
  if(camera)idLock->setChecked(camera->isDimLock());
  QObject::connect(camera,SIGNAL(lockDimChanged(bool)),idLock,SLOT(setChecked(bool)));
  addAction(eyef,tr("&Fit to Window"),       camera,SLOT(reDim()));

}
Beispiel #5
0
void wxStfChildFrame::Saveperspective() {
    wxString perspective = m_mgr.SavePerspective();
    // Save to wxConfig:
    wxGetApp().wxWriteProfileString(wxT("Settings"),wxT("Windows"),perspective);
#ifdef _STFDEBUG
    wxFile persp(wxT("perspective.txt"), wxFile::write);
    persp.Write(perspective);
    persp.Close();
#endif
}
Beispiel #6
0
void MyGLWidget::loadProjectionMatrix() {

    fetchArData();  // Get the Data: Camera Matrix
    double nearVal = 0.1;
    double farVal = 100.0 ;

    // Beim Einlesen der cameraMatrix aus dem Config-File gehen Kodierungsinfos verloren.
    // Deshalb hier auf Nummer sicher gehen.
    cv::Mat cameraMatrixConverted ;
    cameraMatrix.convertTo(cameraMatrixConverted,CV_32F);



    if(persp.empty()) {
                persp.create(4,4);
                persp.setTo(0);

                // http://kgeorge.github.io/2014/03/08/calculating-opengl-perspective-matrix-from-opencv-intrinsic-matrix/
                qDebug() << cameraMatrixConverted.at<float>(0,0);
                qDebug() << cameraMatrixConverted.at<float>(1,1);
                qDebug() << cameraMatrixConverted.at<float>(0,2);
                qDebug() << cameraMatrixConverted.at<float>(1,2);

                double fx = cameraMatrixConverted.at<float>(0,0);
                double fy = cameraMatrixConverted.at<float>(1,1);
                double cx = cameraMatrixConverted.at<float>(0,2);
                double cy = cameraMatrixConverted.at<float>(1,2);
                persp(0,0) = fx/cx;
                persp(1,1) = fy/cy;
                persp(2,2) = -(farVal+nearVal)/(farVal-nearVal);
                persp(2,3) = -2.0*farVal*nearVal / (farVal-nearVal);
                persp(3,2) = -1.0;

                // Transponieren entfernt, da in QMatrix gespeichert wird und diese dann für OpenGL transponiert.
                //persp = persp.t(); //to col-major

                glMatrixMode(GL_PROJECTION);;
                glLoadMatrixd((double*)persp.data);
                projectionCalculated = true ;

            }

}
Beispiel #7
0
Transform Perspective(float fov, float n, float f) {
	// Perform projective divide
	float inv_denom = 1.f / (1.f - n / f);
	Matrix4x4 persp(1, 0, 0, 0,
			0, 1, 0, 0,
			0, 0, inv_denom, -n*inv_denom,
			0, 0, 1, 0);
	// Scale to canonical viewing volume
	float invTanAng = 1.f / tanf(Radians(fov) / 2.f);
	return Scale(invTanAng, invTanAng, 1) * Transform(persp);
}
Beispiel #8
0
void NGLScene::render()
{
  // clear the screen and depth buffer
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   switch(m_activeWindow)
   {
     case ALL :
     {
       front(PANEL);
       side(PANEL);
       top(PANEL);
       persp(PANEL);
       break;
     }
     case FRONT : {front(FULLSCREEN); break; }
     case SIDE : {side(FULLSCREEN); break; }
     case TOP : {top(FULLSCREEN); break; }
     case PERSP : {persp(FULLSCREEN); break; }

   }
}
Beispiel #9
0
void init(void)
{
	pack_data data;

	if(load_pack(&data,"shaders.bin"))
	{
		set_global_pack(&data);

		if(init_model_vbo() && init_text_pro())
		{
			mat4 proj, view;

			glClearColor(0.02f,0.0f,0.02f,1.0f);

			persp(proj,75.0f,asp(),1.0f,20.0f);
			look(view,v3(0.0f,0.0f,1.7f),v3(-1.0f,0.0f,1.7f));
			mult(pview,proj,view);

			done_pack(&data);
			if(load_pack(&data,"assets.bin"))
			{
				if(load_model(&area_mod,"area-mod.bin"))
				{
					gen_texs(1,&area_tex);
					if(load_tex_compressed(area_tex,"area-tex.bin",tf_mipmap))
					{
						use_basic();
						basic_texmode(1);

						use_text_pro();
						text_instanced(1);

						if(load_font(&font,"sans-fontmap.bin","sans-fontdata.bin"))
							init_text(&text,10.0f,10.0f,"Demo scene");
						else quit();
					}
					else quit();
				}
				else quit();
			}
			else quit();
		}
		else quit();

		set_global_pack(NULL);
		done_pack(&data);
	}
	else quit();
}
Beispiel #10
0
//! renvoie la transformation associee a une camera perspective (Projection). zfar est a l'inifini
//! cf http://www.terathon.com/gdc07_lengyel.pdf
Transform InfPerspective( float fov, float aspect, float znear )
{
    // perspective, openGL version
    //~ const float eps= 0.000001f;
    const float eps= 0.f;
    const float inv_tan= 1.f / tanf(Radians(fov) * 0.5f);
    Matrix4x4 persp( 
        inv_tan/aspect,       0,  0,             0,
                     0, inv_tan,  0,             0,
                     0,       0, eps -1.f, (eps -2.f)*znear, 
                     0,       0, -1,             0
    );

    return Transform(persp);
}
Beispiel #11
0
void
ViewCameraGL::fillToolBar(QToolBar * toolBar)
{
  QPixmap home(ViewerIcon::getPixmap(ViewerIcon::home));
  QPixmap persp(ViewerIcon::getPixmap(ViewerIcon::perspective));
  QPixmap eye(ViewerIcon::getPixmap(ViewerIcon::eye));
  QPixmap eyef(ViewerIcon::getPixmap(ViewerIcon::eyef));
  drawArrow(&eye,2);
  QBitmap mask=eye.mask();
  drawArrow(&mask,2);
  QAction * bt = toolBar->addAction(home,tr("Home Position"),this, SLOT(home()));
  bt->setWhatsThis(tr("<b>Home Position</b><br><br>"
	"Set the view to the Initial Position.<br>"
	"You can also use Menu <br><b>Tools > Camera > Home</b><br>"));

  bt = toolBar->addAction(eye,tr("Camera Position"));
  QMenu * selctmenu = new QMenu(toolBar);
  selctmenu->addAction(tr("Front View (YZ)"),this,SLOT(YZView()));
  selctmenu->addAction(tr("Right View (XZ)"),this,SLOT(XZView()));
  selctmenu->addAction(tr("Top View (XY)"),this,SLOT(XYView()));
  bt->setMenu(selctmenu);
  // bt2->setPopupDelay(0);

  bt = toolBar->addAction(eyef,tr("Fit to Window"),this, SLOT(reDim()));
  bt->setWhatsThis(tr("<b>Fit to Window</b><br><br>"
	"Set the view to fit the scene.<br>"
	"You can also use Menu <br><b>Tools > Camera > Fit to Window</b><br>"));

  bt = toolBar->addAction(persp,tr("Perspective Camera"),
                         this, SLOT(changeCameraMode()));
  bt->setWhatsThis(tr("<b>Projection</b><br><br>"
	"Camera can be <b>Perspective</b> or <b>Orthographic</b>.<br><br>"
	"Setting this button <i>On</i> make the camera in Perspective mode, "
	"<i>Off</i> in Orthographic mode<br><br>"
	"You can also use Menu <br><b>Tools > Camera > Projection</b><br>"
	));
   bt->setCheckable(true) ;
   bt->setChecked(__projectionmode);
   QObject::connect(this,SIGNAL(projectionChanged(bool)),bt,SLOT(setChecked(bool)));
   toolBar->addSeparator();
}
Beispiel #12
0
Datei: app.c Projekt: youka2/fx
void init(void)
{
	if(init_mblur() && init_vig() && init_quad())
	{
		int size=0; void *data=NULL;

		/*glClearColor(1.0f,1.0f,1.0f,1.0f);*/
		glClearColor(0.04f,0.0f,0.04f,1.0f);

		use_mblur();
		send_mblur_samples(16.0f); /* adjust motion blur samples here */

		use_vig();
		send_vig_size((float)sw(),(float)sh());
		vigmode(0);

		use_basic();
		persp(proj,75.0f,asp(),0.1f,24.0f);

		if(fload("data/area-model.bin",&size,&data))
		{
			add_to_vbo(&area_mod,data,size);
			free(data);

			update_vbo();

			gen_texs(1,&area_tex);
			//if(load_tex_compressed(area_tex,"data/area-ao-texture.bin",tf_mipmap))
			if(load_tex_compressed(area_tex,"data/area-texture.bin",tf_mipmap))
			{
				const int downsample=1; /* adjust fb down-sizing here */
				texmode(1);

				nsw=sw()/downsample;
				nsh=sh()/downsample;

				gen_texs(4,texs);
				gen_rbs(3,rbs);
				gen_fbs(4,fbos);

				use_fb(fbos[0]);
				add_fb_rb(0,rbs[0],nsw,nsh,GL_RGB8,4); /* adjust renderbuffer samples here */
				add_fb_rb(0,rbs[1],nsw,nsh,GL_DEPTH_COMPONENT24,4); /* adjust renderbuffer samples here */

				use_fb(fbos[1]);
				add_fb_tex(0,texs[0],nsw,nsh,GL_RGB8,tf_linear);
				add_fb_rb(0,rbs[2],nsw,nsh,GL_DEPTH_COMPONENT24,0);

				use_fb(fbos[2]);
				add_fb_tex(0,texs[1],nsw,nsh,GL_RGB8,tf_linear);
				add_fb_tex(1,texs[2],nsw,nsh,GL_RGBA32F,tf_linear);
				add_fb_rb(0,rbs[2],nsw,nsh,GL_DEPTH_COMPONENT24,0);

				use_fb(fbos[3]);
				add_fb_tex(0,texs[3],nsw,nsh,GL_RGB8,tf_linear);

				use_fb(0);
				use_rb(0);
				use_tex(0);
			}
			else quit();
		}
		else quit();
	}
	else quit();
}