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 |
|
|
|
#include <GL/gl.h> |
|
|
#include <GL/glu.h> |
|
|
|
|
24 |
#include <Foundation/NSObject.h> |
#include <Foundation/NSObject.h> |
25 |
|
|
26 |
#include "Model/MdlAnimatedModel.h" |
#include "Interface.h" |
27 |
#include "Model/MdlModel.h" |
#include "GameWidget.h" |
|
|
|
|
#include "Map/MapDisplay.h" |
|
|
|
|
|
#include "GameEngine/HgGame.h" |
|
|
#include "GameEngine/HgPlayer.h" |
|
|
|
|
|
#include "Common/Camera.h" |
|
|
#include "Common/Frustum.h" |
|
|
|
|
28 |
#include "GameFrame.h" |
#include "GameFrame.h" |
29 |
|
|
|
@interface GameController : NSObject |
|
|
|
|
|
@end |
|
|
|
|
|
@implementation GameController |
|
|
|
|
|
@end |
|
|
|
|
30 |
@implementation GameFrame |
@implementation GameFrame |
31 |
|
|
32 |
- (void) _initGL |
- (id) initWithInterface: (Interface *)interface |
|
{ |
|
|
static const GLfloat lightAmbient[] = {0.75f, 0.75f, 0.75f, 1.0f}; |
|
|
static const GLfloat lightDiffuse[] = {0.7f, 0.7f, 0.7f, 1.0f}; |
|
|
// static const GLfloat lightPosition[] = {10.0f, 350.0f, 10.0f}; |
|
|
|
|
|
glShadeModel (GL_SMOOTH); |
|
|
glEnable (GL_LIGHTING); |
|
|
glEnable (GL_LIGHT0); |
|
|
glLightfv (GL_LIGHT0, GL_AMBIENT, lightAmbient); |
|
|
glLightfv (GL_LIGHT0, GL_DIFFUSE, lightDiffuse); |
|
|
} |
|
|
|
|
|
- (id) init |
|
33 |
{ |
{ |
34 |
self = [super initWithParent: nil]; |
self = [super initWithInterface: interface]; |
35 |
if (self != nil) |
if (self != nil) |
36 |
{ |
{ |
37 |
_camera = [[Camera alloc] initWithFovy: 60 |
_gameWidget = [[GameWidget alloc] init]; |
|
aspect: 1.0 |
|
|
zNear: 0.01 |
|
|
zFar: 10000.0 |
|
|
eye: MakeCoord (0.0,0.0,100.0) |
|
|
center: MakeCoord (0.0,0.0,0.0) |
|
|
up: MakeCoord (0.0,1.0,0.0) ]; |
|
38 |
|
|
39 |
|
[self addWidget: _gameWidget]; |
|
/* Model */ |
|
|
MdlModel *model = [[MdlModel alloc] initWithName: @"lara_lower.md3" |
|
|
withTexName: @"lara_lower.skin" |
|
|
withConfigName: @"lara_lower.cfg"]; |
|
|
_anim = [[MdlAnimatedModel alloc] initWithModel: model |
|
|
animation: @"LEGS_WALK"]; |
|
|
RELEASE (model); |
|
|
|
|
|
/* map */ |
|
|
// _map = [[MapDisplay alloc] initWithImageName: @"map.tiff" |
|
|
// colorsImageName: @"colors.tiff" |
|
|
// mapShadow: nil]; |
|
|
|
|
|
/* game */ |
|
|
_game = [[HgGame alloc] initWithName: @"Jeu"]; |
|
|
[_game setMap: (HgMap *)_map]; |
|
|
|
|
|
/* player */ |
|
|
_player1 = [[HgPlayer alloc] initWithName: @"Cyrille" |
|
|
user: @"Kirk" |
|
|
host: @"Host"]; |
|
|
|
|
40 |
} |
} |
41 |
|
|
42 |
return self; |
return self; |
43 |
} |
} |
44 |
|
|
45 |
- (void) _display |
- (void) dealloc |
46 |
{ |
{ |
47 |
glMatrixMode (GL_PROJECTION); |
RELEASE (_gameWidget); |
|
glPushMatrix (); |
|
|
glLoadIdentity (); |
|
|
gluPerspective (50, (GLfloat)(4.0f/3.0f), 0.1, 1000); |
|
|
|
|
|
glMatrixMode (GL_MODELVIEW); |
|
|
gluLookAt ((GLdouble)[_camera eye].x, |
|
|
(GLdouble)[_camera eye].y, |
|
|
(GLdouble)[_camera eye].z, |
|
|
(GLdouble)[_camera center].x, |
|
|
(GLdouble)[_camera center].y, |
|
|
(GLdouble)[_camera center].z, |
|
|
(GLdouble)[_camera up].x, |
|
|
(GLdouble)[_camera up].y, |
|
|
(GLdouble)[_camera up].z); |
|
|
|
|
|
// [_map displayWithCamera: _camera |
|
|
// numberOfRay: 80 |
|
|
// lastStep: 5]; |
|
|
|
|
|
Frustum * _frustum = [[Frustum alloc] initWithCurrentGlState]; |
|
48 |
|
|
49 |
glPushMatrix(); |
[super dealloc]; |
|
glTranslatef(15.0,15.0,50.0); |
|
|
glRotatef (-90.0f, 1.0f, 0.0f, 0.0f); |
|
|
[_anim displayWithFrustum: nil]; |
|
|
glPopMatrix(); |
|
|
|
|
|
glMatrixMode (GL_PROJECTION); |
|
|
glPopMatrix (); |
|
|
glMatrixMode (GL_MODELVIEW); |
|
|
|
|
50 |
} |
} |
51 |
|
|
52 |
- (void) dealloc |
- (Interface *)interface |
53 |
{ |
{ |
54 |
RELEASE (_anim); |
return (Interface *)[super interface]; |
55 |
RELEASE (_map); |
} |
|
RELEASE (_game); |
|
|
RELEASE (_player1); |
|
56 |
|
|
57 |
[super dealloc]; |
- (GameWidget *) gameWidget |
58 |
|
{ |
59 |
|
return _gameWidget; |
60 |
} |
} |
61 |
|
|
62 |
@end |
@end |