Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
if(!dojo._hasResource["dojox.gfx3d.vector"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["dojox.gfx3d.vector"] = true;
3
dojo.provide("dojox.gfx3d.vector");
4
 
5
dojo.mixin(dojox.gfx3d.vector, {
6
	sum: function(){
7
		// summary: sum of the vectors
8
		var v = {x: 0, y: 0, z:0};
9
		dojo.forEach(arguments, function(item){ v.x += item.x; v.y += item.y; v.z += item.z; });
10
		return v;
11
	},
12
 
13
	center: function(){
14
		// summary: center of the vectors
15
		var l = arguments.length;
16
		if(l == 0){
17
			return {x: 0, y: 0, z: 0};
18
		}
19
		var v = dojox.gfx3d.vector.sum(arguments);
20
		return {x: v.x/l, y: v.y/l, z: v.z/l};
21
	},
22
 
23
	substract: function(/* Pointer */a, /* Pointer */b){
24
		return  {x: a.x - b.x, y: a.y - b.y, z: a.z - b.z};
25
	},
26
 
27
	_crossProduct: function(x, y, z, u, v, w){
28
		// summary: applies a cross product of two vectorss, (x, y, z) and (u, v, w)
29
		// x: Number: an x coordinate of a point
30
		// y: Number: a y coordinate of a point
31
		// z: Number: a z coordinate of a point
32
		// u: Number: an x coordinate of a point
33
		// v: Number: a y coordinate of a point
34
		// w: Number: a z coordinate of a point
35
		return {x: y * w - z * v, y: z * u - x * w, z: x * v - y * u}; // Object
36
	},
37
 
38
	crossProduct: function(/* Number||Point */ a, /* Number||Point */ b, /* Number, optional */ c, /* Number, optional */ d, /* Number, optional */ e, /* Number, optional */ f){
39
		// summary: applies a matrix to a point
40
		// matrix: dojox.gfx3d.matrix.Matrix3D: a 3D matrix object to be applied
41
		// a: Number: an x coordinate of a point
42
		// b: Number: a y coordinate of a point
43
		// c: Number: a z coordinate of a point
44
		// d: Number: an x coordinate of a point
45
		// e: Number: a y coordinate of a point
46
		// f: Number: a z coordinate of a point
47
		if(arguments.length == 6 && dojo.every(arguments, function(item){ return typeof item == "number"; })){
48
			return dojox.gfx3d.vector._crossProduct(a, b, c, d, e, f); // Object
49
		}
50
		// branch
51
		// a: Object: a point
52
		// b: Object: a point
53
		// c: null
54
		// d: null
55
		// e: null
56
		// f: null
57
		return dojox.gfx3d.vector._crossProduct(a.x, a.y, a.z, b.x, b.y, b.z); // Object
58
	},
59
 
60
	_dotProduct: function(x, y, z, u, v, w){
61
		// summary: applies a cross product of two vectorss, (x, y, z) and (u, v, w)
62
		// x: Number: an x coordinate of a point
63
		// y: Number: a y coordinate of a point
64
		// z: Number: a z coordinate of a point
65
		// u: Number: an x coordinate of a point
66
		// v: Number: a y coordinate of a point
67
		// w: Number: a z coordinate of a point
68
		return x * u + y * v + z * w; // Number
69
	},
70
	dotProduct: function(/* Number||Point */ a, /* Number||Point */ b, /* Number, optional */ c, /* Number, optional */ d, /* Number, optional */ e, /* Number, optional */ f){
71
		// summary: applies a matrix to a point
72
		// matrix: dojox.gfx3d.matrix.Matrix3D: a 3D matrix object to be applied
73
		// a: Number: an x coordinate of a point
74
		// b: Number: a y coordinate of a point
75
		// c: Number: a z coordinate of a point
76
		// d: Number: an x coordinate of a point
77
		// e: Number: a y coordinate of a point
78
		// f: Number: a z coordinate of a point
79
		if(arguments.length == 6 && dojo.every(arguments, function(item){ return typeof item == "number"; })){
80
			return dojox.gfx3d.vector._dotProduct(a, b, c, d, e, f); // Object
81
		}
82
		// branch
83
		// a: Object: a point
84
		// b: Object: a point
85
		// c: null
86
		// d: null
87
		// e: null
88
		// f: null
89
		return dojox.gfx3d.vector._dotProduct(a.x, a.y, a.z, b.x, b.y, b.z); // Object
90
	},
91
 
92
	normalize: function(/* Point||Array*/ a, /* Point */ b, /* Point */ c){
93
		// summary: find the normal of the implicit surface
94
		// a: Object: a point
95
		// b: Object: a point
96
		// c: Object: a point
97
		var l, m, n;
98
		if(a instanceof Array){
99
			l = a[0]; m = a[1]; n = a[2];
100
		}else{
101
			l = a; m = b; n = c;
102
		}
103
 
104
		var u = dojox.gfx3d.vector.substract(m, l);
105
		var v = dojox.gfx3d.vector.substract(n, l);
106
		return dojox.gfx3d.vector.crossProduct(u, v);
107
	}
108
});
109
 
110
}