# Visual Basic > Games and Graphics Programming > Game Demos >  [VB6]102,168 Poly Teapot Example

## 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  :Wink:

----------


## dglienna

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.

----------


## penagate

I like  :Smilie: 

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.

----------


## dglienna

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

----------


## Jacob Roman

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

----------


## moeur

Very nice,

Get rid of this line from your Fast_Cos and Fast_Sin functions 

VB Code:
Theta = Theta Mod 360
Change to this
VB Code:
Public Function Fast_Cos(ByVal Theta As Single) As Single
     If Theta < 0 Then Theta = Theta + 360
     Dim Theta_Integer As Long
    Dim Theta_Fraction As Single
    
    Theta_Integer = Theta Mod 360
    Theta_Fraction = Theta - Int(Theta)
    
    Fast_Cos = Cos_Look_Up_Table(Theta_Integer) + Theta_Fraction * (Cos_Look_Up_Table(Theta_Integer + 1) - Cos_Look_Up_Table(Theta_Integer))
    
End Function

----------


## Jacob Roman

> Very nice,
> 
> Get rid of this line from your Fast_Cos and Fast_Sin functions 
> 
> VB Code:
> Theta = Theta Mod 360


Sorry bout that. It's done. I forgot that the mod operator automatically eliminated the decimals.   :Thumb:

----------


## moeur

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

----------


## Jacob Roman

Ok will do  :Thumb: 

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

----------


## moeur

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:
Public Function Fast_Cos(ByVal Theta As Single) As Single
     If Theta < 0 Then Theta = Theta + 360
    
    Dim Theta_Integer As Long
    Dim Theta_Fraction As Single
    
    'remove this checking, too slow
'    Theta_Integer = Theta Mod 360
     Theta_Integer = CLng(Theta)
    Theta_Fraction = Theta - Theta_Integer
   
    'Old function
    'Fast_Cos = Cos_Look_Up_Table(Theta_Integer) + Theta_Fraction * (Cos_Look_Up_Table(Theta_Integer + 1) - Cos_Look_Up_Table(Theta_Integer))
    
    'New function
    'cos(A+a) = Cos(A)*Cos(a) - Sin(A)*Sin(a)
    Fast_Cos = Cos_Look_Up_Table(Theta_Integer) - Sin_Look_Up_Table(Theta_Integer) * Theta_Fraction * DegToRad
    
End Function
 Public Function Fast_Sin(ByVal Theta As Single) As Single
     If Theta < 0 Then Theta = Theta + 360
     Dim Theta_Integer As Long
    Dim Theta_Fraction As Single
    
    'remove this checking, too slow
    'Theta_Integer = Theta Mod 360
    Theta_Integer = CLng(Theta)
    Theta_Fraction = Theta - Theta_Integer
    'old function
    'Fast_Sin = Sin_Look_Up_Table(Theta_Integer) + Theta_Fraction * (Sin_Look_Up_Table(Theta_Integer + 1) - Sin_Look_Up_Table(Theta_Integer))
     'New function
    'sin(A+a)= Sin(A)*Cos(a) + Cos(A)*Sin(a)
    Fast_Sin = Sin_Look_Up_Table(Theta_Integer) + Cos_Look_Up_Table(Theta_Integer) * Theta_Fraction * DegToRad
 End Function

----------


## Jacob Roman

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

----------


## NoteMe

> 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... :Wink:  So your statement doesn't hold...sorry JR... :Wink: 


- ØØ -

----------


## Jacob Roman

> 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  :Wink:

----------


## NoteMe

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.

----------

