Convert irr::core::vector3d< T > to another data type?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Ein
Posts: 33
Joined: Thu Feb 12, 2009 11:39 pm
Location: UK - Matrix
Contact:

Convert irr::core::vector3d< T > to another data type?

Post by Ein »

Is it possible to convert irr::core::vector3d< T > to another data type, such as char?

I would like to be able to pass the node position, which is a irr::core::vector3df, to the buff argument of the send() function see Here

It says that I need to "A pointer to a buffer containing the data to be transmitted." so I passed it the pointer address, like this &position and it still said it cant convert to char.

any ideas?
Thanks,
Pete
Ein knowledge seeker
RedDragCZ
Posts: 9
Joined: Tue Aug 28, 2007 9:32 pm
Location: Czech Republic
Contact:

Re: Convert irr::core::vector3d< T > to another data t

Post by RedDragCZ »

Ein wrote:Is it possible to convert irr::core::vector3d< T > to another data type, such as char?
Ein wrote:It says that I need to "A pointer to a buffer containing the data to be transmitted." so I passed it the pointer address, like this &position and it still said it cant convert to char.
Not truly convert, but you can just reinterpret the pointer to it and send it as a generic binary data. Try something like this:

Code: Select all

vector3df aaa(1, 2, 3);
c8* vectorData = reinterpret_cast<c8*>(&aaa);
As the size (length) of the data use then the sizeof(vector3df);

EDIT: @Travis: Yes, you are of course right, just forgot to mention.
Last edited by RedDragCZ on Sun Aug 16, 2009 1:58 pm, edited 1 time in total.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

That will only work if the system you're sending the data to is compatible with the one you're sending from. Issues such as endianness, padding and alignment can all cause that code to fail.

Travis
Post Reply