It is currently Mon Jun 26, 2017 12:28 am

All times are UTC - 5 hours




 Page 1 of 1 [ 5 posts ] 
Author Message
 Post subject:
PostPosted: Thu Apr 12, 2007 8:53 pm 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1094
Location: Ontario Canada
This video shows you how to create a class to represent a 3D plane mathematically. The plane can be defined by a normal and a point, or by passing three points to the constructor. To get the plane class working, a number of modifications to the Vector3 class had to be made.


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 28 - Infinite Plane Class
PostPosted: Thu Apr 12, 2007 9:07 pm 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1094
Location: Ontario Canada
After reviewing the constructors in the plane class I realized that there is a problem with the way that it is done in the video. It is better to use the following code instead of what is showed in the video:

Inside both Plane constructors:

Don't set m_bOk = true; before the call to m_v3Normal.Normalize(); Do the following instead:

Some code here....
  m_v3Normal.Normalize();

  if (m_v3Normal.isZero()) {
      m_bOk = false;
      return;
  }

   m_bOk = true;
   return;

} //Plane


This way if the isZero() function fails then the constructor will return m_bOk = false. If isZero is okay then set m_bOk = true.


Last edited by Marek on Sun Nov 23, 2008 9:24 am, edited 2 times in total.

Offline
 Profile  
 
 Post subject: Re: GameDev VMK 28 - Infinite Plane Class
PostPosted: Sat Apr 14, 2007 6:40 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1094
Location: Ontario Canada
You will notice that if you do a clean build of your project, in Visual studio you will get the following warning message:

MathLib.lib(Plane.obj) : warning LNK4221: no public symbols found; archive member will be inaccessible

To get rid of this message, add the following code inside Plane.cpp:
//--------------------------------------------------------------
// Name: ~Plane(:)
// Desc: default destructor
//
Plane::~Plane() {

} //~Plane


I show you how to correct this in VMK29a.


Last edited by Marek on Sun Nov 23, 2008 9:23 am, edited 1 time in total.

Offline
 Profile  
 
 Post subject: an enigma to a wider audience
PostPosted: Sun Nov 23, 2008 8:42 am 

Joined: Wed Aug 06, 2008 7:53 pm
Posts: 182
Location: Russia
This good tutorial put me in mind of the next puzzle. One fine morning 3 swallows is leaving their nest. It is dry and warm, the sky is clear, only 3 small clouds are moving around high above. The question is: how probable that the swallows are belonging to the same plane 3 minutes after they flew up? :)



_________________
«Computer scientists deal with algorithms that you may call practical in theory but unpractical in practice.» © Timothy Gowers
Offline
 Profile  
 
 Post subject: Re: GameDev VMK 28 - Infinite Plane Class
PostPosted: Sun Nov 23, 2008 9:34 am 

Joined: Wed Aug 06, 2008 7:53 pm
Posts: 182
Location: Russia
Marek wrote:
After reviewing the constructors in the plane class I realized that there is a problem with the way that it is done in the video. It is better to use the following code instead of what is showed in the video:

Inside both Plane constructors:

Don't set m_bOk = true; before the call to m_v3Normal.Normalize(); Do the following instead:


Some code here....

m_v3Normal.Normalize();

if (m_v3Normal.isZero()) {
m_bOk = false;
return;
}

m_bOk = true;
return;

} //Plane


This way if the isZero() function fails then the constructor will return m_bOk = false. If isZero is okay then set m_bOk = true.


In the code above it's better to write m_bOk = !m_v3Normal.isZero();, but the point is that if we normalize the vector before we check that it is nonzero, then we have a potential Zero Divide problem in case the vector is zero indeed (let alone that it is pointless to normalize zero length vector). This is sort of due to deficiency of Vector3::Normalize() implementation, since normalization code contains "1.0 / magnitude" statement. Thus, it is still better to check that vector is nonzero first, as it was in original video, e.g.
if ( m_v3Normal.isZero() ) {
    m_bOk = false;
} else {
    m_v3Normal.Normalize();
    m_bOk = true;
}


It is rather interesting to note that Division By Zero condition is not necessarily raises an exception. This depends upon the FPU control registers state (control words). AFAIK, VC disables FPU ZERODIVIDE exception by default. To change control word we can use the _control87() function (and its friends).

Nonetheless please do not be discouraged at these comments. This is not what they are meant for. VMKs are tremendously good.



_________________
«Computer scientists deal with algorithms that you may call practical in theory but unpractical in practice.» © Timothy Gowers
Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 1 [ 5 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 0 guests


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

Jump to:  

cron