Exemplo n.º 1
0
void setLightMatrix(double *result, double *shadowProjection, double *shadowModelView, double* camModelView) {
	/*Matrix44f shadowTransMatrix = mShadowCam.getProjectionMatrix();
	shadowTransMatrix *= mShadowCam.getModelViewMatrix();
	shadowTransMatrix *= camera.getInverseModelViewMatrix();
	return shadowTransMatrix;*/
	
	// Adding the BIAS means we can use shadow2DProj which is good for linear filtering on the FBO for free with NVidia cards
	
	double bias[16] = {	
		0.5, 0.0, 0.0, 0.0, 
		0.0, 0.5, 0.0, 0.0,
		0.0, 0.0, 0.5, 0.0,
		0.5, 0.5, 0.5, 1.0};
	
	
	double trans[16];
	multMatrix(trans, bias, shadowProjection);
	double trans2[16];
	
	multMatrix(trans2,trans,shadowModelView);
	//setEqual(trans, shadowModelView);
	double inv[16];
	invertMatrix(inv, camModelView);
	multMatrix(result, trans2, inv);
	
}
Exemplo n.º 2
0
/*
double Cos(double angle)
{
	float temp = 0;
	temp = 1 - angle*angle/(1*2) + angle*angle*angle*angle/(1*2*3*4);
	return temp;	
}

double Sin(double angle)
{
	float temp = 0;
	temp = angle - angle*angle*angle/(1*2*3) + angle*angle*angle*angle*angle/(1*2*3*4*5); 
	return temp;	
}

*/
void demo_transform(float rz, Vector tr, Vector* v, Vector* tv)
{
	double  angle;
	double  c;
	double  s;
	float  matID[16];
	float  matTR[16];
	float  matRZ[16];
	float  mat[16];
	float  mat2[16];
	int    i;


	// Affine transformation done in software (NOT optimized).
	angle = PI * rz / 180.0f;
	c     = (float)cos(angle);
	s     = (float)sin(angle);
	loadIdentityMatrix(matID);
	loadTranslationMatrix(matTR, tr);
	loadZRotationMatrix(matRZ, c, s);
	multMatrix(mat, matTR, matID);
	multMatrix(mat2, matRZ, mat);
	// Linear combination of source data and transformation matrix (z computation disabled).
	for (i = 0; i < 4; i++) {
		tv[i].x = v[i].x * mat2[ 0] + v[i].y * mat2[ 4] + mat2[12];// + v[i].z * mat2[ 8];
		tv[i].y = v[i].x * mat2[ 1] + v[i].y * mat2[ 5] + mat2[13];// + v[i].z * mat2[ 9];
	}
}
Exemplo n.º 3
0
// convert Euler angles to rotation matrix
void Interpolator::Euler2Rotation(double anglesDeg[3], double R[9])
{
	// convert angles to radians
	double angles[3];
	for(int i=0; i<3; i++)
	    angles[i] = anglesDeg[i] * M_PI/180;

	// create the 3 individual rotation matrices with respect to each angle
	double R1[9] = {1,					0,					0,					// 0,1,2  array indices for matrix
					0,					cos(angles[0]),		-sin(angles[0]),	// 3,4,5
					0,					sin(angles[0]),		cos(angles[0])};	// 6,7,8

	double R2[9] = {cos(angles[1]),		0,					sin(angles[1]),
					0,					1,					0,
					-sin(angles[1]),	0,					cos(angles[1])};

	double R3[9] = {cos(angles[2]),		-sin(angles[2]),	0,
					sin(angles[2]),		cos(angles[2]),		0,
					0,					0,					1};

	double R32[9];
	multMatrix(R3,R2,R32);
	multMatrix(R32,R1,R);

}
Exemplo n.º 4
0
// Computes derived matrices
void computeDerivedMatrix(ComputedMatrixTypes aType) {
	
	memcpy(mCompMatrix[VIEW_MODEL], mMatrix[VIEW], 16 * sizeof(float));
	multMatrix(mCompMatrix[VIEW_MODEL], mMatrix[MODEL]);

	if (aType == PROJ_VIEW_MODEL) {
		memcpy(mCompMatrix[PROJ_VIEW_MODEL], mMatrix[PROJECTION], 16 * sizeof(float));
		multMatrix(mCompMatrix[PROJ_VIEW_MODEL], mCompMatrix[VIEW_MODEL]);
	}
}
Exemplo n.º 5
0
Arquivo: vsml.c Projeto: arokem/Fos
// gluLookAt implementation
void
VSML::lookAt(float xPos, float yPos, float zPos,
                    float xLook, float yLook, float zLook,
                    float xUp, float yUp, float zUp)
{
    float dir[3], right[3], up[3];
 
    up[0] = xUp;    up[1] = yUp;    up[2] = zUp;
 
    dir[0] =  (xLook - xPos);
    dir[1] =  (yLook - yPos);
    dir[2] =  (zLook - zPos);
    normalize(dir);
 
    crossProduct(dir,up,right);
    normalize(right);
 
    crossProduct(right,dir,up);
    normalize(up);
 
    float m1[16],m2[16];
 
    m1[0]  = right[0];
    m1[4]  = right[1];
    m1[8]  = right[2];
    m1[12] = 0.0f;
 
    m1[1]  = up[0];
    m1[5]  = up[1];
    m1[9]  = up[2];
    m1[13] = 0.0f;
 
    m1[2]  = -dir[0];
    m1[6]  = -dir[1];
    m1[10] = -dir[2];
    m1[14] =  0.0f;
 
    m1[3]  = 0.0f;
    m1[7]  = 0.0f;
    m1[11] = 0.0f;
    m1[15] = 1.0f;
 
    setIdentityMatrix(m2,4);
    m2[12] = -xPos;
    m2[13] = -yPos;
    m2[14] = -zPos;
 
    multMatrix(MODELVIEW, m1);
    multMatrix(MODELVIEW, m2);
 
#ifdef VSML_ALWAYS_SEND_TO_OPENGL
    matrixToGL(MODELVIEW);
#endif
}
Exemplo n.º 6
0
vector<vector<double>> DOptimization::getMNK(int i)
{
	vector<vector<double>> result;
	result = multMatrix(optimal->getTransponLocalModelMatrix(), mainOwnershipFunction->getDiagOwnershipMatrix(i));
	result = multMatrix(result, optimal->getLocalModelMatrix());
	result = mainLocalModel->invertMatrix(result);
	result = multMatrix(result, optimal->getTransponLocalModelMatrix());
	result = multMatrix(result, mainOwnershipFunction->getDiagOwnershipMatrix(i));
	result = multMatrix(result, mainLocalModel->getLocalMatrix());

	return result;
}
Exemplo n.º 7
0
int main(void){
	int i,j;
		
	TYPE_MATRIX a;
	TYPE_MATRIX b;
	TYPE_MATRIX u;
	TYPE_MATRIX ab;
	TYPE_MATRIX ua;
	
	
	a = newMatrix(MatM,MatN);
	b = newMatrix(MatN,MatP);
	u = newMatrix(MatM,MatM);
	
	for (i=0;i<MatM;i++){
		for (j=0;j<MatN;j++){
			M(a,i,j)=1;
		}
	}
	
	for (i=0;i<MatN;i++){
		for (j=0;j<MatP;j++){
			M(b,i,j)=(j+i*(MatN));
		}
	}
	
	for (i=0; i<MatM;i++){
		for (j=0;j<MatM;j++){
			if (i==j) M(u,i,j)=1;
			else M(u,i,j)=0;
		}
	}
	

	printf("A:\n");
	showMatrix(a);
	printf("B:\n");
	showMatrix(b);
	printf("U:\n");
	showMatrix(u);

	ua=newMatrix(MatN,MatN);
	ua=multMatrix(u,a);
	ab=newMatrix(MatN,MatP);
	ab=multMatrix(a,b);
	
	printf("AB:\n");
	showMatrix(ab);
	printf("UA:\n");
	showMatrix(ua);
	return 0;
}
Exemplo n.º 8
0
// gluLookAt implementation
void 
VSMatrix::lookAt(FLOATTYPE xPos, FLOATTYPE yPos, FLOATTYPE zPos,
					FLOATTYPE xLook, FLOATTYPE yLook, FLOATTYPE zLook,
					FLOATTYPE xUp, FLOATTYPE yUp, FLOATTYPE zUp)
{
	FLOATTYPE dir[3], right[3], up[3];

	up[0] = xUp;	up[1] = yUp;	up[2] = zUp;

	dir[0] =  (xLook - xPos);
	dir[1] =  (yLook - yPos);
	dir[2] =  (zLook - zPos);
	normalize(dir);

	crossProduct(dir,up,right);
	normalize(right);

	crossProduct(right,dir,up);
	normalize(up);

	FLOATTYPE m1[16],m2[16];

	m1[0]  = right[0];
	m1[4]  = right[1];
	m1[8]  = right[2];
	m1[12] = 0.0f;

	m1[1]  = up[0];
	m1[5]  = up[1];
	m1[9]  = up[2];
	m1[13] = 0.0f;

	m1[2]  = -dir[0];
	m1[6]  = -dir[1];
	m1[10] = -dir[2];
	m1[14] =  0.0f;

	m1[3]  = 0.0f;
	m1[7]  = 0.0f;
	m1[11] = 0.0f;
	m1[15] = 1.0f;

	setIdentityMatrix(m2,4);
	m2[12] = -xPos;
	m2[13] = -yPos;
	m2[14] = -zPos;

	multMatrix(m1);
	multMatrix(m2);
}
Exemplo n.º 9
0
// gluLookAt implementation
void lookAt(float xPos, float yPos, float zPos,
					float xLook, float yLook, float zLook,
					float xUp, float yUp, float zUp)
{
	float dir[3], right[3], up[3];

	up[0] = xUp;	up[1] = yUp;	up[2] = zUp;

	dir[0] =  (xLook - xPos);
	dir[1] =  (yLook - yPos);
	dir[2] =  (zLook - zPos);
	normalize(dir);

	crossProduct(dir,up,right);
	normalize(right);

	crossProduct(right,dir,up);
	normalize(up);

	float m1[16],m2[16];

	m1[0]  = right[0];
	m1[4]  = right[1];
	m1[8]  = right[2];
	m1[12] = 0.0f;

	m1[1]  = up[0];
	m1[5]  = up[1];
	m1[9]  = up[2];
	m1[13] = 0.0f;

	m1[2]  = -dir[0];
	m1[6]  = -dir[1];
	m1[10] = -dir[2];
	m1[14] =  0.0f;

	m1[3]  = 0.0f;
	m1[7]  = 0.0f;
	m1[11] = 0.0f;
	m1[15] = 1.0f;

	setIdentityMatrix(m2,4);
	m2[12] = -xPos;
	m2[13] = -yPos;
	m2[14] = -zPos;

	multMatrix(VIEW, m1);
	multMatrix(VIEW, m2);
}
Exemplo n.º 10
0
void setLightMatrixNoBias(double *result, double *shadowProjection, double *shadowModelView, double* camModelView) {
	/*Matrix44f shadowTransMatrix = mShadowCam.getProjectionMatrix();
	 shadowTransMatrix *= mShadowCam.getModelViewMatrix();
	 shadowTransMatrix *= camera.getInverseModelViewMatrix();
	 return shadowTransMatrix;*/
	
	double trans2[16];
	
	multMatrix(trans2,shadowProjection,shadowModelView);
	//setEqual(trans, shadowModelView);
	double inv[16];
	invertMatrix(inv, camModelView);
	multMatrix(result, trans2, inv);
	
}
Exemplo n.º 11
0
//------------------------------------------------------------------------------
void
bindProgram(GLuint program)
{
    glUseProgram(program);

    // shader uniform setting
    GLint position = glGetUniformLocation(program, "lightSource[0].position");
    GLint ambient = glGetUniformLocation(program, "lightSource[0].ambient");
    GLint diffuse = glGetUniformLocation(program, "lightSource[0].diffuse");
    GLint specular = glGetUniformLocation(program, "lightSource[0].specular");
    GLint position1 = glGetUniformLocation(program, "lightSource[1].position");
    GLint ambient1 = glGetUniformLocation(program, "lightSource[1].ambient");
    GLint diffuse1 = glGetUniformLocation(program, "lightSource[1].diffuse");
    GLint specular1 = glGetUniformLocation(program, "lightSource[1].specular");
    
    glProgramUniform4f(program, position, 0.5, 0.2f, 1.0f, 0.0f);
    glProgramUniform4f(program, ambient, 0.1f, 0.1f, 0.1f, 1.0f);
    glProgramUniform4f(program, diffuse, 0.7f, 0.7f, 0.7f, 1.0f);
    glProgramUniform4f(program, specular, 0.8f, 0.8f, 0.8f, 1.0f);
    
    glProgramUniform4f(program, position1, -0.8f, 0.4f, -1.0f, 0.0f);
    glProgramUniform4f(program, ambient1, 0.0f, 0.0f, 0.0f, 1.0f);
    glProgramUniform4f(program, diffuse1, 0.5f, 0.5f, 0.5f, 1.0f);
    glProgramUniform4f(program, specular1, 0.8f, 0.8f, 0.8f, 1.0f);

    GLint otcMatrix = glGetUniformLocation(program, "objectToClipMatrix");
    GLint oteMatrix = glGetUniformLocation(program, "objectToEyeMatrix");
    GLfloat modelView[16], proj[16], mvp[16];
    glGetFloatv(GL_MODELVIEW_MATRIX, modelView);
    glGetFloatv(GL_PROJECTION_MATRIX, proj);
    multMatrix(mvp, modelView, proj);
    glProgramUniformMatrix4fv(program, otcMatrix, 1, false, mvp);
    glProgramUniformMatrix4fv(program, oteMatrix, 1, false, modelView);
}
Exemplo n.º 12
0
void
MyEffect::SetMatrix(const float *modelview, const float *projection) {
    float mvp[16];
    multMatrix(mvp, modelview, projection);
    
    struct Transform {
        float ModelViewMatrix[16];
        float ProjectionMatrix[16];
        float ModelViewProjectionMatrix[16];
    } transformData;
    memcpy(transformData.ModelViewMatrix, modelview, sizeof(float)*16);
    memcpy(transformData.ProjectionMatrix, projection, sizeof(float)*16);
    memcpy(transformData.ModelViewProjectionMatrix, mvp, sizeof(float)*16);

    // set transform
    if (! g_transformUB) {
        glGenBuffers(1, &g_transformUB);
        glBindBuffer(GL_UNIFORM_BUFFER, g_transformUB);
        glBufferData(GL_UNIFORM_BUFFER,
                sizeof(transformData), NULL, GL_STATIC_DRAW);
    };
    glBindBuffer(GL_UNIFORM_BUFFER, g_transformUB);
    glBufferSubData(GL_UNIFORM_BUFFER,
                0, sizeof(transformData), &transformData);
    glBindBuffer(GL_UNIFORM_BUFFER, 0);

    glBindBufferBase(GL_UNIFORM_BUFFER, g_transformBinding, g_transformUB);
}
Exemplo n.º 13
0
void ofMatrixStack::multViewMatrix(const glm::mat4 & matrix){
	ofMatrixMode lastMatrixMode = currentMatrixMode;
	currentMatrixMode = OF_MATRIX_MODELVIEW;
	viewMatrix = viewMatrix * matrix;
	multMatrix(matrix);
	currentMatrixMode = lastMatrixMode;
}
Exemplo n.º 14
0
void Matrix::rotate(const float degrees, const float x, const float y, const float z)
{
    float mat[16];
    const float radians = DEGTORAD(degrees);
    const float co = cos(radians);
    const float si = sin(radians);
    const float x2 = x*x;
    const float y2 = y*y;
    const float z2 = z*z;

    mat[0] = x2 + (y2 + z2) * co;
    mat[4] = x * y * (1 - co) - z * si;
    mat[8] = x * z * (1 - co) + y * si;
    mat[12]= 0.0f;

    mat[1] = x * y * (1 - co) + z * si;
    mat[5] = y2 + (x2 + z2) * co;
    mat[9] = y * z * (1 - co) - x * si;
    mat[13]= 0.0f;

    mat[2] = x * z * (1 - co) - y * si;
    mat[6] = y * z * (1 - co) + x * si;
    mat[10]= z2 + (x2 + y2) * co;
    mat[14]= 0.0f;

    mat[3] = 0.0f;
    mat[7] = 0.0f;
    mat[11]= 0.0f;
    mat[15]= 1.0f;

    multMatrix(mat);
}
void computeStrain(){
	printf("Computing Green strain tensor...\n");

	computeDeformGradient();

	int j, atom;

	double matrI[9];

	for (atom = 0; atom < pdbData.atomCount; atom++){

		for (j = 0; j < 9; j++){
			atomGreenStrain[atom][j] = 0.0;
		}

		transposeMatrix(atomDeformGradient[atom], matrI);
		multMatrix(matrI, atomDeformGradient[atom], atomGreenStrain[atom]);

		for(j = 0; j < 9; j++)
			matrI[j] = 0.0;
		matrI[0] = -1.0;
		matrI[4] = -1.0;
		matrI[8] = -1.0;

		addMatrix(atomGreenStrain[atom], matrI);
		multScalarMatrix(atomGreenStrain[atom], 0.5);

	}
	if(stretchOn)
		computeStretch();
}
Exemplo n.º 16
0
void 
drawElement(e2dElement* elem)  {
    glPushMatrix();
    
    multMatrix(&elem->localTransform);
    switch(elem->type)
    {
            
        case(E2D_GROUP):
            drawGroup((e2dGroup*)elem);
            break;
           
        case(E2D_PATH):
            drawPath((e2dPath*)elem);
            break;
            
        case(E2D_IMAGE):
            drawImage((e2dImage*)elem);
            break;
          
        case(E2D_CLONE):
            drawClone((e2dClone*)elem);
            break;
            
        default:
            break;
    }
        
    drawAxis();
    drawRect(elem->bboxPosition, elem->bboxWidth, elem->bboxHeight);
    glPopMatrix();
}
Exemplo n.º 17
0
// glRotate implementation with matrix selection
void 
VSMathLib::rotate(MatrixTypes aType, float angle, float x, float y, float z)
{
	float mat[16];

	float radAngle = DegToRad(angle);
	float co = cos(radAngle);
	float si = sin(radAngle);
	float x2 = x*x;
	float y2 = y*y;
	float z2 = z*z;

	mat[0] = x2 + (y2 + z2) * co; 
	mat[4] = x * y * (1 - co) - z * si;
	mat[8] = x * z * (1 - co) + y * si;
	mat[12]= 0.0f;
	   
	mat[1] = x * y * (1 - co) + z * si;
	mat[5] = y2 + (x2 + z2) * co;
	mat[9] = y * z * (1 - co) - x * si;
	mat[13]= 0.0f;
	   
	mat[2] = x * z * (1 - co) - y * si;
	mat[6] = y * z * (1 - co) + x * si;
	mat[10]= z2 + (x2 + y2) * co;
	mat[14]= 0.0f;
	   
	mat[3] = 0.0f;
	mat[7] = 0.0f;
	mat[11]= 0.0f;
	mat[15]= 1.0f;

	multMatrix(aType,mat);
}
Exemplo n.º 18
0
// The equivalent to glRotate applied to the model matrix
void rotate(float angle, float x, float y, float z) {

	float aux[16];

	setRotationMatrix(aux,angle,x,y,z);
	multMatrix(modelMatrix,aux);
	setModelMatrix();
}
Exemplo n.º 19
0
// The equivalent to glTranslate applied to the model matrix
void translate(float x, float y, float z) {

	float aux[16];

	setTranslationMatrix(aux,x,y,z);
	multMatrix(modelMatrix,aux);
	setModelMatrix();
}
Exemplo n.º 20
0
// The equivalent to glScale applied to the model matrix
void scale(float x, float y, float z) {

	float aux[16];

	setScaleMatrix(aux,x,y,z);
	multMatrix(modelMatrix,aux);
	setModelMatrix();
}
Exemplo n.º 21
0
void Matrix::scale(const float x, const float y, const float z)
{
    float mat[16];
    setIdentityMatrix(mat);
    mat[0] = x;
    mat[5] = y;
    mat[10] = z;

    multMatrix(mat);
}
Exemplo n.º 22
0
void Matrix::translate(const float x, const float y, const float z)
{
    float mat[16];
    setIdentityMatrix(mat);
    mat[12] = x;
    mat[13] = y;
    mat[14] = z;

    multMatrix(mat);
}
Exemplo n.º 23
0
void GLRenderer::setCamera(const Matrix4x4 &proj, const Matrix4x4 &view) {
	glMatrixMode(GL_PROJECTION);
	loadMatrix(proj);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	/* Apply a rotation to account for the difference in camera
	   conventions. In OpenGL, forward is z=-1, in Mitsuba it is z=+1 */
	glScalef(-1.0f, 1.0f, -1.0f);
	multMatrix(view);
}
Exemplo n.º 24
0
// glScale implementation with matrix selection
void scale(MatrixTypes aType, float x, float y, float z) 
{
	float mat[16];

	setIdentityMatrix(mat,4);
	mat[0] = x;
	mat[5] = y;
	mat[10] = z;

	multMatrix(aType,mat);
}
Exemplo n.º 25
0
// glTranslate implementation with matrix selection
void translate(MatrixTypes aType, float x, float y, float z) 
{
	float mat[16];

	setIdentityMatrix(mat);
	mat[12] = x;
	mat[13] = y;
	mat[14] = z;

	multMatrix(aType,mat);
}
Exemplo n.º 26
0
void TurnAlways::simulateUntil(unsigned long t)
{
	unsigned long dt = t - lastV;	// how long since last update
	float secs = ((float) dt) / 1000;	// convert ms to sec
	lastV = t;
	Matrix delta, newT;
	rotMatrix(delta,'Y',secs * vel);
	multMatrix(delta,owner->transform,newT);
	copyMatrix(newT,owner->transform);

	lastV = t;
}
Exemplo n.º 27
0
// gl Scale implementation with matrix selection
void 
VSMatrix::scale(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z) 
{
	FLOATTYPE mat[16];

	setIdentityMatrix(mat,4);
	mat[0] = x;
	mat[5] = y;
	mat[10] = z;

	multMatrix(mat);
}
Exemplo n.º 28
0
// gl Translate implementation with matrix selection
void 
VSMatrix::translate(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z) 
{
	FLOATTYPE mat[16];

	setIdentityMatrix(mat);
	mat[12] = x;
	mat[13] = y;
	mat[14] = z;

	multMatrix(mat);
}
Exemplo n.º 29
0
void SMatrix4D::scale(tFPType sx, tFPType sy, tFPType sz)
{
  SMatrix4D m;

  m.loadIdentity();
  m.setElem(0, 0, sx);
  m.setElem(1, 1, sy);
  m.setElem(2, 2, sz);

  multMatrix(m);

  return;
}
Exemplo n.º 30
0
void GLRenderer::setCamera(const ProjectiveCamera *camera,
		const Point2 &apertureSample, const Point2 &aaSample, Float timeSample) {
	Float time = camera->getShutterOpen() + camera->getShutterOpenTime() * timeSample;

	glMatrixMode(GL_PROJECTION);
	loadMatrix(camera->getProjectionTransform(
		apertureSample, aaSample).getMatrix());
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	/* Apply a rotation to account for the difference in camera
	   conventions. In OpenGL, forward is z=-1, in Mitsuba it is z=+1 */
	glScalef(-1.0f, 1.0f, -1.0f);
	multMatrix(camera->getViewTransform(time).getMatrix());
}