MCPcopy Create free account
hub / github.com/davideberly/GeometricTools / OnCameraMotion

Method OnCameraMotion

GTE/Graphics/Terrain.cpp:124–182  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

122}
123
124void Terrain::OnCameraMotion()
125{
126 // Get the camera location/direction in the model space of the terrain.
127 Vector4<float> worldEye = mCamera->GetPosition();
128#if defined(GTE_USE_VEC_MAT)
129 Vector4<float> modelEye = worldEye * worldTransform.Inverse();
130#else
131 Vector4<float> modelEye = worldTransform.Inverse() * worldEye;
132#endif
133
134 // Update the model-space origins of the terrain pages. Start the
135 // process by locating the page that contains the camera.
136 size_t newCameraCol = static_cast<size_t>(std::floor(modelEye[0] / mLength));
137 size_t newCameraRow = static_cast<size_t>(std::floor(modelEye[1] / mLength));
138 if (newCameraCol != mCameraCol || newCameraRow != mCameraRow)
139 {
140 mCameraCol = newCameraCol;
141 mCameraRow = newCameraRow;
142
143 // Translate page origins for toroidal wraparound.
144 int32_t cminO = static_cast<int32_t>(mCameraCol) - static_cast<int32_t>(mNumCols / 2);
145 int32_t cminP = (cminO + static_cast<int32_t>(mNumCols)) % static_cast<int32_t>(mNumCols);
146 int32_t rminO = static_cast<int32_t>(mCameraRow) - static_cast<int32_t>(mNumRows / 2);
147 int32_t rminP = (rminO + static_cast<int32_t>(mNumRows)) % static_cast<int32_t>(mNumRows);
148
149 int32_t rO = rminO, rP = rminP;
150 for (size_t row = 0; row < mNumRows; ++row)
151 {
152 int32_t cO = cminO, cP = cminP;
153 for (size_t col = 0; col < mNumCols; ++col)
154 {
155 auto const& child = mChild[cP + mNumCols * rP];
156 auto page = std::dynamic_pointer_cast<Page>(child);
157 Vector2<float> oldOrigin = page->GetOrigin();
158 Vector2<float> newOrigin{ cO * mLength, rO * mLength };
159 Vector3<float> pageTrn
160 {
161 newOrigin[0] - oldOrigin[0],
162 newOrigin[1] - oldOrigin[1],
163 page->localTransform.GetTranslation()[2]
164 };
165 page->localTransform.SetTranslation(pageTrn);
166
167 ++cO;
168 if (++cP == static_cast<int32_t>(mNumCols))
169 {
170 cP = 0;
171 }
172 }
173
174 ++rO;
175 if (++rP == static_cast<int32_t>(mNumRows))
176 {
177 rP = 0;
178 }
179 }
180 Update();
181 }

Callers 1

UpdateSceneMethod · 0.80

Calls 5

InverseMethod · 0.80
SetTranslationMethod · 0.80
floorFunction · 0.50
GetPositionMethod · 0.45
GetTranslationMethod · 0.45

Tested by

no test coverage detected