index.html (6209B)
1 <!DOCTYPE html> 2 <html lang="en-US"> 3 4 <head> 5 <meta http-equiv="X-Clacks-Overhead" content="GNU Terry Pratchett" /> 6 <meta charset="utf-8"> 7 <meta name="viewport" content="width=device-width, initial-scale=1.0" /> 8 <link rel="shortcut icon" href="https://electrosoup.com/favicon.png" /> 9 <title>Understanding Camera Look-At. | Electrosoup</title> 10 <meta name="title" content="Understanding Camera Look-At." /> 11 <meta name="description" content="Often times, we want to position the camera in our scene at a particular point, 12 such as the head of the character in a first-person shooter or the cockpit of a 13 plane in a flight simulator. We also want the camera to look in the direction 14 that the player is trying to move." /> 15 <meta name="author" content="" /> 16 <meta name="keywords" content="Graphics,Matrices,OpenGL," /> 17 18 19 20 21 22 23 24 <meta property="og:url" content="https://electrosoup.com/posts/look-at/"> 25 <meta property="og:site_name" content="Electrosoup"> 26 <meta property="og:title" content="Understanding Camera Look-At."> 27 <meta property="og:description" content="Often times, we want to position the camera in our scene at a particular point, such as the head of the character in a first-person shooter or the cockpit of a plane in a flight simulator. We also want the camera to look in the direction that the player is trying to move."> 28 <meta property="og:locale" content="en_US"> 29 <meta property="og:type" content="article"> 30 <meta property="article:section" content="posts"> 31 <meta property="article:published_time" content="2022-10-10T00:31:00-04:00"> 32 <meta property="article:modified_time" content="2022-10-10T00:31:00-04:00"> 33 <meta property="article:tag" content="Graphics"> 34 <meta property="article:tag" content="Matrices"> 35 <meta property="article:tag" content="OpenGL"> 36 37 38 39 40 <meta name="twitter:card" content="summary"> 41 <meta name="twitter:title" content="Understanding Camera Look-At."> 42 <meta name="twitter:description" content="Often times, we want to position the camera in our scene at a particular point, such as the head of the character in a first-person shooter or the cockpit of a plane in a flight simulator. We also want the camera to look in the direction that the player is trying to move."> 43 44 45 46 47 <meta itemprop="name" content="Understanding Camera Look-At."> 48 <meta itemprop="description" content="Often times, we want to position the camera in our scene at a particular point, such as the head of the character in a first-person shooter or the cockpit of a plane in a flight simulator. We also want the camera to look in the direction that the player is trying to move."> 49 <meta itemprop="datePublished" content="2022-10-10T00:31:00-04:00"> 50 <meta itemprop="dateModified" content="2022-10-10T00:31:00-04:00"> 51 <meta itemprop="wordCount" content="210"> 52 <meta itemprop="keywords" content="Graphics,Matrices,OpenGL"> 53 54 55 <link href="/herman.min.css" rel="stylesheet"> 56 57 58 59 60 61 62 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.css" integrity="sha384-nB0miv6/jRmo5UMMR1wu3Gz6NLsoTkbqJghGIsx//Rlm+ZU03BU6SQNC66uf4l5+" crossorigin="anonymous"> 63 <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.js" integrity="sha384-7zkQWkzuo3B5mTepMUcHkMB5jZaolc2xDwL6VFqjFALcbeS9Ggm/Yr2r3Dy4lfFg" crossorigin="anonymous"></script> 64 <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/contrib/auto-render.min.js" integrity="sha384-43gviWU0YVjaDtb/GhzOouOXtZMP/7XUzwPTstBeZFe/+rCMvRwr4yROQP43s0Xk" crossorigin="anonymous" 65 onload="renderMathInElement(document.body);"></script> 66 67 68 </head> 69 70 <body> 71 <header><a class="skip-link" href="#main-content">Skip to main content</a> 72 73 <nav> 74 <a href="/">Main</a> 75 76 <a href="/posts/">Posts</a> 77 78 <a href="https://git.electrosoup.com">Code</a> 79 80 <a href="https://christianermann.dev">Resume</a> 81 82 83 84 85 86 87 88 89 90 </nav> 91 </header> 92 <main id="main-content"> 93 94 <h1>Understanding Camera Look-At.</h1> 95 <p class="byline"> 96 97 <time datetime='2022-10-10' pubdate> 98 2022-10-10 99 </time> 100 101 </p> 102 103 <content> 104 <p>Often times, we want to position the camera in our scene at a particular point, 105 such as the head of the character in a first-person shooter or the cockpit of a 106 plane in a flight simulator. We also want the camera to look in the direction 107 that the player is trying to move.</p> 108 <p>To do this, we need to find the forward, right, and up vectors that correspond 109 to the desired view.</p> 110 <p>If we let $\vec{p}$ be the camera’s position and $\vec{t}$ be the position of 111 what we want to look at, the camera’s look direction is 112 $$\vec{l}=\vec{t}-\vec{p}\,.$$ 113 Conventionally, the camera looks down the negative forward axis so 114 $$\vec{f}=-\vec{l}\,.$$</p> 115 <p>In order to determine the right vector, we need a reference up direction, 116 $\vec{up}$ (which isn’t necessarily orthogonal to $\vec{f}$). This enables us 117 to calculate 118 $$\vec{r} = \vec{f} \times \vec{up}$$ 119 and 120 $$\vec{u} = \vec{r} \times \vec{f}\,.$$</p> 121 <p>Now we can use the camera position $\vec{p}$ and normalized forms of $\vec{f}$, 122 $\vec{r}$, and $\vec{u}$ to fill in our 123 <a href="/posts/view-matrix/">view matrix</a>:</p> 124 <p>$$ 125 V 126 = 127 \begin{bmatrix} 128 r_{x} & r_{y} & r_{z} & -(\vec{r} \cdot \vec{p}) \\ 129 u_{x} & u_{y} & u_{z} & -(\vec{u} \cdot \vec{p}) \\ 130 f_{x} & f_{y} & f_{z} & -(\vec{f} \cdot \vec{p}) \\ 131 0 & 0 & 0 & 1 132 \end{bmatrix} 133 $$</p> 134 135 </content> 136 <p> 137 138 <a class="blog-tags" href="/tags/graphics/">#graphics</a> 139 140 <a class="blog-tags" href="/tags/matrices/">#matrices</a> 141 142 <a class="blog-tags" href="/tags/opengl/">#opengl</a> 143 144 </p> 145 146 147 <p> 148 <a href='mailto:christianermann@gmail.com?subject=Reply%20to%20"Understanding%20Camera%20Look-At."'> 149 Reply to this post by email ↪ 150 </a> 151 </p> 152 153 154 155 </main> 156 <footer><footer> 157 158 <a href="https://git.electrosoup.com">Code</a>. 159 160 <a href="https://christianermann.dev">Resume</a>. 161 162 <a href='https://electrosoup.com/index.xml'>RSS</a>. 163 <p>Copyright © 2026 Christian Ermann. | Made with <a href="https://github.com/clente/hugo-bearcub">Bear Cub</a></p> 164 </footer> 165 </footer> 166 167 168 </body> 169 170 </html>