Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include "Palette.h"
- #include <stdio.h>
- #include <math.h>
- #include "Keyboard.h"
- #include "Common.h"
- #include "Mouse.h"
- #define M_PI 3.14159265358979323846
- #define M_2PI (2*M_PI)
- #define DEG2RAD(deg) (deg * M_PI / 180)
- static const BITMAPINFO bmi = { { sizeof(BITMAPINFOHEADER), WIDTH, -HEIGHT, 1, 32, BI_RGB, SIZE, 0, 0, 0, 0 }, { 0, 0, 0, 0 } };
- static DWORD pixel[SIZE];
- BYTE buffer[SIZE];
- BYTE cgabuffer[16000];
- struct Vector
- {
- float x, y, z;
- };
- struct Coord
- {
- int x, y;
- };
- Vector cube[8] = {
- {-8, -8, -8},
- {8, -8, -8},
- {-8, 8, -8},
- {8, 8, -8},
- {-8, -8, 8},
- {8, -8, 8},
- {-8, 8, 8},
- {8, 8, 8}
- };
- Vector cubetrans[8];
- void rotatezaxis(Vector &vecout, Vector vecin, float ang)
- {
- vecout.x = vecin.x*cos(ang) - vecin.y*sin(ang);
- vecout.y = vecin.x*sin(ang) + vecin.y*cos(ang);
- vecout.z = vecin.z;
- }
- void rotatexaxis(Vector &vecout, Vector vecin, float ang)
- {
- vecout.y = vecin.y*cos(ang) - vecin.z*sin(ang);
- vecout.z = vecin.y*sin(ang) + vecin.z*cos(ang);
- vecout.x = vecin.x;
- }
- void rotateyaxis(Vector &vecout, Vector vecin, float ang)
- {
- vecout.z = vecin.z*cos(ang) - vecin.x*sin(ang);
- vecout.x = vecin.z*sin(ang) + vecin.x*cos(ang);
- vecout.y = vecin.y;
- }
- void translatez(Vector &vecout, float z)
- {
- vecout.z += z;
- }
- void project(Coord &coord, Vector vec, float fov)
- {
- coord.x = (WIDTH / 2) + (vec.x * fov) / vec.z;
- coord.y = (HEIGHT / 2) + (vec.y * fov) / vec.z;
- }
- void entrypoint()
- {
- HDC hDC = GetDC(0);
- SelectObject(CreateCompatibleDC(0), CreateCompatibleBitmap(hDC, WIDTH, HEIGHT));
- Coord scr;
- Vector t0, t1;
- float angx, angy, angz;
- float aa = 0;
- while (!GetAsyncKeyState(VK_ESCAPE))
- {
- Mouse::Update();
- memset(buffer, 0, 64000);
- angx += 0.05;
- angy += 0.02;
- angz += 0.03;
- aa += 0.1;
- for (int i = 0; i < 8; i++)
- {
- rotatezaxis(t1, cube[i], angz);
- rotatexaxis(t0, t1, angx);
- rotateyaxis(t1, t0, angy);
- translatez(t1, 30.0f+sin(aa)*12);
- //t1 holds rotated and translated vector.
- //project this vector:
- project(scr, t1, 60);
- if (scr.x < 0) scr.x = 0; if (scr.x >=WIDTH-1) scr.x = WIDTH-1;
- if (scr.y < 0) scr.y = 0; if (scr.y >=HEIGHT-1) scr.y = HEIGHT-1;
- buffer[scr.x + scr.y * WIDTH] = 15;
- }
- for (int i = 0; i < SIZE; i++) pixel[i] = palmcga[buffer[i]];
- StretchDIBits(hDC, STARTX, STARTY, WINWIDTH, WINHEIGHT, 0, 0, WIDTH, HEIGHT, (DWORD*)pixel, &bmi, DIB_RGB_COLORS, SRCCOPY);
- Sleep(50);
- }
- ExitProcess(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement