Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Compiler Crash - quaternion C++

Options
  • 15-04-2008 10:45pm
    #1
    Registered Users Posts: 83,307 ✭✭✭✭


    Im declaring my own Quaternion class in C++, but is class Quaternion already declared in the STL?

    The error im getting is a straight to windows crash of the C/C++ compiler and inside the compiler it gives me the error noticed that 'Quaternion' is not a recognized type; nor does it recognize any of its member variables or functions.


Comments

  • Registered Users Posts: 2,426 ✭✭✭ressem


    Not the STL. It's included in BOOST, if you're using it.
    While parts of the BOOST libraries might be on your computer if you have some TR1 extensions installed ( C++0x, next planned C++ standard) I don't think that the quaternion is included.

    http://www.boost.org/doc/libs/1_35_0/libs/libraries.htm


  • Registered Users Posts: 83,307 ✭✭✭✭Overheal


    Well its just being a **** then.

    Using VS 2005 with DxSDK Aug 2007 so no it wouldnt be included.

    Trying to run an OpenGL project.

    Heres the .h
    #ifndef QUATERNION_H
    #define QUATERNION_H
    
    #include "stdAfx.h"
    #include "Vector.h"
    
    
    #define PI			3.1415926535
    #define PIOVER180   0.0174532925
    
    class Quaternion
    {
    private:
    	float x, y, z, w;
    
    public:
    
    	Quaternion( float X, float Y, float Z, float W );
    	~Quaternion();
    	
    	Quaternion operator *(const Quaternion &rq); //multiply 2 quaternions
    	Quaternion GetConjugate(); //returns the complex conjugate of the calling quaternion
    	void QuatNormalise(); //normalise into a unit Quaternion
    	void FromEuler(float pitch, float yaw, float roll); //generate a quaternion from Euler Angles
    	void CreateMatrix(float *pMatrix);//create a 4x4 matrix from the calling Quaternion
    		
    
    };
    
    #endif
    

    Heres the .cpp
    #include "Quaternion.h"
    #include "stdAfx.h"
    #include <cmath>
    
    Quaternion::Quaternion(float X, float Y, float Z, float W) // point of error 1 
    { // point of error 2
    	x = X; y = Y; z = Z; w = W; // point of errors 3, 4, 5, 6
    } // point of error 7
    
    Quaternion::~Quaternion() // point of error 8
    {
    
    }
    
    Quaternion Quaternion::operator *(const Quaternion &rq)
    {
    	return Quaternion(	w * rq.x + x * rq.w + y * rq.z - z * rq.y,
    						w * rq.y + y * rq.w + z * rq.x - x * rq.z,
    						w * rq.z + z * rq.w + x * rq.y - y * rq.x,
    						w * rq.w - x * rq.x - y * rq.y - z * rq.z );
    }
    
    Quaternion Quaternion::GetConjugate()
    {
    	return Quaternion(-x, -y, -z, -w);
    }
    
    void Quaternion::QuatNormalise()
    {
    	float magnitude = w * w + x * x + y * y + z * z;
    	magnitude = sqrt(magnitude);
    	w /= magnitude;
    	x /= magnitude;
    	y /= magnitude;
    	z /= magnitude;
    }
    
    void Quaternion::FromEuler(float pitch, float yaw, float roll)
    {
    	// Create 3 quaternions: for pitch, yaw and roll
    	// Multiply these together
    	// Code below does this in a shorter format
    	// Calculations courtesy of Reference1 in .h
    
    	pitch	= pitch * PIOVER180 / 2.0f;
    	yaw		= yaw * PIOVER180 / 2.0f;
    	roll	= roll * PIOVER180 / 2.0f;
    
    	float sinp = sin(pitch);
    	float siny = sin(yaw);
    	float sinr = sin(roll);
    	float cosp = cos(pitch);
    	float cosy = cos(yaw);
    	float cosr = cos(roll);
    
    	x = sinr * cosp * cosy - cosr * sinp * siny;
    	y = cosr * sinp * cosy + sinr * cosp * siny;
    	z = cosr * cosp * siny - sinr * sinp * cosy;
    	w = cosr * cosp * cosy + sinr * sinp * siny;
    
    	QuatNormalise();
    }
    
    void Quaternion::CreateMatrix(float *pMatrix)
    {
    	if(pMatrix)
    	{
    		// First Row
    		pMatrix[0] = 1.0f - 2.0f * ( y * y + z * z );
    		pMatrix[1] = 2.0f * ( x * y - w * z );
    		pMatrix[2] = 2.0f * ( x * z + w * z );
    		pMatrix[3] = 0.0f;
    
    		// Second Row
    		pMatrix[4] = 2.0f * ( x * y + w * z );
    		pMatrix[5] = 1.0f - 2.0f * ( x * x + z * z );
    		pMatrix[6] = 2.0f * ( y * z - w * x );
    		pMatrix[7] = 0.0f;
    
    		// Third Row
    		pMatrix[8] = 2.0f * ( x * z - w * y );
    		pMatrix[9] = 2.0f * ( y * z + w * x );
    		pMatrix[10] = 1.0f - 2.0f * ( x * x + y * y );
    		pMatrix[11] = 0.0f;
    
    		// Fourth Row
    		pMatrix[12] = 0;
    		pMatrix[13] = 0;
    		pMatrix[14] = 0;
    		pMatrix[15] = 1.0f;
    	}
    }
    

    and the errors:
    Compiling...
    Quaternion.cpp
    1: error C2653: 'Quaternion' : is not a class or namespace name
    2: error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    3: error C2065: 'x' : undeclared identifier
    4: error C2065: 'y' : undeclared identifier
    5: error C2065: 'z' : undeclared identifier
    6: error C2065: 'w' : undeclared identifier
    7: warning C4508: 'Quaternion' : function should return a value; 'void' return type assumed
    8: error C2653: 'Quaternion' : is not a class or namespace name
    9: fatal error C1903: unable to recover from previous error(s); stopping compilation
    Ship.cpp
    Generating Code...

    edit: added points of errors in code (comments)

    why is it giving out about my constructor and destructor?


  • Registered Users Posts: 2,426 ✭✭✭ressem


    The precompiled header file #include "stdafx.h" should be the first header found in the cpp file. Switch them around and try again.

    Try moving the #include statements into the header file (just to be neat).
    -- Edit:Replace out of with in to. Insert Excuse here--

    .h
    #ifndef QUATERNION_H
    #define QUATERNION_H

    #include <cmath>
    #include "Vector.h"

    .cpp
    #include "stdafx.h"
    #include "Quaternion.h"

    --- --


    From the wiki on precompiled headers
    stdafx.h

    Visual C++ will not compile anything before the #include "stdafx.h" in the source file, unless the compile option /Yu'stdafx.h' is unchecked (by default); it assumes all code in the source up to and including that line is already compiled.


  • Registered Users Posts: 83,307 ✭✭✭✭Overheal


    that seems to only have crashed the compiler directly.

    on the plus side im only getting one error now :D
    Error 4 fatal error C1001: An internal error has occurred in the compiler. c:\program files\microsoft visual studio 8\vc\include\xlocnum 123

    edit: I've excluded both files from the solution. the compiler still seems to be crashing. Im investigating.


  • Registered Users Posts: 83,307 ✭✭✭✭Overheal


    may have found the culprit.

    It didnt make a difference before I made the Quaternion class,

    but in the project properties under Code Generation I changed the runtime Check from Checking Unitialized Variables and Stack Frames to default.

    *shrugs* anyway it runs. Thanks ressem


  • Advertisement
Advertisement