/[hegemonie]/hegemonie/Source/GameWidget.m
ViewVC logotype

Diff of /hegemonie/Source/GameWidget.m

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

revision 1.2 by dam, Tue Jul 29 12:48:18 2003 UTC revision 1.3 by dam, Mon Aug 18 01:57:15 2003 UTC
# Line 21  Line 21 
21   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22   */   */
23    
24    #include <SDL/SDL_keysym.h> /* FIXME */
25    
26  #include <GL/gl.h>  #include <GL/gl.h>
27  #include <GL/glu.h>  #include <GL/glu.h>
28    
29  #include <Foundation/NSObject.h>  #include <Foundation/NSObject.h>
30    #include <AppKit/NSEvent.h>
31    
32  #include "Model/MdlAnimatedModel.h"  #include "Model/MdlAnimatedModel.h"
33  #include "Model/MdlModel.h"  #include "Model/MdlModel.h"
# Line 40  Line 43 
43    
44  #include "GameWidget.h"  #include "GameWidget.h"
45    
46    @interface GameWidgetController : NSObject
47    {
48    @private
49      GameWidget *_view;
50    }
51    
52    - (id) initWithView: (GameWidget *)view;
53    - (BOOL) keyDown: (NSEvent *)event;
54    
55    @end
56    
57    @implementation GameWidgetController
58    
59    - (id) initWithView: (GameWidget *)view
60    {
61      NSParameterAssert (view);
62    
63      self = [super init];
64      if (self != nil)
65        {
66          _view = RETAIN(view);
67        }
68    
69      return self;
70    }
71    
72    - (void) dealloc
73    {
74      RELEASE(_view);
75    
76      [super dealloc];
77    }
78    
79    - (BOOL) keyDown: (NSEvent *)event
80    {
81      Camera *camera = [_view camera];
82    
83      NSParameterAssert (event);
84    
85      switch ([event keyCode])
86        {
87        case SDLK_UP:
88          [camera forward: 3.0f];
89          return YES;
90        case SDLK_DOWN:
91          [camera backward: 3.0f];
92          return YES;
93        case SDLK_RIGHT:
94          [camera strafRight: 3.0f];
95          return YES;
96        case SDLK_LEFT:
97          [camera strafLeft: 3.0f];
98          return YES;
99        case SDLK_PAGEUP:
100          [camera moveUp: 3.0f];
101          return YES;
102        case SDLK_PAGEDOWN:
103          [camera moveDown: 3.0f];
104          return YES;
105        }
106      
107      return NO;
108    }
109    
110    @end
111    
112    
113  @implementation GameWidget  @implementation GameWidget
114    
115  - (void) _initGL  - (void) _initGL
116  {  {
117    static const GLfloat lightAmbient[] = {0.75f, 0.75f, 0.75f, 1.0f};    const GLfloat lightAmbient[] = {0.75f, 0.75f, 0.75f, 1.0f};
118    static const GLfloat lightDiffuse[] = {0.7f, 0.7f, 0.7f, 1.0f};    const GLfloat lightDiffuse[] = {0.7f, 0.7f, 0.7f, 1.0f};
119  //   static const GLfloat lightPosition[] = {10.0f, 350.0f, 10.0f};   //  const GLfloat lightPosition[] = {10.0f, 350.0f, 10.0f};
120    
   glShadeModel (GL_SMOOTH);  
   glEnable (GL_LIGHTING);  
121    glEnable (GL_LIGHT0);    glEnable (GL_LIGHT0);
122    glLightfv (GL_LIGHT0, GL_AMBIENT, lightAmbient);    glLightfv (GL_LIGHT0, GL_AMBIENT, lightAmbient);
123    glLightfv (GL_LIGHT0, GL_DIFFUSE, lightDiffuse);    glLightfv (GL_LIGHT0, GL_DIFFUSE, lightDiffuse);
124    
125      glShadeModel (GL_SMOOTH);
126    
127    //   glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
128  }  }
129    
130  - (id) init  - (id) init
# Line 61  Line 133 
133                              size: NSMakeSize (1024.0f, 768.0f)];                              size: NSMakeSize (1024.0f, 768.0f)];
134    if (self != nil)    if (self != nil)
135      {      {
136          [self _initGL];
137          GameWidgetController *controller
138            = [[GameWidgetController alloc] initWithView: self];
139          [self setDelegate: controller];
140          RELEASE (controller);
141      }      }
142        
143    return self;    return self;
144  }  }
145    
146    - (void) dealloc
147    {
148      [self endGame];
149    
150      [super dealloc];
151    }
152    
153  - (void) newGame  - (void) newGame
154  {  {
155    _camera = [[Camera alloc] initWithFovy: 50    _camera = [[Camera alloc] initWithFovy: 50
# Line 90  Line 174 
174        
175    /* game */    /* game */
176    _game = [[HgGame alloc] initWithName: @"Jeu"];    _game = [[HgGame alloc] initWithName: @"Jeu"];
177    [_game setMap: (HgMap *)_map];    [_game setMap: _map];
178        
179    /* player */    /* player */
180    _player1 = [[HgPlayer alloc] initWithName: @"Cyrille"    _player1 = [[HgPlayer alloc] initWithName: @"Cyrille"
181                                 user: @"Kirk"                                 user: @"Kirk"
182                                 host: @"Host"];                                 host: @"Host"
183                                   game: _game];
184  }  }
185    
186  - (void) _display  - (void) _display
# Line 123  Line 208 
208               (GLdouble)[_camera up].z);               (GLdouble)[_camera up].z);
209        
210    [_map displayWithCamera: _camera    [_map displayWithCamera: _camera
211                numberOfRay: 80                   lastStep: 5.0
212                   lastStep: 5.0];                numberOfRay: 80];
213        
214    Frustum * _frustum = [[Frustum alloc] initWithCurrentGlState];    Frustum * _frustum = [[Frustum alloc] initWithCurrentGlState];
215        
# Line 147  Line 232 
232    RELEASE (_player1);    RELEASE (_player1);
233  }  }
234    
235  - (void) dealloc  - (Camera *) camera
236  {  {
237    [self endGame];    return _camera;
   
   [super dealloc];  
238  }  }
239    
240  @end  @end

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

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