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

SCM Repository

[diderot] View of /trunk/src/include/Diderot/inline-vec3.h
ViewVC logotype

View of /trunk/src/include/Diderot/inline-vec3.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1115 - (download) (as text) (annotate)
Thu May 5 04:42:18 2011 UTC (8 years, 9 months ago) by jhr
File size: 1955 byte(s)
  More merging of pure-cfg back into trunk
/*! \file inline-vec3.h
 *
 * \author John Reppy
 *
 * \brief inline functions for 3D vectors
 */

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

#ifndef _DIDEROT_INLINE_VEC3_H_
#define _DIDEROT_INLINE_VEC3_H_

#ifndef _DIDEROT_TYPES_H_
#include "Diderot/types.h"
#endif

STATIC_INLINE vec3f_t vec3f (float a, float b, float c)
{
    return __extension__ (vec3f_t){ a, b, c, 0.0f };
}

STATIC_INLINE vec3i_t vec3ftoi (vec3f_t v)
{
    union3f_t u;
    u.v = v;
    return __extension__ (vec3i_t){ (int32_t)u.r[0], (int32_t)u.r[1], (int32_t)u.r[2], 0 };
}

STATIC_INLINE vec3f_t vec3itof (vec3i_t v)
{
    union3i_t u;
    u.v = v;
    return __extension__ (vec3f_t){ (float)u.i[0], (float)u.i[1], (float)u.i[2], 0 };
}

STATIC_INLINE vec3f_t scale3f (float s, vec3f_t v)
{
    return vec3f(s, s, s) * v;
}

STATIC_INLINE vec3f_t lerp3f (vec3f_t a, vec3f_t b, float t)
{
    return a + scale3f(t, b - a);
}

STATIC_INLINE vec3f_t floor3f (vec3f_t v)
{
    union3f_t u;
    u.v = v;
    return vec3f(floorf(u.r[0]), floorf(u.r[1]), floorf(u.r[2]));
}

STATIC_INLINE vec3i_t truncToInt3f (vec3f_t v)
{
    union3f_t t;
    t.v = v;
    return __extension__ (vec3i_t){
	(int32_t)truncf(t.r[0]),
	(int32_t)truncf(t.r[1]),
	(int32_t)truncf(t.r[2]),
	0 };
}

STATIC_INLINE float dot3f (vec3f_t u, vec3f_t v)
{
    union3f_t uv = __extension__ (union3f_t)(u*v);
    return uv.r[0] + uv.r[1] + uv.r[2];
}

STATIC_INLINE float length3f (vec3f_t v)
{
    return sqrtf(dot3f(v, v));
}

STATIC_INLINE vec3f_t normalize3f (vec3f_t v)
{
    return scale3f(1.0 / length3f(v), v);
}

STATIC_INLINE vec3f_t cross3f (vec3f_t u, vec3f_t v)
{
    union3f_t uu = (union3f_t)u;
    union3f_t uv = (union3f_t)v;
    return __extension__ (vec3f_t){
	uu.r[1]*uv.r[2] - uu.r[2]*uv.r[1],
	uu.r[2]*uv.r[0] - uu.r[0]*uv.r[2],
        uu.r[0]*uv.r[1] - uu.r[1]*uv.r[0],
	0 };
}

#endif /* !_DIDEROT_INLINE_VEC3_H_ */

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