Chapter 3 user interface and Interactive Technology User Interface Design
3.1 User Interface Design
A good graphic user interface should have the following features:
Easy to understand and accept by users;
Easy to operate and use;
High efficiency, reliability and practicability.
Consistency principle:
The consistency principle means that unified and simple rules should be followed in all aspects of the system design to ensure that no exceptions or special circumstances occur, regardless of information display or command input.
It is more important to do it in a way that the user thinks is the most normal and logical.
Reduce memory volume:
Operations on user interfaces should be easily understood and remembered.
The important principle is to wake up user recognition rather than memory.
Logical Input Device -- pickup device
Pickup device: the pickup device is used to select the part to be modified, edited, and processed in the scenario.
3.2 omitted
3.3 Interactive Drawing Technology
Basic Interactive Drawing Technology:
Explicit display constraint mesh gravity field rubber band technical drafting technology drag rotation Deformation
3D Interaction Technology:
3D image data input
3D Positioning
3D Orientation
3.4 OpenGL Implementation of rubber band technology
Implementation of rubber band technology:
By using different colors or operations, the original image is not erased, but a straight line segment is drawn and operated differently or with the original image. At this time, the original image disappears from the screen;
The dual-cache technology is used to draw two caches respectively when drawing the image and display them alternately.
Mouse implementation
Mouse Response Function
Glumousefunc
Move the corresponding function with the mouse
Glumotionfunc
Glupassivemotionfunc
Keyboard implementation
Keyboard Functions
Glukeyboardfunc
3.5 OpenGL
Set the pickup Buffer
Void glselectbuffer (glsizei N, glunint * buff );
Enter the selection mode
Glint glrendermode (glenum mode );
Name stack operation
Initialize the name stack (glinitnames)
Push a name into the stack (glpushname)
Replace glloadname)
Pop up the top element of the stack (glpopname)
Set the appropriate conversion process
Glupickmatrix (xpick, ypick, widthpick, heightpick, * vp );
Assign a name for each element and draw it
Switch back to rendering Mode
Analyze Data in the selected Buffer
3.6 menu functions in OpenGL
Menu registration function
Glucreatemenu (processmenu );
Add a menu item
Void gluaddmenuentry (char * Name, glint value );
Associate a menu with a mouse button
Void maid (button );
# Include <Gl/glut. h>
Int ipointnum = 0; // Number of vertices that have been determined
Int X1 = 0, X2 = 0, Y1 = 0, y2 = 0; // determined Coordinate
Int winwidth = 400, winheight = 300; // the width and height of the window
Void initial (void)
{
Glclearcolor (1.0f, 1.0f, 1.0f, 1.0f );
}
Void changesize (int w, int H)
{
Winwidth = W; winheight = h;
Glviewport (0, 0, W, H); // specify the display area of the window.
Glmatrixmode (gl_projection); // sets the projection parameter.
Glloadidentity ();
Gluortho2d (0.0, winwidth, 0.0, winheight );
}
Void display (void)
{
Glclear (gl_color_buffer_bit );
Glcolor3f (1.0f, 0.0f, 0.0f );
If (ipointnum> = 1 ){
Glbegin (gl_lines); // draw a line segment
Glvertex2i (x1, Y1 );
Glvertex2i (X2, Y2 );
Glend ();
}
Gluswapbuffers (); // swap Buffer
}
Void mouseplot (glint button, glint action, glint xmouse, glint ymouse)
{
If (Button = maid & Action = maid ){
If (ipointnum = 0 | ipointnum = 2 ){
Ipointnum = 1;
X1 = xmouse; Y1 = winheight-ymouse;
}
Else {
Ipointnum = 2;
X2 = xmouse; y2 = winheight-ymouse;
Glupostredisplay (); // specify the redraw window
}
}
If (Button = maid & Action = maid ){
Ipointnum = 0;
Glupostredisplay ();
}
}
Void passivemousemove (glint xmouse, glint ymouse)
{
If (ipointnum = 1 ){
X2 = xmouse;
Y2 = winheight-ymouse;
Glupostredisplay ();
}
}
Int main (INT argc, char * argv [])
{
Gluinit (& argc, argv );
Fig; // uses the dual cache and RGB model
Gluinitwindowsize (400,300 );
Gluinitwindowposition (100,100 );
Ngcreatewindow ("rubber band technology ");
Gludisplayfunc (Display );
Glureshapefunc (changesize); // specifies the callback function of the window in the integer.
Glumousefunc (mouseplot); // specifies the mouse response function.
Glupassivemotionfunc (passivemousemove); // specifies the response function for moving the mouse
Initial ();
Glumainloop ();
Return 0;
}
# Include <Gl/glut. h>
Int ipointnum = 0; // Number of vertices that have been determined
Int X1 = 0, X2 = 0, Y1 = 0, y2 = 0; // determined Coordinate
Int winwidth = 400, winheight = 300; // the width and height of the window
Void initial (void)
{
Glclearcolor (1.0f, 1.0f, 1.0f, 1.0f );
}
Void changesize (int w, int H)
{
Winwidth = W; winheight = h;
Glviewport (0, 0, W, H); // specify the display area of the window.
Glmatrixmode (gl_projection); // sets the projection parameter.
Glloadidentity ();
Gluortho2d (0.0, winwidth, 0.0, winheight );
}
Void display (void)
{
Glclear (gl_color_buffer_bit );
Glcolor3f (1.0f, 0.0f, 0.0f );
If (ipointnum> = 1 ){
Glbegin (gl_lines); // draw a line segment
Glvertex2i (x1, Y1 );
Glvertex2i (X2, Y2 );
Glend ();
}
Gluswapbuffers (); // swap Buffer
}
Void passivemousemove (glint xmouse, glint ymouse)
{
If (ipointnum = 1 ){
X2 = xmouse;
Y2 = winheight-ymouse;
Glupostredisplay ();
}
}
Void key (unsigned char key, int X, int y)
{
Switch (key ){
Case 'p ':
If (ipointnum = 0 | ipointnum = 2 ){
Ipointnum = 1;
X1 = x; Y1 = winheight-y;
}
Else {
Ipointnum = 2;
X2 = x; y2 = winheight-y;
Glupostredisplay ();
}
Break;
Default: break;
}
}
Int main (INT argc, char * argv [])
{
Gluinit (& argc, argv );
Fig; // uses the dual cache and RGB model
Gluinitwindowsize (400,300 );
Gluinitwindowposition (100,100 );
Ngcreatewindow ("rubber band technology ");
Gludisplayfunc (Display );
Glureshapefunc (changesize); // specifies the callback function of the window in the integer.
Glukeyboardfunc (key); // specifies the keyboard response function.
Glupassivemotionfunc (passivemousemove); // specifies the response function for moving the mouse
Initial ();
Glumainloop ();
Return 0;
}
# Include <Gl/glut. h>
# Include "stdio. H"
Const glint picksize = 32;
Int winwidth = 400, winheight = 300;
Void initial (void)
{
Glclearcolor (1.0f, 1.0f, 1.0f, 1.0f );
}
Void drawrect (glenum Mode)
{
If (mode = gl_select) glpushname (1); // press the stack
Glcolor3f (1.0f, 0.0f, 0.0f );
Glrectf (600000f, 500000f, 1500000f, 1500000f );
If (mode = gl_select) glpushname (2); // press the stack
Glcolor3f (0.0f, 1.0f, 0.0f );
Glrectf (2300000f, 500000f, 3300000f, 1500000f );
If (mode = gl_select) glpushname (3); // press the stack
Glcolor3f (0.0f, 0.0f, 1.0f );
Glrectf (1400000f, 1400000f, 240.0f, 240.0f );
}
Void processpicks (glint npicks, gluint pickbuffer [])
{
Glint I;
Gluint name, * PTR;
Printf ("the selected number is % d/N", npicks );
PTR = pickbuffer;
For (I = 0; I <npicks; I ++ ){
Name = * PTR; // position of the selected element in the stack
PTR + = 3; // skip the name and depth information
PTR + = Name-1; // obtain the name of the selected element based on the Location Information
If (* PTR = 1) printf ("you have selected the red element/N ");
If (* PTR = 2) printf ("you have selected the green element/N ");
If (* PTR = 3) printf ("you have selected the blue element/N ");
PTR ++;
}
Printf ("/n ");
}
Void changesize (int w, int H)
{
Winwidth = W;
Winheight = h;
Glviewport (0, 0, W, H );
Glmatrixmode (gl_projection );
Glloadidentity ();
Gluortho2d (0.0, winwidth, 0.0, winheight );
}
Void display (void)
{
Glclear (gl_color_buffer_bit );
Drawrect (gl_render );
Glflush ();
}
Void mouseplot (glint button, glint action, glint xmouse, glint ymouse)
{
Gluint pickbuffer [picksize];
Glint npicks, VP [4];
If (Button = maid & Action = maid ){
Glselectbuffer (picksize, pickbuffer); // you can specify a buffer.
Glrendermode (gl_select); // activate the selection mode
Glinitnames (); // initialize the name Stack
Glmatrixmode (gl_projection );
Glpushmatrix ();
Glloadidentity ();
Glgetintegerv (gl_viewport, vp );
// Define a 10*10 selection area
Glupickmatrix (gldouble (xmouse), gldouble (VP [3]-ymouse), 10.0, 10.0, vp );
Gluortho2d (0.0, winwidth, 0.0, winheight );
Drawrect (gl_select );
// Restore the Projection Transformation
Glmatrixmode (gl_projection );
Glpopmatrix ();
Glflush ();
// Obtain and output the selection set
Npicks = glrendermode (gl_render );
Processpicks (npicks, pickbuffer );
Glupostredisplay ();
}
}
Int main (INT argc, char * argv [])
{
Gluinit (& argc, argv );
Fig );
Gluinitwindowsize (400,300 );
Gluinitwindowposition (100,100 );
Valley createwindow ("Pick Up Operation ");
Gludisplayfunc (Display );
Glureshapefunc (changesize );
Glumousefunc (mouseplot );
Initial ();
Glumainloop ();
Return 0;
}
An error occurred while compiling the final program in vs2005:
Error 1 error c2057: Expected constant expression E:/VC/opengl1/opengl1/OpenGL. C 65
Error 2 error c2466: cannot allocate an array of constant size 0 E:/VC/opengl1/opengl1/OpenGL. C 65
Error 3 error c2133: 'pickbuffer': Unknown size E:/VC/opengl1/opengl1/OpenGL. C 65
Error 4 error c2143: syntax error: Missing ') 'before' type 'e:/VC/opengl1/opengl1/OpenGL. c 78
Error 5 Error c2198: 'glupickmatrix ': Too few arguments for call E:/VC/opengl1/opengl1/OpenGL. c 78
Modify two items:
1. gluint pickbuffer [32]; // [picksize];
2. glupickmatrix (gldouble) xmouse, (gldouble) (VP [3]-ymouse), 10.0, 10.0, vp );