~hidravfx-dev-team/hidravfx/trunk

« back to all changes in this revision

Viewing changes to src/vertex.c

  • Committer: illusions.hu at gmail
  • Date: 2012-09-09 15:17:57 UTC
  • Revision ID: illusions.hu@gmail.com-20120909151757-slk3bgssh25k2xu2
vertex.c added

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
Copyright (C) 2012 HidraVFX development team
 
3
            <https://launchpad.net/~hidravfx-dev-team>
 
4
 
 
5
This file is part of the HidraVFX project.
 
6
 
 
7
HidraVFX is free software: you can redistribute it and/or modify
 
8
it under the terms of the GNU General Public License as published by
 
9
the Free Software Foundation, either version 3 of the License, or
 
10
(at your option) any later version.
 
11
 
 
12
HidraVFX is distributed in the hope that it will be useful,
 
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
15
GNU General Public License for more details.
 
16
 
 
17
You should have received a copy of the GNU General Public License
 
18
along with HidraVFX. If not, see <http://www.gnu.org/licenses/>.
 
19
****************************************************************************/
 
20
 
 
21
#include <math.h>
 
22
#include <mathplus.h>
 
23
#include <vertex.h>
 
24
 
 
25
void tpoint_swap(tpoint *a, tpoint *b)
 
26
{
 
27
  tpoint temp;
 
28
 
 
29
  temp.x = a->x;
 
30
  temp.y = a->y;
 
31
  temp.z = a->z;
 
32
  a->x = b->x;
 
33
  a->y = b->y;
 
34
  a->z = b->z;
 
35
  b->x = temp.x;
 
36
  b->y = temp.y;
 
37
  b->z = temp.z;
 
38
}
 
39
 
 
40
tpoint tpoint_2d(double xi,double yi)
 
41
{
 
42
  tpoint p;
 
43
  p.x = xi;
 
44
  p.y = yi;
 
45
  p.z = 0;
 
46
  return p;
 
47
}
 
48
 
 
49
 
 
50
tpoint tpoint_3d(double xi,double yi,double zi)
 
51
{
 
52
  tpoint p;
 
53
  p.x = xi;
 
54
  p.y = yi;
 
55
  p.z = zi;
 
56
  return p;
 
57
}
 
58
 
 
59
tvertex tvertex_2d(double x0,double y0)
 
60
{
 
61
  tvertex v;
 
62
  v.x = x0;
 
63
  v.y = y0;
 
64
  v.z = 1;
 
65
  return v;
 
66
}
 
67
 
 
68
tvertex tvertex_3d(double x0,double y0,double z0)
 
69
{
 
70
  tvertex v;
 
71
  v.x = x0;
 
72
  v.y = y0;
 
73
  v.z = z0;
 
74
  return v;
 
75
}
 
76
 
 
77
tvertex tvertex_copy(tvertex *a)
 
78
{
 
79
  tvertex v;
 
80
  v.x = a->x;
 
81
  v.y = a->y;
 
82
  v.z = a->z;
 
83
  return v;
 
84
}
 
85
 
 
86
tvertex tvertex_null(void)
 
87
{
 
88
  tvertex v;
 
89
  v.x = 0;
 
90
  v.y = 0;
 
91
  v.z = 0;
 
92
  return v;
 
93
}
 
94
 
 
95
tvertex tvertex_sub(tvertex *v1, tvertex *v2)
 
96
{
 
97
  tvertex v;
 
98
  v.x = v1->x-v2->x;
 
99
  v.y = v1->y-v2->y;
 
100
  v.z = v1->z-v2->z;
 
101
  return v;
 
102
}
 
103
 
 
104
tvertex tvertex_add(tvertex *v1, tvertex *v2)
 
105
{
 
106
  tvertex v;
 
107
  v.x = v1->x+v2->x;
 
108
  v.y = v1->y+v2->y;
 
109
  v.z = v1->z+v2->z;
 
110
  return v;
 
111
}
 
112
 
 
113
tvertex tvertex_mul(tvertex *v1, tvertex *v2)
 
114
{
 
115
  tvertex v;
 
116
  v.x = v1->x*v2->x;
 
117
  v.y = v1->y*v2->y;
 
118
  v.z = v1->z*v2->z;
 
119
  return v;
 
120
}
 
121
 
 
122
double tvertex_length(tvertex *v)
 
123
{
 
124
  double l;
 
125
  l = sqrt(sqr(v->x)+sqr(v->y)+sqr(v->z));
 
126
  return l;
 
127
}