龙书D3D11章节习题答案(第五章)

2023-11-14



以下答案仅供参考,有错欢迎留言。


Chapter 5:The Rendering Pipeline

1. Construct the vertex and index list of a pyramid(金字塔), as shown in Figure 5.35(即下图).

Vertex   pyramid[5] = {v0, v1, v2, v3, v4, v5};

// 注意要从面的outside看向inside,然后按照顺时针绕序,如下

UINT     indexList[6] = { 0, 1, 4,

                                      0, 3, 2,

                                      0, 4, 3,

                                      0, 2, 1,

                                      3, 4, 1,

                                      3, 1, 2};

这里我用dx9绘制了一下来验证结果:

1.为了方便观察金字塔全貌,让绘制出的金字塔绕x轴向上翻转45°,并绕y轴不停旋转。

2.设置CULLMODE为D3DCULL_NONE,观察到所有顶点及其连线。

理由:默认的背面剔除方式是剔除逆时针绕序的三角形,即D3DCULL_CCW (Couter-Clock-Wise)。

而在这种方式下,因为旋转中的金字塔底部对于我们的视角(摄像机镜头)来说,一会是正面(绘制)一会是反面(不绘制)。




2. Consider the two shapes shown in Figure 5.36(即下图). Merge the objects into one vertex and index list. (The idea here is that when you append the 2nd index list to the first, you will need to update the appended indices since they reference vertices in the original vertex list, not the merged vertex list.)

这道题的意思似乎是把绘制a和b所用到的vertex list和index list合起来写。。定义v0,v1,...,v12,v13,慢慢写索引不就行了。。也许是我没悟到题目的意思...

更新:作者的意思其实是将多个vertex list和index list合并vertex list都写在vertex buffer里,index list都写在index buffer里,  对于新的vertex list,vertexList1从0开始计数,vertexList2从0+vertexList1.size()开始计数,vertexList3从0+vertexList1.size()+vertexList2.size()开始计数......以此类推。相应地对于新的index list,由于对应的vertex list现在发生了改变,原索引值也需要加上一个偏移量。IndexList1不变,IndexList2需要为每个索引值加上vertexList1.size()来得到原顶点。这些是新的List的改动。。在绘制的时候,比如DrawIndexed,那么还需要给出每个绘制对象的Index开始位置,那么就需要从0,0+IndexList1.size(),0+IndexList1.size()+IndexList2.size()...累计,具体代码在第六章有,这里就只说个大概。




3. Relative to the world coordinate system, suppose that the camera is positioned at (−20, 35, −50) and looking at the point (10, 0, 30). Compute the view matrix assuming (0, 1, 0) describes the “up” direction in the world.

这题是关于ViewMatrix推导的。


View Transform(视图变换)详解

条件:EyePosition(-20,35,-50),   FocusPosition(10,0,30),  UpDirection(0,1,0)

#include <iostream>
#include <windows.h>  // FLOAT
#include <xnamath.h>
using namespace std;

// Overload the  "<<" operators so that we can use cout to 
// output XMVECTOR and XMMATRIX objects.
ostream& operator<<(ostream& os, FXMVECTOR v)
{
	XMFLOAT4 dest;
	XMStoreFloat4(&dest, v);

	os << "(" << dest.x << ", " << dest.y << ", " << dest.z << ", " << dest.w << ")";
	return os;
}

ostream& operator<<(ostream& os, CXMMATRIX m)
{
	for(int i = 0; i < 4; ++i)
	{
		for(int j = 0; j < 4; ++j)
			os << m(i, j) << "\t";
		os << endl;
	}
	return os;
}
// 把条件代入XNMATH提供的XMMatrixLookAtLH函数里面计算结果,然后再根据自己推导的步骤计算,若结果相同,则推导正确。
int main()
{
	// Check support for SSE2 (Pentium4, AMD K8, and above).
	if( !XMVerifyCPUSupport() )
	{
		cout << "xna math not supported" << endl;
		return 0;
	}

	XMVECTOR pos = XMVectorSet(-20.0f, 35.0f, -50.0f, 1.0f);
	XMVECTOR target = XMVectorSet(10.0f, 0.0f, 30.0f, 1.0f);
	XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);

	XMMATRIX view = XMMatrixLookAtLH(pos, target, up);
	cout.precision(4);
	cout << endl << view << endl;

	// direction
	XMVECTOR d = target - pos;
	d = XMVector3Normalize(d);
	cout << "d =  "<< d << endl;

	// right
	XMVECTOR r = XMVector3Cross(up, d);
	r = XMVector3Normalize(r);
	cout << "r =  "<< r << endl;

	// up
	XMVECTOR u = XMVector3Cross(d, r);
	cout << "u =  "<< u << endl;


	float x = -XMVectorGetY(XMVector3Dot(pos,r));  
	float y = -XMVectorGetY(XMVector3Dot(pos,u));  
	float z = -XMVectorGetY(XMVector3Dot(pos,d)); 


	XMMATRIX M;
	M(0,0) = r.m128_f32[0]; // r.x
	M(1,0) = r.m128_f32[1]; // r.y
	M(2,0) = r.m128_f32[2]; // r.z
	M(3,0) = x;

	M(0,1) = u.m128_f32[0];
	M(1,1) = u.m128_f32[1];
	M(2,1) = u.m128_f32[2];
	M(3,1) = y;

	M(0,2) = d.m128_f32[0];
	M(1,2) = d.m128_f32[1];
	M(2,2) = d.m128_f32[2];
	M(3,2) = z;

	M(0,3) = 0.0f;
	M(1,3) = 0.0f;
	M(2,3) = 0.0f;
	M(3,3) = 1.0f;

	cout << endl << M <<endl;
	return 0;
}

对XMVector3Dot返回的是XMVECTOR感到很奇怪。。

Return value

Returns a vector. The dot product between V1 and V2 is replicated into each component. 


不过不妨碍我们使用它,根据解释,对返回的XMVECTOR调用XMVectorGetX、XMVectorGetY、XMVectorGetZ都可以取到想要的点积的值。




4. Given that the view frustum has a vertical field of view angle θ = 45°, the aspect ratio is a = 4/3, the near plane is n = 1, and the far plane is f = 100, find the corresponding perspective projection matrix.


这题是关于Perspective Matrix的。


A = 1/(a*tan(θ/2) = 1.81066;
B = 1/(tan(θ/2) = 2.41421;

C = f/(f-n) = 1.0101;

D = -nf/(f-n) = -1.0101;


透视投影详解

深入探索透视投影变换 



5. Suppose that the view window has height 4. Find the distance d from the origin the view window must be to create a vertical field of view angle θ = 60°.

已知h/2 = 2, θ/2 = 30°,(h/2)/d = tan(θ/2) ,  故d = 2根号3。




6. Consider the following perspective projection matrix:


Find the vertical field of view angle α, the aspect ratio r, and the near and far plane values that were used to build this matrix.

1/(tan(θ/2) = 3.73205        --->  θ = 30°

1.86603 = 1/2 *3.73205    --->  r = 2

-5.12821/1.02564 = -5      --->  n = 5

f/(f-n) = 1.02564                --->  f = 200




7. Suppose that you are given the following perspective projection matrix with fixed A, B, C, D:


Find the vertical field of view angle a, the aspect ratio r, and the near and far plane values that were used to build this matrix in terms of A, B, C, D.That is, solve the following equations:


Solving these equations will give you formulas for extracting the vertical field of view angle α, the aspect ratio r, and the near and far plane values from any perspective projection matrix of the kind described in this book.

r = B/A;

α = 2 * arctan(1/B);

n = - D/C;

f  = n/(1 - 1/C);




8. For projective texturing algorithms, we multiply an affine(仿射) transformation matrix T after the projection matrix. Prove that it does not matter if we do the perspective divide before or after multiplying by T. Let v be a 4D vector, P be a projection matrix, T be a 4 × 4 affine transformation matrix, and let a w subscript(下标) denote the w-coordinate of a 4D vector, and prove:


证明就略过了,仿射变换包括旋转、缩放、平移等变换,我分别把这三种仿射矩阵代入T当中运算,等式成立。




9. Prove that the inverse of the projection matrix is given by:




代入A、B、C、D之后,所得矩阵正好与题目所给的矩阵相同。




10. Let [x, y, z, 1] be the coordinates of a point in view space, and let [xndc, yndc, zndc, 1] be the coordinates of the same point in NDC space. Prove that you can transform from NDC space to view space in the following way:

Explain why you need the division by w. Would you need the division by w if you were transforming from homogeneous clip space to view space?

使用第九题的 p 和 p逆 计算一下即可证明上式。

(x, y, z, 1) * p = (Ax, By, Cz+D, z) = (Ax/z, By/z, C+D/z, 1),即[xndc, yndc, zndc, 1]  = (Ax/z, By/z, C+D/z, 1);

(Ax/z, By/z, C+D/z, 1) * p逆 = (x/z, y/z, 1, 1/z); 同除w分量(此处w=1/z),得到 (x, y, z, 1),即原先view space里的点。

为什么需要除以w,是要让经过变换后的四维坐标的w分量与变换前的四维坐标的w分量相同,即两个坐标点表示处在同一个三维空间中( 就像14题的结论(a)描述的 )。

需要,理由同上。



11. Another way to describe the view frustum is by specifying the width and height of the view volume at the near plane. Given the width w and height h of the view volume at the near plane, and given the near plane n and far plane f, show that the perspective projection matrix is given by:


Figure 5.37. The x- and y-coordinates sheared by the z-coordinate. The top face of the box lies in the z = 1 plane. Observe that the shear transform translates points in this plane.

 1/( (w/h)*( (h/2) / n ) ) = 2n/w

 1/( (h/2) / n ) = 2n/h




12. Given a view frustum with vertical field of view angle θ, aspect ratio a, near plane n, and far plane f, find the 8 vertex corners of the frustum.

 (h/2) / n = tan(θ/2)

h = 2n*tan(θ/2)

w = a*2n*tan(θ/2)

近平面的四个顶点(±w/2, ±h/2, n, 1), 代入w、h

n/f = (±w/2)/x = (±h/2)/y

远平面的四个顶点(±wf/2n, fh/2n, f, 1), 代入w、h




13. Consider the 3D shear transform given by Sxy (x, y, z) = (x + ztx, y + zty, z). This transformation is illustrated in Figure 5.37. Prove that this is a linear transformation and has the following matrix representation:

变换的方式只是根据z坐标值的大小,或多或少地把原坐标点向+x,+y轴各自移动一段距离,变换显然是线性的。

(x, y, z) * Sxy = (x + ztx, y + zty, z)




14. Consider 3D points in the plane z = 1; that is, points of the form (x, y, 1). Observe that transforming a point (x, y, 1) by the shear transformation Sxy given in the previous exercise amounts to a 2D translation in the z = 1 plane:

If we are working on a 2D application, we could use 3D coordinates, but where our 2D universe always lies on the plane z = 1; then we could use Sxy to do translations in our 2D space.


Conclude the following generalizations:
(a) Just as a plane in 3D space is a 2D space, a plane in 4D space is a 3D space. When we write homogeneous points (x, y, z, 1) we are working in the 3D space that lives in the 4D plane w = 1.


(b) The translation matrix is the matrix representation of the 4D shear transformation Sxyz(x, y, z, w) = (x + wtx, y + wty, z + wtz, w). The 4D shear transformation has the effect of translating points in the plane w = 1.

读了两遍,说的很有道理,但没找到题目是什么。。





本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

龙书D3D11章节习题答案(第五章) 的相关文章

  • SQL及NoSQL学习系列1

    关系型数据库SQL 关系型数据库系统实现了关系模型 并用它来处理数据 关系模型在表中将信息与字段关联起来 也就是schemas 从而存储数据 这种数据库管理系统需要结构 例如表 在存储数据之前被定义出来 有了表 每一列 字段 都存储一个不同
  • javassist 在 spring boot jar中启动报错:javassist.NotFoundException

    由于需要在Springboot项目中动态替换一个方法的实现 所以引入了javassist 然而在IDEA中开发时一切正常 但是java jar启动就报错 Caused by javassist NotFoundException 在stac
  • [创业之路-64]:股权激励的十种形式

    薪酬有三件事 第一 实际绩效提高 第二 员工感受提高 第三 放大员工的未来价值 股权激励是放大价值最有效的说法 股权激励有利于企业与员工成为利益共同体 让员工相信对企业有利的一定对自己有利 股权激励有两个方向 一个是与奖励相关 二是与福利相
  • python入门学习随记(四)

    4 1 查找指定字符 本题要求编写程序 从给定字符串中查找某指定的字符 输入格式 输入的第一行是一个待查找的字符 第二行是一个以回车结束的非空字符串 不超过80个字符 输出格式 如果找到 在一行内按照格式 index 下标 输出该字符在字符
  • WinForm:禁用Panel容器滚动条自动移动位置的功能

    今天遇到了一个问题 描述如下 有一个Panel容器 将AutoScroll属性设置为True 此时Panel容器会在内容过多时自动展示一个滚动条 这个滚动条存在一个缺点 即会随着焦点变化自动滚向焦点位置 如果仅初始化界面时Panel滚动条位
  • MIT-BIH ECG 心电数据的下载和读取图解

    一 如何下载获取MIT BIH的数据从下面这个官方链接页面可以下载到所有48组MIT BIH心电数据 http www physionet org physiobank database mitdb 下面这个链接是MIT BIH数据库的详细
  • cocos2dx游戏以插件形式嵌入IE浏览器的实现

    一 cocos2dx渲染窗口修改及导出dll 1 思路 cocos2dx引擎使用opengl进行游戏画面的渲染 opengl的渲染窗口由其自身创建 具有跨平台性 那么我可以对渲染窗口进行修改 便可以达到将游戏窗口嵌入其他窗口的效果 2 实现
  • 【火灾检测】基于HSV特征实现火灾检测附matlab代码

    1 简介 针对传统火灾监测系统对于大空间的室内场合和开阔的室外环境易失效的问题 提出了一种结合火灾火焰特征和烟雾特征来进行判断的数字图像型火灾监测算法 火焰颜色特征是基于RGB颜色模型中的R G B三基色分量和它们之间的关系来判断是否有火焰
  • 网络攻防——ARP欺骗

    arp基础攻防 1 什么是arp攻击 2 arp攻击条件 3 arp如何进行攻击 3 1靶机环境搭建 3 2攻击机环境搭建 3 3如何发起arp攻击 4 如何防止arp攻击 5 参考文献 1 什么是arp攻击 ARP攻击是指攻击者利用ARP
  • python [3.2] urllib的使用

    urllib是python的一个获取url Uniform Resource Locators 统一资源定址器 的模块 它用urlopen函数的形式提供了一个非常简洁的接口 这使得用各种各样的协议获取url成为可能 它同时 也提供了一个稍微
  • 图灵1

    简介 艾伦 麦席森 图灵 英语 Alan Mathison Turing 1912年6月23日 1954年6月7日 英国数学家 逻辑学家 被称为计算机科学之父 人工智能之父 艾伦 麦席森 图灵 生平 1912年6月23日 艾伦 麦席森 图灵
  • SpringAOP的实现原理

    一 SpringAOP的面向切面编程 是面向对象编程的一种补充 用于处理系统中分布的各个模块的横切关注点 比如说事务管理 日志 缓存等 它是使用动态代理实现的 在内存中临时为增强某个方法生成一个AOP对象 这个对象包含目标对象的所有方法 在
  • 求m到n之间的素数和(函数)python

    目录 题目描述 AC代码 题目描述 输入两个正整数m和n m
  • k8s持久化存储

    目录 一 为什么要做持久化存储 1 emptyDir类型 2 hostPath 3 nfs 4 pvc 1 pv是什么 2 PVC是什么 5 storageclass 一 为什么要做持久化存储 在k8s中部署的应用都是以pod容器的形式运行

随机推荐

  • Windows 安装Redis(图文详解)

    一 Redis是什么数据库 Remote Dictionary Server Redis 是一个开源的使用 ANSI C 语言编写 遵守 BSD 协议 支持网络 可基于内存 分布式 可选持久性的键值对 Key Value 存储数据库 并提供
  • eclipse怎么在包里建一个包

    实现效果如下图 废话不多说 上图 1 设置Package Presentation 为Hierarchical 最为关键一步 2 在src下新建一个名为com abc hrm的包 3 在父包下新建子包a 因为只有一个子包 建完的子包会这样显
  • 关于绿色校园建设中综合能效平台的管理效益与研究

    摘要 伴随当前环保理念的不断发展 绿色节能理念也在逐步深入校园 为响应国家建设节约型校园的号召 本文以校园智能化综合能效管理平台建设为主题 介绍了平台建设方案 比较了某高校平台建设前后学生宿舍 教学及实训楼用能情况 分析结果表明高校综合能效
  • 啊哈C的简单使用

    打开啊哈C 新建一个程序输出hello world include
  • Java如何获取平台(操作系统)的默认编码

    Java如何获取平台 操作系统 的默认编码 平台 这两个字指的就是操作系统 比如Windows平台 MacOS平台 Linux平台 这也是我们经常读API文档的时候见到的英文 platform 如 platform encoding 如何获
  • spring-MVC

    Spring MVC Hello Spring MVC web xml 在WEB INF目录下创建 web xml 配置Spring MVC的入口 DispatcherServlet 把所有的请求都提交到该Servlet
  • 数据库十一章——并发控制

    11 1 并发控制概述 1 并发操作带来的数据不一致性 1 丢失修改 Lost Update 两个事务T1和T2读入同一数据并修改 T2的提交结果破坏了T1提交的结果 导致T1的修改被丢失 2 不可重复读 Non repeatable Re
  • XGBoost学习(六):输出特征重要性以及筛选特征

    XGBoost学习 一 原理 XGBoost学习 二 安装及介绍 XGBoost学习 三 模型详解 XGBoost学习 四 实战 XGBoost学习 五 参数调优 XGBoost学习 六 输出特征重要性以及筛选特征 完整代码及其数据 XGB
  • makefile-gdb

    makefile gdb 1 makefile makefile 文件中定义了 一系列的规则来指定 哪些文件需要先编译 哪些文件需要后编译 哪些文件需要重新编译 甚至于进行更复杂的功能操作 就像是一个shell脚本 其中也可以执行操作系统的
  • 关于迅雷与优酷

    迅雷的用户许可协议上有这样一段 4 4 使用本 软件 涉及到互联网服务 可能会受到各个环节不稳定因素的影响 存在因不可抗力 计算机病毒 黑客攻击 系统不稳定 用户所在位置 用户关机以及其他任何网络 技术 通信线路等原因造成的服务中断或不能满
  • 语义分割方法总结与综述

    语义分割论文 Dilated convolution low level high level information fusion 2019 CVPR DFANet Deep Feature Aggregation for Real Ti
  • 2207 字符串中最多数目的子字符串(递推)

    1 问题描述 给你一个下标从 0 开始的字符串 text 和另一个下标从 0 开始且长度为 2 的字符串 pattern 两者都只包含小写英文字母 你可以在 text 中任意位置插入一个字符 这个插入的字符必须是 pattern 0 或者
  • Axios请求使用XML格式进行请求

    第一次接触xml格式请求 因为我们公司要对接其他公司的平台 需要用XML格式进行请求 才可以打通内网访问 在网上查了好多资料也没明白这个格式怎么使用 试了多次 发现用模板字符串将请求内容包裹进去就可以使用 废话不多说 直接上代码 此处是请求
  • PL/SQL 动态Sql拼接where条件

    完整例子 DECLARE SQLSTR VARCHAR 200 SELECT FROM hr employees where 1 1 TYPE EMPCURTYP IS REF CURSOR V EMP CURSOR EMPCURTYP E
  • shell的文本处理( grep / sed / awk / find)

    1 grep文本过滤明令 全面搜索研究正则表达式并显示出来 grep 命令是一种强大的文本搜索工具 根据用户指定的 模式 对目标文本进行匹配检查 打印匹配到的行 由正则表达式或者字符及基本文本字符所编写的过滤条件 1 grep的格式 gre
  • 网络切片技术缺点_中国联通携手紫光展锐发布首款5G网络切片技术

    出品 搜狐科技 编辑 张雅婷 11月9日 中国联通携手紫光展锐发布全球首款支持完整3GPP标准化网络切片和eSIM的5G CPE VN007 据了解 CPE全称为客户终端设备 是适用于家里的一种微基站 不需要有线进户即可享受到高速上网体验的
  • 谷粒商城-启动renren-fast-vue

    关于启动renren fast vue 为了启动这个 这两天都快搞疯了 本人没搞过前端 所以很费劲 资料 包含node js10 16 3与python2 7 2 链接 https pan baidu com s 1CLSNkiQhMgtM
  • arXiv上传文章注意事项

    1 注册 不忍吐槽arxiv的注册过程 密码有格式要求 而且一旦输错了 得从头填一遍密码和验证码 唯一需要注意的是 如果想要后续用这个账号上传文章 一定记得用自己的 edu邮箱注册 edu cn自然也可以 因为非edu邮箱注册的账号 在上传
  • Java架构直通车——过滤器和拦截器使用

    文章目录 过滤器和拦截器的区别 Filter过滤器 Interceptor拦截器 过滤器和拦截器的区别 规范不同 Filter是Servlet规范中定义的 是Servlet容器支持的 而拦截器是Spring容器内的 是Spring框架支持的
  • 龙书D3D11章节习题答案(第五章)

    以下答案仅供参考 有错欢迎留言 Chapter 5 The Rendering Pipeline 1 Construct the vertex and index list of a pyramid 金字塔 as shown in Figu