help

Dear all¡G
Can I let arbitrarily point to be the origin of my scene??for example,when I scale an object it always scale with its object coordinate,can i scale with the origin of my scene??? sorry for my poor English…

Thanks in advance

yes; you just need to rearrange your coordinate system. For example… suppose you have a unit sphere (from glutSolidSphere) that you want to be scaled to 5 units (so the SPHERE has a radius of 5) and is it at (2.0, 0.0, 2.0) relative to the world origin. You’d have the transform like:

glLoadIdentity();
gluLookAt(); /* camera transform */

glTranslatef(2.0, 0.0, 2.0);
glScalef(5.0, 5.0, 5.0);

glutSolidSPhere(1.0);

this works because you’re scaling the object to a radius of 5 before you move it, so the scale origin is in the middle of the object (because thats how glutSOlidSphere is drawn. it doesn’t haev to be like this, tho’, so don’t assume that the origin is necessarily in the middle of the obj). we only translate AFTER we’ve scaled the object, which is why the scale is indepdent of the scene origin. (Remember that the transforms are POST multiplied, so the scale is actually done first, even though its last in the code.)

now, suppose you want to scale the teapot by (1.0, 2.0, 3.0) relative to the SCENE origin. you’d use:

glLoadIdentity();
gluLookAt(); /* camera transform */

glScalef(1.0, 2.0, 3.0);
glTranslatef(2.0, 0.0, 2.0);
glScalef(5.0, 5.0, 5.0);

glutSolidSPhere(1.0);

this works because we’ve scaled AFTER we’ve translated the sphere to its point in the scene!!

hope this helps!

cheers,
John

Thanks John!But if my object is translated to some place and my object coordinate translated too.and now I want my scene to scale with the center of my scene(object is not at my scene center,Do just as CAD-System zoom…)How can i do??? Thanks again!!

hmmm if you want to scale your entire scene, you just shoukd translate yourself backwards and everything gets scaled…

yer, like whatshisname said, you need to do some tricky translating to get your coordinate system aligned with the middle of your object (or, whatever you want to pivot on, which isn’t necessarily the middle (after all=))

okay. suppose you had a cube bound by 0…1 (instead of bounded by -1.0 … 1.0, so the origin lies in the middle), then you’d need to translte the cube back by -0.5 so the origin is in the middle. like so:

glLoadIdentity();

glScalef(10.0, 10.0, 10.0); /* scale the SCENE by 10 /
glTranslatef(1.0, 2.0, 3.0); /
move the cube to its position in the scene /
glScale(5.0, 5.0, 5.0); /
scale the cube on its local axis /
glTranslatef(-0.5, -0.5, -0.5); /
compensate for off-centre alignment */

cheers,
John