File: rsVec.h

package info (click to toggle)
rss-glx 0.7.5-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 10,184 kB
  • ctags: 1,561
  • sloc: cpp: 11,577; ansic: 4,233; sh: 3,315; asm: 1,312; xml: 552; makefile: 194; perl: 49
file content (94 lines) | stat: -rw-r--r-- 2,364 bytes parent folder | download
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
/*
 * Copyright (C) 2002  Terence M. Welsh
 * Ported to Linux by Tugrul Galatali <tugrul@galatali.com>
 *
 * rsMath is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as 
 * published by the Free Software Foundation.
 *
 * rsMath 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; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef RSVEC_H
#define RSVEC_H

#include "rsMatrix.h"

class rsMatrix;
class rsVec;

class rsVec {
      public:
	float v[3];

	  rsVec ();
	  rsVec (float xx, float yy, float zz);
	  virtual ~ rsVec ();
	void set (float xx, float yy, float zz);
	float length ();
	float normalize ();
	float dot (rsVec);
	void cross (rsVec, rsVec);
	void scale (float);
	void transPoint (const rsMatrix & m);
	void transVec (const rsMatrix & m);
	int almostEqual (rsVec vec, float tolerance);

	float &operator [] (int i) {
		return v[i];
	} const float &operator [] (int i)const {
		return v[i];
	} rsVec & operator = (const rsVec & vec) {
		v[0] = vec[0];
		v[1] = vec[1];
		v[2] = vec[2];
		return *this;
	};
	rsVec operator + (const rsVec & vec) {
		return (rsVec (v[0] + vec[0], v[1] + vec[1], v[2] + vec[2]));
	};
	rsVec operator - (const rsVec & vec) {
		return (rsVec (v[0] - vec[0], v[1] - vec[1], v[2] - vec[2]));
	};
	rsVec operator * (const float &mul) {
		return (rsVec (v[0] * mul, v[1] * mul, v[2] * mul));
	};
	rsVec operator / (const float &div) {
		float rec = 1.0f / div;

		return (rsVec (v[0] * rec, v[1] * rec, v[2] * rec));
	};
	rsVec & operator += (const rsVec & vec) {
		v[0] += vec[0];
		v[1] += vec[1];
		v[2] += vec[2];
		return *this;
	};
	rsVec & operator -= (const rsVec & vec) {
		v[0] -= vec[0];
		v[1] -= vec[1];
		v[2] -= vec[2];
		return *this;
	};
	rsVec & operator *= (const rsVec & vec) {
		v[0] *= vec[0];
		v[1] *= vec[1];
		v[2] *= vec[2];
		return *this;
	};
	rsVec & operator *= (const float &mul) {
		v[0] *= mul;
		v[1] *= mul;
		v[2] *= mul;
		return *this;
	};
};

#endif // RSVEC_H