srmeier / KnightOnline

OpenKO is an open source version of the old school Knight Online MMORPG

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using GLM for 3D structures such as vectors, matrices and quaternions

onurcanbektas opened this issue · comments

I was thinking to use GLM for 3D structures such as vectors, matrices and quaternions, which are defined in My_3DStruct.h file by using directx library.

I have already started experimenting with the library, and wanted to take your opinion.

So what do you guys think ? Should we use it ? Do you have another suggestions ?

Let me know your thoughts.

OpenGL it is slow?

I'm not an expert on OpenGL, and I'm pretty sure that if you google it, you can find a lot of article about the performance of OpenGL.

You ask us if we want to use it, but you never provide your own reasoning for this proposal:

  1. Why do you propose using a library for this (what problem are you trying to solve?) and,
  2. Why this particular library?

@twostars Good point :) Before I start, I should notice that I have never developed such a complex and portable project, so what I'm looking from a library to use in the project obviously will not be a good criteria to determine whether to use it or not.

First of all, it is a platform independent library, which isone of the main point that I was looking (and the main problem that I was trying to solve :) ). Also it is a header only library, and this makes easy to use. I mean considering the fact that different platforms using different type of lib files (.dll , .a ...), this make this library to easy to use, sort of.

Plus, in order to compile to code on the major operating system, we can use gcc and apple's clang, which are the default compilers that comes with linux distributions and OSX, respectively.

However, I must admit that the documentation is not so much good.

Okay. So in another project I'm a lot further with moving away from DirectX, and this in particular is something I've attempted to do (not with GLM, but with the engine's own math library), so I have some insight on this.

The long and the short of it is I really wouldn't. Some of the behaviour is implemented slightly differently to how other math libraries work, in part because of the fact DirectX uses a left-handed coordinate system. Additionally we have a lot of custom interoperability and special ways in which certain operators work which will break "random" logic very subtly when switching with a more standard math library.

What I would do however is reverse the DirectX logic to implement within our classes for our portable builds (or just in general, but note that using DirectX calls means the calculations can be run on the GPU or otherwise more specifically optimised where available). And also add tests for every one to ensure we get the same result, because changing these can definitely break things in very crazy ways.

tl;dr: It ultimately isn't really a simple thing. It's quite time consuming to go over every use case and suss out which is using custom behaviour. The considerably easier way is to keep our existing classes and just reverse the DX calls.

@twostars I couldn't understand what do you mean by "reverse the DirectX logic to implement within our classes for our portable builds ".

I mean reverse engineer the DX API calls the classes are using to provide the exact same result as expected.

e.g.

inline __Matrix44::__Matrix44(const D3DXQUATERNION& qt)
{
	D3DXMatrixRotationQuaternion(this, &qt);
}
..
	_32 = vUp.z; // view(2, 1) = up.z;
	_13 = vDir2.x; // view(0, 2) = view_dir.x;
	_23 = vDir2.y; // view(1, 2) = view_dir.y;
	_33 = vDir2.z; // view(2, 2) = view_dir.z;

	D3DXMatrixInverse(this, NULL, this);
..
inline void __Quaternion::RotationAxis(const __Vector3& v, float fRadian)
{
	D3DXQuaternionRotationAxis(this, &v, fRadian);
}

inline void __Quaternion::RotationAxis(float fX, float fY, float fZ, float fRadian)
{
	__Vector3 v(fX, fY, fZ);
	D3DXQuaternionRotationAxis(this, &v, fRadian);
}

inline void __Quaternion::operator = (const D3DXMATRIX& mtx)
{
	D3DXQuaternionRotationMatrix(this, &mtx);
}

inline void __Quaternion::AxisAngle(__Vector3& vAxisResult, float& fRadianResult) const
{
	D3DXQuaternionToAxisAngle(this, &vAxisResult, &fRadianResult);
}

inline void __Quaternion::Slerp(const D3DXQUATERNION& qt1, const D3DXQUATERNION& qt2, float fDelta)
{
	D3DXQuaternionSlerp(this, &qt1, &qt2, fDelta);
}

inline __Quaternion::__Quaternion(const D3DXMATRIX& mtx)
{
	D3DXQuaternionRotationMatrix(this, &mtx);
}