Jump to content
  • Advertisement

tamlam

Member
  • Content Count

    16
  • Joined

  • Last visited

Community Reputation

0 Neutral

About tamlam

  • Rank
    Member

Personal Information

  • 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.
  3. Hi @DerTroll and @Green_Baron Here is my code //OctVoxel is a class that saved the centers of cubes //Draw3DcoordArrowGL is used to draw three arrows ox oy oz from cube centers void DrawOXarrow(CVector3d currentCoord, GLdouble D) { GLdouble x1 = currentCoord.x; GLdouble y1 = currentCoord.y; GLdouble z1 = currentCoord.z; GLdouble x2 = currentCoord.x + 0.5; GLdouble y2 = currentCoord.y; GLdouble z2 = currentCoord.z; double x = x2 - x1; double y = y2 - y1; double z = z2 - z1; double L = sqrt(x*x + y * y + z * z); GLUquadricObj *quadObj; glPushMatrix(); glTranslated(x1, y1, z1); if ((x != 0.) || (y != 0.)) { glRotated(atan2(y, x) / RADPERDEG, 0., 0., 1.); glRotated(atan2(sqrt(x*x + y * y), z) / RADPERDEG, 0., 1., 0.); } else if (z < 0) { glRotated(180, 1., 0., 0.); } glTranslatef(0, 0, L - 4 * D); quadObj = gluNewQuadric(); gluQuadricDrawStyle(quadObj, GLU_FILL); gluQuadricNormals(quadObj, GLU_SMOOTH); gluCylinder(quadObj, 2 * D, 0.0, 4 * D, 32, 1); gluDeleteQuadric(quadObj); quadObj = gluNewQuadric(); gluQuadricDrawStyle(quadObj, GLU_FILL); gluQuadricNormals(quadObj, GLU_SMOOTH); gluDisk(quadObj, 0.0, 2 * D, 32, 1); gluDeleteQuadric(quadObj); glTranslatef(0, 0, -L + 4 * D); quadObj = gluNewQuadric(); gluQuadricDrawStyle(quadObj, GLU_FILL); gluQuadricNormals(quadObj, GLU_SMOOTH); gluCylinder(quadObj, D, D, L - 4 * D, 32, 1); gluDeleteQuadric(quadObj); quadObj = gluNewQuadric(); gluQuadricDrawStyle(quadObj, GLU_FILL); gluQuadricNormals(quadObj, GLU_SMOOTH); gluDisk(quadObj, 0.0, D, 32, 1); gluDeleteQuadric(quadObj); glPopMatrix(); } void Draw3DcoordArrowGL(int rotAngle, double Xcoord, double Ycoord, double Zcoord, double Xdir, double Ydir, double Zdir, GLdouble D) { CVector3d temp; temp.x = Xcoord; temp.y = Ycoord; temp.z = Zcoord; glTranslatef(Xcoord, Ycoord, Zcoord); glRotatef(rotAngle, Xdir, Ydir, Zdir); DrawOXarrow(temp, D); DrawOYarrow(temp, D - 0.02); DrawOZarrow(temp, D + 0.02); glTranslatef(-1.5, 0.5, 0.5);//const } void DrawCubeRolling() { OctVoxel cb = newCube[numberCube]; //only for cube rolling right-up or left-up for (int a = 0; a < cubeNum; a++) { if (newCube[a].getSelected()) { glPushMatrix(); glLineWidth(1.9f); std::cout << "+++++++++++ right ++++++++++++ " << std::endl; if (newCube[a].getRightRolling()) { //for Right rolling direction glTranslatef(cb.getCoordX() - 0.5, cb.getCoordY() - 0.5, 0.0); glRotatef(angleRotation, cb.getDirectionX(), cb.getDirectionY(), cb.getDirectionZ()); glTranslatef(-0.5, 0.5, 0.5);//const glColor3f(0.5, 0.5, 1.0); glutSolidCube(1); Draw3DcoordArrowGL(angleRotation, cb.getCoordX() - 0.5, cb.getCoordY() - 0.5, 0.0, cb.getDirectionX(), cb.getDirectionY(), cb.getDirectionZ(), 0.02); } else { //for up rolling direction - no need now std::cout << "------------ up -----------" << std::endl; } glPopMatrix(); } } if (angleRotation >= 90) { newCube[numberCube].setSelected(false); //cb will stop numberCube += 1; //move to next cb numberCube %= cubeNum; newCube[numberCube].setSelected(true); angleRotation = 0; } } //-------- When I make //Draw3DcoordArrowGL to comments in void DrawCubeRolling() {..}, the cube rolls along its edges perfectly without rolling 3 arrows. The problem is that glutSolidCube(1) is a function from OpenGl that I could not add or change anything.
  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[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.
  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. tamlam

    Change Animation in OpenGL

    Thanks for your great source. I will study this tutorial.
  9. 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.
  10. 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.
  11. 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; } }
  12. 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.
  13. 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.
  14. 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?
  15. 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.
  • 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!