<commit_before>/*************** <auto-copyright.pl BEGIN do not edit this line> **************
 *
 * VR Juggler is (C) Copyright 1998, 1999, 2000 by Iowa State University
 *
 * Original Authors:
 *   <NAME>, <NAME>,
 *   <NAME>, <NAME>,
 *   <NAME>, <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * -----------------------------------------------------------------
 * File:          $RCSfile$
 * Date modified: $Date$
 * Version:       $Revision$
 * -----------------------------------------------------------------
 *
 *************** <auto-copyright.pl END do not edit this line> ***************/


#ifndef _VJ_QUAT_H_
#define _VJ_QUAT_H_

#include <math.h>

#include <Math/vjVec4.h>
#include <Math/vjVec3.h>
#include <Math/vjMatrix.h>
#include <VPR/vjSystem.h>

#define VJ_QUAT_EPSILON     0.00001f

// ----------------------------------------------------------------------------
//: Class to encapsulate quaternion behaviors.
//
// Note: The code for most of these routines was borrowed from the the folling
// sources.
//
//    Game Developer Magazine: Feb 98, pg.34-42                   <br>
//    Advanced Animation and Rendering Techniques: pp363-365      <br>
//    Quaternion Calculus for Animation,  <NAME> SIGGRAPH course notes 1989  <br>
//    Animating Rotation with Quaternion Curves,  <NAME> <br>
//       SIGGRAPH Proceedings Vol 19, Number 3, 1985           <br>
//-----------------------------------------------------------------------------
//!PUBLIC_API:
class vjQuat : public vjVec4
{
public:
   vjQuat()
   {}

   //: Construct Quat from 4 floats
   vjQuat( const float x,
           const float y,
           const float z,
           const float w)
   {
      vec[VJ_X] = x;
      vec[VJ_Y] = y;
      vec[VJ_Z] = z;
      vec[VJ_W] = w;
   }

   //: Construct quat from matrix
   void makeQuat(const vjMatrix& mat);

   //: get the quat's twist (radians) and vector
   void getRot( float& rad, float& x, float& y, float& z ) const
   {
      float halfrad = vjSystem::acos(vec[VJ_W]);
      float sin_halfrad = vjSystem::sin( halfrad );
      float oneOverSinHalfRad;
      
      if (sin_halfrad != 0.0f)
      {
         oneOverSinHalfRad = 1.0f / sin_halfrad;
      }
      
      // avoid NAN
      // if rad == 0, then the vector is undefined anyway, 
      // since there is no twist, there is no need for a vector (set to 0)
      else 
      {
         oneOverSinHalfRad = 0.0f;
      }
      
	   rad = halfrad * 2.0f;
      vjVec3 t;
	   t[0] = vec[VJ_X] * ( oneOverSinHalfRad );
      t[1] = vec[VJ_Y] * ( oneOverSinHalfRad );
		t[2] = vec[VJ_Z] * ( oneOverSinHalfRad );
      //t.normalize();
      x = t[0];
      y = t[1];
      z = t[2];
      
      // avoid 0,0,0,0 when deg is 0.  make it 0,1,0,0
      if (oneOverSinHalfRad == 0.0f)
      {
         x = 1.0f;
      }
   }

   //: make a quat from a twist (radians) about a vector (normalized)
   void makeRot( const float& rad, const float& x, const float& y, const float& z )
   {
      float halfRad = rad * 0.5f;
	   float sinHalfRad = sinf( halfRad );
	   vjVec3 vecNormalized;
         
      if (rad == 0.0f || (x == 0.0f && y == 0.0f && z == 0.0f))
      {
         vecNormalized.set( 1.0f, 0.0f, 0.0f );
      }
      else
      {
         vecNormalized.set( x, y, z );
	      vecNormalized.normalize();
      }
	   vec[VJ_W] = cosf( halfRad );
	   vec[VJ_X] = sinHalfRad * vecNormalized[0];
	   vec[VJ_Y] = sinHalfRad * vecNormalized[1];
	   vec[VJ_Z] = sinHalfRad * vecNormalized[2];
	   this->unit();
   }
 
   //: set to conj of quat
   void conj(const vjQuat& quat)
   {<commit_msg>sinf() --> vjSystem::sin() cosf() --> vjSystem::cos()<commit_after>/*************** <auto-copyright.pl BEGIN do not edit this line> **************
 *
 * VR Juggler is (C) Copyright 1998, 1999, 2000 by Iowa State University
 *
 * Original Authors:
 *   <NAME>, <NAME>,
 *   <NAME>, <NAME>,
 *   <NAME>, <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * -----------------------------------------------------------------
 * File:          $RCSfile$
 * Date modified: $Date$
 * Version:       $Revision$
 * -----------------------------------------------------------------
 *
 *************** <auto-copyright.pl END do not edit this line> ***************/


#ifndef _VJ_QUAT_H_
#define _VJ_QUAT_H_

#include <math.h>

#include <Math/vjVec4.h>
#include <Math/vjVec3.h>
#include <Math/vjMatrix.h>
#include <VPR/vjSystem.h>

#define VJ_QUAT_EPSILON     0.00001f

// ----------------------------------------------------------------------------
//: Class to encapsulate quaternion behaviors.
//
// Note: The code for most of these routines was borrowed from the the folling
// sources.
//
//    Game Developer Magazine: Feb 98, pg.34-42                   <br>
//    Advanced Animation and Rendering Techniques: pp363-365      <br>
//    Quaternion Calculus for Animation,  Ken Shoemake SIGGRAPH course notes 1989  <br>
//    Animating Rotation with Quaternion Curves,  Ken Shoemake <br>
//       SIGGRAPH Proceedings Vol 19, Number 3, 1985           <br>
//-----------------------------------------------------------------------------
//!PUBLIC_API:
class vjQuat : public vjVec4
{
public:
   vjQuat()
   {}

   //: Construct Quat from 4 floats
   vjQuat( const float x,
           const float y,
           const float z,
           const float w)
   {
      vec[VJ_X] = x;
      vec[VJ_Y] = y;
      vec[VJ_Z] = z;
      vec[VJ_W] = w;
   }

   //: Construct quat from matrix
   void makeQuat(const vjMatrix& mat);

   //: get the quat's twist (radians) and vector
   void getRot( float& rad, float& x, float& y, float& z ) const
   {
      float halfrad = vjSystem::acos(vec[VJ_W]);
      float sin_halfrad = vjSystem::sin( halfrad );
      float oneOverSinHalfRad;
      
      if (sin_halfrad != 0.0f)
      {
         oneOverSinHalfRad = 1.0f / sin_halfrad;
      }
      
      // avoid NAN
      // if rad == 0, then the vector is undefined anyway, 
      // since there is no twist, there is no need for a vector (set to 0)
      else 
      {
         oneOverSinHalfRad = 0.0f;
      }
      
	   rad = halfrad * 2.0f;
      vjVec3 t;
	   t[0] = vec[VJ_X] * ( oneOverSinHalfRad );
      t[1] = vec[VJ_Y] * ( oneOverSinHalfRad );
		t[2] = vec[VJ_Z] * ( oneOverSinHalfRad );
      //t.normalize();
      x = t[0];
      y = t[1];
      z = t[2];
      
      // avoid 0,0,0,0 when deg is 0.  make it 0,1,0,0
      if (oneOverSinHalfRad == 0.0f)
      {
         x = 1.0f;
      }
   }

   //: make a quat from a twist (radians) about a vector (normalized)
   void makeRot( const float& rad, const float& x, const float& y, const float& z )
   {
      float halfRad = rad * 0.5f;
	   float sinHalfRad = vjSystem::sin( halfRad );
	   vjVec3 vecNormalized;
         
      if (rad == 0.0f || (x == 0.0f && y == 0.0f && z == 0.0f))
      {
         vecNormalized.set( 1.0f, 0.0f, 0.0f );
      }
      else
      {
         vecNormalized.set( x, y, z );
	      vecNormalized.normalize();
      }
	   vec[VJ_W] = vjSystem::cos( halfRad );
	   vec[VJ_X] = sinHalfRad * vecNormalized[0];
	   vec[VJ_Y] = sinHalfRad * vecNormalized[1];
	   vec[VJ_Z] = sinHalfRad * vecNormalized[2];
	   this->unit();
   }
 
   //: set to conj of quat
   void conj(const vjQuat& quat)
   {
{'fraction_non_alphanumeric': 0.18712505768343332, 'fraction_numerical': 0.025380710659898477, 'mean_word_length': 1.8819813829787233, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7299608', 'n_tokens_mistral': 3056, 'n_tokens_neox': 2809, 'n_words': 901}