Last active
March 4, 2019 01:27
-
-
Save izumiikezaki/2d68272161c2b95a317a1dc6c1ef632c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const divNum = 12;//波の分割数 | |
const waveNum = 1;//波の数 | |
//ベジェ曲線の制御点の座標 | |
var p1 = new THREE.Vector3(); | |
var p2 = new THREE.Vector3(); | |
var s1 = new THREE.Vector3(); | |
var s2 = new THREE.Vector3(); | |
function bezer(p1,p2,s1,s2,t){//三次ベジェ曲線の座標を返す | |
var x = (1-t)*(1-t)*(1-t)*p1.x + 3*(1-t)*(1-t)*t*s1.x + 3*(1-t)*t*t*s2.x + t*t*t*p2.x; | |
var y = (1-t)*(1-t)*(1-t)*p1.y + 3*(1-t)*(1-t)*t*s1.y + 3*(1-t)*t*t*s2.y + t*t*t*p2.y; | |
return new THREE.Vector3(x,y,0); | |
} | |
function planeAnim(){ | |
p1.setX(-60); | |
p1.setY(Math.sin(clock.getElapsedTime())*0); | |
p2.setX(60); | |
p2.setY(Math.sin(clock.getElapsedTime())*0); | |
s1.setX(-30); | |
s1.setY(Math.sin(clock.getElapsedTime())*20); | |
s2.setX(30); | |
s2.setY(Math.sin(clock.getElapsedTime()+60)*20); | |
for (var i = 0; i < planeGeo.vertices.length; i++) { | |
var divNumIndex = i % divNum;//波の節のインデックス(左から0番~[divNum]番) | |
var waveNumIndex = Math.floor(i/(divNum+1)) ;//波の数のインデックス(0番~[waveNum]番) | |
if(waveNumIndex==1){//波ごとに処理 | |
var tmp = bezer(p1,p2,s1,s2,(i-12)/divNum); | |
planeGeo.vertices[i].copy(tmp); | |
}else{ | |
//planeGeo.vertices[i].y=Math.sin((clock.getElapsedTime()+(i/6))*2)*20; | |
} | |
} | |
planeGeo.verticesNeedUpdate=true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment