Page 1 of 1

vector3df to int

Posted: Wed Apr 12, 2006 4:21 pm
by Halan
hi guys,

im searching for a way to convert vector3df to 3 ints, you know one for x, for y and for z coordinate...

thanks,
Halan

Posted: Wed Apr 12, 2006 4:29 pm
by hybrid
What about accessing vec.X, vec.Y and vec.Z and using them :roll: C++ is a rather sophisticated language which can convert between floats and ints.

Posted: Wed Apr 12, 2006 5:10 pm
by Spintz

Code: Select all

core::vector3d< int > intVec = core::vector3d< float >( 1.0f, 1.0f, 1.0f );

Posted: Wed Apr 12, 2006 5:38 pm
by Baal Cadar
Spintz, this won't work. Different template specialisations are handled as completely different types. So if core::vector3d<int> doesn't contain an assignment operator or ctor taking core::vector3d<float> as argument this won't work.

Posted: Wed Apr 12, 2006 6:43 pm
by Halan
hybrid wrote:What about accessing vec.X, vec.Y and vec.Z and using them :roll: C++ is a rather sophisticated language which can convert between floats and ints.
i dont know how to access them. I tried vector.X and vector.X() it doesnt work

Posted: Wed Apr 12, 2006 7:00 pm
by Baal Cadar
http://irrlicht.sourceforge.net/docu/cl ... tor3d.html

And I am very sure your compiler just didn't say "Doesn't work". It gave you a specific error message. Seriously, why is it so difficult to provide a proper problem description?

Posted: Thu Apr 13, 2006 11:41 am
by Rabid Mantis
int x = int(vector.X);
int y = int(vector.Y);
int z = int(vector.Z);

or exchange "int" for "s32"
make sure you havent mistyped the vector name. If you're using visual studio it should pop up the members of vector after you get to "vector."... if not then you may have an error elsewhere. Make sure to tell us error if you need help so we can figure out why yours isnt working.

Posted: Thu Apr 13, 2006 1:14 pm
by sudi
I don't get the problem just do:

vector3df vec;
int x = vec.X;
int y = vec.Y;
int z = vec.Z;

Posted: Thu Apr 13, 2006 1:30 pm
by hybrid
Your compiler should warn you about loss of precision such that you have to tell him you're aware of this. But I would prefer the explicit cast syntax over Rabid Mantis' ones:
int.x = (int)vec.X;