Example #1
0
//verlet x = vt + 1/2*at^2
void nextPosition(int currentPtc) {
	M3DVector3f temp;
	//get last shift: + vt
	m3dSubtractVectors3(temp, ClothLnk[currentPtc].position, ClothLnk[currentPtc].pre_position);
	m3dAddVectors3(ClothLnk[currentPtc].next_position, ClothLnk[currentPtc].position, temp);
	//if (currentPtc==55)
	//	printf("	[%d].shift		{%.1f, %.1f, %.1f} \n", currentPtc, shift[0], shift[1], shift[2]);

	//get accumulation: + 1/2*at^2
	m3dCopyVector3(temp, ClothLnk[currentPtc].force);
	m3dScaleVector3(temp, (GLfloat)TimeStep*TimeStep*AccumulateStiff/ClothLnk[currentPtc].Mass/2);
	m3dAddVectors3(ClothLnk[currentPtc].next_position, ClothLnk[currentPtc].next_position, temp);

	//collide
	//if (adjustPositionByCollision(ClothLnk[currentPtc].next_position) ) {
	//	m3dCopyVector3(ClothLnk[currentPtc].next_position, ClothLnk[currentPtc].position);
	//}

	adjustPositionByCollision(ClothLnk[currentPtc].position, ClothLnk[currentPtc].next_position);

	M3DVector3f shift;
	m3dSubtractVectors3(shift, ClothLnk[currentPtc].next_position, ClothLnk[currentPtc].position);
	GLfloat length = (GLfloat)m3dGetVectorLength(shift);
	if (length >= shiftRange ) {
		m3dScaleVector3(shift, 1.0f/length);
		m3dAddVectors3(ClothLnk[currentPtc].next_position, ClothLnk[currentPtc].position, shift);
	}

}
Example #2
0
tu_model_t *tu_getCube() {
  // Create vertices for a cube.  We need to create seperate vertices for each face as the normals are different
  tu_model_t *model = (tu_model_t*)calloc(1, sizeof(tu_model_t));
  model->nVertices  = sizeof(cubeV)/sizeof(M3DVector3f);
  model->nIndices   = sizeof(cubetris)/sizeof(unsigned);
  model->vertices   = (M3DVector3f *)calloc(model->nVertices, sizeof(M3DVector3f));
  model->normals    = (M3DVector3f *)calloc(model->nVertices, sizeof(M3DVector3f));
  model->texcoords  = (M3DVector3f *)calloc(model->nVertices, sizeof(M3DVector3f));
  for (int i = 0; i < model->nVertices; i++) {
    m3dCopyVector3(model->vertices[i],  cubeV[i]);
    m3dCopyVector3(model->normals[i],   cubeN[i/4]);
    m3dCopyVector3(model->texcoords[i], cubeV[i]);
  }
  model->indices    = (unsigned *)calloc(model->nIndices, sizeof(unsigned));
  memcpy(model->indices, cubetris, sizeof(cubetris));
  return model;
}
Example #3
0
void draw_icosahedron_smooth(int n_faces, float *vertices, int *faces) {
   float normal[3];
   for(int i = 0; i < n_faces; ++i) {
      for(int j=0 ; j < 3 ; ++j) {
         m3dCopyVector3(normal, vertices + 3 * faces[i * 3 + j]);
         m3dNormalizeVector3(normal);
         draw_trinagle_face(vertices + 3 * faces[3 * i], vertices + 3 * faces[3 * i + 1], vertices + 3 * faces[3 * i + 2], normal, 0.0f, 1.0f, 0.0f);
      }
   }
}
Example #4
0
//----------------------------------------------------
void drawSmoothTriangles(int n_faces, float *vertices, int *faces) {
    M3DVector3f normal;
    for (int i = 0; i < n_faces; i++) {
		glBegin(GL_TRIANGLES);
    	for(int j=0;j<3;++j) {
			m3dCopyVector3(normal,vertices+3*faces[i*3+j]);
			m3dNormalizeVector3(normal);
    		glVertexAttrib3fv(GLT_ATTRIBUTE_NORMAL, normal);
    		glVertex3fv(vertices+3*faces[i*3+j]);
		}
    glEnd();
    }
}
Example #5
0
void refreshPosition() {
	for (int i = 0; i < PTCAMT; i ++) {
		m3dCopyVector3(ClothLnk[i].pre_position, ClothLnk[i].position);
		m3dCopyVector3(ClothLnk[i].position, ClothLnk[i].next_position);
	}
}
Example #6
0
void needStop(int currentPtc) {
	if ((GLfloat)m3dGetVectorLength(ClothLnk[currentPtc].force) <= minForce) {
		m3dLoadVector3(ClothLnk[currentPtc].force, 0.0f, 0.0f, 0.0f);
		m3dCopyVector3(ClothLnk[currentPtc].pre_position, ClothLnk[currentPtc].position);
	}
}