티스토리 뷰


function createBox(vertData, idxData){
	var s=	500;
	vertData.push(-s,  s, -s);
	vertData.push( s,  s, -s);
	vertData.push(-s, -s, -s);
	vertData.push( s, -s, -s);
	vertData.push(-s,  s,  s);
	vertData.push( s,  s,  s);
	vertData.push(-s, -s,  s);
	vertData.push( s, -s,  s);

	idxData.push(0, 2, 1);//Front
	idxData.push(1, 2, 3);
	idxData.push(4, 5, 6);//Back
	idxData.push(5, 7, 6);
	idxData.push(0, 4, 2);//Left
	idxData.push(2, 4, 6);
	idxData.push(1, 3, 5);//Right
	idxData.push(5, 3, 7);
	idxData.push(0, 5, 4);//Top
	idxData.push(0, 1, 5);
	idxData.push(2, 6, 7);//Bottom
	idxData.push(3, 2, 7);
}

function createSphereMesh(vertData, texData, idxData){
			
	var nSlice=	3;
	var nStack=	3;
	var radius=	500;

	//Create Sphere Vertices
	for(var i=0; i<=nStack; ++i){
		var theta=		i * Math.PI / nSlice;
		var sinTheta=	Math.sin(theta);
		var cosTheta=	Math.cos(theta);
		for(var j=0; j<=nSlice; ++j){
			var phi=		j * 2 * Math.PI / nStack;
			var sinPhi=		Math.sin(phi);
			var cosPhi=		Math.cos(phi);

			var x=	cosPhi * sinTheta;
			var y=	cosTheta;
			var z=	sinPhi * sinTheta;
			vertData.push(radius*x, radius*y, radius*z);
			
			var u=	1.0 - (j/nSlice);
			var v=	1.0 - (i/nStack);
			texData.push(u, v);
		}
	}

	//Create Sphere Indices
	for(var i=0; i<nStack; ++i){
		for(var j=0; j<nSlice; ++j){
			var first=	(i*(nStack+1))+j;
			var second=	first+nStack+1;
			idxData.push(first, second, first+1);
			idxData.push(second, second+1, first+1);
		}
	}
}

'Computer > Graphics' 카테고리의 다른 글

Javascript - SphereMesh, CubeMesh  (0) 2010.09.06
GPU based Geometry Clipmap  (0) 2010.06.10
Trapezoidal Rule(사다리꼴 공식)  (0) 2010.03.16
Project to tangent plane  (0) 2010.02.22
Noise Function  (0) 2010.02.08
Dijkstra  (0) 2010.01.29
댓글
Total
168,077
Today
10
Yesterday
34