1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
/* bzflag
* Copyright (c) 1993 - 2006 Tim Riker
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the license found in the file
* named COPYING that should have accompanied this file.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef __VECTOR_MATH_H__
#define __VECTOR_MATH_H__
#include <string.h>
typedef float fvec2[2];
typedef float fvec3[3];
typedef float fvec4[4];
class cfvec2 {
public:
cfvec2(){};
cfvec2(const float values[2]) {
memcpy (data, values, sizeof(float[2]));
}
cfvec2& operator=(const float values[2]) {
memcpy (data, values, sizeof(float[2]));
return *this;
}
inline float& operator[](int pos) { return data[pos]; }
float data[2];
};
class cfvec3 {
public:
cfvec3(){};
cfvec3(const float values[3]) {
memcpy (data, values, sizeof(float[3]));
}
cfvec3& operator=(const float values[3]) {
memcpy (data, values, sizeof(float[3]));
return *this;
}
inline float& operator[](int pos) { return data[pos]; }
float data[3];
};
class cfvec4 {
public:
cfvec4(){};
cfvec4(const float values[4]) {
memcpy (data, values, sizeof(float[4]));
}
cfvec4& operator=(const float values[4]) {
memcpy (data, values, sizeof(float[4]));
return *this;
}
inline float& operator[](int pos) { return data[pos]; }
float data[4];
};
// FIXME - some these should go into a common file
// Some handy geometry functions
static inline void vec3add (float *result, const float* v1, const float* v2)
{
result[0] = v1[0] + v2[0];
result[1] = v1[1] + v2[1];
result[2] = v1[2] + v2[2];
return;
}
static inline void vec3sub (float *result, const float* v1, const float* v2)
{
result[0] = v1[0] - v2[0];
result[1] = v1[1] - v2[1];
result[2] = v1[2] - v2[2];
return;
}
static inline float vec3dot (const float* v1, const float* v2)
{
return (v1[0] * v2[0]) + (v1[1] * v2[1]) + (v1[2] * v2[2]);
}
static inline void vec3cross (float* result, const float* v1, const float* v2)
{
result[0] = (v1[1] * v2[2]) - (v1[2] * v2[1]);
result[1] = (v1[2] * v2[0]) - (v1[0] * v2[2]);
result[2] = (v1[0] * v2[1]) - (v1[1] * v2[0]);
return;
}
#endif // __VECTOR_MATH_H__
// Local variables: ***
// mode: C++ ***
// tab-width: 8 ***
// c-basic-offset: 2 ***
// indent-tabs-mode: t ***
// End: ***
// ex: shiftwidth=2 tabstop=8
|