Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


lemming77

Member Since 19 Jul 2012
Offline Last Active Sep 02 2012 07:39 PM

Topics I've Started

Double and Float based fundamental types (vectors, matrices, etc.) implemented side by...

19 July 2012 - 02:00 AM

Hi,

As I'm sure is standard practice, I have written a library to implement types like vectors, matrices, and so on, and it all works quite nicely. However I have hit a hurdle.

Using D3D9 for graphics, that seems to like having it's data in the form of single precision floats. Which is fair enough. But I'm feeling the need to do some intense physics simulation using double precision. So what I really want is some means of implementing both without duplicating my entire library.

My current implementation lets me switch between Float and Double types before compiling by means of a typedef instruction. But this doesn't quite give me the solution I need, as I'm stuck choosing one over the other.

[source lang="cpp"]// The library is called Util. Not a great name, I know. Here's a small excerpt// from Util.h. Define DOUBLE before compiling to use the double type.// Otherwise, use the float type.#ifdef DOUBLEtypedef double Real;#define NAMESPACE Maths::Double#elsetypedef float Real;#define NAMESPACE Maths#endifnamespace Util { namespace NAMESPACE { struct Angle; // Euler angle struct Matrix; // 4x4 Matrix struct Quaternion; struct Vector3; }}// An excerpt from Vector3.hnamespace util { namespace NAMESPACE { // Vector3, 3D coordinates struct Vector3 { public: Real x, y, z; Vector3(); // x=0 y=0 z=0 Vector3(Real); // x=a y=a z=a Vector3(Real, Real, Real); // x=a y=b z=c/// ... Etc. };}[/source]

Can anyone recommend a means to implement both types into the same library? Preferably while duplicating as little source code as possible.

I'm using Visual C++ 2010 Express. Thanks Posted Image

PARTNERS