Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /branches/pure-cfg/src/include/Diderot/inline-matrix.h
ViewVC logotype

View of /branches/pure-cfg/src/include/Diderot/inline-matrix.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 815 - (download) (as text) (annotate)
Tue Apr 12 19:45:09 2011 UTC (8 years, 5 months ago) by jhr
File size: 3648 byte(s)
  added functions to initialize a matrix to zero or the identity
/*! \file inline-matrix.h
 *
 * \author John Reppy
 */

/*
 * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 */

#ifndef _DIDEROT_INLINE_MATRIX_H_
#define _DIDEROT_INLINE_MATRIX_H_

#ifndef _DIDEROT_TYPES_H_
#include "types.h"
#endif
#ifndef _DIDEROT_INLINE_VEC2_H_
#  include "inline-vec2.h"
#endif
#ifndef _DIDEROT_INLINE_VEC3_H_
#  include "inline-vec3.h"
#endif
#ifndef _DIDEROT_INLINE_VEC4_H_
#  include "inline-vec4.h"
#endif


/********** 2x2 matrix functions **********/

STATIC_INLINE void zero2x2f (Diderot_Mat2x2_t dst)
{
    dst[0].v = vec2f(0.0, 0.0);
    dst[1].v = vec2f(0.0, 0.0);
}

STATIC_INLINE void identity2x2f (Diderot_Mat2x2_t dst)
{
    dst[0].v = vec2f(1.0, 0.0);
    dst[1].v = vec2f(0.0, 1.0);
}

STATIC_INLINE void copy2x2f (Diderot_Mat2x2_t dst, Diderot_Mat2x2_t src)
{
    dst[0].v = src[0].v;
    dst[1].v = src[1].v;
}

STATIC_INLINE float trace2x2f (Diderot_Mat2x2_t m)
{
    return m[0].r[0] + m[1].r[1];
}

// The Frobenius norm of a matrix is the sqrt of the sum of the squares of the elements
STATIC_INLINE float norm2x2f (Diderot_Mat2x2_t m)
{
    return sqrtf(dot2f(m[0].v,m[0].v) + dot2f(m[1].v,m[1].v));
}


/********** 3x3 matrix functions **********/

STATIC_INLINE void zero3x3f (Diderot_Mat3x3_t dst)
{
    dst[0].v = vec3f(0.0, 0.0, 0.0);
    dst[1].v = vec3f(0.0, 0.0, 0.0);
    dst[2].v = vec3f(0.0, 0.0, 0.0);
}

STATIC_INLINE void identity3x3f (Diderot_Mat3x3_t dst)
{
    dst[0].v = vec3f(1.0, 0.0, 0.0);
    dst[1].v = vec3f(0.0, 1.0, 0.0);
    dst[2].v = vec3f(0.0, 0.0, 1.0);
}

STATIC_INLINE vec3f_t column3x3f (Diderot_Mat3x3_t m, int i)
{
    return vec3f(m[0].r[i], m[1].r[i], m[2].r[i]);
}

STATIC_INLINE void copy3x3f (Diderot_Mat3x3_t dst, Diderot_Mat3x3_t src)
{
    dst[0].v = src[0].v;
    dst[1].v = src[1].v;
    dst[2].v = src[2].v;
}

STATIC_INLINE vec3f_t mulVec3Mat3x3f (vec3f_t v, Diderot_Mat3x3_t m)
{
    return vec3f(
	dot3f(v, column3x3f(m, 0)),
	dot3f(v, column3x3f(m, 1)),
	dot3f(v, column3x3f(m, 2)));
}

STATIC_INLINE vec3f_t mulMat3x3Vec3f (Diderot_Mat3x3_t m, vec3f_t v)
{
    return vec3f(dot3f(m[0].v, v), dot3f(m[1].v, v), dot3f(m[2].v, v));
}

STATIC_INLINE void mulMat3x3Mat3x3f (Diderot_Mat3x3_t dst, Diderot_Mat3x3_t m1, Diderot_Mat3x3_t m2)
{
    dst[0].v = vec3f(
	dot3f(m1[0].v, column3x3f(m2, 0)),
	dot3f(m1[0].v, column3x3f(m2, 1)),
	dot3f(m1[0].v, column3x3f(m2, 2)));
    dst[1].v = vec3f(
	dot3f(m1[1].v, column3x3f(m2, 0)),
	dot3f(m1[1].v, column3x3f(m2, 1)),
	dot3f(m1[1].v, column3x3f(m2, 2)));
    dst[2].v = vec3f(
	dot3f(m1[2].v, column3x3f(m2, 0)),
	dot3f(m1[2].v, column3x3f(m2, 1)),
	dot3f(m1[2].v, column3x3f(m2, 2)));
}

STATIC_INLINE float trace3x3f (Diderot_Mat3x3_t m)
{
    return m[0].r[0] + m[1].r[1] + m[2].r[2];
}

// The Frobenius norm of a matrix is the sqrt of the sum of the squares of the elements
STATIC_INLINE float norm3x3f (Diderot_Mat3x3_t m)
{
    return sqrtf(dot3f(m[0].v,m[0].v) + dot3f(m[1].v,m[1].v) + dot3f(m[2].v,m[2].v));
}


/********** 4x4 matrix functions **********/

STATIC_INLINE void copy4x4f (Diderot_Mat4x4_t dst, Diderot_Mat4x4_t src)
{
    dst[0].v = src[0].v;
    dst[1].v = src[1].v;
    dst[2].v = src[2].v;
    dst[3].v = src[3].v;
}

STATIC_INLINE float trace4x4f (Diderot_Mat4x4_t m)
{
    return m[0].r[0] + m[1].r[1] + m[2].r[2] + m[3].r[3];
}

// The Frobenius norm of a matrix is the sqrt of the sum of the squares of the elements
STATIC_INLINE float norm4x4f (Diderot_Mat4x4_t m)
{
    return sqrt(dot4f(m[0].v,m[0].v) + dot4f(m[1].v,m[1].v) + dot4f(m[2].v,m[2].v) + dot4f(m[3].v,m[3].v));
}

#endif /* !_DIDEROT_INLINE_MATRIX_H_ */

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0