/* * Get placement for a ray through a projected point. */ void CPerspectiveProjection3D::RayThroughPoint(const FLOAT3D &v3dViewPoint, CPlacement3D &plRay) const { // check that the projection object is prepared for projecting ASSERT(pr_Prepared); /* Assume z coordinate of -1 and calculate x and y for that. * These are in fact just the perspective formulae, solved for transformed point. * The result is a direction in viewer space. */ FLOAT3D v3dDirection; v3dDirection(1) = -(v3dViewPoint(1) - pr_ScreenCenter(1))/ppr_PerspectiveRatios(1); v3dDirection(2) = -(v3dViewPoint(2) - pr_ScreenCenter(2))/ppr_PerspectiveRatios(2); v3dDirection(3) = -1.0f; // back-rotate the ray to absolute space v3dDirection *= !pr_ViewerRotationMatrix; // normalize the ray v3dDirection.Normalize(); // now calculate the angles from the direction DirectionVectorToAngles(v3dDirection, plRay.pl_OrientationAngle); // position is same as viewer's plRay.pl_PositionVector = pr_vViewerPosition; }
bool pickTerrainSurface(TerrainVolume* terrainVolume, float startX, float startY, float startZ, float dirAndLengthX, float dirAndLengthY, float dirAndLengthZ, float* resultX, float* resultY, float* resultZ) { Vector3F v3dStart(startX, startY, startZ); Vector3F v3dDirection(dirAndLengthX, dirAndLengthY, dirAndLengthZ); //v3dDirection *= length; RaycastTestFunctor<MaterialSet> raycastTestFunctor; ::PolyVox::RaycastResult myResult = terrainRaycastWithDirection(dynamic_cast<TerrainVolume*>(terrainVolume)->_getPolyVoxVolume(), v3dStart, v3dDirection, raycastTestFunctor, 0.5f); if(myResult == ::PolyVox::RaycastResults::Interupted) { *resultX = raycastTestFunctor.mLastPos.getX(); *resultY = raycastTestFunctor.mLastPos.getY(); *resultZ = raycastTestFunctor.mLastPos.getZ(); return true; } return false; }