ページから次のリストがあります。
#include "vector.h"
// An axis-aligned bounding box
class AABB
{
public:
VECTOR P; //position
VECTOR E; //x,y,z extents
AABB( const VECTOR& p, const VECTOR& e): P(p) ,E(e) {}
// ...
const SCALAR min( long i ) const
{
return ((AABB*)this)->P[i] - ((AABB*)this)->E[i];
}
// ...
};
今私が理解していないのは、長い値を持つ min() によってアクセスされるものです。調べvector.h
たところ、角かっこ演算子がオーバーロードされていることがわかりました。
class VECTOR
{
public:
SCALAR x,y,z; //x,y,z coordinates
//...
//index a component
//NOTE: returning a reference allows
//you to assign the indexed element
SCALAR& operator [] ( const long i )
{
return *((&x) + i);
}
//...
};
後で次のように使用されます。
// each axis
for( long i=0 ; i<3 ; i++ )
{
if( A.max(i)<B.min(i) && v[i]<0 )
{
x
では、値の参照が だけインクリメントされるのはなぜi
ですか?
この質問がとてつもなく簡単である場合は、ご容赦ください。私はまだ新人です。これで十分な情報が得られない場合は、実際のソースを提供できます