Files
kraken/KREngine/kraken/KRVector3.h
Kearwood Gilbert e0aaafc327 - Implemented KRBehavior class
- Imported animations now have the auto_play and loop flags set to false by default
- Implemented Pre-Rotation, Post-Rotation, Scale Offset, Rotate Offset, Scale Pivot, and Rotate Pivot transform attributes.
- Reduced use of euler angles, replacing them with Quaternions where possible
- Fixed bug with incorrect Y rotation in KRMat4::rotate
- Material / GL Context changes have been optimized to reduce redundant glUniform calls
- New KRMesh format implemented, with support for importing BindPose matrices
- Fixed bug that caused a duplicate "default_camera" node to be added rather than picking up an existing "default_camera" node imported from FBX.  This enables animations to drive the camera correctly.
- Implemented KRVector3::Scale
- Implemented KRVector3::KRVector3(double *v);
2013-05-24 12:20:47 -07:00

129 lines
4.5 KiB
C++

//
// KRVector3.h
// KREngine
//
// Copyright 2012 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The views and conclusions contained in the software and documentation are those of the
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert.
//
#ifndef KRVECTOR3
#define KRVECTOR3
#include "KREngine-common.h"
class KRVector4;
class KRVector3 {
public:
union {
struct {
float x, y, z;
};
float c[3];
};
KRVector3();
KRVector3(float X, float Y, float Z);
KRVector3(float v);
KRVector3(float *v);
KRVector3(double *v);
KRVector3(const KRVector3 &v);
KRVector3(const KRVector4 &v);
~KRVector3();
KRVector3& operator =(const KRVector3& b);
KRVector3& operator =(const KRVector4& b);
KRVector3 operator +(const KRVector3& b) const;
KRVector3 operator -(const KRVector3& b) const;
KRVector3 operator +() const;
KRVector3 operator -() const;
KRVector3 operator *(const float v) const;
KRVector3 operator /(const float v) const;
KRVector3& operator +=(const KRVector3& b);
KRVector3& operator -=(const KRVector3& b);
KRVector3& operator *=(const float v);
KRVector3& operator /=(const float v);
bool operator ==(const KRVector3& b) const;
bool operator !=(const KRVector3& b) const;
// Comparison operators are implemented to allow insertion into sorted containers such as std::set
bool operator >(const KRVector3& b) const;
bool operator <(const KRVector3& b) const;
float& operator[](unsigned i);
float operator[](unsigned i) const;
float sqrMagnitude() const; // calculate the square of the magnitude (useful for comparison of magnitudes without the cost of a sqrt() function)
float magnitude() const;
void scale(const KRVector3 &v);
void normalize();
static KRVector3 Normalize(const KRVector3 &v);
static KRVector3 Cross(const KRVector3 &v1, const KRVector3 &v2);
static float Dot(const KRVector3 &v1, const KRVector3 &v2);
static KRVector3 Min();
static KRVector3 Max();
static KRVector3 Zero();
static KRVector3 One();
static KRVector3 Forward();
static KRVector3 Backward();
static KRVector3 Up();
static KRVector3 Down();
static KRVector3 Left();
static KRVector3 Right();
static KRVector3 Scale(const KRVector3 &v1, const KRVector3 &v2);
static KRVector3 Lerp(const KRVector3 &v1, const KRVector3 &v2, float d);
static KRVector3 Slerp(const KRVector3 &v1, const KRVector3 &v2, float d);
static void OrthoNormalize(KRVector3 &normal, KRVector3 &tangent); // Gram-Schmidt Orthonormalization
void setUniform(GLint location) const;
void setXMLAttribute(const std::string &base_name, tinyxml2::XMLElement *e);
void getXMLAttribute(const std::string &base_name, tinyxml2::XMLElement *e, const KRVector3 &default_value);
};
namespace std {
template<>
struct hash<KRVector3> {
public:
size_t operator()(const KRVector3 &s) const
{
size_t h1 = hash<float>()(s.x);
size_t h2 = hash<float>()(s.y);
size_t h3 = hash<float>()(s.z);
return h1 ^ ( h2 << 1 ) ^ (h3 << 2);
}
};
};
#endif