- Timestamp:
- 08/11/11 00:45:55 (13 years ago)
- Location:
- ps/trunk/source/graphics
- Files:
-
- 2 edited
-
Camera.cpp (modified) (2 diffs)
-
Camera.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
ps/trunk/source/graphics/Camera.cpp
r9814 r9988 287 287 } 288 288 289 CVector3D CCamera::GetFocus() 289 CVector3D CCamera::GetFocus() const 290 290 { 291 291 // Basically the same as GetWorldCoordinates … … 294 294 int x, z; 295 295 296 CVector3D origin, dir, delta, currentTarget;296 CVector3D origin, dir, delta, terrainPoint, waterPoint; 297 297 298 298 origin = m_Orientation.GetTranslation(); 299 299 dir = m_Orientation.GetIn(); 300 300 301 if (tracer.RayIntersect(origin, dir, x, z, currentTarget)) 302 return (currentTarget); 303 304 // Off the edge of the world? 305 // Work out where it /would/ hit, if the map were extended out to infinity with average height. 306 307 return (origin + dir * ((50.0f - origin.Y) / dir.Y)); 301 bool gotTerrain = tracer.RayIntersect(origin, dir, x, z, terrainPoint); 302 303 CPlane plane; 304 plane.Set(CVector3D(0.f, 1.f, 0.f), // upwards normal 305 CVector3D(0.f, g_Renderer.GetWaterManager()->m_WaterHeight, 0.f)); // passes through water plane 306 307 bool gotWater = plane.FindRayIntersection( origin, dir, &waterPoint ); 308 309 // Clamp the water intersection to within the map's bounds, so that 310 // we'll always return a valid position on the map 311 ssize_t mapSize = g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide(); 312 if (gotWater) 313 { 314 waterPoint.X = clamp(waterPoint.X, 0.f, (float)((mapSize-1)*CELL_SIZE)); 315 waterPoint.Z = clamp(waterPoint.Z, 0.f, (float)((mapSize-1)*CELL_SIZE)); 316 } 317 318 if (gotTerrain) 319 { 320 if (gotWater) 321 { 322 // Intersecting both heightmap and water plane; choose the closest of those 323 if ((origin - terrainPoint).LengthSquared() < (origin - waterPoint).LengthSquared()) 324 return terrainPoint; 325 else 326 return waterPoint; 327 } 328 else 329 { 330 // Intersecting heightmap but parallel to water plane 331 return terrainPoint; 332 } 333 } 334 else 335 { 336 if (gotWater) 337 { 338 // Only intersecting water plane 339 return waterPoint; 340 } 341 else 342 { 343 // Not intersecting terrain or water; just return 0,0,0. 344 return CVector3D(0.f, 0.f, 0.f); 345 } 346 } 308 347 } 309 348 -
ps/trunk/source/graphics/Camera.h
r9814 r9988 88 88 // Get the point on the plane at height h corresponding to pixel (px,py) 89 89 CVector3D GetWorldCoordinates(int px, int py, float h) const; 90 // Get the point on the terrain the camera is pointing towards91 CVector3D GetFocus() ;90 // Get the point on the terrain (or water plane) the camera is pointing towards 91 CVector3D GetFocus() const; 92 92 93 93 // Build an orientation matrix from camera position, camera focus point, and up-vector
Note:
See TracChangeset
for help on using the changeset viewer.
