Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <SDL/SDL.h>
- #include <SDL/SDL_gfxPrimitives.h>
- #include <iostream>
- #include <vector>
- #include <math.h>
- #define PI 3.14159265
- using namespace std;
- const int WINDOW_WIDTH = 640;
- const int WINDOW_HEIGHT = 480;
- const char* WINDOW_TITLE = "SDL POLY TEST";
- class CPoly {
- private:
- vector<int> points;
- int* vpBuffer = (int*) calloc(50,sizeof(int));
- int rotang;
- int xoffs;
- int yoffs;
- public:
- CPoly (vector<int> tpoints, int rot, int xoff, int yoff) {
- free(vpBuffer);
- points = tpoints;
- rotang = rot;
- xoffs = xoff;
- yoffs = yoff;
- }
- void setRot (int newrot) {
- rotang=newrot;
- }
- void render (SDL_Surface* screen) {
- int wang=rotang*PI/180;
- for(int i=2;i<points.size();i+=2) {
- int xa=points[i-2];
- int ya=points[i-1];
- int xb=points[i];
- int yb=points[i+1];
- lineRGBA(screen,
- xoffs+((xa*cos(wang))-(ya*sin(wang))),
- yoffs+((xa*sin(wang))+(ya*cos(wang))),
- xoffs+((xb*cos(wang))-(yb*sin(wang))),
- yoffs+((xb*sin(wang))+(yb*cos(wang))),
- 255,255,255,255);
- }
- }
- };
- vector<int> makeRect(int width,int height) {
- vector<int> vpoints;
- vpoints.push_back(-width/2);
- vpoints.push_back(-height/2);
- vpoints.push_back(-width/2);
- vpoints.push_back(height/2);
- vpoints.push_back(width/2);
- vpoints.push_back(height/2);
- vpoints.push_back(width/2);
- vpoints.push_back(-height/2);
- vpoints.push_back(-width/2);
- vpoints.push_back(-height/2);
- return vpoints;
- }
- vector<int> makeCircle(int r,int depth) {
- vector<int> vpoints;
- int x,y;
- int thang;
- for(int i=0;i<360/(360/depth);i++) {
- thang=i*(360/depth)*PI/180;
- x=r*cos(thang);
- y=r*sin(thang);
- vpoints.push_back(x);
- vpoints.push_back(y);
- }
- vpoints.push_back(vpoints[0]);
- vpoints.push_back(vpoints[1]);
- return vpoints;
- }
- int main(int argc, char **argv)
- {
- SDL_Init( SDL_INIT_VIDEO );
- SDL_Surface* screen = SDL_SetVideoMode( WINDOW_WIDTH, WINDOW_HEIGHT, 0,
- SDL_HWSURFACE | SDL_DOUBLEBUF );
- SDL_WM_SetCaption( WINDOW_TITLE, 0 );
- SDL_Event event;
- int myints[] = {0,0,0,50,50,50,50,0,25,-25,0,0};
- vector<int> vertices (myints,myints+sizeof(myints)/sizeof(int));
- CPoly derpity (vertices,0,200,200);
- CPoly derpette (makeCircle(50,40),0,400,250);
- int step=0;
- bool gameRunning = true;
- while (gameRunning) {
- step++;
- if (SDL_PollEvent(&event)) {
- if (event.type == SDL_QUIT) {
- gameRunning = false;
- }
- }
- SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
- derpity.render(screen);
- derpette.render(screen);
- derpette.setRot(step%360);
- derpity.setRot(step%360);
- SDL_Flip(screen);
- }
- SDL_Quit();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement