You are not logged in.
Hi, I need to draw a graph showing the x position of the wiimote in function of the time.
The (simpified) code should be something like this:
33 if ( held & WPAD_BUTTON_A ){ 34 graph[grr]={grr, ir1.sx, 0}; 35 grc++; 36 GRRLIB_NPlot(graph, 0xFFFFFFFF, 640); 37 if(grc==640)grc=0; 38 }
(Of course each variable and the vector are properly defined in main() ).
But it doesn't work, I get this error when compiling:
main.c:34: error: expected expression before '{' token
What am I doing wrong? I couldn't find any example using it, so I have no reference, and the only example using vectors (Day 9 tutorial) defines the vector at main(), and I need to define it in while(1).
Thanks previously.
Offline
Hi, graph is declared as what? Could paste the code?
Offline
What I really need is to show a graph of the distance from the screen center to the wiimote cursor.
#include <stdio.h> #include <stdlib.h> #include <gccore.h> #include <wiiuse/wpad.h> #include <math.h> #include "GRRLIB/GRRLIB/GRRLIB.h" #include "gfx/console.h" Mtx GXmodelView2D; int main() { ir_t ir1; // Initialise the video system GRRLIB_Init(); // This function initialises the attached controllers WPAD_Init(); WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR); GRRLIB_texImg tex_font = GRRLIB_LoadTexture(console); GRRLIB_InitTileSet(&tex_font, 8, 8, 0); int grc = 0; Vector grafica[640]; while(1) { WPAD_SetVRes(0, 640, 480); WPAD_ScanPads(); WPAD_IR(WPAD_CHAN_0, &ir1); u32 pressed = WPAD_ButtonsDown(0); u32 held = WPAD_ButtonsHeld(0); int xpos = ir1.sx-250; int ypos = ir1.sy-250; // Si pulsamos A calculamos la distancia del cursor al centro de la pantalla y trazamos la línea que une a este con el cursor if ( held & WPAD_BUTTON_A ){ int vx = abs(xpos-320)^2; int vy = abs(ypos-240)^2; int distance = (vx+vy); GRRLIB_Printf(10, 10, tex_font, 0xFFFFFFFF,1, "\n%i", distance); GRRLIB_Printf(10, 20, tex_font, 0xFFFFFFFF,1, "\n%i", grc); GRRLIB_Line(320, 240, xpos, ypos, 0xFFFFFFFF); //vector hacia el lápiz grc++; grafica[grc]={grc, distance, 0.0f} GRRLIB_NPlot(grafica, 0xFFFFFFFF, 640); if(grc==640)grc=0; } // We return to the launcher application via exit if ( pressed & WPAD_BUTTON_HOME ) break; GRRLIB_Render(); } GRRLIB_Exit(); return 0; }
Last edited by Kadede (2009-06-26 23:14:57)
Offline
Ok I don't know the type Vector? And what is the Day 9 tutorial?
Offline
This is the day 9 tutorial:
http://grrlib.santo.fr/wiki/wikka.php?wakka=Day9
Of course, it works if I give the vector values in main(), but this is not what I want. In adittion, I need 640 different vectors - too much to be defined.
Last edited by Kadede (2009-06-26 23:59:59)
Offline
Kadede wrote:
This is the day 9 tutorial:
http://grrlib.santo.fr/wiki/wikka.php?wakka=Day9
This an old GRRLIB 3.0.1 alpha tutorial.
Would it be easier to create an array of struct?
typedef struct { int Count; int Position; int Something; } MyArray; MyArray grafica[640];
I not sure yet I understand what you want to do!
Offline
hi Crayon,
From what i know, Vector is something like this :
typedef struct
{
int x;
int y;
int z;
} Vector;
so...
Offline
NoNameNo wrote:
hi Crayon,
From what i know, Vector is something like this :
typedef struct
{
int x;
int y;
int z;
} Vector;
so...
It's almost that
That's what I just found in gu.h
typedef struct _vecf { f32 x,y,z; } Vector;
Offline
Crayon and Nonameno, really thanks for the help. Finally I solved it by this way:
grc++; grafica[grc]=distance; for(i=0; i<640; i++){ GRRLIB_Plot(i, grafica[i], 0xFFFFFFFF); } if(grc==640)grc=0;
It is simplier and easier. Thanks again.
EDIT:
This way better:
grc++; grafica[grc]=480-distance; for(i=0; i<640; i++){ if(grafica[i]!=0)GRRLIB_Line(i, grafica[i], i-1, grafica[i+-1], 0x00FF00FF); } if(grc==640)grc=0;
Last edited by Kadede (2009-06-27 00:49:58)
Offline
The other way around would have been:
Vector vTemp; vTemp.x = grc; vTemp.y = distance; vTemp.z = 0.0f; grafica[grc] = vTemp; GRRLIB_NPlot(grafica, 0xFFFFFFFF, 640);
Offline
Crayon wrote:
That's what I just found in gu.h
Code:
typedef struct _vecf { f32 x,y,z; } Vector;
19 hours ago the Vector structure was change to guVector to avoid collisions.
Changes could be seen on this page: http://devkitpro.svn.sourceforge.net/vi … mp;r2=3650
Offline
according to this i think grrlib need a little update...
Offline