libpacket & floats

Discuss the development of software, tools, libraries and anything else that helps make ps2dev happen.

Moderators: cheriff, Herben

Post Reply
tumnes
Posts: 23
Joined: Fri Sep 17, 2004 12:02 pm
Contact:

libpacket & floats

Post by tumnes »

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);
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);
And the results were as expected.

Now my question is: What is the proper way to do this?
cheriff
Regular
Posts: 258
Joined: Wed Jun 23, 2004 5:35 pm
Location: Sydney.au

Post by cheriff »

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: Select all

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!
Post Reply