 16

0 Neutral

• Rank
Member

• Interests
Programming

Recent Profile Visitors

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

1. Thanks @taby. I am reviewing my code again and upload to github.
2. Sorry I can not publish the code at this moment. Which part do you need to clarify? Please let some feedbacks from the above source which relates to my problem.
4. Hi Baron, thanks for reply. I understand your answer, but you may not understand what I mean. Let me clarify again. I COULD do rotate the cube through the edge. Right rolling: 1st center XYZ (X-right, Z-up, -back) 2nd center X-down, Z-right, Y-back 3rd center: X-left, Z-down, Y-back..... My problem: although I see the coordinate system rotate,1st, 2nd, 3rd center are still (X-right, Z-up, -back) Whenever I call DrawArrow function, it always draws oxyz.
5. Hello. I attached the picture below to describe my problem. I am using OpenGL to do an animation about rolling 3D coordinate OXYZ from A to B to C. Input: coordinate of cube: (0,0,0), (1,0,0) , (2,0,0), the cube rolling along its edge so the coordinate of cube center will rotate along the curve as the dash line. Problem: I created a function call DrawCoordSystem to draw Oxyz of the cube center. I could do rolling from 1st position to 2nd position; HOWEVER, at the 2nd rolling, when I call the DrawCoordSystem it will create oxyz within the same orientation (at the wrong way in the image) I do not know how to save the orientation of oxyz after the 1st rolling. Please help me to comments on the solution. Thanks a lot
6. 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 = (x0, y0, 0); and true for rolling aside with x_axis //cube.cubeCenter = (x1, y1, 0); and true for rolling aside with x_axis //cube.cubeCenter = (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.
7. 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); }
8. Thanks for your great source. I will study this tutorial.
9. 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.
10. 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.
11. 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; } }
12. 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.
13. Thanks so much. Can you please share your source code. I would like to test on my computer to see the result.
14. 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?
15. 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.