[7f9531]: vecops.h  Maximize  Restore  History

Download this file

131 lines (109 with data), 3.8 kB

  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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*=============================================================================
Asteroids3D - a first person game of blowing up asteroids
Copyright Š Jan Engelhardt <jengelh [at] linux01 gwdg de>, 2003 - 2005
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public
License along with this program kit; if not, write to:
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Boston, MA 02110-1301 USA
=============================================================================*/
#ifndef AS3D_VECOPS_H
#define AS3D_VECOPS_H 1
#ifdef __cplusplus
extern "C" {
#endif
#include <math.h>
#include <string.h>
#include "asteroids3D.h"
#if !defined(__NO_INLINE__) && defined(__OPTIMIZE__)
# ifndef IMPLEMENT_vecops
# define IMPLEMENT_vecops
# endif
# define autolinkage static inline
#else
# ifdef IMPLEMENT_vecops
# define autolinkage
# endif
# define DECLARE_vecops
#endif
extern const Vector ZERO_VEC;
#ifdef DECLARE_vecops
extern void vec_add(Vector *, const Vector *, const Vector *);
extern void vec_addmul(Vector *, const Vector *, double, const Vector *);
extern double vec_dist(const Vector *, const Vector *);
extern double vec_dot(const Vector *, const Vector *);
extern double vec_length(const Vector *);
extern void vec_sdiv(Vector *, const Vector *, double);
extern void vec_smul(Vector *, const Vector *, double);
extern void vec_sub(Vector *, const Vector *, const Vector *);
extern void vec_zero(Vector *);
extern double vp_length(double, double, double);
#endif // DECLARE_vecops
#ifdef IMPLEMENT_vecops
autolinkage void vec_add(Vector *r, const Vector *v, const Vector *w) {
r->x = v->x + w->x;
r->y = v->y + w->y;
r->z = v->z + w->z;
//vec_addmul(r, v, 1, w);
return;
}
autolinkage void vec_addmul(Vector *r, const Vector *v, double f,
const Vector *w)
{
r->x = v->x + f * w->x;
r->y = v->y + f * w->y;
r->z = v->z + f * w->z;
return;
}
autolinkage void vec_sub(Vector *r, const Vector *v, const Vector *w) {
r->x = v->x - w->x;
r->y = v->y - w->y;
r->z = v->z - w->z;
//vec_addmul(r, v, -1, w);
return;
}
autolinkage void vec_smul(Vector *r, const Vector *v, double f) {
r->x = v->x * f;
r->y = v->y * f;
r->z = v->z * f;
//vec_addmul(r, &ZERO_VEC, f, v);
return;
}
autolinkage void vec_sdiv(Vector *r, const Vector *v, double f) {
r->x = v->x / f;
r->y = v->y / f;
r->z = v->z / f;
//vec_addmul(r, &ZERO_VEC, 1 / f, v); // <- imprecise
return;
}
autolinkage double vec_dot(const Vector *a, const Vector *b) {
return a->x * b->x + a->y * b->y + a->z * b->z;
}
autolinkage double vec_length(const Vector *v) {
return sqrt(vec_dot(v, v));
}
autolinkage double vp_length(double x, double y, double z) {
return sqrt(x * x + y * y + z * z);
}
autolinkage double vec_dist(const Vector *a, const Vector *b) {
return vp_length(b->x - a->x, b->y - a->y, b->z - a->z);
}
autolinkage void vec_zero(Vector *v) {
memset(v, 0, sizeof(Vector));
return;
}
#endif // IMPLEMENT_vecops
#undef DECLARE_vecops
#undef IMPLEMENT_vecops
#ifdef __cplusplus
} // extern "C"
#endif
#endif // AS3D_VECOPS_H
//=============================================================================

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks