Domanda

I have 3 transformations in the following order and with the following variables:

glTranslate(dirX, dirY, dirZ);
glRotate(angleX, 1, 0, 0);
glRotate(angleY, 0, 1, 0);

With these, I'm able to transform my ModelView in 3D achieving several effects (translate object around space, rotate object around its center, zoom in and out from origin) .

With the same variables, and using gluLookAt(), I want to achieve the last 2 (rotate around center of object, zoom from origin)

È stato utile?

Soluzione

target = object_position
pos.x = zoom * sin(phi) * cos(theta);
pos.y = zoom * cos(phi);
pos.z = zoom * sin(phi) * sin(theta);

pos += target;

gluLookAt(pos, target, vec3(0, 1, 0)); // up vector is fixed...

The code above creates a 'camera' that is looking at the object centre and can rotate around (using spherical coords).

http://mathworld.wolfram.com/SphericalCoordinates.html

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top