Malcolm McLean said:
בת×ריך ×™×•× ×©× ×™, 30 ב×פריל 2012 09:08:29 UTC+1, מ×ת jacob navia:
The issue is that it needs to be accepted as a standard by someone with
the weight to make everyone use it.
Anyone can write typedef float[3] vect3; The hard part is getting
everyone
to use the same typedef for their 3d libraries.
Does it happen often that you want to make the same application work with
several different libraries? Even if exactly the same typedef was used,
there would be entirely different sets of functions, macros, defines. For
example to get your GDI32 application to work with OpenGL instead, might
involve more than a compatible set of typedefs.
I don't see the problem. And if there is, the usual solution is to write
wrappers around the libraries to make their interface more acceptable.
yes.
the usual split IME is to split the "inside" and "outside" worlds of the
codebase, with the inside using its own conventions, and most external
interfacing being done by wrappers.
generally, this is much cleaner IME than letting the outside types and
APIs and similar be directly exposed to internal code.
So, what *should* be the common 3D point representation? What about a 3D
vector? See, it's not so easy...
Although the comment was more to do with basic screen graphics.
in my case, to a large degree I have roughly adopted a variant inspired
by GLSL:
'vec3': contains 3 floats;
'vec3d': contains 3 doubles;
'vec4' and 'vec4d', likewise.
....
as-is they are represented as one of:
a structure containing 4 floats ('w' is ignored for vec3);
a structure containing an "__xmm128" (SIMD intrinsics are used depending
on the compiler and compiler options in use);
another version specialized for my own C compiler and tools (these are
mapped to built-in vector-math types and intrinsics).
sadly, the above difference does create a worry that there "could" be
potential compatibility issues between libraries compiled with different
compiler options (say, due to differences in representation and alignment).
most basic operations are handled by either wrapper macros or
static-inline functions, with some more complex ones (for example,
"slerp", ...) redirecting to library functions.
for example: "v3dot(a, b)" calculates the dot-product of two 'vec3'
vectors, "v3add(a, b)" adds two vectors, "v3cross(a, b)" does
cross-product, "v3x(a)" gets the x component, "v3xz(a)" gets an XZ
vector (vec2), ...
my script language also supports them as a built-in feature (and using
binary operators instead), internally representing them as "boxed
value-types" (heap-allocated objects using value-type semantics).
a lot of my older C code makes use of raw float pointers and arrays, but
this is being gradually replaced. due to being both more generally
awkward and, actually, apparently slightly slower on-average.
although for in certain cases arrays of floats are faster, in many other
cases they seem to work out marginally slower "for some reason" than the
use of passing structs around by-value (I actually find this a bit
counter-intuitive).
but, performance is like this sometimes.
nevermind, there are a few regions of code which use arrays of doubles
as the default vector type, ...
but, float is generally sufficient for "most things" in a 3D engine (and
double is often overkill).