Jump to content
  • Advertisement

PeterJobs

Member
  • Content Count

    7
  • Joined

  • Last visited

Community Reputation

106 Neutral

About PeterJobs

  • Rank
    Newbie
  1. PeterJobs

    Keyboard triggers animation

    Yeah, I know, my doubt is more related to basic programming than anything else. Now I did read the links you recommended properly, and I'm starting to understand a bit more about the problems related to floating comparisons (although it looks like I'm way too noob to get some of those stuff as of now). And a TimerFunc, in the case I need, looks a better option (than an IdleFunc). Thanks for your reply, 'cause it opened my eyes to problems I didn't know existed. I'll just test and study more to get to the result I want.
  2. PeterJobs

    Keyboard triggers animation

    Sorry, hadn't seen the code was still posted broken. I'll try it again: [source lang="cpp"]void Timer(int value) { if (posInitialxObject == -1.5) { while (posInitialxObject != posFinalxObject) posInitialxObject += -0.1; } else { while (posFinalxObject != posInitialxObject) posInitialxObject -= -0.1; } glutPostRedisplay(); glutTimerFunc(33, Timer, 1); }[/source] The -1.5 was the initial X position of the object on the screen. Until that position was different then -2.3, the X variable should decrease -0.1, making it translate. Now I've created two global variables w/ the initial and final position, so I'm comparing these two.
  3. PeterJobs

    Keyboard triggers animation

    I'm sorry, my Timer function didn't appear correctly, so I'm posting it here: [source lang="cpp"]void Timer(int value) { if (positionObject == -1.5) { while (positionObject <= -2.3) positionObject += -0.1; } else { while (positionObject != -1.5) positionObject -= -0.1; } glutPostRedisplay(); glutTimerFunc(33, Timer, 1); }[/source]
  4. Hi everyone! I needed a little help with a similar question this morning, but in this one I'm really stuck and don't know what I'm doing, so any help will be appreciated. I have to move smoothly an object from one side of my 3d room to another, every time a single key is pressed. I declare a global variable with the initial x position of it, and then I render it: [source lang="cpp"]glPushMatrix(); glTranslatef(positionObject, 1, -6); object->Render(); glPopMatrix();[/source] So I guess that, for the smooth movement, I'll need a timer that shows the object position several times per second, right? I'm doing it like this (not the proper way to do it, I'm aware): [source lang="cpp"]void Timer (int value) { if (positionObject == -1.5) { while (positionObject <= -2.3) positionObject += -0.1; } else { while (positionObject != -1.5) positionObject -= -0.1; } glutPostRedisplay(); glutTimerFunc (33, Timer, 1); }[/source] And my final doubt is: what do I call in my keyboard callback function for it to work? [source lang="cpp"]void KeyboardCallback (unsigned char key, int x, int y){ switch (key) { case 'r': case 'R': //do sth; break; } }[/source]
  5. PeterJobs

    Rotating specific .obj with keyboard key

    Guys, thank you all for your answer. All your considerations were basically right, and now it is rotating perfectly. The main problem was that I wasn't applying glRotate when the object was first called and rendered. You guys rock.. thanks once again!
  6. [color=#333333][font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif][background=rgb(250, 250, 250)]Good morning guys,[/background][/font] [color=#333333][font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif][background=rgb(250, 250, 250)]I'm having difficulties in rotating an imported .obj when the key 'C' is pressed. I think my problem is with my KeyboardCallback function, but still, I can't figure out how to do it properly. My program compiles, but nothing happens when the key is pressed.[/background][/font] [color=#333333][font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif][background=rgb(250, 250, 250)]First, I declare some static pointes to the .objs that I'm importing:[/background][/font] [source lang="cpp"]static Mesh *book, *can, *table;[/source] [color=#333333][font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif][background=rgb(250, 250, 250)]Then I render the objects:[/background][/font] [source lang="cpp"]void Render(void){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); if (book) { glPushMatrix(); glTranslatef(0, -2, -8); book->Render(); glPopMatrix(); } .... }[/source] [color=#333333][font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif][background=rgb(250, 250, 250)]That all works perfectly fine. And here my doubts start. My KeyboardCallback function:[/background][/font] [source lang="cpp"]void KeyboardCallback(unsigned char key, int x, int y){ switch (key) { case 27: exit(0); break; case 'c': case 'C': RotateBook(book); break; }[/source] [color=#333333][font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif][background=rgb(250, 250, 250)]And finally, my RotateBook function:[/background][/font] [source lang="cpp"]void RotateBook(Mesh *){ glPushMatrix(); glRotatef(45, 0, 1, 0); book->Render(); glPopMatrix(); }[/source] [color=#333333][font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif][background=rgb(250, 250, 250)]Can someone please indicate what I'm doing wrong?[/background][/font] [color=#333333][font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif][background=rgb(250, 250, 250)]Thanks in advance.[/background][/font]
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!