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

jsp网站开发学习心得微信广告朋友圈投放

jsp网站开发学习心得,微信广告朋友圈投放,网站psd模板,南宁网页制作招聘网1.实现Renderer.cpp 中的 Render():为每个像素生成光线 这里你需要为每个像素生成一条对应的光 线,然后调用函数 castRay() 来得到颜色,最后将颜色存储在帧缓冲区的相 应像素中。 我们要做的就是将屏幕空间下的坐标最后转换到世界空间的坐标…

1.实现Renderer.cpp 中的 Render():为每个像素生成光线

这里你需要为每个像素生成一条对应的光 线,然后调用函数 castRay() 来得到颜色,最后将颜色存储在帧缓冲区的相 应像素中。

我们要做的就是将屏幕空间下的坐标最后转换到世界空间的坐标

这里一开始是处于屏幕空间坐标下的,如下图,这里假设原点在左上角,opengl原点在左下角,dx原点在左上角,那么首先想到的是将i,j分别加0.5取得像素中心坐标

接着将坐标变换到NDC空间,NDC空间是一个长宽高取值范围为[-1,1]的立方体,超过这个范围的顶点,会被GPU剪裁。:在DirectX里面,NDC的z方向取值范围是[0,1]

DX下的NDC空间如下图,要转换到NDC空间下,首先要用x,y分别除以屏幕的宽度贺高度。然后NDC空间需要将坐标轴原点变回到屏幕中间位置。

 i方向即宽方向,[0,1]->[-1,1],因为变化是线性的,很容易得到 i = 2*i-1。

 j方向即高方向,[0,1]->[1,-1],因为变化是线性的,很容易得到 i = -2*i+1

最后要将坐标转换到世界空间,要解决两个问题:

①横纵方向的长度并不是1:1的;

②物体本身并不是在[-1,1]的,[-1,1]是缩放后的范围。

解决办法:

①imageAspectRatio即宽高比,是原本scene的宽高比,所以要想恢复原始的比例需要用 宽 * 宽高比,即 x * imageAspectRatio。

②scale为一半可看角度(fov/2)的tan值,即下图tan(α/2),它代表了原本图像屏幕高度与图像到X-Y平面距离的比值,又由代码已给出的 Vector3f dir = Vector3f(x, y, -1) ,可以知道原本的图像屏幕距离X-Y平面为1,所以scale即为原本的图像高度,而现在的图像高度为1,所以令x,y同时乘以scale即可得到原始世界坐标下的坐标。

综上所述,最后直接给出代码计算

void Renderer::Render(const Scene& scene)
{std::vector<Vector3f> framebuffer(scene.width * scene.height);//float scale = std::tan(deg2rad(scene.fov * 0.5f));//宽高比float imageAspectRatio = (float)scene.width / (float)scene.height;// Use this variable as the eye position to start your rays.Vector3f eye_pos(0);int m = 0;for (int j = 0; j < scene.height; ++j){for (int i = 0; i < scene.width; ++i){// generate primary ray directionfloat x = (2 * (((float)i + 0.5) / scene.width) - 1)* imageAspectRatio * scale;float y = (1.0 - 2 * ((float)j + 0.5) / scene.height) * scale;// TODO: Find the x and y positions of the current pixel to get the direction// vector that passes through it.// Also, don't forget to multiply both of them with the variable *scale*, and// x (horizontal) variable with the *imageAspectRatio*    //vector = op,说明scene在z=-1,故znear距离人眼距离=1   Vector3f dir = normalize(Vector3f(x, y, -1)); // Don't forget to normalize this direction!framebuffer[m++] = castRay(eye_pos, dir, scene, 0);}UpdateProgress(j / (float)scene.height);}// save framebuffer to fileFILE* fp = fopen("binary.ppm", "wb");(void)fprintf(fp, "P6\n%d %d\n255\n", scene.width, scene.height);for (auto i = 0; i < scene.height * scene.width; ++i) {static unsigned char color[3];color[0] = (char)(255 * clamp(0, 1, framebuffer[i].x));color[1] = (char)(255 * clamp(0, 1, framebuffer[i].y));color[2] = (char)(255 * clamp(0, 1, framebuffer[i].z));fwrite(color, 1, 3, fp);}fclose(fp);
}

到这一步输出的结果:

window下查看ppm图片貌似需要用到第三方软件,这里给出我用的一个网站:

在线查看 PPM 文件的免费在线工具 - ImageToStl

2.Triangle.hpp 中的 rayTriangleIntersect():实现视射线与三角形相交

主要就是根据这个公式分别带入不同的参数就可以

origin是相机的位置,dir是射出的方向

bool rayTriangleIntersect(const Vector3f& v0, const Vector3f& v1, const Vector3f& v2, const Vector3f& orig,const Vector3f& dir, float& tnear, float& u, float& v)
{// TODO: Implement this function that tests whether the triangle// that's specified bt v0, v1 and v2 intersects with the ray (whose// origin is *orig* and direction is *dir*)// Also don't forget to update tnear, u and v.Vector3f E1 = v1 - v0, E2 = v2 - v0 ;Vector3f S = orig - v0,S1 = crossProduct(dir, E2), S2 = crossProduct(S, E1);if (dotProduct(S1, E1) <= 0) return false;tnear = dotProduct(S2, E2) / dotProduct(S1, E1);u = dotProduct(S1, S) / dotProduct(S1, E1);v = dotProduct(S2, dir) / dotProduct(S1, E1);if (tnear >= 0 && u >= 0 && v >= 0 && (1 - u - v) >= 0) return true;return false;
}

最后的结果

http://www.dinnco.com/news/40670.html

相关文章:

  • 广州花都区廊坊seo优化
  • 投票活动网站怎么做seo关键词分类
  • 网站怎么做的南宁市优化网站公司
  • 网站下雪的效果怎么做的百度快照优化排名
  • 作品集模板网站棋牌软件制作开发多少钱
  • 网站备案会过期吗广州推广优化
  • 建设一个电子商务网站win7优化大师
  • 找谁做网站网络安全培训机构哪家好
  • 网站建设企业网站制作电商网站设计方案
  • 做58网站怎么赚钱吗免费seo优化
  • 南宁网站建设 传导虎扑体育网体育
  • 成都私人网站制作seo网站结构优化的方法
  • 天猫网站是用什么技术做的自媒体seo优化
  • 做独立网站需要注意些什么重庆黄埔seo整站优化
  • 旅游电子商务网站开发实验报告沈阳网站制作
  • 提供免费网站建设品牌推广的三个阶段
  • 公司网站制作服务深圳网络优化seo
  • 宁波网页关键词优化公司小红书seo优化
  • 赚钱的网站做任务百度站长收录入口
  • 网站制作替我们购买域名什么是搜索引擎营销?
  • wordpress安装包下载荥阳seo
  • 可以设计什么网站广西壮族自治区人民医院
  • 哪个网站做的游戏好玩四川网络推广推广机构
  • 上哪儿找做网站百度推广怎么做的
  • 做网站项目时 需求分析的内容百度快照官网
  • 做视频特效的网站如何发布自己的网站
  • 做平面找那些网站找活网络营销与直播电商专升本
  • 红十字会三合一网站建设方案河南做网站的
  • 企业网站建设背景网络营销的现状及问题
  • wordpress播放视频该插件不支持济南优化seo公司