当前位置: 首页>>代码示例>>C++>>正文


C++ PerspectiveCamera类代码示例

本文整理汇总了C++中PerspectiveCamera的典型用法代码示例。如果您正苦于以下问题:C++ PerspectiveCamera类的具体用法?C++ PerspectiveCamera怎么用?C++ PerspectiveCamera使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PerspectiveCamera类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: renderBucket

	void RenderManager::renderBucket(RenderBucket bucket, Camera &camera, Environment &env)
	{
		bool canRender = false;

		vector<Geometry*> geomList = buckets[bucket];
		if (geomList.size() > 0)
		{
			for (size_t i = 0; i < geomList.size(); i++)
			{
				if (frustumCullingEnabled)
				{
					PerspectiveCamera *pers = static_cast<PerspectiveCamera*>(&camera);
					if (pers->getFrustum().intersectAABB(geomList[i]->getGlobalBoundingBox()))
						canRender = true;
				}
				else
					canRender = true;

				if (canRender)
				{
					geomList[i]->render(camera, env);
				}
			}
		}
	}
开发者ID:ajmd17,项目名称:apexengine,代码行数:25,代码来源:rendermanager.cpp

示例2: LoadTestScene

void LoadTestScene()
{
    Scene* firstScene = new Scene();
    engine->AddScene(firstScene);

    Transform* t = nullptr;
    
    PerspectiveCamera* camera = new PerspectiveCamera(Color::Red(), 1.f, 1000.f, 45.f, Screen::AspectRatio());
    firstScene->AddGameObject(camera);
    firstScene->RegisterCamera(camera);
    t = camera->GetTransform();
    t->SetRotation(glm::vec3(0, 180.f, 0));

    GameObject* triangle = new GameObject();
    firstScene->AddGameObject(triangle);
    
    triangle->SetName("Triangle");
    triangle->ModifyMeshRenderer(Mesh::Triangle(), Shader::GetDefaultShader(Shader::DefaultShaderName::UNLIT_COLOR));
    
    t = triangle->GetTransform();
    t->Translate(glm::vec3(0.f, 0, 3.f));

    auto mr = triangle->GetMeshRenderer();
    mr->mesh->Colorize(Color::Yellow());
    glm::vec4 colors[3]{ Color::Red() , Color::Green() ,Color::Blue() };
    mr->mesh->Colorize(colors, 3);
}
开发者ID:PeterMerkert,项目名称:symphony,代码行数:27,代码来源:main.cpp

示例3: Parse

void XmlSceneParser::Parse (const ParseNode& decl, PerspectiveCamera& node, Node& parent, SceneContext& context)
{
  try
  {
      //попытка найти параметры в кеше
      
    PerspectiveCameraDeclPtr node_decl = impl->PreparePerspectiveCamera (decl);

      //настройка камеры

    if (node_decl->params [PerspectiveCameraDecl::FovX].state)  node.SetFovX (degree (node_decl->params [PerspectiveCameraDecl::FovX].value));
    if (node_decl->params [PerspectiveCameraDecl::FovY].state)  node.SetFovY (degree (node_decl->params [PerspectiveCameraDecl::FovY].value)); 
    if (node_decl->params [PerspectiveCameraDecl::ZNear].state) node.SetZNear (node_decl->params [PerspectiveCameraDecl::ZNear].value);
    if (node_decl->params [PerspectiveCameraDecl::ZFar].state)  node.SetZFar (node_decl->params [PerspectiveCameraDecl::ZFar].value);

      //разбор родительских параметров

    Parse (decl, static_cast<Camera&> (node), parent, context);    
  }
  catch (xtl::exception& e)
  {
    e.touch ("scene_graph::XmlSceneParser::Parse(const ParseNode&,PerspectiveCamera&,Node&,SceneContext&)");
    throw;
  }
}
开发者ID:untgames,项目名称:funner,代码行数:25,代码来源:sg_xml_scene_parser.cpp

示例4: Spectrum

void PathHybridState::Init(const PathHybridRenderThread *thread) {
	PathHybridRenderEngine *renderEngine = (PathHybridRenderEngine *)thread->renderEngine;
	Scene *scene = renderEngine->renderConfig->scene;

	depth = 1;
	lastPdfW = 1.f;
	throuput = Spectrum(1.f);

	directLightRadiance = Spectrum();

	// Initialize eye ray
	PerspectiveCamera *camera = scene->camera;
	Film *film = thread->threadFilm;
	const u_int filmWidth = film->GetWidth();
	const u_int filmHeight = film->GetHeight();

	sampleResults[0].screenX = std::min(sampler->GetSample(0) * filmWidth, (float)(filmWidth - 1));
	sampleResults[0].screenY = std::min(sampler->GetSample(1) * filmHeight, (float)(filmHeight - 1));
	camera->GenerateRay(sampleResults[0].screenX, sampleResults[0].screenY, &nextPathVertexRay,
		sampler->GetSample(2), sampler->GetSample(3));

	sampleResults[0].alpha = 1.f;
	sampleResults[0].radiance = Spectrum(0.f);
	lastSpecular = true;
}
开发者ID:scollinson,项目名称:luxrays,代码行数:25,代码来源:pathstate.cpp

示例5: glutGet

void GameManager::update()
{
	double elapsed = glutGet(GLUT_ELAPSED_TIME);
	double delta_t = elapsed - _elapsed;
	_elapsed = elapsed;


	_car->updateComp(delta_t);
	_car->update(delta_t);
	_car->resetLimits();

	for (std::vector<StaticObject*>::iterator it = _gameobjects_static.begin(); it != _gameobjects_static.end(); it++)
	{

		(*it)->update(delta_t);
		(*it)->resetLimits();

	}

	for (std::vector<DynamicObject*>::iterator it = _gameobjects_road.begin(); it != _gameobjects_road.end(); it++)
	{
		(*it)->update(delta_t);
		(*it)->resetLimits();
	}
	
	for (std::vector<DynamicObject*>::iterator it = _gameobjects_road.begin(); it != _gameobjects_road.end(); it++)
	{
		if (_car->checkColision((*it))){
			_car->treatColision();
			for (std::vector<DynamicObject*>::iterator it = _gameobjects_road.begin(); it != _gameobjects_road.end(); it++)
				(*it)->resetClock();
			break;
		}

	}
	for (std::vector<StaticObject*>::iterator it = _gameobjects_static.begin(); it != _gameobjects_static.end(); it++)
	{
		if (_car->checkColision((*it))){
			_car->treatStaticColision();
			break;
		}

	}

	PerspectiveCamera* camera = (PerspectiveCamera*)_cameras.at(_camera);
	if (_camera == 2)
	{
		camera->setPosition(_car->getPosition()->getX() - 15 * cos(_car->getDirection()*3.14 / 180), _car->getPosition()->getY() - 15 * sin(_car->getDirection()*3.14 / 180), 10);
		camera->setAt(_car->getPosition()->getX(), _car->getPosition()->getY(), 3);
		//camera->setUp(0, 1, 0);
		_cameras.at(_camera)->update();
	}




}
开发者ID:ThatGuy986,项目名称:Projeto-CG,代码行数:57,代码来源:GameManager.cpp

示例6: computePiDensity

void DensityField::computePiDensity(const PerspectiveCamera& cam, const Scene& scene) {
    printInfo("Performing fog density preintegration.");
    printInfo("This will take a few seconds. Please wait! :-)");
    const auto& res = m_pi_dens_res = ivec3{cam.resolution(), m_res.z};
    // Allocate storage
    m_pi_dens_data = new float[piDensSize()];
    // Set up render loop
    assert(0 == res.x % PACKET_SZ && 0 == res.y % PACKET_SZ);
    const ivec2 n_packets{cam.resolution() / PACKET_SZ};
    #pragma omp parallel for
    for (int p_j = 0; p_j < n_packets.y; ++p_j)
        for (int p_i = 0; p_i < n_packets.x; ++p_i)
            for (int p_y = 0; p_y < PACKET_SZ; ++p_y)
                for (int p_x = 0; p_x < PACKET_SZ; ++p_x) {
                    const int x{p_x + p_i * PACKET_SZ};
                    const int y{p_y + p_j * PACKET_SZ};
                    // Use pixel center: offset by 0.5
                    rt::Ray ray{cam.getPrimaryRay(x + 0.5f, y + 0.5f)};
                    // Intersect the bounding volume of density field
                    const auto is = m_bbox.intersect(ray);
                    if (is) {
                        // Determine distance to the geometry
                        scene.trace(ray);
                        // Compute parametric ray bounds
                        const float t_min{max(is.entr, 0.0f)};
                        const float t_max{min(is.exit, ray.inters.distance)};
                        // Sample density at interval endpoints
                        const int   n_intervals{res.z * 4};
                        const float dt{(t_max - t_min) / n_intervals};
                        // Perform ray marching
                        float prev_dens{sampleDensity(ray.o + t_min * ray.d)};
                        float dens{0.0f};
                        for (int i = 1; i <= n_intervals; ++i) {
                            // Distance to the end of the interval
                            const float t{t_min + i * dt};
                            const float curr_dens{sampleDensity(ray.o + t * ray.d)};
                            // Use trapezoidal rule for integration
                            dens += 0.5f * (curr_dens + prev_dens);
                            prev_dens = curr_dens;
                            if (2 == i % 4) {
                                // We are in the middle of the camera-space voxel (froxel)
                                const int z{i / 4};
                                m_pi_dens_data[x + y * res.x + z * res.x * res.y] = dens * dt;
                            }
                        }     
                    } else {
                        // Set density to zero along the ray
                        for (int z = 0; z < res.z; ++z) {
                            m_pi_dens_data[x + y * res.x + z * res.x * res.y] = 0.0f;
                        }
                    }
                }
    // Save it to disk
    writePiDens("Assets\\pi_df.3dt");
    // Load data into OpenGL texture
    createPiDensTex();
}
开发者ID:lieff,项目名称:GIGL,代码行数:57,代码来源:DensityField.cpp

示例7: main

int main(int /*argc*/, char ** /*argv*/) {
  BaseApp app;
  ProgramObject program;

  auto mainWindow = app.getMainWindow();

  std::string prefix = app.getResourceDir() + "Shaders/Examples/e06_ModelLoader/";

  PerspectiveCamera cam;
  OrbitManipulator manipulator(&cam);
  manipulator.setupCallbacks(app);
  NodeShared root;

  GLuint query[2];

  
  app.addInitCallback([&]() {
    auto vs = compileShader(GL_VERTEX_SHADER, Loader::text(prefix + "phong.vert"));
    auto fs = compileShader(GL_FRAGMENT_SHADER, Loader::text(prefix + "phong.frag"));
    program = createProgram(vs, fs);

    root = Loader::scene(app.getResourceDir() + "Models/sponza/sponza.fbx");
    glCreateQueries(GL_TIMESTAMP, 2, query);
    SDL_GL_SetSwapInterval(0);
  });

  app.addResizeCallback([&](int w, int h) {
    glViewport(0, 0, w, h);
    cam.setAspect(float(w) / float(h));
  });

  app.addDrawCallback([&]() {


    glQueryCounter(query[0], GL_TIMESTAMP);
    glClearColor(0.2, 0.2, 0.2, 1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    //bunny

    program.use();
    program.setMatrix4fv("p", value_ptr(cam.getProjection()));
    program.setMatrix4fv("v", value_ptr(cam.getView()));

    drawNode(program, root);
    glQueryCounter(query[1], GL_TIMESTAMP);

    GLuint64 time1, time2;
    glGetQueryObjectui64v(query[0], GL_QUERY_RESULT, &time1);
    glGetQueryObjectui64v(query[1], GL_QUERY_RESULT, &time2);

    std::string s = "fps: " + std::to_string(1e9 / (time2 - time1)) + " (" + std::to_string(ImGui::GetIO().Framerate) + ")";
    label(s, 0, 0, 300, 100);
  });
  return app.run();
}
开发者ID:dormon,项目名称:FitGL,代码行数:56,代码来源:main.cpp

示例8: atmGetWindowSize

void TitleWindow::drawCallback()
{
    const uvec2 &wsize = atmGetWindowSize();
    PerspectiveCamera cam;
    cam.setAspect((float32)wsize.x/(float32)wsize.y);
    cam.setPosition(vec3(0.0f, 0.0f, 3.0f));
    cam.setZNear(0.01f);
    cam.setZFar(10.0f);

    atmGetRenderer()->setGameCamera(cam);
    atmGetRenderer()->setTime(m_time);
    atmGetBackgroundPass()->setBGShader(SH_BG7);
}
开发者ID:ezhangle,项目名称:atomic,代码行数:13,代码来源:TitleWindow.cpp

示例9: execSyncV

void PerspectiveCameraBase::execSyncV(      FieldContainer    &oFrom,
                                        ConstFieldMaskArg  whichField,
                                        AspectOffsetStore &oOffsets,
                                        ConstFieldMaskArg  syncMode,
                                  const UInt32             uiSyncInfo)
{
    PerspectiveCamera *pThis = static_cast<PerspectiveCamera *>(this);

    pThis->execSync(static_cast<PerspectiveCamera *>(&oFrom),
                    whichField,
                    oOffsets,
                    syncMode,
                    uiSyncInfo);
}
开发者ID:marcusl,项目名称:OpenSG,代码行数:14,代码来源:OSGPerspectiveCameraBase.cpp

示例10: testCamera

void testCamera() {

	ParamSet params;

	GaussianFilter *filter = new GaussianFilter(2, 2, 2);
	float crop[4] = { 0, 1, 0, 1 };
    ImageFilm* film = new ImageFilm(100, 100, filter, crop, "filename", false);

	Transform t = LookAt(Point(0,0,0), Point(0,0,-100), Vector(0,1,0));
	AnimatedTransform cam2world(&t, 0, &t, 0);

	//BoxFilter *filter = CreateBoxFilter(params);
	//ImageFilm *film = CreateImageFilm(params, filter);
	PerspectiveCamera *camera = CreatePerspectiveCamera(params, cam2world, film);

    bool jitter = false; //params.FindOneBool("jitter", true);
    // Initialize common sampler parameters
    int xstart, xend, ystart, yend;
    film->GetSampleExtent(&xstart, &xend, &ystart, &yend);
    int xsamp = 1;
    int ysamp = 1;
    StratifiedSampler *sampler = new StratifiedSampler(
		xstart, xend, ystart, yend,
		xsamp, ysamp,
        jitter, camera->shutterOpen, camera->shutterClose);

	RNG rng;
	Sample sample(sampler, NULL, NULL, NULL);

	int count = 0;
	while (sampler->GetMoreSamples(&sample, rng) && count < 10) {

		//sample.imageX
		printf("sample imageX: %g, imageY: %g\n", sample.imageX, sample.imageY);

		Ray ray;
		camera->GenerateRay(sample, &ray);

		print("ray.o", ray.o);
		print("ray.d", ray.d);
		printf("ray mint: %g, maxt: %g", ray.mint, ray.maxt);

		count++;
	}

	//CameraSample sample;

	//camera->GenerateRay(
}
开发者ID:mhietajarvi,项目名称:kalajoki2015,代码行数:49,代码来源:pbrt.cpp

示例11: randomSpheres

void randomSpheres(Scene* &scene, Camera* &camera, QtFilm* &film) {
    // Create scene
    scene = new Scene(new ListAggregate());
    *scene << new SkyLight(vec3(0.8f, 0.8f, 1.0f));
    
    Texture* spheresTexture = ImageLoading::LoadImage("/Users/gael/Desktop/Courses/CSE_168/models/textures/earth.jpg");
    Texture* planeTexture = ImageLoading::LoadImage("/Users/gael/Desktop/Courses/CSE_168/models/textures/scale_brown.png");
    
    // Materials
    Matte* spheresMaterial = new Matte(spheresTexture);
    Matte* planeMaterial = new Matte(planeTexture);
    //white->setColor(vec3(0.6f));
    
    // Create ground plane
    Plane* groundShape = new Plane();
    GeometricPrimitive* ground = new GeometricPrimitive(groundShape, planeMaterial);
    *scene << ground;
    
    // Create spheres
    for(int i=0; i<20; ++i) {
        Sphere* sphereShape = new Sphere();
        GeometricPrimitive* sphere = new GeometricPrimitive(sphereShape, spheresMaterial);
        float rad = RangeRand(0.25f,0.5f);
        vec3 pos(RangeRand(-5.0f,5.0f), rad, RangeRand(-5.0f,5.0f));
        sphereShape->setRadius(rad);
        sphereShape->setCenter(pos);
        *scene << sphere;
    }
    
    // Create lights
    DirectionalLight* sunlgt = new DirectionalLight();
    sunlgt->setSpectrum(Spectrum(vec3(1.0f, 1.0f, 0.9f)));
    sunlgt->setIntensity(1.0f);
    sunlgt->setDirection(vec3(2.0f, -3.0f, -2.0f));
    *scene << sunlgt;
    
    // Create camera
    PerspectiveCamera* perspectiveCamera = new PerspectiveCamera();
    
    perspectiveCamera->lookAt(vec3(-0.75f,0.25f,5.0f), vec3(0.0f,0.5f,0.0f));
    film = new QtFilm(vec2(800, 600));
    perspectiveCamera->setFilm(film);
    
    perspectiveCamera->setVFov(40.0f);
    perspectiveCamera->setAspect(1.33f);
    
    camera = perspectiveCamera;
}
开发者ID:gaelduplessix,项目名称:lvv,代码行数:48,代码来源:RandomSpheres.cpp

示例12: rayTrace

	void Renderer::rayTrace(Film *film, Shape& scene, PerspectiveCamera& camera, Lights& lights) {
		int w = film->width(), h = film->height();
		IntersectResult result;
		for (int y = 0; y < h; y++) {
			float sy = 1.0f - (float)y / h;
			for (int x = 0; x < w; x++) {
				float sx = (float)x / w;
				Ray& ray = camera.GenerateRay(sx, sy);
				scene.Intersect(ray, &result);
				if (result.geometry) {
					Material* pMaterial = result.geometry->material;
					Color color(0, 0, 0);
					for (int i = 0; i < lights.size(); i++) {
						Vector3dF incidence = lights[i]->incidence(result.position);
						Color c = pMaterial->Sample(ray, result.position, result.normal, incidence);
						color = color + c;
					}
					//printf("c=%f,%f,%f\n", color->r(),color->g(),color->b());
					film->set(x, y, 
						min(int(color.r() * 255), 255),
						min(int(color.g() * 255), 255),
						min(int(color.b() * 255), 255));
				}
			}
		}
	}
开发者ID:voyagingmk,项目名称:renderer,代码行数:26,代码来源:renderer.cpp

示例13: update

void FPSCameraController::update(PerspectiveCamera& a_camera, float a_deltaSec, bool a_focused)
{
	glm::ivec2 newMousePos;
	GLEngine::input->getMousePosition(newMousePos.x, newMousePos.y);
	if (m_mousePos.x == -1 && m_mousePos.y == -1) // First update, dont process movement
		m_mousePos = newMousePos;
	glm::ivec2 mouseMovement = m_mousePos - newMousePos;
	m_mousePos = newMousePos;

	if (!a_focused)
		return;
	if (!GLEngine::input->isMousePressed(EMouseButton::LEFT))
		mouseMovement = glm::ivec2(0);

	const float xLookRotation = (mouseMovement.x * m_mouseLookSensitivity);
	const float yLookRotation = (mouseMovement.y * m_mouseLookSensitivity);

	glm::vec3 direction = a_camera.getDirection();
	const glm::vec3 tmp = direction;
	const glm::vec3 side = glm::cross(direction, UP);
	const glm::vec3 up = glm::cross(side, direction);
	const glm::quat yaw = glm::angleAxis(glm::radians(xLookRotation), up);

	const float xzAngle = std::atan2(direction.x, direction.z); //calculate axis to rotate vertically on
	const glm::vec3 yRotAxis(-glm::cos(xzAngle), 0.0f, glm::sin(xzAngle));
	const glm::quat pitch = glm::angleAxis(glm::radians(yLookRotation), yRotAxis);
	const glm::quat orientation = glm::normalize(glm::cross(pitch, yaw));
	direction = glm::rotate(orientation, direction);
	
	const float newXZ = std::atan2(direction.x, direction.z);
	const float xzDiff = glm::abs(xzAngle - newXZ);
	if (xzDiff > 2.0f && xzDiff < 4.0f) // flip protection
	{
		direction = tmp;
	}

	a_camera.lookAtDir(direction);
	a_camera.translateRelative(getLocalSpaceMovementVector() * m_cameraSpeed * a_deltaSec);
	a_camera.updateMatrices();
}
开发者ID:ocirne23,项目名称:GLEngine,代码行数:40,代码来源:FPSCameraController.cpp

示例14: lock

void RenderingConfig::SetMotionBlur(const bool v) {
	boost::unique_lock<boost::mutex> lock(cfgMutex);

	bool wasRunning = renderThreadsStarted;
	// First stop all devices
	if (wasRunning)
		StopAllRenderThreadsLockless();

	film->Reset();
	PerspectiveCamera *camera = scene->camera;
	camera->motionBlur = v;
	if (camera->motionBlur) {
		camera->mbOrig = camera->orig;
		camera->mbTarget = camera->target;
		camera->mbUp = camera->up;
	}
	camera->Update(film->GetWidth(), film->GetHeight());

	// Restart all devices
	if (wasRunning)
		StartAllRenderThreadsLockless();
}
开发者ID:zeldaiscool,项目名称:luxrays,代码行数:22,代码来源:renderconfig.cpp

示例15: getLastClickedGrid

void GridSystem::getLastClickedGrid(PerspectiveCamera pc, int &reti, int &retj){
	int retij[2] = { -1, -1 };
	float min_dist = FLT_MAX;

	Vector3f ray = pc.getRay();
	float d = sqrt(pow(ray.x(), 2) + pow(ray.y(), 2) + pow(ray.z(), 2)); //dist from ray to projection pt
	Vector3f p = pc.getCameraLocation() + ray;
	for (int i = 0; i < grids.size(); i++)
	{
		for (int j = 0; j < grids[0].size(); j++)
		{
			Grid* g = grids[i][j];
			Vector3f pt = g->getXYZ();
			Vector3f newray = pt - pc.getCameraLocation(); //ray from camera to pt
			float dist = sqrt(pow(newray.x(), 2) + pow(newray.y(), 2) + pow(newray.z(), 2)); //dist from camera to pt
			Vector3f extNewray = newray.normalized() * d;
			Vector3f extPt = pc.getCameraLocation() + extNewray; //extended point in objective 3d space (0, 0, 592, 592)
			
			float threshold = (exp(4-(dist/15.0f))/d)*1500.0f*offset; //exp(3) = 20. (quite efficient for dist 4-30)
			if (abs(extPt.x() - p.x()) < threshold \
				&& abs(extPt.y() - p.y()) < threshold \
				&& abs(extPt.z() - p.z()) < threshold){ //NO LONGER DUMMY LOL //IT WORKS
				if (min_dist > dist){
					min_dist = dist;
					retij[0] = i; retij[1] = j;
					//g->show();
					//cout << "min_dist: " << min_dist << endl;
				}
			}

		}
	}
	//cout << "-------------" << endl;

	reti = retij[0];
	retj = retij[1];
}
开发者ID:luccan,项目名称:Final_Project_OpenGL,代码行数:37,代码来源:GridSystem.cpp


注:本文中的PerspectiveCamera类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。