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

  • Home
  • SEARCH
  • 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 7434671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:55:55+00:00 2026-05-29T09:55:55+00:00

I would like to move an object (I have a simple rectangle) and I

  • 0

I would like to move an object (I have a simple rectangle) and I would like to move it up to a specific position and back (maybe repeat forever).

I know I should have a variable in the matrix translation (gltranslate) but where/how do I make this variable and animate each frame.

  • 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-29T09:55:56+00:00Added an answer on May 29, 2026 at 9:55 am

    It’s hard to be certain what stage you are at but assuming you already have a rectangle drawing on screen:

    Wherever you have your ‘drawMyRectangle’ function create these variables:

    //Your starting position
    float startPositionX;
    float startPositionY;
    //Your ending position
    float endPositionX;
    float endPositionY;
    //The value that describes where in between these positions you are
    
    float translationAlpha;
    float animationDirection;
    

    So fill in those values with translationAlpha starting at 0 and animatingForward at 1.

    I recommend doing this next part in a separate function but you will need code that steps your animation, simply

    void step()
    {
        translationAlpha += .01 * animationDirection;//.01 is the per
        if (animationDirection > 0.0 && translationAlpha >= 1.0 ||
            animationDirection < 0.0 && translationAlpha <= 0.0) {
            animationDirection *= -1.0;
        }
    }
    

    It sounds like you are keeping it simple so just call that every time you draw.

    So make sure you have a glPushMatrix and a glPopMatrix surrounding your draw.
    after you pushMatrix and before you call your draw add:

    glTranslate2f(startPositionX + translationAlpha * (endPositionX - startPositionX),
                  startPositionY + translationAlpha * (endPositionY - startPositionY));
    

    That covers a really primitive way to do what you described, also consider this pseudocode because I don’t know what functions you are using and how you are handling your matrices.

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

Sidebar

Related Questions

I would like to move data back and fourth between clojure applications. Application settings
I have two XmlDocuments and I would like to move an XmlNode selected from
I have a Pylons app where I would like to move some of the
I have two divs. I would like to move/populate the text from div id
I have some code in <head> in .apsx I would like to move to
I would like to know if there is a way to move the node
Thus far i have only used glDrawArrays and would like to move over to
I have an object with which I would like to make follow a bezier
I would like to move a file or folder from one place to another
I would like to move some files around in Visual Studio. But I see

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.