Exemple #1
0
void myLookAt(GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ,
	          GLdouble centerX, GLdouble centerY, GLdouble centerZ,
	          GLdouble upX, GLdouble upY, GLdouble upZ) {
	
	GLdouble cz[3];
	GLdouble cy[3];
	GLdouble cx[3];
	
	GLdouble up[3] = {upX, upY, upZ};
	GLdouble minEye[3] = {-eyeX, -eyeY, -eyeZ};
	
	// cz is the vector Pcamera to Plookat
	cz[0] = eyeX - centerX;
	cz[1] = eyeY - centerY;
	cz[2] = eyeZ - centerZ;
	
	// Normalize cz
	normalizeVector(cz);
	
	// cx = up x cz
	crossProduct(up, cz, cx);
	
	// Normalize cy
	normalizeVector(cx);
	
	// cy = cz x cx
	crossProduct(cz, cx, cy);

	GLfloat RT[16] = {
		cx[0], cy[0], cz[0], 0,
		cx[1], cy[1], cz[1], 0,
		cx[2], cy[2], cz[2], 0,
		0    , 0    , 0    , 1
	};
	
	glTranslatef(inProduct(minEye, cx), inProduct(minEye, cy), 
			inProduct(minEye, cz));
	glMultMatrixf(RT);
}
int ViolinClassification::svmfun(vector<vector<float>> &sv, vector<float> &alpha, vector<float> &shift, vector<float> &scalefactor, float bias, vector<float> &feat)
{
    for (int i=0; i<feat.size(); i++)
        feat[i] = (feat[i] + shift[i])*scalefactor[i];
    
    float value = 0;
    for (int i=0; i<sv.size(); i++)
        value += inProduct(sv[i], feat)*alpha[i];
    value += bias;
    if (value >= 0)
        return 1;
    return 2;
}