YSRESULT YsShellExt_SweepInfoMultiStep::SetUpNonParallelSweepWithPath(const YsShellExt &shl,YSSIZE_T nPathVt,const YsShellVertexHandle pathVtHdArrayIn[],YSBOOL isLoop,const YsVec3 nom[],const double scaling[])
{
	const auto &allVtHd=GetVertexAll(); // Need the original normal.


	CleanUpLayer();

	if(2<=nPathVt)
	{
		YsConstArrayMask <YsShellVertexHandle> pathVtHd(nPathVt,pathVtHdArrayIn);
		YsArray <YsVec3> pathPnt(nPathVt,NULL);
		for(YSSIZE_T idx=0; idx<pathVtHd.GetN(); ++idx)
		{
			pathPnt[idx]=shl.GetVertexPosition(pathVtHd[idx]);
		}

		const YSSIZE_T nLayer=(YSTRUE==isLoop ? nPathVt : nPathVt-1);
		SetUpNLayer(shl,nLayer+1);   // First set of vertices are not counted as a layer.  Number of layers will be nPathVt-1.

		// Rotation must be progressive.  Why?  Assume nom[0] and nom[5] are 180 degrees opposite.
		// If the rotation is calculated for each layer by YsRotation::MakeAtoB(nom[0],nom[layerIndex]),
		// rotational axis for nom[5] may become different from other layers, and thus the continuity is lost.
		// The solution is calculating the rotation for each step progressively.

		YsArray <YsMatrix3x3> rot(nPathVt-1,NULL);
		YsMatrix3x3 prevRot;
		for(int layerIdx=0; layerIdx<nPathVt-1; ++layerIdx)
		{
			YsRotation thisRot;
			thisRot.MakeAtoB(nom[layerIdx],nom[layerIdx+1]);
			prevRot*=thisRot;
			rot[layerIdx]=prevRot;
		}

		for(auto layerIdx=0; layerIdx<nPathVt-1; ++layerIdx)
		{
			YsMatrix4x4 tfm;

			tfm.Translate(pathPnt[layerIdx+1]);
			tfm*=rot[layerIdx];
			tfm.Scale(scaling[layerIdx+1],scaling[layerIdx+1],scaling[layerIdx+1]);
			tfm.Translate(-pathPnt[0]);

			for(auto vtHd : allVtHd)
			{
				YSSIZE_T indexInLayer;
				if(YSOK==srcVtKeyToMidPointIndex.FindElement(indexInLayer,shl.GetSearchKey(vtHd)))
				{
					auto &point=layerArray[layerIdx].pointArray[indexInLayer];
					if(vtHd==pathVtHd[0])
					{
						point.vtHd=pathVtHd[layerIdx+1];
						point.pos=shl.GetVertexPosition(pathVtHd[layerIdx+1]);
					}
					else
					{
						point.vtHd=NULL;
						point.pos=tfm*shl.GetVertexPosition(vtHd);
					}
				}
			}
		}

		if(YSTRUE==isLoop)
		{
			for(auto vtHd : allVtHd)
			{
				YSSIZE_T indexInLayer;
				if(YSOK==srcVtKeyToMidPointIndex.FindElement(indexInLayer,shl.GetSearchKey(vtHd)))
				{
					auto &point=layerArray[nLayer-1].pointArray[indexInLayer];
					point.vtHd=vtHd;
					point.pos=shl.GetVertexPosition(vtHd);
				}
			}
		}

		return YSOK;
	}
	return YSERR;
}
Esempio n. 2
0
File: main.cpp Progetto: HLH15/24783
/* virtual */ void FsLazyWindowApplication::Draw(void)
{
	int wid,hei;
	FsGetWindowSize(wid,hei);

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	glEnable(GL_DEPTH_TEST);

	drawEnv.SetProjectionMode(YsProjectionTransformation::PERSPECTIVE);
	drawEnv.SetAspectRatio((double)wid/(double)hei);
	drawEnv.SetFOVY(YsPi/4.0);
	drawEnv.SetNearFar(0.1,100.0);
	drawEnv.SetViewTarget((min+max)/2.0);
	drawEnv.SetViewDistance((max-min).GetLength());

	GLfloat projMat[16];
	drawEnv.GetProjectionMatrix().GetOpenGlCompatibleMatrix(projMat);


	auto &view=drawEnv.GetViewMatrix();

	YsMatrix4x4 modeling;

	YsMatrix4x4 fullMatrix=view*modeling;

	GLfloat viewMat[16];
	fullMatrix.GetOpenGlCompatibleMatrix(viewMat);

	{
		YsGLSLPlain3DRenderer renderer;  // Again, do not nest the renderer!
		renderer.SetProjection(projMat);
		renderer.SetModelView(viewMat);

		GLfloat color[8]={0,0,1,1, 1,0,0,1};
		const GLfloat vtx[6]=
		{
			lastClick[0].xf(),lastClick[0].yf(),lastClick[0].zf(),
			lastClick[1].xf(),lastClick[1].yf(),lastClick[1].zf()
		};
		renderer.DrawVtxCol(GL_LINES,2,vtx,color);

		glEnable(GL_PROGRAM_POINT_SIZE);
		renderer.SetUniformPointSize(3.0);
		renderer.DrawVtx(GL_POINTS,cellVtx.size()/3,cellVtx.data());
	}
	{
		GLfloat lightDir[]={0,0,1};

		YsGLSLShaded3DRenderer renderer;  // Again, do not nest the renderer!
		renderer.SetProjection(projMat);
		renderer.SetModelView(viewMat);
		renderer.SetLightDirectionInCameraCoordinate(0,lightDir);

		renderer.DrawVtxNomCol(GL_TRIANGLES,vtx.size()/3,vtx.data(),nom.data(),col.data());
	}
	
	YsMatrix4x4 shadowMat;
	shadowMat.Translate(0.0,-12.0,0.0);
	shadowMat.Scale(1.0,0.0,1.0);

	fullMatrix=view*shadowMat*modeling;
	fullMatrix.GetOpenGlCompatibleMatrix(viewMat);
	{
		GLfloat color[]={0,0,0,1};

		YsGLSLPlain3DRenderer renderer;  // Again, do not nest the renderer!
		renderer.SetProjection(projMat);
		renderer.SetModelView(viewMat);
		renderer.SetUniformColor(color);
		renderer.DrawVtx(GL_TRIANGLES,vtx.size()/3,vtx.data());
	}


	FsSwapBuffers();

	needRedraw=false;
}