Scaling models... easy but where is my fault?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Scaling models... easy but where is my fault?

Post by LuMo »

i just want to scale a model for psp to fit the screen
using the code below does scale, but it does not keep aspect ratio

if someone finds my mistake please point me towards it

Thanks in Advance
lumo

Code: Select all

minX = lmesh.verticesV3[0].x; // init...
        minY = lmesh.verticesV3[0].y;
        minZ = lmesh.verticesV3[0].z;
        maxX = lmesh.verticesV3[0].x;
        maxY = lmesh.verticesV3[0].y;
        maxZ = lmesh.verticesV3[0].z;

        for&#40; unsigned long idx = 1; idx<lmesh.vertexCount; idx++ &#41;
        &#123;
          minX = min&#40;minX, lmesh.verticesV3&#91;idx&#93;.x&#41;;
          minY = min&#40;minY, lmesh.verticesV3&#91;idx&#93;.y&#41;;
          minZ = min&#40;minZ, lmesh.verticesV3&#91;idx&#93;.z&#41;;
          maxX = max&#40;maxX, lmesh.verticesV3&#91;idx&#93;.x&#41;;
          maxY = max&#40;maxY, lmesh.verticesV3&#91;idx&#93;.y&#41;;
          maxZ = max&#40;maxZ, lmesh.verticesV3&#91;idx&#93;.z&#41;;
        &#125;	    	
				// resize values
				sizeX = maxX - minX;
				sizeY = maxY - minY;
				sizeZ = maxZ - minZ;
				
				// write new values
				for &#40;unsigned int i=0;i<lmesh.vertexCount;i++&#41;
				&#123;
					lmesh.verticesV3&#91;i&#93;.x = &#40;lmesh.verticesV3&#91;i&#93;.x/sizeX&#41;*scaleX;
					lmesh.verticesV3&#91;i&#93;.y = &#40;lmesh.verticesV3&#91;i&#93;.y/sizeY&#41;*scaleY;
					lmesh.verticesV3&#91;i&#93;.z = &#40;lmesh.verticesV3&#91;i&#93;.z/sizeZ&#41;*scaleZ;
				&#125; 
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
User avatar
groepaz
Posts: 305
Joined: Thu Sep 01, 2005 7:44 am
Contact:

Post by groepaz »

Code: Select all

        minY = lmesh.verticesV3&#91;0&#93;.y; 
        minZ = lmesh.verticesV3&#91;0&#93;.z; 
        maxX = lmesh.verticesV3&#91;0&#93;.x; 
        maxY = lmesh.verticesV3&#91;0&#93;.y; 
        maxZ = lmesh.verticesV3&#91;0&#93;.z;
that somehow looks wrong to me (min and max will be same)

anyway, any reason why you dont use a matrix to scale?
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

this (the code you marked) only sets the initial values;
i do not use a matrix cause i scale the model before i load it to psp
so the calculation is just to resize while model is on PC
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
User avatar
groepaz
Posts: 305
Joined: Thu Sep 01, 2005 7:44 am
Contact:

Post by groepaz »

ah ok i see. cant see an obvious error then either *shrug*

tried with a simple modell (like a cube) ? thats what i usually do to see what really happens
ufoz
Posts: 86
Joined: Thu Nov 10, 2005 2:36 am
Location: Tokyo
Contact:

Post by ufoz »

It doesn't keep the aspect ratio because you're normalizing the entire model into the (-1,1) cube and then scaling that with scaleX,Y,Z
So your output will have the same ratio that scaleX,Y,Z have.
gsus
Posts: 5
Joined: Thu May 11, 2006 11:08 pm

Post by gsus »

seawas...

your model is between [min max]
tranform it first, so the midpoint is at coordinate origin
widht pos = pos-(max+min)/2, so its between [-(min+max)/2 (min+max)/2]
now you can scale it with pos = pos*2*scale/size.. and your is in [-scale scale]

also it might depend on your projecion matrices..

regards, gsus
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

my model is already centered (done before)
i changed the code today, did not test the result, if mine fails again, ill try yours; let you know later
thanks for help
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
User avatar
Saotome
Posts: 182
Joined: Sat Apr 03, 2004 3:45 am

Post by Saotome »

If you didn't already solve it, your problem seems to be, that you're scaling each aixs with it's maximum (i.e. each axis with a different value). But you should scale all axes with just one maximum. -> find the max of sizeX,sizeY and sizeZ, and scale by that one value.
infj
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

yeah! thats was my fault!
thanks :))
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
Post Reply