使用HTML5转换完成三维立方体模型,它可以实现360个旋转没有死角。唯一的缺点是不可能在旋转时判断每一张脸的顺序,而一个朋友能理解它。




为了更好地把握变换的本质,决定完成三维立方体的模型,并能实现360无死角的三维旋转效果。

但旋转时,很难判断每一张脸的顺序。这个问题还没有完全解决。我希望有人能回答。

源直接贡献:

复制代码代码如下所示:

cuboid_side_div {。
位置:绝对;
边境:1px solid # 333;
-webkit-transition:ease all 1s;
}



*本版本中存在以下问题:
*在三维旋转在计算有问题
它还缺乏各种模型,包括线、面、椎体、球体、椭球体等。
* /
功能cuboidmodel(left_init,top_init,long_init,width_init,height_init)
{
中的
初始化私有变量
中的
初始化长方体的位置和大小。
左= left_init VaR;
var = top_init;
VaR长= long_init;
VaR的宽度= width_init;
VaR高度= height_init;
初始化转换角,默认值为0。
无功rotatex = 0;
无功rotatey = 0;
无功rotatez = 0;
VaR在= 0;
长方体/物体的六个曲面的定义
无功div_front;
无功div_behind;
无功div_left;
无功div_right;
无功div_top;
无功div_bottom;

中的
初始化一个长方体
中的
根据初始位置 /六表面结构。
this.init =函数(){
创建前面的/ div / div
div_front = document.createelement(div);
div_front.classname =cuboid_side_div ;
div_front.innerhtml =div的前面;
div_front。风格。背景颜色=# f1b2b2 ;
document.body.appendchild(div_front);
创建后面的 / div
div_behind = document.createelement(div);
div_behind.classname =cuboid_side_div ;
div_behind.innerhtml =div后面;
div_behind。风格。背景颜色=# bd91eb ;
document.body.appendchild(div_behind);
创建左/ div
div_left = document.createelement(div);
div_left.classname =cuboid_side_div ;
div_left.innerhtml =div左;
div_left。风格。背景颜色=# 64a3c3 ;
document.body.appendchild(div_left);
创建右/ div
div_right = document.createelement(div);
div_right.classname =cuboid_side_div ;
div_right.innerhtml =div的权利;
div_right。风格。背景颜色=# 78e797 ;
document.body.appendchild(div_right);
创建顶部 / div
div_top = document.createelement(div);
div_top.classname =cuboid_side_div ;
div_top.innerhtml =div上;
div_top。风格。背景颜色=# e7db78 ;
document.body.appendchild(div_top);
创建底部
div_bottom = document.createelement(div);
div_bottom.classname =cuboid_side_div ;
div_bottom.innerhtml =div底;
div_bottom。风格。背景颜色=# e79c78 ;
document.body.appendchild(div_bottom);
This.refresh ();
};
/ /重绘
this.refresh =功能()
{
/ /定义div_front风格
div_front.style.left =左+PX;
div_front.style.top = +PX;
div_front.style.width =长+PX;
div_front.style.height =高度+PX;
div_front.style.webkittransformorigin =50% 50%+((- 1)*宽 / 2)+PX;
/ /定义div_behind风格
div_behind.style.left =左+PX;
div_behind.style.top = +PX;
div_behind.style.width = div_front.style.width;
div_behind.style.height = div_front.style.height;
div_behind.style.webkittransformorigin =50% 50%+((- 1)*宽 / 2)+PX;
/ /定义div_left风格
div_left.style.left =左+((长身高) / 2)+PX;
div_left.style.top = +((高度,宽度) / 2)+PX;
div_left.style.width =高度+PX;
div_left.style.height =宽+PX;
div_left.style.webkittransformorigin =50% 50%+((- 1)*长 / 2)+PX;
/ /定义div_right风格
div_right.style.left = div_left.style.left;
div_right.style.top = div_left.style.top;
div_right.style.width = div_left.style.width;
div_right.style.height = div_left.style.height;
div_right.style.webkittransformorigin =50% 50%+((- 1)*长 / 2)+PX;
/ /定义div_top风格
div_top.style.left =左+PX;
div_top.style.top = +((高度,宽度) / 2)+PX;
div_top.style.width =长+PX;
div_top.style.height =宽+PX;
div_top.style.webkittransformorigin =50% 50%+((- 1)*高 / 2)+PX;
/ /定义div_bottom风格
div_bottom.style.left = div_top.style.left;
div_bottom.style.top = div_top.style.top;
div_bottom.style.width = div_top.style.width;
Div_bottom.style.height = div_top.style.height;
div_bottom.style.webkittransformorigin =50% 50%+((- 1)*高 / 2)+PX;
this.rotate(rotatex,rotatey,rotatez);
};
旋转立方体
this.rotate =函数(x,y,z){
rotatex = x;
rotatey = Y;
rotatez = Z;
无功rotatex_front = rotatex;
无功rotatey_front = rotatey;
无功rotatez_front = rotatez;
每个表面的旋转角{判断}
无功rotatex_behind = rotatex_front + 180;
无功rotatey_behind = rotatey_front *(1);
无功rotatez_behind = rotatez_front *(1);
无功rotatex_top = rotatex_front + 90;
无功rotatey_top = rotatez_front;
无功rotatez_top = rotatey_front *(1);
无功rotatex_bottom = rotatex_front-90;
无功rotatey_bottom = rotatez_front *(1);
无功rotatez_bottom = rotatey_front;
无功rotatex_left = rotatex_front + 90;
无功rotatey_left = rotatez_front - 90;
无功rotatez_left = rotatey_front *(1);
无功rotatex_right = rotatex_front + 90;
无功rotatey_right = rotatez_front + 90;
无功rotatez_right = rotatey_front *(1);
z轴显示判断/顺序。
无功zindex_front_default = - 1;
无功zindex_behind_default = - 6;
无功zindex_top_default = - 5;
无功zindex_bottom_default = - 2;
无功zindex_left_default = - 4;
无功zindex_right_default = - 3;
VaR西=(rotatex_front / 90)% 4;
无功益=(rotatey_front / 90)% 4;
VaR子=(rotatez_front / 90)% 4;
无功zindex_matrix =新的数组();
对于(var i = 0;i < 3;i + +){
zindex_matrix.push(新数组());
}
zindex_matrix =
{zindex_left
{
无功zindex_matrix_behind =zindex_behind ;
/ /在计算
如果((西西= - 4溪<0>=3){)
}(如果其他(西西= - 3溪<1>=2){)
无功zindex_matrix_tmp = zindex_matrix { 0 } { 1 };
zindex_matrix { 0 } { 1 } = zindex_matrix { 1 } { 1 };
zindex_matrix { 1 } { 1 } = zindex_matrix { 1 } { 2 };
zindex_matrix { 1 } { 2 } = zindex_matrix_behind;
zindex_matrix_behind = zindex_matrix_tmp;
}(如果其他(西西= - 2溪<2>=1){)
无功zindex_matrix_tmp = zindex_matrix { 0 } { 1 };
zindex_matrix { 0 } { 1 } = zindex_matrix { 2 } { 1 };
zindex_matrix { 2 } { 1 } = zindex_matrix_tmp;
zindex_matrix_tmp = zindex_matrix { 1 } { 1 };
zindex_matrix { 1 } { 1 } = zindex_matrix_behind;
zindex_matrix_behind = zindex_matrix_tmp;
}(如果其他(西> = 3 = - 1西西<0)){
无功zindex_matrix_tmp = zindex_matrix { 0 } { 1 };
zindex_matrix { 0 } { 1 } = zindex_matrix_behind;
zindex_matrix_behind = zindex_matrix { 2 } { 1 };
zindex_matrix { 2 } { 1 } = zindex_matrix { 1 } { 1 };
zindex_matrix { 1 } { 1 } = zindex_matrix_tmp;
}
(如果(易- 4易> < 0 < = 3)){
无功zindex_matrix_tmp = zindex_matrix { 1 } { 0 };
zindex_matrix { 1 } { 0 } = zindex_matrix_behind;
zindex_matrix_behind = zindex_matrix { 1 } { 2 };
zindex_matrix { 1 } { 2 } = zindex_matrix { 1 } { 1 };
zindex_matrix { 1 } { 1 } = zindex_matrix_tmp;
}(如果(易- 3易> 1 < = 2)){
无功zindex_matrix_tmp = zindex_matrix { 1 } { 0 };
zindex_matrix { 1 } { 0 } = zindex_matrix { 1 } { 2 };
zindex_matrix { 1 } { 2 } = zindex_matrix_tmp;
zindex_matrix_tmp = zindex_matrix { 1 } { 1 };
zindex_matrix { 1 } { 1 } = zindex_matrix_behind;
zindex_matrix_behind = zindex_matrix_tmp;
}(如果(易- 2易> 2 < = 1)){
无功zindex_matrix_tmp = zindex_matrix { 1 } { 0 };
zindex_matrix { 1 } { 0 } = zindex_matrix { 1 } { 1 };
zindex_matrix { 1 } { 1 } = zindex_matrix { 1 } { 2 };
zindex_matrix { 1 } { 2 } = zindex_matrix_behind;
zindex_matrix_behind = zindex_matrix_tmp;
}(如果(易- 1易> 3 <=0)){
}

(如子字4子>0 <=3){)
无功zindex_matrix_tmp = zindex_matrix { 0 } { 1 };
zindex_matrix { 0 } { 1 } = zindex_matrix { 1 } { 0 };
zindex_matrix { 1 } { 0 } = zindex_matrix { 2 } { 1 };
zindex_matrix { 2 } { 1 } = zindex_matrix { 1 } { 2 };
zindex_matrix { 1 } { 2 } = zindex_matrix_tmp;
}(如果(子字3子> 1 <=2)){
无功zindex_matrix_tmp = zindex_matrix { 0 } { 1 };
zindex_matrix { 0 } { 1 } = zindex_matrix { 2 } { 1 };
zindex_matrix { 2 } { 1 } = zindex_matrix_tmp;
zindex_matrix_tmp = zindex_matrix { 1 } { 0 };
zindex_matrix { 1 } { 0 } = zindex_matrix { 1 } { 2 };
zindex_matrix { 1 } { 2 } = zindex_matrix_tmp;
}(如果(子字2子> 2 <=1)){
无功zindex_matrix_tmp = zindex_matrix { 0 } { 1 };
zindex_matrix { 0 } { 1 } = zindex_matrix { 1 } { 2 };
zindex_matrix { 1 } { 2 } = zindex_matrix { 2 } { 1 };
zindex_matrix { 2 } { 1 } = zindex_matrix { 1 } { 0 };
zindex_matrix { 1 } { 0 } = zindex_matrix_tmp;
}(如果(子字- 1子> 3 <=0)){
}
/ /分配在
eval(zindex_matrix { 0 } { 1 } +=+ zindex_top_default);
eval(zindex_matrix { 1 } { 0 } +=+ zindex_left_default);
Eval (zIndex_matrix{1}{1}+ = +zIndex_front_default);
eval(zindex_matrix { 1 } { 2 } +=+ zindex_right_default);
eval(zindex_matrix { 2 } { 1 } +=+ zindex_bottom_default);
eval(zindex_matrix_behind +=+ zindex_behind_default);
/前面
无功transform_rotate_front = 的观点(500px)rotatex(+ rotatex_front + )
°)rotatey(+ rotatey_front +
°)rotatez(+ rotatez_front +°);
div_front.style.webkittransform = transform_rotate_front;
div_front.style.zindex = zindex_front;
在后面
无功transform_rotate_behind = 的观点(500px)rotatex(+ rotatex_behind + )
°)rotatey(+ rotatey_behind +
°)rotatez(+ rotatez_behind +°);
div_behind.style.webkittransform = transform_rotate_behind;
div_behind.style.zindex = zindex_behind;
左/左
无功transform_rotate_left = 的观点(500px)rotatex(+ rotatex_left + )
°)rotatez(+ rotatez_left +
°)rotatey(+ rotatey_left +°);
div_left.style.webkittransform = transform_rotate_left;
div_left.style.zindex = zindex_left;
对/对
无功transform_rotate_right = 的观点(500px)rotatex(+ rotatex_right + )
°)rotatez(+ rotatez_right +
°)rotatey(+ rotatey_right +°);
div_right.style.webkittransform = transform_rotate_right;
div_right.style.zindex = zindex_right;

无功transform_rotate_top = 的观点(500px)rotatex(+ rotatex_top + )
°)rotatez(+ rotatez_top +
°)rotatey(+ rotatey_top +°);
div_top.style.webkittransform = transform_rotate_top;
div_top.style.zindex = zindex_top;
底部
无功transform_rotate_bottom = 的观点(500px)rotatex(+ rotatex_bottom + )
°)rotatez(+ rotatez_bottom +
°)rotatey(+ rotatey_bottom +°);
div_bottom.style.webkittransform = transform_rotate_bottom;
div_bottom.style.zindex = zindex_bottom;
};
重置长度、宽度和高度
this.resize =功能(new_long,new_width,new_height)
{
长= new_long;
宽度= new_width;
高度= new_height;
This.refresh();
};
重新设置/长方体位置
this.move =功能(new_left,new_top){
最高new_top;
左= new_left;
This.refresh();
};
}

函数转换(){
cuboid.resize(parseInt(document.getelementbyid(长)的价值。),
ParseInt(document.getelementbyid(宽度)。值),
ParseInt(document.getelementbyid(高度)。价值)));
Cuboid.move(parseInt(document.getelementbyid(左)的价值。),
ParseInt(document.getelementbyid(顶)。价值)));
cuboid.rotate(parseInt(document.getelementbyid(rotatex)。值),
ParseInt(document.getelementbyid(rotatey)。值),
ParseInt(document.getelementbyid(rotatez)。价值)));
/ / cuboid.refresh();
}


左:PX

上图:PX

长:PX

宽度:PX

高度:PX

rotatex:°

RotateY: DEG

RotateZ:°






VaR的长方体=新cuboidmodel(parseInt(document.getelementbyid(左)的价值。),
ParseInt(document.getelementbyid(顶)。值),
ParseInt(document.getelementbyid()。值),
ParseInt(document.getelementbyid(宽度)。值),
ParseInt(document.getelementbyid(高度)。价值)));
Cuboid.init();