Book a Demo

Author Topic: Question with reverse engineering  (Read 2271 times)

dchooper

  • EA Novice
  • *
  • Posts: 1
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Question with reverse engineering
« on: March 29, 2006, 04:28:29 pm »
Hi,

I'm using EA 5.00.769 (Build 769) and I imported a C++ header file but I've got some questions about the results.  

It imported everything down to the first overloaded operator correctly.  But, the first overloaded operator, operator+() was declared as an attribute.  Nothing after the first overloaded operator appears to have been imported.

I'd really appreciate any insight you might have concerning if I've done something wrong, etc.

Here is the source code that I was importing.  I'm sorry - but it's fairly large.  The file is named: quaternion.h  Its a quaternion class:

/** Quaternion.h
*
* Basic Quaternion class. This one is simpler than the boost version and only
* and doesn't include complex types.
*
* Todo someday: sin, cos, exp, log, pow functions.
*/

#ifndef QUATERNION_H
#define QUATERNION_H

#include <iostream>
#include <cmath>
#include <boost/numeric/ublas/matrix.hpp>

template<typename T>
class Quaternion {
public:
   typedef T value_type;
   typedef Quaternion<T> self_type;
   typedef boost::numeric::ublas::c_matrix<T,3,3> rotation_matrix;

   Quaternion() :
       m_x(0),
       m_y(0),
       m_z(0),
       m_w(0)
   {}

   Quaternion(T x, T y, T z) :
       m_x(x),
       m_y(y),
       m_z(z),
       m_w(0)
   {}

   Quaternion(T x, T y, T z, T w) :
       m_x(x),
       m_y(y),
       m_z(z),
       m_w(w)
   {}

   // Accessors
   T x() const { return m_x; }
   T y() const { return m_y; }
   T z() const { return m_z; }
   T w() const { return m_w; }

   // Property functions

   /** Return the sum of the squared components */
   T norm() const { return m_x*m_x + m_y*m_y + m_z*m_z + m_w*m_w; }

   /** Return the square root of the sum of the squared components */
   T abs() const { return std::sqrt(this->norm()); }

   /** Return copy of self. */
   self_type dup() const { return *this; }

   /** Return C style rotation matrix equivalent to self */
   rotation_matrix asRotationMatrix()
   {
       rotation_matrix mat(3,3);
       const T one = 1, nrm = 2/this->norm();
       const T x  = m_x, y  = m_y, z  = m_z, w = m_w;
       const T xx = x*x, xy = x*y, xz = x*z, xw = x*w;
       const T yy = y*y, yz = y*z, yw = y*w;
       const T zz = z*z, zw = z*w;
       const T ww = w*w;
       mat(0,0) = one - nrm*(yy + zz);
       mat(0,1) =       nrm*(xy - zw);
       mat(0,2) =       nrm*(xz + yw);
       mat(1,0) =       nrm*(xy + zw);
       mat(1,1) = one - nrm*(xx + zz);
       mat(1,2) =       nrm*(yz - xw);
       mat(2,0) =       nrm*(xz - yw);
       mat(2,1) =       nrm*(yz + xw);
       mat(2,2) = one - nrm*(xx + yy);
       return mat;
   }

   // Unary operators

   /** Negate and return reference to self */
   self_type& neg()
   {
       m_x = -m_x;
       m_y = -m_y;
       m_z = -m_z;
       m_w = -m_w;
       return *this;
   }

   /** Conjugate and return reference to self*/
   self_type& conj()
   {
       m_x = -m_x;
       m_y = -m_y;
       m_z = -m_z;
       return *this;
   }

   /** Invert and return reference to self*/
   self_type& inv()
   {
       const T psc = static_cast<T>(1)/this->norm();
       const T msc = -psc;
       m_x *= msc;
       m_y *= msc;
       m_z *= msc;
       m_w *= psc;
       return *this;
   }

   /** Scale so self.abs() == 1 and return reference to self */
   self_type& normalize()
   {
       const T sc = static_cast<T>(1)/this->abs();
       m_x *= sc;
       m_y *= sc;
       m_z *= sc;
       m_w *= sc;
       return *this;
   }

   // Operators with scalars

   /** Add scalar and return reference to self */
   self_type& add(const T rhs)
   {
       m_w += rhs;
       return *this;
   }

   /** Subtract scalar and return reference to self */
   self_type& sub(const T rhs)
   {
       m_w -= rhs;
       return *this;
   }

   /** Multiply by scalar and return reference to self */
   self_type& mul(const T rhs)
   {
       m_x *= rhs;
       m_y *= rhs;
       m_z *= rhs;
       m_w *= rhs;
       return *this;
   }

   /** Divide by scalar and return reference to self */
   self_type& div(const T rhs)
   {
       m_x /= rhs;
       m_y /= rhs;
       m_z /= rhs;
       m_w /= rhs;
       return *this;
   }

   // Operators with Quaternions

   /** Add Quaternion and return reference to self */
   template<typename X>
   self_type& add(Quaternion<X> const & rhs)
   {
       m_x += static_cast<T>(rhs.x());
       m_y += static_cast<T>(rhs.y());
       m_z += static_cast<T>(rhs.z());
       m_w += static_cast<T>(rhs.w());
       return *this;
   }

   /** Subtract Quaternion and return reference to self */
   template<typename X>
   self_type& sub(Quaternion<X> const & rhs)
   {
       m_x -= static_cast<T>(rhs.x());
       m_y -= static_cast<T>(rhs.y());
       m_z -= static_cast<T>(rhs.z());
       m_w -= static_cast<T>(rhs.w());
       return *this;
   }

   /** Multiply by Quaternion and return reference to self */
   template<typename X>
   self_type& mul(Quaternion<X> const & rhs)
   {
       const T xr = static_cast<T>(rhs.x());
       const T yr = static_cast<T>(rhs.y());
       const T zr = static_cast<T>(rhs.z());
       const T wr = static_cast<T>(rhs.w());
       const T xt = m_x;
       const T yt = m_y;
       const T zt = m_z;
       const T wt = m_w;

       m_x = wt*xr + xt*wr + yt*zr - zt*yr;
       m_y = wt*yr - xt*zr + yt*wr + zt*xr;
       m_z = wt*zr + xt*yr - yt*xr + zt*wr;
       m_w = wt*wr - xt*xr - yt*yr - zt*zr;
       return *this;
   }

   /** Divide by Quaternion and return reference to self */
   template<typename X>
   self_type& div(Quaternion<X> const & rhs)
   {
       const T xr = -static_cast<T>(rhs.x());
       const T yr = -static_cast<T>(rhs.y());
       const T zr = -static_cast<T>(rhs.z());
       const T wr = +static_cast<T>(rhs.w());
       const T sc = static_cast<T>(1)/(wr*wr + xr*xr + yr*yr + zr*zr);
       const T xt = m_x;
       const T yt = m_y;
       const T zt = m_z;
       const T wt = m_w;

       m_x = (wt*xr + xt*wr + yt*zr - zt*yr)*sc;
       m_y = (wt*yr - xt*zr + yt*wr + zt*xr)*sc;
       m_z = (wt*zr + xt*yr - yt*xr + zt*wr)*sc;
       m_w = (wt*wr - xt*xr - yt*yr - zt*zr)*sc;
       return *this;
   }

   // Operator overloading

   /** Return copy of self */
   self_type operator+() { return *this; }

   /** Negate and return copy of self */
   self_type operator-() { return (*this).dup().neg(); }

   /** Add scalar to self and return reference to self; */
   self_type& operator+=(const T rhs) { return this->add(rhs); }

   /** Subtract scalar from self and return reference to self; */
   self_type& operator-=(const T rhs) { return this->sub(rhs); }

   /** Multilply self by scalar reference to self; */
   self_type& operator*=(const T rhs) { return this->mul(rhs); }

   /** Divide self by scalar and return reference to self; */
   self_type& operator/=(const T rhs) { return this->div(rhs); }

   /** Add Quaternion to self and return reference to self; */
   template<typename X>
   self_type& operator+=(const Quaternion<X> & rhs) { return this->add(rhs); }

   /** Subtract Quaternion from self and return reference to self; */
   template<typename X>
   self_type& operator-=(const Quaternion<X> & rhs) { return this->sub(rhs); }

   /** Multilply self by Quaternion reference to self; */
   template<typename X>
   self_type& operator*=(const Quaternion<X> & rhs) { return this->mul(rhs); }

   /** Divide self by Quaternion and return reference to self; */
   template<typename X>
   self_type& operator/=(const Quaternion<X> & rhs) { return this->div(rhs); }

   /** Return true if scalar == real part and unreal part of self is zero. */
   bool operator==(const T rhs) const
   {
       return m_x == 0 && m_y == 0 && m_z == 0 && m_w == rhs;
   }

   /** Return true if scalar != real part and unreal part of self is zero. */
   bool operator!=(const T rhs) const
   {
       return !((*this) == rhs);
   }

   /** Return true if Quaternion components are == */
   template<typename X>
   bool operator==(const Quaternion<X> & rhs) const
   {
       const T tx = static_cast<X>(rhs.x());
       const T ty = static_cast<X>(rhs.y());
       const T tz = static_cast<X>(rhs.z());
       const T tw = static_cast<X>(rhs.w());
       return m_x == tx && m_y == ty && m_z == tz && m_w == tw;
   }

   /** Return true if Quaternion components are != */
   template<typename X>
   bool operator!=(const Quaternion<X> & rhs) const
   {
       return !((*this) == rhs);
   }

protected:
   double m_x, m_y, m_z, m_w;
};


// functions
template <typename T>
inline T abs(const Quaternion<T> & q) { return q.abs(); }

template <typename T>
inline T norm(const Quaternion<T> & q) { return q.norm(); }

template <typename T>
inline Quaternion<T> conj(const Quaternion<T> q) { return q.dup().conj(); }

// Quaternion printing
template <typename T>
inline std::ostream & operator <<(std::ostream & out, const Quaternion<T> rhs)
{
   out << "[x,y,z,w](";
   out << rhs.x() << ",";
   out << rhs.y() << ",";
   out << rhs.z() << ",";
   out << rhs.w() << ")";
   return out;
}

#endif /* QUATERNION_H */

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Question with reverse engineering
« Reply #1 on: March 29, 2006, 10:17:31 pm »
Version 6.0 of EA introduced a much more intelligent parser.  Up until then it had a lot more trouble with code like this.

I just double checked and it is imported well in 6.1.