2

openGL を使用して形状をアニメーション化するプログラムを作成しているときに、ここで問題に遭遇しました。

現在、プログラムでは、次のスニペットを使用していくつかの形状を作成しています

for(int i=50;i<=150;i=i+50){
for(int j=50;j<=750;j=j+200){
//Draw rectangle shape at position(j,i); //shape has additional capability for animations }
}

これにより、次の出力が得られます。

ここに画像の説明を入力

ここで、これらの長方形のサイズを変更し、すべてを別の位置に移動する必要があります。移動する必要がPointある最初の四角形の最終的なターゲットがあります。rectangle at position[0][0]ただし、これらの長方形のサイズを次のようなものでアニメーション化すると

rectangle.resize(newWidth, newHeight, animationTime);

明らかな理由で長方形がくっつかず、次のような結果になります。

ここに画像の説明を入力

Groupingサイズ変更(およびモーションなど)などのさまざまなアニメーションが適用された場合でも、頂点または境界が互いに接触するように、これらの形状を結合できるようなものを探しています。

Groupingここが主なものであることに注意してください。将来、独立したアニメーション (回転など) が既に実行されている最後の列で 2 つの四角形をグループ化する必要があるという要件が生じる可能性があります。だから、私はこれplane/containerをこれらの2つの長方形を持つようなものとして描き、plane/containerそれ自体を位置などのためにアニメーション化することができます.私はコードではなくアルゴリズム/コンセプトに問題はありません.

4

2 に答える 2

0

CPU でジオメトリをアニメートする代わりに、CPU でスケール/位置マトリックスをアニメートし、MVP マトリックスを介してジオメトリの変換を頂点シェーダーに任せます。すべての長方形に 1 つの同じスケール マトリックスを使用します。(または、倍率が X と Y で異なる場合は 2 つの行列)。

PS。次に例を示します。

float sc = 0;

void init()
{
  glMatrixMode (GL_MODELVIEW);
  glLoadIdentity ();
}

void on_each_frame()
{
  // do other things 

  // draw pulsating rectangles
  sc += 0.02;
  glMatrixMode(GL_MODELVIEW);
  glPushMatrix();
  glScalef((float)sin(sc) + 1.5f);
  // draw rectangles as usual, **without** scaling them
  glPopMatrix();

  // do other things
}
于 2012-12-14T16:33:55.017 に答える
0

アニメーション化して描画できる高レベルの 3D オブジェクトである「DrawableAnimatableObject」を実装し、内部データとしてポリゴン (この場合は複数の四角形) を含めることを考えてください。アイデアを得るために、次の不完全なコードを参照してください。

class DrawableAnimatableObject {
private:
    Mesh *mesh;
    Vector3 position;
    Quaternion orientation;
    Vector3 scale;
    Matrix transform;

public:
    DrawableAnimatableObject();
    ~DrawableAnimatableObject();

    //update the object properties for the next frame.
    //it updates the scale, position or orientation of your
    //object to suit your animation.
    void update();  

    //Draw the object. 
    //This function converts scale, orientation and position 
    //information into proper OpenGL matrices and passes them 
    //to the shaders prior to drawing the polygons, 
    //therefore no need to resize the polygons individually.
    void draw();

    //Standard set-get;
    void setPosition(Vector3 p);
    Vector3 getPosition();
    void setOrientation(Quaternion q);
    Quaternion getOrientation();
    void setScale(float f);
    Vector3 getScale();
};

このコードでは、Mesh はポリゴンを含むデータ構造です。簡単に言えば、頂点と面のリスト、またはハーフエッジのようなより複雑な構造にすることができます。DrawableAnimatableObject::draw() 関数は次のようになります。

DrawableAnimatableObject::draw() {

    transform = Matrix::CreateTranslation(position) * Matrix::CreateFromQuaternion(orientation) * Matrix::CreateScale(scale);

    // in modern openGL this matrix should be passed to shaders.
    // in legacy OpenGL you will apply this matrix with:
    glPushMatrix();
    glMultMatrixf(transform);

    glBegin(GL_QUADS);
    //...
    // Draw your rectangles here.
    //...
    glEnd();

    glPopMatrix();
}
于 2012-12-20T19:01:08.353 に答える