vector3df to int

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
Halan
Posts: 447
Joined: Tue Oct 04, 2005 8:17 pm
Location: Germany, Freak City
Contact:

vector3df to int

Post 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
hybrid

Post 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.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Code: Select all

core::vector3d< int > intVec = core::vector3d< float >( 1.0f, 1.0f, 1.0f );
Image
Baal Cadar
Posts: 377
Joined: Fri Oct 28, 2005 10:28 am
Contact:

Post 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.
Halan
Posts: 447
Joined: Tue Oct 04, 2005 8:17 pm
Location: Germany, Freak City
Contact:

Post 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
Baal Cadar
Posts: 377
Joined: Fri Oct 28, 2005 10:28 am
Contact:

Post 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?
Rabid Mantis
Posts: 61
Joined: Sun May 08, 2005 11:30 am

Post 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.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

I don't get the problem just do:

vector3df vec;
int x = vec.X;
int y = vec.Y;
int z = vec.Z;
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
hybrid

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