Ejemplo n.º 1
0
void Trackball::motion(int x, int y)
{
	GLfloat current_position[3], dx, dy, dz;

	if (tb_tracking == GL_FALSE)
		return;

	_tbPointToVector(x, y, tb_width, tb_height, current_position);

	/* calculate the angle to rotate by (directly proportional to the
		length of the mouse movement */
	dx = current_position[0] - tb_lastposition[0];
	dy = current_position[1] - tb_lastposition[1];
	dz = current_position[2] - tb_lastposition[2];
	tb_angle = 90.0f * sqrtf(dx * dx + dy * dy + dz * dz);

	/* calculate the axis of rotation (cross product) */
	tb_axis[0] = tb_lastposition[1] * current_position[2] - 
				tb_lastposition[2] * current_position[1];
	tb_axis[1] = tb_lastposition[2] * current_position[0] - 
				tb_lastposition[0] * current_position[2];
	tb_axis[2] = tb_lastposition[0] * current_position[1] - 
				tb_lastposition[1] * current_position[0];

	/* reset for next time */
	tb_lasttime = (int)(1000*clock()/CLOCKS_PER_SEC);
	tb_lastposition[0] = current_position[0];
	tb_lastposition[1] = current_position[1];
	tb_lastposition[2] = current_position[2];

	/* remember to draw new position */
	//glutPostRedisplay();
}
Ejemplo n.º 2
0
void tbMotion(int x, int y)
{
	GLfloat current_position[3], dx, dy, dz;
	
	assert(tb_button != -1);
	
	if (tb_tracking == GL_FALSE)
		return;
	
	_tbPointToVector(x, y, tb_width, tb_height, current_position);
	
	/* calculate the angle to rotate by (directly proportional to the
     length of the mouse movement */
	dx = current_position[0] - tb_lastposition[0];
	dy = current_position[1] - tb_lastposition[1];
	dz = current_position[2] - tb_lastposition[2];
	tb_angle = 90.0 * sqrt(dx * dx + dy * dy + dz * dz);
	
	/* calculate the axis of rotation (cross product) */
	tb_axis[0] = tb_lastposition[1] * current_position[2] - 
	tb_lastposition[2] * current_position[1];
	tb_axis[1] = tb_lastposition[2] * current_position[0] - 
	tb_lastposition[0] * current_position[2];
	tb_axis[2] = tb_lastposition[0] * current_position[1] - 
	tb_lastposition[1] * current_position[0];
	
	/* reset for next time */
	tb_lasttime = glutGet(GLUT_ELAPSED_TIME);
	tb_lastposition[0] = current_position[0];
	tb_lastposition[1] = current_position[1];
	tb_lastposition[2] = current_position[2];
	
	/* remember to draw new position */
	glutPostRedisplay();
}
Ejemplo n.º 3
0
void _tbStartMotion(int x, int y, int button, int time)
{
	assert(tb_button != -1);
	
	tb_tracking = GL_TRUE;
	tb_lasttime = time;
	_tbPointToVector(x, y, tb_width, tb_height, tb_lastposition);
}
Ejemplo n.º 4
0
void
_tbStartMotion(GLfloat x, GLfloat y, int button, int time)
{
	//printf("_tbStartMotion x%f y%f button%d time%d\n",x,y,button,time);
  assert(tb_button != -1);

  tb_tracking = GL_TRUE;
  tb_lasttime = time;
  _tbPointToVector(x, y, tb_width, tb_height, tb_lastposition);
}
Ejemplo n.º 5
0
void CTrackball::_tbStartMotion(int x, int y, int button, int time)
{
	tb_tracking = GL_TRUE;
	tb_lasttime = time;
	_tbPointToVector(x, y, tb_width, tb_height, tb_lastposition);
}