Jump to content

  • Log In with Google      Sign In   
  • Create Account


Some question about transformation


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
11 replies to this topic

#1 jenny_wui   Members   -  Reputation: 196

Like
0Likes
Like

Posted 08 April 2014 - 04:59 PM

Hello, I think my previous postings were a bit confusing. I just wanted to clarify that in this posting. I have a plane and attached figure shows two positions of the plane, (a) no rotation and (b) with rotation where rotation axis is defined by ax + by + cz.

Now, the plane will rotate, but it will always look without rotation as shown in figure (a).

I think I need to play around with my glutReshape function which looks like follows:

/*******************************/
void glutReshape(int width, int height)
{

width = glutGet(GLUT_WINDOW_WIDTH);
height = glutGet(GLUT_WINDOW_HEIGHT);

if (width && height)
{
glViewport(0, 0, width, height);

nearDist = 150.0 / tan((kFovY / 2.0) * kPI / 180.0);
farDist = nearDist + 100.0;
aspect = (double) width / height;

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(kFovY, aspect, 0.1, farDist+20);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

gluLookAt( 0.0, 0.0, (nearDist + 5.0), // camera/ eye
0.0, 0.0, 0.0, // center
0.0, 1.0, 0.0); // up vector

}
}
/*******************************/
But I fail to correctly manipulate it. When rotation axis will move from (0, 0, 1) to (ax + by + bz), the eye/ camera will be changed from ( 0, 0, nearDist +5) to {(nearDist+5)*ax, (nearDist+ 5)*ay, (nearDist + 5)*az}. Is it right?

But what about the up vector? How will it change for this rotation? How can I calculate new up vector? Also what other parameters in my glutReshape function needs to be changed?

Please provide me some suggestion so that I can fix this problem.

Thanks in advance.

Attached Thumbnails

  • plane.png


Sponsor:

#2 JohnnyCode   Members   -  Reputation: 206

Like
0Likes
Like

Posted 09 April 2014 - 10:50 AM

from what I am understanding, you wish to manipulate plane by rotating it not in its world transformation but in view transformation. You could effectively do this by making glulookat  matrix corespond to plane normal you have as the rotaion definition. In that case you can make eye-at vector to have the direction of that normal. Meaning, have lookat point to be the plane center (or so) always,  and compute eye position vector from lookat+rotationnormal*radius - lookat and rotationnormal are vectors and radius is a scalar. With this you would rotate around plane with distance of radius (if rotationnormal is unit vector)



#3 jenny_wui   Members   -  Reputation: 196

Like
0Likes
Like

Posted 09 April 2014 - 11:51 AM

Thank you very much for the reply. I think I have calculated the new eye point in my posting as you suggested. But how to find the new up vector? Please provide me some suggestion. Thanks

#4 DiegoSLTS   Members   -  Reputation: 994

Like
0Likes
Like

Posted 09 April 2014 - 11:51 AM

glut is not a graphical specification, is just for handling input and output.

 

glutReshape is intended for other things, it doesn't really care about what you're drawing, that callback is called when you reshape the window: http://www.opengl.org/resources/libraries/glut/spec3/node48.html

 

You can do whatever you want in that function, but it'll be called only once (when the window is created) if you don't change the size somehow. If you're reshaping your windows every frame based on what's inside ignore what I've said, but it sounds like a really weird idea for a game or an application.



#5 JohnnyCode   Members   -  Reputation: 206

Like
0Likes
Like

Posted 09 April 2014 - 03:31 PM

Thank you very much for the reply. I think I have calculated the new eye point in my posting as you suggested. But how to find the new up vector? Please provide me some suggestion. Thanks

you will set only eye and lookat vectors, keep the up vector constantly (0,1,0). Up vector does not have to change very likely in your case, changing up vector affects camera rotation around the (lookat minus eye) axis, what is the effect of rotating the very screen to left or right moment. It is rarely an intent. As I adviced, keep up vector (0,1,0) and lookat vector constant and compute the eye by formula I have provided- this will result in camera spectating the plane from the direction you have provided by the unit vector- if this is what will work for your intent.



#6 jenny_wui   Members   -  Reputation: 196

Like
0Likes
Like

Posted 09 April 2014 - 05:27 PM

Hi JohnnyCode, I have worked with only changing eye position calculating from new look at vector and used it in gluLookAt function, but the plane does not look square as it should be, it still looks trapezoidal like Figure (b). That's why I'm thinking whether I need to change other prameters in gluLookAt function. Suppose if the plane is rotated parallel to the xz plane, then still it should look like the picture inFigure (a). Then do you think only change in eye position will work, I don't need to change the up vector?

Please provide some suggestions.

Thanks in advance.

#7 JohnnyCode   Members   -  Reputation: 206

Like
0Likes
Like

Posted 09 April 2014 - 07:04 PM

that is the result of the projection matrix transformation being perspective. if you use orthogonal projection matrix, it will be like figure a. Orthogonal projection is simplified perspective projection. you shoud have a glut function for orthogonal perspective matrix building from parameters.

 

An identity matrix is an orthogonal projection matrix case  witth scale 1.0 in all three directions. Meaning that if you do not use projection transformation matrix at all (setting it to identity), it will be like using orthogonal projection with scale 1.0.



#8 jenny_wui   Members   -  Reputation: 196

Like
0Likes
Like

Posted 09 April 2014 - 07:46 PM

Thank you very much for the reply. Could you be a bit clearer, if possible with example? Do I really need to switch to glortho to accomplish this? I would like to use perspective projection. I think my view volume will be rotated in the latter case. I saw Nate Robbin's tutorial but a confused how to make it work.

#9 JohnnyCode   Members   -  Reputation: 206

Like
0Likes
Like

Posted 10 April 2014 - 11:46 AM

perspective projection will always result in deformation by depth, there is nothing to adress about this into view matrix.  All you can do is to set the object incredibly far- yet this will only minimize the effect. In case of precise observing, perspective matrix is never used. View frustum of a perspective matrix is a pyramid and it results in not "real" size of objects, while ortho projection view frustum is a cube/quad and it results in real size of objects when onserved, not dependant on distance from camera. Though this effect does not match real phenomena of observing, it is critical for architectural softwares or image manipulation softwares and genaraly softwares that need to see precise placing in all three directions.

 

you can switch from orthogonal projection to perspective projection though - at any time



#10 haegarr   Crossbones+   -  Reputation: 3991

Like
0Likes
Like

Posted 10 April 2014 - 12:27 PM

Perhaps the goal is to find a position and orientation for the camera (i.e. a view transform) so that the plane does not change w.r.t. the view space although it is changed in the world space? If so, then the math is as follows (I'm using matrices for transformations because problems like this can be described with matrices very compact; I further use column vectors as is common when dealing with OpenGL):

 

a) The initial situation is given by a world transform M0 of the plane and a view transform V0 of the camera. Then the transform of the plane in view space, i.e. its placement relative to the camera, is given as

     V0 * M0

It seems from the OP that M0 is just the identity matrix and V0 is just the inverse of a simple translation of the camera.

 

b) When the plane's transform is changed in world space to current Mi, you want a adapted view transform Vi. The transform of the plane in view space is again the product of both. However, you want the plane in view space to be the same as in the initial situation, hence

     Vi * Mi =  V0 * M0

Solving this for the unknown view transform gives

     Vi =  V0 * M0 * Mi-1

 

This result makes sense, because it undoes the current plane transform (see the inverse Mi) and lets the initials transform remain (see the V0 * M0 which is what we had in the beginning).

 

 

There are several ways of implementing the above solution. The best and future-proof way is to drop usage of OpenGL's matrix routines (with the exception of glLoadMatrix as long as you deal with the fixed function pipeline) inclusive the companion routines of GLU. Instead, use a math library like GLM and handle transforms yourself. As can be seen here, solving problems like this can easily be done in matrices (if matrices itself are understood, of course) but are seriously error-prone when using OpenGL directly.

 

Are you able to switch to using a matrix library yet, or do you really need to stick with OpenGL's matrix stack?


Edited by haegarr, 10 April 2014 - 12:29 PM.


#11 jenny_wui   Members   -  Reputation: 196

Like
0Likes
Like

Posted 10 April 2014 - 04:22 PM

Thank you very much for the reply Crossbones. I tried with changing the eye position calculated from rotation vector but don't understand why it is not working. I would like to use OpenGL. Could you provide any related examples? Also could be a more elaborate on how to change gluLookAt function?
Thanks again.

#12 steven katic   Members   -  Reputation: 270

Like
0Likes
Like

Posted 11 April 2014 - 03:40 PM

Hi jenny,

 

RE: " I saw Nate Robbin's tutorial but a confused how to make it work."

 

Thats not a good sign. You will be struggling with this until you do understand the fundamental concepts that Nate's samples are based on. Have you downloaded the examples and ran them?: Have you played around with the values in them to learn by doing and seeing the effects of changing parameters? You cannot get around doing something like this in order to grasp the fundamental knowledge you need to get to a solution. There are no short cuts. It is a matter of finding material suitable to the way you learn.

 

So here are a few things to try:

Search on terms like "opengl camera". there is lots of info around: only you know what will suit you.

Start by reading this: http://www.glprogramming.com/red/chapter03.html. Or even scanning it for (more hands on) examples to here:

http://www.glprogramming.com/red/chapter03.html#name8. This stuff is an example of the easiest/simplest and well explained info you must grasp before you try to solve your problem (otherwise you will continually be asking people to hold your hand on every little step of your journey into 3d graphics likely making very little progress).

 

Let us know if this helps


Edited by steven katic, 11 April 2014 - 04:04 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS