/
FXVec3d.i
111 lines (91 loc) · 3.51 KB
/
FXVec3d.i
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
/***********************************************************************
* FXRuby -- the Ruby language bindings for the FOX GUI toolkit.
* Copyright (c) 2001-2009 by Lyle Johnson. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* For further information please contact the author by e-mail
* at "lyle@lylejohnson.name".
***********************************************************************/
/// Double-precision 3-element vector
class FXVec3d {
public:
FXdouble x;
FXdouble y;
FXdouble z;
public:
/// Default constructor
%extend {
FXVec3d() {
return new FXVec3d(0.0, 0.0, 0.0);
}
}
/// Copy constructor
FXVec3d(const FXVec3d& v);
/// Initialize with components
FXVec3d(FXdouble xx,FXdouble yy,FXdouble zz=1.0);
/// Initialize with color
FXVec3d(FXColor color);
/// Length and square of length
FXdouble length2() const;
FXdouble length() const;
%extend {
/// Indexing
FXdouble __getitem__(FXint i) const {
if(i<0||i>2) rb_raise(rb_eIndexError,"index %d out of bounds",i);
return (*self)[i];
}
FXdouble __setitem__(FXint i,FXdouble d){
if(i<0||i>2) rb_raise(rb_eIndexError,"index %d out of bounds",i);
(*self)[i]=d;
return d;
}
/// Unary
FXVec3d operator-() const { return -(*self); }
/// Adding
FXVec3d operator+(const FXVec3d& other) const { return (*self)+other; }
/// Subtracting
FXVec3d operator-(const FXVec3d& other) const { return (*self)-other; }
/// Scaling
FXVec3d operator*(FXdouble n) const { return (*self)*n; }
FXVec3d operator/(FXdouble n) const {
if(n==0.0) rb_raise(rb_eZeroDivError,"divided by 0");
return (*self)/n;
}
/// Dot product
FXdouble operator*(const FXVec3d& other) const { return (*self)*other; }
FXdouble dot(const FXVec3d& other) const { return (*self)*other; }
/// Cross product
FXVec3d operator^(const FXVec3d& other) const { return (*self)^other; }
FXVec3d cross(const FXVec3d& other) const { return (*self)^other; }
/// Equality tests
bool operator==(const FXVec3d& other) const { return (*self)==other; }
/// Normalize vector
FXVec3d normalize() const { return normalize(*self); }
/// Lowest or highest components
FXVec3d lo(const FXVec3d& other) const { return lo(*self,other); }
FXVec3d hi(const FXVec3d& other) const { return hi(*self,other); }
/// Compute normal from three points a,b,c
static FXVec3d normal(const FXVec3d& a,const FXVec3d& b,const FXVec3d& c){
return FX::normal(a,b,c);
}
/// Compute approximate normal from four points a,b,c,d
static FXVec3d normal(const FXVec3d& a,const FXVec3d& b,const FXVec3d& c,const FXVec3d& d){
return FX::normal(a,b,c,d);
}
}
/// Clamp values of vector between limits
FXVec3d& clamp(FXdouble lo,FXdouble hi);
};