1 /* 2 3 Copyright (c) 2002, Calum Robinson 4 All rights reserved. 5 6 Redistribution and use in source and binary forms, with or without 7 modification, are permitted provided that the following conditions are met: 8 9 * Redistributions of source code must retain the above copyright notice, this 10 list of conditions and the following disclaimer. 11 12 * Redistributions in binary form must reproduce the above copyright notice, 13 this list of conditions and the following disclaimer in the documentation 14 and/or other materials provided with the distribution. 15 16 * Neither the name of the author nor the names of its contributors may be used 17 to endorse or promote products derived from this software without specific 18 prior written permission. 19 20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 24 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 31 */ 32 #include "Star.h" 33 #include "Shared.h" 34 35 #define BIGMYSTERY 1800.0 36 #define MAXANGLES 16384 37 38 /* Construction/Destruction */ 39 void InitStar(Star *s) 40 { 41 int i; 42 for (i=0;i<3;i++) { 43 s->position[i] = RandFlt(-10000.0, 10000.0); 44 } 45 s->rotSpeed = RandFlt(0.4, 0.9); 46 s->mystery = RandFlt(0.0, 10.0); 47 } 48 49 void UpdateStar(flurry_info_t *info, Star *s) 50 { 51 /* speed control */ 52 float rotationsPerSecond = (float) (2.0*M_PI*12.0/MAXANGLES) * s->rotSpeed; 53 double thisPointInRadians; 54 double thisAngle = info->fTime*rotationsPerSecond; 55 float cf; 56 double tmpX1,tmpY1,tmpZ1; 57 double tmpX2,tmpY2,tmpZ2; 58 double tmpX3,tmpY3,tmpZ3; 59 double tmpX4,tmpY4,tmpZ4; 60 double rotation; 61 double cr; 62 double sr; 63 64 s->ate = 0; 65 66 cf = ((float) (cos(7.0*((info->fTime)*rotationsPerSecond)) + 67 cos(3.0*((info->fTime)*rotationsPerSecond)) + 68 cos(13.0*((info->fTime)*rotationsPerSecond)))); 69 cf /= 6.0f; 70 cf += 0.75f; 71 thisPointInRadians = 2.0 * M_PI * (double) s->mystery / (double) BIGMYSTERY; 72 73 s->position[0] = 250.0f * cf * (float) cos(11.0 * (thisPointInRadians + (3.0*thisAngle))); 74 s->position[1] = 250.0f * cf * (float) sin(12.0 * (thisPointInRadians + (4.0*thisAngle))); 75 s->position[2] = 250.0f * (float) cos((23.0 * (thisPointInRadians + (12.0*thisAngle)))); 76 77 rotation = thisAngle*0.501 + 5.01 * (double) s->mystery / (double) BIGMYSTERY; 78 cr = cos(rotation); 79 sr = sin(rotation); 80 tmpX1 = s->position[0] * cr - s->position[1] * sr; 81 tmpY1 = s->position[1] * cr + s->position[0] * sr; 82 tmpZ1 = s->position[2]; 83 84 tmpX2 = tmpX1 * cr - tmpZ1 * sr; 85 tmpY2 = tmpY1; 86 tmpZ2 = tmpZ1 * cr + tmpX1 * sr; 87 88 tmpX3 = tmpX2; 89 tmpY3 = tmpY2 * cr - tmpZ2 * sr; 90 tmpZ3 = tmpZ2 * cr + tmpY2 * sr + seraphDistance; 91 92 rotation = thisAngle*2.501 + 85.01 * (double) s->mystery / (double) BIGMYSTERY; 93 cr = cos(rotation); 94 sr = sin(rotation); 95 tmpX4 = tmpX3 * cr - tmpY3 * sr; 96 tmpY4 = tmpY3 * cr + tmpX3 * sr; 97 tmpZ4 = tmpZ3; 98 99 s->position[0] = (float) tmpX4; 100 s->position[1] = (float) tmpY4; 101 s->position[2] = (float) tmpZ4; 102 } 103