Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21136

Infinity Issues

$
0
0
I'm working with Infinity to use in my Sweep AABB collision detection. How I implemented infinity was simple:

vb Code:
  1. Public INFINITY As Double
  2.  
  3. Public Sub Initialize_Infinity()
  4.   On Error Resume Next
  5.   INFINITY = 1 / 0
  6. End Sub

Problem is, is that I can multiply regular numbers to INFINITY, but if I multiply a variable to it, I get an overflow. So for example, since there is no movement, Collision_Time equals -INFINITY, as in negative infinity:

vb Code:
  1. Public Sub Collision_Response()
  2.     Dim Velocity As D3DVECTOR2
  3.     Dim Result As Single
  4.     Dim Collision_Time As Single
  5.    
  6.     Collision_Time = Sweep_Collision_Detection(P1, Puck)
  7.     Velocity = Vector_Subtract(P1.Position, P1.Old_Position)
  8.     Result = Velocity.X * Collision_Time
  9. End Sub

The line that has Result = Velocity.X * Collision_Time got the overflow. Which doesnt make sense because Infinity * 0 = 0. I do not wanna use error checking as it will slow down this sub, and I plan on using 100s of objects to check for collision, so that slowdown will add up. Is there any way I can work with a variable that has Infinity for simple multiplication? Thanks in advance.

Viewing all articles
Browse latest Browse all 21136

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>