function sumvec(vec1, vec2) { var resv = [0,0,0] resv[0] = vec1[0]+vec2[0]; resv[1] = vec1[1]+vec2[1]; resv[2] = vec1[2]+vec2[2]; return resv; } function difvec(vec1, vec2) { var resv = [0,0,0] resv[0] = vec1[0]-vec2[0]; resv[1] = vec1[1]-vec2[1]; resv[2] = vec1[2]-vec2[2]; return resv; } function veceq(a,b) { for (var i = 0; i < 3; ++i) { if (a[i] != b[i]) { return false; } } return true; } function prodmatvec(mat, vec) { var respr = [0,0,0]; respr[0] = mat[0][0]*vec[0]+mat[0][1]*vec[1]+mat[0][2]*vec[2]; respr[1] = mat[1][0]*vec[0]+mat[1][1]*vec[1]+mat[1][2]*vec[2]; respr[2] = mat[2][0]*vec[0]+mat[2][1]*vec[1]+mat[2][2]*vec[2]; return respr; } function prodmat(mat1,mat2) { var resmat = [[0,0,0],[0,0,0],[0,0,0]]; resmat[0][0] = mat1[0][0]*mat2[0][0] + mat1[0][1]*mat2[1][0] + mat1[0][2]*mat2[2][0]; resmat[0][1] = mat1[0][0]*mat2[0][1] + mat1[0][1]*mat2[1][1] + mat1[0][2]*mat2[2][1]; resmat[0][2] = mat1[0][0]*mat2[0][2] + mat1[0][1]*mat2[1][2] + mat1[0][2]*mat2[2][2]; resmat[1][0] = mat1[1][0]*mat2[0][0] + mat1[1][1]*mat2[1][0] + mat1[1][2]*mat2[2][0]; resmat[1][1] = mat1[1][0]*mat2[0][1] + mat1[1][1]*mat2[1][1] + mat1[1][2]*mat2[2][1]; resmat[1][2] = mat1[1][0]*mat2[0][2] + mat1[1][1]*mat2[1][2] + mat1[1][2]*mat2[2][2]; resmat[2][0] = mat1[2][0]*mat2[0][0] + mat1[2][1]*mat2[1][0] + mat1[2][2]*mat2[2][0]; resmat[2][1] = mat1[2][0]*mat2[0][1] + mat1[2][1]*mat2[1][1] + mat1[2][2]*mat2[2][1]; resmat[2][2] = mat1[2][0]*mat2[0][2] + mat1[2][1]*mat2[1][2] + mat1[2][2]*mat2[2][2]; return resmat; } function rot(prevp, plp, axis) { var resu = [0, 0, 0]; if (veceq(axis,[-1,0,0])) { resu[0] = prevp[0]; resu[1] = prevp[1] + (plp[1]-prevp[1]) - (plp[2]-prevp[2]); resu[2] = prevp[2] + (plp[1]-prevp[1]) + (plp[2]-prevp[2]); } else if (veceq(axis,[1,0,0])) { resu[0] = prevp[0]; resu[1] = prevp[1] + (plp[1]-prevp[1]) + (plp[2]-prevp[2]); resu[2] = prevp[2] - (plp[1]-prevp[1]) + (plp[2]-prevp[2]); } else if (veceq(axis,[0,0,-1])) { resu[0] = prevp[0] + (plp[0]-prevp[0]) - (plp[1]-prevp[1]); resu[1] = prevp[1] + (plp[0]-prevp[0]) + (plp[1]-prevp[1]); resu[2] = prevp[2]; } else if (veceq(axis,[0,0,1])) { resu[0] = prevp[0] + (plp[0]-prevp[0]) + (plp[1]-prevp[1]); resu[1] = prevp[1] - (plp[0]-prevp[0]) + (plp[1]-prevp[1]); resu[2] = prevp[2]; } return resu; } var playspace = 1; var ph = [0,0,0]; var pp = [0,0,0]; var matrotinit = [[1,0,0],[0,1,0],[0,0,1]]; var matrotHtB = [[1,0,0],[0,1,0],[0,0,1]]; var matrotP = [[1,0,0],[0,1,0],[0,0,1]]; orPH = [[1,0,0],[0,1,0],[0,0,1]]; var time = 0; var ph0 = false; var ph1 = false; var PhPp0b = [0,0,0]; var PhPp1b = [0,0,0]; var PhPp0h = [0,0,0]; var PhPp1h = [0,0,0]; var ph0x = 0; var ph0y = 0; var ph0z = 0; var ph1x = 0; var ph1y = 0; var ph1z = 0; var pospx = 0; var pospy = 1.4; var pospz = -10; room.update = function(dt) { ph0 = player.hand0_active; ph1 = player.hand1_active; ph0x = player.hand0_pos.x; ph0y = player.hand0_pos.y; ph0z = player.hand0_pos.z; ph1x = player.hand1_pos.x; ph1y = player.hand1_pos.y; ph1z = player.hand1_pos.z; if (playspace == 1) { if ((ph0==true)&&(Math.sqrt((ph0x-pospx)*(ph0x-pospx)/4+(ph0y-pospy)*(ph0y-pospy)+(ph0z-pospz)*(ph0z-pospz)/4)<0.1)) { playspace = 2; PhPp0b = [pospx-ph0x,pospy-ph0y,pospz-ph0z]; matrotinit[0] = [player.hand0_xdir.x,player.hand0_xdir.y,player.hand0_xdir.z]; matrotinit[1] = [player.hand0_ydir.x,player.hand0_ydir.y,player.hand0_ydir.z]; matrotinit[2] = [player.hand0_zdir.x,player.hand0_zdir.y,player.hand0_zdir.z]; PhPp0h = prodmatvec(matrotinit,PhPp0b); room.objects["disap1"].pos.y = 1.034; } else if ((ph1==true)&&(Math.sqrt((ph1x-pospx)*(ph1x-pospx)/4+(ph1y-pospy)*(ph1y-pospy)+(ph1z-pospz)*(ph1z-pospz)/4)<0.1)) { playspace = 3; PhPp1b = [pospx-ph1x,pospy-ph1y,pospz-ph1z]; matrotinit[0] = [player.hand1_xdir.x,player.hand1_xdir.y,player.hand1_xdir.z]; matrotinit[1] = [player.hand1_ydir.x,player.hand1_ydir.y,player.hand1_ydir.z]; matrotinit[2] = [player.hand1_zdir.x,player.hand1_zdir.y,player.hand1_zdir.z]; PhPp1h = prodmatvec(matrotinit,PhPp1b); room.objects["disap1"].pos.y = 1.034; } } else if (playspace == 2) { if (ph0 == true) { room.objects["pipe1"].scale.x = 0.3; room.objects["pipe1"].scale.y = 0.3; room.objects["pipe1"].scale.z = 0.3; matrotHtB[0] = [player.hand0_xdir.x, player.hand0_ydir.x, player.hand0_zdir.x]; matrotHtB[1] = [player.hand0_xdir.y, player.hand0_ydir.y, player.hand0_zdir.y]; matrotHtB[2] = [player.hand0_xdir.z, player.hand0_ydir.z, player.hand0_zdir.z]; room.objects["pipe1"].pos.x = ph0x + prodmatvec(matrotHtB, PhPp0h)[0]; room.objects["pipe1"].pos.y = ph0y + prodmatvec(matrotHtB, PhPp0h)[1]; room.objects["pipe1"].pos.z = ph0z + prodmatvec(matrotHtB, PhPp0h)[2]; matrotP = prodmat(matrotHtB, matrotinit); room.objects["pipe1"].xdir.x = matrotP[0][0]; room.objects["pipe1"].xdir.y = matrotP[1][0]; room.objects["pipe1"].xdir.z = matrotP[2][0]; room.objects["pipe1"].ydir.x = matrotP[0][1]; room.objects["pipe1"].ydir.y = matrotP[1][1]; room.objects["pipe1"].ydir.z = matrotP[2][1]; room.objects["pipe1"].zdir.x = matrotP[0][2]; room.objects["pipe1"].zdir.y = matrotP[1][2]; room.objects["pipe1"].zdir.z = matrotP[2][2]; } else { room.objects["pipe1"].scale.x = 0; room.objects["pipe1"].scale.y = 0; room.objects["pipe1"].scale.z = 0; } } else if (playspace == 3) { if (ph1 == true) { room.objects["pipe1"].scale.x = 0.3; room.objects["pipe1"].scale.y = 0.3; room.objects["pipe1"].scale.z = 0.3; matrotHtB[0] = [player.hand1_xdir.x, player.hand1_ydir.x, player.hand1_zdir.x]; matrotHtB[1] = [player.hand1_xdir.y, player.hand1_ydir.y, player.hand1_zdir.y]; matrotHtB[2] = [player.hand1_xdir.z, player.hand1_ydir.z, player.hand1_zdir.z]; room.objects["pipe1"].pos.x = ph1x + prodmatvec(matrotHtB, PhPp1h)[0]; room.objects["pipe1"].pos.y = ph1y + prodmatvec(matrotHtB, PhPp1h)[1]; room.objects["pipe1"].pos.z = ph1z + prodmatvec(matrotHtB, PhPp1h)[2]; matrotP = prodmat(matrotHtB, matrotinit); room.objects["pipe1"].xdir.x = matrotP[0][0]; room.objects["pipe1"].xdir.y = matrotP[1][0]; room.objects["pipe1"].xdir.z = matrotP[2][0]; room.objects["pipe1"].ydir.x = matrotP[0][1]; room.objects["pipe1"].ydir.y = matrotP[1][1]; room.objects["pipe1"].ydir.z = matrotP[2][1]; room.objects["pipe1"].zdir.x = matrotP[0][2]; room.objects["pipe1"].zdir.y = matrotP[1][2]; room.objects["pipe1"].zdir.z = matrotP[2][2]; } else { room.objects["pipe1"].scale.x = 0; room.objects["pipe1"].scale.y = 0; room.objects["pipe1"].scale.z = 0; } } }