/[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.4 by gabby, Fri Jul 18 14:57:55 2003 UTC revision 1.5 by gabby, Thu Jul 24 13:55:06 2003 UTC
# Line 40  Line 40 
40  int _nbRay = 70;  int _nbRay = 70;
41  double _lastStep = 4.0;  double _lastStep = 4.0;
42  int _mode = 1;  int _mode = 1;
43  int _viewTop = 1;  
44  double _camZFar = 255.0;  double _camZFar = 255.0;
45    
46  const GLfloat lightAmbient[] = { 0.75f, 0.75f, 0.75f, 1.0f };  const GLfloat lightAmbient[4] = {0.75f, 0.75f, 0.75f, 1.0f};
47  const GLfloat lightDiffuse[] = { 0.7f, 0.7f, 0.7f, 1.0f };  const GLfloat lightDiffuse[4] = {0.7f, 0.7f, 0.7f, 1.0f};
48  const GLfloat lightPosition[] = { 10.0f, 350.0f, 10.0f};  const GLfloat lightPosition[4] = {10.0f, 350.0f, 10.0f};
49    const GLfloat fogColor[4]= {1.0f, 1.0f, 1.0f, 1.0f};
50    
51    
52  - (id) initWithFrame: (NSRect)frameRect  - (id) initWithFrame: (NSRect)frameRect
# Line 57  const GLfloat lightPosition[] = { 10.0f, Line 58  const GLfloat lightPosition[] = { 10.0f,
58      {      {
59        _init = NO;        _init = NO;
60        _display = NO;        _display = NO;
61          printf("INIT MapView\n");
62      }        }  
63    return self;    return self;
64  }  }
65    
66  - (void) dealloc  - (void) dealloc
67  {  {
68    RELEASE(_camera);    printf("dealloc MapView \n");
69    RELEASE(_map);    TEST_RELEASE(_camera);
70      TEST_RELEASE(_map);
71    
72    [super dealloc];    [super dealloc];
73  }  }
# Line 90  const GLfloat lightPosition[] = { 10.0f, Line 93  const GLfloat lightPosition[] = { 10.0f,
93    
94    glShadeModel (GL_SMOOTH);    glShadeModel (GL_SMOOTH);
95    
   glFogi(GL_FOG_MODE, GL_LINEAR);  
   glFogf(GL_FOG_START, _camZFar - 10.0);  
   glFogf(GL_FOG_END, _camZFar + 1.0);  
   GLfloat fog_c[] = {0.5f, 0.5f, 0.5f, 1.0f};  
   glFogfv(GL_FOG_COLOR, fog_c);  
   if (!_viewTop)  
     glEnable(GL_FOG);  
   
96    //glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);    //glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);
97    glHint (GL_POLYGON_SMOOTH_HINT, GL_FASTEST);    glHint (GL_POLYGON_SMOOTH_HINT, GL_FASTEST);
98    //glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);    //glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
# Line 112  const GLfloat lightPosition[] = { 10.0f, Line 107  const GLfloat lightPosition[] = { 10.0f,
107    return YES;    return YES;
108  }  }
109    
110    - (void) setFogParameter
111    {
112      glClearColor(fogColor[0], fogColor[1], fogColor[2], fogColor[3]);
113      glFogi(GL_FOG_MODE, GL_LINEAR);
114      glFogf(GL_FOG_START, [_camera zFar] - 10.0);
115      glFogf(GL_FOG_END, [_camera zFar] + 1.0);
116      //GLfloat fog_c[] = {0.5f, 0.5f, 0.5f, 1.0f};
117      glFogfv(GL_FOG_COLOR, fogColor);
118    }
119    
120  - (void) reshape  - (void) reshape
121  {  {
122    NSRect sceneBounds;    NSRect sceneBounds;
# Line 140  const GLfloat lightPosition[] = { 10.0f, Line 145  const GLfloat lightPosition[] = { 10.0f,
145      {      {
146        [[self openGLContext] makeCurrentContext];        [[self openGLContext] makeCurrentContext];
147        [self initGL];        [self initGL];
148        [self reshape];        glClearColor(0.,0.,0.,1.0);
149          glClear(GL_COLOR_BUFFER_BIT);
150          glClearColor(fogColor[0], fogColor[1], fogColor[2], fogColor[3]);
151        _init = YES;        _init = YES;
152      }      }
153    
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  
   glLoadIdentity();  
   
154    if (_display)    if (_display)
155      {      {
156          glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
157          glLoadIdentity();
158    
159        glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);        glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
160    
161        gluLookAt ((GLdouble)[_camera eye].x,        gluLookAt ((GLdouble)[_camera eye].x,
# Line 161  const GLfloat lightPosition[] = { 10.0f, Line 168  const GLfloat lightPosition[] = { 10.0f,
168                   (GLdouble)[_camera up].y,                   (GLdouble)[_camera up].y,
169                   (GLdouble)[_camera up].z);                   (GLdouble)[_camera up].z);
170    
171          // printf ("viewTop %d\n", _viewTop);
172          //NSLog (@" camera %@ \n", _camera);
173        if (_viewTop)        if (_viewTop)
174          [_map displayWithCamera: _camera          [_map displayWithCamera: _camera
175                      numberOfRay: _nbRay];                      numberOfRay: _nbRay];
# Line 168  const GLfloat lightPosition[] = { 10.0f, Line 177  const GLfloat lightPosition[] = { 10.0f,
177          [_map displayWithCamera: _camera          [_map displayWithCamera: _camera
178                      numberOfRay: _nbRay                      numberOfRay: _nbRay
179                         lastStep: _lastStep];                         lastStep: _lastStep];
   
180      }      }
181    
182     [self update];    [self update];
183    [[self openGLContext] flushBuffer];    [[self openGLContext] flushBuffer];
184  }  }
185    
186  - (void) setCamera: (Camera *)camera  - (void) setCamera: (Camera *)camera
187  {  {
188    if (_camera)    TEST_RELEASE (_camera);
189      RELEASE (_camera);    _camera = TEST_RETAIN (camera);
   
   _camera = RETAIN (camera);  
190  }  }
191    
192  - (void) setTerrain: (MapDisplay *)map  - (void) setTerrain: (MapDisplay *)map
193  {  {
194    if (_map)    TEST_RELEASE (_map);
195      RELEASE (_map);    _map = TEST_RETAIN (map);
196      //  printf("setTerrain\n");
   _map = RETAIN (map);  
197  }  }
198    
199  - (void) displayTerrain: (BOOL)display  - (void) displayTerrain: (BOOL)display
# Line 196  const GLfloat lightPosition[] = { 10.0f, Line 201  const GLfloat lightPosition[] = { 10.0f,
201    _display = display;    _display = display;
202  }  }
203    
204    - (void) setViewTop: (BOOL)viewTop
205    {
206      _viewTop = viewTop;
207      if (_viewTop)
208        glDisable (GL_FOG);
209      else
210        glEnable (GL_FOG);
211    
212    }
213    
214    // - (void) displayMapBorder
215    // {
216    //    repere=glGenLists(1);
217    //   glNewList(repere,GL_COMPILE);
218    //   glDisable(GL_LIGHTING);
219    //   glLineWidth(2.0);
220    //     glBegin(GL_LINES);
221    //       glColor3f(1.0,0.0,0.0);
222    //       glVertex3f(0.0,200.0,0.0);
223    //       glVertex3f(3.0,200.0,0.0);
224    
225    //       glColor3f(0.0,1.0,0.0);
226    //       glVertex3f(0.0,200.0,0.0);
227    //       glVertex3f(0.0,203.0,0.0);
228    
229    //       glColor3f(0.0,0.0,1.0);
230    //       glVertex3f(0.0,200.0,0.0);
231    //       glVertex3f(0.0,200.0,3.0);
232    //     glEnd();
233    //     glEnable(GL_LIGHTING);
234    //     glLineWidth(1.0);
235    //   glEndList();
236    // }
237    
238  - (BOOL) performKeyEquivalent: (NSEvent *)theEvent  - (BOOL) performKeyEquivalent: (NSEvent *)theEvent
239  {  {
240    NSString *keyString;    NSString *keyString;
241    unichar keyChar;    unichar keyChar;
   double f = 3.0;  
   double h = 1.0;  
   double p = 1.0;  
242    double l = 0.2;    double l = 0.2;
243    
244    if (_display)    if (_display)
245      {    {
246        keyString = [theEvent charactersIgnoringModifiers];        keyString = [theEvent charactersIgnoringModifiers];
247        keyChar = [keyString characterAtIndex:0];        keyChar = [keyString characterAtIndex:0];
248    
249        switch(keyChar)        switch(keyChar)
250          {          {        
         case NSUpArrowFunctionKey:  
         case 'z':  
           [_camera forward: f];  
           break;  
             
         case NSDownArrowFunctionKey:  
         case 's':  
           [_camera backward: f];  
           break;  
             
         case NSLeftArrowFunctionKey:  
         case 'q':  
           [_camera strafLeft: f];  
           break;  
             
         case NSRightArrowFunctionKey:  
         case 'd':  
           [_camera strafRight: f];  
           break;  
             
         case NSPageUpFunctionKey:  
         case 'a':  
           [_camera moveUp: f];  
           break;  
             
         case NSPageDownFunctionKey:  
         case 'e':  
           [_camera moveDown: f];  
           break;  
             
         case '4':  
           [_camera rotateHeading: h];  
           break;  
         case '6':  
           [_camera rotateHeading: -h];  
           break;  
         case '8':  
           [_camera rotatePitch: p];  
           break;  
         case '2':  
           [_camera rotatePitch: -p];  
           break;  
             
251          case 'f':          case 'f':
252            _mode = 1 - _mode;            _mode = 1 - _mode;
253            if (_mode)            if (_mode)
# Line 285  const GLfloat lightPosition[] = { 10.0f, Line 278  const GLfloat lightPosition[] = { 10.0f,
278            printf("lastStep: %lf\n", _lastStep);            printf("lastStep: %lf\n", _lastStep);
279            break;            break;
280                        
         case 'v':  
           _viewTop = 1 - _viewTop;  
           coord_t eye = [_camera eye];  
   
           if (_viewTop)  
             glDisable (GL_FOG);  
           else  
             glEnable (GL_FOG);  
   
           if (_viewTop)  
             [_camera initWithFovy: 45.0  
                            aspect: 1.0  
                             zNear: 5.0  
                              zFar: 855.0  
                               eye: eye  
                            center: MakeCoord (eye.x, eye.y - 10.0, eye.z)  
                                up: MakeCoord (0.0, 0.0, 1.0)];  
           else  
             [_camera initWithFovy: 45.0  
                            aspect: 1.0  
                             zNear: 5.0  
                              zFar: 255.0  
                               eye: eye  
                            center: MakeCoord (eye.x, eye.y, eye.z + 30.0)  
                                up: MakeCoord (0.0, 1.0, 0.0)];  
           [self reshape];  
           break;  
             
281          default:          default:
282            [_mapController keyStroke: keyChar];            [_mapController keyStroke: keyChar];
283            break;            break;
284          }          }
285      }    }
286    return YES;    return YES;
287  }  }
288    

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

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