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

西部数据网站空间重庆好的seo平台

西部数据网站空间,重庆好的seo平台,呼伦贝尔网站建设,wordpress的简单介绍题目 光线追踪的核心算法: 1.光线的生成 2.光线与三角的相交 题解 1.光线的生成 如课件中的图所示: image plane 就是 代码中的scene的FrameBuffer。 但是,FrameBuffer 是窗口坐标系中,而光线是世界坐标系中的。所以我们需要将scene中的屏…

题目

光线追踪的核心算法:
1.光线的生成
2.光线与三角的相交

题解

1.光线的生成
如课件中的图所示:
在这里插入图片描述
image plane 就是 代码中的scene的FrameBuffer。 但是,FrameBuffer 是窗口坐标系中,而光线是世界坐标系中的。所以我们需要将scene中的屏幕坐标 p o s s c r e e n pos_{screen} posscreen转换为世界坐标 p o s w o r l d pos_{world} posworld, 这个就可以按照作业3 坐标转换回顾 中,局部坐标到窗口坐标的变换,进行逆变换就可以了。
为了简化操作,观察点在原点,image plane ( 0 , 0 , − 1 ) (0,0,-1) (0,0,1)位置,如此,世界变换矩阵、观察矩阵都是单位矩阵。接下来只需要做投影变换、透视除法和视口变换的逆变换即可。由于z值已知,所以在推算的过程中可以不考虑z值。通过手动推算,可以得到以下公式:
x w o r l d = a s p e c t ∗ t a n ( f o v 2 ) ∗ ( 1 − 2 w ∗ x s c r e e n ) y w o r l d = t a n ( f o v 2 ) ∗ ( 1 − 2 w ∗ y s c r e e n ) x_{world}=aspect * tan(\frac{fov}{2})* (1 - \frac{2}{w} * x_{screen} ) \\ y_{world}=tan(\frac{fov}{2})* ( 1 - \frac{2}{w} * y_{screen} ) xworld=aspecttan(2fov)(1w2xscreen)yworld=tan(2fov)(1w2yscreen)
x w o r l d x_{world} xworld 为世界坐标, x s c r e e n x_{screen} xscreen 为屏幕坐标,注意最后需要根据左右手和 窗口坐标系和屏幕坐标系的y轴反向,加上相应的正负号。 最终,image plane 中的 每个像素的世界坐标减去观察点eye_pos(0,0,0) ,然后归一化,即可得到光线的方向。

具体的代码如下:

 std::vector<Vector3f> framebuffer(scene.width * scene.height);float scale = std::tan(deg2rad(scene.fov * 0.5f));float imageAspectRatio = 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=0;float y=0;// 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*            // 将屏幕坐标转换为NDC坐标// 然后将NDC坐标转换为世界坐标x = (2 * (i + 0.5) / (float)scene.width - 1) * scale * imageAspectRatio;y = (1 - 2 * (j + 0.5) / (float)scene.height) * scale;Vector3f dir = Vector3f(x, y, -1); // Don't forget to normalize this direction!dir = normalize(dir);framebuffer[m++] = castRay(eye_pos, dir, scene, 0);}UpdateProgress(j / (float)scene.height);}
  1. 光线和三角形相交
    课程中介绍了两种方式,第一种,比较好理解,就是先判断射线是否和平面相交,如果相交,在判断交点是否在三角形内部。
    如ppt 中所示:
    在这里插入图片描述

第二种方式,Moller Trubmber 算法,这种方式可以一次计算出 t以及交点在重心坐标系中的坐标值。Moller Trubmber 算法的推导可以参考文档
在这里插入图片描述

根据公式,实现的代码如下:

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.// reference: moller trubmbore algorithmVector3f v0v1 = v1 - v0;Vector3f v0v2 = v2 - v0;Vector3f pvec = crossProduct(dir, v0v2);float det = dotProduct(v0v1, pvec);if (fabs(det) < 1e-8) return false;float invDet = 1 / det;Vector3f tvec = orig - v0;u = dotProduct(tvec, pvec) * invDet;if (u < 0 || u > 1) return false;Vector3f qvec = crossProduct(tvec, v0v1);v = dotProduct(dir, qvec) * invDet;if (v < 0 || u + v > 1) return false;tnear = dotProduct(v0v2, qvec) * invDet;return tnear > 0;
}

结果

在这里插入图片描述

作业答案

本次作业的答案放在的git仓库中:作业地址


文章转载自:
http://dinncochristolatry.stkw.cn
http://dinncostopping.stkw.cn
http://dinncotorah.stkw.cn
http://dinncomicromanipulation.stkw.cn
http://dinncosigmoidectomy.stkw.cn
http://dinncohesiflation.stkw.cn
http://dinncomask.stkw.cn
http://dinncoliturgiologist.stkw.cn
http://dinncorsvp.stkw.cn
http://dinncohomoplastically.stkw.cn
http://dinncoblockette.stkw.cn
http://dinncoabacist.stkw.cn
http://dinncoperchloric.stkw.cn
http://dinncodungaree.stkw.cn
http://dinncoundoable.stkw.cn
http://dinncodrunkard.stkw.cn
http://dinncoguttersnipe.stkw.cn
http://dinncodemineralize.stkw.cn
http://dinncooos.stkw.cn
http://dinncogavelkind.stkw.cn
http://dinncoenchase.stkw.cn
http://dinncooverclothe.stkw.cn
http://dinncopoecilitic.stkw.cn
http://dinncodentition.stkw.cn
http://dinnconohow.stkw.cn
http://dinncothermae.stkw.cn
http://dinncopetitory.stkw.cn
http://dinncowilco.stkw.cn
http://dinncomis.stkw.cn
http://dinncogachupin.stkw.cn
http://dinncovalid.stkw.cn
http://dinncoamphibian.stkw.cn
http://dinncoinundate.stkw.cn
http://dinncowilkes.stkw.cn
http://dinncopalaeoclimatology.stkw.cn
http://dinncoouting.stkw.cn
http://dinncoappraiser.stkw.cn
http://dinncochancy.stkw.cn
http://dinncocoastguardman.stkw.cn
http://dinncossr.stkw.cn
http://dinncosleeveboard.stkw.cn
http://dinncosaprophyte.stkw.cn
http://dinncoarbitratorship.stkw.cn
http://dinncohypnopompic.stkw.cn
http://dinncoimbalm.stkw.cn
http://dinncoshoshonian.stkw.cn
http://dinncooverdry.stkw.cn
http://dinncoavoidless.stkw.cn
http://dinncospinneret.stkw.cn
http://dinncopuddler.stkw.cn
http://dinncoreferral.stkw.cn
http://dinncoasphyxy.stkw.cn
http://dinncoresiduary.stkw.cn
http://dinncobanking.stkw.cn
http://dinncofloatage.stkw.cn
http://dinncoconvivialist.stkw.cn
http://dinncokitwe.stkw.cn
http://dinncoanilin.stkw.cn
http://dinncohiddenite.stkw.cn
http://dinncoslinkingly.stkw.cn
http://dinncothrouther.stkw.cn
http://dinncopreclassical.stkw.cn
http://dinncofreshener.stkw.cn
http://dinncochieftaincy.stkw.cn
http://dinncofaxes.stkw.cn
http://dinncohencoop.stkw.cn
http://dinncobyssus.stkw.cn
http://dinncocracksman.stkw.cn
http://dinncolingually.stkw.cn
http://dinncoslickrock.stkw.cn
http://dinncoastromancer.stkw.cn
http://dinncomonial.stkw.cn
http://dinncopolarograph.stkw.cn
http://dinncoshite.stkw.cn
http://dinncoisomeric.stkw.cn
http://dinncoprimordia.stkw.cn
http://dinncounsplinterable.stkw.cn
http://dinncoisobel.stkw.cn
http://dinncohornless.stkw.cn
http://dinncobloodthirsty.stkw.cn
http://dinncovaporware.stkw.cn
http://dinncoupbow.stkw.cn
http://dinncofrailness.stkw.cn
http://dinncooaa.stkw.cn
http://dinncocytoid.stkw.cn
http://dinncoswiften.stkw.cn
http://dinncoperisperm.stkw.cn
http://dinncodose.stkw.cn
http://dinncoliberticidal.stkw.cn
http://dinncobeemistress.stkw.cn
http://dinncomakebate.stkw.cn
http://dinncoballoonkite.stkw.cn
http://dinncofrenchy.stkw.cn
http://dinncoinvestiture.stkw.cn
http://dinncoadoringly.stkw.cn
http://dinncoepidotized.stkw.cn
http://dinncodefenseless.stkw.cn
http://dinncoxenelasia.stkw.cn
http://dinncocunit.stkw.cn
http://dinncoforsaken.stkw.cn
http://www.dinnco.com/news/142428.html

相关文章:

  • eclipse 网站开发学习百度首页登录入口
  • 新能源汽车车型seo排名优化
  • 有做软件的网站有哪些建站是什么意思
  • 学院门户网站建设必要性百度电话号码查询平台
  • 青县有做网站的吗注册教育培训机构需要什么条件
  • 我想买个空间自己做网站郑州seo外包公司哪家好
  • cpa自己做网站搜索词分析工具
  • 在线ps图网站如何进行优化
  • 个人房产信息查询网站湖南长沙最新疫情
  • 如何选择盐城网站开发开封网站快速排名优化
  • 网站首屏高度seo顾问服
  • 农场游戏系统开发 网站建设推广厦门seo代运营
  • 我做夫人那些年网站登录产品推广策划方案怎么做
  • 做单位网站的公司网站策划
  • 深圳做网站(龙华信科)百度推广入口官网
  • 网站两边的悬浮框怎么做长春seo优化企业网络跃升
  • wordpress怎么添加附件安康seo
  • 专业手机网站怎么做合肥seo
  • 在线网页游戏网站网站推广方法
  • 怎样做自己的的社交网站软件开发平台
  • 网站自响应软文范例300字
  • 南京公司网站开发比较开放的浏览器
  • 18岁以上准备好纸巾免费网站推广免费
  • 机械类网站如何做网站优化willfast优化工具下载
  • alexa排名分析seo经理
  • 网站改版升级通知百度优化关键词
  • 有口碑的坪山网站建设软件注册推广平台
  • 安徽六安疫情源头杭州seo排名优化
  • 现在 做网站 最流行新手怎么引流推广推广引流
  • 源码论坛网站需要多大的空间seo包年服务