Programming 2D Games

The official forum for "Programming 2D Games" the book by: Charles Kelly

It is currently Sat Dec 07, 2019 6:07 am

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Thu Mar 21, 2019 4:50 pm 
Offline
Site Admin
User avatar

Joined: Sat Jan 28, 2012 4:36 pm
Posts: 553
The normalize function in Windows::Foundation::Numerics does not work correctly with very small numbers. It returns infinity in both terms of the vector. I corrected the issue like this:

Code:
//=============================================================================
// Normalize the vector.
//=============================================================================
inline void Normalize(Vec2 &v)
{
    if (std::abs(v.x) <= EPSILON)   // Set very small numbers to 0 to avoid
        v.x = 0;                    // problems with Numerics::normalize().
    if (std::abs(v.y) <= EPSILON)
        v.y = 0;

    v = Windows::Foundation::Numerics::normalize(v);
    // If normalize function returns NaN (Not a Number) for X or Y
    // component in vector.
    if (v.x != v.x)     // If v.x is Nan
        v.x = 0;        // Force to 0
    if (v.y != v.y)     // If v.y is Nan
        v.y = 0;        // Force to 0
}

_________________
Professor Kelly


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group