Ejemplo n.º 1
0
void BinnedMap::save(QTextStream& ts, const QString& indent) {
  QString l2 = indent + "  ";
  ts << indent << "<plugin name=\"Binned Map\">" << endl;
  ts << l2 << "<tag>" << QStyleSheet::escape(tagName()) << "</tag>" << endl;

  for (KstVectorMap::Iterator i = _inputVectors.begin(); i != _inputVectors.end(); ++i) {
    ts << l2 << "<ivector name=\"" << QStyleSheet::escape(i.key()) << "\">"
        << QStyleSheet::escape(i.data()->tagName())
        << "</ivector>" << endl;
  }

  for (KstMatrixMap::Iterator i = _outputMatrices.begin(); i != _outputMatrices.end(); ++i) {
    ts << l2 << "<omatrix name=\"" << QStyleSheet::escape(i.key());
    ts << "\">" << QStyleSheet::escape(i.data()->tagName())
        << "</omatrix>" << endl;
  }
  ts << 12 << "<minX>" << xMin() << "</minX>" << endl;
  ts << 12 << "<maxX>" << xMax() << "</maxX>" << endl;
  ts << 12 << "<minY>" << yMin() << "</minY>" << endl;
  ts << 12 << "<maxY>" << yMax() << "</maxY>" << endl;
  ts << 12 << "<nX>" << nX() << "</nX>" << endl;
  ts << 12 << "<nY>" << nY() << "</nY>" << endl;
  if (autoBin()) {
    ts << 12 << "<autoBin/>" << endl;
  }

  ts << indent << "</plugin>" << endl;
}
Ejemplo n.º 2
0
void AABox::ComputePlanes()
{
    CVector3 nX( 1.0f, 0.0f, 0.0f );
    CVector3 nY( 0.0f, 1.0f, 0.0f );
    CVector3 nZ( 0.0f, 1.0f, 0.0f );

    mPlaneNX[0] = CPlane( nX, mMin.GetX() );
    mPlaneNX[1] = CPlane( -nX, mMax.GetX() );

    mPlaneNY[0] = CPlane( nY, mMin.GetY() );
    mPlaneNY[1] = CPlane( -nY, mMax.GetY() );

    mPlaneNZ[0] = CPlane( nZ, mMin.GetZ() );
    mPlaneNZ[1] = CPlane( -nZ, mMax.GetZ() );
}
/* The main drawing function. */
void DrawGLScene()
{
	static bool init = true;
	static ClothSimulation clothSimulation;

	if(init)
	{
		clothSimulation.init(-2.0, -1.0, 0.1,
					4.0, 2.0,
					4.0 / 250,
					50.51, 0.);
		//clothSimulation.init(-2.0, -2.0, 0.1,
		//			4.0, 4.0,
		//			4.0 / 250,
		//			50.51, 0.);
		init = false;
	}
	
	clothSimulation.computeInternalForces();
	clothSimulation.handleCollision(1);
	clothSimulation.integrate();
	clothSimulation.transfertFromGpu();

  glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);	// Clear The Screen And The Depth Buffer
  glLoadIdentity();				// Reset The View

  glTranslatef(0.f,0.0f,-6.0f);		// Move Left 1.5 Units And Into The Screen 6.0
  glRotatef(110.0,1.0f,0.0f,0.0f);		// Rotate The Pyramid On The Y axis 
	
  glRotatef(rtri,0.0f,0.0f,1.0f);		// Rotate The Pyramid On The Y axis 

  glBegin(GL_TRIANGLES);				// start drawing a pyramid


  int gridSizeX = clothSimulation.getSizeX();
  int gridSizeY = clothSimulation.getSizeY();
  std::vector<float>& X = clothSimulation.getNodeX();
  std::vector<float>& Y = clothSimulation.getNodeY();
  std::vector<float>& Z = clothSimulation.getNodeZ();
 
  std::vector<float> nX(X.size());
  std::vector<float> nY(Y.size());
  std::vector<float> nZ(Z.size());
 
  std::fill(nX.begin(), nX.end(), 0.);
  std::fill(nY.begin(), nY.end(), 0.);
  std::fill(nZ.begin(), nZ.end(), 0.);
 
 ///////////////////////////
 //     smooth normals    //
 ///////////////////////////
  for(int i = 0 ; i < gridSizeX-1 ; ++i)
	  for(int j = 0 ; j < gridSizeY-1 ; ++j)
		  {
		  	  int n1Idx = i * gridSizeY + j;
		  	  int n2Idx = i * gridSizeY + j + 1;
		  	  int n3Idx = (i+1) * gridSizeY + j;
		  	  int n4Idx = (i+1) * gridSizeY + j + 1;
		  	  

			  float nx = (Y[n2Idx] - Y[n1Idx]) * (Z[n3Idx] - Z[n1Idx])-  (Y[n3Idx] - Y[n1Idx]) * (Z[n2Idx] - Z[n1Idx]);
			  float ny = (Z[n2Idx] - Z[n1Idx]) * (X[n3Idx] - X[n1Idx]) - (Z[n3Idx] - Z[n1Idx]) * (X[n2Idx] - X[n1Idx]);
			  float nz = (X[n2Idx] - X[n1Idx]) * (Y[n3Idx] - Y[n1Idx]) - (X[n3Idx] - X[n1Idx]) * (Y[n2Idx] - Y[n1Idx]);
				
			nX[n1Idx] += nx;
			nY[n1Idx] += ny;
			nZ[n1Idx] += nz;
			
			nX[n2Idx] += nx;
			nY[n2Idx] += ny;
			nZ[n2Idx] += nz;
			
			nX[n3Idx] += nx;
			nY[n3Idx] += ny;
			nZ[n3Idx] += nz;
			
			nX[n4Idx] += nx;
			nY[n4Idx] += ny;
			nZ[n4Idx] += nz;
} 

//normalize normals.
for(int i = 0 ; i < nX.size() ; i++)
{
	float norm = sqrt(nX[i] * nX[i] + nY[i] * nY[i] + nZ[i] * nZ[i]);
	if(norm)
	{
	nX[i] /= -norm;
	nY[i] /= -norm;
	nZ[i] /= -norm;
	}
}  

///////////////////////////
//    Display triangles  //
///////////////////////////
  for(int i = 0 ; i < gridSizeX-1 ; ++i)
	  for(int j = 0 ; j < gridSizeY-1 ; ++j)
		  {
			  int n1Idx = i * gridSizeY + j;
		  	  int n2Idx = i * gridSizeY + j + 1;
		  	  int n3Idx = (i+1) * gridSizeY + j;
		  	  int n4Idx = (i+1) * gridSizeY + j + 1;
		  	  
			  //Display first triangle
			  glColor3f(0.0f,0.3f,0.7f);
  			  glVertex3f(X[n1Idx], Y[n1Idx], -Z[n1Idx]);
  			  glNormal3f(-nX[n1Idx], -nY[n1Idx], -nZ[n1Idx]);
  			  
			  glColor3f(0.0f,0.3f,0.7f);
			  glVertex3f(X[n2Idx], Y[n2Idx], -Z[n2Idx]);
 			  glNormal3f(-nX[n2Idx], -nY[n2Idx], -nZ[n2Idx]);
 			  
			  glColor3f(0.0f,0.3f,0.7f);
			  glVertex3f(X[n3Idx], Y[n3Idx], -Z[n3Idx]);
 			  glNormal3f(-nX[n3Idx], -nY[n3Idx], -nZ[n3Idx]);
 		  	
		  	  //Display second triangle
		  	  glColor3f(0.0f,0.3f,0.7f);
  			  glVertex3f(X[n3Idx], Y[n3Idx], -Z[n3Idx]);
  			  glNormal3f(-nX[n3Idx], -nY[n3Idx], -nZ[n3Idx]);
  			  
			  glColor3f(0.0f,0.3f,0.7f);
			  glVertex3f(X[n2Idx], Y[n2Idx], -Z[n2Idx]);
 			  glNormal3f(-nX[n2Idx], -nY[n2Idx], -nZ[n2Idx]);
 			  
			  glColor3f(0.0f,0.3f,0.7f);
			  glVertex3f(X[n4Idx], Y[n4Idx], -Z[n4Idx]);
 			  glNormal3f(-nX[n4Idx], -nY[n4Idx], -nZ[n4Idx]);
 		  }


  glEnd();

  rtri+= 0.15f;

  // swap the buffers to display, since double buffering is used.
  glutSwapBuffers();
}