示例#1
0
void TestGLCanvas::OnPaint( wxPaintEvent& WXUNUSED(event) )
{
    // must always be here
    wxPaintDC dc(this);

    SetCurrent(*m_glRC);

    // Initialize OpenGL
    if (!m_gldata.initialized)
    {
        InitGL();
        ResetProjectionMode();
        m_gldata.initialized = true;
    }

    // Clear
    glClearColor( 0.3f, 0.4f, 0.6f, 1.0f );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    // Transformations
    glLoadIdentity();
    glTranslatef( 0.0f, 0.0f, -20.0f );
    GLfloat m[4][4];
    build_rotmatrix( m, m_gldata.quat );
    glMultMatrixf( &m[0][0] );

    m_renderer.Render();

    // Flush
    glFlush();

    // Swap
    SwapBuffers();
}
示例#2
0
void Pcb3D_GLCanvas::Redraw( void )
/**********************************/
{
    SetCurrent();

	InitGL();

    glMatrixMode(GL_MODELVIEW);    /* position viewer */
    /* transformations */
    GLfloat mat[4][4];
	glTranslatef(Draw3d_dx, Draw3d_dy, 0.0F);

    build_rotmatrix( mat, g_Parm_3D_Visu.m_Quat );
    glMultMatrixf( &mat[0][0] );

    glRotatef(g_Parm_3D_Visu.m_Rot[0], 1.0, 0.0, 0.0);
	glRotatef(g_Parm_3D_Visu.m_Rot[1], 0.0, 1.0, 0.0);
    glRotatef(g_Parm_3D_Visu.m_Rot[2], 0.0, 0.0, 1.0);

	if( m_gllist ) glCallList( m_gllist );
	else
	{
		m_gllist = CreateDrawGL_List();
//		m_gllist = DisplayCubeforTest();
	}

	glFlush();
	SwapBuffers();
 }
示例#3
0
文件: camera.cpp 项目: eunsol/proj3
void Camera::updateTransform()
{
	// Store the rotation matrix here.
	float matRot[4][4];

	// Determine rotation matrix from quaternion.
	build_rotmatrix(matRot, m_fQuat);

	// Normal camera direction
	Vec3f vDirection(0,0,m_fDolly);
	Vec3f vUpVector(0,1,0);

	// Apply the rotation matrix to determine the camera's new direction.
	Vec3f vNewDirection(
		matRot[0][0] * vDirection[0] + matRot[0][1] * vDirection[1] + matRot[0][2] * vDirection[2],
		matRot[1][0] * vDirection[0] + matRot[1][1] * vDirection[1] + matRot[1][2] * vDirection[2],
		matRot[2][0] * vDirection[0] + matRot[2][1] * vDirection[1] + matRot[2][2] * vDirection[2]
	);

	// Apply the rotation matrix to determine the camera's new up-vector.
	Vec3f vNewUpVector(
		matRot[0][0] * vUpVector[0] + matRot[0][1] * vUpVector[1] + matRot[0][2] * vUpVector[2],
		matRot[1][0] * vUpVector[0] + matRot[1][1] * vUpVector[1] + matRot[1][2] * vUpVector[2],
		matRot[2][0] * vUpVector[0] + matRot[2][1] * vUpVector[1] + matRot[2][2] * vUpVector[2]
	);

	// Update camera.
	m_vPosition = m_vLookAt + vNewDirection;
	m_vUpVector = vNewUpVector;

	// Not dirty anymore
	m_bDirtyTransform = false;
}
示例#4
0
void
drawBox(void)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

	glPushMatrix();

	glTranslatef(
		((stl_max_x(stl) + stl_min_x(stl))/2),
		((stl_max_y(stl) + stl_min_y(stl))/2),
		((stl_max_z(stl) + stl_min_z(stl))/2));


	glScalef(zoom, zoom, zoom);

        GLfloat rot_matrix[4][4];
        build_rotmatrix(rot_matrix, rot_cur_quat);
        glMultMatrixf(&rot_matrix[0][0]);

	glTranslatef(
		-((stl_max_x(stl) + stl_min_x(stl))/2),
		-((stl_max_y(stl) + stl_min_y(stl))/2),
		-((stl_max_z(stl) + stl_min_z(stl))/2));

	glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular );
	glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

        glCallList(model);

        glPopMatrix();

	glFlush();
	glutSwapBuffers();
}
示例#5
0
gint redrawGL2PS()
{
	GLdouble m[4][4];
	GtkWidget *widget = GLArea;
	if(!GTK_IS_WIDGET(widget)) return TRUE;
	if(!GTK_WIDGET_REALIZED(widget)) return TRUE;

    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
	addFog();
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	set_background_color();

	mYPerspective(45,(GLdouble)widget->allocation.width/(GLdouble)widget->allocation.height,1,100);
    	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	if(optcol==-1) drawChecker();

    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
	if(perspective)
		mYPerspective(Zoom,(GLdouble)widget->allocation.width/(GLdouble)widget->allocation.height,zNear,zFar);
	else
	{
	  	gdouble fw = (GLdouble)widget->allocation.width/(GLdouble)widget->allocation.height;
	  	gdouble fh = 1.0;
		glOrtho(-fw,fw,-fh,fh,-1,1);
	}

    	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	if(perspective)
		glTranslatef(Trans[0],Trans[1],Trans[2]);
	else
	{
		 glTranslatef(Trans[0]/10,Trans[1]/10,0);
		 glScalef(1/Zoom*2,1/Zoom*2,1/Zoom*2);
	}
	SetLight();

	build_rotmatrix(m,Quat);
	glMultMatrixd(&m[0][0]);

	redrawGeometry();
	redrawSurfaces();
	redrawCell();
	redrawContours();
	redrawPlanesMapped();
	if(get_show_symbols() || get_show_numbers() || get_show_charges()) showLabelSymbolsNumbersCharges();
	if(get_show_dipole()) showLabelDipole();
	if(get_show_distances()) showLabelDistances();
	if(get_show_axes()) showLabelAxes();
	if(get_show_axes()) showLabelPrincipalAxes();
	showLabelTitle(GLArea->allocation.width,GLArea->allocation.height);

	/* Swap backbuffer to front */
	glFlush();

	return TRUE;
}
示例#6
0
void rotateBy(float axis[3], float phi) {
    GLfloat m[4][4];
    float q[4] = {0};
    axis_to_quat(axis, RAD(phi), q);
    build_rotmatrix(m, q);
    glMultMatrixf(&m[0][0]);
}
示例#7
0
文件: main.c 项目: behnam/lfptools
static void
display()
{
    GLfloat mat[4][4];

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glEnable(GL_DEPTH_TEST);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    // camera & rotate
    gluLookAt(view_org[0], view_org[1], view_org[2],
          view_tgt[0], view_tgt[1], view_tgt[2],
          0.0, 1.0, 0.0);

    build_rotmatrix(mat, curr_quat);
    glMultMatrixf(&mat[0][0]);

    glBindTexture(GL_TEXTURE_2D, gTexIDs[curr_layer]);

    draw_mesh();

    //glBegin(GL_POLYGON);
    //    glTexCoord2f(0 , 0); glVertex2f(-0.9 , -0.9);
    //    glTexCoord2f(0 , 1); glVertex2f(-0.9 , 0.9);
    //    glTexCoord2f(1 , 1); glVertex2f(0.9 , 0.9);
    //    glTexCoord2f(1 , 0); glVertex2f(0.9 , -0.9);
    //glEnd();

    glutSwapBuffers();
}
示例#8
0
文件: gl_window.c 项目: cjac/jenkara
void
gl_window_orient_window(GtkGLArea *glarea)
{
  gl_window_info *info = gtk_object_get_data(GTK_OBJECT(glarea), "info");
  GLfloat median;
  float m[4][4];

  if (gtk_gl_area_make_current(GTK_GL_AREA(glarea))){

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glMatrixMode(GL_PROJECTION);

    if(info->orientation == ORIENTATION_3D ||
       info->orientation == ORIENTATION_TEXTURE ){

      glMatrixMode(GL_PROJECTION);
      glFrustum( -0.0005 * info->aspect_ratio, 0.0005 * info->aspect_ratio,
		 -0.0005 , 0.0005,
		 0.001, 1000
		 );

    }else{
      if(info->x_median >= info->y_median)
	median = info->x_median;
      else
	median = info->y_median;


      glOrtho(-1 * info->x_median, info->x_median,      // left, right
	      -1 * info->y_median, info->y_median,      // bottom, top
	      median * -3, median * 3                   // near, far
	      );
    }

    switch(info->orientation)
      {

      case ORIENTATION_FRONT:	break;
      case ORIENTATION_3D:
      case ORIENTATION_TEXTURE:
	glMatrixMode(GL_MODELVIEW);
	glTranslatef(0,0,-1 * info->zoom);

	build_rotmatrix(m, info->quat);
	glMultMatrixf(&m[0][0]);
	break;
      case ORIENTATION_TOP:	glRotatef(-90, 1,0,0);	break;
      case ORIENTATION_BOTTOM:	glRotatef( 90, 1,0,0);	break;
      case ORIENTATION_LEFT:	glRotatef(90, 0,1,0);	break;
      case ORIENTATION_RIGHT:	glRotatef(-90, 0,1,0);	break;
      case ORIENTATION_BACK:	glRotatef(180, 0,1,0);	break;
      default: break;
      }

  }/*if(gtk_gl_area_make_current(glarea))*/
}
示例#9
0
/* Execute the rotations current encapsulated in the trackball_state:
   this does something analagous to glRotatef().
 */
void
gltrackball_rotate (trackball_state *ts)
{
  GLfloat m[4][4];
  build_rotmatrix (m, ts->q);
  glMultMatrixf (&m[0][0]);
}
示例#10
0
文件: main.cpp 项目: aashish24/myexp
void RenderScenePass()
{
   // We can't simply call this to clear so we take another approach.
   // This is done before this function is called.
   //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glClear(GL_DEPTH_BUFFER_BIT);

   glLoadIdentity();
   glTranslatef(0, 0, -2.5);

   glPushMatrix();
   GLfloat m[4][4];
   build_rotmatrix(m, _gCurQuat);
   glMultMatrixf(&m[0][0]);
   if (_gScalingFactor == 1.0) {
     glDisable(GL_NORMALIZE);
   } else {
     glEnable(GL_NORMALIZE);
   }
   glScalef(_gScalingFactor, _gScalingFactor, _gScalingFactor);
   _gNewModel = 0;

   glColor3f(1.0f, 1.0f, 1.0f); DrawModel(_gModel);
   glPopMatrix();
}
示例#11
0
void transform()
{
  float fnear = 0.01f;
  float ffar = 10.0f;
  float fov = 45;
  float aspect = (float)windowWidth / (float)windowHeight;
  glm::mat4 projMX, modelMX, viewMX;
  glm::mat4 modelInvTranspMX;

  projMX = glm::perspective(fov, aspect, fnear, ffar);
  viewMX = glm::mat4(1.0f);
  modelMX = glm::translate(glm::mat4(1.0f), glm::vec3(modelTranslation[0],
						      modelTranslation[1], 
						      modelTranslation[2]));
  modelInvTranspMX = glm::transpose(glm::inverse(modelMX));

  glm::mat4 m;
  build_rotmatrix(m, curquat);
  modelMX = glm::mat4(modelMX*m);

  glUniformMatrix4fv(glGetUniformLocation(program, "model_mat"),
		     1, GL_FALSE, glm::value_ptr(modelMX));
  glUniformMatrix4fv(glGetUniformLocation(program, "view_mat"),
		     1, GL_FALSE, glm::value_ptr(viewMX));
  glUniformMatrix4fv(glGetUniformLocation(program, "proj_mat"),
		     1, GL_FALSE, glm::value_ptr(projMX));
  glUniformMatrix4fv(glGetUniformLocation(program, "model_it_mat"),
		     1, GL_FALSE, glm::value_ptr(modelInvTranspMX));
}
示例#12
0
void glt_stream_server_t::build_trans_matrix() {
	glLoadIdentity();
    
	glTranslatef( xcam, ycam, zcam);

    GLfloat m[4][4];
    build_rotmatrix( m, quat );
    glMultMatrixf( &m[0][0] );
}
示例#13
0
void
tbMatrix(void)
{
  GLfloat m[4][4];

  assert(tb_button != -1);
  build_rotmatrix(m, curquat);
  glMultMatrixf(&m[0][0]);
}
示例#14
0
static void Display( void )
{
   GLfloat rot[4][4];

   glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

   glPushMatrix();
   build_rotmatrix(rot, CurQuat);
   glMultMatrixf(&rot[0][0]);

   /* First pass: diffuse lighting with base texture */
   glMaterialfv(GL_FRONT, GL_DIFFUSE, Diffuse);
   glMaterialfv(GL_FRONT, GL_SPECULAR, Black);
   glEnable(GL_TEXTURE_2D);
   glBindTexture(GL_TEXTURE_2D, BaseTexture);
   glCallList(Object);

   /* Second pass: specular lighting with reflection texture */
   glEnable(GL_POLYGON_OFFSET_FILL);
   glBlendFunc(GL_ONE, GL_ONE);  /* add */
   glEnable(GL_BLEND);
   glMaterialfv(GL_FRONT, GL_DIFFUSE, Black);
   glMaterialfv(GL_FRONT, GL_SPECULAR, White);
   if (DoSpecTexture) {
      glBindTexture(GL_TEXTURE_2D, SpecularTexture);
      glEnable(GL_TEXTURE_GEN_S);
      glEnable(GL_TEXTURE_GEN_T);
   }
   else {
      glDisable(GL_TEXTURE_2D);
   }
   glCallList(Object);
   glDisable(GL_TEXTURE_GEN_S);
   glDisable(GL_TEXTURE_GEN_T);
   glDisable(GL_BLEND);
   glDisable(GL_POLYGON_OFFSET_FILL);

   glPopMatrix();

   glutSwapBuffers();

   if (Animate) {
      GLint t = glutGet(GLUT_ELAPSED_TIME);
      Frames++;
      if (t - T0 >= 5000) {
         GLfloat seconds = (t - T0) / 1000.0;
         GLfloat fps = Frames / seconds;
         printf("%d frames in %g seconds = %g FPS\n", Frames, seconds, fps);
         fflush(stdout);
         T0 = t;
         Frames = 0;
      }
   }
}
示例#15
0
static gboolean
draw(GtkWidget *widget,
     cairo_t   *cr,
     gpointer   data)
{
  GdkGLContext *glcontext = gtk_widget_get_gl_context(widget);
  GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(widget);

  GLfloat m[4][4];
  mesh_info *info = (mesh_info*)g_object_get_data(G_OBJECT(widget), "mesh_info");

  /*** OpenGL BEGIN ***/
  if (!gdk_gl_drawable_gl_begin(gldrawable, glcontext))
    goto NO_GL;

  /* basic initialization */
  if (info->do_init == TRUE) {
    initgl();
    info->do_init = FALSE;
  }

  /* view */
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(info->zoom, VIEW_ASPECT, 1,100);
  glMatrixMode(GL_MODELVIEW);

  /* draw object */
  glClearColor(.3,.4,.6,1);
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

  glLoadIdentity();
  glTranslatef(0,0,-30);
  add_quats(info->dquat, info->quat, info->quat);
  build_rotmatrix(m,info->quat);
  glMultMatrixf(&m[0][0]);

  lw_object_show(info->lwobject);

  /* swap backbuffer to front */
  if (gdk_gl_drawable_is_double_buffered(gldrawable))
    gdk_gl_drawable_swap_buffers(gldrawable);
  else
    glFlush();

  gdk_gl_drawable_gl_end(gldrawable);
  /*** OpenGL END ***/

 NO_GL:

  return TRUE;
}
示例#16
0
void
recalcModelView(void)
{
      GLfloat m[4][4];		/*the matrix*/

      glPopMatrix();
      glPushMatrix();

      build_rotmatrix(m, curquat);
      glMultMatrixf(&m[0][0]);
      glScalef(glb_scalefactor, glb_scalefactor, glb_scalefactor);
      glb_newmodel=0;
}
示例#17
0
void resetModelView() {
  GLfloat m[4][4];
  glPopMatrix();
  glPushMatrix();
  build_rotmatrix(m, empty);
  glMultMatrixf(&m[0][0]);
  if (scalefactor == 1.0) {
    glDisable(GL_NORMALIZE);
  } else {
    glEnable(GL_NORMALIZE);
  }
  glScalef(scalefactor, scalefactor, scalefactor);
}
示例#18
0
void
recalcModelView(void)
{
  GLfloat m[4][4];

  glPopMatrix();
  glPushMatrix();
  build_rotmatrix(m, curquat);
  glMultMatrixf(&m[0][0]);
  glScalef(scalefactor, scalefactor, scalefactor);
  glTranslatef(-8, -8, -bodyWidth / 2);
  newModel = 0;
}
示例#19
0
文件: trip.c 项目: gwowen/seismicunix
void
recalcModelView(void)
{
	GLfloat m[4][4];		/*the matrix*/

	/* The pop and push are useful */
	glPopMatrix();
	glPushMatrix();

	build_rotmatrix(m, curquat);
	glMultMatrixf(m[0]);
	glScalef(glb_scalefactor, glb_scalefactor, glb_scalefactor);
	glb_newModel=0;
}
示例#20
0
// FUNCTION ======	camera 
void camera (){
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
	glOrtho      ( -zoom*ASPECT_RATIO, zoom*ASPECT_RATIO, -zoom, zoom, -VIEW_DEPTH, +VIEW_DEPTH );
	//glRotatef(	45,   1, 2, 3);

	glMatrixMode (GL_MODELVIEW);
	float camMatrix[4][4];
	build_rotmatrix (camMatrix, qCamera );
	//printf( "qCamera: %f %f %f %f qCameraOld: %f %f %f %f mouse: %f %f \n", qCamera[0], qCamera[1], qCamera[2], qCamera[3],  qCameraOld[0], qCameraOld[1], qCameraOld[2], qCameraOld[3],     mouse_begin_x, mouse_begin_y  );
	//glTranslatef (shift.x, shift.y, 0);
	//glMultMatrixf (&camMatrix[0][0]);
	glLoadMatrixf(&camMatrix[0][0]);
}
示例#21
0
void display(void)
{
	GLfloat m[4][4];

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glPushMatrix();
	build_rotmatrix(m, curquat);
	glMultMatrixf(&m[0][0]);

	draw_cube();

	glPopMatrix();

	glutSwapBuffers();
}
示例#22
0
void camera(){
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
	glOrtho      ( -zoom*ASPECT_RATIO, zoom*ASPECT_RATIO, -zoom, zoom, -VIEW_DEPTH, +VIEW_DEPTH );

	glMatrixMode (GL_MODELVIEW);
	float camMatrix[4][4];
	build_rotmatrix (camMatrix, qCamera );
	glLoadMatrixf(&camMatrix[0][0]);


/*
	glMatrixMode (GL_MODELVIEW);
	glLoadIdentity();
	glTranslatef( -1.5f+(mouseX*0.005-0.5), 0.0f-(mouseY*0.005-0.5), -6.0f );
*/
}
示例#23
0
void recalcModelView(void)
{
    GLdouble m[4][4];

    glPopMatrix();
    glPushMatrix();
    build_rotmatrix(m, curquat);
    glMultMatrixd(&m[0][0]);
    if(scalefactor == 1.0) {
        glDisable(GL_NORMALIZE);
    }
    else {
        glEnable(GL_NORMALIZE);
    }
    glScalef(scalefactor, scalefactor, scalefactor);
//  glTranslatef(-8, -8, -bodyWidth / 2);
    newModel = 0;
}
示例#24
0
void TestGLCanvas::OnPaint( wxPaintEvent& WXUNUSED(event) )
{
    /* must always be here */
    wxPaintDC dc(this);

#ifndef __WXMOTIF__
    if (!GetContext()) return;
#endif

    SetCurrent();

    // Initialize OpenGL
    if (info.do_init)
    {
        InitGL();
        info.do_init = false;
    }

    // View
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluPerspective( info.zoom, VIEW_ASPECT, 1.0, 100.0 );
    glMatrixMode( GL_MODELVIEW );

    // Clear
    glClearColor( 0.3f, 0.4f, 0.6f, 1.0f );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    // Transformations
    GLfloat m[4][4];
    glLoadIdentity();
    glTranslatef( 0.0f, 0.0f, -30.0f );
    build_rotmatrix( m,info.quat );
    glMultMatrixf( &m[0][0] );

    // Draw object
    lw_object_show( info.lwobject );

    // Flush
    glFlush();

    // Swap
    SwapBuffers();
}
示例#25
0
static gboolean
draw(GtkWidget *widget,
     cairo_t   *cr,
     gpointer   data)
{
  GLfloat m[4][4];
  mesh_info *info = (mesh_info*)g_object_get_data(G_OBJECT(widget), "mesh_info");

  /*** OpenGL BEGIN ***/
  if (!gtk_widget_begin_gl (widget))
    goto NO_GL;

  /* basic initialization */
  if (info->do_init == TRUE) {
    initgl();
    info->do_init = FALSE;
  }

  /* view */
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(info->zoom, VIEW_ASPECT, 1,100);
  glMatrixMode(GL_MODELVIEW);

  /* draw object */
  glClearColor(.3,.4,.6,1);
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

  glLoadIdentity();
  glTranslatef(0,0,-30);
  add_quats(info->dquat, info->quat, info->quat);
  build_rotmatrix(m,info->quat);
  glMultMatrixf(&m[0][0]);

  lw_object_show(info->lwobject);

  gtk_widget_end_gl(widget, TRUE);
  /*** OpenGL END ***/

 NO_GL:

  return TRUE;
}
示例#26
0
void
drawAll(void)
{
  int i, j;
  int piece;
  char done[PIECES + 1];
  float m[4][4];

  build_rotmatrix(m, curquat);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glTranslatef(0, 0, -10);
  glMultMatrixf(&(m[0][0]));
  glRotatef(180, 0, 0, 1);

  if (depth) {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  } else {
    glClear(GL_COLOR_BUFFER_BIT);
  }
  for (i = 1; i <= PIECES; i++) {
    done[i] = 0;
  }
  glLoadName(0);
  drawContainer();
  for (i = 0; i < HEIGHT; i++) {
    for (j = 0; j < WIDTH; j++) {
      piece = thePuzzle[i][j];
      if (piece == 0)
        continue;
      if (done[piece])
        continue;
      done[piece] = 1;
      glLoadName(piece);
      if (piece == movingPiece) {
        drawBox(piece, move_x, move_y);
      } else {
        drawBox(piece, j, i);
      }
    }
  }
}
示例#27
0
static void
Redisplay(void)
{
   GLfloat rot[4][4];
   GLfloat trans[16], mvp[16];

   glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

   /* Build the modelview * projection matrix */
   build_rotmatrix(rot, CurQuat);
   mat_translate(trans, 0, 0, -10);
   mat_multiply(mvp, trans, (GLfloat *) rot);
   mat_multiply(mvp, Projection, mvp);
   /* Set the MVP matrix */
   glUniformMatrix4fv(uModelViewProj, 1, GL_FALSE, (float *) mvp);

   /* Draw */
   glDrawArrays(GL_TRIANGLES, 0, 3);

   glutSwapBuffers();
}
示例#28
0
/* Execute the rotations current encapsulated in the trackball_state:
   this does something analagous to glRotatef().
 */
void
gltrackball_rotate (trackball_state *ts)
{
  GLfloat m[4][4];
  if (!ts->button_down_p &&
      (ts->ddx != 0 ||
       ts->ddy != 0))
    {
      /* Apply inertia: keep moving in the same direction as the last move. */
      gltrackball_track_1 (ts, 
                           ts->x + ts->dx,
                           ts->y + ts->dy,
                           ts->ow, ts->oh);

      /* Dampen inertia: gradually stop spinning. */
      gltrackball_dampen (&ts->dx, &ts->ddx);
      gltrackball_dampen (&ts->dy, &ts->ddy);
    }

  build_rotmatrix (m, ts->q);
  glMultMatrixf (&m[0][0]);
}
示例#29
0
void rotate(int by, float axis[3][3], int phi) {
    GLfloat m[4][4];
    float q[4] = {0};
    int i;
    for (i=0; i<4; i++) {
        q[i] = 0;
    }
    axis_to_quat(axis[by],RAD(phi), q);
    build_rotmatrix(m, q);
    
    for (i=0; i<3; i++) {
        if (i != by) {
            multiply(m, axis[i], axis[i]);
        }
    }
    
    for (i=0; i<NV; i++) {
        multiply(m, vertexes[i], vertexes[i]);
    }
    for (i=0; i<4; i++) {
        multiply(m, originalVertex[i], originalVertex[i]);
    }
}
示例#30
0
/*
 * The callback function when a redraw has been requested
 */
void DisplayFunc()
{
	// Create the screen for both colour and depth values
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// The modelview matrix is pushed before drawing the scene
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();

	// Set up the trackball transformation
	float rotmatrix[4][4];
	build_rotmatrix(rotmatrix, quat);
	glMultMatrixf(&rotmatrix[0][0]);

	// Draw the scene from the display list
	if (current_display == DISPLAY_TEAPOT)
		glCallList(teapot_list);
	else {


		/*
		 *
		 * Draw your hierarchical tin robot model here
		 *
		 */

		glColor3f(0.0, 0.0, 1.0);
		DrawBox(400, 400, 400);


	}

	glPopMatrix();

	// Redraw the screen by swapping the buffer
	glutSwapBuffers();
}