当前位置: 首页 > wzjs >正文

pexels素材网站深圳中小企业网站制作

pexels素材网站,深圳中小企业网站制作,网站改版优化,企业局域网的搭建Camera类 我们之前学了很多的图形学知识和相关的程序,现在我们停下脚步,来好好整理一下我们学习的内容,我们将之前的视口代码和渲染代码合并到一个新的单类camera.h,这个类主要负责两项任务: 构建并发射光线到世界中 …
Camera类

我们之前学了很多的图形学知识和相关的程序,现在我们停下脚步,来好好整理一下我们学习的内容,我们将之前的视口代码和渲染代码合并到一个新的单类camera.h,这个类主要负责两项任务:

  • 构建并发射光线到世界中

  • 使用光线的信息来构建渲染图像

这次的重构,我们收集以下几个功能:

  • ray_color()

  • 图像设置

  • 相机设置

  • 渲染

新的相机类将包含两个公有方法:initialize()render() 以及两个私有辅助方法 get_ray()ray_color()

相机类的设计应该遵循尽可能的简单的方式,让我们在后续使用时操作尽可能的简单,使用默认构造函数,且避免复杂的初始化过程。同时允许用户通过直接赋值改变公共变量,避免复杂的setter方法。并且在渲染函数开始时,自动的调用initialize()操作,避免用户操作的复杂性。

现在我们先搭建其camera类的框架:

​
#ifndef RENDER_C___CAMERA_H
#define RENDER_C___CAMERA_H
#include "hittable.h"
class camera{
public://这里设置公有的属性void render(const hittable& world){}
private://这里放置私有的属性void initialize(){ }color ray_color(const ray&r,const hittable& world) const{}  
};
#endif //RENDER_C___CAMERA_H

然后一一将我们的方法和属性完善首先是将main中的上色部分ray_color移动到里面

class camera {...private:...color ray_color(const ray& r, const hittable& world) const {hit_record rec;
​if (world.hit(r, interval(0, infinity), rec)) {return 0.5 * (rec.normal + color(1,1,1));}
​vec3 unit_direction = unit_vector(r.direction());auto a = 0.5*(unit_direction.y() + 1.0);return (1.0-a)*color(1.0, 1.0, 1.0) + a*color(0.5, 0.7, 1.0);}
};
#endif

然后还有剩下的相机的建立和图像的设置也移动到里面:

#ifndef RENDER_C___CAMERA_H
#define RENDER_C___CAMERA_H
​
#include "hittable.h"
​
class camera{
public:double aspect_radio = 1.0;      //图像的宽高比int    image_width = 100;       //图像宽度的像素数
​void render(const hittable& world){initialize();
​std::cout << "P3\n" << image_width << " " << image_height << "\n255\n";for(int j=0;j<image_height;j++){std::clog << "\rScanlines remaining: " << (image_height - j) << ' ' << std::flush;for(int i=0;i<image_width;i++){auto pixel_center = pixel00_loc + (i*pixel_delta_u) + (j*pixel_delta_v);auto ray_direction = pixel_center - camera_center;ray r(camera_center,ray_direction);
​color pixel_color = ray_color(r,world);write_color(std::cout,pixel_color);}}std::clog << "\rDone.                   \n";}
​
private:int image_height;       //渲染图像的高度point3 camera_center;   //相机的中心point3 pixel00_loc;     //像素(0,0)的位置vec3 pixel_delta_u;     //向右的偏移值vec3 pixel_delta_v;     //向下的偏移值
​void initialize(){image_height = int(image_width/aspect_radio);image_height = (image_height < 1) ? 1 : image_height;
​camera_center = point3 (0,0,0);
​//确认视窗的设置auto focal_length = 1.0;    //焦距设置auto viewport_height = 2.0;auto viewport_width = viewport_height*(double (image_width)/image_height);
​//视图边缘的向量计算auto viewport_u = vec3(viewport_width,0,0);auto viewport_v = vec3(0,-viewport_height,0);//计算视图的像素间的水平竖直增量pixel_delta_u = viewport_u/image_width;pixel_delta_v = viewport_v/image_height;//计算左上角第一个像素中心的坐标auto viewport_upper_left = camera_center - vec3(0,0,focal_length) - viewport_v/2 - viewport_u/2;pixel00_loc = viewport_upper_left + 0.5*(pixel_delta_u+pixel_delta_v);}
​color ray_color(ray & r,const hittable& world){hit_record rec;if(world.hit(r,interval(0,infinity),rec)){return 0.5*(rec.normal + color(1,1,1));}
​vec3 unit_direction = unit_vector(r.direction());auto a = 0.5*(unit_direction.y()+1.0);return (1.0 - a)*color(1.0,1.0,1.0) + a*color(0.5,0.7,1.0);}
};
​
#endif //RENDER_C___CAMERA_H

我们使用新的类来实现对main函数的简化:

#include "rtweekend.h"
​
#include "camera.h"
#include "hittable.h"
#include "hittable_list.h"
#include "sphere.h"
​
int main(){hittable_list world;world.add(make_shared<sphere>(point3(0,0,-1),0.5));world.add(make_shared<sphere>(point3(0,-100.5,-1),100));
​camera cam;
​cam.aspect_radio = 16.0/9.0;cam.image_width = 800;
​cam.render(world);
}

这样的操作极大的简化了后续我们的图形的渲染,你看这是渲染出来的放大版:

image.png

那么这一章就到此为止啦

http://www.dtcms.com/wzjs/824159.html

相关文章:

  • 做钓鱼网站原理windows优化大师官网
  • 网站开发融资网站建设去哪找客户
  • 哈尔滨模板建站哪个品牌好巴里坤网站建设
  • 网站建设华网天下制作作网站建设工资高吗
  • 做网站的属于什么网站建设的商业计划书
  • 洛阳网站建设哪家权威上海公司注销需要多少钱费用?
  • 南阳微网站开发建筑网官网软件
  • 公司英文网站建设安徽建设厅证书查询网网站
  • 国家住房部和城乡建设部 网站中国纪检监察报网官网
  • 通辽大柒网站建设有限公司WordPress外链自动转内链
  • 徐州制作网站的公司有哪些视频类的网站制作
  • 本机可以做网站的服务器吗专业的集团网站建设
  • 天猫网站建设的目标是什么网站推广seo代理
  • 泰安网站建设公司哪家好商城开源免费商用
  • 著名的网站建设公司云南建设局网站
  • 贵阳哪里做网站淘宝网网页版登录官网登录
  • 阿里云个人网站制作微信商城网站开发
  • 无锡做网站公司有哪些网站关键词优化怎么做的
  • 怎么做镜像网站谷歌排名推广公司
  • 凌源市建设局网站黄骅市做网站价格
  • 济南的企业网站建设aitt网站建设中
  • 辽宁网站定制企业WordPress的login在哪里改
  • 网站建设柒金手指花总12网站的数据库是什么
  • 网站内部链接有什么作用工业产品设计网
  • 番禺做网站价格重庆丙图网络科技有限公司
  • 静态网页素材四川成都网站优化
  • 局网站建设管理制度网站用ps做还是ai
  • 网站制作怎么样提供会员注册Wordpress 手机端滑动
  • wordpress newcon百度快照优化的优势是什么
  • 大连网站制作.net盐城seo 优化