/[hegemonie]/hegemonie/MapEditor/MapView.m
ViewVC logotype

Diff of /hegemonie/MapEditor/MapView.m

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by gabby, Wed Aug 6 16:30:53 2003 UTC revision 1.9 by gabby, Thu Aug 14 15:22:16 2003 UTC
# Line 47  double _camZFar = 255.0; Line 47  double _camZFar = 255.0;
47    
48  const GLfloat lightAmbient[4] = {0.75f, 0.75f, 0.75f, 1.0f};  const GLfloat lightAmbient[4] = {0.75f, 0.75f, 0.75f, 1.0f};
49  const GLfloat lightDiffuse[4] = {0.7f, 0.7f, 0.7f, 1.0f};  const GLfloat lightDiffuse[4] = {0.7f, 0.7f, 0.7f, 1.0f};
50  const GLfloat lightPosition[4] = {0.0f, 2350.0f, 0.0f};  const GLfloat lightPosition[4] = {0.0f, 350.0f, 0.0f};
51  const GLfloat fogColor[4]= {1.0f, 1.0f, 1.0f, 1.0f};  const GLfloat fogColor[4]= {1.0f, 1.0f, 1.0f, 1.0f};
52    
53  - (id) initWithFrame: (NSRect)frameRect  - (id) initWithFrame: (NSRect)frameRect
# Line 60  const GLfloat fogColor[4]= {1.0f, 1.0f, Line 60  const GLfloat fogColor[4]= {1.0f, 1.0f,
60        _init = NO;        _init = NO;
61        _display = NO;        _display = NO;
62        _displayBorder = YES;        _displayBorder = YES;
63        _mouseLoc.x = 0;        _mouseLoc.x = 0.0;
64        _mouseLoc.y = 0;        _mouseLoc.y = 0.0;
65        printf("INIT MapView\n");        printf("INIT MapView\n");
66      }        }  
67    return self;    return self;
# Line 85  const GLfloat fogColor[4]= {1.0f, 1.0f, Line 85  const GLfloat fogColor[4]= {1.0f, 1.0f,
85    
86    glShadeModel (GL_SMOOTH);    glShadeModel (GL_SMOOTH);
87    
88    //glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);    glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);
89    glHint (GL_POLYGON_SMOOTH_HINT, GL_FASTEST);    //glHint (GL_POLYGON_SMOOTH_HINT, GL_FASTEST);
90    //glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);    glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
91    glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);    //glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
92    
93    [NSTimer scheduledTimerWithTimeInterval: 0.001    [NSTimer scheduledTimerWithTimeInterval: 0.001
94                                     target: self                                     target: self
# Line 115  const GLfloat fogColor[4]= {1.0f, 1.0f, Line 115  const GLfloat fogColor[4]= {1.0f, 1.0f,
115  {  {
116    NSParameterAssert (_map);    NSParameterAssert (_map);
117    glDisable(GL_LIGHTING);    glDisable(GL_LIGHTING);
   //glEnable(GL_LIGHTING);  
118    glLineWidth(2.0);    glLineWidth(2.0);
119    
120    int xLength = [_map xLength];    int xLength = [_map xLength];
# Line 123  const GLfloat fogColor[4]= {1.0f, 1.0f, Line 122  const GLfloat fogColor[4]= {1.0f, 1.0f,
122    
123    glEnable (GL_DEPTH_TEST);    glEnable (GL_DEPTH_TEST);
124    
125      glBegin(GL_LINE_LOOP);    glBegin(GL_LINE_LOOP);
126        glColor3f(1.0,0.0,0.0);    glColor3f(1.0,0.0,0.0);
127      
128        int x;    int x;
129        for (x = 0; x < xLength; x++)    for (x = 0; x < xLength; x++)
130          glVertex3i(x, [_map heightAtPosition: MakeMapCoord (x, 0)] + 1, 0);      glVertex3i(x, [_map heightAtPosition: MakeMapCoord (x, 0)] + 1, 0);
131      
132        int z;    int z;
133        for (z = 0; z < zLength; z++)    for (z = 0; z < zLength; z++)
134          glVertex3i(x, [_map heightAtPosition: MakeMapCoord (x, z)] + 1, z);      glVertex3i(x, [_map heightAtPosition: MakeMapCoord (x, z)] + 1, z);
135      
136        for (x = xLength-1; x >= 0; x--)    for (x = xLength-1; x >= 0; x--)
137          glVertex3i(x, [_map heightAtPosition: MakeMapCoord (x, z)] + 1, z);      glVertex3i(x, [_map heightAtPosition: MakeMapCoord (x, z)] + 1, z);
138      
139        for (z = zLength-1; z >= 0; z--)    for (z = zLength-1; z >= 0; z--)
140          glVertex3i(0, [_map heightAtPosition: MakeMapCoord (0, z)] + 1, z);      glVertex3i(0, [_map heightAtPosition: MakeMapCoord (0, z)] + 1, z);
141      glEnd();    glEnd();
142      
143      //glDisable(GL_LIGHTING);    glLineWidth(1.0);
144      //glEnable(GL_LIGHTING);    glDisable (GL_DEPTH_TEST);
145      glLineWidth(1.0);    glEnable(GL_LIGHTING);
     glDisable (GL_DEPTH_TEST);  
146  }  }
147    
148  - (void) _displayCursorPosition  - (void) _displayCursorPosition
# Line 156  const GLfloat fogColor[4]= {1.0f, 1.0f, Line 154  const GLfloat fogColor[4]= {1.0f, 1.0f,
154    NSRect sceneBounds = [self bounds];    NSRect sceneBounds = [self bounds];
155    double l = sceneBounds.size.width;    double l = sceneBounds.size.width;
156    double h = sceneBounds.size.height;    double h = sceneBounds.size.height;
157    printf ("l %lf h %lf\n" ,l,h);    //  printf ("l %lf h %lf\n" ,l,h);
158    
159    coord_t camEye = [_camera eye];    coord_t camEye = [_camera eye];
160    
# Line 178  const GLfloat fogColor[4]= {1.0f, 1.0f, Line 176  const GLfloat fogColor[4]= {1.0f, 1.0f,
176  //   _mouseMap.y = sqrt(SQUARE(downLeft.y) + SQUARE(upRight.y))  //   _mouseMap.y = sqrt(SQUARE(downLeft.y) + SQUARE(upRight.y))
177  //                 * _mouseLoc.y / h + downLeft.y + 90.0;  //                 * _mouseLoc.y / h + downLeft.y + 90.0;
178    
179    printf("\n\n mouseLoc %lf %lf\n", _mouseLoc.x, _mouseLoc.y);    // printf("\n\n mouseLoc %lf %lf\n", _mouseLoc.x, _mouseLoc.y);
180    printf ("_mouseMap %lf %lf\n" ,_mouseMap.x, _mouseMap.y);    //printf ("_mouseMap %lf %lf\n" ,_mouseMap.x, _mouseMap.y);
   
   
   glDisable(GL_LIGHTING);  
   glDisable (GL_DEPTH_TEST);  
   glLineWidth(2.0);  
   
   glBegin(GL_LINES);  
   glColor3f(1.0,0.0,0.0);  
   
   //horizontal line  
   glVertex3f(_mouseMap.y, 0, downLeft.x);  
   glVertex3f(_mouseMap.y, 0, upRight.x);  
   
   //vertical line  
   glColor3f(0.0,1.0,0.0);  
   glVertex3f(downLeft.y, 0, _mouseMap.x);  
   glVertex3f(upRight.y,  0, _mouseMap.x);  
   
   glEnd();  
181    
182    glLineWidth(1.0);    if (_editingMap)
183        {
184          glDisable(GL_LIGHTING);
185          glDisable (GL_DEPTH_TEST);
186          glLineWidth(2.0);
187          
188          glBegin(GL_LINES);
189          glColor3f(1.0,0.0,0.0);
190          
191          //horizontal line
192          glVertex3f(_mouseMap.y, 0, downLeft.x);
193          glVertex3f(_mouseMap.y, 0, upRight.x);
194          
195          //vertical line
196          glColor3f(0.0,1.0,0.0);
197          glVertex3f(downLeft.y, 0, _mouseMap.x);
198          glVertex3f(upRight.y,  0, _mouseMap.x);
199          
200          glEnd();      
201          glLineWidth(1.0);
202          glEnable(GL_LIGHTING);
203        }
204  }  }
205    
206  - (map_coord_t) positionOnTerrain  - (map_coord_t) positionOnTerrain
# Line 239  const GLfloat fogColor[4]= {1.0f, 1.0f, Line 239  const GLfloat fogColor[4]= {1.0f, 1.0f,
239        glClearColor(0.,0.,0.,1.0);        glClearColor(0.,0.,0.,1.0);
240        glClear(GL_COLOR_BUFFER_BIT);        glClear(GL_COLOR_BUFFER_BIT);
241        glClearColor(fogColor[0], fogColor[1], fogColor[2], fogColor[3]);        glClearColor(fogColor[0], fogColor[1], fogColor[2], fogColor[3]);
242    
243          glEnable(GL_LIGHTING);
244          glEnable(GL_LIGHT0);
245    
246        _init = YES;        _init = YES;
247      }      }
248    
# Line 247  const GLfloat fogColor[4]= {1.0f, 1.0f, Line 251  const GLfloat fogColor[4]= {1.0f, 1.0f,
251        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
252        glLoadIdentity();        glLoadIdentity();
253    
254        glEnable(GL_LIGHTING);         if (!_enableTexture)
       glEnable(GL_LIGHT0);  
       if (!_enableTexture)  
255          {          {
256            //glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);            //glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
257            //glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);            //glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);
# Line 266  const GLfloat fogColor[4]= {1.0f, 1.0f, Line 268  const GLfloat fogColor[4]= {1.0f, 1.0f,
268                   (GLdouble)[_camera up].y,                   (GLdouble)[_camera up].y,
269                   (GLdouble)[_camera up].z);                   (GLdouble)[_camera up].z);
270    
271        // printf ("viewTop %d\n", _viewTop);        if (_moveMap)
272        //NSLog (@" camera %@ \n", _camera);          {
273              double coef = 7.0;
274              NSPoint _mouseMapOld = _mouseMap;
275              [self _displayCursorPosition];
276              double sign = (_mouseMap.y - _mouseMapOld.y > 0.0 ? 1.0 : -1.0);
277              if (_mouseMap.y - _mouseMapOld.y != 0.0)
278                [_camera moveUp: coef * sign];
279              sign = (_mouseMap.x - _mouseMapOld.x > 0.0 ? 1.0 : -1.0);
280              if (_mouseMap.x - _mouseMapOld.x != 0.0)
281                [_camera strafRight: coef * sign];
282    
283    //        double coef = 10.0;
284    //        NSPoint _mouseLocOld = _mouseLoc;
285    //        [self _displayCursorPosition];
286    //        double sign = (_mouseLoc.y - _mouseLocOld.y > 0.0 ? 1.0 : -1.0);
287    //        if (_mouseLoc.y - _mouseLocOld.y != 0.0)
288    //          [_camera moveUp: coef * sign];
289    //        sign = (_mouseLoc.x - _mouseLocOld.x > 0.0 ? 1.0 : -1.0);
290    //        if (_mouseLoc.x - _mouseLocOld.x != 0.0)
291    //          [_camera strafRight: coef * sign];
292    
293    //        [_camera moveTo: MakeCoord
294    //                 (_mouseMap.y / coef + _mouseMap.y,
295    //                  [_camera eye].y,
296    //                  _mouseMap.x / coef + _mouseMap.x)];
297            }
298    
299        if (_viewTop)        if (_viewTop)
300          [_map displayWithCamera: _camera          [_map displayWithCamera: _camera
301                      numberOfRay: _nbRay];                      numberOfRay: _nbRay];
# Line 279  const GLfloat fogColor[4]= {1.0f, 1.0f, Line 307  const GLfloat fogColor[4]= {1.0f, 1.0f,
307        if (_displayBorder)        if (_displayBorder)
308          [self _displayMapBorder];          [self _displayMapBorder];
309    
310        if (_viewTop & _editingMap)              if (_editingMap)
311          [self _displayCursorPosition];          [self _displayCursorPosition];
312    
313        //NSPoint mouseLoc = [[self window] mouseLocationOutsideOfEventStream];        //NSPoint mouseLoc = [[self window] mouseLocationOutsideOfEventStream];
314        //NSPoint mouseLoc = [self mouseLocation];        //NSPoint mouseLoc = [self mouseLocation];
315        //printf("\n\n mouseLoc %lf %lf\n", mouseLoc.x, mouseLoc.y);        //printf("\n\n mouseLoc %lf %lf\n", mouseLoc.x, mouseLoc.y);
         
       glDisable(GL_LIGHTING);  
       glDisable(GL_LIGHT0);  
316      }      }
   
317    [self update];    [self update];
318    [[self openGLContext] flushBuffer];    [[self openGLContext] flushBuffer];
319  }  }
# Line 306  const GLfloat fogColor[4]= {1.0f, 1.0f, Line 330  const GLfloat fogColor[4]= {1.0f, 1.0f,
330    _map = TEST_RETAIN (map);    _map = TEST_RETAIN (map);
331  }  }
332    
 - (void) swapTextureColor  
 {  
   //_enableTexture = [_map isTexturesEnable];  
   _enableTexture = !_enableTexture;  
 }  
   
333  - (void) displayTerrain: (BOOL)display  - (void) displayTerrain: (BOOL)display
334  {  {
335    _enableTexture = [_map isTexturesEnable];    _enableTexture = [_map isTexturesEnable];
# Line 332  const GLfloat fogColor[4]= {1.0f, 1.0f, Line 350  const GLfloat fogColor[4]= {1.0f, 1.0f,
350    _editingMap = editingMap;    _editingMap = editingMap;
351  }  }
352    
353    - (void) setMoveMap: (BOOL)moveMap
354    {
355      _moveMap = moveMap;
356    }
357    
358  - (void) displayMapBorder  - (void) displayMapBorder
359  {  {
360    _displayBorder = !_displayBorder;    _displayBorder = !_displayBorder;
# Line 397  const GLfloat fogColor[4]= {1.0f, 1.0f, Line 420  const GLfloat fogColor[4]= {1.0f, 1.0f,
420    
421  - (void) mouseDown: (NSEvent *)theEvent  - (void) mouseDown: (NSEvent *)theEvent
422  {  {
423    _mouseLoc = [theEvent locationInWindow];    //_mouseLoc = [theEvent locationInWindow];
424      _mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
425    //printf("\n\n mouseLoc %lf %lf\n", _mouseLoc.x, _mouseLoc.y);            //printf("\n\n mouseLoc %lf %lf\n", _mouseLoc.x, _mouseLoc.y);        
   //_displayCursor = YES;  
426    //printf("mouse NSLeftMouseDown\n");    //printf("mouse NSLeftMouseDown\n");
427  }  }
428    
429  - (void)mouseDragged: (NSEvent *) theEvent  - (void)mouseDragged: (NSEvent *) theEvent
430  {  {
431    _mouseLoc = [theEvent locationInWindow];    //_mouseLoc = [theEvent locationInWindow];
432    //printf("mouse NSLeftMouseDragged\n");    _mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
433      printf("mouse NSLeftMouseDragged\n");
434  }  }
435    
436  - (void) mouseUp: (NSEvent *)theEvent  - (void) mouseUp: (NSEvent *)theEvent
437  {  {
438    //printf("mouse NSLeftMouseUp\n");    //printf("mouse NSLeftMouseUp\n");
439    _mouseLoc = [theEvent locationInWindow];    //_mouseLoc = [theEvent locationInWindow];
440    //_displayCursor = NO;    _mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
441  }  }
442    
 //     return;  
 // }  
   
443  // - (void) mouseDown: (NSEvent *)theEvent  // - (void) mouseDown: (NSEvent *)theEvent
444  // {  // {
445  //   BOOL keepOn = YES;  //   BOOL keepOn = YES;
# Line 457  const GLfloat fogColor[4]= {1.0f, 1.0f, Line 478  const GLfloat fogColor[4]= {1.0f, 1.0f,
478  //                     /* Ignore any other kind of event. */  //                     /* Ignore any other kind of event. */
479  //                     break;  //                     break;
480  //         }  //         }
   
481  //     };  //     };
   
 //     return;  
   
 //   while (keepOn)  
 //     {  
 //     //theEvent = [[self window] nextEventMatchingMask: NSLeftMouseUpMask |  
 //     //         NSLeftMouseDraggedMask];  
   
 //     //mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil];  
 //       NSPoint mouseLoc = [theEvent locationInWindow];  
 //       printf("\n\n mouseLoc %lf %lf\n", mouseLoc.x, mouseLoc.y);  
   
 //       //NSLog (@" mouseLoc %@ \n", mouseLoc);  
 //       isInside = [self mouse:mouseLoc inRect:[self bounds]];  
   
 //       switch ([theEvent type])  
 //      {  
 //        //case NSMouseMoved:  
 //        [self _displayCursorPosition: [theEvent locationInWindow]];  
 //        break;  
 //      case NSLeftMouseUp:  
 //        if (isInside) //[self doSomethingSignificant];  
 //          printf("mouse\n");  
 //        printf(" mouseLoc %lf %lf\n", mouseLoc.x, mouseLoc.y);  
 //        keepOn = NO;  
 //        break;  
 //      default:  
 //        //  Ignore any other kind of event.  
 //          break;  
 //      }  
 //     }  
482  //     return;  //     return;
483  //}  //}
484    

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26