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 

libpacket & floats

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



Joined: 17 Sep 2004
Posts: 23

PostPosted: Wed Mar 15, 2006 12:08 pm    Post subject: libpacket & floats Reply with quote

I was playing around with making some vif packets using the library provided in ps2sdk. For some reason when I try to append a float, it gets all messed up. My guess is the compiler is trying to convert it to an unsigned int. So I a list of vertices:
float *vertices = {...};
and when I try to do:
packet_append_32(&packet, vertices[i]);
It puts something strange in where the float should be.

Now I was able to get around it by doing this:
u32 *vertices2 = vertices;
packet_append_32(&packet, vertices2[i]);
And the results were as expected.

Now my question is: What is the proper way to do this?
Back to top
View user's profile Send private message Visit poster's website AIM Address
cheriff
Regular


Joined: 23 Jun 2004
Posts: 262
Location: Sydney.au

PostPosted: Wed Mar 15, 2006 12:27 pm    Post subject: Reply with quote

You pretty much got it. When gcc sees you passing floats to a function expecting ints, it automatically does the conversion. For example 5.0f -> 5 which have different binary representations.

I usually keep several pointers of differing types to the same array/packet usually 32/64/128bit and floats to make putting stuff into them eaire.

Alternatively, you could use casting to the same effect:
Code:
packet_append_32(&packet, ((u32*)vertices2)[i]);
Would do the same thing, but is quit ugle IMO. Each to his own.[/code]
_________________
Damn, I need a decent signature!
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