forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

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

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Fri May 19, 2006 8:36 pm    Post subject: Scaling models... easy but where is my fault? Reply with quote

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
View user's profile Send private message Visit poster's website
groepaz



Joined: 01 Sep 2005
Posts: 305

PostPosted: Fri May 19, 2006 8:52 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Fri May 19, 2006 9:02 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
groepaz



Joined: 01 Sep 2005
Posts: 305

PostPosted: Fri May 19, 2006 9:06 pm    Post subject: Reply with quote

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
_________________
http://www.hitmen-console.org
http://hitmen.c02.at/files/yapspd/
Back to top
View user's profile Send private message Visit poster's website
ufoz



Joined: 10 Nov 2005
Posts: 86
Location: Tokyo

PostPosted: Fri May 19, 2006 9:08 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
gsus



Joined: 11 May 2006
Posts: 5

PostPosted: Sat May 20, 2006 4:56 am    Post subject: Reply with quote

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
View user's profile Send private message
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Sat May 20, 2006 5:44 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Saotome



Joined: 03 Apr 2004
Posts: 182

PostPosted: Sat May 20, 2006 6:29 am    Post subject: Reply with quote

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
View user's profile Send private message
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Sat May 20, 2006 6:34 am    Post subject: Reply with quote

yeah! thats was my fault!
thanks :))
_________________
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group