Пример #1
0
HemisphereSampler::HemisphereSampler(Vec3 normal, int us, int ts)
    : _max_us(us), _max_ts(ts), _us(0), _ts(0), _normal(normal) {

    Vec3 up = Vec3(0,1,0);
    Vec3 w = normal;
    Vec3 u;
    Vec3 v;
    w.norm();
    //w = w * -1;

    if(w.y() >= 0.9995 || w.y() <= -0.995) {
        u = Vec3(1,0,0);
        v = Vec3(0,0,1);
    } else {
        up.cross(w, &u);
        u.norm();
        w.cross(u, &v);
    }

    //cout << "Camera Loc: " << endl << m1 << endl;

    MyMat m = MyMat(u.x(), v.x(), w.x(), 0,
                    u.y(), v.y(), w.y(), 0,
                    u.z(), v.z(), w.z(), 0,
                    0, 0, 0, 1);

    _matrix = m;
    //cout << "UVW: " << endl << m2 << endl;

    //_matrix = m.inverse();
}
Пример #2
0
/* Parse raw rotation data into new keyframes for the shark. Locations of points and quads that make up the shark 
* will be set with this method
* Requires infomation in Shark class with the same names to be passed in. 
 */
void Keyframe::gatherTransformData(GLfloat segmentRot[], GLfloat segLength[], Mesh *mesh, int segments, glQuaternion *glQuat )
{
	int startingPoint = 3;

	float start = mesh->lengthMax, end = mesh->lengthMax;//, length =0;
	for(int i = 0; i <= startingPoint; i++)
	{
		end = start; 
		start -= segLength[i];
		//length += start;
	}
	MyMat stackMatrix = MyMat();
	stackMatrix.makeTranslate(Vector3f(-segLength[startingPoint], 0, 0));

	transformHeirarchy(startingPoint, 0, segmentRot, segLength, mesh, segments, 
			glQuat, startingPoint, stackMatrix, start, end);
	 
	createQuads();                    
}
Пример #3
0
MyMat MyMat::multScalar(const float multi)
{
	MyMat newMat = MyMat();
	newMat[0][0] = m_Elem[0][0] * multi ;
	newMat[0][1] = m_Elem[0][1] * multi ;
	newMat[0][2] = m_Elem[0][2] * multi ;
	newMat[0][3] = m_Elem[0][3] * multi ;
	newMat[1][0] = m_Elem[1][0] * multi ;
	newMat[1][1] = m_Elem[1][1] * multi ;
	newMat[1][2] = m_Elem[1][2] * multi ;
	newMat[1][3] = m_Elem[1][3] * multi ;
	newMat[2][0] = m_Elem[2][0] * multi ;
	newMat[2][1] = m_Elem[2][1] * multi ;
	newMat[2][2] = m_Elem[2][2] * multi ;
	newMat[2][3] = m_Elem[2][3] * multi ;
	newMat[3][0] = m_Elem[3][0] * multi ;
	newMat[3][1] = m_Elem[3][1] * multi ;
	newMat[3][2] = m_Elem[3][2] * multi ;
	newMat[3][3] = m_Elem[3][3] * multi ;
	return newMat;
}
Пример #4
0
/*Subroutine of transformHeiararchy(), this function calculates the position and rotation for a given bone segment and 
* generates quaderlaterals with those transformations */
void Keyframe::segmentMatrixMake( GLfloat segmentRot[], GLfloat segLength[], Mesh *mesh, int segments, glQuaternion *glQuat, int curSegment, 
		MyMat *stackMatrix, float start, float end, int isDownstream)
{
	double rotate = segmentRot[curSegment];                  //get rotation of current segment
	                                   //current shark model segment
	MyMat Matrix = *stackMatrix;
	MyMat transrix;
	transrix.makeTranslate(Vector3f((isDownstream == 2 ? segLength[curSegment] : -segLength[curSegment]), 0, 0));	
	MyMat secondStack = MyMat();
	GLfloat glm[16];
	
	glQuat->CreateFromAxisAngle(0,1,0,isDownstream == 2? -rotate : rotate);
	glQuat->CreateMatrix(glm); 
	MyMat rotatrix = MyMat(glm[0], glm[4], glm[8], glm[12], glm[1], glm[5],glm[9],
			glm[13],glm[2],glm[6],glm[10],glm[14],glm[3],glm[7],
			glm[11],glm[15]);

	Matrix = Matrix.multRight(rotatrix); //roatation goes before translates
	Matrix = Matrix.multRight(transrix); //doesnt matter which order translates are done

	*stackMatrix = Matrix; //advance heirarchy
	MyMat transrix2;
	transrix2.makeTranslate(Vector3f(isDownstream == 2? -end : -start, 0, 0));
	Matrix = Matrix.multRight(transrix2);
	//------------------------------------ 
	float center;
	for(int in = 0; in < mesh->vertCounter; in+=4)
	{
		//find center of face
		center = (mesh->vertList[in].x + mesh->vertList[in+1].x + mesh->vertList[in+2].x 
				+ mesh->vertList[in+3].x ) / 4;
		//draw if face is between start and end
		if(center >= start && center <= end )
		{
			Quad *curQuad = new Quad();
			curQuad->gNormal() = Vector3f(0,0,0);
			for(int corn = 0; corn < 4; corn++) //corner iteration
			{
				SharkVertex *curVert = new SharkVertex();   //current vertex
				curVert->local = mesh->vertList[in+corn];   //setting untransformed vertex
				curVert->transformed = Vector3f(Matrix.multVec(mesh->vertList[in+corn], true)); //setting transformed vertex
				curVert->normal = Vector3f(0,0,0);	//normal of the vertex, away from mesh			
				map<Vector3f, SharkVertex*, compareVect3>::iterator findTest 
					= uVertices.find(mesh->vertList[in+corn]);   //checking to see if vertex is already in the list.
				if(findTest == uVertices.end()) 
				{ 
					//vertex not in list. Add it to the list and to the quad.
					uVertices.insert(pair<Vector3f, SharkVertex*>(mesh->vertList[in+corn]
								, curVert));	
					curQuad->sVert(corn, curVert);
				}
				else   //vertex is in the list, so it's added to the existing quad.
				{
					delete curVert;
					curQuad->sVert(corn, (*findTest).second);
				}
				curQuad->gNormal() += Matrix.multVec(mesh->normals[in+corn], false);  //setting normal of the face
				
			}//end corners
			curQuad->gNormal() /= 4.0; //take average of normals to get the actual normal.
			curQuad->sBoneNo(curSegment); //record the bone this quad belongs to the most.
			faces.push_back(curQuad);
		}//end if
	}//end quads 

}