[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
立方体の変な形になるバグを改良しました。
ソースも乗せておきます。
数字が表示されていますが、
点の番号と座標です。
影のつけ方なんかは適当です。
var ay = 0;
var v = 60;
var s = Stage.width / 2 / Math.tan(v / 2 * Math.PI / 180);
var emp: Array = new Array();
var cha: Number = 0;
var cl = new Array();
for(i = 0; i < cl.length; i++){
cl[i] = new Array();
}
cl = [
[-50, 50, -50],
[50, 50, -50],
[50, 50, 50],
[-50, 50, 50],
[-50, -50, -50],
[50, -50, -50],
[50, -50, 50],
[-50, -50, 50]
];
var cw = new Array();
for(i = 0; i < cl.length; i++){
cw[i] = new Array();
}
var cwx = new Array();
for(i = 0; i < cl.length; i++){
cwx[i] = new Array();
}
var cwy = new Array();
for(i = 0; i < cl.length; i++){
cwy[i] = new Array();
}
var cc = new Array();
var cp = new Array();
var cv = new Array();
cc = [0, 0, 400];
cp = [
[0, 1, 4, 0xB0B0B0],
[1, 4, 5, 0xB0B0B0],
[2, 6, 7, 0xC0C0C0],
[2, 3, 7, 0xC0C0C0],
[0, 1, 3, 0xA0A0A0],
[1, 2, 3, 0xA0A0A0],
[5, 6, 7, 0xD0D0D0],
[4, 5, 7, 0xD0D0D0],
[0, 3, 4, 0x909090],
[3, 4, 7, 0x909090],
[2, 5, 6, 0xE0E0E0],
[1, 2, 5, 0xE0E0E0]
];
this.onEnterFrame = function()
{
this.clear();
for(i = 0; i < cl.length; i++){
cwx[i][0] = cl[i][0];
cwx[i][1] = cl[i][1] * Math.cos(ax * Math.PI / 180) - cl[i][2] * Math.sin(ax * Math.PI / 180);
cwx[i][2] = cl[i][1] * Math.sin(ax * Math.PI / 180) + cl[i][2] * Math.cos(ax * Math.PI / 180);
}
for(i = 0; i < cwx.length; i++){
cwy[i][0] = cwx[i][0] * Math.cos(ay * Math.PI / 180) + cwx[i][2] * Math.sin(ay * Math.PI / 180);
cwy[i][1] = cwx[i][1];
cwy[i][2] = - cwx[i][0] * Math.sin(ay * Math.PI / 180) + cwx[i][2] * Math.cos(ay * Math.PI / 180);
}
for(i = 0; i < cwy.length; i++){
cw[i][0] = cwy[i][0] + cc[0];
cw[i][1] = cwy[i][1] + cc[1];
cw[i][2] = cwy[i][2] + cc[2];
}
for(i = 0; i < cw.length; i++){
cv[i] = [s * cw[i][0] / cw[i][2], s * cw[i][1] / cw[i][2]];
}
do{
cha = 0;
for(i = 0; i + 1 < cp.length; i++){
if(Math.sqrt(Math.pow((cw[cp[i][0]][0] + cw[cp[i][1]][0] + cw[cp[i][2]][0]) / 3, 2) + Math.pow((cw[cp[i][0]][1] + cw[cp[i][1]][1] + cw[cp[i][2]][1]) / 3, 2) + Math.pow((cw[cp[i][0]][2] + cw[cp[i][1]][2] + cw[cp[i][2]][2]) / 3, 2)) < Math.sqrt(Math.pow((cw[cp[i + 1][0]][0] + cw[cp[i + 1][1]][0] + cw[cp[i + 1][2]][0]) / 3, 2) + Math.pow((cw[cp[i + 1][0]][1] + cw[cp[i + 1][1]][1] + cw[cp[i + 1][2]][1]) / 3, 2) + Math.pow((cw[cp[i + 1][0]][2] + cw[cp[i + 1][1]][2] + cw[cp[i + 1][2]][2]) / 3, 2))){
emp = cp[i];
cp[i] = cp[i + 1];
cp[i + 1] = emp;
cha++;
}
}
}while(cha > 0);
for(i = 0; i < cp.length; i++){
this.beginFill(cp[i][3]);
this.lineStyle(0, cp[i][3]);
this.moveTo(cv[cp[i][0]][0] + Stage.width / 2, Stage.height / 2 - cv[cp[i][0]][1]);
this.lineTo(cv[cp[i][1]][0] + Stage.width / 2, Stage.height / 2 - cv[cp[i][1]][1]);
this.lineTo(cv[cp[i][2]][0] + Stage.width / 2, Stage.height / 2 - cv[cp[i][2]][1]);
this.lineTo(cv[cp[i][0]][0] + Stage.width / 2, Stage.height / 2 - cv[cp[i][0]][1]);
this.endFill();
}
/*
for(i = 0; i < cp.length; i++){
this.lineStyle(1, 0x000000);
this.moveTo(cv[cp[i][0]][0] + Stage.width / 2, Stage.height / 2 - cv[cp[i][0]][1]);
this.lineTo(cv[cp[i][1]][0] + Stage.width / 2, Stage.height / 2 - cv[cp[i][1]][1]);
this.lineTo(cv[cp[i][2]][0] + Stage.width / 2, Stage.height / 2 - cv[cp[i][2]][1]);
this.lineTo(cv[cp[i][0]][0] + Stage.width / 2, Stage.height / 2 - cv[cp[i][0]][1]);
}
*/
for(i = 0; i < cv.length; i++){
this.createTextField("text_" + i, i + 1, cv[i][0] + Stage.width / 2, Stage.height / 2 - cv[i][1], 20, 20);
this["text_" + i].setNewTextFormat(new TextFormat("MS Pゴシック", 16, 0xFF0000, false, false, false));
this["text_" + i].text = i;
this.createTextField("text_" + i + cv.length, i + cv.length + 1, cv[i][0] + Stage.width / 2 + 20, Stage.height / 2 - cv[i][1], 100, 10);
this["text_" + i + cv.length].setNewTextFormat(new TextFormat("MS Pゴシック", 6, 0x0000FF, false, false, false));
this["text_" + i + cv.length].text = "( " + Math.round(cw[i][0] * 100) / 100 + ", " + Math.round(cw[i][1] * 100) / 100 + ", " + Math.round(cw[i][2] * 100) / 100 + ")";
}
if(Key.isDown(Key.UP))
{
cc[2] += 10;
}
if(Key.isDown(Key.DOWN))
{
cc[2] -= 10;
}
if(Key.isDown(Key.LEFT))
{
cc[0] -= 10;
}
if(Key.isDown(Key.RIGHT))
{
cc[0] += 10;
}
if(Key.isDown(Key.PGUP))
{
cc[1] += 10;
}
if(Key.isDown(Key.PGDN))
{
cc[1] -= 10;
}
if(Key.isDown(Key.ENTER)){
trace("ax:"+ax);
trace("ay:"+ay);
for(i = 0; i < cw.length; i++){
trace("CW"+ i + " : " + cw[i]);
}
}
};
this.onMouseDown = function()
{
dn = true;
mx = this._xmouse;
my = this._ymouse;
};
this.onMouseUp = function()
{
dn = false;
};
this.onMouseMove = function()
{
if(dn){
if(this._xmouse > mx){
ay -= 3;
}else if(this._xmouse < mx){
ay += 3;
}
mx = this._xmouse;
if(this._ymouse > my){
ax -= 3;
}else if(this._ymouse < my){
ax += 3;
}
my = this._ymouse;
}
};