/* -*- Objc -*- */ /* * $Id: MapView.m,v 1.1 2003/07/06 22:15:10 dam Exp $ * * Copyright (C) 2003 Free Software Foundation, Inc. * * This file is part of GNU Hégémonie. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include "Common/Camera.h" #include "Map/MapDisplay.h" #include "MapView.h" @implementation MapView - (id) initWithFrame: (NSRect)frameRect pixelFormat: (NSOpenGLPixelFormat *)format { self = [super initWithFrame: frameRect pixelFormat: format]; if (self != nil) { _init = NO; _camera = [[Camera alloc] initWithFovy: 50.0 aspect: 1.0 zNear: 5.0 zFar: 750.0 eye: MakeCoord (0.0, 150.0, 0.0) center: MakeCoord (0.0, 150.0, 30.0) up: MakeCoord (0.0, 1.0, 0.0)]; _map = [[MapDisplay alloc] initWithImageName: @"carte.tiff" colorsImageName: @"degrades.tiff" mapShadow: nil]; } return self; } - (void) dealloc { RELEASE(_camera); RELEASE(_map); [super dealloc]; } - (BOOL) initGL { glShadeModel (GL_SMOOTH); glClearColor (0.0f, 0.0f, 0.0f, 0.0f); glEnable (GL_DEPTH_TEST); [NSTimer scheduledTimerWithTimeInterval: 0.001 target: self selector: @selector(display) userInfo: nil repeats: YES]; return YES; } - (void) reshape { NSRect sceneBounds; sceneBounds = [self bounds]; glViewport (0, 0, sceneBounds.size.width, sceneBounds.size.height); glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluPerspective ((GLdouble)[_camera fovy], (GLdouble)[_camera aspect], (GLdouble)[_camera zNear], (GLdouble)[_camera zFar]); glMatrixMode (GL_MODELVIEW); } - (void) drawRect: (NSRect)aRect { if (!_init) { [[self openGLContext] makeCurrentContext]; [self initGL]; [self reshape]; _init = YES; } glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity (); 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: 70 firstStep: 150 secondStep: 200]; [self update]; [[self openGLContext] flushBuffer]; } @end