You are not logged in.

#1 2009-06-27 06:34:55

Hizna
Member

Help needed with GRRLIB_NGone

Hi there,

I'm trying to create some code that will draw hexagons to the screen.  I've got it so I can make one okay, but if I have 2 and they overlap, the program crashes on closing.

Also, without having them overlap, when I quit the program, the hexagons disappear one at a time.  Ideally I'd want them to go away at the same time.

Also - I tried putting the render calls in main() after the calls to drawHexagon(), but that didn't seem to help things.

Here is the code thus far:

Code:

#include "../../../GRRLIB/GRRLIB/GRRLIB.h"

#include <stdlib.h>
#include <wiiuse/wpad.h>
#include <math.h>

#define GRRLIB_BLACK   0x000000FF
#define GRRLIB_GREEN   0x008000FF
#define GRRLIB_PURPLE  0x800080FF

Mtx GXmodelView2D;

void drawHexagon(float x, float y, float side, u32 color);

int main() {
    u32 wpaddown;
    u32 wpadheld;
    
    GRRLIB_Init();
    WPAD_Init();
    

    while(1) {
        WPAD_ScanPads();
        wpaddown = WPAD_ButtonsDown(0);
        wpadheld = WPAD_ButtonsHeld(0);
        
        GRRLIB_FillScreen(GRRLIB_BLACK); 
        
        drawHexagon(100, 100, 25, GRRLIB_GREEN);
        drawHexagon(200, 200, 25, GRRLIB_PURPLE);
        

        if(wpaddown & WPAD_BUTTON_A) {
            break;
        }
  
        if(wpadheld & WPAD_BUTTON_A) {
            break;
        }
        
    }
    GRRLIB_Exit(); // Be a good boy, clear the memory allocated by GRRLIB

    return 0;
}

void drawHexagon(float x, float y, float side, u32 color){

    float h = sin(30 * M_PI / 180) * side;
    float r = cos(30 * M_PI / 180) * side;
    
    Vector hex[] = {{x,y,0},
                    {x+side,y,0},
                    {x+side+h,y+r,0},
                    {x+side,y+r+r,0},
                    {x,y+r+r,0},
                    {x-h,y+r,0},
                    {x,y,0}};    
    
    GRRLIB_NGone(hex,color,7);
    GRRLIB_Render();
}

If you are curious, I found the info on drawing hexagons here.

Thanks for any insight you can give!

Last edited by Hizna (2009-06-27 06:35:10)

Offline

 

#2 2009-06-29 05:29:18

eckyecky
Member

Re: Help needed with GRRLIB_NGone

try this (tested in dolphin)
http://www.upload.mn/files/thumbs/10fhj10xq3fn7ioo7nub_thumb.jpeg
dolphin crashed with render in the function.
and color needs to be an array of color at each vector point.

Code:

#include "../../../GRRLIB/GRRLIB/GRRLIB.h"

#include <stdlib.h>
#include <wiiuse/wpad.h>
#include <math.h>

#define GRRLIB_BLACK   0x000000FF
#define GRRLIB_GREEN   0x008000FF
#define GRRLIB_PURPLE  0x800080FF


Mtx GXmodelView2D;

void drawHexagon(float x, float y, float side, u32 color);

int main() {
    u32 wpaddown;
    u32 wpadheld;
    
    GRRLIB_Init();
    WPAD_Init();
    

    while(1) {
        WPAD_ScanPads();
        wpaddown = WPAD_ButtonsDown(0);
        wpadheld = WPAD_ButtonsHeld(0);
        
        GRRLIB_FillScreen(GRRLIB_BLACK); 
        
        drawHexagon(100, 100, 25, GRRLIB_GREEN);
        drawHexagon(125, 125, 25, GRRLIB_PURPLE);
        GRRLIB_Render();
        if(wpaddown & WPAD_BUTTON_A) {
            break;
        }
  
        if(wpadheld & WPAD_BUTTON_A) {
            break;
        }
        
    }
    GRRLIB_Exit(); // Be a good boy, clear the memory allocated by GRRLIB

    return 0;
}

void drawHexagon(float x, float y, float side, u32 color){

    float h = sin(30 * M_PI / 180) * side;
    float r = cos(30 * M_PI / 180) * side;
    int i;
    Vector hex[] = {{x,y,0},
                    {x+side,y,0},
                    {x+side+h,y+r,0},
                    {x+side,y+r+r,0},
                    {x,y+r+r,0},
                    {x-h,y+r,0},
                    {x,y,0}};
    u32 ncolor[7];
    for (i=0;i<7;i++)
        ncolor[i]=color;
    GRRLIB_NGone(hex,ncolor,7);
    
}

Last edited by eckyecky (2009-06-29 05:37:11)

Offline

 

Board footer

Powered by FluxBB