Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / gfx3d / vector.js @ 9

History | View | Annotate | Download (1.54 KB)

1
/*
2
        Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3
        Available via Academic Free License >= 2.1 OR the modified BSD license.
4
        see: http://dojotoolkit.org/license for details
5
*/
6

    
7

    
8
if(!dojo._hasResource["dojox.gfx3d.vector"]){
9
dojo._hasResource["dojox.gfx3d.vector"]=true;
10
dojo.provide("dojox.gfx3d.vector");
11
dojo.mixin(dojox.gfx3d.vector,{sum:function(){
12
var v={x:0,y:0,z:0};
13
dojo.forEach(arguments,function(_1){
14
v.x+=_1.x;
15
v.y+=_1.y;
16
v.z+=_1.z;
17
});
18
return v;
19
},center:function(){
20
var l=arguments.length;
21
if(l==0){
22
return {x:0,y:0,z:0};
23
}
24
var v=dojox.gfx3d.vector.sum(arguments);
25
return {x:v.x/l,y:v.y/l,z:v.z/l};
26
},substract:function(a,b){
27
return {x:a.x-b.x,y:a.y-b.y,z:a.z-b.z};
28
},_crossProduct:function(x,y,z,u,v,w){
29
return {x:y*w-z*v,y:z*u-x*w,z:x*v-y*u};
30
},crossProduct:function(a,b,c,d,e,f){
31
if(arguments.length==6&&dojo.every(arguments,function(_2){
32
return typeof _2=="number";
33
})){
34
return dojox.gfx3d.vector._crossProduct(a,b,c,d,e,f);
35
}
36
return dojox.gfx3d.vector._crossProduct(a.x,a.y,a.z,b.x,b.y,b.z);
37
},_dotProduct:function(x,y,z,u,v,w){
38
return x*u+y*v+z*w;
39
},dotProduct:function(a,b,c,d,e,f){
40
if(arguments.length==6&&dojo.every(arguments,function(_3){
41
return typeof _3=="number";
42
})){
43
return dojox.gfx3d.vector._dotProduct(a,b,c,d,e,f);
44
}
45
return dojox.gfx3d.vector._dotProduct(a.x,a.y,a.z,b.x,b.y,b.z);
46
},normalize:function(a,b,c){
47
var l,m,n;
48
if(a instanceof Array){
49
l=a[0];
50
m=a[1];
51
n=a[2];
52
}else{
53
l=a;
54
m=b;
55
n=c;
56
}
57
var u=dojox.gfx3d.vector.substract(m,l);
58
var v=dojox.gfx3d.vector.substract(n,l);
59
return dojox.gfx3d.vector.crossProduct(u,v);
60
}});
61
}