/* -*- Objc -*- */ /* * $Id: ParticleSystemCyl.m,v 1.1 2003/07/15 13:59:10 madruon 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 "ParticleSystem/ParticleSystemCyl.h" /** * This class creates a particle system "Cylinder" : particles are sent from a * circular base in a same direction. It can be used to create effects like * smoke, tunnels, ... */ @implementation ParticleSystemCyl /** * Initialisation of all variables. */ - (id) init { self = [super init]; if (self != nil) { _radiusMin = 0.0; _radiusMax = 1.0; _radiusStep = 0.1; _angleMin = 0.0; _angleMax = 360.0; _angleStep = 1.0; _direction = MakeCoord(0.0, 1.0, 0.0); tmpRadius = 0.0; tmpAngle = 0.0; tmpCos = 0.0; tmpSin = 0.0; } return self; } /** * Sets the minimal radius and the maximal radius of the base. */ - (void) setRadiusMin: (double)radiusMin radiusMax: (double)radiusMax radiusStep: (double)radiusStep { _radiusMin = radiusMin; _radiusMax = radiusMax; _radiusStep = radiusStep; } /** * Sets the opening angle (in degree) of the base, from the X axis. * For example, if "angleMin" = 0 and "angleMax" = 90 then the base will be * an semi-circle staring in (1, 0, 0) and ending in (0, 0, -1). */ - (void) setAngleMin: (double)angleMin angleMax: (double)angleMax angleStep: (double)angleStep { _angleMin = angleMin; _angleMax = angleMax; _angleStep = angleStep; } /** * Sets the direction of all particles. */ - (void) setDirection: (coord_t)direction { if ((direction.x == 0.0) && (direction.y == 0.0) && (direction.z == 0.0)) { NSAssert (NO, @"Invalid direction of the particle system"); } _direction = direction; } /** * Creates a new particle. In this system, the direction is the same for all * particles, but the origin is generated randomly. "life", "speed", "size" * and "color" are also generated randomly. */ - (Particle *) createParticle { // We compute the position tmpRadius = _radiusMin + (int) ((_radiusMax - _radiusMin) / _radiusStep * rand() / (RAND_MAX + 1.0)) * _radiusStep; tmpAngle = _angleMin + (int) ((_angleMax - _angleMin) / _angleStep * rand() / (RAND_MAX + 1.0)) * _angleStep; tmpCos = cos (tmpAngle * M_PI / 180.0) * tmpRadius; tmpSin = sin (tmpAngle * M_PI / 180.0) * tmpRadius; return [[Particle alloc] initWithPosition: MakeCoord (tmpCos, 0.0, -tmpSin) direction: _direction life: [self computeLife] speed: [self computeSpeed] size: [self computeSize] color: [self computeColor] shininess: _shininess]; } @end