Revision: 19929
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19929
Author:   ben2610
Date:     2009-04-26 14:23:30 +0200 (Sun, 26 Apr 2009)

Log Message:
-----------
BGE: Fix Orthographic mode and viewport scaling

- the BGE now uses correct glOrtho projection whe camera is in orthographic mode
- 

Modified Paths:
--------------
    trunk/blender/projectfiles_vc9/gameengine/gameplayer/ghost/GP_ghost.vcproj
    trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp
    trunk/blender/source/gameengine/Ketsji/KX_Camera.cpp
    trunk/blender/source/gameengine/Ketsji/KX_Camera.h
    trunk/blender/source/gameengine/Ketsji/KX_Dome.cpp
    trunk/blender/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
    trunk/blender/source/gameengine/Ketsji/KX_Light.cpp
    trunk/blender/source/gameengine/Rasterizer/RAS_CameraData.h
    trunk/blender/source/gameengine/Rasterizer/RAS_FramingManager.cpp
    trunk/blender/source/gameengine/Rasterizer/RAS_FramingManager.h
    trunk/blender/source/gameengine/Rasterizer/RAS_IRasterizer.h
    
trunk/blender/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
    
trunk/blender/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h
    trunk/blender/source/gameengine/VideoTexture/ImageRender.cpp

Modified: 
trunk/blender/projectfiles_vc9/gameengine/gameplayer/ghost/GP_ghost.vcproj
===================================================================
--- trunk/blender/projectfiles_vc9/gameengine/gameplayer/ghost/GP_ghost.vcproj  
2009-04-26 09:41:39 UTC (rev 19928)
+++ trunk/blender/projectfiles_vc9/gameengine/gameplayer/ghost/GP_ghost.vcproj  
2009-04-26 12:23:30 UTC (rev 19929)
@@ -166,12 +166,13 @@
                        <Tool
                                Name="VCLinkerTool"
                                AdditionalOptions="/MACHINE:I386"
-                               AdditionalDependencies="odelib.lib fmodvc.lib 
ws2_32.lib vfw32.lib odbc32.lib odbccp32.lib opengl32.lib glu32.lib 
openal_static.lib libjpeg.lib dxguid.lib libeay32.lib libpng.lib libz.lib 
qtmlClient.lib SDL.lib freetype2ST.lib python25.lib pthreadVSE2.lib 
pthreadVC2.lib Half.lib Iex.lib IlmImf.lib IlmThread.lib Imath.lib 
avcodec-52.lib avformat-52.lib avutil-50.lib swscale-0.lib avdevice-52.lib"
+                               AdditionalDependencies="odelib.lib ws2_32.lib 
vfw32.lib odbc32.lib odbccp32.lib opengl32.lib glu32.lib openal_static.lib 
libjpeg.lib dxguid.lib libeay32.lib libpng.lib libz.lib qtmlClient.lib SDL.lib 
freetype2ST.lib python25.lib pthreadVSE2.lib pthreadVC2.lib Half.lib Iex.lib 
IlmImf.lib IlmThread.lib Imath.lib avcodec-52.lib avformat-52.lib avutil-50.lib 
swscale-0.lib avdevice-52.lib"
                                OutputFile="..\..\..\..\bin\blenderplayer.exe"
                                LinkIncremental="1"
                                SuppressStartupBanner="true"
                                
AdditionalLibraryDirectories="..\..\..\..\..\lib\windows\sdl\lib;..\..\..\..\..\lib\windows\zlib\lib;..\..\..\..\..\lib\windows\ode\lib;..\..\..\..\..\lib\windows\png\lib;..\..\..\..\..\lib\windows\jpeg\lib;..\..\..\..\..\lib\windows\fmod\lib;..\..\..\..\..\lib\windows\openal\lib;..\..\..\..\..\lib\windows\freetype\lib;..\..\..\..\..\lib\windows\openexr\lib_vs2008;..\..\..\..\..\lib\windows\python\lib\lib25_vs2008;..\..\..\..\..\lib\windows\openssl\lib;..\..\..\..\..\lib\windows\QTDevWin\Libraries;..\..\..\..\..\lib\windows\pthreads\lib;..\..\..\..\..\lib\windows\ffmpeg\lib"
                                IgnoreDefaultLibraryNames="libc.lib, 
msvcrt.lib, libcd.lib, libcmtd.lib, msvcrtd.lib"
+                               GenerateDebugInformation="true"
                                
ProgramDatabaseFile="..\..\..\..\..\build\msvc_9\libs\blenderplayer.pdb"
                                SubSystem="1"
                                RandomizedBaseAddress="1"

Modified: trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp      
2009-04-26 09:41:39 UTC (rev 19928)
+++ trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp      
2009-04-26 12:23:30 UTC (rev 19929)
@@ -1620,7 +1620,7 @@
 
 static KX_Camera *gamecamera_from_bcamera(Object *ob, KX_Scene *kxscene, 
KX_BlenderSceneConverter *converter) {
        Camera* ca = static_cast<Camera*>(ob->data);
-       RAS_CameraData camdata(ca->lens, ca->clipsta, ca->clipend, ca->type == 
CAM_PERSP, dof_camera(ob));
+       RAS_CameraData camdata(ca->lens, ca->ortho_scale, ca->clipsta, 
ca->clipend, ca->type == CAM_PERSP, dof_camera(ob));
        KX_Camera *gamecamera;
        
        gamecamera= new KX_Camera(kxscene, KX_Scene::m_callbacks, camdata);

Modified: trunk/blender/source/gameengine/Ketsji/KX_Camera.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_Camera.cpp        2009-04-26 
09:41:39 UTC (rev 19928)
+++ trunk/blender/source/gameengine/Ketsji/KX_Camera.cpp        2009-04-26 
12:23:30 UTC (rev 19929)
@@ -47,7 +47,7 @@
                                        m_camdata(camdata),
                                        m_dirty(true),
                                        m_normalized(false),
-                                       m_frustum_culling(frustum_culling && 
camdata.m_perspective),
+                                       m_frustum_culling(frustum_culling),
                                        m_set_projection_matrix(false),
                                        m_set_frustum_center(false)
 {
@@ -184,8 +184,13 @@
        return m_camdata.m_lens;
 }
 
+float KX_Camera::GetScale() const
+{
+       return m_camdata.m_scale;
+}
 
 
+
 float KX_Camera::GetCameraNear() const
 {
        return m_camdata.m_clipstart;
@@ -264,80 +269,83 @@
        MT_Matrix4x4 clip_camcs_matrix = m_projection_matrix;
        clip_camcs_matrix.invert();
 
-    // detect which of the corner of the far clipping plane is the farthest to 
the origin
-       MT_Vector4 nfar;    // far point in device normalized coordinate
-    MT_Point3 farpoint; // most extreme far point in camera coordinate
-    MT_Point3 nearpoint;// most extreme near point in camera coordinate
-    MT_Point3 farcenter(0.,0.,0.);// center of far cliping plane in camera 
coordinate
-    MT_Scalar F=1.0, N; // square distance of far and near point to origin
-    MT_Scalar f, n;     // distance of far and near point to z axis. f is 
always > 0 but n can be < 0
-    MT_Scalar e, s;     // far and near clipping distance (<0)
-    MT_Scalar c;        // slope of center line = distance of far clipping 
center to z axis / far clipping distance
-    MT_Scalar z;        // projection of sphere center on z axis (<0)
-    // tmp value
-    MT_Vector4 npoint(1., 1., 1., 1.);
-    MT_Vector4 hpoint;
-    MT_Point3 point;
-    MT_Scalar len;
-    for (int i=0; i<4; i++)
-    {
-       hpoint = clip_camcs_matrix*npoint;
-        point.setValue(hpoint[0]/hpoint[3], hpoint[1]/hpoint[3], 
hpoint[2]/hpoint[3]);
-        len = point.dot(point);
-        if (len > F)
-        {
-            nfar = npoint;
-            farpoint = point;
-            F = len;
-        }
-        // rotate by 90 degree along the z axis to walk through the 4 extreme 
points of the far clipping plane
-        len = npoint[0];
-        npoint[0] = -npoint[1];
-        npoint[1] = len;
-        farcenter += point;
-    }
-    // the far center is the average of the far clipping points
-    farcenter *= 0.25;
-    // the extreme near point is the opposite point on the near clipping plane
-    nfar.setValue(-nfar[0], -nfar[1], -1., 1.);
-       nfar = clip_camcs_matrix*nfar;
-    nearpoint.setValue(nfar[0]/nfar[3], nfar[1]/nfar[3], nfar[2]/nfar[3]);
-    N = nearpoint.dot(nearpoint);
-    e = farpoint[2];
-    s = nearpoint[2];
-    // projection on XY plane for distance to axis computation
-    MT_Point2 farxy(farpoint[0], farpoint[1]);
-    // f is forced positive by construction
-    f = farxy.length();
-    // get corresponding point on the near plane
-    farxy *= s/e;
-    // this formula preserve the sign of n
-    n = f*s/e - MT_Point2(nearpoint[0]-farxy[0], 
nearpoint[1]-farxy[1]).length();
-    c = MT_Point2(farcenter[0], farcenter[1]).length()/e;
-    // the big formula, it simplifies to (F-N)/(2(e-s)) for the symmetric case
-    z = (F-N)/(2.0*(e-s+c*(f-n)));
-       m_frustum_center = MT_Point3(farcenter[0]*z/e, farcenter[1]*z/e, z);
-       m_frustum_radius = m_frustum_center.distance(farpoint);
-
-#if 0
-       // The most extreme points on the near and far plane. (normalized 
device coords)
-       MT_Vector4 hnear(1., 1., 0., 1.), hfar(1., 1., 1., 1.);
-       
-       // Transform to hom camera local space
-       hnear = clip_camcs_matrix*hnear;
-       hfar = clip_camcs_matrix*hfar;
-       
-       // Tranform to 3d camera local space.
-       MT_Point3 nearpoint(hnear[0]/hnear[3], hnear[1]/hnear[3], 
hnear[2]/hnear[3]);
-       MT_Point3 farpoint(hfar[0]/hfar[3], hfar[1]/hfar[3], hfar[2]/hfar[3]);
-       
-       // Compute center
-    // don't use camera data in case the user specifies the matrix directly
-       m_frustum_center = MT_Point3(0., 0.,
-               (nearpoint.dot(nearpoint) - 
farpoint.dot(farpoint))/(2.0*(nearpoint[2]-farpoint[2] /*m_camdata.m_clipend - 
m_camdata.m_clipstart*/)));
-       m_frustum_radius = m_frustum_center.distance(farpoint);
-#endif
-
+       if (m_projection_matrix[3][3] == MT_Scalar(0.0)) 
+       {
+               // frustrum projection
+               // detect which of the corner of the far clipping plane is the 
farthest to the origin
+               MT_Vector4 nfar;    // far point in device normalized coordinate
+               MT_Point3 farpoint; // most extreme far point in camera 
coordinate
+               MT_Point3 nearpoint;// most extreme near point in camera 
coordinate
+               MT_Point3 farcenter(0.,0.,0.);// center of far cliping plane in 
camera coordinate
+               MT_Scalar F=-1.0, N; // square distance of far and near point 
to origin
+               MT_Scalar f, n;     // distance of far and near point to z 
axis. f is always > 0 but n can be < 0
+               MT_Scalar e, s;     // far and near clipping distance (<0)
+               MT_Scalar c;        // slope of center line = distance of far 
clipping center to z axis / far clipping distance
+               MT_Scalar z;        // projection of sphere center on z axis 
(<0)
+               // tmp value
+               MT_Vector4 npoint(1., 1., 1., 1.);
+               MT_Vector4 hpoint;
+               MT_Point3 point;
+               MT_Scalar len;
+               for (int i=0; i<4; i++)
+               {
+               hpoint = clip_camcs_matrix*npoint;
+                       point.setValue(hpoint[0]/hpoint[3], 
hpoint[1]/hpoint[3], hpoint[2]/hpoint[3]);
+                       len = point.dot(point);
+                       if (len > F)
+                       {
+                               nfar = npoint;
+                               farpoint = point;
+                               F = len;
+                       }
+                       // rotate by 90 degree along the z axis to walk through 
the 4 extreme points of the far clipping plane
+                       len = npoint[0];
+                       npoint[0] = -npoint[1];
+                       npoint[1] = len;
+                       farcenter += point;
+               }
+               // the far center is the average of the far clipping points
+               farcenter *= 0.25;
+               // the extreme near point is the opposite point on the near 
clipping plane
+               nfar.setValue(-nfar[0], -nfar[1], -1., 1.);
+               nfar = clip_camcs_matrix*nfar;
+               nearpoint.setValue(nfar[0]/nfar[3], nfar[1]/nfar[3], 
nfar[2]/nfar[3]);
+               // this is a frustrum projection
+               N = nearpoint.dot(nearpoint);
+               e = farpoint[2];
+               s = nearpoint[2];
+               // projection on XY plane for distance to axis computation
+               MT_Point2 farxy(farpoint[0], farpoint[1]);
+               // f is forced positive by construction
+               f = farxy.length();
+               // get corresponding point on the near plane
+               farxy *= s/e;
+               // this formula preserve the sign of n
+               n = f*s/e - MT_Point2(nearpoint[0]-farxy[0], 
nearpoint[1]-farxy[1]).length();
+               c = MT_Point2(farcenter[0], farcenter[1]).length()/e;
+               // the big formula, it simplifies to (F-N)/(2(e-s)) for the 
symmetric case
+               z = (F-N)/(2.0*(e-s+c*(f-n)));
+               m_frustum_center = MT_Point3(farcenter[0]*z/e, 
farcenter[1]*z/e, z);
+               m_frustum_radius = m_frustum_center.distance(farpoint);
+       } 
+       else
+       {
+               // orthographic projection
+               // The most extreme points on the near and far plane. 
(normalized device coords)
+               MT_Vector4 hnear(1., 1., 1., 1.), hfar(-1., -1., -1., 1.);
+               
+               // Transform to hom camera local space
+               hnear = clip_camcs_matrix*hnear;
+               hfar = clip_camcs_matrix*hfar;
+               
+               // Tranform to 3d camera local space.
+               MT_Point3 nearpoint(hnear[0]/hnear[3], hnear[1]/hnear[3], 
hnear[2]/hnear[3]);

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to