Tweek the stereo settings: allow negative eye separation.
authorKester Maddock <Christopher.Maddock.1@uni.massey.ac.nz>
Sun, 24 Oct 2004 23:50:44 +0000 (23:50 +0000)
committerKester Maddock <Christopher.Maddock.1@uni.massey.ac.nz>
Sun, 24 Oct 2004 23:50:44 +0000 (23:50 +0000)
source/gameengine/PyDoc/Rasterizer.py
source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h

index 78be4b4804f18e12ab44f620f7e6a285dec9d7b2..f0e48b6ed43a573d4fa64fb17baa78c1ca76e366 100644 (file)
@@ -121,8 +121,6 @@ def setEyeSeparation(eyesep):
        Sets the eye separation for stereo mode.
        
        @param eyesep: The distance between the left and right eye.
-               If eyesep < 0.0, eye separation will be automatically determined from the projection
-               matrix.
        @type eyesep: float
        """
 
@@ -130,9 +128,6 @@ def getEyeSeparation():
        """
        Gets the current eye separation for stereo mode.
        
-       If the returned eye separation is < 0.0, the eye separation will be
-       automatically set on the next frame.
-       
        @rtype: float
        """
        
@@ -140,8 +135,7 @@ def setFocalLength(focallength):
        """
        Sets the focal length for stereo mode.
        
-       @param focallength: The focal length.  If focallength < 0.0, the focal length will
-               be automatically determined.
+       @param focallength: The focal length.  
        @type focallength: float
        """
 
@@ -149,8 +143,5 @@ def getFocalLength():
        """
        Gets the current focal length for stereo mode.
        
-       If the returned focal length is < 0.0, the focal length will be
-       automatically set on the next frame.
-       
        @rtype: float
        """
index 803ccbc2b63cc47d31ae7baa855e58e56037fb1e..78666b6936d59700e840a354d7ba6f27001733ab 100644 (file)
@@ -28,6 +28,9 @@
  *
  * ***** END GPL/BL DUAL LICENSE BLOCK *****
  */
+#include <math.h>
 #include "RAS_OpenGLRasterizer.h"
 
 #ifdef HAVE_CONFIG_H
 
 #include "RAS_GLExtensionManager.h"
 
+/**
+ *  32x32 bit masks for vinterlace stereo mode
+ */
+static GLuint left_eye_vinterlace_mask[32];
+static GLuint right_eye_vinterlace_mask[32];
+
+/**
+ *  32x32 bit masks for hinterlace stereo mode.
+ *  Left eye = &hinterlace_mask[0]
+ *  Right eye = &hinterlace_mask[1]
+ */
+static GLuint hinterlace_mask[33];
 
 RAS_OpenGLRasterizer::RAS_OpenGLRasterizer(RAS_ICanvas* canvas)
        :RAS_IRasterizer(canvas),
@@ -58,12 +73,22 @@ RAS_OpenGLRasterizer::RAS_OpenGLRasterizer(RAS_ICanvas* canvas)
        m_time(0.0),
        m_stereomode(RAS_STEREO_NOSTEREO),
        m_curreye(RAS_STEREO_LEFTEYE),
-       m_eyeseparation(-1.0f),
-       m_focallength(-1.0f),
+       m_eyeseparation(0.0),
+       m_seteyesep(false),
+       m_focallength(0.0),
+       m_setfocallength(false),
        m_noOfScanlines(32),
        m_materialCachingInfo(0)
 {
        m_viewmatrix.Identity();
+       
+       for (int i = 0; i < 32; i++)
+       {
+               left_eye_vinterlace_mask[i] = 0x55555555;
+               right_eye_vinterlace_mask[i] = 0xAAAAAAAA;
+               hinterlace_mask[i] = (i&1)*0xFFFFFFFF;
+       }
+       hinterlace_mask[32] = 0;
 }
 
 
@@ -461,8 +486,6 @@ void RAS_OpenGLRasterizer::SetEye(StereoEye eye)
                        if (m_curreye == RAS_STEREO_LEFTEYE)
                        {
                                glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_FALSE);
-                               m_2DCanvas->ClearBuffer(RAS_ICanvas::COLOR_BUFFER);
-                               glColorMask(GL_FALSE, GL_FALSE, GL_TRUE, GL_FALSE);
                        } else {
                                //glAccum(GL_LOAD, 1.0);
                                glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE);
@@ -471,26 +494,16 @@ void RAS_OpenGLRasterizer::SetEye(StereoEye eye)
                        break;
                case RAS_STEREO_VINTERLACE:
                {
-                       GLuint pat[32];
-                       const unsigned char mask = 0x55;  // 01010101
-                       memset(pat, m_curreye == RAS_STEREO_RIGHTEYE?~mask:mask, sizeof(pat));
                        glEnable(GL_POLYGON_STIPPLE);
-                       glPolygonStipple((const GLubyte*) pat);
+                       glPolygonStipple((const GLubyte*) ((m_curreye == RAS_STEREO_LEFTEYE) ? left_eye_vinterlace_mask : right_eye_vinterlace_mask));
                        if (m_curreye == RAS_STEREO_RIGHTEYE)
                                ClearDepthBuffer();
                        break;
                }
                case RAS_STEREO_INTERLACED:
                {
-                       GLuint pat[32];
-                       GLuint mask = m_curreye == RAS_STEREO_LEFTEYE?~0:0;
-                       for (int y = 0; y < 32; y+=2)
-                       {
-                               pat[y] = mask;
-                               pat[y+1] = ~mask;
-                       }
                        glEnable(GL_POLYGON_STIPPLE);
-                       glPolygonStipple((const GLubyte*) pat);
+                       glPolygonStipple((const GLubyte*) &hinterlace_mask[m_curreye == RAS_STEREO_LEFTEYE?0:1]);
                        if (m_curreye == RAS_STEREO_RIGHTEYE)
                                ClearDepthBuffer();
                        break;
@@ -509,6 +522,7 @@ RAS_IRasterizer::StereoEye RAS_OpenGLRasterizer::GetEye()
 void RAS_OpenGLRasterizer::SetEyeSeparation(float eyeseparation)
 {
        m_eyeseparation = eyeseparation;
+       m_seteyesep = true;
 }
 
 float RAS_OpenGLRasterizer::GetEyeSeparation()
@@ -519,6 +533,7 @@ float RAS_OpenGLRasterizer::GetEyeSeparation()
 void RAS_OpenGLRasterizer::SetFocalLength(float focallength)
 {
        m_focallength = focallength;
+       m_setfocallength = true;
 }
 
 float RAS_OpenGLRasterizer::GetFocalLength()
@@ -1159,9 +1174,9 @@ MT_Matrix4x4 RAS_OpenGLRasterizer::GetFrustumMatrix(
        {
                        float near_div_focallength;
                        // next 2 params should be specified on command line and in Blender publisher
-                       if (m_focallength < 0.0f)
+                       if (!m_setfocallength)
                                m_focallength = 1.5 * right;  // derived from example
-                       if (m_eyeseparation < 0.0f)
+                       if (!m_seteyesep)
                                m_eyeseparation = 0.18 * right;  // just a guess...
 
                        near_div_focallength = frustnear / m_focallength;
index 9ab7b772cf9fdb4dbea7bb6f82b98277bce90137..d5a0e7ff5515d21ee9c68249d038763de9d9bf50 100644 (file)
@@ -72,7 +72,9 @@ class RAS_OpenGLRasterizer : public RAS_IRasterizer
        StereoMode              m_stereomode;
        StereoEye               m_curreye;
        float                   m_eyeseparation;
+       bool                    m_seteyesep;
        float                   m_focallength;
+       bool                    m_setfocallength;
        int                             m_noOfScanlines;
        
        bool                    InterlacedStereo() const;