Vector4.js 1.1 KB
Newer Older
1 2
/**
 * @author supereggbert / http://www.paulbrunt.co.uk/
M
Mr.doob 已提交
3
 * @author philogb / http://blog.thejit.org/
4 5 6 7
 */

THREE.Vector4 = function ( x, y, z, w ) {

8 9 10 11
	this.x = x || 0;
	this.y = y || 0;
	this.z = z || 0;
	this.w = w || 1;
12 13 14 15 16

};

THREE.Vector4.prototype = {

17
	set: function ( x, y, z, w ) {
18

19 20 21 22
		this.x = x;
		this.y = y;
		this.z = z;
		this.w = w;
23

24
	},
25

26
	copy: function ( v ) {
27

28 29 30 31
		this.x = v.x;
		this.y = v.y;
		this.z = v.z;
		this.w = v.w;
32

33
	},
34

35
	add: function ( v1, v2 ) {
36

37 38 39 40
		this.x = v1.x + v2.x;
		this.y = v1.y + v2.y;
		this.z = v1.z + v2.z;
		this.w = v1.w + v2.w;
41

42
	},
43

44
	addSelf: function ( v ) {
45

46 47 48 49
		this.x += v.x;
		this.y += v.y;
		this.z += v.z;
		this.w += v.w;
50

B
Ben Nolan 已提交
51 52
		return this;

53
	},
54

55
	sub: function ( v1, v2 ) {
56

57 58 59 60
		this.x = v1.x - v2.x;
		this.y = v1.y - v2.y;
		this.z = v1.z - v2.z;
		this.w = v1.w - v2.w;
61

62
	},
63

64
	subSelf: function ( v ) {
65

66 67 68 69
		this.x -= v.x;
		this.y -= v.y;
		this.z -= v.z;
		this.w -= v.w;
70

B
Ben Nolan 已提交
71 72
		return this;

73
	},
74

75
	clone: function () {
76

77
		return new THREE.Vector4( this.x, this.y, this.z, this.w );
78

79
	},
80

81
	toString: function () {
82

83
		return 'THREE.Vector4 (' + this.x + ', ' + this.y + ', ' + this.z + ', ' + this.w + ')';
84

85
	}
86 87

};