コード例 #1
0
ファイル: physics.cpp プロジェクト: awjc/OpenGLPhysics
void keyboard( unsigned char key, int x, int y )
{
	if (!cameraControl->handleKey(key))
	{
		switch( key ) {
		case 033: // Escape Key
		case 'q': case 'Q':
			exit( EXIT_SUCCESS );
			break; 
			// when we change the axis of rotation, want to take its current
			// position and start rotating about the new axis, so we compose
			// the current rotation with the current orientation matrix
		case 'x':
			currentOrientation = getCurrentRotation() * currentOrientation;
			currentAxis = XAxis;
			degrees = 0;
			break;
		case 'y':
			currentOrientation = getCurrentRotation() * currentOrientation;
			currentAxis = YAxis;
			degrees = 0;
			break;
		case 'z':
			currentOrientation = getCurrentRotation() * currentOrientation;
			currentAxis = ZAxis;
			degrees = 0;
			break;		
		case '+':
			increment += 0.1;
			break;
		case '-':
			increment -= 0.1;
			break;
		case ' ':   // pause
			paused = 1 - paused;
			break;
		case 'c':
			shrink -= 0.05;
			if (shrink <= 0.0) shrink = 0.0;
			break;
		case 'C':
			shrink += 0.05;
			if (shrink >= 1.0) shrink = 1.0;
			break;
		case 'e':
			explode += 0.1;
			break;
		case 'E':
			explode -= 0.1;
			break;
		case 't':
			tesselate += 0.001;
			break;
		case 'T':
			tesselate -= 0.001;
			break;
		}
	}
	glutPostRedisplay();
}
コード例 #2
0
ファイル: input.c プロジェクト: Djeezus/woykivnc
inline void transformTouchCoordinates(int *x, int *y,int width,int height)
{
  int scale=4096.0;
  int old_x=*x,old_y=*y;
  int rotation=getCurrentRotation();

  if (rotation==0)
  {  
    *x = old_x*scale/width-scale/2.0;
    *y = old_y*scale/height-scale/2.0;
  }
  else if (rotation==90)
  {
    *x =old_y*scale/height-scale/2.0;
    *y = (width - old_x)*scale/width-scale/2.0;
  }
  else if (rotation==180)
  {
    *x =(width - old_x)*scale/width-scale/2.0;
    *y =(height - old_y)*scale/height-scale/2.0;
  }
  else if (rotation==270)
  {
    *y =old_x*scale/width-scale/2.0; 
    *x =(height - old_y)*scale/height-scale/2.0;
  }

}
コード例 #3
0
ファイル: physics.cpp プロジェクト: awjc/OpenGLPhysics
void display( void )
{
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

	// increase the rotation angle
	if (!paused)
	{
		degrees += increment;
		while (degrees >= 360.0) degrees -= 360.0;
		while (degrees <= -360.0) degrees += 360.0;
	}

	lpos.x = 2*sin(DegreesToRadians * degrees);
	lpos.y = .5;
	lpos.z = 2*cos(DegreesToRadians * degrees);

	// apply the rotation to the current orientation of the cube
	mat4 model = getCurrentRotation() * currentOrientation * initialTransform;

	mat4 view = camera->GetView();
	mat4 projection = camera->GetProjection();

	// Create normal matrix
	mat4 mv = view * model;
	mat3 normalMatrix = mat3(vec3(mv[0][0], mv[0][1], mv[0][2]),
		vec3(mv[1][0], mv[1][1], mv[1][2]),
		vec3(mv[2][0], mv[2][1], mv[2][2]));


	// Bind shader and set uniforms
	phongShader->Bind();
	phongShader->SetUniform("normalMatrix", normalMatrix);
	phongShader->SetUniform("lightPosition", lpos);
	phongShader->SetUniform("model", model);
	phongShader->SetUniform("view", view);
	phongShader->SetUniform("projection", projection);
	phongShader->SetUniform("materialProperties", material);
	phongShader->SetUniform("lightProperties", light);
	phongShader->SetUniform("shininess", shininess);
	phongShader->SetUniform("shrink", shrink);
	phongShader->SetUniform("explode", explode);
	phongShader->SetUniform("tesselate", tesselate);
	phongShader->SetUniform("black", 0);
	phongShader->Unbind();

	silhShader->Bind();
	silhShader->SetUniform("model", model);
	silhShader->SetUniform("view", view);
	silhShader->SetUniform("projection", projection);
	glLineWidth(10);
	silhShader->Unbind();

	object->Draw(phongShader, true, silhShader);

	// Bind shader for axes and set uniforms
	vertexColorShader->Bind();
	vertexColorShader->SetUniform("transform", projection * view);

	// Bind VAO for axes and draw
	axesVao->Bind(*vertexColorShader);
	glLineWidth(2);
	axesVao->Draw(GL_LINES);

	vertexColorShader->Unbind();
	axesVao->Unbind();

	// instead of glFlush, display the back buffer now
	glutSwapBuffers();

}