Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#Actualirreversible

Posted 27 March 2013 - 10:15 AM

If you need to keep all vector classes intact, then the safest way is to roll your own vector class and write conversion functions. Usually this is not the case. It'd also add conversion overhead.

 

If the classes share the same members (eg, x, y, z) and overloads, you can get away with writing global copy functions and just using them directly (one type at a time and on a per-component basis if you need to use them interchangeably). I'd advise against this, however, as it'll create a mess.

 

As a matter of speed and clarity, for instance idTech uses macro-based vector operators, which automatically resolve into inline code and are inherently faster. You could adopt the same approach. Eg:

 

vec2d v0, v1, v2;

 

v2 = v0 * v1;

 

becomes:

 

#define VecMult2D(a, b, res) (res[0] = (a[0]) * (b[0]), res[1] = (a[1]) * (b[1]))

 

VecMult2D(v0, v1, v2);

 

You'd no longer be dependent on member functions and your "vector class" would degenerate into a simple POD. Furthermore, you could mix vec2dA and vec2dB if both of them provide a bracket operator overload. Eg:

 

vec2dA v0;

vec2dB v1;

myvec2d v2;

 

VecMult2D(v0, v1, v2);

 

Not that this would be a good idea. The biggest problem with this is likely converting code from operator-oriented form into macro-oriented form, which can and will be a true hassle.

 

A third and most likely simplest option would be to rename one to the other or both to your own. Once again, if the operator overloads and members are the same, the conversion is actually pretty simple in most IDE-s: use Replace All (usually Ctrl+H or Ctrl+Shift+H) and rename one class name to the other (or, again, both to your own class). If you have differences in member names, then the conversion can be a real PITA, though.

 

A fourth and most efficient way is to use some form of refactoring. I don't know what native refactoring capabilities are like in IDE-s, but VisualAssist X (can be pricey, but is well worth the investment if you have the money) excels in stuff like this.

 

There is no automatic way to handle this.


#3irreversible

Posted 27 March 2013 - 10:12 AM

If you need to keep all vector classes intact, then the safest way is to roll your own vector class and write conversion functions. Usually this is not the case. It'd also add conversion overhead.

 

If the classes share the same members (eg, x, y, z) and overloads, you can get away with writing global copy functions and just using them directly (one type at a time and on a per-component basis if you need to use them interchangeably). I'd advise against this, however, as it'll create a mess.

 

As a matter of speed and clarity, for instance idTech uses macro-based vector operators, which automatically resolve into inline code and are inherently faster. You could adopt the same approach. Eg:

 

vec2d v0, v1, v2;

 

v2 = v0 * v1;

 

becomes:

 

#define VecMult2D(a, b, res) (res[0] = (a[0]) * (b[0]), res[1] = (a[1]) * (b[1]))

 

VecMult2D(v0, v1, v2);

 

You'd no longer be dependent on member functions and your "vector class" would degenerate into a simple POD. Furthermore, you could mix vec2dA and vec2dB if both of them provide a bracket operator overload. Eg:

 

vec2dA v0;

vec2dB v1;

myvec2d v2;

 

VecMult2D(v0, v1, v2);

 

Not that this would be a good idea. The biggest problem with this is likely converting code from operator-oriented form into macro-oriented form, which can and will be a true hassle.

 

A third and most likely simplest option would be to rename one to the other or both to your own. Once again, if the operator overloads and members are the same, the conversion is actually pretty simple in most IDE-s: use Replace All (usually Ctrl+H or Ctrl+Shift+H) and rename one class name to the other (or, again, both to your own class). If you have differences in member names, then the conversion can be a real PITA, though.

 

There is no automatic way to handle this.


#2irreversible

Posted 27 March 2013 - 10:05 AM

If you need to keep all vector classes intact, then the safest way is to roll your own vector class and write conversion functions. Usually this is not the case. It'd also add conversion overhead.

 

If the vectors share the same members (eg, x, y, z) and overloads, you can get away with writing global copy functions and just using them directly (one type at a time and on a per-component basis if you need to use them interchangeably). I'd advise against this, however, as it'll create a mess.

 

As a matter of speed and clarity, for instance idTech uses macro-based vector operators, which automatically resolve to inline code and are inherently faster. You could adopt the same approach. Eg:

 

vec2d v0, v1, v2;

 

v2 = v0 * v1;

 

becomes:

 

#define VecMult2D(a, b, res) (res[0] = (a[0]) * (b[0]), res[1] = (a[1]) * (b[1]))

 

VecMult2D(v0, v1, v2)

 

You'd no longer be dependent on member functions and your "vector class" would degenerate into a simple POD. Furthermore, you could mix vec2dA and vec2dB if both of them provide a brace operator overload.

 

A third option would be to rename one to the other or both to your own. Once again, if the operator overloads and members are the same, the conversion is actually pretty simple in most IDE-s: use Replace All (usually Ctrl+H) and rename one class name to the other (or, again, both to your own class). If you have differences in member names, then the conversion can be a real PITA, though.

 

There is no automatic way to handle this.


#1irreversible

Posted 27 March 2013 - 10:00 AM

If you need to keep all vector classes intact, then the safest way is to roll your own vector class and write conversion functions.

 

If the vectors share the same members (eg, x, y, z) and overloads, you can get away with writing global copy functions and just using them interchangeably. I'd advise against this, however, as it'll create a mess. As a matter of speed, for instance idTech uses macro-based vector operations, which automatically resolves to inline code and is inherently faster. You could adopt the same approach. Eg:

 

v0 * v1

 

becomes

 

#define VecMult2D(a, b, res) (res[0] = (a[0]) * (b[0]), res[1] = (a[1]) * (b[1]))

 

VecMult2D(v0, v1, v2)

 

You'd no longer be dependent on member functions and your "vector class" would degenerate into a simple POD.

 

A third option would be to rename one to the other or both to your own. Once again, if the operator overloads and members are the same, the conversion is actually pretty simple in most IDE-s: use Replace All (usually Ctrl+H) and rename one class name to the other (or, again, both to your own class). If you have differences in member names, then the conversion can be a real PITA, though.

 

There is no automatic way to handle this.


PARTNERS