Graves::Graves(int mode,int numgraves,GLuint *tex,Terrain *map,GLGeometryTransform *pGLGTin,Camera *camIn)
{
	clones = numgraves;
	graveFrame = new GLFrame[clones];

	char* fname = "grave";
	this->multi = true;
	numParts = Loaders::uwsmMultiCheck(fname);
	mesh = new MyTBatch[numParts];
	Vec3 tmax,tmin;
	Loaders::uwsmMultiLoad(fname,mesh,&tmax,&tmin);

	this->max = tmax;
	this->min = tmin;

	theTerrain = map;
	this->pGLGT = pGLGTin;
	this->myTex = tex;
	this->scaleValue=1.0f;
	this->radius = 0.4f;
	this->ptype = 0;
	this->theCam = camIn;
	this->mode = mode;
	myS = new Shader(camIn,"Shaders/nospec.vert","Shaders/nospec.frag",&myTex[0]);

	m3dRotationMatrix44(mx4,D2R*90,0.0,1.0,0.0);
	m3dExtractRotationMatrix33(mx3,mx4);

	setup();
}
Esempio n. 2
0
void Transform::Rotate( float angle, float x, float y, float z ) 
{
	M3DMatrix44f _rotmatrix;
	m3dRotationMatrix44( _rotmatrix, angle, x, y, z );
	M3DMatrix44f _source;
	m3dCopyMatrix44(_source, _matrix);

	m3dMatrixMultiply44(_matrix, _source, _rotmatrix);
}
Esempio n. 3
0
// Called to draw scene
void RenderScene(void)
    {
    M3DMatrix44f   transformationMatrix;   // Storeage for rotation matrix
    static GLfloat yRot = 0.0f;         // Rotation angle for animation
    yRot += 0.5f;
        
    // Clear the window with current clearing color
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        
    // Build a rotation matrix
    m3dRotationMatrix44(transformationMatrix, m3dDegToRad(yRot), 0.0f, 1.0f, 0.0f);
    transformationMatrix[12] = 0.0f;
    transformationMatrix[13] = 0.0f;
    transformationMatrix[14] = -2.5f;
        
    DrawTorus(transformationMatrix);

    // Do the buffer Swap
    glutSwapBuffers();
    }
Esempio n. 4
0
void MouseMoveEvent(int x, int y)
{

	if (isStartTrackBall)
	{
		GLfloat theta;
		M3DVector3f p1, p2, n;
		int width = glutGet(GLUT_WINDOW_WIDTH);
		int height = glutGet(GLUT_WINDOW_HEIGHT);

		MousePtToSphereVec(p1, mMouseX, mMouseY, width, height);
		MousePtToSphereVec(p2, x, y, width, height);

		mMouseX = x;
		mMouseY = y;

		m3dNormalizeVector3(p1);
		m3dNormalizeVector3(p2);
		theta = acos(m3dDotProduct3(p1, p2)) ;

		//theta = m3dGetAngleBetweenVectors3(p1, p2);

		m3dCrossProduct3(n, p1, p2);
		m3dNormalizeVector3(n);

		M3DMatrix44f tempRotation;
		m3dLoadIdentity44(tempRotation);
		GLfloat dis = m3dGetDistance3(p1, p2);
		if (dis != 0.0f)
		{
			m3dRotationMatrix44(tempRotation, theta, m3dGetVectorX(n), m3dGetVectorY(n), m3dGetVectorZ(n));
		}
		m3dMatrixMultiply44(mRotation, tempRotation, mRotation);

		glutPostRedisplay();

		
	}
	
}
void SceneShader()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

	GLfloat VColor[] = {0.25f,0.25f,0.25f,1.0f};

	M3DMatrix44f RotationMatrix;
	Rot += 1.0f; 

	//get the Rotation Matrix 
	//m3dDegToRad: translate angle to radian
	m3dRotationMatrix44(RotationMatrix, m3dDegToRad(Rot), 0.0f, 0.0f, 1.0f);  

	//use the flat shader
	shaderManager.UseStockShader(GLT_SHADER_FLAT, RotationMatrix ,VColor);

	SquareRotationBatch.Draw();

	// Swap buffers, and immediately refresh
	glutSwapBuffers();   
	glutPostRedisplay(); 
}
void RenderScence(void)
{

	static CStopWatch rotTimer;
	float yRot = rotTimer.GetElapsedSeconds() * 60.0f;//每秒旋转60度?

	//Clear the window and the depth buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	M3DMatrix44f mTranslate, mRotate, mModelView, mModelViewProjection;

	//生成一个平移矩阵,用于将花环移回视野中,有个问题,1.0f会是什么效果?1.0会看不见花托。有可能截头体是世界坐标1.0-1000.0f是指距离camera的。所以此矩阵是相对于摄像机的操作,移到摄像机面前2.5f深度距离处
	//即摄像机所在的地方为原点(0,0,0)
	m3dTranslationMatrix44(mTranslate, 0.0f, 0.0f, -2.5f);

	//生成旋转矩阵 以y为轴,旋转时间t产生的旋转角 yRot
	m3dRotationMatrix44(mRotate, m3dDegToRad(yRot), 0.0f, 1.0f, 0.0f);

	//组合为模型变换矩阵,而原模型矩阵在最右边,即先旋转再平移 ?
	m3dMatrixMultiply44(mModelView, mTranslate, mRotate);

	//组合成模型投影矩阵,而原模型矩阵在最右边,先做模型变换再投影 ?
	m3dMatrixMultiply44(mModelViewProjection, viewFrustum.GetProjectionMatrix(), mModelView);

	GLfloat vBlack[] = { 1.0f, 1.0f, 1.0f, 1.0f };

	//选择要配置的渲染操作类型,非smooth,每种模式对应的参数要熟悉才能正确使用
	shaderManger.UseStockShader(GLT_SHADER_FLAT, mModelViewProjection, vBlack);//黑色背景?不是,是设置当前画笔颜色

	torusBatch.Draw();

	glutSwapBuffers();

	glutPostRedisplay();

	//整个流程是:先旋转在平移,然后进行投影剪裁,最后光栅化。UseStockShader 和draw函数之前的变换管线还是不清晰
}