Sign in to follow this  
mggm

save mouse coordinates into .dat file

Recommended Posts

hi ! all my code is for drawing some thing on window through mouse am trying to save mouse locations in form of x,y coordinates in a .DAT file as but the problem is i am able to save not all continuous coordinates but only the last one,code is here //Headers #include <GL/glut.h> #include<stdio.h> #include<dos.h> #include <stdlib.h> #include <iostream.h> #include <fstream.h> //definitions #define passive 0 //Modes #define active 1 #define RMAX 1 const int wh=500,ww = 500; //Window wh, Window ww static int a[RMAX],b[RMAX]; int i; static int reportw; static int repw; GLubyte rasters[24] = { 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xff, 0x00, 0xff, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xff, 0xc0, 0xff, 0xc0 }; //Function Prototypes void display(); void reshape(GLsizei, GLsizei); void init(); void meradisplay(int ,int); void mousekamotion(int, int); void Display(int a[],int b[]); void send(int x, int y); void isplay(void); void minit(void); void diskoplay(void); void rereshape(int w, int h); void Risplay(void); static void myinit(void); void static reshape(int w, int h); void mouse(int button, int state, int x, int y); void keyboard(unsigned char key, int x, int y); int mai(int x,int y); //////////////////////////////////////////////////// //Function Definitions //-------------------------- void diskoplay(void) { glClear(GL_COLOR_BUFFER_BIT); glColor3f (1.0, 1.0, 1.0); glRasterPos2i (20, 20); glBitmap (10, 12, 0.0, 0.0, 11.0, 0.0, rasters); glBitmap (10, 12, 0.0, 0.0, 11.0, 0.0, rasters); glBitmap (10, 12, 0.0, 0.0, 11.0, 0.0, rasters); glFlush(); } //------------------------------------ void rereshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho (0, w, 0, h, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); } //------------------------------------- void Risplay(void) { printf("bye buddy%h",'F'); {glClearColor (0.0, 0.0, 0.0, 0.0); glColor3i(1,1,1); glPointSize(9.0); glBegin(GL_LINE_LOOP); glVertex2f(0.5,0.5); glVertex2f(10.5,10.5); glVertex2f(20.5,20.5); glVertex2f(60.5,60.5); glEnd(); } } /* static void reshape(int w, int h) //shared / { ww = w; wh = h; glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (w <= h) glOrtho (-1.0, 1.0, -1.0*(GLfloat)h/(GLfloat)w, 1.0*(GLfloat)h/(GLfloat)w, -1.0, 1.0); else glOrtho (-1.0*(GLfloat)w/(GLfloat)h, 1.0*(GLfloat)w/(GLfloat)h, -1.0, 1.0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity (); glEnable(GL_DEPTH_TEST); } end reshape static void controlReshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, (float)ww, 0.0, (float)wh); all at z=0 glMatrixMode(GL_MODELVIEW); glLoadIdentity (); }*/ //---------------------------------- static void myinit(void) { glClearColor (1.0, 1.0, 1.0, 1.0); glColor3f (0.0, 0.0, 0.0); } //------------------------------------- void static reshape(int w, int h) { /* set the whole window as a viewport */ glViewport(0, 0, w, h); /* initialize the transform matrix */ glLoadIdentity(); /* re-size the display area on the screen propotional to the viewport */ glOrtho(-w / 200.0, w / 200.0, -h / 200.0, h / 200.0, -1.0, 1.0); } //---To detect and send to diplay of pen location---- void mouse(int button, int state, int x, int y) { switch (button) { case GLUT_LEFT_BUTTON: printf("Left"); break; case GLUT_MIDDLE_BUTTON: printf("Middle"); break; case GLUT_RIGHT_BUTTON: printf("Right"); break; default: break; } printf(" button is:\t"); switch (state) { case GLUT_UP: printf("up\n"); break; case GLUT_DOWN: printf("down\n"); break; default: break; } printf("\nThere is a new Vertex introduced"); printf(" at: \t(%d, %d)\n", x, y); } //--------------------------------------- void meradisplay(int xmin,int ymin) { glColor3f(1.0,1.0,1.0); // Pen POINT WITH whITE INK glPointSize(4.0); //the tip parameter of pen point is size of 4.0 glBegin(GL_POINTS); glVertex2i(xmin,ymin); //printf(" mera display\t%d and \t%d\n\n", xmin,wh-ymin); glEnd(); glFlush(); //usefull for network client based applications to complete //the execution in finite time } //---------------------------------- void send(int xmin, int ymin) { //for(i=0;i<10;i++) a[i]=xmin; b[i]=ymin; //Display(a,b); printf(" Edge Coordinates r:\t %d\t %d\n", a[i],wh-b[i]); i++; //mai(xmin); glutDisplayFunc(isplay); } //------------------------------- void isplay(void) { glClearColor(1,1,1,1); glBegin(GL_POINTS); glColor3i(0,0,0); glVertex2i(a[i],b[i]); glEnd(); glFlush(); } //--------------------------------- void mousekamotion(int mousex, int mousey) { GLint x = mousex; GLint y = wh - mousey; // coordinates for mouse movement //origin is left down corner of window meradisplay(x,y); //glutMouseFunc(mouse); // printf(" mousekamotion\t%d and \t%d\n\n", x,mousey); //printf("\n\n\t\t\aHI Ye Kye Hei\t\t\a\a\n\n"); send(x,y); mai(x,wh-mousey); } //-- To display the Window ----------- //////////////////////////////////////////////////////// void display(void) {} //-- To display what ever is being drawn on screen --- /////////////////////////////////////////////////////////// //----------------------------------------------------- //Initialization of all prosess to Draw a Window void init(void) { glMatrixMode(GL_PROJECTION); // sets the current matrix mode. glLoadIdentity(); glOrtho(0.0, (GLdouble)ww,0.0 , (GLdouble)wh,-1.0,1.0); glClearColor(0.0,0.0,0.0,0.0); // the background Color is set to BLaCK glClear(GL_COLOR_BUFFER_BIT); } //----------------------------------- void minit(void) { glPixelStorei (GL_UNPACK_ALIGNMENT, 1); glClearColor (0.0, 0.0, 0.0, 0.0); } //----------------------------------- void Quit(int value) { if (value == 666) exit(0); if(value == 777) // printf("\nHi kya bukvass\n"); glClearColor (1.0, 1.0, 1.0, 1.0); else init(); } //-------------------------------- void keyboard(unsigned char key, int x, int y) { switch (key) { case 69: case 101: exit(0); } } //---------------------------------------- //////////////////////////////////////////////// ////////////////////////////////////////////// int main(int argc, char* argv[]) { printf("\t\t hi budyy \n\n\t "); int mode = active,submenu; //initialization of Window glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowPosition(25,wh-450); glutInitWindowSize(ww,wh); repw=glutCreateWindow("Draw what u want : MggM"); myinit(); glutKeyboardFunc(keyboard); glutDisplayFunc(display); glutMouseFunc(mouse); glutMotionFunc(mousekamotion); submenu = glutCreateMenu(Quit); glutAddMenuEntry("Quit lye Baap", 666); glutAddMenuEntry("UnDo", 777); // glutAddSubMenu("Polygon mode", submenu); glutAttachMenu(GLUT_RIGHT_BUTTON); minit(); glutReshapeFunc(rereshape); glutDisplayFunc(diskoplay); init(); glutInitWindowPosition(25+ww,50); glutInitWindowSize(ww,wh); reportw=glutCreateWindow("report"); init(); glutKeyboardFunc(keyboard); glutDisplayFunc(Risplay); glutMouseFunc(mouse); /* ANSI C requires main to return int. */ init(); glutMainLoop(); return 0; } //END //----------------------------------------------- /* int ma(int x,int y) { char *p; p=x; ostrstream outt; outt<<x<<"\t"<<y<<"\n"; outt.setf(ios::showbase); outt<<100<<ends; p=outt.str(); cout<<p; //delete p; //.open("1.dat"); // cout<<"Record Data...." <<endl; // outs<<x<<"\t"<<y<<"\n"; // // outs.close(); ofstrstrea &flush(); return 0; } int mai(int x,int y) { ofstream outs; outs.open("1.dat"); cout<<"Record Data...." <<endl; outs<<x<<"\t"<<y<<"\n"; outs.close(); ofstream &flush(); return 0; } please help me out how should i do to save all coordinates traveled by mouse

Share this post


Link to post
Share on other sites
Nope - I don't get it. What are you really trying to do?
You already have a GlutMouseHandler - so you already have the ability to trap every mouse movement. What more do you want ?

If you need to have a faster sampling rate to fill in the gaps between each successive mouse event then why not perform a simple linear or cubic lerp between the last two (or three) mouse events.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this