Scale in a 3D world

Started by
8 comments, last by GalaxyQuest 22 years, 4 months ago
I am gonna be programming a Terrain demo in 3d(opengl) and probably for sake of simplifying my life i will use Quake2(md2) models to represent humaniod figures. How do i determine scale for all the different objects in my game??? - Ill have a map(maybe an island that i want realistic distances...say 1 mile long), quake human models, trees of some sort, etc etc etc. Do i just pic a model and base all scaling off that model...im not sure. Scale is important for how phsyics should behave, i believe, since such things as gravity and flying objects(like arrows) need some calculations for how far they can move relative to the scaled world. Please help. thnx! (and have a nice thanksgiving)
Advertisement
Scale is really 100% relative in OGL. As far as i see it doesnt matter much how may units a meter is, as long as the floating values are precise enough (which shouldnt be a problem).

You should scale your models before runtime though, since scaling uses quite may ticks if you do it every frame.
and as for the physics, you can scale that too. gravity is 32 feet/sec/sec; if a unit in your scaled world is one foot, gravity is 32 units/sec/sec; if a unit is two feet, gravity is 16 units/sec/sec; et cetera.

--- krez (krezisback@aol.com)
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
Krez: so when you say "unit" do you mean "1.0f"?

NewDeal: Is saving the scale of an object before the game starts trivial or is there a lot to it. For example, once i load a quake2 model, do i just scale it accordingly at the beginning and thats it?

All: Ok, but part of my question was missed, or maybe im not fully getting it. Lets look at the note that i may use quake2 models.

I am assuming that i will need to load these up in opengl just to "see" how large they are in opengl and so to say compare them to a measuring stick of sorts to find out how big they are to my unit(1.0f)?

Wont there be a lot of guess/scale fiddling work to make this model of correct size? Will I need to do this with every model i create(in say Milkshape). I am guessing that the models created in somthing like milkshape should already be the scale I want, or a factor of the scale? Do you guys understand what im trying to find out here?
It *is* trivial

What i did in my terrain-demo was to simply set 1.0 OGL units to a meter. Humanoid models would the be somewhere around 1.8 units tall (1.8 ms3d units as well). Gravity would still accelerate at 9.82units/s/s etc (gravity is 9.82 m/s/s). But as i said earlier, its all relative, as long as you stick with your original decisions throughout the program you''ll be ok. Choose something which makes sense to you (feet/inches id guess).

Im not sure how you load your models. What i usually do, is to simply import the coordinates given in the Milkshape file. This enables you to control the size from your modelling software, and no need for unnescessary scaling during runtime.
Alternatively (probably better) you could implement some sort of scaling in your loader (just multiply each coordinate with a constant).

One last thing, im not sure entirely how much effort scaling takes but ive been taught to avoid it when possible. Any thoughts on this ?


(I preface this with stating that I could be wrong about how OpenGL implements transformations).

If you are talking about scaling in 3-D space, I wouldn''t worry too much about performance. You''re going to have to translate and rotate your model anyway, so adding scaling to the transformation won''t make much difference.

When you transform in 3-D, you first calculate the composite transformation matrix for the model. In the case of displaying an object such as an MD2, you would FIRST multiply three matricies together (a translation matrix, a scaling matrix, and a rotation matrix), which would be two matrix multiplications (which is actually several additions and multiplications). After that matrix is calculated (usually once for frame), it is multiplied by every vertex in your model. If you have N verticies, that will be N+2 matrix multiplications, as apposed to N+1 if you left scaling off. They''re both O(N), so there shouldn''t be much of a difference.

I tend to make all of my objects fit in a bounding box from <-1,-1,-1> to <1,1,1> centered at <0,0,0>. Then I scale to the size I think that object should be. If I had a person that I thought should be 1.8 meters, I would scale by <1.8, 1.8, 1.8>. If I had a giant that should be 50 meters, I could scale that same model by <50, 50, 50>.

Of couse this is a personal preference, but it makes perfect sense to me. It also makes small adjustments to the sizes of your objects easy to do (I work better in C++ than I do in 3D modeling software, so that is why I do it that way).

Now in 2-D graphics, scaling is a slow transformation (then again so is rotation).

-- MattJ
Just make 1.0f units = 1 metre, or a foot, anything that makes sense to you.

What I''m doing in my program is that every 10 units is a metre, and I leave the actual "scaling" up to my modelling program (ms3d), i just make the model''s height = 18 for a normal person, maybe 22 for a big person, 200 for a giant dragon, and let''s say 20000 units wide for a 2 kilometer island.

The only problem that might arrise is if you''re using a map editor that needs a certain scale, then you can just make your models bigger accordingly.

Ok, you guys are giving some good advice, thanks.

As for Milkshape, I havnt tested this but I thought one of you said that 1 "unit" in Milkshape == 1.0f in opengl. Can any of you confirm this or have confirmed this??

Although I will probably test both methods(1 - using Milkshape to do the scaling, and 2 - use opengl to perform scaling) I am leaning more towards having the Modeler do more of this work. I just got to find out the ratio between 1 unit in Milkshape and 1 unit in OpenGL. Which is why i ask the question above. Who knows, maybe after testing Ill go for doing the scaling in Opengl, like MattJ said.
quote:
As for Milkshape, I havnt tested this but I thought one of you said that 1 "unit" in Milkshape == 1.0f in opengl. Can any of you confirm this or have confirmed this??


Hehe, one more try Lets try an example.

Say we''re modelling a B52 bomber in Milkshape (could be any modelling software). We decide that this machine should have a wingspan of 50 metres. To make thing easy for ourselves we center the model at (0,0,0) and extend the wings 50 units out to each side (100 units for 2 wings). The bomber was 50 metres wide, so if everything has to add up 1 unit in Milkshape is now defined as 0.5m.

When we output the model to a file the wingtips will be given by to vertices (50, 0, 0) and (-50, 0, 0). Import this to OGL and the vertices are still (50, 0, 0) and (-50, 0, 0). The bomber though, we decided to be 50m wide which means, if things should add up, that 1 unit in OGL is now defined as 0.5m.

The size of every other model you import now only has meaning compared to the bomber. Its all about definitions.

Have fun
Got it. Thanks.

This topic is closed to new replies.

Advertisement