Results 1 to 14 of 14

Thread: [VB6]102,168 Poly Teapot Example

  1. #1

    Thread Starter
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    [VB6]102,168 Poly Teapot Example

    Who says VB is too slow for games? I just managed to pull off 102,168 polygons to be visible on the screen at once, not including the mouse cursor and skybox, and still managed to stick with realtime speed. It's faster in fullscreen mode. You can download the source code here where it says "Download my 3D Engine HERE"

    www.angelfire.com/fl5/memorydll/index.html

    Use the Numpad and Mouse to control the camera, F12 to Snapshot, and Esc to quit. Enjoy
    Attached Images Attached Images  

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: [VB6]102,168 Poly Teapot Example

    Nice, but you forgot an Error_Handler line in the UnLoad event. I added one, and it ran fine. You should really use Option Explicit.

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [VB6]102,168 Poly Teapot Example

    I like

    dglienna - he is using Option Explicit. It doesn't catch undefined labels. I think the issue there is using "Start with Full Compile", or turning off "Compile On Demand". That catches it.

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: [VB6]102,168 Poly Teapot Example

    I thought about that after I posted, and of course you are right.
    It was missing though.

  5. #5

    Thread Starter
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: [VB6]102,168 Poly Teapot Example

    Yeah my VB is set to where it automatically puts in Option Explicit.

  6. #6
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: [VB6]102,168 Poly Teapot Example

    Very nice,

    Get rid of this line from your Fast_Cos and Fast_Sin functions
    VB Code:
    1. Theta = Theta Mod 360
    Change to this
    VB Code:
    1. Public Function Fast_Cos(ByVal Theta As Single) As Single
    2.  
    3.     If Theta < 0 Then Theta = Theta + 360
    4.  
    5.     Dim Theta_Integer As Long
    6.     Dim Theta_Fraction As Single
    7.    
    8.     Theta_Integer = Theta Mod 360
    9.     Theta_Fraction = Theta - Int(Theta)
    10.    
    11.     Fast_Cos = Cos_Look_Up_Table(Theta_Integer) + Theta_Fraction * (Cos_Look_Up_Table(Theta_Integer + 1) - Cos_Look_Up_Table(Theta_Integer))
    12.    
    13. End Function
    Last edited by moeur; Nov 19th, 2005 at 02:02 PM.

  7. #7

    Thread Starter
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: [VB6]102,168 Poly Teapot Example

    Quote Originally Posted by moeur
    Very nice,

    Get rid of this line from your Fast_Cos and Fast_Sin functions
    VB Code:
    1. Theta = Theta Mod 360
    Sorry bout that. It's done. I forgot that the mod operator automatically eliminated the decimals.

  8. #8
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: [VB6]102,168 Poly Teapot Example

    Actually you still need a mod operator in case theta > 360 so change as I edited above.

  9. #9

    Thread Starter
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: [VB6]102,168 Poly Teapot Example

    Ok will do

    If you have any other suggestions and optimizations that I can make, let me know. Maybe we can push it even further.

  10. #10
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: [VB6]102,168 Poly Teapot Example

    Actually, the code you have for Fast_Sin and Fast_Cos runs more slowly than the intrinsic sin and cos functions. This is mainly because of the Mod statement.

    If you can insure that the angle never goes beyond +-359 then you can remove that statement. Here is a modified version that runs slightly faster than the intrinsic functions and faster than your original function with more accuracy.
    These formulas were derived from the following trig formulas
    cos(A+a) = Cos(A)*Cos(a) - Sin(A)*Sin(a)
    sin(A+a)= Sin(A)*Cos(a) + Cos(A)*Sin(a)
    Sin(a) = a - (a^3)/6 + (a^5)/720 - ... where a is in radians
    Cos(a) = 1 - (a^2)/2 + (a^4)/24 - ... where a is in radians
    VB Code:
    1. Public Function Fast_Cos(ByVal Theta As Single) As Single
    2.  
    3.     If Theta < 0 Then Theta = Theta + 360
    4.    
    5.     Dim Theta_Integer As Long
    6.     Dim Theta_Fraction As Single
    7.    
    8.     'remove this checking, too slow
    9. '    Theta_Integer = Theta Mod 360
    10.      Theta_Integer = CLng(Theta)
    11.     Theta_Fraction = Theta - Theta_Integer
    12.    
    13.     'Old function
    14.     'Fast_Cos = Cos_Look_Up_Table(Theta_Integer) + Theta_Fraction * (Cos_Look_Up_Table(Theta_Integer + 1) - Cos_Look_Up_Table(Theta_Integer))
    15.    
    16.     'New function
    17.     'cos(A+a) = Cos(A)*Cos(a) - Sin(A)*Sin(a)
    18.     Fast_Cos = Cos_Look_Up_Table(Theta_Integer) - Sin_Look_Up_Table(Theta_Integer) * Theta_Fraction * DegToRad
    19.    
    20. End Function
    21.  
    22. Public Function Fast_Sin(ByVal Theta As Single) As Single
    23.  
    24.     If Theta < 0 Then Theta = Theta + 360
    25.  
    26.     Dim Theta_Integer As Long
    27.     Dim Theta_Fraction As Single
    28.    
    29.     'remove this checking, too slow
    30.     'Theta_Integer = Theta Mod 360
    31.     Theta_Integer = CLng(Theta)
    32.     Theta_Fraction = Theta - Theta_Integer
    33.     'old function
    34.     'Fast_Sin = Sin_Look_Up_Table(Theta_Integer) + Theta_Fraction * (Sin_Look_Up_Table(Theta_Integer + 1) - Sin_Look_Up_Table(Theta_Integer))
    35.  
    36.     'New function
    37.     'sin(A+a)= Sin(A)*Cos(a) + Cos(A)*Sin(a)
    38.     Fast_Sin = Sin_Look_Up_Table(Theta_Integer) + Cos_Look_Up_Table(Theta_Integer) * Theta_Fraction * DegToRad
    39.  
    40. End Function

  11. #11

    Thread Starter
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: [VB6]102,168 Poly Teapot Example

    Thanks moeur, I'll give that a whirl when I get home.

  12. #12
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: [VB6]102,168 Poly Teapot Example

    Quote Originally Posted by Jacob Roman
    Who says VB is too slow for games? I just managed to pull off 102,168 polygons to be visible on the screen at once, not including the mouse cursor and skybox, and still managed to stick with realtime speed. It's faster in fullscreen mode. You can download the source code here where it says "Download my 3D Engine HERE"

    www.angelfire.com/fl5/memorydll/index.html

    Use the Numpad and Mouse to control the camera, F12 to Snapshot, and Esc to quit. Enjoy

    An example like this doesn't show ANYTHING about VBs speed. Since nearly ALL the processing for this sample is done on the GPU... So your statement doesn't hold...sorry JR...


    - ØØ -

  13. #13

    Thread Starter
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: [VB6]102,168 Poly Teapot Example

    Quote Originally Posted by NoteMe
    An example like this doesn't show ANYTHING about VBs speed. Since nearly ALL the processing for this sample is done on the GPU... So your statement doesn't hold...sorry JR...


    - ØØ -
    I'm just showing that it is possible to pull off commercial quality games with a 100,000-1,000,000 polygons on the screen at once in VB

  14. #14
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: [VB6]102,168 Poly Teapot Example

    But it has nothing to do with VB I tell you. It is like making NotePad in VB and say that VB is soooo fast, because it works...Your VB code in that example is executed about 1/300 of the time. The rest is used to push graphics over the Bus, and to do the actual rendering, which has nothing to do with VB.

Posting Permissions

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



Click Here to Expand Forum to Full Width