📄 tutorial_44.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><!-- 这篇文章由Dancingwind翻译,作者的联系方式zhouwei02@mails.tsinghua.edu.cn --><title>NeHe OpenGL教程第四十四课,DancingWind翻译</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
A:active {
BACKGROUND: none transparent scroll repeat 0% 0%; COLOR: #bbccff; TEXT-DECORATION: none
}
A:link {
BACKGROUND: none transparent scroll repeat 0% 0%; COLOR: #bbccff; TEXT-DECORATION: none
}
A:visited {
BACKGROUND: none transparent scroll repeat 0% 0%; COLOR: #bbccff; TEXT-DECORATION: none
}
A:hover {
BACKGROUND: none transparent scroll repeat 0% 0%; COLOR: #ffda6a; TEXT-DECORATION: none
}
BODY {
COLOR: #ffffff; BACKGROUND-COLOR: #000000
}
TD IMG {
DISPLAY: block
}
.back {
BACKGROUND: #000022; COLOR: #ffffff
}
.back2 {
BACKGROUND: #000000; COLOR: #ffffff
}
.back3 {
BACKGROUND: #000022; COLOR: #ffffff
}
.copy {
FONT-SIZE: 11px; LINE-HEIGHT: normal; FONT-STYLE: normal; FONT-FAMILY: Tahoma, Verdana, sans-serif; FONT-VARIANT: normal; TEXT-DECORATION: none
}
.head {
FONT: bold 13px Tahoma, Verdana, sans-serif; TEXT-DECORATION: none
}
.link {
FONT-SIZE: 14px; LINE-HEIGHT: normal; FONT-STYLE: normal; FONT-FAMILY: Tahoma, Verdana, sans-serif; FONT-VARIANT: normal; TEXT-DECORATION: none
}
.menu {
FONT: bold 17px Tahoma, Verdana, sans-serif; TEXT-DECORATION: none
}
.news {
BACKGROUND: #00008b; COLOR: #ffffff
}
.tab {
PADDING-LEFT: 35px
}
.text {
FONT-SIZE: 12px; LINE-HEIGHT: normal; FONT-STYLE: normal; FONT-FAMILY: Tahoma, Verdana, sans-serif; FONT-VARIANT: normal; TEXT-DECORATION: none
}
.theme {
BACKGROUND: none transparent scroll repeat 0% 0%; COLOR: #bbccff
}
.dotted {
BORDER-RIGHT: #00008b 2px dotted; BORDER-TOP: #00008b 2px dotted; BORDER-LEFT: #00008b 2px dotted; BORDER-BOTTOM: #00008b 2px dotted
}
.solid {
BORDER-RIGHT: #ffffff 1px solid; BORDER-TOP: #ffffff 1px solid; BORDER-LEFT: #ffffff 1px solid; BORDER-BOTTOM: #ffffff 1px solid
}
.logo {
BACKGROUND-IMAGE: url(../graphics/rgb/logo.jpg)
}
.menubar {
BACKGROUND-IMAGE: url(../graphics/rgb/menubar.jpg)
}
.menubg {
BACKGROUND-IMAGE: url(../graphics/rgb/menubg.jpg)
}
.menuheading {
BACKGROUND-IMAGE: url(../graphics/rgb/menuheading.jpg)
}
.nehebutton {
BACKGROUND-IMAGE: url(../graphics/rgb/nehebutton.jpg)
}
.newslogo {
BACKGROUND-IMAGE: url(../graphics/rgb/newslogo.jpg)
}
.tinylogo {
BACKGROUND-IMAGE: url(../graphics/rgb/border/tinylogo.jpg)
}
.bc {
BACKGROUND-IMAGE: url(../Pic/bc.png)
}
.bl {
BACKGROUND-IMAGE: url(../Pic/bl.png)
}
.br {
BACKGROUND-IMAGE: url(../Pic/br.png)
}
.c {
BACKGROUND-IMAGE: url(../Picc.png)
}
.l {
BACKGROUND-IMAGE: url(../Pic/l.png)
}
.lc {
BACKGROUND-IMAGE: url(../Piclc.png)
}
.r {
BACKGROUND-IMAGE: url(../Pic/r.png)
}
.rc {
BACKGROUND-IMAGE: url(../Picrc.png)
}
.tc {
BACKGROUND-IMAGE: url(../Pic/tc.png)
}
.tl {
BACKGROUND-IMAGE: url(../Pic/tl.png)
}
.tr {
BACKGROUND-IMAGE: url(../Pic/tr.png)
}
</style></head><body bgcolor="black" link="#aaccff" text="white" vlink="#aaccff">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td class="tinylogo" height="130" width="326"><img alt="NeHe Productions" src="Tutorial_44_files/logo.png" height="130" width="326"></td>
<td align="center" valign="center"><div align="center"><font class="text"><font class="theme" size="+3"><b><i>第44课</i></b></font></font></div></td>
</tr></tbody></table>
<!-- 上边框-->
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td><img src="Tutorial_44_files/tl.jpg" height="28" width="28"></td>
<td width="100%"><img src="Tutorial_44_files/tc.gif" height="28" width="100%"></td>
<td><img src="Tutorial_44_files/tr.gif" height="28" width="28"></td>
</tr>
</tbody>
</table>
<!-- 中部-->
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<!-- 中部左边框-->
<td background="Tutorial_44_files/l.gif"><img src="Tutorial_44_files/l.gif" height="28" width="28"></td>
<!-- 中部文字部分-->
<td valign="top" width="100%">
<table border="0" width="100%">
<tbody><tr>
<td width="20%"><img src="Tutorial_44_files/lesson44.jpg" height="120" width="160"></td>
<td width="80%"><p><font><b>3D 光晕</b></font><font size="2"><b></b></font></p>
<p><font size="3">当镜头对准太阳的时候就会出现这种效果,模拟它非常的简单,一点数学和纹理贴图就够了。好好看看吧。</font></p></td>
</tr>
</tbody></table>
</td>
<!-- 中部右边框-->
<td background="Tutorial_44_files/r.gif"><img src="Tutorial_44_files/r.gif" height="28" width="28"></td>
</tr>
</tbody>
</table>
<!-- 下边框-->
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td><img src="Tutorial_44_files/bl.gif" height="28" width="28"></td>
<td width="100%"><img src="Tutorial_44_files/bc.gif" height="28" width="100%"></td>
<td><img src="Tutorial_44_files/br.gif" height="28" width="28"></td>
</tr>
</tbody>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td class="tl"><img alt="" src="Tutorial_44_files/blank1.gif" height="28" width="28"></td>
<td class="tc" width="100%"><img alt="" src="Tutorial_44_files/blank1.gif" height="28" width="100%"></td>
<td class="tr"><img alt="" src="Tutorial_44_files/blank1.gif" height="28" width="28"></td></tr></tbody></table>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td class="l"><img alt="" src="Tutorial_44_files/blank1.gif" height="28" width="28"></td>
<td class="back3" valign="top" width="100%">大家好,欢迎来到新的一课,在这一课中我们将扩展glCamera类,来实现镜头光晕的效果。在日常生活中,当我们对着光源看时,会发现强烈的反光。<br>
为了完成这个效果,我们需要一些数学知识。首先,我们需要一些函数,用来检测某个点或球是否在当前的视景体内。接着我们需要一些纹理作为我们的光晕效果,我们可以把它贴在显示面上。
<p>在我的上一个摄像机类里把下面函数写错了,现在修正如下:</p>
</td>
<td class="r"><img alt="" src="Tutorial_44_files/blank1.gif" height="28" width="28"></td></tr></tbody></table>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td class="bl"><img alt="" src="Tutorial_44_files/blank1.gif" height="28" width="28"></td>
<td class="bc" width="100%"><img alt="" src="Tutorial_44_files/blank1.gif" height="28" width="28"></td>
<td class="br"><img alt="" src="Tutorial_44_files/blank1.gif" height="28" width="28"></td></tr></tbody></table>
<pre>void glCamera::SetPrespective()<br>{<br> GLfloat Matrix[16]; <br> glVector v; <br> </pre>
<p> <span class="theme">// 根据当前的偏转角旋转视线</span><br>
glRotatef(m_HeadingDegrees, 0.0f, 1.0f, 0.0f);<br>
glRotatef(m_PitchDegrees, 1.0f, 0.0f, 0.0f);</p>
<p> <span class="theme">// 返回模型变换矩阵</span><br>
glGetFloatv(GL_MODELVIEW_MATRIX, Matrix);</p>
<p> <span class="theme">// 获得视线的方向</span><br>
m_DirectionVector.i = Matrix[8];<br>
m_DirectionVector.j = Matrix[9];<br>
m_DirectionVector.k = -Matrix[10];</p>
<p> <span class="theme">// 重置矩阵</span><br>
glLoadIdentity();</p>
<p> <span class="theme">// 旋转场景</span><br>
glRotatef(m_PitchDegrees, 1.0f, 0.0f, 0.0f);<br>
glRotatef(m_HeadingDegrees, 0.0f, 1.0f, 0.0f);</p>
<p> <span class="theme">// 设置当前摄像机的位置</span><br>
v = m_DirectionVector;<br>
v *= m_ForwardVelocity;<br>
m_Position.x += v.i;<br>
m_Position.y += v.j;<br>
m_Position.z += v.k;</p>
<p> <span class="theme">// 变换到新的位置</span><br>
glTranslatef(-m_Position.x, -m_Position.y, -m_Position.z);<br>
}</p>
<p></p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td class="tl"><img alt="" src="Tutorial_44_files/blank1.gif" height="28" width="28"></td>
<td class="tc" width="100%"><img alt="" src="Tutorial_44_files/blank1.gif" height="28" width="100%"></td>
<td class="tr"><img alt="" src="Tutorial_44_files/blank1.gif" height="28" width="28"></td></tr></tbody></table>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td class="l"><img alt="" src="Tutorial_44_files/blank1.gif" height="28" width="28"></td>
<td class="back3" valign="top" width="100%"> <p>好了,我们现在开始吧。我将使用4个对立的纹理来制造我们的镜头光晕,第一和二个光晕图像被放置在光源处,第三和第四个图像将根据视点的位置和方向动态的生成。纹理的图像如下所示:</p>
<table align="center" border="0">
<tbody>
<tr>
<td align="center"><font class="text">Big Glow<br>
<br>
<img src="Tutorial_44_files/big_glow.jpg" height="128" width="128"></font></td>
<td width="100"> </td>
<td align="center"><font class="text">Streaks<br>
<br>
<img src="Tutorial_44_files/streaks.jpg" height="128" width="128"></font></td>
</tr>
<tr>
<td align="center"><font class="text">Glow<br>
<br>
<img src="Tutorial_44_files/glow.jpg" height="64" width="64"></font></td>
<td width="100"> </td>
<td align="center"><font class="text">Halo<br>
<br>
<img src="Tutorial_44_files/halo.jpg" height="64" width="64"></font></td>
</tr>
</tbody>
</table>
<p> </p>
<p> </p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -