Commit | Line | Data |
---|---|---|
7faf1d71 AW |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "xhtml1-transitional.dtd"> |
2 | <!-- saved from url=(0013)about:internet --> | |
3 | <?xml-stylesheet type="text/xsl" href="mathml.xsl"?><html xmlns="http://www.w3.org/1999/xhtml" xmlns:pref="http://www.w3.org/2002/Math/preference" pref:renderer="mathplayer-dl"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>gluPerspective</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /></head><body><div class="refentry" lang="en" xml:lang="en"><a id="gluPerspective"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>gluPerspective — set up a perspective projection matrix</p></div><div class="refsynopsisdiv"><h2>C Specification</h2><div class="funcsynopsis"><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0"><tr><td><code class="funcdef">void <b class="fsfunc">gluPerspective</b>(</code></td><td>GLdouble </td><td><var class="pdparam">fovy</var>, </td></tr><tr><td> </td><td>GLdouble </td><td><var class="pdparam">aspect</var>, </td></tr><tr><td> </td><td>GLdouble </td><td><var class="pdparam">zNear</var>, </td></tr><tr><td> </td><td>GLdouble </td><td><var class="pdparam">zFar</var><code>)</code>;</td></tr></table></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="parameters"></a><h2>Parameters</h2><div class="variablelist"><dl><dt><span class="term"><em class="parameter"><code>fovy</code></em></span></dt><dd><p> | |
4 | Specifies the field of view angle, in degrees, in the <span class="emphasis"><em>y</em></span> direction. | |
5 | </p></dd><dt><span class="term"><em class="parameter"><code>aspect</code></em></span></dt><dd><p> | |
6 | Specifies the aspect ratio that determines | |
7 | the field of view in the <span class="emphasis"><em>x</em></span> direction. | |
8 | The aspect ratio is the ratio of <span class="emphasis"><em>x</em></span> (width) to <span class="emphasis"><em>y</em></span> (height). | |
9 | </p></dd><dt><span class="term"><em class="parameter"><code>zNear</code></em></span></dt><dd><p> | |
10 | Specifies the distance from the viewer to the near clipping plane | |
11 | (always positive). | |
12 | </p></dd><dt><span class="term"><em class="parameter"><code>zFar</code></em></span></dt><dd><p> | |
13 | Specifies the distance from the viewer to the far clipping plane | |
14 | (always positive). | |
15 | </p></dd></dl></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="description"></a><h2>Description</h2><p> | |
16 | <code class="function">gluPerspective</code> specifies a viewing frustum into the world coordinate system. | |
17 | In general, the aspect ratio in <code class="function">gluPerspective</code> should match the aspect ratio | |
18 | of the associated viewport. For example, | |
19 | <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" overflow="scroll"> | |
20 | ||
21 | <mml:mrow> | |
22 | <mml:mi mathvariant="italic">aspect</mml:mi> | |
23 | <mml:mo>=</mml:mo> | |
24 | <mml:mn>2.0</mml:mn> | |
25 | </mml:mrow> | |
26 | </mml:math> | |
27 | means | |
28 | the viewer's | |
29 | angle of view is twice as wide in <span class="emphasis"><em>x</em></span> as it is in <span class="emphasis"><em>y</em></span>. | |
30 | If the viewport is | |
31 | twice as wide as it is tall, it displays the image without distortion. | |
32 | </p><p> | |
33 | The matrix generated by <code class="function">gluPerspective</code> is multipled by the current matrix, | |
34 | just as if <a class="citerefentry" href="glMultMatrix.xml"><span class="citerefentry"><span class="refentrytitle">glMultMatrix</span></span></a> were called with the generated matrix. | |
35 | To load the perspective matrix onto the current matrix stack instead, | |
36 | precede the call to <code class="function">gluPerspective</code> with a call to <a class="citerefentry" href="glLoadIdentity.xml"><span class="citerefentry"><span class="refentrytitle">glLoadIdentity</span></span></a>. | |
37 | </p><p> | |
38 | Given <span class="emphasis"><em>f</em></span> defined as follows: | |
39 | </p><p> | |
40 | </p><div class="informalequation"><mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" overflow="scroll"> | |
41 | ||
42 | <mml:mrow> | |
43 | <mml:mi mathvariant="italic">f</mml:mi> | |
44 | <mml:mo>=</mml:mo> | |
45 | <mml:mrow> | |
46 | <mml:mi mathvariant="italic">cotangent</mml:mi> | |
47 | <mml:mo></mml:mo> | |
48 | <mml:mfenced open="(" close=")"> | |
49 | <mml:mfrac> | |
50 | <mml:mi mathvariant="italic">fovy</mml:mi> | |
51 | <mml:mn>2</mml:mn> | |
52 | </mml:mfrac> | |
53 | </mml:mfenced> | |
54 | </mml:mrow> | |
55 | </mml:mrow> | |
56 | </mml:math></div><p> | |
57 | The generated matrix is | |
58 | </p><p> | |
59 | </p><div class="informalequation"><mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" overflow="scroll"> | |
60 | ||
61 | <mml:mfenced open="(" close=")"> | |
62 | <mml:mtable> | |
63 | <mml:mtr> | |
64 | <mml:mtd> | |
65 | <mml:mfrac> | |
66 | <mml:mi mathvariant="italic">f</mml:mi> | |
67 | <mml:mi mathvariant="italic">aspect</mml:mi> | |
68 | </mml:mfrac> | |
69 | </mml:mtd> | |
70 | <mml:mtd> | |
71 | <mml:mn>0</mml:mn> | |
72 | </mml:mtd> | |
73 | <mml:mtd> | |
74 | <mml:mn>0</mml:mn> | |
75 | </mml:mtd> | |
76 | <mml:mtd> | |
77 | <mml:mn>0</mml:mn> | |
78 | </mml:mtd> | |
79 | </mml:mtr> | |
80 | <mml:mtr> | |
81 | <mml:mtd> | |
82 | <mml:mn>0</mml:mn> | |
83 | </mml:mtd> | |
84 | <mml:mtd> | |
85 | <mml:mi mathvariant="italic">f</mml:mi> | |
86 | </mml:mtd> | |
87 | <mml:mtd> | |
88 | <mml:mn>0</mml:mn> | |
89 | </mml:mtd> | |
90 | <mml:mtd> | |
91 | <mml:mn>0</mml:mn> | |
92 | </mml:mtd> | |
93 | </mml:mtr> | |
94 | <mml:mtr> | |
95 | <mml:mtd> | |
96 | <mml:mn>0</mml:mn> | |
97 | </mml:mtd> | |
98 | <mml:mtd> | |
99 | <mml:mn>0</mml:mn> | |
100 | </mml:mtd> | |
101 | <mml:mtd> | |
102 | <mml:mfrac> | |
103 | <mml:mfenced open="" close=""> | |
104 | <mml:mrow> | |
105 | <mml:mi mathvariant="italic">zFar</mml:mi> | |
106 | <mml:mo>+</mml:mo> | |
107 | <mml:mi mathvariant="italic">zNear</mml:mi> | |
108 | </mml:mrow> | |
109 | </mml:mfenced> | |
110 | <mml:mfenced open="" close=""> | |
111 | <mml:mrow> | |
112 | <mml:mi mathvariant="italic">zNear</mml:mi> | |
113 | <mml:mo>-</mml:mo> | |
114 | <mml:mi mathvariant="italic">zFar</mml:mi> | |
115 | </mml:mrow> | |
116 | </mml:mfenced> | |
117 | </mml:mfrac> | |
118 | </mml:mtd> | |
119 | <mml:mtd> | |
120 | <mml:mfrac> | |
121 | <mml:mfenced open="" close=""> | |
122 | <mml:mrow> | |
123 | <mml:mn>2</mml:mn> | |
124 | <mml:mo>×</mml:mo> | |
125 | <mml:mi mathvariant="italic">zFar</mml:mi> | |
126 | <mml:mo>×</mml:mo> | |
127 | <mml:mi mathvariant="italic">zNear</mml:mi> | |
128 | </mml:mrow> | |
129 | </mml:mfenced> | |
130 | <mml:mfenced open="" close=""> | |
131 | <mml:mrow> | |
132 | <mml:mi mathvariant="italic">zNear</mml:mi> | |
133 | <mml:mo>-</mml:mo> | |
134 | <mml:mi mathvariant="italic">zFar</mml:mi> | |
135 | </mml:mrow> | |
136 | </mml:mfenced> | |
137 | </mml:mfrac> | |
138 | </mml:mtd> | |
139 | </mml:mtr> | |
140 | <mml:mtr> | |
141 | <mml:mtd> | |
142 | <mml:mn>0</mml:mn> | |
143 | </mml:mtd> | |
144 | <mml:mtd> | |
145 | <mml:mn>0</mml:mn> | |
146 | </mml:mtd> | |
147 | <mml:mtd> | |
148 | <mml:mn>-1</mml:mn> | |
149 | </mml:mtd> | |
150 | <mml:mtd> | |
151 | <mml:mn>0</mml:mn> | |
152 | </mml:mtd> | |
153 | </mml:mtr> | |
154 | </mml:mtable> | |
155 | </mml:mfenced> | |
156 | </mml:math></div><p> | |
157 | </p></div><div class="refsect1" lang="en" xml:lang="en"><a id="notes"></a><h2>Notes</h2><p> | |
158 | Depth buffer precision is affected by the values specified for | |
159 | <em class="parameter"><code>zNear</code></em> and <em class="parameter"><code>zFar</code></em>. | |
160 | The greater the ratio of <em class="parameter"><code>zFar</code></em> to <em class="parameter"><code>zNear</code></em> is, | |
161 | the less effective the depth buffer will be at distinguishing between | |
162 | surfaces that are near each other. | |
163 | If | |
164 | </p><p> | |
165 | <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" overflow="scroll"> | |
166 | ||
167 | <mml:mrow> | |
168 | <mml:mi mathvariant="italic">r</mml:mi> | |
169 | <mml:mo>=</mml:mo> | |
170 | <mml:mfrac> | |
171 | <mml:mi mathvariant="italic">zFar</mml:mi> | |
172 | <mml:mi mathvariant="italic">zNear</mml:mi> | |
173 | </mml:mfrac> | |
174 | </mml:mrow> | |
175 | </mml:math> | |
176 | </p><p> | |
177 | </p><p> | |
178 | roughly | |
179 | <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" overflow="scroll"> | |
180 | ||
181 | <mml:mrow> | |
182 | <mml:msub><mml:mi mathvariant="italic">log</mml:mi> | |
183 | <mml:mn>2</mml:mn> | |
184 | </mml:msub> | |
185 | <mml:mo></mml:mo> | |
186 | <mml:mfenced open="(" close=")"> | |
187 | <mml:mi mathvariant="italic">r</mml:mi> | |
188 | </mml:mfenced> | |
189 | </mml:mrow> | |
190 | </mml:math> | |
191 | bits of depth buffer precision are lost. | |
192 | Because | |
193 | <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" overflow="scroll"><mml:mi mathvariant="italic">r</mml:mi></mml:math> | |
194 | approaches infinity as <em class="parameter"><code>zNear</code></em> approaches 0, | |
195 | <em class="parameter"><code>zNear</code></em> must never be set to 0. | |
196 | </p></div><div class="refsect1" lang="en" xml:lang="en"><a id="seealso"></a><h2>See Also</h2><p> | |
197 | <a class="citerefentry" href="gluOrtho2D.xml"><span class="citerefentry"><span class="refentrytitle">gluOrtho2D</span></span></a>, | |
198 | <a class="citerefentry" href="glFrustum.xml"><span class="citerefentry"><span class="refentrytitle">glFrustum</span></span></a>, | |
199 | <a class="citerefentry" href="glLoadIdentity.xml"><span class="citerefentry"><span class="refentrytitle">glLoadIdentity</span></span></a>, | |
200 | <a class="citerefentry" href="glMultMatrix.xml"><span class="citerefentry"><span class="refentrytitle">glMultMatrix</span></span></a> | |
201 | </p></div><div class="refsect1" lang="en" xml:lang="en"><a id="Copyright"></a><h2>Copyright</h2><p> | |
202 | Copyright <span class="trademark"></span>© 1991-2006 | |
203 | Silicon Graphics, Inc. This document is licensed under the SGI | |
204 | Free Software B License. For details, see | |
205 | <a class="ulink" href="http://oss.sgi.com/projects/FreeB/" target="_top">http://oss.sgi.com/projects/FreeB/</a>. | |
206 | </p></div></div></body></html> |