Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 514887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:34:17+00:00 2026-05-13T07:34:17+00:00

I’m trying to animate object. I use keyframe animation: I have two vertex buffers

  • 0

I’m trying to animate object. I use keyframe animation: I have two vertex buffers (two frames) with vertices of my object – first buffer is for object start state and second for end state. To transform the object I simply use linear interpolation.
To make it more clear, please take a look at the code snippet:



FloatBuffer vertexBuffer_motion;
FloatBuffer  vertexBuffer_source, vertexBuffer_destination;
...
int indicesCount = mSphereFrame1.getVertexBuffer().capacity()
...
public void onDrawFrame(GL10 gl) {

   float percentDone = (float)timeSinceStartKeyFrame / (float)animationDuration;   
   //Calculate the new position of each vertex - this is done for each frame
   for (int i = 0; i < indicesCount; i++) {
      float diffIndice = vertexBuffer_destination.get(i) - vertexBuffer_source.get(i);          
      vertexBuffer_motion.put( vertexBuffer_source.get(i) + (percentDone * diffIndice) );           
   }
   ...
   //draw the object
   gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer_motion);
   gl.glDrawElements(GL10.GL_TRIANGLES, mSphereFrame1.getElementsCount(),
                     GL10.GL_UNSIGNED_SHORT, mSphereFrame1.getIndexBuffer());
}

As you can see I actually use one more buffer. vertexBuffer_motion is the one I use to draw my object in intermediate state.

Time for my question.
What is the best approach for such keyframe animation on android? Can I somehow avoid (quite time consuming) operations of calculating and copying new state of all vertices to vertexBuffer_motion?

I know I could use VBO but still, I would have to prepare this vertexBuffer_motion and use glBufferData to set data to this VBO (or not?).
Could someone provide me with some code example showing the best approach for keyframe animation on android?

Thanks for reading.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:34:17+00:00Added an answer on May 13, 2026 at 7:34 am

    I’m assuming you’re making a game, if you aren’t ignore the bits about velocity and position, everything else applies.

    You’re going to have to calculate where to draw everything, there isn’t really a shortcut around that.

    However, as far as copying state goes, you need to approach the problem a little differently.

    Each visible game object (Actor, Doodad, etc.) must maintain it’s own state of where it is, where it is going, what frame of animation to show. The way I’m showing you here will also prevent temporal aliasing

    As part of your game loop, you should first update each object by looping through them, passing them the delta time since the last update, and then each object should maintain a previous and current state. When asked to draw with a dt, that the time to do the linear interpolation between the two states, to create a drawable state.

    When calculating the proper time, you should follow the guideline here. Yes, the article is about a integrating engine but the approach used will work with games without them, and will allow a game to downscale gracefully in environments where there isn’t enough power to keep up as well as never to run too fast if the hardware changes under your feet.

    Pseudo code:

    Abstract Class GameObject {
         private State previous_state;
         private State current_state;
         private State draw_state;
    
         void Update(float dt) {
              previous_state = current_state.copy();
              current_state = current_state + dt;
         }
         void Draw(float dt) {
              draw_state = interpolate(previous_state, current_state, dt);
              //Do opengl commands to draw draw_state
         }
    }
    

    Then your game loop should look like:

    void GameLoop() {
         while(1) {
              //Calculate dt here
              process_inputs();
              for {game_object in object_list} {
                   game_object.Update(dt)
              }
              //...
              for {game_object in object_list} {
                   game_object.Draw(dt)
              }
     }
    

    Each State contains all the information needed to describe the object’s position, velocity and animation frame. A simple State class might look like:

    Class State {
         public float position_x;
         public float position_y;
         public float velocity_x;
         public float velocity_y;
         public int frame_number;
         public int max_frame;
         public float animation_duration;  //milliseconds
    }
    

    Subtracting two states should produce an intermediate state. Adding a time to a State should calculate the next position based on the velocity, as well as determine the next frame of animation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.