File: mpVector.cxx

package info (click to toggle)
drawxtl 5.4%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 10,004 kB
  • ctags: 1,988
  • sloc: cpp: 34,558; ansic: 2,271; makefile: 190; sh: 55
file content (139 lines) | stat: -rw-r--r-- 3,274 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
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
131
132
133
134
135
136
137
138
139
// $Id: mpVector.cxx 797 2009-01-16 15:06:53Z larry $
/*  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; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
//
/////////////////////////////////////////////////////////////////////////////////////////////////////
//
//	FileName:	mpVector.cpp
//	Author	:	Michael Y. Polyakov
//	email	:	myp@andrew.cmu.edu	or  mikepolyakov@hotmail.com
//	Website	:	www.angelfire.com/linux/myp
//	Date	:	7/16/2002
//	
//		Provides basic vector handling. 
//////////////////////////////////////////////////////////////////////////////////////////////////////

#include "mpVector.h"

mpVector::mpVector(float xx, float yy, float zz) : 
	x(xx), y(yy), z(zz)
	{ }

mpVector::mpVector() : x(0), y(0), z(0)
	{ }
mpVector::mpVector(const mpVector& other) : x(other.x), y(other.y), z(other.z)
	{ }

mpVector& mpVector::Normalize()
{
	float length = (float)sqrt(x*x + y*y + z*z);
	if(!length) return *this;
	x /= length;
	y /= length;
	z /= length;
	return *this;
}

float mpVector::Magnitude()
{
	return (float)sqrt(x*x + y*y + z*z);
}

mpVector mpVector::Cross(const mpVector& other)
{
	return mpVector(y*other.z-z*other.y, z*other.x-x*other.z, x*other.y-y*other.x);
}

mpVector mpVector::operator - (mpVector v) 
{
	return mpVector(x - v.x, y - v.y, z - v.z);
}

mpVector mpVector::operator + (mpVector v)
{
	return mpVector(x + v.x, y + v.y, z + v.z);
}

float mpVector ::operator * (mpVector v)
{
	return x*v.x + y*v.y + z*v.z;
}
mpVector mpVector::operator - (float c)
{
	return mpVector(x-c, y-c, z-c);
}

mpVector mpVector::operator + (float c)
{
	return mpVector(x+c, y+c, z+c);
}

mpVector mpVector::operator / (float c)
{
	return mpVector(x/c, y/c, z/c);
}

mpVector mpVector::operator * (float c)
{
	return mpVector(x*c, y*c, z*c);
}

void mpVector::operator = (const mpVector& other)
{
	x = other.x;
	y = other.y;
	z = other.z;
}

mpVector::operator mp4Vector() const
{
	return mp4Vector(*this);
}


mp4Vector::mp4Vector() : x(0), y(0), z(0), val(0)
{ }

mp4Vector::mp4Vector(float aa, float bb, float cc, float dd) :
	x(aa), y(bb), z(cc), val(dd)
{ }

mp4Vector::mp4Vector(const mp4Vector& other) : 
	x(other.x), y(other.y), z(other.z), val(other.val)
{ }

mp4Vector::mp4Vector(const mpVector& v, const float value) :
	x(v.x), y(v.x), z(v.z), val(value)
{ }

void mp4Vector::operator = (const mp4Vector& v)
{
	x = v.x; y = v.y; z = v.z; val = v.val;
}

void mp4Vector::operator = (const mpVector& v)
{
	x = v.x; y = v.y; z = v.z;
}

mp4Vector::operator mpVector() const
{
	return mpVector(x, y, z);
}

bool mp4Vector::operator == (const mp4Vector& v) const
{
	return x == v.x && y == v.y && z == v.z && val == v.val;
}