My function to draw a line (not just horiz or vert) that works In libwiiu

Discussion in 'Wii U - Hacking & Backup Loaders' started by brienj, Feb 24, 2016.

  1. brienj
    OP

    brienj Trying to avoid getting cancer

    Member
    1,232
    1,705
    Jan 3, 2016
    United States
    The function drawLine in libwiiu only draws a horizontal or vertical line. So what if you want to draw a 30, 45, or 60 degree angle? I was doing some testing, and found the DDA Algorithm, modified to work with libwiiu, to be the best. So here is the code for the DDA Algorithm I modified. You can replace the normal drawLine function with it if you want, it works just as well.

    Code:
    void draw2DLine(int x1, int y1, int x2, int y2, char r, char g, char b)
    {
    	int s, dx, dy, m;
    	float xi, yi, x, y;
    	dx = x2 - x1;
    	dy = y2 - y1;
    	if (abs(dx) > abs(dy)) {
    		s = dx;
    	}
    	else {
    		s = dy;
    	}
    	xi = dx / (float) s;
    	yi = dy / (float) s;
    	x = x1;
    	y = y1;
    
    	drawPixel(x1, y1, r, g, b);
    	if (s > m) {
    		m = 0;
    		for (m; m < s; m++) {
    			x += xi;
    			y += yi;
    			drawPixel(x, y, r, g, b);
    		}
    	}
    	else {
    		m = 0;
    		for (m; m > s; m--) {
    			x -= xi;
    			y -= yi;
    			drawPixel(x, y, r, g, b);
    		}
    	}
    }
    
     
    supermalloch and Voxel like this.
  2. Voxel

    Voxel Fable Junkie

    Member
    GBAtemp Patron
    Voxel is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    5,198
    5,902
    Jun 27, 2015
    United Kingdom
    England, UK
    Awesome! Why don't you create a merge pull request in the libwiiu repo on github? ^_^

    ...unless you already have done?
     
    brienj likes this.
  3. brienj
    OP

    brienj Trying to avoid getting cancer

    Member
    1,232
    1,705
    Jan 3, 2016
    United States
    I'm not even on github. I really need to one of these days though.
     
  4. Voxel

    Voxel Fable Junkie

    Member
    GBAtemp Patron
    Voxel is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    5,198
    5,902
    Jun 27, 2015
    United Kingdom
    England, UK
    i don't even know how to set up a repository still. :sleep: