View Full Version : glscale problem

amhigh

06-12-2002, 08:27 PM

Hi, Everyone:

I have two questions need helps, they are both related to glScaled.

1>Suppose I read an object from a file, and when I draw this object on

the graphics window, how do I know what is the value should I use to

glScaled(value,value,value) so that the object can be drawn to fit

the graphics window? I use glOrtho.

2>Suppose an object is drawn in the graphics window, and the user would

like to zoom in part of the object, so the user use the rubberband to draw

a rectangle area over the object. How can I bring the selected part

of that object to fit the entire graphics window?

Thanks for any hints and suggestions.

1. While reading the model, keep track of min/max xyz and calculate the required scaling based on those values.

2. Once you have the min/max screen xy of the rubberband rectangle, recalculate the world xy(z) bounds based on those values. When using glOrtho this is simple.

BTW zooming is easier to implement by taking the mouse position as the new viewing center and using a zoom factor (like 1.1, 1.5 or whatever). Shift-clicking can be used to zoom-out by a factor 1/(zoom-in factor).

HTH

Jean-Marc.

amhigh

06-13-2002, 09:08 AM

Originally posted by JML:

1. While reading the model, keep track of min/max xyz and calculate the required scaling based on those values.

2. Once you have the min/max screen xy of the rubberband rectangle, recalculate the world xy(z) bounds based on those values. When using glOrtho this is simple.

BTW zooming is easier to implement by taking the mouse position as the new viewing center and using a zoom factor (like 1.1, 1.5 or whatever). Shift-clicking can be used to zoom-out by a factor 1/(zoom-in factor).

HTH

Jean-Marc.

Thanks, Jean-Marc:

For the first question, you simply say "recalculate the require scaling...", how can I do that? Let say, I know the dimension of the glOrtho (say, x1,x2,y1,y2,z1,z2), and the bounding box of the model (say, mx1,mx2,my1,my2,mz1,mz2), how can I recalculate the factor for glScale so that the model can fit the entire graphics windows? Should I forget the z factor (the z1,z2,mz1,mz2)?

2>When I have the device coordinate of the rubberband, I should convert them to world coordinate (the same coordinate of the model), then do as the first step to figure out the scaling factor?

Please help, thanks.

ioquan

06-13-2002, 11:32 AM

If you have your orthographic projection set up and the model's bounding box, scaling it to fit the window is simple. Note that scaling is just multiplying each vertex by a scalar. If the model's bounding box is twice as big as the viewing volume, you just scale it by 1/2. So its viewing_volume/bounding_box.

If you want to do OpenGL, you're going to need to learn how to solve simple mathematical problems like this.

amhigh

06-13-2002, 12:28 PM

Originally posted by ioquan:

If you have your orthographic projection set up and the model's bounding box, scaling it to fit the window is simple. Note that scaling is just multiplying each vertex by a scalar. If the model's bounding box is twice as big as the viewing volume, you just scale it by 1/2. So its viewing_volume/bounding_box.

If you want to do OpenGL, you're going to need to learn how to solve simple mathematical problems like this.

Thanks for pointing out this is a simple math problem.

But I guess you might mis-understand my question. I don't want change my model by multiplying any value to its vertics, instead, I like to know how can I use the glScale(value,value,value) to change the transformation matrix, so that the model object can be shown properly in the graphics windows.

Let say the Ortho Volume (X:-10 to 10, Y:-10 to 10, Z:-1000 to 1000), and the bounding box of the object is (X:-5 to 5, Y:-5 to 5, Z:5 to 5), now you see the formula you gave me will end up (20*20*2000)/(10*10*0) = inf?

Ok, now look at the other case, suppose my model object has (X:-5 to 5, Y:-5 to 5, Z:-5 to 5), now according to your fomula, I will have (20*20*2000)/(10*10*10) = 800, either I time 800 or 1/800 to the vertics of the model object, I don't think the model object will fit as much as possible in the graphics window? Am I doing something wrong?

Sorry I just new, Can anyone tell me what I did it wrong?

Thanks.

ioquan

06-13-2002, 12:39 PM

Using glScale is the same thing as multiplying all your verts by a scalar.

Multiplying a point by a scalar is defined like this:

point(x,y,z) * scalar =

point(x*scalar,y*scalar,z*scalar).

If you dont want the object to be distorted by the scaling, here is what you do.

1. scalar = (viewtop - viewbottom)/(modeltop - modelbottom)

2. Now glScale(scalar, scalar, scalar);

[This message has been edited by ioquan (edited 06-13-2002).]

amhigh

06-13-2002, 12:52 PM

------------------------------

Originally posted by ioquan:

Using glScale is the same thing as multiplying all your verts by a scalar.

--->Thanks,

Multiplying a point by a scalar is defined like this:

point(x,y,z) * scalar =

point(x*scalar,y*scalar,z*scalar).

--> I understand this too. Thanks,

If you dont want the object to be distorted by the scaling, here is what you do.

1. scalar = (viewtop - viewbottom)/(modeltop - modelbottom)

2. Now glScale(scalar, scalar, scalar);

-->No, I don't want my model object be distorted! But I like the whole bounding box of the model object be shown in the graphics windows! ie, the model object is shown ENTIRELy in the graphics window, no cut or anything.

Did I explain anything wrong for the example I show (the Ortho Volume and the Bounding box stuff)???

Thanks.

ioquan

06-13-2002, 01:57 PM

Well the steps I gave you should work for what you are trying to accomplish. Did you try it?

Actually, it doesnt take into account the x coordinates. It only scales it so the y coordinates are within the y range of the viewing volume. You can add a couple extra steps to take the x values into consideration.

float scalar,scalary,scalarx;

scalary = (viewtop-viewbottom)/(modeltop-modlebottom);

scalarx = (viewright-viewleft)/(modelrigght-modelleft);

//take the smaller of the two scalars

if (scalary < scalarx)

scalar = scalary;

else

scalar = scalarx;

glScale(scalar,scalar,scalar);

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