Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • ad428c9
  • /
  • Quaternion.h
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:0212a79d68515933120610e4223362a5cd4df288
directory badge
swh:1:dir:ad428c94274ada48e69d91a4a5779e224a058fc2

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
Quaternion.h
#ifndef _Quaternion_h
#define _Quaternion_h

#include "Matrix4x4.h"

class  Quaternion
{
public:

	Quaternion();	
	Quaternion(float ax, float ay, float az, float angle);	
	Quaternion&	operator=(const Quaternion &q)	
	{
		x = q.x;
		y = q.y;
		z = q.z;
		w = q.w;
		return(*this);	
	}
	Quaternion(const Quaternion &q)                    
	{
		x = q.x;
		y = q.y;
		z = q.z;
		w = q.w;
	}

	void Identity()
	{
		x	= 0.0f;
		y	= 0.0f;
		z	= 0.0f;
		w	= 1.0f;
	}
	void Normalize()
	{
		float normInv = 1.0f/sqrtf(x*x+y*y+z*z+w*w);
		x *= normInv;
		y *= normInv;
		z *= normInv;
		w *= normInv;	
		return;
	}

	Quaternion& operator *= (const Quaternion&);	
	Matrix4x4 ToMatrix () const
	{
		Matrix4x4 mat;
		float *m = mat;
		m[0]  = 1.0f - 2.0f * (y*y + z*z);
		m[1]  = 2.0f * (x*y + z*w);
		m[2]  = 2.0f * (z*x - y*w);
		m[3]  = 0.0f;

		m[4]  = 2.0f * (x*y - z*w);
		m[5]  = 1.0f - 2.0f * (z*z + x*x);
		m[6]  = 2.0f * (y*z + x*w);
		m[7]  = 0.0f;

		m[8]  = 2.0f * (z*x + y*w);
		m[9]  = 2.0f * (y*z - x*w);
		m[10] = 1.0f - 2.0f * (x*x + y*y);
		m[11] = 0.0f;

		m[12] = 0.0f;
		m[13] = 0.0f;
		m[14] = 0.0f;
		m[15] = 1.0f;	
		return mat;
	}

	float	x,y,z,w;			

};

inline Quaternion operator * (const Quaternion &p, const Quaternion &q)
{
	Quaternion res;

	res.w	= p.w*q.w - p.x*q.x - p.y*q.y - p.z*q.z;
	res.x	= p.w*q.x + p.x*q.w + p.y*q.z - p.z*q.y;
	res.y	= p.w*q.y + p.y*q.w + p.z*q.x - p.x*q.z;
	res.z	= p.w*q.z + p.z*q.w + p.x*q.y - p.y*q.x;

	return res;
}
inline Quaternion& Quaternion::operator *= (const Quaternion& q)
{
	*this=*this*q;
	return (*this);	
}


#endif

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API