Post

Visualizzazione dei post da 2020

Sort Points by clockwise Angle

Immagine
    Points[4] = {...};     Point origin; ...     // Sort Points by Angles     for(int m=0; m<3; m++)         for (int i = m + 1; i < 4; i++)         {             if (GetClockwiseAngle(Points[i], origin) < GetClockwiseAngle(Points[m], origin);)             {                                SwapPoint(Points, i, m);                }         }         ... double GetClockwiseAngle(Point point, Point origin) {     double angle = 0.0;     angle = atan2(point.Y - origin.Y, point.X - origin.X) * 180 / M_PI;;     return angle; }

Middle point of a line segment

Immagine
A(x,y) B(x,y) MidAB.X = (A.X + B.X) / 2; MidAB.Y = (A.Y + B.Y) / 2;

Rotate Point Around Origin

//---------------------------------------------------------------------------- void RotatePointAroundOrigin(&Point, Point origin, double angle) {     float s = sin(angle);     float c = cos(angle);     // Translate point back to origin:     point.X -= origin.X;     point.Y -= origin.Y;     // Rotate point     float xnew = point.X * c - point.Y * s;     float ynew = point.X * s + point.Y * c;     // Translate point back:     point.X = xnew + origin.X;     point.Y = ynew + origin.Y; }

Angle between two points

//---------------------------------------------------------------------------- double CalculateAngle(Point point1, Point point2, Point origin) {     double angleToP1 = atan2((point1.X - origin.X), (point1.Y - origin.Y));     double angleToP2 = atan2((point2.X - origin.X), (point2.Y - origin.Y));     double angle = angleToP2 - angleToP1;     if (angle < 0) angle += (2 * vtkMath::Pi());         return angle; }

VTK Textured Map Plane + Image Data

Ref: https://vtk.org/Wiki/VTK/Examples/Cxx/Visualization/TextureMapPlane   Ref: https://vtk.org/Wiki/VTK/Examples/Cxx/Visualization/TextureMapImageData  ...    vtkImageCanvasSource2D *imageSource; vtkNEW(imageSource);     imageSource->SetScalarTypeToUnsignedChar();     imageSource->SetExtent(0, 10, 0, 10, 0, 0);     imageSource->SetNumberOfScalarComponents(3);     imageSource->SetDrawColor(127, 255, 100);     imageSource->FillBox(0, 10, 0, 10);     imageSource->SetDrawColor(20, 20, 20);     imageSource->DrawSegment(0, 0, 9, 9);     imageSource->DrawSegment(9, 0, 0, 9);     imageSource->Update();         texture->SetInput(imageSource->GetOutput());     // Create a plane     vtkPlaneSource *plane; vtkNEW(plane);     plane->SetCenter(0.0, 0.0, 0.0);     plane->SetNormal(0.0, 0.0, -1.0);     vtkPolyDataMapper *planeMapper; vtkNEW(planeMapper);     plane->GetOutput()->GetPointData()->SetTCoords(textureCoordinates);     planeMapper-&g

vtk textured polygon

Ref: https://vtk.org/Wiki/VTK/Examples/Cxx/Visualization/TextureMapQuad // Read the image which will be the texture vtkSmartPointer < vtkJPEGReader > jPEGReader = vtkSmartPointer < vtkJPEGReader >:: New (); jPEGReader -> SetFileName ( inputFilename . c_str () ); // Create a plane vtkSmartPointer < vtkPoints > points = vtkSmartPointer < vtkPoints >:: New (); points -> InsertNextPoint ( 0.0 , 0.0 , 0.0 ); points -> InsertNextPoint ( 1.0 , 0.0 , 0.0 ); points -> InsertNextPoint ( 1.0 , 1.0 , 0.0 ); points -> InsertNextPoint ( 0.0 , 2.0 , 0.0 ); vtkSmartPointer < vtkCellArray > polygons = vtkSmartPointer < vtkCellArray >:: New (); vtkSmartPointer < vtkPolygon > polygon = vtkSmartPointer < vtkPolygon >:: New (); polygon -> GetPointIds () -> SetNumberOfIds ( 4 ); //make a quad polygon -> GetPointIds () -> SetId ( 0 , 0 ); polygon -

Hello world - Progress Bar (Loading...)

Immagine
Vector2 m_Position = {100, 100}; Vector2 m_Size = {400, 20}; Vector2 m_ProgressBar_Size = m_Size; int m_Progress = 0;  // Update m_Progress  m_Progress_Rectangle.setPosition(m_Position);  m_ProgressBar_Size.x = (m_Size.x / 100)*m_Progress;  m_Progress_Rectangle.setSize( m_ProgressBar_Size );  print( "Loading...%d%" , m_Progress); 

Hello world - Game Loop

// Ver.1 - Easy Loop --------------------------------------------------- while( true ) {   processInput();   update();   render(); } // Ver. 2 - Add Time and FPS --------------------------------------------------- MS_PER_FRAME 16 //60 FPS == 16 millisecondi per frame   while( true ) {   double  start  =  getCurrentTime();   processInput();   update();   render();   sleep( start  +  MS_PER_FRAME  -  getCurrentTime ()); }