Transformation

To add scale, rotation and translation to a sample program:

Start with the project you created in Vector Load and Save.

  1. Add this local variable under L_INT nRet; in the WndProc function:

    VECTORPOINT Point; 

  2. Add these cases under the WM_COMMAND case:

    case WM_CHAR: 
    switch( wParam ) 
    { 
       case 'x': 
       case 'X': 
       case 'y': 
       case 'Y': 
       case 'z': 
       case 'Z': 
       // get current rotation value 
       L_VecGetRotation ( &Vector, &Point ); 
       Point.x += ( wParam == 'x' || wParam == 'X' ) ? 5.0 : 0; 
       Point.y += ( wParam == 'y' || wParam == 'Y' ) ? 5.0 : 0; 
       Point.z += ( wParam == 'z' || wParam == 'Z' ) ? 5.0 : 0; 
       // set new rotation value 
       L_VecSetRotation ( &Vector, &Point, NULL, NULL, 0 ); 
       InvalidateRect( hWnd, NULL, FALSE ); 
       break; 
        
       case '+': 
       case '-': 
       // get current scale value 
       L_VecGetScale ( &Vector, &Point ); 
       Point.x += ( wParam == '+' ) ? 0.1 : -0.1; 
       Point.y += ( wParam == '+' ) ? 0.1 : -0.1; 
       Point.z += ( wParam == '+' ) ? 0.1 : -0.1; 
       // set new scale value 
       L_VecSetScale ( &Vector, &Point, NULL, NULL, 0 ); 
       InvalidateRect( hWnd, NULL, FALSE ); 
       break; 
    } 
    break; 
     
    case WM_KEYDOWN: 
    switch( wParam ) 
    { 
       case VK_UP: 
       case VK_DOWN: 
       case VK_LEFT: 
       case VK_RIGHT: 
       // get current translation 
       L_VecGetTranslation ( &Vector, &Point ); 
       if( wParam == VK_LEFT ) Point.x -= 1.0; 
          if( wParam == VK_RIGHT ) Point.x += 1.0; 
          if( wParam == VK_UP ) Point.y += 1.0; 
          if( wParam == VK_DOWN ) Point.y -= 1.0; 
          // set new translation value 
          L_VecSetTranslation ( &Vector, &Point, NULL, 0 ); 
       InvalidateRect( hWnd, NULL, FALSE ); 
       break; 
    } 
    break; 

  3. Compile and run the demo.

  4. Select File/Open from the program menu. Browse to C:\LEADTOOLS21\Resources\Images\random.dxf and click OK.

  5. Now you should be able to rotate the vector drawing around any axis using the x, y and z keys on your keyboard and scale up and down using the + and keys.

Help Version 21.0.2021.4.7
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Vector C API Help