| View previous topic :: View next topic |
| Author |
Message |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Fri May 19, 2006 8:36 pm Post subject: Scaling models... easy but where is my fault? |
|
|
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: | 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( unsigned long idx = 1; idx<lmesh.vertexCount; idx++ )
{
minX = min(minX, lmesh.verticesV3[idx].x);
minY = min(minY, lmesh.verticesV3[idx].y);
minZ = min(minZ, lmesh.verticesV3[idx].z);
maxX = max(maxX, lmesh.verticesV3[idx].x);
maxY = max(maxY, lmesh.verticesV3[idx].y);
maxZ = max(maxZ, lmesh.verticesV3[idx].z);
}
// resize values
sizeX = maxX - minX;
sizeY = maxY - minY;
sizeZ = maxZ - minZ;
// write new values
for (unsigned int i=0;i<lmesh.vertexCount;i++)
{
lmesh.verticesV3[i].x = (lmesh.verticesV3[i].x/sizeX)*scaleX;
lmesh.verticesV3[i].y = (lmesh.verticesV3[i].y/sizeY)*scaleY;
lmesh.verticesV3[i].z = (lmesh.verticesV3[i].z/sizeZ)*scaleZ;
} |
_________________ "Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com |
|
| Back to top |
|
 |
groepaz

Joined: 01 Sep 2005 Posts: 305
|
Posted: Fri May 19, 2006 8:52 pm Post subject: |
|
|
| Code: | 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; |
that somehow looks wrong to me (min and max will be same)
anyway, any reason why you dont use a matrix to scale? _________________ http://www.hitmen-console.org
http://hitmen.c02.at/files/yapspd/ |
|
| Back to top |
|
 |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Fri May 19, 2006 9:02 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
groepaz

Joined: 01 Sep 2005 Posts: 305
|
|
| Back to top |
|
 |
ufoz
Joined: 10 Nov 2005 Posts: 86 Location: Tokyo
|
Posted: Fri May 19, 2006 9:08 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
gsus
Joined: 11 May 2006 Posts: 5
|
Posted: Sat May 20, 2006 4:56 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Sat May 20, 2006 5:44 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Saotome

Joined: 03 Apr 2004 Posts: 182
|
Posted: Sat May 20, 2006 6:29 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Sat May 20, 2006 6:34 am Post subject: |
|
|
yeah! thats was my fault!
thanks :)) _________________ "Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com |
|
| Back to top |
|
 |
|