View Full Version : Better modifying the render or moving the camera?

elect

02-27-2012, 01:18 AM

Hi all,

Since I gogled for it without finding anything interesting, I would like to ask you for some suggestions regarding if it is better to scale/translate the render itself keeping the camera position fixed or maybe moving closer/further or rotate the camera keeping the render position fixed?

I need a zooming out/in, rotation in all the 3 axes and also this kind of rotation

http://www.reknow.de/downloads/opengl/capture-1.avi

that is, if I first translate my render and then I apply a rotation, this rotation should consider the center always the windows center, and not the translated one

menzel

02-27-2012, 02:23 AM

I'm not sure i understood you completely: So you ask if transformations of your objects are faster than transformations of your camera? Both will boil down to a single matrix multiplication of the vertices in model coordinates to view coordinates. So both is equaly fast.

elect

02-27-2012, 02:34 AM

I'm not sure i understood you completely: So you ask if transformations of your objects are faster than transformations of your camera?

(Sorry for my english) more or less, my question is more oriented on which is the best way in terms of implementation (that is, which is easier and clearer to implement).

My requirements are:

- zooming

- rotation over the 3 axes

- the rotation should always be performed taking the windows center, like the rotation center, even you translate/push the render away (the video explains this easier)

- I am rendering complex and big models, and that's why I would like that when the user clicks (with the middle mouse) on a point on the rendered model, that point automatically turns to be the windows center

To achieve all these transformations, which is better: moving the camera or the render/model/world?

menzel

02-27-2012, 04:39 AM

I would move the camera, but that's just personal taste. Also, zooming would change the FoV which is related to the camra and not the model. Although you probably don't want to zoom but to move closer to the object.

elect

02-27-2012, 09:25 AM

I would move the camera, but that's just personal taste. Also, zooming would change the FoV which is related to the camra and not the model. Although you probably don't want to zoom but to move closer to the object.

Ok..

By the way, how do I implement a rotation such as in the video?

http://www.reknow.de/downloads/opengl/video.mp4

elect

03-07-2012, 09:22 AM

Ok guys, actually I am stuck on my program since 2 days and I dont know what to do...

Right now, I am rendering a cylinder, I can pan and zoom using this:

display() {

...

glu.gluLookAt(translationX/gLAutoDrawable.getWidth()*scale*2,

-translationY/gLAutoDrawable.getHeight()*scale*2, 2,

translationX/gLAutoDrawable.getWidth()*scale*2,

-translationY/gLAutoDrawable.getHeight()*scale*2, 0,

...

}

I can also rotate using some custom functions:

display() {

...

glu.gluLookAt

...

gl.glMultMatrixf(currentRotation, 0);

...

}

mouseDragged() {

...

if(rotationMode) {

float newRotation[] = multiply(rotationX(-dy), rotationY(-dx));

currentRotation = multiply(currentRotation, newRotation);

rotationX +=dx;

rotationY +=dy;

}

...

}

private static float[] rotationX(float angleDeg) {

float m[] = identity();

float angleRad = (float)Math.toRadians(angleDeg);

float ca = (float)Math.cos(angleRad);

float sa = (float)Math.sin(angleRad);

m[ 5] = ca;

m[ 6] = sa;

m[ 9] = -sa;

m[10] = ca;

return m;

}

private static float[] rotationY(float angleDeg) {

float m[] = identity();

float angleRad = (float)Math.toRadians(angleDeg);

float ca = (float)Math.cos(angleRad);

float sa = (float)Math.sin(angleRad);

m[ 0] = ca;

m[ 2] = -sa;

m[ 8] = sa;

m[10] = ca;

return m;

}

private static float[] multiply(float m0[], float m1[]) {

float m[] = new float[16];

for (int x=0; x < 4; x++) {

for(int y=0; y < 4; y++) {

m[x*4 + y] = m0[x*4+0] * m1[y+ 0] +

m0[x*4+1] * m1[y+ 4] +

m0[x*4+2] * m1[y+ 8] +

m0[x*4+3] * m1[y+12];

}

}

return m;

}

This special rotation was mandatory because if I use glRotate to rotate my cylinder a first time over the horizontal plane, lets say, then my modelview coordinates rotates as well, and I dont want to have this, since I still need to rotate over the vertical axes

Now, the problem is that the rotation is performed taking the modelview origin as the rotation point...

This means that if I pan (aka move the camera) I would like to see a rotation over the center of my screen, and not the center of the modelview (that has been panned)

I hope it's clear, otherwise I can post something else to illustrate it better..

Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.