• Create Account

# DerekEhrman

Member Since 27 Sep 2006
Offline Last Active Oct 12 2012 01:17 PM

### In Topic: Ball to Circular Wall Interior Collision Response

31 July 2012 - 12:39 PM

First, I would store a radius instead of a diameter (why do the division constantly when what you really want is the radius? Just do the division once and you have the value to work from!).

Second, I would make the hole itself also have a radius member so you can remove what appear to be *magic numbers* (where is 17 from?). I know the radius is constant in this example, but it would be much cleaner and cooler to support any sized hole, right?

Now, your core collision detection is algorithm is doing more work than it needs to be (hypot uses the very expensive square root function) and is not an accurate representation of the object (I am assuming this is why you used the value 17 instead of the actual diameter value in your test?)

I think you can greatly simplify the algorithm to something more like:
* calculate the distance from the center of the hole to the center of the circle
* if this value is greater than or equal to the radius of the hole, we have a collision

### In Topic: error lnk1104

30 July 2012 - 09:22 AM

Just to be sure ... have you double-checked that you do indeed have the required lib on your machine in an appropriate location?

### In Topic: SSE vector normalization

27 July 2012 - 09:20 AM

Sounds to me like a perfect time to use assert, like was suggested...

Agreed, I had meant to reiterate that a debug-only assertion was a valid solution!

### In Topic: SSE vector normalization

27 July 2012 - 09:01 AM

There is actually a very valid reason to simply crash on a 0 vector in your normalization function and I promise it has nothing to do with "ignorance or laziness". The entire point of using SSE is that it is high performance code. Normalization of a 0 vector, as previously stated is technically an invalid operation.

Adding vector validation (i.e. checking for a 0 vector) in your normalization code will introduce unnecessary run-time overhead (in the form of potential branch mis-predictions and LHS) to a performance-sensitive area of your code. As the operation in question is technically invalid, those concerned with performance will opt to have the function crash rather than introduce the overhead. If this code crashes, the real bug lies elsewhere (the attempt to normalize a 0 vector ... why is your vector 0? Why are you trying to normalize it if it is? These are the bugs you should be concerned with).

If there is a case in your code where you *may* be normalizing a 0 vector (direction derived via velocity when player is standing still perhaps?), then you should validate the vector *before* the attempt to normalize. The reason for this is that these cases are likely few and far between, and introducing the overhead that I explained above to *every* instance of a call to normalize is unfairly penalizing everyone who calls the function, whether they have a chance to pass a 0 vector or not.

PARTNERS