2011-10-25 05:03:10 +00:00
//
// KRMat4.h
2012-03-15 20:09:01 +00:00
// KREngine
2011-10-25 05:03:10 +00:00
//
2012-03-15 20:09:01 +00:00
// Copyright 2012 Kearwood Gilbert. All rights reserved.
2011-10-25 06:16:47 +00:00
//
// 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.
2011-10-25 05:03:10 +00:00
//
2013-01-11 03:21:19 +00:00
# include "KRVector3.h"
2013-04-25 16:21:28 -07:00
# include "KRVector4.h"
2011-10-25 05:03:10 +00:00
2013-01-11 03:21:19 +00:00
# include "KREngine-common.h"
2012-03-15 23:58:37 +00:00
2011-10-25 05:03:10 +00:00
# ifndef KRMAT4_I
# define KRMAT4_I
# define EMPTY_MATRIX4 { 0.0, 0.0, 0.0, 0.0,\
0.0 , 0.0 , 0.0 , 0.0 , \
0.0 , 0.0 , 0.0 , 0.0 , \
0.0 , 0.0 , 0.0 , 0.0 }
# define IDENTITY_MATRIX4 { 1.0, 0.0, 0.0, 0.0,\
0.0 , 1.0 , 0.0 , 0.0 , \
0.0 , 0.0 , 1.0 , 0.0 , \
0.0 , 0.0 , 0.0 , 1.0 }
typedef enum {
X_AXIS ,
Y_AXIS ,
Z_AXIS
} AXIS ;
2012-10-18 07:32:21 +00:00
class KRQuaternion ;
2011-10-25 05:03:10 +00:00
class KRMat4 {
2013-04-25 16:21:28 -07:00
public :
2013-05-13 13:16:25 -07:00
float c [ 16 ] ; // Matrix components, in column-major order
2013-04-25 16:21:28 -07:00
2011-10-25 05:03:10 +00:00
// Default constructor - Creates an identity matrix
KRMat4 ( ) ;
2013-04-25 16:21:28 -07:00
KRMat4 ( float * pMat ) ;
2011-10-25 05:03:10 +00:00
2013-02-20 18:24:07 -08:00
KRMat4 ( const KRVector3 & axis_x , const KRVector3 & axis_y , const KRVector3 & axis_z , const KRVector3 & trans ) ;
2011-10-25 05:03:10 +00:00
// Destructor
~ KRMat4 ( ) ;
// Copy constructor
KRMat4 ( const KRMat4 & m ) ;
// Overload assignment operator
KRMat4 & operator = ( const KRMat4 & m ) ;
2012-02-10 05:48:59 +00:00
// Overload comparison operator
2013-10-08 20:44:31 -07:00
bool operator = = ( const KRMat4 & m ) const ;
2012-02-10 05:48:59 +00:00
2011-10-25 05:03:10 +00:00
// Overload compound multiply operator
KRMat4 & operator * = ( const KRMat4 & m ) ;
2012-06-10 06:38:31 +00:00
float & operator [ ] ( unsigned i ) ;
float operator [ ] ( unsigned i ) const ;
2011-10-25 05:03:10 +00:00
// Overload multiply operator
//KRMat4& operator*(const KRMat4 &m);
2012-10-26 01:17:35 +00:00
KRMat4 operator * ( const KRMat4 & m ) const ;
2011-10-25 05:03:10 +00:00
2013-04-25 16:21:28 -07:00
float * getPointer ( ) ;
2011-10-25 05:03:10 +00:00
2013-04-25 16:21:28 -07:00
void perspective ( float fov , float aspect , float nearz , float farz ) ;
void ortho ( float left , float right , float top , float bottom , float nearz , float farz ) ;
void translate ( float x , float y , float z ) ;
2012-09-05 18:14:08 +00:00
void translate ( const KRVector3 & v ) ;
2013-04-25 16:21:28 -07:00
void scale ( float x , float y , float z ) ;
2012-09-05 18:14:08 +00:00
void scale ( const KRVector3 & v ) ;
2013-04-25 16:21:28 -07:00
void scale ( float s ) ;
void rotate ( float angle , AXIS axis ) ;
2012-10-18 07:32:21 +00:00
void rotate ( const KRQuaternion & q ) ;
2011-10-25 05:03:10 +00:00
void bias ( ) ;
bool invert ( ) ;
2012-04-13 01:13:18 +00:00
void transpose ( ) ;
2012-06-10 06:38:31 +00:00
2012-12-15 01:39:32 +00:00
static KRVector3 DotNoTranslate ( const KRMat4 & m , const KRVector3 & v ) ; // Dot product without including translation; useful for transforming normals and tangents
2012-10-18 07:32:21 +00:00
static KRMat4 Invert ( const KRMat4 & m ) ;
static KRMat4 Transpose ( const KRMat4 & m ) ;
2012-06-10 06:38:31 +00:00
static KRVector3 Dot ( const KRMat4 & m , const KRVector3 & v ) ;
2013-04-25 16:21:28 -07:00
static KRVector4 Dot4 ( const KRMat4 & m , const KRVector4 & v ) ;
2012-09-11 03:06:35 +00:00
static float DotW ( const KRMat4 & m , const KRVector3 & v ) ;
static KRVector3 DotWDiv ( const KRMat4 & m , const KRVector3 & v ) ;
2012-10-17 19:43:15 +00:00
static KRMat4 LookAt ( const KRVector3 & cameraPos , const KRVector3 & lookAtPos , const KRVector3 & upDirection ) ;
2012-10-18 08:25:47 +00:00
2013-05-24 12:20:47 -07:00
static KRMat4 Translation ( const KRVector3 & v ) ;
static KRMat4 Rotation ( const KRVector3 & v ) ;
static KRMat4 Scaling ( const KRVector3 & v ) ;
2012-10-18 08:25:47 +00:00
void setUniform ( GLint location ) const ;
2011-10-25 05:03:10 +00:00
} ;
# endif // KRMAT4_I