Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Think about implementing a 'DrawableAnimatableObject' which is a high level 3D object that is able to animate and draw itself, and contains your polygons (multiple rectangles in your case) as internal data. See the following incomplete code to give you an idea: </p> <pre><code>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(); }; </code></pre> <p>In this code, Mesh is a data structure that contains your polygons. Simply put, it can be a vertex-face list, or a more complicated structure like half-edge. The DrawableAnimatableObject::draw() function should look something like this:</p> <pre><code>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(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload