Page 1 of 1

Request: real template-class vector

Posted: Mon Nov 16, 2009 7:47 pm
by Manawenuz
Hi everybody,

I suggest that the vector2d and vector3d classes be really template classes.
Indeed, the ISceneNode::setPosition method takes as an argument a 'vector3df', whereas I would like to pass a vector3d<double>...
Why isn't there templates everywhere?

Posted: Mon Nov 16, 2009 9:57 pm
by hybrid
Because the gfx APIs (OpenGL and D3D) cannot handle doubles. This would increase the render time due to too many conversions. And most people woulnd't gain a thing from this extra precision. Most of the basic class methods are already templated and should work as expected.

Posted: Wed Nov 18, 2009 12:36 pm
by Manawenuz
OK Thanks for the answer.
But it would have been useful for me, because I need to draw space vessels and planets at the scale, with a precision of 1 cm...
But I will do it in an other way.

Posted: Wed Nov 18, 2009 4:27 pm
by Nox
Little Hint: keep in mind that the mantissa of a float is 7 and for a double 15 digits. So you can not easily add i.e. 0.00124 to 1234^10. So i guess none of the basic data types will fullfill your requirements.

P.S: think about seperating space into different blocks :)

Posted: Wed Nov 18, 2009 6:12 pm
by Dorth
Anyway, if you want a specific range, you do not want float, since the quality of float will vary. You integet want integer, based on your smallest unit (a very big integer, called, guess what, big int), or a fixed point system built again on the same integer. But better yet, you can split your game's world in sections or bucket, and consider everything in one such section as being from point 0.0 in the middle of it. That way you can mix and match integer and floats. Lots of documentation on that specific subject, look around m8.