Advertisement
Shaun_B

CPP classes using GDI+ in VC++

Dec 18th, 2011
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 17.44 KB | None | 0 0
  1. //CPP files first...
  2. //WeekTwoWork.cpp is our main thingy thing:
  3. // WeekTwoWork.cpp : Defines the entry point for the application.
  4. //
  5. #include                "stdafx.h"
  6. #include                "WeekTwoWork.h"
  7. #include                <Gdiplus.h>
  8. #include                "AppEngine.h"
  9. #include                "Rasterizer.h"
  10. #include                "Vertex.h"
  11. using namespace         Gdiplus;
  12. #pragma comment         (lib, "Gdiplus.lib")
  13. #define MAX_LOADSTRING  100
  14. #define EXIT_SUCCESS    0
  15. #define WINDOW_WIDTH    640
  16. #define WINDOW_HEIGHT   480
  17. // Global Variables:
  18. HWND                    hWnd;
  19. HDC                     hdc;
  20. HINSTANCE               hInst;                                      // current instance
  21. TCHAR                   szTitle[MAX_LOADSTRING];                    // The title bar text
  22. TCHAR                   szWindowClass[MAX_LOADSTRING];              // the main window class name
  23. AppEngine appEngine;
  24. // Forward declarations of functions included in this code module:
  25. ATOM                MyRegisterClass(HINSTANCE hInstance);
  26. BOOL                InitInstance(HINSTANCE, int);
  27. LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
  28. INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
  29. int APIENTRY _tWinMain(HINSTANCE hInstance,
  30.                      HINSTANCE hPrevInstance,
  31.                      LPTSTR    lpCmdLine,
  32.                      int       nCmdShow)
  33. {
  34.     UNREFERENCED_PARAMETER(hPrevInstance);
  35.     UNREFERENCED_PARAMETER(lpCmdLine);
  36.     // TODO: Place code here.
  37.     MSG                     msg;
  38.     HACCEL                  hAccelTable;
  39.     GdiplusStartupInput     gdiplusStartupInput;
  40.     ULONG_PTR               gdiplusToken;
  41.     GdiplusStartup          (&gdiplusToken, &gdiplusStartupInput, NULL);
  42.     // Initialize global strings
  43.     LoadString              (hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  44.     LoadString              (hInstance, IDC_WEEKTWOWORK, szWindowClass, MAX_LOADSTRING);
  45.     MyRegisterClass         (hInstance);
  46.     // Perform application initialization:
  47.     if (!InitInstance (hInstance, nCmdShow))
  48.     {
  49.         return FALSE;
  50.     }
  51.     hAccelTable=            LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WEEKTWOWORK));
  52.     appEngine.Initialise(hWnd, hdc);
  53.     // Main message loop:
  54.     while (true)
  55.     {
  56.             if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  57.             {
  58.                     if (msg.message==WM_QUIT)
  59.                     {
  60.                         break;
  61.                     }
  62.                     if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  63.                     {
  64.                         TranslateMessage(&msg);
  65.                         DispatchMessage(&msg);
  66.                     }
  67.             }
  68.             appEngine.Process();
  69.     }
  70.     appEngine.Shutdown();
  71.     GdiplusShutdown (gdiplusToken);
  72.     return (int) msg.wParam;
  73. }
  74. //
  75. //  FUNCTION: MyRegisterClass()
  76. //
  77. //  PURPOSE: Registers the window class.
  78. //
  79. //  COMMENTS:
  80. //
  81. //    This function and its usage are only necessary if you want this code
  82. //    to be compatible with Win32 systems prior to the 'RegisterClassEx'
  83. //    function that was added to Windows 95. It is important to call this function
  84. //    so that the application will get 'well formed' small icons associated
  85. //    with it.
  86. //
  87. ATOM MyRegisterClass(HINSTANCE hInstance)
  88. {
  89.     WNDCLASSEX              wcex;
  90.     wcex.cbSize=            sizeof(WNDCLASSEX);
  91.     wcex.style=             CS_HREDRAW | CS_VREDRAW;
  92.     wcex.lpfnWndProc=       WndProc;
  93.     wcex.cbClsExtra=        0;
  94.     wcex.cbWndExtra=        0;
  95.     wcex.hInstance=         hInstance;
  96.     wcex.hIcon=             LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WEEKTWOWORK));
  97.     wcex.hCursor=           LoadCursor(NULL, IDC_ARROW);
  98.     wcex.hbrBackground=     (HBRUSH)(COLOR_WINDOW+1);
  99.     wcex.lpszMenuName=      MAKEINTRESOURCE(IDC_WEEKTWOWORK);
  100.     wcex.lpszClassName=     szWindowClass;
  101.     wcex.hIconSm=           LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  102.     return RegisterClassEx(&wcex);
  103. }
  104. //
  105. //   FUNCTION: InitInstance(HINSTANCE, int)
  106. //
  107. //   PURPOSE: Saves instance handle and creates main window
  108. //
  109. //   COMMENTS:
  110. //
  111. //        In this function, we save the instance handle in a global variable and
  112. //        create and display the main program window.
  113. //
  114. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  115. {
  116.     //HWND hWnd;
  117.     hInst=          hInstance; // Store instance handle in our global variable
  118.     hWnd=           CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  119.                                 CW_USEDEFAULT, CW_USEDEFAULT, WINDOW_WIDTH,
  120.                                 WINDOW_HEIGHT, NULL, NULL, hInstance, NULL);
  121.     if (!hWnd)
  122.     {
  123.         return FALSE;
  124.     }
  125.     ShowWindow(hWnd, nCmdShow);
  126.     UpdateWindow(hWnd);
  127.     return TRUE;
  128. }
  129. //
  130. //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  131. //
  132. //  PURPOSE:  Processes messages for the main window.
  133. //
  134. //  WM_COMMAND  - process the application menu
  135. //  WM_PAINT    - Paint the main window
  136. //  WM_DESTROY  - post a quit message and return
  137. //
  138. //
  139. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  140. {
  141.     int             wmId, wmEvent;
  142.     PAINTSTRUCT     ps;
  143.     HDC             hdc;
  144.     switch (message)
  145.     {
  146.     case WM_COMMAND:
  147.         wmId=       LOWORD(wParam);
  148.         wmEvent=    HIWORD(wParam);
  149.         // Parse the menu selections:
  150.         switch (wmId)
  151.         {
  152.         case IDM_ABOUT:
  153.             DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
  154.             break;
  155.         case IDM_EXIT:
  156.             DestroyWindow(hWnd);
  157.             break;
  158.         default:
  159.             return DefWindowProc(hWnd, message, wParam, lParam);
  160.         }
  161.         break;
  162.     case WM_PAINT:
  163.         hdc=BeginPaint(hWnd, &ps);
  164.         appEngine.Paint(hdc);
  165.         EndPaint(hWnd, &ps);
  166.         break;
  167.     case WM_DESTROY:
  168.         PostQuitMessage(0);
  169.         break;
  170.     default:
  171.         return DefWindowProc(hWnd, message, wParam, lParam);
  172.     }
  173.     return EXIT_SUCCESS;
  174. }
  175. // Message handler for about box.
  176. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  177. {
  178.     UNREFERENCED_PARAMETER(lParam);
  179.     switch (message)
  180.     {
  181.     case WM_INITDIALOG:
  182.         return (INT_PTR)TRUE;
  183.     case WM_COMMAND:
  184.         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  185.         {
  186.             EndDialog(hDlg, LOWORD(wParam));
  187.             return (INT_PTR)TRUE;
  188.         }
  189.         break;
  190.     }
  191.     return (INT_PTR)FALSE;
  192. }
  193.  
  194. //Vertex.cpp next:
  195. #include "StdAfx.h"
  196. #include "Vertex.h"
  197. // Constructors
  198. Vertex::Vertex(void)
  199. {
  200.     Init(0.0f, 0.0f, 0.0f, 0.0f);
  201. }
  202. Vertex::Vertex(float x, float y, float z, float w)
  203. {
  204.     Init(x, y, z, w);
  205. }
  206. Vertex::Vertex(const Vertex& v)
  207. {
  208.     Copy(v);
  209. }
  210. Vertex::~Vertex(void)
  211. {
  212. }
  213. // Accessors and mutators
  214. float Vertex::GetX(void) const
  215. {
  216.     return _x;
  217. }
  218. void Vertex::SetX(float x)
  219. {
  220.     _x=x;
  221. }
  222. float Vertex::GetY(void) const
  223. {
  224.     return _y;
  225. }
  226. void Vertex::SetY(float y)
  227. {
  228.     _y=y;
  229. }
  230. float Vertex::GetW(void) const
  231. {
  232.     return _w;
  233. }
  234. void Vertex::SetW(float w)
  235. {
  236.     _w=w;
  237. }
  238. float Vertex::GetZ(void) const
  239. {
  240.     return _z;
  241. }
  242. void Vertex::SetZ(float z)
  243. {
  244.     _z=z;
  245. }
  246. // Operator overloads
  247. Vertex& Vertex::operator=(const Vertex &rhs)
  248. {
  249.     if (this!=&rhs)
  250.     {
  251.         // Only copy if we are not assigning to ourselves.
  252.         // (remember that a = b is the same as a.operator=(b))
  253.         Copy(rhs);
  254.     }
  255.     return *this;
  256. }
  257. const Vertex Vertex::operator+(const Vertex &other) const
  258. {
  259.     Vertex result;
  260.     result.SetX(_x+other.GetX());
  261.     result.SetY(_y+other.GetY());
  262.     result.SetZ(_z+other.GetZ());
  263.     result.SetW(_w+other.GetW());
  264.     return result;
  265. }
  266. const Vertex Vertex::operator-(const Vertex &other) const
  267. {
  268.     Vertex result;
  269.     result.SetX(_x-other.GetX());
  270.     result.SetY(_y-other.GetY());
  271.     result.SetZ(_z-other.GetZ());
  272.     result.SetW(_w-other.GetW());
  273.     return result;
  274. }
  275. // Private methods
  276. void Vertex::Init(float x, float y, float z, float w)
  277. {
  278.     _x=x;
  279.     _y=y;
  280.     _z=z;
  281.     _w=w;
  282. }
  283. void Vertex::Copy(const Vertex& v)
  284. {
  285.     _x=v.GetX();
  286.     _y=v.GetY();
  287.     _z=v.GetZ();
  288.     _w=v.GetW();
  289. }
  290.  
  291. // And now the Rasterizer.cpp source:
  292. #include "StdAfx.h"
  293. #include "Rasterizer.h"
  294. Rasterizer::Rasterizer(void)
  295. {
  296.     // Declared private so should not be called.
  297.     _bitmap=NULL;
  298.     _graphics=NULL;
  299. }
  300. Rasterizer::Rasterizer(unsigned int width, unsigned int height)
  301. {
  302.     // Create a bitmap of the specified size and get a reference to the graphics object
  303.     // for that bitmap. Note that these calls could theoretically fail so we really should
  304.     // handle that, but we will leave that for now.
  305.     _width=width;
  306.     _height=height;
  307.     _bitmap=new Bitmap(_width, _height, PixelFormat32bppARGB);
  308.     _graphics=new Graphics(_bitmap);
  309. }
  310. Rasterizer::~Rasterizer(void)
  311. {
  312.     // Clean up all dynamically created objects
  313.     if (_graphics)
  314.     {
  315.         delete _graphics;
  316.         _graphics=NULL;
  317.     }
  318.     if (_bitmap)
  319.     {
  320.         delete _bitmap;
  321.         _bitmap=NULL;
  322.     }
  323. }
  324. // Accessors
  325. unsigned int Rasterizer::GetWidth() const
  326. {
  327.     return _width;
  328. }
  329. unsigned int Rasterizer::GetHeight() const
  330. {
  331.     return _height;
  332. }
  333. Bitmap* Rasterizer::GetBitmap() const
  334. {
  335.     return _bitmap;
  336. }
  337. // Clear the bitmap using the specified colour
  338. void Rasterizer::Clear(const Color& color)
  339. {
  340.     if (_graphics)
  341.     {
  342.         _graphics->Clear(color);
  343.     }
  344. }
  345. void Rasterizer::DrawSquare(Vertex square[4], bool Update, HWND _hWnd)
  346. {
  347.     HWND hWnd;
  348.     hWnd=_hWnd;
  349.     Pen pen(Color(255,12,48,150));
  350.     for (int i=0; i<4; i=i+1)
  351.     {
  352.         if (i+1==4)
  353.         {
  354.             _graphics->DrawLine(&pen, square[i].GetX(), square[i].GetY(), square[0].GetX(), square[0].GetY());
  355.         }
  356.         else
  357.             _graphics->DrawLine(&pen, square[i].GetX(), square[i].GetY(), square[i+1].GetX(), square[i+1].GetY());
  358.     }
  359.     if(!Update)
  360.     {
  361.         return;
  362.     }
  363.     else
  364.         InvalidateRect(_hWnd, NULL, FALSE);
  365.     /**else
  366.         UpdateWindow(hWnd);*/
  367.     //_graphics->DrawLine(&pen, square[0].GetX(), square[0].GetY(), square[1].GetX(), square[1].GetY());
  368.     //_graphics->DrawLine(&pen, square[1].GetX(), square[1].GetY(), square[2].GetX(), square[2].GetY());
  369.     //_graphics->DrawLine(&pen, square[2].GetX(), square[2].GetY(), square[3].GetX(), square[3].GetY());
  370.     //_graphics->DrawLine(&pen, square[3].GetX(), square[3].GetY(), square[0].GetX(), square[0].GetY());
  371. }
  372. void Rasterizer::LineTo(int col[4],int x0, int y0, int x1, int y1, bool Update, HWND _hWnd)
  373. {
  374.     HWND hWnd;
  375.     hWnd= _hWnd;
  376.     Pen pen(Color(col[0],col[1],col[2],col[3]));
  377.     _graphics->DrawLine(&pen, x0, y0, x1, y1);
  378.     if(!Update)
  379.     {
  380.         return;
  381.     }
  382.     else
  383.         InvalidateRect(_hWnd, NULL, FALSE);
  384.         //InvalidateRect(hWnd, NULL, FALSE);
  385.         //UpdateWindow(hWnd);
  386. }
  387.  
  388. // Here's our Matrix2D.cpp file:
  389.  
  390. #include "StdAfx.h"
  391. #include "Matrix2D.h"
  392. #define WIDTH   4
  393. #define HEIGHT  4
  394. //Constructors
  395. Matrix2D::Matrix2D(void)
  396. {
  397.     float matrix[WIDTH][HEIGHT];
  398.     for (int i=0; i<WIDTH; i=i+1)
  399.     {
  400.         for (int j=0; j<HEIGHT; j=j+1)
  401.         {
  402.             matrix[i][j]=0.00f;
  403.         }
  404.     }
  405.     Init(matrix);
  406. }
  407. Matrix2D::Matrix2D(float matrix[][WIDTH])
  408. {
  409.     Init(matrix);
  410. }
  411. Matrix2D::Matrix2D(const Matrix2D& m)
  412. {
  413.     Copy(m);
  414. }
  415. Matrix2D::~Matrix2D(void)
  416. {
  417. }
  418. //Accessors and mutators
  419. float Matrix2D::GetM(int x, int y) const
  420. {
  421.     return _matrix[x][y];
  422. }
  423. void Matrix2D::SetM(int x, int y, float f)
  424. {
  425.     for (int i=0; i<WIDTH; i=i+1)
  426.     {
  427.         for (int j=0; j<HEIGHT; j=j+1)
  428.         {
  429.             _matrix[x][y]=f;
  430.         }
  431.     }
  432. }
  433. //Operators
  434. const Matrix2D Matrix2D::operator*(const Matrix2D &other) const
  435. {
  436.     Matrix2D result;
  437.     float sum;
  438.     for (int i=0; i<4; i=i+1)
  439.     {
  440.         for (int j=0; j<4; j=j+1)
  441.         {
  442.             sum=0;
  443.             for (int k=0; k<4; k=k+1)
  444.             {
  445.                 sum=sum+_matrix[i][k]*other.GetM(k,j);
  446.             }
  447.             result.SetM(i,j,sum);
  448.         }
  449.     }
  450.     return result;
  451. }
  452. const Vertex Matrix2D::operator*(const Vertex &p) const
  453. {
  454.     Vertex result;
  455.     result.SetX(((_matrix[0][0]*p.GetX())+(_matrix[1][0]*p.GetY())+(_matrix[2][0]*p.GetZ())+(_matrix[3][0]*p.GetW())));
  456.     result.SetY(((_matrix[0][1]*p.GetX())+(_matrix[1][1]*p.GetY())+(_matrix[2][1]*p.GetZ())+(_matrix[3][1]*p.GetW())));
  457.     result.SetZ(((_matrix[0][2]*p.GetX())+(_matrix[1][2]*p.GetY())+(_matrix[2][2]*p.GetZ())+(_matrix[3][2]*p.GetW())));
  458.     result.SetW(((_matrix[0][3]*p.GetX())+(_matrix[1][3]*p.GetY())+(_matrix[2][3]*p.GetZ())+(_matrix[3][3]*p.GetW())));
  459.     return result;
  460. }
  461. //Private Methods
  462. void Matrix2D::Init(float matrix[][WIDTH])
  463. {
  464.     for (int i=0; i<HEIGHT; i=i+1)
  465.     {
  466.         for (int j=0; j<WIDTH; j=j+1)
  467.         {
  468.             _matrix[i][j]=matrix[i][j];
  469.         }
  470.     }
  471. }
  472. void Matrix2D::Copy(const Matrix2D& m)
  473. {
  474.     for (int i=0;i<HEIGHT;i=i+1)
  475.     {
  476.         for (int j=0;j<WIDTH;j=j+1)
  477.         {
  478.             _matrix[j][i]=m.GetM(j,i);
  479.         }
  480.     }
  481. }
  482.  
  483. // And finally our AppEngine.cpp:
  484.  
  485. #include "StdAfx.h"
  486. #include "AppEngine.h"
  487. #include "Rasterizer.h"
  488. #include <cmath>
  489. #include <math.h>
  490. #include "Matrix2D.h"
  491. #define PI  3.14159265
  492. // Globals here, innit:
  493. float       rads=PI/180;        // Work out our radians
  494. float       angle=2.00f*rads;   // Set a default value for our angle
  495. RECT        clientWindowRect;
  496. float       centreWidth,
  497.             centreHeight;       // For centre point of canvas
  498. // Main 'engine' class for our application. This is where all of the core processing work is done
  499. AppEngine::AppEngine(void)
  500. {
  501.     _rasterizer=NULL;
  502. }
  503. AppEngine::~AppEngine(void)
  504. {
  505.     // Make sure everything is cleaned up (in case Shutdown() was now called directly)
  506.     Shutdown();
  507. }
  508. void AppEngine::Initialise(HWND hWnd, HDC hdc)
  509. {
  510.     _hdc=hdc;
  511.     _hWnd=hWnd;
  512.     // Get the width and height of the window so that we can tell the rasterizer to create a bitmap
  513.     // of the same size.  Note that this only works for the initial size of the window. If you want
  514.     // your code to handle resizing of the window, you will need to add code for this yourself.
  515.     long int width;
  516.     long int height;
  517.     RECT clientWindowRect;
  518.     if (GetClientRect(_hWnd, &clientWindowRect))
  519.     {
  520.         width=clientWindowRect.right;
  521.         height=clientWindowRect.bottom;
  522.     }
  523.     else
  524.     {
  525.         width=640;
  526.         height=480;
  527.     }
  528.     // This will therefore define our relative centre point:
  529.     centreWidth=width/2.00f;
  530.     centreHeight=height/2.00f;
  531.     _rasterizer=new Rasterizer((unsigned int)width,(unsigned int)height);
  532. }
  533. void AppEngine::Process(void)
  534. {
  535.     // At the moment, all we do is render a new image. In the future, we might do more here
  536.     Render();
  537. }
  538. void AppEngine::Render(void)
  539. {
  540.     // Default colour, with full alpha (non-transparent):
  541.     _rasterizer->Clear(Color(255,255,255,255));
  542.     // This will define the length and height of our object:
  543.     float   sqWid=30.00f,
  544.             sqHei=15.00f;
  545.     // Okay, so if we want the object in the centre of the
  546.     // window, we could do:
  547.     float topLeftX=             centreWidth-sqWid;
  548.     float topLeftY=             centreHeight-sqHei;
  549.     // Now we can work out the relative centre of your object
  550.     // assuming that it's a square, by:
  551.     sqWid=sqWid*2; sqHei=sqHei*2;       // Can you see what I did there?
  552.     float centreP=              (topLeftX*0.25f)+
  553.                                 ((topLeftX+sqWid)*0.25f)+
  554.                                 (topLeftY*0.25f)+
  555.                                 ((topLeftY+sqHei)*0.25f);
  556.     float Y=                    centreP;
  557.     Vertex square [4];
  558.     square[0]=                  Vertex(topLeftX,topLeftY,0,1);
  559.     square[1]=                  Vertex(topLeftX+sqWid,topLeftY,0,1);
  560.     square[2]=                  Vertex(topLeftX+sqWid,topLeftY+sqHei,0,1);
  561.     square[3]=                  Vertex(topLeftX,topLeftY+sqHei,0,1);
  562.     Vertex point;
  563.     point=                      square[0];
  564.     // Let's do this:
  565.     _rasterizer->DrawSquare(square, true, _hWnd);
  566.     // Identity matrix:
  567.     float matrixID[4][4];
  568.     matrixID[0][0]=1.00f;       matrixID[0][1]=0.00f;           matrixID[0][2]=0.00f;       matrixID[0][3]=0.00f;
  569.     matrixID[1][0]=0.00f;       matrixID[1][1]=1.00f;           matrixID[1][2]=0.00f;       matrixID[1][3]=0.00f;
  570.     matrixID[2][0]=0.00f;       matrixID[1][1]=0.00f;           matrixID[1][2]=1.00f;       matrixID[1][3]=0.00f;
  571.     matrixID[3][0]=0.00f;       matrixID[3][1]=0.00f;           matrixID[3][2]=0.00f;       matrixID[3][3]=1.00f;
  572.     Matrix2D _matrixID(matrixID);
  573.     // Y rotation, also called heading or pan, "Y" is the rotation value:
  574.     float matrixYPan[4][4];
  575.     matrixYPan[0][0]=cos(Y);        matrixYPan[0][1]=0.00f;         matrixYPan[0][2]=sin(Y);        matrixYPan[0][3]=0.00f;
  576.     matrixYPan[1][0]=0.00f;         matrixYPan[1][1]=1.00f;         matrixYPan[1][2]=0.00f;         matrixYPan[1][3]=0.00f;
  577.     matrixYPan[2][0]=-sin(Y);       matrixYPan[1][1]=0.00f;         matrixYPan[1][2]=cos(Y);        matrixYPan[1][3]=0.00f;
  578.     matrixYPan[3][0]=0.00f;         matrixYPan[3][1]=0.00f;         matrixYPan[3][2]=0.00f;         matrixYPan[3][3]=1.00f;
  579.     Matrix2D _matrixYPan(matrixYPan);
  580.     // Basic rotate matrix:
  581.     float matrixRotate[4][4];
  582.     matrixRotate[0][0]=cos(0.1f);   matrixRotate[1][0]=-sin(0.1f);      matrixRotate[2][0]=0.00f;       matrixRotate[3][0]=0.00f;
  583.     matrixRotate[0][1]=sin(0.1f);   matrixRotate[1][1]=cos(0.1f);       matrixRotate[2][1]=0.00f;       matrixRotate[2][1]=0.00f;
  584.     matrixRotate[0][2]=0.00f;       matrixRotate[1][2]=0.00f;           matrixRotate[2][2]=1.00f;       matrixRotate[2][2]=0.00f;
  585.     matrixRotate[0][3]=0.00f;       matrixRotate[1][3]=0.00f;           matrixRotate[2][3]=0.00f;       matrixRotate[3][3]=1.00f;
  586.     Matrix2D _matrixRotate(matrixRotate);
  587.     float matrixScale[4][4];
  588.     matrixScale[0][0]=1.10f;            matrixScale[1][0]=0.00f;                matrixScale[2][0]=0.00f;        matrixScale[3][0]=0.00f;
  589.     matrixScale[0][1]=0.00f;            matrixScale[1][1]=1.10f;                matrixScale[2][1]=0.00f;        matrixScale[3][1]=0.00f;
  590.     matrixScale[0][2]=0.00f;            matrixScale[1][2]=0.00f;                matrixScale[2][2]=0.00f;        matrixScale[3][2]=0.00f;
  591.     matrixScale[0][3]=0.00f;            matrixScale[1][3]=0.00f;                matrixScale[2][3]=0.00f;        matrixScale[3][3]=1.00f;
  592.     Matrix2D _matrixScale(matrixScale);
  593.     Matrix2D scaleAndRotateMatirix=_matrixScale*_matrixRotate;
  594.     // Yay for Mathematics!
  595.     for (int j=0; j<360;j=j+1) // j=j+1 is more like the Mathematics I'm all about!
  596.     {
  597.         for (int i=0; i<4; i=i+1)
  598.         {
  599.             square[i]=square[i]-point;
  600.             square[i]=_matrixRotate*square[i];
  601.             //square[i]=scaleAndRotateMatirix*square[i];
  602.             square[i]=square[i]+point;
  603.         }
  604.         _rasterizer->DrawSquare(square, true, _hWnd); //draw scaled square
  605.         //Paint (_hdc);
  606.     }
  607.     int blue[4]={255, 0, 0, 255};
  608.     int red [4]={255, 255, 0, 0};
  609.     int y = 256;
  610.     for (int x=0; x<256; x=x+5)
  611.     {
  612.         _rasterizer->LineTo(blue, 0, y, x, 0, true, _hWnd);
  613.         _rasterizer->LineTo(red, 256, x, y, 256, true, _hWnd);
  614.         y=y-5;
  615.         Paint (_hdc);
  616.         ReleaseDC(_hWnd, _hdc);
  617.         //Paint (_hdc);
  618.     }
  619.     // Ensure that Windows is told that the contents of the window now needs painting
  620. }
  621. void AppEngine::Paint(HDC hdc)
  622. {
  623.     // Copy the contents of the rasterizer's bitmap to our window
  624.     if (_rasterizer)
  625.     {
  626.         Graphics graphics(hdc);
  627.         graphics.DrawImage(_rasterizer->GetBitmap(), 0, 0, _rasterizer->GetWidth(), _rasterizer->GetHeight());
  628.     }
  629. }
  630. void AppEngine::Shutdown(void)
  631. {
  632.     // Clean up all memory that has been dynamically allocated
  633.     if (_rasterizer)
  634.     {
  635.         delete _rasterizer;
  636.         _rasterizer = NULL;
  637.     }
  638. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement