var GLL = function(){
this.isMided = false;
this.position = new THREE.Vector3()
this.objs = [];
this.scale = {x:0,y:0,z:0}
}
var G__ = function(){
this.isMided = false;
this.position = new THREE.Vector3()
this.objs = [];
this.scale = {x:0,y:0,z:0}
}
function l_begin() {return new GLL();}
function __begin() {return new G__();}
function dsk(){
return addDesk();
}
function bd(w){
w = w || c.roomWidth/2
var bd = hp.addBox(w, c.boardHeight, canRad*2, 0, 0, 0, {move:true})
arrTarget.push(bd);
return bd ;
}
function can(){
return addCan()
}
o = function o(x){
x = x || canWidth
return {
scale:{x:x},
position:{ set:function(){}, copy:function(){} },
body:{
position:{ set:function(){}, copy:function(){} }
}
}
}
GLL.prototype.pu = G__.prototype.pu = function(){
for (var i = 0; i < arguments.length; ++i){
this.objs.push(arguments[i]);
}
}
GLL.prototype.end = G__.prototype.end = function(baba){
baba.objs.push(this)
}
GLL.prototype.movVec3 = G__.prototype.movVec3 = function(vec3){
this.objs.forEach(item => {
if (item.objs){//组对象
item.movVec3(vec3)
}
else{
item.body.position.x += vec3.x ;
item.body.position.y += vec3.y ;
item.body.position.z += vec3.z ;
if (item.body.type === 2) {//static
item.body.syncShapes();
item.position.copy( item.body.position )
}
}
})
};
GLL.prototype.movX = G__.prototype.movX = function(val){
this.objs.forEach(item => {
if (item.objs){//组对象
item.movX(val)
}
else{
item.body.position.x += val ;
if (item.body.type === 2) {//static
item.body.syncShapes();
item.position.copy( item.body.position )
}
}
})
};
GLL.prototype.posLeft = function(x, y, z){
this.isMided = false;
this.position.set(x,y,z)
var topY = y;
this.objs.forEach(item => {
if (item.objs){//组对象
if (item.isMided){
var vec3 = {x: x - item.position.x , y: topY - item.position.y, z: z - item.position.z}
item.movVec3(vec3)
}else
item.posLeft(x, topY, z)
}
else{
var posX = x + item.scale.x/2;
var posY = topY + item.scale.y/2;
item.body.position.set(posX, posY, z)
if (item.body.type === 2) {//static
item.body.syncShapes();
item.position.set(posX, posY, z)
}
}
topY += item.scale.y
if (this.scale.x < item.scale.x) //找出最宽item
this.scale.x = item.scale.x;
});
this.scale.y = topY - y;
}
G__.prototype.posLeft = function(x, y, z){
this.isMided = false;
this.position.set(x,y,z)
var endX = x;
this.objs.forEach(item => {
if (item.objs){//组对象
if (item.isMided){
var vec3 = {x: endX - item.position.x , y: y - item.position.y, z: z - item.position.z}
item.movVec3(vec3)
}else
item.posLeft(endX, y, z)
}
else {
var posX = endX + item.scale.x/2;
var posY = y + item.scale.y/2;
item.body.position.set(posX, posY, z)
if (item.body.type === 2) {//static
item.body.syncShapes();
item.position.set(posX, posY, z)
}
}
endX += item.scale.x
if (this.scale.y < item.scale.y) //找出最高item
this.scale.y = item.scale.y;
});
this.scale.x = endX - x;
}
GLL.prototype.posMid = function(){
if (this.isMided)
return;
this.isMided = true;
this.position.x -= this.scale.x/2
this.objs.forEach(item => {
var val = -item.scale.x/2;
if (item.objs){//组对象
item.movX(val)
}
else {
item.body.position.x += val
if (item.body.type === 2) {//static
item.body.syncShapes();
item.position.x = item.body.position.x
}
}
})
}
G__.prototype.posMid = function(){
if (this.isMided)
return;
this.isMided = true;
this.position.x -= this.scale.x/2
var val = -this.scale.x/2
this.objs.forEach(item => {
if (item.objs){//组对象
item.movX(val)
}
else {
item.body.position.x += val;
if (item.body.type === 2) {//static
item.body.syncShapes();
item.position.x = item.body.position.x
}
}
})
}
G__.prototype.pos = GLL.prototype.pos = function(x, y, z){
this.posLeft(x, y, z);
this.posMid();
}