Gerard-Meier

LibNDS drawcircle (inefficient)

Feb 10th, 2011
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <stdio.h>
  4. #include <nds.h>
  5. #include <math.h>
  6.  
  7. #include "Vector2D.cpp"
  8.  
  9. #define PI 3.14159265
  10.  
  11. #ifndef GRAPHICS_CPP
  12. #define GRAPHICS_CPP
  13.  
  14. class Graphics {
  15.     private:
  16.         u16* videoRam;
  17.        
  18.     public:
  19.         Graphics() {
  20.             videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE);
  21.             vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
  22.             REG_BG3CNT = BG_BMP16_256x256 | BG_BMP_BASE(0);
  23.             REG_BG3PA  = 1 << 8;
  24.             REG_BG3PB  = 0;
  25.             REG_BG3PC  = 0;
  26.             REG_BG3PD  = 1 << 8;
  27.             videoRam   = BG_BMP_RAM(0);
  28.         }
  29.        
  30.         void drawPixel(int x, int y) {
  31.             videoRam[y * SCREEN_WIDTH + x] = RGB15(0,31,0) | (1<<15);
  32.         }
  33.        
  34.         // Extremely basic and inefficient implementation to draw a circle:
  35.         void drawCircle(int x, int y, int radius) {
  36.             for(int i = 0; i < 360; ++i) {
  37.                 int tmpX = x + round(cos(i * PI / 180) * radius);
  38.                 int tmpY = y + round(sin(i * PI / 180) * radius);
  39.                
  40.                 drawPixel(tmpX, tmpY);
  41.                
  42.             }
  43.         }
  44.  
  45. };
  46.  
  47.  
  48. #endif
Advertisement
Add Comment
Please, Sign In to add comment