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 

3d world float to screen float

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



Joined: 27 Dec 2004
Posts: 61

PostPosted: Fri Apr 17, 2009 4:47 pm    Post subject: 3d world float to screen float Reply with quote

can someone point me to a formula to quickly convert a float decimal vlaue to the screen's 4-bit decimal value. it should make things move smoother onscreen. i guess its kind of complex, because it depends how precise the decimal is.




float

to

GS_XYZ->x
Back to top
View user's profile Send private message
LionX



Joined: 27 Dec 2004
Posts: 61

PostPosted: Fri Apr 17, 2009 5:58 pm    Post subject: Reply with quote

ok, lets work it out.

4bits holds 16 digits: 0-15

the GS says '15' = '.9375'

so '0001' = .9375 / 15

so '0001' = '.625'




now let do the float:

we divide 1.0f into 15 parts

so 1.0 / 15 = 0.066666666666666666666666666666667

lets just say 0.066




so when the worldscreen float have a decimal of '.066' then the screen decimal should have a value of '0001'(.625)




i think we are ready to convert it


1st we extract decimal number from our worldscreen flaot like this:

float f = 58.8686464...;


int intpart = (int) f;
float decpart = f - intpart;


then calculate our final screen 4 bit decimal like this:


int screen_xy_4bit_decimal = (int) (decpart / 0.066)


i thnk that should do it.
.


anyone think this doesnt work ?
Back to top
View user's profile Send private message
Lukasz



Joined: 19 Jan 2004
Posts: 248
Location: Denmark

PostPosted: Sat Apr 18, 2009 2:43 am    Post subject: Reply with quote

There is a much eaiser way to do this.

Code:
#define FTOI4(x) ((int)((x)*16.0f))

From here

The reason this works is because you want to keep 4 bits of the fraction portion of your float. Shifting 4 bits left is equal to multiplying by 16. So by multiplying your float with 16, you get 4 more bits in your int (when you cast it), which equal the fraction part.

On the VU1 you can use the FTOI4 instruction to do this for you.
_________________
Lukasz.dk
Back to top
View user's profile Send private message Visit poster's website
LionX



Joined: 27 Dec 2004
Posts: 61

PostPosted: Sat Apr 18, 2009 3:29 am    Post subject: Reply with quote

nice and simple
:)


you are right:

if i have a float value of 123.45

then: 123.45 * 16.0 = 1975 (bin:11110110111)


if you cut off the last 4 bit you get : '1111011'

which brings us back to the whole number of '123'





and if you check the last 4 bits that we cut off is == 7 witch is about 0.45


THIS IS TOO COOL
.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 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