1/* 2 3Copyright (c) 2002, Calum Robinson 4All rights reserved. 5 6Redistribution and use in source and binary forms, with or without 7modification, 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 20THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 24ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27ANY 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 29SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 31*/ 32 33 34#include "Star.h" 35#include "Shared.h" 36 37 38#define BIGMYSTERY 1800.0 39#define MAXANGLES 16384 40 41 42// Construction/Destruction 43void 44InitStar(Star* s) 45{ 46 for (int i=0; i < 3; i++) 47 s->position[i] = RandFlt(-10000.0, 10000.0); 48 49 s->rotSpeed = RandFlt(0.4, 0.9); 50 s->mystery = RandFlt(0.0, 10.0); 51} 52 53 54void 55UpdateStar(flurry_info_t* info, Star* s) 56{ 57 /* speed control */ 58 float rotationsPerSecond = (float)(2.0 * M_PI * 12.0 / MAXANGLES) 59 * s->rotSpeed; 60 double thisPointInRadians; 61 double thisAngle = info->fTime * rotationsPerSecond; 62 float cf; 63 double tmpX1; 64 double tmpY1; 65 double tmpZ1; 66 double tmpX2; 67 double tmpY2; 68 double tmpZ2; 69 double tmpX3; 70 double tmpY3; 71 double tmpZ3; 72 double tmpX4; 73 double tmpY4; 74 double tmpZ4; 75 double rotation; 76 double cr; 77 double sr; 78 79 s->ate = 0; 80 81 cf = ((float)(cos(7.0 * ((info->fTime) * rotationsPerSecond)) 82 + cos(3.0 * ((info->fTime) * rotationsPerSecond)) 83 + cos(13.0 * ((info->fTime) * rotationsPerSecond)))); 84 cf /= 6.0f; 85 cf += 0.75f; 86 thisPointInRadians = 2.0 * M_PI * (double) s->mystery / (double) BIGMYSTERY; 87 88 s->position[0] = 250.0f * cf * (float)cos(11.0 * (thisPointInRadians 89 + (3.0 * thisAngle))); 90 s->position[1] = 250.0f * cf * (float)sin(12.0 * (thisPointInRadians 91 + (4.0 * thisAngle))); 92 s->position[2] = 250.0f * (float)cos((23.0 * (thisPointInRadians 93 + (12.0 * thisAngle)))); 94 95 rotation = thisAngle * 0.501 + 5.01 * (double)s->mystery 96 / (double)BIGMYSTERY; 97 cr = cos(rotation); 98 sr = sin(rotation); 99 tmpX1 = s->position[0] * cr - s->position[1] * sr; 100 tmpY1 = s->position[1] * cr + s->position[0] * sr; 101 tmpZ1 = s->position[2]; 102 103 tmpX2 = tmpX1 * cr - tmpZ1 * sr; 104 tmpY2 = tmpY1; 105 tmpZ2 = tmpZ1 * cr + tmpX1 * sr; 106 107 tmpX3 = tmpX2; 108 tmpY3 = tmpY2 * cr - tmpZ2 * sr; 109 tmpZ3 = tmpZ2 * cr + tmpY2 * sr + seraphDistance; 110 111 rotation = thisAngle * 2.501 + 85.01 * (double)s->mystery 112 / (double) BIGMYSTERY; 113 cr = cos(rotation); 114 sr = sin(rotation); 115 tmpX4 = tmpX3 * cr - tmpY3 * sr; 116 tmpY4 = tmpY3 * cr + tmpX3 * sr; 117 tmpZ4 = tmpZ3; 118 119 s->position[0] = (float)tmpX4; 120 s->position[1] = (float)tmpY4; 121 s->position[2] = (float)tmpZ4; 122} 123