Results 1 to 7 of 7

Thread: Increase the fps

  1. #1

    Increase the fps

    Hello everybody,
    I'm running to create a 3d soccer games like PES, then my question is:
    how to load the model and textures that the camera sees?
    ,and clear all model not seen by a camera .
    to increase the fps.
    thank you all

  2. #2

    Re: Increase the fps

    I don't think this is a good idea.
    From brazil (:

    Pascal pownz!

  3. #3

    Re: Increase the fps

    -I load all model in oncreat but in the game i want load the model and textures that the camera sees.
    -My problem I load all model my fps turn to 30 fps

  4. #4

    Re: Increase the fps

    You should load all data when the application starts and unload it when your app terminates. Loaded data doesn't hurt performance.

    However, you should limit the ammount of geometry you render every frame. Only draw object that are visible to the camera. You could use frustum culling for this.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  5. #5

    Re: Increase the fps

    I don't wanna discourage you, but making a game like PES is a very hard job. Believe, I've once had an attempt at it and it's really not an easy task. Having everything controlled by animation is the easiest way to go, but people will hate the game and still go for FIFA or PES.

    But if you still want an answer, here it is. I'm not sure if GLScene has any decent culling mechanism implemented, but the one I'd go for if I were you is, like chronozphere suggested, frustum culling. Here's the implementation I used (whoa, I didn't even know I had such an old code anywhere yet lol):
    Code:
    {
    
      ______       _     _____        _
      | ___ \      (_)    | ___|       (_)
      | |_/ / _ __ __ _ _ _ __ | |__ _ __  __ _ _ _ __  ___
      | ___ \| '__|/ _` || || '_ \ | __|| '_ \ / _` || || '_ \ / _ \
      | |_/ /| | | (_| || || | | || |___| | | || (_| || || | | || __/
      \____/ |_|  \__,_||_||_| |_|\____/|_| |_| \__, ||_||_| |_| \___|
                            __/ |
                            |___/
    
              Copyright © 2007-2008 Blue Crystal Studios.
                   All rights reserved.
                 www.bluecrystalstudios.com
    
      Redistribution and use in source and binary forms, with or without
      modification, are permitted provided that the following conditions are met:
    
      * Redistributions of source code must retain the above copyright notice,
       this list of conditions and the following disclaimer.
      * Redistributions in binary form must reproduce the above copyright notice,
       this list of conditions and the following disclaimer in the documentation
       and/or other materials provided with the distribution.
      * Neither the name of Blue Crystal Studios nor the names of its contributors
       may be used to endorse or promote products derived from this software
       without specific prior written permission.
    
      THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
      AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
      THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
      PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
      CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
      EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
      PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
      OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
      WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
      OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
      ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      
    }
    unit UFrustum;
    
    interface
    
    uses
     // -- Headers --
     dglOpenGL,
     // -- Base Units --
     GeometryBB, VectorGeometry;
    
    const
     Right = 0;
     Left = 1;
     Bottom = 2;
     Top = 3;
     Back = 4;
     Front = 5;
    
    type
     { .: TBrainFrustum :. }
     TBrainFrustum = class(TObject)
     private
      { Private declarations }
      FFrustum: array[0..5] of THmgPlane;
     public
      { Public declarations }
      procedure Calculate();
    
      function PointInFrustum(V: TAffineVector): Boolean;
      function SphereInFrustum(Sphere: TBSphere): Boolean;
      function BoxInFrustum(Box: TAABB): Boolean;
     end;
    
    implementation
    
    { TBrainFrustum }
    
    function TBrainFrustum.BoxInFrustum(Box: TAABB): Boolean;
    var
     I: Integer;
    begin
     Result := False;
    
     with Box do
      for I := 0 to 5 do
      begin
       if ((FFrustum[I][0] * min[0]) + (FFrustum[I][1] * min[1]) +
        (FFrustum[I][2] * min[2]) + FFrustum[I][3] > 0.0) then
        continue;
       if ((FFrustum[I][0] * max[0]) + (FFrustum[I][1] * min[1]) +
        (FFrustum[I][2] * min[2]) + FFrustum[I][3] > 0.0) then
        continue;
       if ((FFrustum[I][0] * min[0]) + (FFrustum[I][1] * max[1]) +
        (FFrustum[I][2] * min[2]) + FFrustum[I][3] > 0.0) then
        continue;
       if ((FFrustum[I][0] * max[0]) + (FFrustum[I][1] * max[1]) +
        (FFrustum[I][2] * min[2]) + FFrustum[I][3] > 0.0) then
        continue;
       if ((FFrustum[I][0] * min[0]) + (FFrustum[I][1] * min[1]) +
        (FFrustum[I][2] * max[2]) + FFrustum[I][3] > 0.0) then
        continue;
       if ((FFrustum[I][0] * max[0]) + (FFrustum[I][1] * min[1]) +
        (FFrustum[I][2] * max[2]) + FFrustum[I][3] > 0.0) then
        continue;
       if ((FFrustum[I][0] * min[0]) + (FFrustum[I][1] * max[1]) +
        (FFrustum[I][2] * max[2]) + FFrustum[I][3] > 0.0) then
        continue;
       if ((FFrustum[I][0] * max[0]) + (FFrustum[I][1] * max[1]) +
        (FFrustum[I][2] * max[2]) + FFrustum[I][3] > 0.0) then
        continue;
       exit;
      end;
     Result := True;
    end;
    
    procedure TBrainFrustum.Calculate;
    var
     ProjM, ModM, Clip: array[0..15] of Single;
    begin
     glGetFloatv(GL_PROJECTION_MATRIX, @ProjM);
     glGetFloatv(GL_MODELVIEW_MATRIX, @ModM);
    
     Clip[0] := ModM[0] * ProjM[0] + ModM[1] * ProjM[4] + ModM[2] * ProjM[8] +
      ModM[3] * ProjM[12];
     Clip[1] := ModM[0] * ProjM[1] + ModM[1] * ProjM[5] + ModM[2] * ProjM[9] +
      ModM[3] * ProjM[13];
     Clip[2] := ModM[0] * ProjM[2] + ModM[1] * ProjM[6] + ModM[2] * ProjM[10] +
      ModM[3] * ProjM[14];
     Clip[3] := ModM[0] * ProjM[3] + ModM[1] * ProjM[7] + ModM[2] * ProjM[11] +
      ModM[3] * ProjM[15];
     Clip[4] := ModM[4] * ProjM[0] + ModM[5] * ProjM[4] + ModM[6] * ProjM[8] +
      ModM[7] * ProjM[12];
     Clip[5] := ModM[4] * ProjM[1] + ModM[5] * ProjM[5] + ModM[6] * ProjM[9] +
      ModM[7] * ProjM[13];
     Clip[6] := ModM[4] * ProjM[2] + ModM[5] * ProjM[6] + ModM[6] * ProjM[10] +
      ModM[7] * ProjM[14];
     Clip[7] := ModM[4] * ProjM[3] + ModM[5] * ProjM[7] + ModM[6] * ProjM[11] +
      ModM[7] * ProjM[15];
     Clip[8] := ModM[8] * ProjM[0] + ModM[9] * ProjM[4] + ModM[10] * ProjM[8] +
      ModM[11] * ProjM[12];
     Clip[9] := ModM[8] * ProjM[1] + ModM[9] * ProjM[5] + ModM[10] * ProjM[9] +
      ModM[11] * ProjM[13];
     Clip[10] := ModM[8] * ProjM[2] + ModM[9] * ProjM[6] + ModM[10] * ProjM[10] +
      ModM[11] * ProjM[14];
     Clip[11] := ModM[8] * ProjM[3] + ModM[9] * ProjM[7] + ModM[10] * ProjM[11] +
      ModM[11] * ProjM[15];
     Clip[12] := ModM[12] * ProjM[0] + ModM[13] * ProjM[4] + ModM[14] * ProjM[8] +
      ModM[15] * ProjM[12];
     Clip[13] := ModM[12] * ProjM[1] + ModM[13] * ProjM[5] + ModM[14] * ProjM[9] +
      ModM[15] * ProjM[13];
     Clip[14] := ModM[12] * ProjM[2] + ModM[13] * ProjM[6] + ModM[14] * ProjM[10] +
      ModM[15] * ProjM[14];
     Clip[15] := ModM[12] * ProjM[3] + ModM[13] * ProjM[7] + ModM[14] * ProjM[11] +
      ModM[15] * ProjM[15];
    
     FFrustum[Right][0] := Clip[3] - Clip[0];
     FFrustum[Right][1] := Clip[7] - Clip[4];
     FFrustum[Right][2] := Clip[11] - Clip[8];
     FFrustum[Right][3] := Clip[15] - Clip[12];
     NormalizePlane(FFrustum[Right]);
    
     FFrustum[Left][0] := Clip[3] + Clip[0];
     FFrustum[Left][1] := Clip[7] + Clip[4];
     FFrustum[Left][2] := Clip[11] + Clip[8];
     FFrustum[Left][3] := Clip[15] + Clip[12];
     NormalizePlane(FFrustum[Left]);
    
     FFrustum[Bottom][0] := Clip[3] + Clip[1];
     FFrustum[Bottom][1] := Clip[7] + Clip[5];
     FFrustum[Bottom][2] := Clip[11] + Clip[9];
     FFrustum[Bottom][3] := Clip[15] + Clip[13];
     NormalizePlane(FFrustum[Bottom]);
    
     FFrustum[Top][0] := Clip[3] - Clip[1];
     FFrustum[Top][1] := Clip[7] - Clip[5];
     FFrustum[Top][2] := Clip[11] - Clip[9];
     FFrustum[Top][3] := Clip[15] - Clip[13];
     NormalizePlane(FFrustum[Top]);
    
     FFrustum[Back][0] := Clip[3] - Clip[2];
     FFrustum[Back][1] := Clip[7] - Clip[6];
     FFrustum[Back][2] := Clip[11] - Clip[10];
     FFrustum[Back][3] := Clip[15] - Clip[14];
     NormalizePlane(FFrustum[Back]);
    
     FFrustum[Front][0] := Clip[3] + Clip[2];
     FFrustum[Front][1] := Clip[7] + Clip[6];
     FFrustum[Front][2] := Clip[11] + Clip[10];
     FFrustum[Front][3] := Clip[15] + Clip[14];
     NormalizePlane(FFrustum[Front]);
    end;
    
    function TBrainFrustum.PointInFrustum(V: TAffineVector): Boolean;
    var
     I: Integer;
    begin
     Result := False;
     for I := 0 to 5 do
      if (FFrustum[I][0] * V[0] + FFrustum[I][1] * V[1] + FFrustum[I][2] * V[2] +
       FFrustum[I][3] <= 0.0) then
       exit;
     Result := True;
    end;
    
    function TBrainFrustum.SphereInFrustum(Sphere: TBSphere): Boolean;
    var
     I: Integer;
    begin
     Result := False;
     for I := 0 to 5 do
      if (FFrustum[I][0] * Sphere.Center[0] + FFrustum[I][1] * Sphere.Center[1] +
       FFrustum[I][2] * Sphere.Center[2] + FFrustum[I][3] <= -Sphere.Radius) then
       exit;
     Result := True;
    end;
    
    end.
    To use it, every object on the scene must have a bounding box calculated. Then you can use the BoxInFrustum function to check if a box is inside the viewing frustum. If it is, then it should be displayed. If it's not, hide it.

    Calculating the frustum should be done using the Calculate method every time a camera is updated (i.e. moved). It's no use calculating the frustum every frame, because there may be moments when camera is static and it's pointless to re-calculate it.

  6. #6

    Re: Increase the fps

    thank you Brainer I'll test the code

  7. #7

    Re: Increase the fps

    Just in case you had problems implementing it, here's an example: http://www.delphigl.de/files/frustumcull.zip
    It seems this is where I have the frustum code from.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •