Public Group

# changing camera angle in a scene with lots of independent objects???

This topic is 4784 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hi to all i am new comer to this forum... i have lots of independent obnject in my scene which was actually 2d and every object have abilities such as rotating, dragging and etc. now i change my world to 3d and i want to change these rotate,drag,.. properties from any camera angle because now my camera is dynamic. the problem is i could not form the logic, what should i do to improve my 3d scene to 3d scene with dynamic camera... and a question: in my original 2d scene i use glLoadIdentity after rotating , transforming and drawing each object. now in 3d i think that glLoadIdentity cause a problem and i should use glpush/popmatrix. am i right or is it ok to use glLoadIdentity after every object drawing operation.

##### Share on other sites
Quote:
 Original post by ahmetyortanlihi to alli am new comer to this forum...i have lots of independent object in my scene which was actually 2d and every object have abilities such as rotating, dragging and etc.now i change my world to 3d and i want to change these rotate,drag,.. properties from any camera angle because now my camera is dynamic.the problem is i could not form the logic, what should i do to improve my 3d scene to 3d scene with dynamic camera...

If I understand your question correctly, you want to know how to:
- determine which object the mouse points to
- drag this object in the direction the mouse moves (which is within the x,y plane of the camera rather than object x,y plane)
- rotate this object using the camera space axis

Question one has two solutions. Use OpenGL picking or determine a ray shooting from the mouse into the scene and determine intersections with (bounding boxes of) selectable objects. Although the second option may sound much harder (due to math), it's actually preferrable IMO.
The other two questions can be solved by transforming the camera x,y and z-axis to object space (i.e. multipling (1,0,0), (0,1,0) and (0,0,1) with the transposed of the modelview matrix). You can then use these 3 vectors as a base for your rotations and translations, rather than the object axis. If you're not realy into vector math this might be tricky, but there is no 'math-free' solution.

Quote:
 Original post by ahmetyortanliand a question:in my original 2d scene i use glLoadIdentity after rotating , transforming and drawing each object. now in 3d i think that glLoadIdentity cause a problem and i should use glpush/popmatrix. am i right or is it ok to use glLoadIdentity after every object drawing operation.

Assuming you use the OpenGL matrix stack properly:
- you have a projection matrix (gluPerspective/glFrustum) on the projection stack and nothing else
- the first matrix you load on the modelview stack is the view matrix (e.g. gluLookAt)
- after this first matrix, you apply model specific transformations
In this setup it becomes clear that loading identity on the modelview stack after loading a model matrix is incorrect, because it will wipe out the view matrix you used. glPush and glPop are much better. A typical use would be:
// setup projection hereglMatrixMode(GL_MODELVIEW);gluLookAt(...);for all models{    glPushMatrix();      glTranslate(model.position);      glRotate(model.orientation);      glScale(model.scale);      model.draw();    glPopMatrix();}

Tom

##### Share on other sites
but i have no problem with object rotation and etc.
i am confused with rotation or dragging in different camera angles. in clear, when i change my camera position and rotate something , i think it rotates with respect to default camera view not for my new camera view (and same for dragging).

and thanks for answer of my second question. it really helps me.

##### Share on other sites
Quote:
 Original post by ahmetyortanlithanks for answeringbut i have no problem with object rotation and etc.i am confused with rotation or dragging in different camera angles. in clear, when i change my camera position and rotate something , i think it rotates with respect to default camera view not for my new camera view (and same for dragging).

I probably worded it ackwardly but that's what I ment to say. My solution, transforming the x,y,z camera axis to the object will solve precisely this problem. To elaborate on this solution:
The transposed modelview matrix, for a given object, transforms vectors from camera space to object space. The three axis of your camera expressed in camera space are always x:(1,0,0), y:(0,1,0), z:(0,0,1) by definition. This is true in all situations, no matter how your camera is positioned in the scene. When we multiply these vectors with the transposed modelview, they will be transformed to the coordinate system of a specific object. At that point you know what the direction of the camera x,y and z-axis are from the perspective of that specific object. So if your mouse moved 3% of the screen to the right (x-direction in camera space), the proper x-translation would be:
x-trans = 0.03 * x'.
x' is the transformed x-axis: x' = modelview.transposed() * vector(1,0,0).

There will definately be other solutions, but if you have limited experience with 3D vector/matrix math, they will all probably a bit tricky.

Tom

##### Share on other sites
ok. now i understand
thank you

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633736
• Total Posts
3013598
×