 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
tumnes
Joined: 17 Sep 2004 Posts: 23
|
Posted: Wed Mar 15, 2006 12:08 pm Post subject: libpacket & floats |
|
|
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 |
|
 |
cheriff Regular
Joined: 23 Jun 2004 Posts: 262 Location: Sydney.au
|
Posted: Wed Mar 15, 2006 12:27 pm Post subject: |
|
|
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 |
|
 |
|
|
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
|