Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About tamlam

  • Rank

Personal Information

  • Interests

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Thanks so much for great comments. Let me clarify more. In the real code, I want to roll the cube in different direction within x_axis and y_axis. //cube.cubeCenter[0] = (x0, y0, 0); and true for rolling aside with x_axis //cube.cubeCenter[1] = (x1, y1, 0); and true for rolling aside with x_axis //cube.cubeCenter[2] = (x2, y2, 0); and false for rolling aside with y_axis //..... for (int i = 0; i < cube.cubeCenter.size(); i++) { if(cube.cubeCenter[i]==true){ //means that it rolls along x_axis //SDirection = true; // in order to increase angle value; } } When I check boolean cube.cubeCenter, sometimes it is true, sometimes it's false due to rolling along x_axis or y_axis. I think it is the right boolean condition. You are right with the error with a condition for Count. It should be: // if (cube.cubeCenter[i] == true){ //rolling along X_axis SDirection = true; if (Count <= 90){ ...... //do X_axis rolling // in order to increase angle value }else{ angle = 0; Count = 0; } }else{ // means: cube.cubeCenter[i] == false //rolling along Y_axis SDirection = false; if (Count <= 90){ ...... //do Y_axis rolling }else{ angle = 0; Count = 0; } } This is also my misunderstanding. Whenever the program runs, the Display() will run the same time with SpecialKey function. As a result, all cubes will appear without rolling. When pressing the 'r' key, it starts to roll for all cubes. Currently, I am trying to do that. But don't know why the program does not stop in if (cube.cubeCenter == true) condition to roll the cube before moving to the next cube. When I set a breakpoint like if (cube.cubeCenter == true) => print rolling x_axis, else {print rolling y_axis}, they are right with the condition.
  2. I have a vector saving 5 cube coordinates in oxy plan. Task: 1st cube roll 90 degrees, then disappear then 2nd cube roll 90 dg … until the last cube in the vector. Problem: whenever the program runs, all the cube will appear and roll the same time. Q: How can I solve this problem? I checked the value in for loop (temp), and value of (count) as below: angle 1 count 1 temp0 temp1 temp2 temp3 temp4 temp5 temp6 temp7 angle 2 count 2 temp0 temp1 temp2 temp3 temp4 temp5 temp6 temp7 => I do not know why the for loop does not wait for for the “presskey” action to increase the angle value before move to the next temp value. int Count(0); void Display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); SetLight(); glPushMatrix(); ConclusiveAxis(); DrawGrid(); for (int temp = 0; temp < cube.coordinates.size(); temp++) { cout<< "temp" << temp << endl; if ((cube.coordinates[temp] == true)) { sDirection = true; if (Count <= 90) { glPushMatrix(); glTranslatef(cube.coordinates[temp].x - 0.5, cube.coordinates[temp].y - 0.5, 0.0); glRotatef(angle, 0, 1, 0); glTranslatef(-0.5, 0.5, 0.5); glColor3f(0.5, 1.5, 1.0); glutSolidCube(1); glPopMatrix(); } else if (Count > 90) { angle = 0; Count = 0; } else { sDirection = false; } } else { } } glPopMatrix(); glutSwapBuffers(); } void SpecialKey(unsigned char key, int x, int y) { switch (key) { case 'r': //condition for next check if (sDirection == true) { angle++; glutPostRedisplay(); Count++; cout << "angle " << angle << " count " << Count << endl; } else { glutPostRedisplay(NULL); } break; } } void OpenGLCallBackAnimation(void) { GLSettings0.PickObject = PickObject0; OpenGLInitialize(0, GLSettings0, 300, 150, 1000, 650, "window"); glutDisplayFunc(Display); glutMouseFunc(MouseButton); glutMotionFunc(OnMouseMotion); glutPassiveMotionFunc(PassiveMotion); glutKeyboardFunc(SpecialKey); //keyboard call glutMouseWheelFunc(OpenGLMouseWheel0); glutReshapeFunc(OpenGLReshape0); //glutTimerFunc(0, time_callback, 0); OpenGLPostprocessor(GLSettings0); }
  3. tamlam

    Change Animation in OpenGL

    Thanks for your great source. I will study this tutorial.
  4. tamlam

    Change Animation in OpenGL

    Thanks, GoliathForge. I got these ideas. However, I think the problems related to the callback function. I am trying to fix this problem ^^ before changing to modern OpenGL. hi, I have just started the simple project with the old version. I can improve programming skill in computer graphics. After finishing this project, I may change to Modern OpenGL.
  5. tamlam

    Change Animation in OpenGL

    I see a problem that although pressing key 1 time, the displayCube(void) runs many times. So, if we use the for loop inside the the displayCube(void) function, the loop will run many times. for examples, when I press 'w' key, i variable will run from 0 to 5 many times, it means all cubes will appear. When I delete the for loop, it may work. How can we avoid it? with still using for loop inside display() function.
  6. tamlam

    Change Animation in OpenGL

    I have another problem below: If I press "w" there are 5 cubes will appear at the same time. How can I make 5 cubes in 5 times press the 'w' key? Would you please give comments. int countcube(0); bool presskey(false); void drawBox(int i) { glPushMatrix(); glTranslatef(i+0.5, i+0.5, 0.5); glColor3f(0.5,0.0, 1.5); glutWireCube(1); glPopMatrix(); } void displayCube(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ZERO); SetLight(); glPushMatrix(); for (int i(0); i < 5; i++) { drawBox(i); } glPopMatrix(); glutSwapBuffers(); } void keyCube(unsigned char key, int x, int y) { switch (key) { case 'w': if (presskey == true) { countcube++; glutPostRedisplay(); } else { } break; } }
  7. tamlam

    Change Animation in OpenGL

    Thanks so much again for sharing the great source. I will try to implement my code then can show here. I think that I need to improve the C++ knowledge in OpenGL, especially in 3D computer graphic.
  8. tamlam

    Change Animation in OpenGL

    Thanks so much. Can you please share your source code. I would like to test on my computer to see the result.
  9. tamlam

    Change Animation in OpenGL

    Thanks for comment. I tried but it did not work. The problem is that in order to roll a cube along its edge. There are some steps (just like youtube link : 1. translate the cube until the contact edge for rolling == Y_axis.) 2. rotate the cube with new coordinate (90 degrees) around Y_Axis. 3. translate the rotated cube to a new coordinate. When we do animation (only for rotation) we have to do 3 steps in OpenGL, how can I only show the rotation because it has to pass these 3 above steps?
  10. tamlam

    Change Animation in OpenGL

    Hi @GoliathForge, I can move to the world coord. then rotation then translation. However, it only has the final result (the new rotated cube) not the animation. I try to use the below function glutTimerFunc(0, Timer, 0); but it only happens for one rotation action. global float angle=0.0f; In the void Display(), rolling the cube with glRotatef(angle, 0, 0, 1); at the end of function with angle += 10. I do not know when I can call the function for translation. for the 1st action, I translated the lower right corner to (0,0,0) then rotates from 0 -90 degree for animation. then the 2nd action is wrong with the coordinate. In OpenGl when I used glutDisplayFunc(Display); it always calls back the Display() function that I could not modify the next action.
  11. Hello all, I am trying to do animation by rolling a cube (1x1x1) along x_Axis. I just want to roll this cube 90 degrees along the edge (parallel with y_Axis) in three times, then stop. Then rolling within 45 degrees. then stop. When I use OpenGL to do animation, it always rolls in cycle time. I do not know how to make the animation with different actions as I draw in the below image. Please give me advice or useful links to reference. Thanks a lot. rollingCUbe.bmp
  • 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!