2016-04-29 13 views
0

重力を含むQtを使用してC++でパーティクルシステムを作成しました。システムにも衝突を含めることができるようにバウンディングボックスを含めたいと思いますが、動作させることはできません。ここに私の.hコードは次のとおりです。C++パーティクルシステムの境界ボックスが機能しない

typedef struct { 
    int top; 
    int bottom; 
    int left; 
    int right; 

}BoundingBox; 

BoundingBox makeBoundingBox(int top, int bottom, int left, int right); 

た.cpp:

for(int i=0; i<m_numParticles; ++i) 
    { 

     if (m_pos.m_y >= _boundingBox.top) 
     { 
      m_dir.m_y = (-1)*(m_dir.m_y); 
     } 

     if (m_pos.m_y <= _boundingBox.bottom) 
     { 
      m_dir.m_y = (-1)*(m_dir.m_y); 
     } 

     if (m_pos.m_x <= _boundingBox.left) 
     { 
      m_dir.m_x = (-1)*(m_dir.m_x); 
     } 

     if (m_pos.m_x >= _boundingBox.right) 
     { 
      m_dir.m_x = (-1)*(m_dir.m_x); 
     } 

     m_particles[i].update(m_gravity, _boundingBox); 

をと設定している:

BoundingBox makeBoundingBox(int top, int bottom, int left, int right) 
{ 
    BoundingBox boundingBox; 
    boundingBox.top = top; 
    boundingBox.bottom = bottom; 
    boundingBox.left = left; 
    boundingBox.right = right; 

    return boundingBox; 
} 

私は、このループを使用して、私のエミッタクラスのバウンディングボックスを更新しました私のウィンドウ内のバウンディングボックスは次のようになります。

m_emitter->setBoundingBox(makeBoundingBox(m_height, 0, 0, m_width)); 

エラーは発生していませんが、動作していないと思われます。 ありがとう

+0

この文脈で意味 "それが機能していない" んか?物理学における単純なボックスボックス交差テストには注意してください。ベロシティが>ボックスサイズの場合、彼らはお互いに右に行くことが可能です。 – Robinson

+0

あなたの関数にいくつかのcout文を入れて、あなたの関数がどのような種類の数値を取得しているかを調べ、if文が真であるかどうかを確認する衝突をチェックします。あなたは粒子そのものの変形をしていますか?その場合は、変換がバウンディングボックスにも適用されていることを確認してください – element11

答えて

0

Xが小さくなると左に、Yが小さくなると上が上がることを前提とします。また、速度に沿って位置を更新して、複数回連続してトリガされないようにします。

Yのための例は、座標:

// Are we going up too much? 
if (m_pos.m_y < _boundingBox.top) 
{ 
    m_dir.m_y = (-1)*(m_dir.m_y); 
    m_pos.m_y = _boundingBox.top + 1; 
} 
// Or are we going down too much? 
else if (m_pos.m_y > _boundingBox.bottom) 
{ 
    m_dir.m_y = (-1)*(m_dir.m_y); 
    m_pos.m_y = _boundingBox.bottom - 1; 
} 
0

はないはずです。

m_emitter->setBoundingBox(makeBoundingBox(m_height, 0, 0, m_width)); 

がbe:

m_emitter->setBoundingBox(makeBoundingBox(0, m_height, 0, m_width)); 
関連する問題