Example #1
0
Vector RenderableView::GetScreenPoint(const Vector& p) const
{
	float distance = m_WindowSize / 2.0f / (float)tan( m_FieldOfView/2.0f );

	Matrix matrix = Matrix::translation(-m_Target);
	matrix.preMultiplication(m_Orientation.inverse().buildMatrix());
	matrix.preMultiplication(Matrix::translation(0.0f, 0.0f, -distance));

	Vector result = matrix*p;

	result[0] = result[0] * distance / -result[2];
	result[1] = result[1] * distance / -result[2];
	result[2] = 0.0;
	result[3] = 1.0;

	result[0] = result[0] / (m_WindowSize / (m_Height<m_Width?m_Height: m_Width));
	result[1] = result[1] / (m_WindowSize / (m_Height<m_Width?m_Height: m_Width));
	result[0] = (float)result[0]+(float)m_Width/2.0f;
	result[1] = (float)result[1]+(float)m_Height/2.0f;
	result[1] = InvertY(result[1]);


	return result;

}
Example #2
0
/* 
 * DrawSceneOutline() 
 *	- draws scene outline within main drawing area
 *
 * PARAMETERS
 *	data	- pointer to MyProgram structure
 *
 * RETURNS
 *	nothing
 */
void
DrawSceneOutline(MyProgram *data)
{
   XPoint	points[5];

   points[0].x = DEFAULT_SCENE_BOT_LEFT_X;
   points[0].y = InvertY(DEFAULT_SCENE_BOT_LEFT_Y);

   points[1].x = DEFAULT_SCENE_BOT_LEFT_X;
   points[1].y = InvertY(DEFAULT_SCENE_TOP_RIGHT_Y);

   points[2].x = DEFAULT_SCENE_TOP_RIGHT_X;
   points[2].y = InvertY(DEFAULT_SCENE_TOP_RIGHT_Y);

   points[3].x = DEFAULT_SCENE_TOP_RIGHT_X;
   points[3].y = InvertY(DEFAULT_SCENE_BOT_LEFT_Y);

   points[4].x = DEFAULT_SCENE_BOT_LEFT_X;
   points[4].y = InvertY(DEFAULT_SCENE_BOT_LEFT_Y);

   DrawPolyline( &points[0], 5 );
}
Example #3
0
/* 
 * DrawSceneTextArea() 
 *	- updates scene text area within main drawing area
 *
 * PARAMETERS
 *	data	- pointer to MyProgram structure
 *
 * RETURNS
 *	nothing
 */
void
DrawSceneTextArea(MyProgram *data)
{
   pointType	left_pt, right_pt;

   int		height;
   XFont	font;

   int 		vert_spacing, text_offset;


   font = GetWidgetFont( data->draw_area_widget );
   height = FontHeight( font );

   vert_spacing = 2 * DEFAULT_SCENE_TEXT_SPACING;

   text_offset = DEFAULT_SCENE_TEXT_SPACING;

   left_pt.x = DEFAULT_SCENE_BOT_LEFT_X;
   left_pt.y = height + DEFAULT_SCENE_BOT_LEFT_Y + vert_spacing;

   right_pt.x = DEFAULT_SCENE_TOP_RIGHT_X;
   right_pt.y = left_pt.y;

   DrawLine( left_pt.x, InvertY(left_pt.y), right_pt.x, InvertY(right_pt.y) );
   DrawText( "Sound:", (left_pt.x+text_offset), 
		InvertY((left_pt.y-text_offset-height)) );

   left_pt.y += (height + vert_spacing);
   right_pt.y = left_pt.y;

   DrawLine( left_pt.x, InvertY(left_pt.y), right_pt.x, InvertY(right_pt.y) );
   DrawText( "Dialog:", (left_pt.x+text_offset), 
		InvertY((left_pt.y-text_offset-height)) );

   left_pt.y += (height + vert_spacing);
   right_pt.y = left_pt.y;

   DrawLine( left_pt.x, InvertY(left_pt.y), right_pt.x, InvertY(right_pt.y) );
   DrawText( "Action:", (left_pt.x+text_offset), 
		InvertY((left_pt.y-text_offset-height)) );

}
Ray OrthographicView::GetPickRay(int x, int y) const
{
	y = InvertY(y);
	float fx = (float)x-(float)m_Width/2.0f;
	float fy = (float)y-(float)m_Height/2.0f;
	float objectDx = fx * m_WindowSize / (m_Height<m_Width?m_Height: m_Width);
	float objectDy = fy * m_WindowSize / (m_Height<m_Width?m_Height: m_Width);

	Matrix matrix = Matrix::translation(0.0f, 0.0f, 200.0f);
	matrix.preMultiplication(m_Orientation.buildMatrix());
	matrix.preMultiplication(Matrix::translation(m_Target));

	return Ray(matrix*Vector(objectDx,objectDy,0.0f,1.0f), matrix*Vector(0.0f,0.0f,-1.0f,0.0f));
}
Example #5
0
/***********************************************************************

  DrawLinks() - this function draws the current link hierarchy as stated 
		in the data structure 'data'.

***********************************************************************/
int 
DrawLinks(MyProgram *data)
{
   int i;

   if (data->redraw == TRUE)
      SetDrawMode(SANE_XOR);

   /*  draw each link 
    */
   for (i = 0; i < data->num_links; i++)
      DrawLine(data->links[i].start.x, InvertY(data->links[i].start.y), 
		data->links[i].visend.x, InvertY(data->links[i].visend.y));

   /*  draw end effector
    */
   switch(data->end_effect.type) {
      case ENDEFF_SQUARE:
         DrawFilledBox(data->end_effect.center.x, 
			InvertY(data->end_effect.center.y),
			ENDEFF_SIZE, ENDEFF_SIZE);
         break;
      case ENDEFF_CIRCLE:
         DrawFilledArc(data->end_effect.center.x, 
			InvertY(data->end_effect.center.y),
			ENDEFF_SIZE, ENDEFF_SIZE, 0, 360);
         break;
      case ENDEFF_TRIANGLE:
         break;
      default:
         break;
   }

   SetDrawMode(GXcopy);

   return(0);
} /* end of DrawLinks() */
Example #6
0
Ray RenderableView::GetPickRay(int x, int y) const
{
	y = InvertY(y);
	float fx = (float)x-(float)m_Width/2.0f;
	float fy = (float)y-(float)m_Height/2.0f;
	float objectDx = fx * m_WindowSize / (m_Height<m_Width?m_Height: m_Width);
	float objectDy = fy * m_WindowSize / (m_Height<m_Width?m_Height: m_Width);

	float distance;

	distance = m_WindowSize / 2.0f / (float)tan( m_FieldOfView/2.0f );

	Matrix matrix = Matrix::translation(0.0f, 0.0f, distance);
	matrix.preMultiplication(m_Orientation.buildMatrix());
	matrix.preMultiplication(Matrix::translation(m_Target));

	return Ray(matrix*Vector(0.0f,0.0f,0.0f,1.0f), matrix*Vector(objectDx,objectDy,-distance,0.0f));
}
Example #7
0
/***********************************************************************

  HandleButton() - this function determines if the end effector of the 
		structure has been grabbed or not.

***********************************************************************/
int 
HandleButton(MyProgram *data)
{
   pointType curr_p;

   curr_p.x = data->curr_mousx;
   curr_p.y = InvertY(data->curr_mousy);

   if (data->button_state == BUTTON_DOWN)  /* check if actually grabbed */

      if (PointInBox(curr_p, data->end_effect.extent) == TRUE) {
         data->endgrabbed = TRUE;
         printf("end effector was grabbed\n");
      }
      else
         data->endgrabbed = FALSE;

   else
      return(1);			/* error, unknown button state */
   
   return(0);
} /* end of HandleButton() */
Example #8
0
/* 
 * DrawHeader() 
 *	- draws header label within main drawing area
 *
 * PARAMETERS
 *	data	- pointer to MyProgram structure
 *
 * RETURNS
 *	nothing
 */
void
DrawHeader(MyProgram *data)
{
   pointType	label_pos;

   int		width, height;
   XFont	font;


   font = GetWidgetFont( data->draw_area_widget );
   height = FontHeight( font );

   label_pos.x = DEFAULT_PROJ_LABEL_X;
   label_pos.y = DEFAULT_PROJ_LABEL_y;
   DrawText("Project:", label_pos.x, InvertY(label_pos.y));

   width = TextWidth( font, "Project:" );
   label_pos.x += (width + DEFAULT_LABEL_SPACING1);
   DrawText(data->proj.projname_str, label_pos.x, InvertY(label_pos.y));

   width = TextWidth( font, data->proj.projname_str );
   label_pos.x += (width + DEFAULT_LABEL_SPACING2);
   DrawText("Act:", label_pos.x, InvertY(label_pos.y));

   width = TextWidth( font, "Act:" );
   label_pos.x += (width + DEFAULT_LABEL_SPACING1);
   DrawText("1", label_pos.x, InvertY(label_pos.y));

   width = TextWidth( font, "1" );
   label_pos.x += (width + DEFAULT_LABEL_SPACING2);
   DrawText("Scene:", label_pos.x, InvertY(label_pos.y));

   width = TextWidth( font, "Scene:" );
   label_pos.x += (width + DEFAULT_LABEL_SPACING1);
   DrawText("1", label_pos.x, InvertY(label_pos.y));

}