Stereo.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. #include "stdh.h"
  13. #include <Engine/Graphics/Stereo.h>
  14. #include <Engine/Math/Projection.h>
  15. #include <Engine/Graphics/GfxLibrary.h>
  16. #include <Engine/Graphics/ViewPort.h>
  17. #include <Engine/Graphics/Gfx_wrapper.h>
  18. extern INDEX gfx_iStereo;
  19. extern INDEX gfx_bStereoInvert;
  20. extern INDEX gfx_iStereoOffset;
  21. extern FLOAT gfx_fStereoSeparation;
  22. // query whether user has turned stereo rendering on
  23. BOOL Stereo_IsEnabled(void)
  24. {
  25. return gfx_iStereo!=0;
  26. }
  27. // set buffer for stereo rendering left/right/nostereo
  28. void Stereo_SetBuffer(INDEX iEye)
  29. {
  30. if( gfx_bStereoInvert) gfx_bStereoInvert = 1;
  31. const ULONG ulLeftMask = gfx_bStereoInvert ? CT_BMASK|CT_GMASK : CT_RMASK;
  32. const ULONG ulRightMask = gfx_bStereoInvert ? CT_RMASK : CT_BMASK|CT_GMASK;
  33. if( iEye==STEREO_BOTH || gfx_iStereo==0) {
  34. gfxSetColorMask(CT_RMASK|CT_GMASK|CT_BMASK|CT_AMASK);
  35. } else if (iEye==STEREO_LEFT) {
  36. gfxSetColorMask(ulLeftMask);
  37. } else if (iEye==STEREO_RIGHT) {
  38. gfxSetColorMask(ulRightMask);
  39. }
  40. }
  41. // adjust perspective projection stereo rendering left/right/nostereo
  42. void Stereo_AdjustProjection(CProjection3D &pr, INDEX iEye, FLOAT fFactor)
  43. {
  44. // prepare and clamp
  45. CPerspectiveProjection3D &ppr = (CPerspectiveProjection3D &)pr;
  46. gfx_fStereoSeparation = Clamp( gfx_fStereoSeparation, 0.01f, 1.0f);
  47. gfx_iStereoOffset = Clamp( gfx_iStereoOffset, -100L, +100L);
  48. // apply!
  49. if (iEye==STEREO_BOTH || gfx_iStereo==0) {
  50. NOTHING;
  51. } else if (iEye==STEREO_LEFT) {
  52. pr.ViewerPlacementL().Translate_OwnSystem( FLOAT3D(-gfx_fStereoSeparation*fFactor/2,0,0) );
  53. ppr.ppr_boxSubScreen = ppr.pr_ScreenBBox;
  54. ppr.ppr_boxSubScreen -= FLOAT2D(-gfx_iStereoOffset/2.0f, 0.0f);
  55. } else if (iEye==STEREO_RIGHT) {
  56. pr.ViewerPlacementL().Translate_OwnSystem( FLOAT3D(+gfx_fStereoSeparation*fFactor/2,0,0) );
  57. ppr.ppr_boxSubScreen = ppr.pr_ScreenBBox;
  58. ppr.ppr_boxSubScreen -= FLOAT2D(+gfx_iStereoOffset/2.0f, 0.0f);
  59. }
  60. }