/* -*- Objc -*- */ /* * $Id: ParticleSystemPlane.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/ParticleSystemPlane.h" /** * This class creates a particle system "Plane" : particles are sent from a * plane in a same direction. It can be used to create effects like snow, * rain, ... */ @implementation ParticleSystemPlane /** * Initialisation of all variables. */ - (id) init { self = [super init]; if (self != nil) { _originXMin = -1.0; _originXMax = 1.0; _originXStep = 0.1; _originYMin = -1.0; _originYMax = 1.0; _originYStep = 0.1; _originZMin = -1.0; _originZMax = 1.0; _originZStep = 0.1; _direction = MakeCoord (0.0, 1.0, 0.0); _particleOrigin = MakeCoord (0.0, 0.0, 0.0); } return self; } /** * Sets the minimal origin and the maximal origin of one particle, on * the X axis. */ - (void) setOriginXMin: (double)originXMin originXMax: (double)originXMax originXStep: (double)originXStep { _originXMin = originXMin; _originXMax = originXMax; _originXStep = originXStep; } /** * Sets the minimal origin and the maximal origin of one particle, on * the Y axis. */ - (void) setOriginYMin: (double)originYMin originYMax: (double)originYMax originYStep: (double)originYStep { _originYMin = originYMin; _originYMax = originYMax; _originYStep = originYStep; } /** * Sets the minimal origin and the maximal origin of one particle, on * the Z axis. */ - (void) setOriginZMin: (double)originZMin originZMax: (double)originZMax originZStep: (double)originZStep { _originZMin = originZMin; _originZMax = originZMax; _originZStep = originZStep; } /** * 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 origin _particleOrigin.x = _originXMin + (int) ((_originXMax - _originXMin) / _originXStep * rand() / (RAND_MAX + 1.0)) * _originXStep; _particleOrigin.y = _originYMin + (int) ((_originYMax - _originYMin) / _originYStep * rand() / (RAND_MAX + 1.0)) * _originYStep; _particleOrigin.z = _originZMin + (int) ((_originZMax - _originZMin) / _originZStep * rand() / (RAND_MAX + 1.0)) * _originZStep; return [[Particle alloc] initWithPosition: _particleOrigin direction: _direction life: [self computeLife] speed: [self computeSpeed] size: [self computeSize] color: [self computeColor] shininess: _shininess]; } @end