﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-Ricky</title><link>http://www.cppblog.com/EverBeU/</link><description /><language>zh-cn</language><lastBuildDate>Tue, 09 Jun 2026 17:48:39 GMT</lastBuildDate><pubDate>Tue, 09 Jun 2026 17:48:39 GMT</pubDate><ttl>60</ttl><item><title>opengl中glulookat函数的意思</title><link>http://www.cppblog.com/EverBeU/archive/2012/02/12/165429.html</link><dc:creator>EverBeU</dc:creator><author>EverBeU</author><pubDate>Sun, 12 Feb 2012 12:47:00 GMT</pubDate><guid>http://www.cppblog.com/EverBeU/archive/2012/02/12/165429.html</guid><wfw:comment>http://www.cppblog.com/EverBeU/comments/165429.html</wfw:comment><comments>http://www.cppblog.com/EverBeU/archive/2012/02/12/165429.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/EverBeU/comments/commentRss/165429.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/EverBeU/services/trackbacks/165429.html</trackback:ping><description><![CDATA[<span style="text-align: center; widows: 2; text-transform: none; text-indent: 0px; letter-spacing: normal; border-collapse: separate; font: medium Simsun; white-space: normal; orphans: 2; color: rgb(0,0,0); word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class="Apple-style-span"><span style="text-align: left; font-family: Arial, Helvetica, simsun, u5b8bu4f53; font-size: 12px" class="Apple-style-span">&nbsp;gluLookAt(<span class="Apple-converted-space">&nbsp;</span>摄像机x,摄像机y,摄像机z,<span class="Apple-converted-space">&nbsp;</span>目标点x,目标点y,目标点z,<span class="Apple-converted-space">&nbsp;</span>摄像机顶朝向x,摄像机顶朝向y,摄像机顶朝向z<span class="Apple-converted-space">&nbsp;</span>)
<div style="text-align: left; padding-bottom: 5px; line-height: 25px; overflow-x: hidden; overflow-y: hidden; margin: 15px 0px; padding-left: 0px; padding-right: 0px; word-wrap: break-word; color: rgb(85,85,84); font-size: 14px; padding-top: 5px" class="bct fc05 fc11 nbw-blog ztag js-fs2">
<div style="line-height: 25px">
<div style="line-height: 25px"><span style="line-height: 43px; font-size: 18pt"><font style="line-height: 32px" size="4">osg中camera-&gt;setViewMatrixAsLopengl 的函数相当于opengl中的glulookat</font></span></div>
<div style="line-height: 25px"><span style="line-height: 43px; font-size: 18pt"><font style="line-height: 32px" size="4">openGL变换小节：</font></span></div>
<div style="line-height: 25px"><span style="line-height: 43px; font-size: 18pt"><font style="line-height: 32px" size="4">视图：指定观察者或摄像机的位置</font></span></div>
<div style="line-height: 25px"><span style="line-height: 43px; font-size: 18pt"><font style="line-height: 32px" size="4">模型：在场景中移动对象</font></span></div>
<div style="line-height: 25px"><span style="line-height: 43px; font-size: 18pt"><font style="line-height: 32px" size="4">模型视图：描述视图变换盒模型变换的对偶性</font></span></div>
<div style="line-height: 25px"><span style="line-height: 43px; font-size: 18pt"><font style="line-height: 32px" size="4">投影：对视见空间进行修剪和改变大小</font></span></div>
<div style="line-height: 25px"><span style="line-height: 43px; font-size: 18pt"><font style="line-height: 32px" size="4">视见区: 对到窗口的最终输出进行缩放</font></span></div>
<div style="line-height: 25px"><span style="line-height: 43px; font-size: 18pt"><font style="line-height: 32px" size="4">眼坐标：来自观察者的观察点，与可能发生的任何变换无关，可以把它们视为&#8220;绝对&#8221;屏幕坐标。因此并不是真正的坐标，而是代表一个虚拟的固定坐标系，用作参考的公共框架。大部分变换都是根据它们相对于眼坐标系的效果来描述的。</font></span></div>
<div style="line-height: 25px"><img style="line-height: 25px; border-right-width: 0px; width: 656px; zoom: 1; max-width: 100%; border-top-width: 0px; border-bottom-width: 0px; height: 416px; border-left-width: 0px; cursor: pointer" border="0" alt="opengl中glulookat函数的意思 - 流光如梦 - 流光手记" src="http://www.gissky.net/blog/UploadFiles/2007-7/72883088.bmp" width="927" height="323" resized="true" /></div><br style="line-height: 25px" /><br style="line-height: 25px" /><br style="line-height: 25px" /><br style="line-height: 25px" />
<div style="line-height: 25px">视图变换的过程如下：视图（eye)变换或者模型变换，投影变换（正射投影和透视投影），视见区变换。</div>
<div style="line-height: 25px">利用实用库函数<span style="line-height: 28px; font-size: 12pt">gluLookAt()</span>设置视觉坐标系。在实际的编程应用中，用户在完成场景的建模后，往往需要选择一个合适的视角或者不停地变换视角，以对场景作观察。实用库函数<span style="line-height: 28px; font-size: 12pt">gluLookAt()</span>就提供了这样的一个功能。</div>
<p style="padding-bottom: 0px; line-height: 25px; margin: 0px 0px 10px; padding-left: 0px; padding-right: 0px; padding-top: 0px" align="justify"><span style="line-height: 28px; font-size: 12pt">void gluLookAt(GLdouble eyex,GLdouble eyey,GLdouble eyez,</span></p>
<p style="padding-bottom: 0px; line-height: 25px; margin: 0px 0px 10px; padding-left: 0px; padding-right: 0px; padding-top: 0px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GLdouble centerx,GLdouble centery,GLdouble centerz,</p>
<p style="padding-bottom: 0px; line-height: 25px; margin: 0px 0px 10px; padding-left: 0px; padding-right: 0px; padding-top: 0px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GLdouble upx,GLdouble upy,GLdouble upz);</p>
<p style="padding-bottom: 0px; line-height: 25px; margin: 0px 0px 10px; padding-left: 0px; padding-right: 0px; padding-top: 0px" align="justify">该函数定义一个视图矩阵，并与当前矩阵相乘。</p>
<p style="padding-bottom: 0px; line-height: 25px; margin: 0px 0px 10px; padding-left: 0px; padding-right: 0px; padding-top: 0px" align="justify"><span style="line-height: 28px; font-size: 12pt">eyex, eyey,eyez 指定视点的位置</span></p>
<p style="padding-bottom: 0px; line-height: 25px; margin: 0px 0px 10px; padding-left: 0px; padding-right: 0px; padding-top: 0px" align="justify"><span style="line-height: 28px; font-size: 12pt">centerx,centery,centerz 指定参考点的位置</span></p>
<div style="line-height: 25px" align="justify"><span style="line-height: 28px; font-size: 12pt">upx,upy,upz 指定视点向上的方向</span></div>
<div style="line-height: 25px" align="justify"></div>
<div style="line-height: 25px" align="justify"><span style="line-height: 28px; font-size: 12pt"><img style="line-height: 28px; border-right-width: 0px; max-width: 100%; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; cursor: pointer" border="0" alt="opengl中glulookat函数的意思 - 流光如梦 - 流光手记" src="http://www.gissky.net/blog/UploadFiles/2007-7/72478764.gif" /></span></div>
<div style="line-height: 25px" align="justify"><span style="line-height: 28px; font-size: 12pt"><span style="line-height: 28px">&nbsp;&nbsp;&nbsp;</span><span class="Apple-converted-space">&nbsp;</span><span style="line-height: 28px; color: rgb(255,153,0)">图5-1-10 函数gluLookAt()的设置</span></span></div>
<p style="padding-bottom: 0px; line-height: 28px; margin: 0px 0px 10px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><span style="line-height: 28px; font-size: 12pt">&nbsp;&nbsp;&nbsp; 视点</span><span style="line-height: 28px; font-size: 12pt"><em style="line-height: 28px; font-style: italic">E</em></span><span style="line-height: 28px; font-size: 12pt">、<span style="line-height: 28px; font-size: 12pt">参考点</span></span><span style="line-height: 28px; font-size: 12pt"><em style="line-height: 28px; font-style: italic">C</em></span><span style="line-height: 28px; font-size: 12pt">、<span style="line-height: 28px; font-size: 12pt">视点向上的方向U实际上就是设定了一个视觉坐标系。这个视觉坐标系的原点是</span></span><span style="line-height: 28px; font-size: 12pt"><em style="line-height: 28px; font-style: italic">E</em></span><span style="line-height: 28px; font-size: 12pt">，视线的方向（即</span><span style="line-height: 28px; font-size: 12pt"><em style="line-height: 28px; font-style: italic">z</em></span><span style="line-height: 28px; font-size: 12pt">轴）是</span><span style="line-height: 28px; font-size: 12pt"><em style="line-height: 28px; font-style: italic">C</em></span><span style="line-height: 28px; font-size: 12pt">-</span><span style="line-height: 28px; font-size: 12pt"><em style="line-height: 28px; font-style: italic">U</em></span><span style="line-height: 28px; font-size: 12pt">，</span><span style="line-height: 28px; font-size: 12pt"><em style="line-height: 28px; font-style: italic">y</em></span><span style="line-height: 28px; font-size: 12pt">轴方向就是视点向上的方向</span><span style="line-height: 28px; font-size: 12pt"><em style="line-height: 28px; font-style: italic">U</em></span><span style="line-height: 28px; font-size: 12pt">，</span><span style="line-height: 28px; font-size: 12pt">剩下的</span><span style="line-height: 28px; font-size: 12pt"><em style="line-height: 28px; font-style: italic">x</em></span><span style="line-height: 28px; font-size: 12pt">轴方向就是向量((</span><span style="line-height: 28px; font-size: 12pt"><em style="line-height: 28px; font-style: italic">C</em></span><span style="line-height: 28px; font-size: 12pt">-</span><span style="line-height: 28px; font-size: 12pt"><em style="line-height: 28px; font-style: italic">E</em></span><span style="line-height: 28px; font-size: 12pt">)*</span><span style="line-height: 28px; font-size: 12pt"><em style="line-height: 28px; font-style: italic">U</em></span><span style="line-height: 28px; font-size: 12pt">)。由于</span><span style="line-height: 28px; font-size: 12pt"><em style="line-height: 28px; font-style: italic">y</em></span><span style="line-height: 28px; font-size: 12pt">轴和</span><span style="line-height: 28px; font-size: 12pt"><em style="line-height: 28px; font-style: italic">x</em></span><span style="line-height: 28px; font-size: 12pt">轴是垂直的，所以也要求向量(</span><span style="line-height: 28px; font-size: 12pt"><em style="line-height: 28px; font-style: italic">C</em></span><span style="line-height: 28px; font-size: 12pt">-</span><span style="line-height: 28px; font-size: 12pt"><em style="line-height: 28px; font-style: italic">U</em></span><span style="line-height: 28px; font-size: 12pt">)和</span><span style="line-height: 28px; font-size: 12pt"><em style="line-height: 28px; font-style: italic">U</em></span><span style="line-height: 28px; font-size: 12pt">互相垂直。这点在设置该函数参数时是必须注意的。</span></p>
<div style="line-height: 25px"></div></div>
<div style="line-height: 25px">yqchang 发表于 2007-7-2 22:26:00　<a style="line-height: 25px; color: rgb(145,104,13); text-decoration: none" href="http://www.gissky.net/blog/user2/yqchang/archives/2007/14963.html#" rel="nofollow">阅读全文<span style="line-height: 25px">(1267)</span></a><span class="Apple-converted-space">&nbsp;</span>|<span class="Apple-converted-space">&nbsp;</span><a style="line-height: 25px; color: rgb(145,104,13); text-decoration: none" href="http://www.gissky.net/blog/user2/yqchang/archives/2007/14963.html#cmt" rel="nofollow">回复(2)</a><span class="Apple-converted-space">&nbsp;</span>|<span class="Apple-converted-space">&nbsp;</span><a style="line-height: 25px; color: rgb(145,104,13); text-decoration: none" href="http://www.gissky.net/blog/showtb.asp?id=14963" rel="nofollow" target="_blank">引用通告<span style="line-height: 25px">(32)</span></a><span class="Apple-converted-space">&nbsp;</span>|<span class="Apple-converted-space">&nbsp;</span><a style="line-height: 25px; color: rgb(145,104,13); text-decoration: none" href="http://www.gissky.net/blog/user_post.asp?logid=14963" rel="nofollow" target="_blank">编辑</a></div>
<div style="line-height: 25px">
<ul style="padding-bottom: 0px; line-height: 25px; margin: 5px 0px 5px 40px; padding-left: 0px; padding-right: 0px; padding-top: 0px"></ul></div>
<div style="line-height: 25px">
<h3 style="padding-bottom: 0px; line-height: 28px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">Re:opengl中glulookat函数的意思<a style="line-height: 28px; color: rgb(145,104,13); text-decoration: none" rel="nofollow"></a></h3>
<div style="line-height: 25px"><a style="line-height: 25px; color: rgb(145,104,13); text-decoration: none" href="http://hi.baidu.com/%E7%81%AB%E8%8A%B1%E7%9A%84%E6%98%8E%E5%A4%A9" rel="nofollow" target="_blank"><img style="line-height: 25px; border-right-width: 0px; max-width: 100%; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" alt="opengl中glulookat函数的意思 - 流光如梦 - 流光手记" align="absMiddle" src="http://www.gissky.net/blog/images/ico_default.gif" width="48" height="48" /></a><span style="line-height: 25px">还是最后一句:<br style="line-height: 25px" />由于y轴和x轴是垂直的，所以也要求向量(C-U)和U互相垂直。这点在设置该函数参数时是必须注意的。<br style="line-height: 25px" />应用中不垂直也是没问题的,所以有找了个可能更合理的解释<br style="line-height: 25px" />void gluLookAt(<span class="Apple-converted-space">&nbsp;</span><br style="line-height: 25px" />GLdouble eyex,<span class="Apple-converted-space">&nbsp;</span><br style="line-height: 25px" />GLdouble eyey,<span class="Apple-converted-space">&nbsp;</span><br style="line-height: 25px" />GLdouble eyez,<span class="Apple-converted-space">&nbsp;</span><br style="line-height: 25px" />GLdouble centerx,<span class="Apple-converted-space">&nbsp;</span><br style="line-height: 25px" />GLdouble centery,<span class="Apple-converted-space">&nbsp;</span><br style="line-height: 25px" />GLdouble centerz,<span class="Apple-converted-space">&nbsp;</span><br style="line-height: 25px" />GLdouble upx,<span class="Apple-converted-space">&nbsp;</span><br style="line-height: 25px" />GLdouble upy,<span class="Apple-converted-space">&nbsp;</span><br style="line-height: 25px" />GLdouble upz<span class="Apple-converted-space">&nbsp;</span><br style="line-height: 25px" />);<span class="Apple-converted-space">&nbsp;</span><br style="line-height: 25px" /><br style="line-height: 25px" />eye=(eyex, eyey, eyez)是视点(原点)的位置<span class="Apple-converted-space">&nbsp;</span><br style="line-height: 25px" />center = (centerx, centery, centerz)是视口中心点的位置<span class="Apple-converted-space">&nbsp;</span><br style="line-height: 25px" />center - eye是z轴负方向<span class="Apple-converted-space">&nbsp;</span><br style="line-height: 25px" />z = (eye - center) / |eye - center|<span class="Apple-converted-space">&nbsp;</span><br style="line-height: 25px" />up = (upx, upy, upz) - eye表示上方<span class="Apple-converted-space">&nbsp;</span><br style="line-height: 25px" />x轴正方向x = up &#215; z / |up &#215; z|<span class="Apple-converted-space">&nbsp;</span><br style="line-height: 25px" />y轴正方向(就是正上方)y = z &#215; x</span> 
<div style="line-height: 25px"></div></div>
<div style="line-height: 25px">
<p style="padding-bottom: 0px; line-height: 25px; margin: 0px 0px 10px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><a style="line-height: 25px; color: rgb(145,104,13); text-decoration: none" href="http://www.gissky.net/blog/user_comments.asp?act%3Cwbr%3Eion=modify&amp;re=true&amp;id=35566" rel="nofollow" target="_blank"></a>&nbsp;</p>
<p style="padding-bottom: 0px; line-height: 25px; margin: 0px 0px 10px; padding-left: 0px; padding-right: 0px; padding-top: 0px"></p>
<table style="line-height: 25px" border="0" cellspacing="0" cellpadding="0">
<tbody style="line-height: 25px">
<tr style="line-height: 25px">
<td style="line-height: 25px"><cc style="line-height: 25px">恩，1楼正解，那我说个详细的<span class="Apple-converted-space">&nbsp;</span><br style="line-height: 25px" />视点变换可以通过gluLookAt()函数完成，那三组参数分别指定了相机的位置、瞄准方向的参考点和相机向上方向。<span class="Apple-converted-space">&nbsp;</span><br style="line-height: 25px" />通常视点变换操作在模型变换操作之前发出，以便模型变换先对物体发生作用。这样，场景中物体的顶点经过模型转换后一定到所希望的位置，然后再对场景进行视点定位等操作。模型变换和视点变换共同构成模型视景矩阵。<span class="Apple-converted-space">&nbsp;</span><br style="line-height: 25px" />gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);<span class="Apple-converted-space">&nbsp;</span><br style="line-height: 25px" />1、改变前三个参数的值可以模拟人在实际环境中的移动；<span class="Apple-converted-space">&nbsp;</span><br style="line-height: 25px" />2、改变中间三个参数的值，可以模拟人眼的转动，即所观察场景的变化。<span class="Apple-converted-space">&nbsp;</span><br style="line-height: 25px" />3、后三个参数的值比较特殊，它所制定的不是一个点，而是一个方向，即决定将哪一个坐标轴作为向上的方向，如果向上方向与观察点到中心点的方向一致，结果将是不确定的。</cc></td></tr></tbody></table></div></div></div></span></span><img src ="http://www.cppblog.com/EverBeU/aggbug/165429.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/EverBeU/" target="_blank">EverBeU</a> 2012-02-12 20:47 <a href="http://www.cppblog.com/EverBeU/archive/2012/02/12/165429.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>