Changeset 601

Show
Ignore:
Timestamp:
07/09/08 11:29:09 (4 months ago)
Author:
phill
Message:

o Fixed FOV thing.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/x42view.net/Gui/ModelWindow.Preview.cs

    r596 r601  
    140140 
    141141                                const float defFov = 45; 
    142                                 const float DegToRad = (float)(Math.PI / 180.0); 
    143  
    144                                 float fovX = defFov * Helpers.Clamp( Libx42.Math.Vector3.Length( tagMat.GetColumn( 0 ) ), 0.1F, 179.0F / defFov ); 
    145                                 float fovY = defFov * Helpers.Clamp( Libx42.Math.Vector3.Length( tagMat.GetColumn( 1 ) ), 0.1F, 179.0F / defFov ); 
    146  
    147                                 fovX *= DegToRad; 
    148                                 fovY *= DegToRad; 
    149  
    150                                 projection.M11 = 1.0F / ((float)Math.Tan( 0.5F * fovX ) * aspect); 
     142                         
     143                                float sx = Helpers.Clamp( Libx42.Math.Vector3.Length( tagMat.GetColumn( 0 ) ), 0.1F, 179.0F / defFov ); 
     144                                float sy = Helpers.Clamp( Libx42.Math.Vector3.Length( tagMat.GetColumn( 1 ) ), 0.1F, 179.0F / defFov ); 
     145 
     146                                float fovScale = (sx + sy) * 0.5F; 
     147 
     148                                float fovX, fovY; 
     149 
     150                                if( aspect < 1 ) 
     151                                { 
     152                                        fovX = Helpers.ToRadians( defFov * fovScale ); 
     153                                        fovY = 2 * (float)Math.Atan( Math.Tan( fovX * 0.5F ) / aspect ); 
     154                                } 
     155                                else 
     156                                { 
     157                                        fovY = Helpers.ToRadians( defFov * fovScale ); 
     158                                        fovX = 2 * (float)Math.Atan( Math.Tan( fovY * 0.5F ) * aspect ); 
     159                                } 
     160 
     161                                projection.M11 = 1.0F / (float)Math.Tan( 0.5F * fovX ); 
    151162                                projection.M12 = 0; 
    152163                                projection.M13 = 0; 
  • trunk/x42view.net/Helpers.cs

    r479 r601  
    234234                } 
    235235 
    236                 internal static string FormatFileSize( long p ) 
     236                public static string FormatFileSize( long p ) 
    237237                { 
    238238                        return string.Format( "{0:#,#} KB", (p + 1023) / 1024 ); 
    239239                } 
     240 
     241                public static float ToRadians( float degrees ) 
     242                { 
     243                        return degrees * (float)(Math.PI / 180.0); 
     244                } 
    240245        } 
    241246