示例#1
0
// Not implemented
TEST_F(SO3Test, RotationXYZ) {

  EXPECT_CLOSE(Rx(0, 0), 1.0);
  EXPECT_CLOSE(Rx(0, 1), 0.0);
  EXPECT_CLOSE(Rx(0, 2), 0.0);
  EXPECT_CLOSE(Rx(1, 0), 0.0);
  EXPECT_CLOSE(Rx(1, 1), 0.5);
  EXPECT_CLOSE(Rx(1, 2), -std::sqrt(3.0) / 2);
  EXPECT_CLOSE(Rx(2, 0), 0.0);
  EXPECT_CLOSE(Rx(2, 1), std::sqrt(3.0) / 2);
  EXPECT_CLOSE(Rx(2, 2), 0.5);

  EXPECT_CLOSE(Ry(0, 0), 0.5);
  EXPECT_CLOSE(Ry(0, 1), 0.0);
  EXPECT_CLOSE(Ry(0, 2), std::sqrt(3.0) / 2);
  EXPECT_CLOSE(Ry(1, 0), 0.0);
  EXPECT_CLOSE(Ry(1, 1), 1.0);
  EXPECT_CLOSE(Ry(1, 2), 0.0);
  EXPECT_CLOSE(Ry(2, 0), -std::sqrt(3.0) / 2);
  EXPECT_CLOSE(Ry(2, 1), 0.0);
  EXPECT_CLOSE(Ry(2, 2), 0.5);

  EXPECT_CLOSE(Rz(0, 0), 0.5);
  EXPECT_CLOSE(Rz(0, 1), -std::sqrt(3.0) / 2);
  EXPECT_CLOSE(Rz(0, 2), 0.0);
  EXPECT_CLOSE(Rz(1, 0), std::sqrt(3.0) / 2);
  EXPECT_CLOSE(Rz(1, 1), 0.5);
  EXPECT_CLOSE(Rz(1, 2), 0.0);
  EXPECT_CLOSE(Rz(2, 0), 0.0);
  EXPECT_CLOSE(Rz(2, 1), 0.0);
  EXPECT_CLOSE(Rz(2, 2), 1.0);
}
Matrix & cartControlReachAvoidThread::rotx(const double theta)
{
        double t=CTRL_DEG2RAD*theta;
        double c=cos(t);
        double s=sin(t);

        Rx(1,1)=Rx(2,2)=c;
        Rx(1,2)=-s;
        Rx(2,1)=s;

        return Rx;
}
static void createInstanceTransforms(mat4 *transforms, float time) {
	for (int x = 0; x < count; x++) {
		for (int y = 0; y < count; y++) {
			for (int z = 0; z < count; z++) {
				int index = x + y * count + z * count * count;
				vec3 rand = (vec3){randoms[index], randoms[index + 1], randoms[index + 2]};
				float particleSize = .15f;
				vec3 volumeSize = (vec3){4.2f, 4.2f, 12.0f};

				float fallOffset = time * 25.0f;

				mat4 translation = T(
						(x - count/2) * volumeSize.x / particleSize + (0.5f - rand.x) * volumeSize.x * 6.0f,
					-fmodf((y - count/2) * volumeSize.y / particleSize + (0.5f - rand.y) * volumeSize.y * 6.0f + fallOffset, 200.0f),
						-fmodf((z - count/2) * volumeSize.z / particleSize + (0.5f - rand.z) * volumeSize.z * 6.0f + fallOffset * 0.5, volumeSize.z * 25.0));
				// mat4 rotation = Mult(Rx(time * 2.5 * rand.y), Rz(time * 2.0 * rand.x));
				mat4 rotation = Rx(.5f);
				mat4 scale = S(particleSize, particleSize, particleSize);


				transforms[index] = Transpose(Mult(Mult(scale, translation), rotation));
			}
		}
	}
}
示例#4
0
//------------------------------
void MolState::rotate(const double alpha_x, const double alpha_y, const double alpha_z)
{
  // three rotation matrices (instead of making one matrix) arouns x, y, z axes
  KMatrix R(CARTDIM,CARTDIM), Rx(CARTDIM,CARTDIM), Ry(CARTDIM,CARTDIM), Rz(CARTDIM,CARTDIM);

  Rx.Set(0);
  Rx.Elem2(0,0)=1;
  Rx.Elem2(1,1)=cos(alpha_x);
  Rx.Elem2(2,2)=cos(alpha_x);
  Rx.Elem2(2,1)=-sin(alpha_x);
  Rx.Elem2(1,2)=sin(alpha_x);

  Ry.Set(0);
  Ry.Elem2(1,1)=1;
  Ry.Elem2(0,0)=cos(alpha_y);
  Ry.Elem2(2,2)=cos(alpha_y);
  Ry.Elem2(2,0)=sin(alpha_y);
  Ry.Elem2(0,2)=-sin(alpha_y);

  Rz.Set(0);
  Rz.Elem2(2,2)=1;
  Rz.Elem2(0,0)=cos(alpha_z);
  Rz.Elem2(1,1)=cos(alpha_z);
  Rz.Elem2(1,0)=-sin(alpha_z);
  Rz.Elem2(0,1)=sin(alpha_z);

  // overall rotation R=Rx*Ry*Rz
  R.SetDiagonal(1);
  R*=Rx;
  R*=Ry;
  R*=Rz;
  
  // and now rotates using matix R:
  transformCoordinates(R);
}
示例#5
0
Eigen::MatrixXd cameraMatrixKnownRT(const double rx, const double ry, const double rz, const double tx, const double ty, const double tz)
{
	// Rotation matrix R = Rx * Ry * Rz(Euler's rotation theorem: any rotation can be broken into 3 angles)
	// Rx rotation by rx about x:
	Eigen::MatrixXd Rx(3,3), Ry(3,3), Rz(3,3);
	Rx << cos(rx), -sin(rx), 0,
		  sin(rx), cos(rx), 0,
		  0, 0, 1;

	// Ry rotation by ry about y:
	Ry << cos(ry), 0, -sin(ry),
		  0, 1, 0,
		  sin(ry), 0, cos(ry);

	// Rz rotation by rz about z:
	Rz << cos(rz), sin(rz), 0,
		  -sin(rz), cos(rz), 0,
		  0, 0, 1;

	Eigen::MatrixXd R = Rx * Ry * Rz;

	Eigen::MatrixXd P(3,4);
	P << R(0, 0), R(0, 1), R(0, 2), tx,
		 R(1, 0), R(1, 1), R(1, 2), ty,
		 R(2, 0), R(2, 1), R(2, 2), tz;
	return P;
}
示例#6
0
文件: lab3-1.c 项目: simplerr/TSBK07
void render_windmill(struct Windmill* windmill, GLuint program, float time)
{
	mat4 rot, trans, scale, total;

	scale = S(1, 1, 1);
	rot = Rx(-time * 4);
	rot = IdentityMatrix();
	trans = T(windmill->position.x, windmill->position.y, windmill->position.z);
	total = Mult(scale, rot);
	total = Mult(trans, total);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);	// Upload matrix

	// Draw the windmill
	DrawModel(windmill->balcony, program, "in_Position", "in_Normal", "inTexCoord");
	DrawModel(windmill->walls, program, "in_Position", "in_Normal", "inTexCoord");
	DrawModel(windmill->roof, program, "in_Position", "in_Normal", "inTexCoord");

	// Draw the blades
	trans = T(windmill->position.x+5, windmill->position.y+10, windmill->position.z);

	// 1
	rot = Rx(0 + time);
	total = Mult(trans, rot);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);	// Upload matrix
	DrawModel(windmill->blade, program, "in_Position", "in_Normal", "inTexCoord");

	// 2
	rot = Rx(3.14f/2.0f + time);
	total = Mult(trans, rot);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);	// Upload matrix
	DrawModel(windmill->blade, program, "in_Position", "in_Normal", "inTexCoord");

	// 3
	rot = Rx(3.14f + time);
	total = Mult(trans, rot);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);	// Upload matrix
	DrawModel(windmill->blade, program, "in_Position", "in_Normal", "inTexCoord");

	// 3
	rot = Rx(-3.14f/2.0f + time);
	total = Mult(trans, rot);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);	// Upload matrix
	DrawModel(windmill->blade, program, "in_Position", "in_Normal", "inTexCoord");

}
示例#7
0
void dR_dthetay(Matrix3x3 &out, const Vector3 &theta)
{
  Matrix3x3 mRx(Rx(theta.x()));
  Matrix3x3 mRz(Rz(theta.z()));

  Matrix3x3 mdRy_dtheta(dRy_dtheta(theta.y()));

  out = mRz*mdRy_dtheta*mRx;
}
示例#8
0
void dR_dthetaz(Matrix3x3 &out, const Vector3 &theta)
{
  Matrix3x3 mRx(Rx(theta.x()));
  Matrix3x3 mRy(Ry(theta.y()));

  Matrix3x3 mdRz_dtheta(dRz_dtheta(theta.z()));

  out = mdRz_dtheta*mRy*mRx;
}
示例#9
0
// Rotation around arbitrary axis (rotation only)
mat4 ArbRotate(vec3 axis, GLfloat fi)
{
	vec3 x, y, z;
	mat4 R, Rt, Raxel, m;

// Check if parallel to Z
	if (axis.x < 0.0000001) // Below some small value
	if (axis.x > -0.0000001)
	if (axis.y < 0.0000001)
	if (axis.y > -0.0000001)
	{
		if (axis.z > 0)
		{
			m = Rz(fi);
			return m;
		}
		else
		{
			m = Rz(-fi);
			return m;
		}
	}

	x = Normalize(axis);
	z = SetVector(0,0,1); // Temp z
	y = Normalize(CrossProduct(z, x)); // y' = z^ x x'
	z = CrossProduct(x, y); // z' = x x y

	if (transposed)
	{
		R.m[0] = x.x; R.m[4] = x.y; R.m[8] = x.z;  R.m[12] = 0.0;
		R.m[1] = y.x; R.m[5] = y.y; R.m[9] = y.z;  R.m[13] = 0.0;
		R.m[2] = z.x; R.m[6] = z.y; R.m[10] = z.z;  R.m[14] = 0.0;

		R.m[3] = 0.0; R.m[7] = 0.0; R.m[11] = 0.0;  R.m[15] = 1.0;
	}
	else
	{
		R.m[0] = x.x; R.m[1] = x.y; R.m[2] = x.z;  R.m[3] = 0.0;
		R.m[4] = y.x; R.m[5] = y.y; R.m[6] = y.z;  R.m[7] = 0.0;
		R.m[8] = z.x; R.m[9] = z.y; R.m[10] = z.z;  R.m[11] = 0.0;

		R.m[12] = 0.0; R.m[13] = 0.0; R.m[14] = 0.0;  R.m[15] = 1.0;
	}

	Rt = Transpose(R); // Transpose = Invert -> felet ej i Transpose, och det Šr en ortonormal matris

	Raxel = Rx(fi); // Rotate around x axis

	// m := Rt * Rx * R
	m = Mult(Mult(Rt, Raxel), R);
	
	return m;
}
//\fn void ExtrinsicParam::changePanTilt(double pan, double tilt);
///\brief This function computes the new rotation matrix and the new translation vector of the extrinsic parameters when the camera has changed its position.
///\param pan Value of the new camera panoramique.
///\param tilt Value of the new camera tilt.
void ExtrinsicParam::changePanTilt(double pan, double tilt)
{
  // Compute the rotation matrices with the new values of pan and tilt
  Eigen::Matrix3d Rx, Ry;
  Rx.setZero();
  Ry.setZero();
  Rx(0,0) = 1;
  Rx(1,1) = cos((-(tilt-this->tilt))*PI/180.);
  Rx(1,2) = -sin((-(tilt-this->tilt))*PI/180.);
  Rx(2,1) = sin((-(tilt-this->tilt))*PI/180.);
  Rx(2,2) = cos((-(tilt-this->tilt))*PI/180.);
  Ry(0,0) = cos((-(pan-this->pan))*PI/180.);
  Ry(0,2) = sin((-(pan-this->pan))*PI/180.);
  Ry(1,1) = 1;
  Ry(2,0) = -sin((-(pan-this->pan))*PI/180.);
  Ry(2,2) = cos((-(pan-this->pan))*PI/180.);

  Eigen::Vector3d Tx, Ty;
  Tx.setZero();
  Ty.setZero();
  Tx(0) = 2*3.3*sin(0.5*(this->pan-pan)*PI/180.)*cos(0.5*(this->pan-pan)*PI/180.);
  Tx(2) = -2*3.3*sin(0.5*(this->pan-pan)*PI/180.)*cos((90.-0.5*(this->pan-pan))*PI/180.);
  Ty(1) = 2*3.3*sin(0.5*(this->tilt-tilt)*PI/180.)*cos(0.5*(this->tilt-tilt)*PI/180.);
  Ty(2) = -2*3.3*sin(0.5*(this->tilt-tilt)*PI/180.)*cos((90.-0.5*(this->tilt-tilt))*PI/180.);

  // Compute the new values of the extrinsic parameters
  Eigen::Matrix4d Rx1, Ry1, Rt;
  Rt << initial_rotation, initial_translation,
    0,0,0,1;
  Rx1 << Rx, Tx,
    0,0,0,1;
  Ry1 << Ry, Ty,
    0,0,0,1;
  Rt.noalias() = Rx1*Ry1*Rt;
  rotation(0,0) = Rt(0,0);rotation(0,1) = Rt(0,1);rotation(0,2) = Rt(0,2);
  rotation(1,0) = Rt(1,0);rotation(1,1) = Rt(1,1);rotation(1,2) = Rt(1,2);
  rotation(2,0) = Rt(2,0);rotation(2,1) = Rt(2,1);rotation(2,2) = Rt(2,2);
  translation(0) = Rt(0,3);
  translation(1) = Rt(1,3);
  translation(2) = Rt(2,3);
}
示例#11
0
文件: lab3-4.c 项目: Nicsi918/Labs
void UploadObjectMatrices(float x, float y, float z, float rAngle, mat4 view, mat4 projection, GLuint prg)
{
	mat4 transMatrix = T(x, y, z);
   mat4 rotMatrix = Rx(rAngle);
   mat4 total = Mult(rotMatrix, transMatrix);
   mat3 normalMatrix = mat4tomat3(total);
   
   glUniformMatrix4fv(glGetUniformLocation(prg, "viewMatrix"), 1, GL_TRUE, view.m);
   glUniformMatrix3fv(glGetUniformLocation(prg, "normalMatrix"), 1, GL_TRUE, normalMatrix.m);
   glUniformMatrix4fv(glGetUniformLocation(prg, "mdlMatrix"), 1, GL_TRUE, total.m);
   glUniformMatrix4fv(glGetUniformLocation(prg, "projectionMatrix"), 1, GL_TRUE, projection.m);
}
示例#12
0
void dR_dtheta(Matrix3x3 &out, const Vector3 &theta, const Vector3 &theta_dot)
{
  Matrix3x3 mRx(Rx(theta.x()));
  Matrix3x3 mRy(Ry(theta.y()));
  Matrix3x3 mRz(Rz(theta.z()));

  Matrix3x3 mdRx_dtheta(dRx_dtheta(theta.x()));
  Matrix3x3 mdRy_dtheta(dRx_dtheta(theta.y()));
  Matrix3x3 mdRz_dtheta(dRx_dtheta(theta.z()));

  out = mdRz_dtheta*mRy*mRx*theta_dot.z();
  out += mRz*mdRy_dtheta*mRx*theta_dot.y();
  out += mRz*mRy*mdRx_dtheta*theta_dot.x();
}
示例#13
0
文件: main.cpp 项目: PONT-MAX/TSBK07
void draw_boost(Maze* maze){
    
    mat4 total;
    int boost = maze->boost;
    int boost_x_pos = maze->boost_x_pos;
    int boost_z_pos = maze->boost_z_pos;
    mat4 boost_pos = T(boost_x_pos, 5, boost_z_pos);
    
    if (boost == 0) {
        
        //Star
        glBindTexture(GL_TEXTURE_2D, startex);
        glActiveTexture(GL_TEXTURE0);
        total = maze->get_total();
        total = Mult(total, boost_pos); //T(20,5,4));
        total = Mult(total, Rx(M_PI_2));
        total = Mult(total, Rz(M_PI_2));
        total = Mult(total, S(0.5, 0.5, 0.5));
        
        glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);
        DrawModel(Star,program,"inPosition","inNormal","inTexCoord");
    }
    
    else if (boost == 1) {
        //speed
        glBindTexture(GL_TEXTURE_2D, speedtex);
        glActiveTexture(GL_TEXTURE0);
        total = maze->get_total();
        total = Mult(total, boost_pos); //T(5,5,8));
        //total = Mult(total, S(0.1, 0.1, 0.1));
        total = Mult(total, S(0.5, 0.5, 0.5));
        
        glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);
        DrawModel(SpeedObj,program,"inPosition","inNormal","inTexCoord");
    }
    
    
    else if ( boost == 2){
        //imortal
        glBindTexture(GL_TEXTURE_2D, imortaltex);
        glActiveTexture(GL_TEXTURE0);
        total = maze->get_total();
        total = Mult(total, boost_pos); //T(8,4.5,8));
        //total = Mult(total, S(0.3, 0.3, 0.3));
        total = Mult(total, S(0.5, 0.5, 0.5));
        glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);
        DrawModel(Imortal,program,"inPosition","inNormal","inTexCoord");
    }
}
示例#14
0
// ABGR
int value_to_color_888(float v, float max)
{
  int s;
  int R;
  int G;
  int B;

  float fact = max;

  v = v / fact;
  B = (int)255. * Bx(v);
  G = (int)255. * Gx(v);
  R = (int)255. * Rx(v);
  s = (R & 0xFF) + ((G & 0xFF) << 8) + ((B & 0xFF) << 16);
  return s;
}
//---------------------------------------------------------
bool CSG_Direct_Georeferencer::Set_Transformation(CSG_Parameters &Parameters, int nCols, int nRows)
{
	//-----------------------------------------------------
	m_O.Create(2);

	m_O[0]	= nCols / 2.0;
	m_O[1]	= nRows / 2.0;

	m_f		= Parameters("CFL"   )->asDouble() / 1000;		// [mm]     -> [m]
	m_s		= Parameters("PXSIZE")->asDouble() / 1000000;	// [micron] -> [m]

	//-----------------------------------------------------
	m_T.Create(3);

	m_T[0]	= Parameters("X")->asDouble();
	m_T[1]	= Parameters("Y")->asDouble();
	m_T[2]	= Parameters("Z")->asDouble();

	//-----------------------------------------------------
	double		a;
	CSG_Matrix	Rx(3, 3), Ry(3, 3), Rz(3, 3);

	a	= Parameters("OMEGA")->asDouble() * M_DEG_TO_RAD;
	Rx[0][0] =       1; Rx[0][1] =       0; Rx[0][2] =       0;
	Rx[1][0] =       0; Rx[1][1] =  cos(a); Rx[1][2] = -sin(a);
	Rx[2][0] =       0; Rx[2][1] =  sin(a); Rx[2][2] =  cos(a);

	a	= Parameters("PHI"  )->asDouble() * M_DEG_TO_RAD;
	Ry[0][0] =  cos(a); Ry[0][1] =       0; Ry[0][2] =  sin(a);
	Ry[1][0] =       0; Ry[1][1] =       1; Ry[1][2] =       0;
	Ry[2][0] = -sin(a); Ry[2][1] =       0; Ry[2][2] =  cos(a);

	a	= Parameters("KAPPA")->asDouble() * M_DEG_TO_RAD + Parameters("KAPPA_OFF")->asDouble() * M_DEG_TO_RAD;
	Rz[0][0] =  cos(a); Rz[0][1] = -sin(a); Rz[0][2] =       0;
	Rz[1][0] =  sin(a); Rz[1][1] =  cos(a); Rz[1][2] =       0;
	Rz[2][0] =       0; Rz[2][1] =       0; Rz[2][2] =       1;

	switch( Parameters("ORIENTATION")->asInt() )
	{
	case 0:	default:	m_R	= Rz * Rx * Ry;	break;	// BLUH
	case 1:				m_R	= Rx * Ry * Rz;	break;	// PATB
	}

	m_Rinv	= m_R.Get_Inverse();

	return( true );
}
示例#16
0
void display(void) {
	printError("pre display");

	/* clear the screen*/
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	GLfloat t = (GLfloat)glutGet(GLUT_ELAPSED_TIME);
	SetVector(xValue, 0.0, (zValue+3), &p);
	lookAt(&p, &l, 0.0, 1.0, 0.0, &cam);


	glUniformMatrix4fv(glGetUniformLocation(program, "camMatrix"), 1, GL_TRUE, cam);

    T(-3.9, -7.4, 0, trans);
    S(0.8, 0.8, 0.8, shear);
    Mult(trans, shear, total);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total);
    DrawModel(windmillRoof, program, "inPosition", "inNormal", "inTexCoord");

    T(-3.9, -7.4, 0, trans);
    S(0.8, 0.8, 0.8, shear);
    Mult(trans, shear, total);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total);
    DrawModel(windmillBalcony, program, "inPosition", "inNormal", "inTexCoord");

    T(-3.9, -7.4, 0, trans);
    S(0.8, 0.8, 0.8, shear);
    Mult(trans, shear, total);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total);    
	DrawModel(windmillWalls, program, "inPosition", "inNormal", "inTexCoord");

	int i;
	for (i = 0; i < 4; i++) {
	    T(0, 0, 0, trans);
	    S(0.5, 0.5, 0.5, shear);
	    Mult(trans, shear, total);
		Rx(i * PI / 2 + t/1000, rot);
	    Mult(rot, total, total);
		glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total);
	    DrawModel(blade, program, "inPosition", "inNormal", "inTexCoord");
	}

	printError("display");

	glutSwapBuffers();
}
示例#17
0
Matrix rotZ(double w, bool useDegrees)
{
	if (useDegrees == true)
	{
		w = w*(M_PI) / 180.0;
	}

	double mat[] = { cos(w),  -sin(w),	0,		0,
					 sin(w),   cos(w),  0,		0,
					 0,			0,		1,		0,
					 0,			0,		0,		1};
					 
	Matrix Rx(4, 4, mat);

	return Rx;

}
示例#18
0
void CreateCubeHeightMaps(TextureData* terrainTextures[6], mat4 terrainTransformationMatrix[6], struct PlanetStruct* planet)
{
		GLuint i;	
		for(i = 0; i < 6; i++)
		{
			terrainTextures[i] = chkmalloc(sizeof(TextureData));
		}

		// Load terrain data
		for (i = 0; i < 6; i++)
			if(fuzzy == 0)
				LoadTGATextureData("textures/fft-terrain.tga", terrainTextures[i]);
			else
				LoadTGATextureData("testTGA.tga", terrainTextures[i]);


		//Generate terrain model matrix

		planet->terrainWidth = (GLfloat)terrainTextures[0]->width;
		planet->terrainHeight = (GLfloat)terrainTextures[0]->height;
		GLfloat distanceToMiddleX = ((GLfloat)terrainTextures[0]->width*0.5f);
		GLfloat distanceToMiddleZ = ((GLfloat)terrainTextures[0]->height*0.5f);
		GLfloat distanceToMiddleY = planet->radius;

		for (i = 0; i < 4; ++i)
		{
			terrainTransformationMatrix[i] = T(-distanceToMiddleX, distanceToMiddleY, -distanceToMiddleZ);
			terrainTransformationMatrix[i] = Mult( Rz(M_PI*0.5f*(GLfloat)i), terrainTransformationMatrix[i] );
		}

		//Last two sides
		for (i = 0; i < 2; ++i)
		{
			terrainTransformationMatrix[4+i] = T(-distanceToMiddleX, distanceToMiddleY, -distanceToMiddleZ);
			terrainTransformationMatrix[4+i] = Mult( Rx(M_PI*(0.5f+(GLfloat)i)), terrainTransformationMatrix[4+i] );
		}

		//Weird offset: (Probably size dependent)
		terrainTransformationMatrix[1] = Mult(T(0, 1, 0), terrainTransformationMatrix[1]);
		terrainTransformationMatrix[2] = Mult(T(-1, 1, 0), terrainTransformationMatrix[2]);
		terrainTransformationMatrix[3] = Mult(T(-1, 0, 0), terrainTransformationMatrix[3]);
		terrainTransformationMatrix[4] = Mult(T(0, 0, -1), terrainTransformationMatrix[4]);
		terrainTransformationMatrix[5] = Mult(T(0, 1, 0), terrainTransformationMatrix[5]);

}
示例#19
0
void Body::rotate(char direction, float angle)
{
  switch (direction) {
  case 'x':
    // Rotate around x
    rot_mat = Rx(angle) * rot_mat;
    break;
  case 'y':
    // Rotate around y
    rot_mat = rot_mat * Ry(angle) * rot_mat;
    break;
  case 'z':
    // Rotate around z
    rot_mat = Rz(angle) * rot_mat;
    break;
  }
  update();
}
示例#20
0
	//construct the rotation matrices between ICRF and the local frame
	void frame::construct_rotation_matrices(const double& ETepoch)
	{
		//first, get the current date in TBB
		double TDBepoch = convert_ET_to_TDB(ETepoch);

		double days_since_reference_epoch = TDBepoch - 2451545.0;
		double centuries_since_reference_epoch = days_since_reference_epoch / 36525;

		//compute the current values of the angles alpha and delta
		double alpha = alpha0 + alphadot * centuries_since_reference_epoch;
		double delta = delta0 + deltadot * centuries_since_reference_epoch;

		//next, construct the rotation matrix
		math::Matrix<double> Rx (3, (math::PIover2 - delta), math::Rxhat);
		math::Matrix<double> Rz (3, (math::PIover2 + alpha), math::Rzhat);
		R_from_local_to_ICRF = Rz*Rx;
		R_from_ICRF_to_local = R_from_local_to_ICRF.transpose();
	}
示例#21
0
// Normalises a value v in 0. and 1. and converts that to a rgb 565 short int
int value_to_color_565(float v, float max)
{
  int s;
  int R;
  int G;
  int B;

  float fact = max;

  v = v / fact;
  B = (int)31. * Bx(v);
  G = (int)63. * Gx(v);
  R = (int)31. * Rx(v);
  s = (R % 32) + ((G % 64) << 5) + ((B % 32) << 11);
//  if (v == 1.)
  //  s = 0xFE00;
  //printf("vla=%f, max=%f\n", v, max);
  return s;
}
示例#22
0
// Rotation kring godtycklig axel (enbart rotationen)
void ArbRotate(Point3D *axis, GLfloat fi, GLfloat *m)
{
	Point3D x, y, z, a;
	GLfloat R[16], Rt[16], Raxel[16], RtRx[16];
	
// Kolla ocksΠom parallell med Z-axel!
	if (axis->x < 0.0000001) // Under nŒgon tillrŠckligt liten grŠns
	if (axis->x > -0.0000001)
	if (axis->y < 0.0000001)
	if (axis->y > -0.0000001)
		if (axis->z > 0)
		{
			Rz(fi, m);
			return;
		}
		else
		{
			Rz(-fi, m);
			return;
		}

	x = *axis;
	Normalize(&x); // |x|
	SetVector(0,0,1, &z); // Temp z
	CrossProduct(&z, &x, &y);
	Normalize(&y); // y' = z^ x x'
	CrossProduct(&x, &y, &z); // z' = x x y

	R[0] = x.x; R[4] = x.y; R[8] = x.z;  R[12] = 0.0;
	R[1] = y.x; R[5] = y.y; R[9] = y.z;  R[13] = 0.0;
	R[2] = z.x; R[6] = z.y; R[10] = z.z;  R[14] = 0.0;

	R[3] = 0.0; R[7] = 0.0; R[11] = 0.0;  R[15] = 1.0;

	Transpose(&R, &Rt); // Transpose = Invert -> felet ej i Transpose, och det Šr en ortonormal matris
	
	Rx(fi, &Raxel); // Rotate around x axis
	
	// m := Rt * Rx * R
	Mult(&Rt, &Raxel, &RtRx);
	Mult(&RtRx, &R, m);
}
示例#23
0
void display(void) {
	printError("pre display");

	/* clear the screen*/
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	GLfloat t = (GLfloat)glutGet(GLUT_ELAPSED_TIME);

	T(0, 0, -2, trans);
	Ry(t/1000, rot);
    Mult(trans, rot, total);
	Rx(t/1000, rot);
    Mult(total, rot, total);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total);

    glBindVertexArray(bunnyVertexArrayObjID);    // Select VAO
    glDrawElements(GL_TRIANGLES, m->numIndices, GL_UNSIGNED_INT, 0L);
	
	printError("display");
	
	glutSwapBuffers();
}
示例#24
0
// for growing
void base_bin_rel::move_from (const base_bin_rel & other)
{
    POMAGMA_DEBUG("Copying base_bin_rel");

    size_t min_item_dim = min(item_dim(), other.item_dim());
    size_t min_word_dim = min(word_dim(), other.word_dim());

    m_support.move_from(other.m_support);

    if (_symmetric()) {
        POMAGMA_ASSERT(other._symmetric(), "symmetry mismatch");
        for (size_t i = 1; i <= min_item_dim; ++i) {
            memcpy(Lx(i), other.Lx(i), sizeof(Word) * min_word_dim);
        }
    } else {
        POMAGMA_ASSERT(not other._symmetric(), "symmetry mismatch");
        for (size_t i = 1; i <= min_item_dim; ++i) {
            memcpy(Lx(i), other.Lx(i), sizeof(Word) * min_word_dim);
            memcpy(Rx(i), other.Rx(i), sizeof(Word) * min_word_dim);
        }
    }
}
示例#25
0
void display(void)
{
  printError("pre display");

  // clear the screen (using chosen color earlier)
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glClearColor(1,1,1,0);

  // Set rotation matrix
  phi = ( phi < 2*PI ) ? phi+PI/50 : phi-2*PI+PI/50;

  vec3 trans = {1,0,-3};
  vec3 trans2 = {-1,0,-3};
  vec3 lookAtPoint = {0,0,-3};
  vec3 cameraLocation = {3.0f*cos(phi),0.0f,-3+3.0f*sin(phi)};
  vec3 upVector = {0,1,0};

  mat4 translation = T(trans.x,trans.y,trans.z);
  mat4 rotations = Mult(Ry(phi),Mult(Rx(phi), Rz(phi)));

  mat4 lookAtMatrix = lookAtv(cameraLocation,lookAtPoint,upVector);
  transformMatrix = Mult(translation,rotations);

  // Send translMatrix to Vertex
  glUniformMatrix4fv(glGetUniformLocation(program, "transformMatrix"), 1, GL_TRUE,  transformMatrix.m);
  // Send lookAt-vector to vertex shader
  glUniformMatrix4fv(glGetUniformLocation(program, "lookAtMatrix"), 1, GL_TRUE,  lookAtMatrix.m);

  DrawModel(bunny, program, "in_Position", "in_Normal", "inTexCoord");

  // Model 2
  transformMatrix = T(trans2.x, trans2.y, trans2.z);
  glUniformMatrix4fv(glGetUniformLocation(program, "transformMatrix"), 1, GL_TRUE,  transformMatrix.m);
  DrawModel(bunny_model2, program, "in_Position", "in_Normal", "inTexCoord");

  printError("display");

  glutSwapBuffers(); // Swap buffer so that GPU can use the buffer we uploaded to it and we can write to another
}
示例#26
0
void BinaryRelation::validate () const
{
    POMAGMA_INFO("Validating BinaryRelation");

    m_lines.validate();

    size_t num_pairs = 0;

    DenseSet Lx(round_item_dim(), nullptr);
    DenseSet Rx(round_item_dim(), nullptr);
    for (Ob i = 1; i <= item_dim(); ++i) {
        bool sup_i = supports(i);
        Lx.init(m_lines.Lx(i));

        for (Ob j = 1; j <= item_dim(); ++j) {
            bool sup_ij = sup_i and supports(j);
            Rx.init(m_lines.Rx(j));

            bool Lx_ij = Lx.contains(j);
            bool Rx_ij = Rx.contains(i);
            num_pairs += Rx_ij;

            POMAGMA_ASSERT(Lx_ij == Rx_ij,
                    "Lx,Rx disagree at " << i << "," << j
                    << ", Lx is " << Lx_ij << ", Rx is " << Rx_ij  );

            POMAGMA_ASSERT(sup_ij or not Lx_ij,
                    "Lx unsupported at " << i << "," << j );

            POMAGMA_ASSERT(sup_ij or not Rx_ij,
                    "Rx unsupported at " << i << "," << j );
        }
    }

    size_t true_size = count_pairs();
    POMAGMA_ASSERT(num_pairs == true_size,
            "incorrect number of pairs: "
            << num_pairs << " should be " << true_size);
}
示例#27
0
void display(void)
{
  printError("pre display");

  // clear the screen (using chosen color earlier)
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  // Set rotation matrix
  phi += PI/50;

  mat4 translation = T(0,0,-3);
  mat4 rotations = Mult(Ry(phi),Mult(Rx(phi), Rz(phi)));
  transformMatrix = Mult(translation,rotations);

  // Send translMatrix to Vertex
  glUniformMatrix4fv(glGetUniformLocation(program, "transformMatrix"), 1, GL_TRUE,  transformMatrix.m); // Variate shader

  glBindVertexArray(bunnyVertexArrayObjID);	// Select VAO
  glDrawElements(GL_TRIANGLES, m->numIndices, GL_UNSIGNED_INT, 0L);

  printError("display");

  glutSwapBuffers(); // Swap buffer so that GPU can use the buffer we uploaded to it and we can write to another
}
示例#28
0
void base_bin_rel::validate() const
{
    m_support.validate();

    // TODO validate Lx, Rx agree with support
    // (move code over from dense_bin_rel::validate()

    if (_symmetric()) {

        // check emptiness outside of support
        dense_set set(item_dim(), NULL);
        dense_set round_set(m_round_item_dim, NULL);
        for (oid_t i = 0; i < m_round_item_dim; ++i) {
            if (1 <= i and i <= item_dim()) {
                set.init(Lx(i));
                set.validate();
            } else {
                round_set.init(m_Lx_lines + m_round_word_dim * i);
                round_set.validate();
                POMAGMA_ASSERT(round_set.empty(),
                        "unsupported Lx(" << i << ") has " <<
                        round_set.count_items() << " items");
            }
        }

        // check for Lx/Rx agreement
        for (oid_t i = 1; i <= item_dim(); ++i) {
        for (oid_t j = i; j <= item_dim(); ++j) {
            POMAGMA_ASSERT(Lx(i, j) == Rx(i, j),
                    "Lx, Rx disagree at " << i << ',' << j);
        }}

    } else {

        // check emptiness outside of support
        dense_set set(item_dim(), NULL);
        dense_set round_set(m_round_item_dim, NULL);
        for (oid_t i = 0; i < m_round_item_dim; ++i) {
            if (1 <= i and i <= item_dim()) {
                set.init(Lx(i));
                set.validate();
                set.init(Rx(i));
                set.validate();
            } else {
                round_set.init(m_Lx_lines + m_round_word_dim * i);
                round_set.validate();
                POMAGMA_ASSERT(round_set.empty(),
                        "unsupported Lx(" << i << ") has " <<
                        round_set.count_items() << " items");
                round_set.init(m_Rx_lines + m_round_word_dim * i);
                round_set.validate();
                POMAGMA_ASSERT(round_set.empty(),
                        "unsupported Rx(" << i << ") has " <<
                        round_set.count_items() << " items");
            }
        }

        // check for Lx/Rx agreement
        for (oid_t i = 1; i <= item_dim(); ++i) {
        for (oid_t j = 1; j <= item_dim(); ++j) {
            POMAGMA_ASSERT(Lx(i, j) == Rx(i, j),
                    "Lx, Rx disagree at " << i << ',' << j);
        }}
    }
}
示例#29
0
文件: main.c 项目: ErikHK/tsbk03
void OnTimer(int value)
{
	glutTimerFunc(20, &OnTimer, value);

	old_t = t;
	t = (GLfloat)glutGet(GLUT_ELAPSED_TIME)/1000.0;
	delta_t = (t - old_t);
	//printf("%f\n", delta_t);

	GLfloat tmpppp[3] = {cow.pos.x, cow.pos.y, cow.pos.z};
	glUniform3fv(glGetUniformLocation(g_shader, "cow_pos"), 1, tmpppp);


	turn_cow(&cow, -m_angle);
	update_cow(&cow, delta_t);
	update_fence(&ff, &cow, delta_t);
	move_cow(&cow, m_angle);
	update_floor(&f, &cow);
	update_wall(&wall, &cow, delta_t);
	update_ball(&ball, &cow, delta_t);
	update_farmer(&farmer);
        if(keyIsDown('k'))
	update_ragdoll(&ragdoll, delta_t);

	if(check_collision_2(&cow.bb, &wall.bb))
	{
	  //printf("yey\n");
	  glUniform1i(glGetUniformLocation(g_shader, "collision"), 1);
	  //cow.momentum = SetVector(-cow.momentum.x, cow.momentum.y, -cow.momentum.z);
	  //wall_collision(wall, cow);
	}
	else
	  glUniform1i(glGetUniformLocation(g_shader, "collision"), 0);



	//printf("%f, %f\n", delta_t, old_t);
	glUniform1f(glGetUniformLocation(g_shader, "time"), t);


	mat4 proj_matrix = frustum(-1, 1, -1, 1, 1, 750.0);
	mat4 cam_matrix = lookAt(cam_dist*cos(m_angle)+cow.pos.x, 9+cow.pos.y,  cam_dist*sin(m_angle)+cow.pos.z, cow.pos.x, 8.5+cow.pos.y, cow.pos.z, 0.0, 1.0, 0.0);
	//mat4 cam_matrix = lookAt(200+200*cos(cam_angle), 0,  200, 0, 8, 0, 0.0, 1.0, 0.0);

	//g_shader = loadShaders("shader.vert" , "shader.frag");
	//glUseProgram(g_shader);

	glUniformMatrix4fv(glGetUniformLocation(g_shader, "proj_matrix"), 1, GL_TRUE, proj_matrix.m);
	glUniformMatrix4fv(glGetUniformLocation(g_shader, "cam_matrix"), 1, GL_TRUE, cam_matrix.m);
	//glutDisplayFunc(DisplayWindow);

	//draw_cow(&cow, g_shader);
	//draw_bone(&bone, g_shader);

	mat4 tmp, testjoint, testjoint2;
	testjoint = IdentityMatrix();

	joint_s * j = &head_joint[0];
	joint_s * jc = j->child[0];
	joint_s * jcc = jc->child[0];
	//joint_s * jp = j->parent;
	//joint_s * jpp = jp->parent;

	float Ms[8][4*4];
	float legMs[8][4*4];
	float currpos[8*3] = {0};
	float bonepos[8*3] = {0};
	float legcurrpos[8*3] = {0};
	float legbonepos[8*3] = {0};
	//GLfloat * Mtmp = Ms;
	int i=0, ii=0;
	//jc->R = ArbRotate(SetVector(0,0,1), cos(4*t/(i+1))/2.5);
	//j->R = ArbRotate(SetVector(0,0,1), 0);
	j->R = ArbRotate(SetVector(0,0,1), sin(4*t/(3+1))/1.2);
	//jcc->R = ArbRotate(SetVector(0,0,1), cos(8*t/(2+1))/4);
	mat4 Mpacc, Minvacc, tmptrans, tmppp, invtrans;
	tmppp = IdentityMatrix();


	float freq = 7;//Norm(cow.speed)/4;

	if(Norm(cow.momentum) < .5)
	  freq = 0;
	else if(Norm(cow.momentum) > 5)
	  freq = 20;
	//printf("%f\n", freq);

	j = &thigh_joint[0];
	jc = j->child[0];
	j->R = ArbRotate(SetVector(0,0,1), sin(freq*t)/1.5);
	jc->R = ArbRotate(SetVector(0,0,1), cos(freq*t)/2.5);

	j = &thigh_joint[1];
	jc = j->child[0];
	j->R = ArbRotate(SetVector(0,0,1), -cos(freq*t)/2.5);
	jc->R = ArbRotate(SetVector(0,0,1), sin(freq*t)/2.5);


	j = &thigh_joint[2];
	jc = j->child[0];
	j->R = ArbRotate(SetVector(0,0,1), sin(freq*t)/1.5);
	jc->R = ArbRotate(SetVector(0,0,1), cos(freq*t)/2.5);

	j = &thigh_joint[3];
	jc = j->child[0];
	j->R = ArbRotate(SetVector(0,0,1), -cos(freq*t)/2.5);
	jc->R = ArbRotate(SetVector(0,0,1), sin(freq*t)/2.5);


	j = &legbase_joint[0];
	//j->R = ArbRotate(SetVector(1,0,0), -cos(7*t/(i+1)));
	//j->R = ArbRotate(SetVector(1,0,0), -M_PI/6);

	j = &thigh_joint[0];
	//j->R = Mult(ArbRotate(SetVector(1,0,0), cos(7*t/(i+1))), j->R);
	//j->R = Mult(ArbRotate(SetVector(1,0,0), M_PI/6), j->R);

	i = 0;
	tmppp = IdentityMatrix();
	//legbase_joint[0].R = ArbRotate(SetVector(0,0,1), cos(3*t)/2);

	//legs
	calc_bone_transform(&legbase_joint[0], 0);
	calc_bone_transform(&legbase_joint[1], 0);
	calc_bone_transform(&legbase_joint[2], 0);
	calc_bone_transform(&legbase_joint[3], 0);

	j = &tail_joint[0];
	j->R = ArbRotate(SetVector(0,0,1), -M_PI/2.5);
	j = &tail_joint[1];
	j->R = ArbRotate(SetVector(0,0,1), -M_PI/8.5);

	//j = &tail_joint[1];
	//j->R = ArbRotate(SetVector(0,0,1), 0);
	j = &tail_joint[2];
	//j->R = ArbRotate(SetVector(0,0,1), 0);
	j = &tail_joint[3];
	j->R = ArbRotate(SetVector(0,0,1), 0);

	//body
	j = &body_joint[1];
	//j->R = ArbRotate(SetVector(0,0,1), cos(t*7)/9.5);
	j->R = ArbRotate(SetVector(0,1,0), m_angle + cow.angle);
	j->R = Mult(j->R, ArbRotate(SetVector(0,0,1), cos(freq*t)/9));

	calc_bone_transform(&body_joint[0],0);

	//tail
	//j = &tail_joint[1];
	//j->R = ArbRotate(SetVector(0,0,1), -M_PI/2.5);

	//j = &tail_joint[1];
	//j->R = ArbRotate(SetVector(0,0,1), 0);

	//j = &tail_joint[2];
	//j->R = ArbRotate(SetVector(0,0,1), 0);

	//j = &tail_joint[3];
	//j->R = ArbRotate(SetVector(0,0,1), 0);

	//calc_bone_transform(&tail_joint[0],0);

	//head
	j = &head_joint[0];

	j->R = ArbRotate(SetVector(0,0,1), sin(7*t)/9.5);

	calc_bone_transform(&head_joint[0],0);



	j = &farmer.skeleton.joints[2];
	//j->R = Rx(cos(4*t));
	j->R = Mult(Rx(M_PI/2.2 + sin(5*t)/11), Ry(cos(-5*t)/2));

	j = &farmer.skeleton.joints[3];
	//j->R = Rx(cos(4*t));
	j->R = Mult(Rx(-M_PI/2.2 + sin(5*t)/11), Ry(cos(5*t)/2));

	//left shoulder (her right)
	//jc = &farmer.skeleton.joints[3];
	//jc->R = Rx(-sin(3*t));

	jc = &farmer.skeleton.joints[4];
	jc->R = Ry(M_PI/3 + cos(5*t)/8);

	jc = &farmer.skeleton.joints[5];
	jc->R = Ry(-M_PI/3 + cos(5*t)/8);


	jc = &farmer.skeleton.joints[10];
	//jc->R = Rz(M_PI/3);
	jc->R = Rz(.5-cos(5*t));

	jc = &farmer.skeleton.joints[12];
	jc->R = Rz((-1-cos(5*t))/2);


	jc = &farmer.skeleton.joints[11];
	//jc->R = Rz(M_PI/3);
	jc->R = Rz(.5+cos(5*t));

	jc = &farmer.skeleton.joints[13];
	jc->R = Rz((-1-cos(5*t))/2);


	calc_bone_transform(&farmer.skeleton.joints[0], 0);
	calc_bone_transform(&farmer.skeleton.joints[2], 0);
	calc_bone_transform(&farmer.skeleton.joints[3], 0);
	//calc_bone_transform(&farmer.skeleton.joints[4], 0);
	calc_bone_transform(&farmer.skeleton.joints[1], 0);

	calc_bone_transform(&farmer.skeleton.joints[10], 0);

	calc_bone_transform(&farmer.skeleton.joints[11], 0);
//	calc_bone_transform(&farmer.skeleton.joints[8], 0);
//	calc_bone_transform(&farmer.skeleton.joints[9], 0);

	glutPostRedisplay();
}
示例#30
0
void display(void) {
    int i, k;

    /* clear the screen*/
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glUseProgram(program);

    GLfloat t = (GLfloat)glutGet(GLUT_ELAPSED_TIME);

    camPos += camMod;

    xValue += xModify * speed;
    yValue += yModify;
    zValue += zModify * speed;

    if (yModify == 0) {
        yCamPos = yValue+2;
    }
    SetVector(xValue + 5 * cos(camPos), yCamPos, zValue + 5 * sin(camPos), &p);
    SetVector(xValue, yCamPos + 0.5, zValue, &l);

    lookAt(&p, &l, 0.0, 1.0, 0.0, cam);
    GLfloat tmp[16];
    CopyMatrix(cam, tmp);
    tmp[3] = 0;
    tmp[7] = 0;
    tmp[11] = 0;
    glUniformMatrix4fv(glGetUniformLocation(program, "camMatrix"), 1, GL_TRUE, tmp);
  
/* ================================================================== */

    glDisable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);

    T(0, 0, 0, trans);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, skyBoxTex);
    glUniform1i(glGetUniformLocation(program, "texUnit"), 0); // Texture unit 0
    glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, trans);
    DrawModel(skyBox, program, "inPosition", "inNormal", "inTexCoord");


    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);

/* ================================================================== */

    glUniformMatrix4fv(glGetUniformLocation(program, "camMatrix"), 1, GL_TRUE, cam);


    T(0, 0, 0, trans);
    S(150,0, 150, shear);
    Mult(trans, shear, total);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, groundTex);
    glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total);
    DrawModel(ground, program, "inPosition", "inNormal", "inTexCoord");

/* ================================================================== */

    T(10.0f, 5.0f, 0.0f, trans);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, groundTex);
    glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, trans);
    DrawModel(ground, program, "inPosition", "inNormal", "inTexCoord");


    T(0.0f, 10.0f, 10.0f, trans);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, groundTex);
    glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, trans);
    DrawModel(ground, program, "inPosition", "inNormal", "inTexCoord");


    T(-10.0f, 0.0f, 0.0f, trans);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, groundTex);
    glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, trans);
    DrawModel(ground, program, "inPosition", "inNormal", "inTexCoord");


    T(0.0f, 0.0f, -15.0f, trans);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, groundTex);
    glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, trans);
    DrawModel(ground, program, "inPosition", "inNormal", "inTexCoord");

/* ================================================================== */

    glUseProgram(programShade);
    glUniform3fv(glGetUniformLocation(programShade, "inCam"), 3, &p);

    glUniformMatrix4fv(glGetUniformLocation(programShade, "camMatrix"), 1, GL_TRUE, cam);
    T(-3.9, 0, 0, trans);
    S(0.8, 0.8, 0.8, shear);
    Mult(trans, shear, total);
    //Ry(M_PI, rot);
    //Mult(total, rot, total);
    glUniformMatrix4fv(glGetUniformLocation(programShade, "mdlMatrix"), 1, GL_TRUE, total);
    DrawModel(windmillRoof, programShade, "inPosition", "inNormal", "inTexCoord");

    T(-3.9, 0, 0, trans);
    S(0.8, 0.8, 0.8, shear);
    Mult(trans, shear, total);
    //Ry(M_PI, rot);
    //Mult(total, rot, total);
    glUniformMatrix4fv(glGetUniformLocation(programShade, "mdlMatrix"), 1, GL_TRUE, total);
    DrawModel(windmillBalcony, programShade, "inPosition", "inNormal", "inTexCoord");

    T(-3.9, 0, 0, trans);
    S(0.8, 0.8, 0.8, shear);
    Mult(trans, shear, total);
    //Ry(M_PI, rot);
    //Mult(total, rot, total);
    glUniformMatrix4fv(glGetUniformLocation(programShade, "mdlMatrix"), 1, GL_TRUE, total);    
    DrawModel(windmillWalls, programShade, "inPosition", "inNormal", "inTexCoord");
    for (i = 0; i < 4; i++) {
        T(0, 7.4, 0, trans);
        S(0.5, 0.5, 0.5, shear);
        Mult(trans, shear, total);
        Rx(i * PI / 2 + t/1000, rot);
        Mult(total, rot, total);
        glUniformMatrix4fv(glGetUniformLocation(programShade, "mdlMatrix"), 1, GL_TRUE, total);
        DrawModel(blade, programShade, "inPosition", "inNormal", "inTexCoord");
    }

/* ================================================================== */

    glUseProgram(programMultitex);
    glEnable(GL_BLEND);
    //glDisable(GL_CULL_FACE);
    //glDisable(GL_DEPTH_TEST);

    glUniformMatrix4fv(glGetUniformLocation(programMultitex, "camMatrix"), 1, GL_TRUE, cam);
    glActiveTexture(GL_TEXTURE1);
    glBindTexture(GL_TEXTURE_2D, bunnyTex);
    glActiveTexture(GL_TEXTURE2);
    glBindTexture(GL_TEXTURE_2D, skyBoxTex);
    glUniform1i(glGetUniformLocation(programMultitex, "texUnit"), 1); // Texture unit 1
    glUniform1i(glGetUniformLocation(programMultitex, "texUnit2"), 2); // Texture unit 2

    yValue += yModify;

    if (gravity < 0 && yValue > 0.5) {
        gravity += 0.03;
        yModify -= gravity;
    } else if (yValue > 0.5) {
        gravity += 0.006;
        yModify -= gravity;
    } else {
        gravity = -0.28;
        yValue = 0.55;
        yModify = 0.0;
    }

//    for (k = -7; k < 7; k++) {
        for (i = 2; i > -2; i--) {
//            T(i * 10, yValue, k * 10, trans);
            T(i * 10, 2.5, 10, trans);
            S(5,5,5, shear);
            Mult(trans, shear, total);
            glUniformMatrix4fv(glGetUniformLocation(programMultitex, "mdlMatrix"), 1, GL_TRUE, total);
            DrawModel(bunny, programMultitex, "inPosition", "inNormal", "inTexCoord");
        }
//    }

    //glEnable(GL_DEPTH_TEST);
    //glEnable(GL_CULL_FACE);
    glDisable(GL_BLEND);





    glFlush();
//    glutSwapBuffers();
}