Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 23

Thread: Need help for animation

  1. #11
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,104
    Why are you doing this?
    Code :
    glTranslatef(gCameraTranslationX,gCameraTranslatio  nY, 0);
    glMultMatrixd(gCameraRotation); 
    glScaled(gCameraScale, gCameraScale,gCameraScale);


    You have already placed your camera in the world with the
    gluLookAt, now you are moving the world.

  2. #12
    Junior Member Regular Contributor
    Join Date
    Jun 2010
    Posts
    162
    Now I am getting some output by setting camera at v0 and center at v2 by adjusting near and far plane in gluPerspective (last time it was too away from camera). I have attached the output. The matrix transformation is unit. So it is actually not making any change in the output. I kept it for mouse based interaction.

    Click image for larger version. 

Name:	model2.jpg 
Views:	55 
Size:	11.9 KB 
ID:	949
    But the result is not ok, I want to see the image centered, but I am getting it partially. As I keep on moving by pressing a key making the center point as camera and center as the next vertex, the output is worse. sometimes ou of the model. I understand I need to finetune the alignment between v0v1 and v1v2 and so on. Please give me some suggestion. Thank you for cooperation from the beginning.

  3. #13
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,104
    Your probelms now are probably fine tuning. If is possible that the direct line from the camera vertex to the center vertex is actually cutting through the model. Also you image on the screen will not be square if the window is not square - that is a circle will look like an oval. This can be fixed but I would ignore it for the moment and just make the window square. Try adjusting the FOV in the perspective camera .

  4. #14
    Junior Member Regular Contributor
    Join Date
    Jun 2010
    Posts
    162
    I have made the window square. Now when I move, I find the camera in the middle of the screen, by adjusting fovY and near plane. But most of time I could see side, roof or floor of the tunnel as shown in my first picture, very few times, I can see the whole boundary as shown in the second picture. How can that be adjusted?

    Click image for larger version. 

Name:	image2.jpg 
Views:	57 
Size:	9.3 KB 
ID:	950 Click image for larger version. 

Name:	image3.jpg 
Views:	58 
Size:	11.6 KB 
ID:	951

  5. #15
    Junior Member Regular Contributor
    Join Date
    Jun 2010
    Posts
    162
    I have managed to get better output by adjusting the FOV. Thanks for the suggestion.

  6. #16
    Junior Member Regular Contributor
    Join Date
    Jun 2010
    Posts
    162
    I need some suggestion about creating animation. i.e. how to process camera with time, and how to modify the path if necessary when the camera traverses a particular distance. Thanks in advance.

  7. #17
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,104
    Ok to move the camera for an animation you need to know the scale of your model; that is, is 1 unit on mesh equal to 1 cm, or 1 m etc. Once you know that you have to think about how far you want the camera to move in 1 second - say 1cm (might be too slow) or 1m (probably to fast).

    Lets say we have a scale of 1 mesh unit = 1 cm. and we want to move the camera 5 cm in a second; then the new camera = old camera + 5 * ||direction||. See my earlier post on how to choose a direction.

  8. #18
    Junior Member Regular Contributor
    Join Date
    Jun 2010
    Posts
    162
    Hi,
    In previous posting, there were following three options:
    1.center can remain along the vector you are currently travelling and you jerk around the corner as you swap vectors when the camera reaches the cornder - this is the easiest to do

    2.stop the camera at the corner and smoothly rotate the center around the corner vertex to the new align along the new vector before continusing along the new vector

    3. have your center go around the corner onto the new vector before the camera has arrived at the corner - this may look better but you have to consider how far ahead of the camera the center is so you don't try to look through the wall of the intestine.

    I think the third option is the best one. Suppose each secnd I travel 5 unit along the look at vector. Now my new point is:
    new_point = camera + lookatvector*5;
    This new point is supposed be the next camera point and is most likely not on the path; Then my question is :
    how can I choose next camera and center? How can the new vector be found?

    I think I can go around the corner by checking the next vector and the angle between two consecutive vectors. But again my new point may not on the line. Then how to keep on proceeding along the path?

    Now this way my original path lmay not be maintained. Then what would be the end condition of traversal?

    Help me clarify the above issues.

  9. #19
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,104
    Thw third option is clearly the hardest. You have to choose a distance the center point is ahead of the camera. If you make it too far you will try to look through the sides of your model. You also have to follow that path across a vertex. If you path is simple set of lines this is quite straight forward.
    Here is the pseudo code

    assume path is V1,V2,V3; camera is at E and center is at C both somewhere along V1-V2

    the distance to move of D = time * velocity.

    new center is
    if D > ( V2-C)
    C = ||V3-V2|| * (D - (V2-C))
    else
    C = ||V2-V1|| * D

    new camera is
    if D > (V2-E)
    E = ||V3-V2|| * (D - (V2-E))
    else
    E = ||V2-V1|| * D

    Note that you should allow for D > (V2-C)+(V3-V2) etc


    If you are using a curved path you approximate it with a set of line vectors

  10. #20
    Junior Member Regular Contributor
    Join Date
    Jun 2010
    Posts
    162
    Thanks. At first I need to find the whole path length and the traversal time which I need to fix by myself. Then traverse the path at a const. velocity. And for each pair of vertices, I need to check the above algorithm. But I didn't understand why I need to have D > (V2 - C) + (V3 - V2). Could you clarify a bit.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •