Can't animate the exact object that I want in openGL & GLUT Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Initializing OpenGL without GLUTCenter an OpenGL window with GLUTLearning OpenGL without GLUT?How to pause an animation with OpenGL / glutOpenGL/GLUT - drawing on an objectsimple 2d animation in glutOPENGL GLUT compiler can't find functionsOpenGL glut animation of 8 puzzle solvingCan't display a PNG using Glut or OpenGLStopping animation with a key using GLUT?

preposition before coffee

How does the math work when buying airline miles?

Girl Hackers - Logic Puzzle

Significance of Cersei's obsession with elephants?

Do wooden building fires get hotter than 600°C?

Intuitive explanation of the rank-nullity theorem

How to compare two different files line by line in unix?

How to write capital alpha?

What does it mean that physics no longer uses mechanical models to describe phenomena?

Trademark violation for app?

Why do aircraft stall warning systems use angle-of-attack vanes rather than detecting airflow separation directly?

What does Turing mean by this statement?

One-one communication

Why can't I install Tomboy in Ubuntu Mate 19.04?

Deconstruction is ambiguous

Dynamic filling of a region of a polar plot

Google .dev domain strangely redirects to https

How long can equipment go unused before powering up runs the risk of damage?

How can I set the aperture on my DSLR when it's attached to a telescope instead of a lens?

How often does castling occur in grandmaster games?

What initially awakened the Balrog?

Crossing US/Canada Border for less than 24 hours

Is it possible for SQL statements to execute concurrently within a single session in SQL Server?

How did Fremen produce and carry enough thumpers to use Sandworms as de facto Ubers?



Can't animate the exact object that I want in openGL & GLUT



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Initializing OpenGL without GLUTCenter an OpenGL window with GLUTLearning OpenGL without GLUT?How to pause an animation with OpenGL / glutOpenGL/GLUT - drawing on an objectsimple 2d animation in glutOPENGL GLUT compiler can't find functionsOpenGL glut animation of 8 puzzle solvingCan't display a PNG using Glut or OpenGLStopping animation with a key using GLUT?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















When I clicked the right button on the particular object it gets started to animate. However, whether I click on the same object to stop it -the animating one- or any other object which is not animating, the animating object stops. But, I want animating object to be stopped only when I click on it.



How can I fix this problem? Here is my onClick and onTimer functions. Should I use the animating bool in structure? if so, how?



if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) {

for(i=0; i<MAX; i++)
if(mx >= arr[i].xB + 0 && mx <= arr[i].xB + 130 && my <= arr[i].yB + 17 && my >= arr[i].yB + - 17)
animation = !animation;
animationNumber = i;
printf("TRUEn");



void onTimer( int v)

glutTimerFunc( TIMER_PERIOD, onTimer, 0) ;


if(animation)
arr[animationNumber].xB++;
if(arr[animationNumber].xB >= 640)
arr[animationNumber].xB -= 1410;


glutPostRedisplay() ; // display()











share|improve this question
























  • The title is wrong. The problem is in the description. I don't want the animating object to be stopped when I click another object.

    – baruj
    Mar 8 at 22:09











  • How is this related to OpenGL?

    – Rabbid76
    Mar 8 at 22:18











  • I am drawing a rocket some other things by using OpenGL

    – baruj
    Mar 8 at 22:27











  • Store animationNumber in an array. In onClick check, if i in an array. If it is - remove it, otherwise add it. In onTimer iterate thru the whole array.

    – Michael Nastenko
    Mar 9 at 0:48











  • still not working.

    – baruj
    Mar 9 at 9:35

















1















When I clicked the right button on the particular object it gets started to animate. However, whether I click on the same object to stop it -the animating one- or any other object which is not animating, the animating object stops. But, I want animating object to be stopped only when I click on it.



How can I fix this problem? Here is my onClick and onTimer functions. Should I use the animating bool in structure? if so, how?



if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) {

for(i=0; i<MAX; i++)
if(mx >= arr[i].xB + 0 && mx <= arr[i].xB + 130 && my <= arr[i].yB + 17 && my >= arr[i].yB + - 17)
animation = !animation;
animationNumber = i;
printf("TRUEn");



void onTimer( int v)

glutTimerFunc( TIMER_PERIOD, onTimer, 0) ;


if(animation)
arr[animationNumber].xB++;
if(arr[animationNumber].xB >= 640)
arr[animationNumber].xB -= 1410;


glutPostRedisplay() ; // display()











share|improve this question
























  • The title is wrong. The problem is in the description. I don't want the animating object to be stopped when I click another object.

    – baruj
    Mar 8 at 22:09











  • How is this related to OpenGL?

    – Rabbid76
    Mar 8 at 22:18











  • I am drawing a rocket some other things by using OpenGL

    – baruj
    Mar 8 at 22:27











  • Store animationNumber in an array. In onClick check, if i in an array. If it is - remove it, otherwise add it. In onTimer iterate thru the whole array.

    – Michael Nastenko
    Mar 9 at 0:48











  • still not working.

    – baruj
    Mar 9 at 9:35













1












1








1








When I clicked the right button on the particular object it gets started to animate. However, whether I click on the same object to stop it -the animating one- or any other object which is not animating, the animating object stops. But, I want animating object to be stopped only when I click on it.



How can I fix this problem? Here is my onClick and onTimer functions. Should I use the animating bool in structure? if so, how?



if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) {

for(i=0; i<MAX; i++)
if(mx >= arr[i].xB + 0 && mx <= arr[i].xB + 130 && my <= arr[i].yB + 17 && my >= arr[i].yB + - 17)
animation = !animation;
animationNumber = i;
printf("TRUEn");



void onTimer( int v)

glutTimerFunc( TIMER_PERIOD, onTimer, 0) ;


if(animation)
arr[animationNumber].xB++;
if(arr[animationNumber].xB >= 640)
arr[animationNumber].xB -= 1410;


glutPostRedisplay() ; // display()











share|improve this question
















When I clicked the right button on the particular object it gets started to animate. However, whether I click on the same object to stop it -the animating one- or any other object which is not animating, the animating object stops. But, I want animating object to be stopped only when I click on it.



How can I fix this problem? Here is my onClick and onTimer functions. Should I use the animating bool in structure? if so, how?



if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) {

for(i=0; i<MAX; i++)
if(mx >= arr[i].xB + 0 && mx <= arr[i].xB + 130 && my <= arr[i].yB + 17 && my >= arr[i].yB + - 17)
animation = !animation;
animationNumber = i;
printf("TRUEn");



void onTimer( int v)

glutTimerFunc( TIMER_PERIOD, onTimer, 0) ;


if(animation)
arr[animationNumber].xB++;
if(arr[animationNumber].xB >= 640)
arr[animationNumber].xB -= 1410;


glutPostRedisplay() ; // display()








c++ animation opengl glut






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 22:11









genpfault

42.7k954100




42.7k954100










asked Mar 8 at 22:08









barujbaruj

61




61












  • The title is wrong. The problem is in the description. I don't want the animating object to be stopped when I click another object.

    – baruj
    Mar 8 at 22:09











  • How is this related to OpenGL?

    – Rabbid76
    Mar 8 at 22:18











  • I am drawing a rocket some other things by using OpenGL

    – baruj
    Mar 8 at 22:27











  • Store animationNumber in an array. In onClick check, if i in an array. If it is - remove it, otherwise add it. In onTimer iterate thru the whole array.

    – Michael Nastenko
    Mar 9 at 0:48











  • still not working.

    – baruj
    Mar 9 at 9:35

















  • The title is wrong. The problem is in the description. I don't want the animating object to be stopped when I click another object.

    – baruj
    Mar 8 at 22:09











  • How is this related to OpenGL?

    – Rabbid76
    Mar 8 at 22:18











  • I am drawing a rocket some other things by using OpenGL

    – baruj
    Mar 8 at 22:27











  • Store animationNumber in an array. In onClick check, if i in an array. If it is - remove it, otherwise add it. In onTimer iterate thru the whole array.

    – Michael Nastenko
    Mar 9 at 0:48











  • still not working.

    – baruj
    Mar 9 at 9:35
















The title is wrong. The problem is in the description. I don't want the animating object to be stopped when I click another object.

– baruj
Mar 8 at 22:09





The title is wrong. The problem is in the description. I don't want the animating object to be stopped when I click another object.

– baruj
Mar 8 at 22:09













How is this related to OpenGL?

– Rabbid76
Mar 8 at 22:18





How is this related to OpenGL?

– Rabbid76
Mar 8 at 22:18













I am drawing a rocket some other things by using OpenGL

– baruj
Mar 8 at 22:27





I am drawing a rocket some other things by using OpenGL

– baruj
Mar 8 at 22:27













Store animationNumber in an array. In onClick check, if i in an array. If it is - remove it, otherwise add it. In onTimer iterate thru the whole array.

– Michael Nastenko
Mar 9 at 0:48





Store animationNumber in an array. In onClick check, if i in an array. If it is - remove it, otherwise add it. In onTimer iterate thru the whole array.

– Michael Nastenko
Mar 9 at 0:48













still not working.

– baruj
Mar 9 at 9:35





still not working.

– baruj
Mar 9 at 9:35












1 Answer
1






active

oldest

votes


















1














Use an array bool animation[MAX] instead of the single boolean variable animation and the indexing variable animationNumber.

With this solution each object has its own state which indicates if it is "animating" or stands still.



bool animation[MAX] = ;


Change the corresponding state of the object in the array, when the mouse button is pressed:



if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)

for (i=0; i<MAX; i++)

if (mx >= arr[i].xB + 0 && mx <= arr[i].xB + 130 &&
my <= arr[i].yB + 17 && my >= arr[i].yB + - 17)

animation[i] = !animation[i];
printf("TRUEn");





Traverse all the objects in the timer function and update the positions of the objects:



void onTimer( int v) 

glutTimerFunc( TIMER_PERIOD, onTimer, 0) ;

for (i=0; i<MAX; i++)

if(animation[i])

arr[i].xB++;
if( arr[i].xB >= 640)
arr[i].xB -= 1410;


glutPostRedisplay();






share|improve this answer























  • thanks for sharing your idea. I solved the problem

    – baruj
    Mar 10 at 14:02











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55071669%2fcant-animate-the-exact-object-that-i-want-in-opengl-glut%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Use an array bool animation[MAX] instead of the single boolean variable animation and the indexing variable animationNumber.

With this solution each object has its own state which indicates if it is "animating" or stands still.



bool animation[MAX] = ;


Change the corresponding state of the object in the array, when the mouse button is pressed:



if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)

for (i=0; i<MAX; i++)

if (mx >= arr[i].xB + 0 && mx <= arr[i].xB + 130 &&
my <= arr[i].yB + 17 && my >= arr[i].yB + - 17)

animation[i] = !animation[i];
printf("TRUEn");





Traverse all the objects in the timer function and update the positions of the objects:



void onTimer( int v) 

glutTimerFunc( TIMER_PERIOD, onTimer, 0) ;

for (i=0; i<MAX; i++)

if(animation[i])

arr[i].xB++;
if( arr[i].xB >= 640)
arr[i].xB -= 1410;


glutPostRedisplay();






share|improve this answer























  • thanks for sharing your idea. I solved the problem

    – baruj
    Mar 10 at 14:02















1














Use an array bool animation[MAX] instead of the single boolean variable animation and the indexing variable animationNumber.

With this solution each object has its own state which indicates if it is "animating" or stands still.



bool animation[MAX] = ;


Change the corresponding state of the object in the array, when the mouse button is pressed:



if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)

for (i=0; i<MAX; i++)

if (mx >= arr[i].xB + 0 && mx <= arr[i].xB + 130 &&
my <= arr[i].yB + 17 && my >= arr[i].yB + - 17)

animation[i] = !animation[i];
printf("TRUEn");





Traverse all the objects in the timer function and update the positions of the objects:



void onTimer( int v) 

glutTimerFunc( TIMER_PERIOD, onTimer, 0) ;

for (i=0; i<MAX; i++)

if(animation[i])

arr[i].xB++;
if( arr[i].xB >= 640)
arr[i].xB -= 1410;


glutPostRedisplay();






share|improve this answer























  • thanks for sharing your idea. I solved the problem

    – baruj
    Mar 10 at 14:02













1












1








1







Use an array bool animation[MAX] instead of the single boolean variable animation and the indexing variable animationNumber.

With this solution each object has its own state which indicates if it is "animating" or stands still.



bool animation[MAX] = ;


Change the corresponding state of the object in the array, when the mouse button is pressed:



if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)

for (i=0; i<MAX; i++)

if (mx >= arr[i].xB + 0 && mx <= arr[i].xB + 130 &&
my <= arr[i].yB + 17 && my >= arr[i].yB + - 17)

animation[i] = !animation[i];
printf("TRUEn");





Traverse all the objects in the timer function and update the positions of the objects:



void onTimer( int v) 

glutTimerFunc( TIMER_PERIOD, onTimer, 0) ;

for (i=0; i<MAX; i++)

if(animation[i])

arr[i].xB++;
if( arr[i].xB >= 640)
arr[i].xB -= 1410;


glutPostRedisplay();






share|improve this answer













Use an array bool animation[MAX] instead of the single boolean variable animation and the indexing variable animationNumber.

With this solution each object has its own state which indicates if it is "animating" or stands still.



bool animation[MAX] = ;


Change the corresponding state of the object in the array, when the mouse button is pressed:



if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)

for (i=0; i<MAX; i++)

if (mx >= arr[i].xB + 0 && mx <= arr[i].xB + 130 &&
my <= arr[i].yB + 17 && my >= arr[i].yB + - 17)

animation[i] = !animation[i];
printf("TRUEn");





Traverse all the objects in the timer function and update the positions of the objects:



void onTimer( int v) 

glutTimerFunc( TIMER_PERIOD, onTimer, 0) ;

for (i=0; i<MAX; i++)

if(animation[i])

arr[i].xB++;
if( arr[i].xB >= 640)
arr[i].xB -= 1410;


glutPostRedisplay();







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 9 at 13:29









Rabbid76Rabbid76

44.8k123354




44.8k123354












  • thanks for sharing your idea. I solved the problem

    – baruj
    Mar 10 at 14:02

















  • thanks for sharing your idea. I solved the problem

    – baruj
    Mar 10 at 14:02
















thanks for sharing your idea. I solved the problem

– baruj
Mar 10 at 14:02





thanks for sharing your idea. I solved the problem

– baruj
Mar 10 at 14:02



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55071669%2fcant-animate-the-exact-object-that-i-want-in-opengl-glut%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved