Advertisement
Guest User

Untitled

a guest
May 25th, 2015
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.48 KB | None | 0 0
  1. #include <Windows.h>
  2. #include "Palette.h"
  3. #include <stdio.h>
  4. #include <math.h>
  5. #include "Keyboard.h"
  6. #include "Common.h"
  7. #include "Mouse.h"
  8.  
  9. #define M_PI 3.14159265358979323846
  10. #define M_2PI (2*M_PI)
  11. #define DEG2RAD(deg) (deg * M_PI / 180)
  12.  
  13. static const BITMAPINFO bmi = { { sizeof(BITMAPINFOHEADER), WIDTH, -HEIGHT, 1, 32, BI_RGB, SIZE, 0, 0, 0, 0 }, { 0, 0, 0, 0 } };
  14. static DWORD pixel[SIZE];
  15.  
  16. BYTE buffer[SIZE];
  17. BYTE cgabuffer[16000];
  18.  
  19. struct Vector
  20. {
  21.     float x, y, z;
  22. };
  23.  
  24. struct Coord
  25. {
  26.     int x, y;
  27. };
  28.  
  29. Vector cube[8] = {
  30.     {-8, -8, -8},
  31.     {8, -8, -8},
  32.     {-8, 8, -8},
  33.     {8, 8, -8},
  34.     {-8, -8, 8},
  35.     {8, -8, 8},
  36.     {-8, 8, 8},
  37.     {8, 8, 8}
  38. };
  39.  
  40. Vector cubetrans[8];
  41.  
  42. void rotatezaxis(Vector &vecout, Vector vecin, float ang)
  43. {
  44.     vecout.x = vecin.x*cos(ang) - vecin.y*sin(ang);
  45.     vecout.y = vecin.x*sin(ang) + vecin.y*cos(ang);
  46.     vecout.z = vecin.z;
  47. }
  48.  
  49. void rotatexaxis(Vector &vecout, Vector vecin, float ang)
  50. {
  51.     vecout.y = vecin.y*cos(ang) - vecin.z*sin(ang);
  52.     vecout.z = vecin.y*sin(ang) + vecin.z*cos(ang);
  53.     vecout.x = vecin.x;
  54. }
  55.  
  56. void rotateyaxis(Vector &vecout, Vector vecin, float ang)
  57. {
  58.     vecout.z = vecin.z*cos(ang) - vecin.x*sin(ang);
  59.     vecout.x = vecin.z*sin(ang) + vecin.x*cos(ang);
  60.     vecout.y = vecin.y;
  61. }
  62.  
  63. void translatez(Vector &vecout, float z)
  64. {
  65.     vecout.z += z;
  66. }
  67.  
  68. void project(Coord &coord, Vector vec, float fov)
  69. {
  70.     coord.x = (WIDTH / 2) + (vec.x * fov) / vec.z;
  71.     coord.y = (HEIGHT / 2) + (vec.y * fov) / vec.z;
  72. }
  73.  
  74. void entrypoint()
  75. {
  76.     HDC hDC = GetDC(0);
  77.     SelectObject(CreateCompatibleDC(0), CreateCompatibleBitmap(hDC, WIDTH, HEIGHT));
  78.  
  79.     Coord scr;
  80.     Vector t0, t1;
  81.     float angx, angy, angz;
  82.     float aa = 0;
  83.     while (!GetAsyncKeyState(VK_ESCAPE))
  84.     {
  85.         Mouse::Update();
  86.  
  87.         memset(buffer, 0, 64000);
  88.  
  89.         angx += 0.05;
  90.         angy += 0.02;
  91.         angz += 0.03;
  92.         aa += 0.1;
  93.         for (int i = 0; i < 8; i++)
  94.         {
  95.             rotatezaxis(t1, cube[i], angz);
  96.             rotatexaxis(t0, t1, angx);
  97.             rotateyaxis(t1, t0, angy);
  98.             translatez(t1, 30.0f+sin(aa)*12);
  99.  
  100.             //t1 holds rotated and translated vector.
  101.             //project this vector:
  102.             project(scr, t1, 60);
  103.             if (scr.x < 0) scr.x = 0;   if (scr.x >=WIDTH-1) scr.x = WIDTH-1;
  104.             if (scr.y < 0) scr.y = 0;   if (scr.y >=HEIGHT-1) scr.y = HEIGHT-1;
  105.             buffer[scr.x + scr.y * WIDTH] = 15;
  106.         }
  107.  
  108.         for (int i = 0; i < SIZE; i++) pixel[i] = palmcga[buffer[i]];
  109.  
  110.         StretchDIBits(hDC, STARTX, STARTY, WINWIDTH, WINHEIGHT, 0, 0, WIDTH, HEIGHT, (DWORD*)pixel, &bmi, DIB_RGB_COLORS, SRCCOPY);
  111.         Sleep(50);
  112.     }
  113.     ExitProcess(0);
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement