Flurry Screen Saver: style fixes, correct Jamfile

This commit is contained in:
John Scipione
2013-11-14 23:30:07 -05:00
parent da854e342f
commit e11db35d48
12 changed files with 1095 additions and 1044 deletions
+65 -61
View File
@@ -29,10 +29,13 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/* /*
* Copyright Karsten Heimrich, [email protected]. All rights reserved. * Copyright Karsten Heimrich, [email protected]. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#include "Flurry.h" #include "Flurry.h"
#include <new> #include <new>
@@ -52,12 +55,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using namespace BPrivate; using namespace BPrivate;
// #pragma mark - FlurryView
FlurryView::FlurryView(BRect bounds) FlurryView::FlurryView(BRect bounds)
: :
BGLView(bounds, (const char *)NULL, B_FOLLOW_ALL, B_FRAME_EVENTS | B_WILL_DRAW, BGLView(bounds, (const char *)NULL, B_FOLLOW_ALL,
B_FRAME_EVENTS | B_WILL_DRAW,
BGL_RGB | BGL_ALPHA | BGL_DEPTH | BGL_DOUBLE), BGL_RGB | BGL_ALPHA | BGL_DEPTH | BGL_DOUBLE),
fOldFrameTime(-1.0), fOldFrameTime(-1.0),
fFlurryInfo_t(NULL) fFlurryInfo(NULL)
{ {
B_TRANSLATE_MARK_SYSTEM_NAME_VOID("Flurry"); B_TRANSLATE_MARK_SYSTEM_NAME_VOID("Flurry");
@@ -68,21 +75,19 @@ FlurryView::FlurryView(BRect bounds)
LockGL(); LockGL();
_SetupFlurryBaseInfo(); _SetupFlurryBaseInfo();
UnlockGL(); UnlockGL();
} }
FlurryView::~FlurryView() FlurryView::~FlurryView()
{ {
if (fFlurryInfo_t) { if (fFlurryInfo != NULL) {
LockGL(); LockGL();
free(fFlurryInfo_t->s); free(fFlurryInfo->s);
free(fFlurryInfo_t->star); free(fFlurryInfo->star);
for (int32 i = 0; i < MAX_SPARKS; ++i) for (int32 i = 0; i < MAX_SPARKS; ++i)
free(fFlurryInfo_t->spark[i]); free(fFlurryInfo->spark[i]);
free(fFlurryInfo_t); free(fFlurryInfo);
UnlockGL(); UnlockGL();
} }
@@ -92,7 +97,7 @@ FlurryView::~FlurryView()
status_t status_t
FlurryView::InitCheck() const FlurryView::InitCheck() const
{ {
return (fFlurryInfo_t != NULL) ? B_OK : B_ERROR; return (fFlurryInfo != NULL) ? B_OK : B_ERROR;
} }
@@ -159,36 +164,36 @@ FlurryView::DrawFlurryScreenSaver()
glColor4f(0.0, 0.0, 0.0, alpha); glColor4f(0.0, 0.0, 0.0, alpha);
glRectd(0.0, 0.0, fWidth, fHeight); glRectd(0.0, 0.0, fWidth, fHeight);
fFlurryInfo_t->dframe++; fFlurryInfo->dframe++;
fFlurryInfo_t->fOldTime = fFlurryInfo_t->fTime; fFlurryInfo->fOldTime = fFlurryInfo->fTime;
fFlurryInfo_t->fTime = _SecondsSinceStart() + fFlurryInfo_t->randomSeed; fFlurryInfo->fTime = _SecondsSinceStart() + fFlurryInfo->randomSeed;
fFlurryInfo_t->fDeltaTime = fFlurryInfo_t->fTime - fFlurryInfo_t->fOldTime; fFlurryInfo->fDeltaTime = fFlurryInfo->fTime - fFlurryInfo->fOldTime;
fFlurryInfo_t->drag = (float)pow(0.9965, fFlurryInfo_t->fDeltaTime * 85.0); fFlurryInfo->drag = (float)pow(0.9965, fFlurryInfo->fDeltaTime * 85.0);
UpdateStar(fFlurryInfo_t, fFlurryInfo_t->star); UpdateStar(fFlurryInfo, fFlurryInfo->star);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glShadeModel(GL_SMOOTH); glShadeModel(GL_SMOOTH);
glBlendFunc(GL_SRC_ALPHA, GL_ONE); glBlendFunc(GL_SRC_ALPHA, GL_ONE);
for (int32 i = 0; i < fFlurryInfo_t->numStreams; ++i) { for (int32 i = 0; i < fFlurryInfo->numStreams; ++i) {
fFlurryInfo_t->spark[i]->color[0] = 1.0; fFlurryInfo->spark[i]->color[0] = 1.0;
fFlurryInfo_t->spark[i]->color[1] = 1.0; fFlurryInfo->spark[i]->color[1] = 1.0;
fFlurryInfo_t->spark[i]->color[2] = 1.0; fFlurryInfo->spark[i]->color[2] = 1.0;
fFlurryInfo_t->spark[i]->color[3] = 1.0; fFlurryInfo->spark[i]->color[3] = 1.0;
UpdateSpark(fFlurryInfo_t, fFlurryInfo_t->spark[i]); UpdateSpark(fFlurryInfo, fFlurryInfo->spark[i]);
} }
UpdateSmoke_ScalarBase(fFlurryInfo_t, fFlurryInfo_t->s); UpdateSmoke_ScalarBase(fFlurryInfo, fFlurryInfo->s);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE); glBlendFunc(GL_SRC_ALPHA, GL_ONE);
const double brite = pow(deltaFrameTime, 0.75) * 10.0; const double brite = pow(deltaFrameTime, 0.75) * 10.0;
DrawSmoke_Scalar(fFlurryInfo_t, fFlurryInfo_t->s, DrawSmoke_Scalar(fFlurryInfo, fFlurryInfo->s,
brite * fFlurryInfo_t->briteFactor); brite * fFlurryInfo->briteFactor);
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND); glDisable(GL_BLEND);
@@ -207,12 +212,12 @@ FlurryView::FrameResized(float newWidth, float newHeight)
BGLView::FrameResized(newWidth, newHeight); BGLView::FrameResized(newWidth, newHeight);
if (fFlurryInfo_t) { if (fFlurryInfo != NULL) {
fWidth = newWidth; fWidth = newWidth;
fHeight = newHeight; fHeight = newHeight;
fFlurryInfo_t->sys_glWidth = fWidth; fFlurryInfo->sys_glWidth = fWidth;
fFlurryInfo_t->sys_glHeight = fHeight; fFlurryInfo->sys_glHeight = fHeight;
glViewport(0, 0, int(fWidth), int(fHeight)); glViewport(0, 0, int(fWidth), int(fHeight));
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
@@ -233,44 +238,44 @@ FlurryView::FrameResized(float newWidth, float newHeight)
void void
FlurryView::_SetupFlurryBaseInfo() FlurryView::_SetupFlurryBaseInfo()
{ {
fFlurryInfo_t = (flurry_info_t *)malloc(sizeof(flurry_info_t)); fFlurryInfo = (flurry_info_t*)malloc(sizeof(flurry_info_t));
if (!fFlurryInfo_t) if (fFlurryInfo == NULL)
return; return;
fFlurryInfo_t->next = NULL; fFlurryInfo->next = NULL;
fFlurryInfo_t->randomSeed = RandFlt(0.0, 300.0); fFlurryInfo->randomSeed = RandFlt(0.0, 300.0);
fFlurryInfo_t->dframe = 0; fFlurryInfo->dframe = 0;
fFlurryInfo_t->fOldTime = 0.0; fFlurryInfo->fOldTime = 0.0;
fFlurryInfo_t->sys_glWidth = fWidth; fFlurryInfo->sys_glWidth = fWidth;
fFlurryInfo_t->sys_glHeight = fHeight; fFlurryInfo->sys_glHeight = fHeight;
fFlurryInfo_t->fTime = _SecondsSinceStart() + fFlurryInfo_t->randomSeed; fFlurryInfo->fTime = _SecondsSinceStart() + fFlurryInfo->randomSeed;
fFlurryInfo_t->fDeltaTime = fFlurryInfo_t->fTime - fFlurryInfo_t->fOldTime; fFlurryInfo->fDeltaTime = fFlurryInfo->fTime - fFlurryInfo->fOldTime;
fFlurryInfo_t->numStreams = 5; fFlurryInfo->numStreams = 5;
fFlurryInfo_t->briteFactor = 1.0; fFlurryInfo->briteFactor = 1.0;
fFlurryInfo_t->streamExpansion = 10000.0; fFlurryInfo->streamExpansion = 10000.0;
fFlurryInfo_t->currentColorMode = tiedyeColorMode; fFlurryInfo->currentColorMode = tiedyeColorMode;
fFlurryInfo_t->s = (SmokeV*)malloc(sizeof(SmokeV)); fFlurryInfo->s = (SmokeV*)malloc(sizeof(SmokeV));
InitSmoke(fFlurryInfo_t->s); InitSmoke(fFlurryInfo->s);
fFlurryInfo_t->star = (Star*)malloc(sizeof(Star)); fFlurryInfo->star = (Star*)malloc(sizeof(Star));
InitStar(fFlurryInfo_t->star); InitStar(fFlurryInfo->star);
fFlurryInfo_t->star->rotSpeed = 1.0; fFlurryInfo->star->rotSpeed = 1.0;
for (int32 i = 0; i < MAX_SPARKS; ++i) { for (int32 i = 0; i < MAX_SPARKS; ++i) {
fFlurryInfo_t->spark[i] = (Spark*)malloc(sizeof(Spark)); fFlurryInfo->spark[i] = (Spark*)malloc(sizeof(Spark));
InitSpark(fFlurryInfo_t->spark[i]); InitSpark(fFlurryInfo->spark[i]);
fFlurryInfo_t->spark[i]->mystery = 1800 * (i + 1) / 13; fFlurryInfo->spark[i]->mystery = 1800 * (i + 1) / 13;
UpdateSpark(fFlurryInfo_t, fFlurryInfo_t->spark[i]); UpdateSpark(fFlurryInfo, fFlurryInfo->spark[i]);
} }
for (int32 i = 0; i < NUMSMOKEPARTICLES / 4; ++i) { for (int32 i = 0; i < NUMSMOKEPARTICLES / 4; ++i) {
for (int32 k = 0; k < 4; ++k) for (int32 k = 0; k < 4; ++k)
fFlurryInfo_t->s->p[i].dead.i[k] = 1; fFlurryInfo->s->p[i].dead.i[k] = 1;
} }
} }
@@ -301,8 +306,9 @@ instantiate_screen_saver(BMessage* archive, image_id imageId)
Flurry::Flurry(BMessage* archive, image_id imageId) Flurry::Flurry(BMessage* archive, image_id imageId)
: BScreenSaver(archive, imageId), :
fFlurryView(NULL) BScreenSaver(archive, imageId),
fFlurryView(NULL)
{ {
struct timeval tv; struct timeval tv;
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
@@ -326,25 +332,25 @@ Flurry::InitCheck()
status_t status_t
Flurry::StartSaver(BView* view, bool preview) Flurry::StartSaver(BView* view, bool preview)
{ {
status_t status = B_ERROR; status_t result = B_ERROR;
if (preview) if (preview)
return status; return result;
SetTickSize(50000); SetTickSize(50000);
fFlurryView = new (std::nothrow) FlurryView(view->Bounds()); fFlurryView = new (std::nothrow) FlurryView(view->Bounds());
if (fFlurryView) { if (fFlurryView != NULL) {
if (fFlurryView->InitCheck() != B_OK) { if (fFlurryView->InitCheck() != B_OK) {
delete fFlurryView; delete fFlurryView;
fFlurryView = NULL; fFlurryView = NULL;
} else { } else {
status = B_OK; result = B_OK;
view->AddChild(fFlurryView); view->AddChild(fFlurryView);
} }
} }
return status; return result;
} }
@@ -367,12 +373,10 @@ void
Flurry::DirectConnected(direct_buffer_info* info) Flurry::DirectConnected(direct_buffer_info* info)
{ {
// Enable or disable direct rendering // Enable or disable direct rendering
#if 1
if (fFlurryView != NULL) { if (fFlurryView != NULL) {
fFlurryView->DirectConnected(info); fFlurryView->DirectConnected(info);
fFlurryView->EnableDirectMode(true); fFlurryView->EnableDirectMode(true);
} }
#endif
} }
+1 -1
View File
@@ -37,7 +37,7 @@ private:
double fStartTime; double fStartTime;
double fOldFrameTime; double fOldFrameTime;
flurry_info_t* fFlurryInfo_t; flurry_info_t* fFlurryInfo;
BTime fTime; BTime fTime;
BDateTime fDateTime; BDateTime fDateTime;
+2 -2
View File
@@ -2,7 +2,7 @@ SubDir HAIKU_TOP src add-ons screen_savers flurry ;
UseBuildFeatureHeaders glu ; UseBuildFeatureHeaders glu ;
UseBuildFeatureHeaders mesa ; UseBuildFeatureHeaders mesa ;
AddResources Message : Flurry.rdef ; AddResources Flurry : Flurry.rdef ;
local sources = local sources =
Flurry.cpp Flurry.cpp
@@ -21,7 +21,7 @@ Includes [ FGristFiles $(sources) ] :
ScreenSaver Flurry : ScreenSaver Flurry :
$(sources) : $(sources) :
be screensaver GL libshared.a localestub $(TARGET_LIBSUPC++) be screensaver GL localestub $(TARGET_LIBSUPC++)
[ BuildFeatureAttribute glu : library ] [ BuildFeatureAttribute glu : library ]
; ;
@@ -32,6 +32,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef _SHARED_H_ #ifndef _SHARED_H_
#define _SHARED_H_ #define _SHARED_H_
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -39,10 +40,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <GL/gl.h> #include <GL/gl.h>
#include <GL/glu.h> #include <GL/glu.h>
struct SmokeV; struct SmokeV;
struct Spark; struct Spark;
struct Star; struct Star;
#define MAX_SPARKS 64 #define MAX_SPARKS 64
#define seraphDistance 2000.0f #define seraphDistance 2000.0f
@@ -54,6 +57,7 @@ struct Star;
#define RandFlt(min, max) (min + (max - min) * rand() / (float) RAND_MAX) #define RandFlt(min, max) (min + (max - min) * rand() / (float) RAND_MAX)
#define RandBell(scale) (scale * (1.0f - (rand() + rand() + rand()) / ((float) RAND_MAX * 1.5f))) #define RandBell(scale) (scale * (1.0f - (rand() + rand() + rand()) / ((float) RAND_MAX * 1.5f)))
typedef enum _ColorModes typedef enum _ColorModes
{ {
redColorMode = 0, redColorMode = 0,
@@ -71,6 +75,7 @@ typedef enum _ColorModes
darkColorMode darkColorMode
} ColorModes; } ColorModes;
typedef struct flurry_info_t { typedef struct flurry_info_t {
flurry_info_t *next; flurry_info_t *next;
ColorModes currentColorMode; ColorModes currentColorMode;
+396 -375
View File
@@ -1,375 +1,396 @@
/* /*
Copyright (c) 2002, Calum Robinson Copyright (c) 2002, Calum Robinson
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this * Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer. list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, * Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution. and/or other materials provided with the distribution.
* Neither the name of the author nor the names of its contributors may be used * Neither the name of the author nor the names of its contributors may be used
to endorse or promote products derived from this software without specific to endorse or promote products derived from this software without specific
prior written permission. prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "Smoke.h"
#include "Shared.h" #include "Smoke.h"
#include "Star.h"
#include "Spark.h" #include "Shared.h"
#include "Star.h"
#define MAXANGLES 16384 #include "Spark.h"
#define NOT_QUITE_DEAD 3
#define streamBias 7.0f #define MAXANGLES 16384
#define incohesion 0.07f #define NOT_QUITE_DEAD 3
#define streamSpeed 450.0
#define gravity 1500000.0f #define streamBias 7.0f
#define intensity 75000.0f; #define incohesion 0.07f
#define streamSize 25000.0f #define streamSpeed 450.0
#define colorIncoherence 0.15f #define gravity 1500000.0f
#define intensity 75000.0f;
static float FastDistance2D(float x, float y) #define streamSize 25000.0f
{ #define colorIncoherence 0.15f
/* this function computes the distance from 0,0 to x,y with ~3.5% error */
float mn;
static float
/* first compute the absolute value of x,y */ FastDistance2D(float x, float y)
x = (x < 0.0f) ? -x : x; {
y = (y < 0.0f) ? -y : y; // this function computes the distance from 0,0 to x,y with ~3.5% error
/* compute the minimum of x,y */ // first compute the absolute value of x,y
mn = x<y?x:y; x = (x < 0.0f) ? -x : x;
y = (y < 0.0f) ? -y : y;
/* return the distance */
return(x+y-(mn*0.5f)-(mn*0.25f)+(mn*0.0625f)); // compute the minimum of x,y
} float mn = x < y ? x : y;
void InitSmoke(SmokeV *s) // return the distance
{ return x + y - (mn * 0.5f) - (mn * 0.25f) + (mn * 0.0625f);
int i; }
s->nextParticle = 0;
s->nextSubParticle = 0;
s->lastParticleTime = 0.25f; void
s->firstTime = 1; InitSmoke(SmokeV* s)
s->frame = 0; {
for (i=0;i<3;i++) { s->nextParticle = 0;
s->old[i] = RandFlt(-100.0, 100.0); s->nextSubParticle = 0;
} s->lastParticleTime = 0.25f;
} s->firstTime = 1;
s->frame = 0;
void UpdateSmoke_ScalarBase(flurry_info_t *info, SmokeV *s)
{ for (int i = 0; i < 3; i++)
int i,j,k; s->old[i] = RandFlt(-100.0, 100.0);
float sx = info->star->position[0]; }
float sy = info->star->position[1];
float sz = info->star->position[2];
double frameRate; void
double frameRateModifier; UpdateSmoke_ScalarBase(flurry_info_t* info, SmokeV* s)
{
float sx = info->star->position[0];
s->frame++; float sy = info->star->position[1];
float sz = info->star->position[2];
if(!s->firstTime) { double frameRate;
/* release 12 puffs every frame */ double frameRateModifier;
if(info->fTime - s->lastParticleTime >= 1.0f / 121.0f) {
float dx,dy,dz,deltax,deltay,deltaz; s->frame++;
float f;
float rsquared; if (!s->firstTime) {
float mag; /* release 12 puffs every frame */
if (info->fTime - s->lastParticleTime >= 1.0f / 121.0f) {
dx = s->old[0] - sx; float dx;
dy = s->old[1] - sy; float dy;
dz = s->old[2] - sz; float dz;
mag = 5.0f; float deltax;
deltax = (dx * mag); float deltay;
deltay = (dy * mag); float deltaz;
deltaz = (dz * mag); float f;
for(i=0;i<info->numStreams;i++) { float rsquared;
float streamSpeedCoherenceFactor; float mag;
s->p[s->nextParticle].delta[0].f[s->nextSubParticle] = deltax; dx = s->old[0] - sx;
s->p[s->nextParticle].delta[1].f[s->nextSubParticle] = deltay; dy = s->old[1] - sy;
s->p[s->nextParticle].delta[2].f[s->nextSubParticle] = deltaz; dz = s->old[2] - sz;
s->p[s->nextParticle].position[0].f[s->nextSubParticle] = sx; mag = 5.0f;
s->p[s->nextParticle].position[1].f[s->nextSubParticle] = sy; deltax = (dx * mag);
s->p[s->nextParticle].position[2].f[s->nextSubParticle] = sz; deltay = (dy * mag);
s->p[s->nextParticle].oldposition[0].f[s->nextSubParticle] = sx; deltaz = (dz * mag);
s->p[s->nextParticle].oldposition[1].f[s->nextSubParticle] = sy; for(int i=0; i < info->numStreams; i++) {
s->p[s->nextParticle].oldposition[2].f[s->nextSubParticle] = sz; float streamSpeedCoherenceFactor;
streamSpeedCoherenceFactor = MAX_(0.0f,1.0f + RandBell(0.25f*incohesion));
dx = s->p[s->nextParticle].position[0].f[s->nextSubParticle] - info->spark[i]->position[0]; s->p[s->nextParticle].delta[0].f[s->nextSubParticle] = deltax;
dy = s->p[s->nextParticle].position[1].f[s->nextSubParticle] - info->spark[i]->position[1]; s->p[s->nextParticle].delta[1].f[s->nextSubParticle] = deltay;
dz = s->p[s->nextParticle].position[2].f[s->nextSubParticle] - info->spark[i]->position[2]; s->p[s->nextParticle].delta[2].f[s->nextSubParticle] = deltaz;
rsquared = (dx*dx+dy*dy+dz*dz); s->p[s->nextParticle].position[0].f[s->nextSubParticle] = sx;
f = streamSpeed * streamSpeedCoherenceFactor; s->p[s->nextParticle].position[1].f[s->nextSubParticle] = sy;
s->p[s->nextParticle].position[2].f[s->nextSubParticle] = sz;
mag = f / (float) sqrt(rsquared); s->p[s->nextParticle].oldposition[0].f[s->nextSubParticle] = sx;
s->p[s->nextParticle].oldposition[1].f[s->nextSubParticle] = sy;
s->p[s->nextParticle].delta[0].f[s->nextSubParticle] -= (dx * mag); s->p[s->nextParticle].oldposition[2].f[s->nextSubParticle] = sz;
s->p[s->nextParticle].delta[1].f[s->nextSubParticle] -= (dy * mag); streamSpeedCoherenceFactor = MAX_(0.0f,1.0f
s->p[s->nextParticle].delta[2].f[s->nextSubParticle] -= (dz * mag); + RandBell(0.25f * incohesion));
s->p[s->nextParticle].color[0].f[s->nextSubParticle] = info->spark[i]->color[0] * (1.0f + RandBell(colorIncoherence)); dx = s->p[s->nextParticle].position[0].f[s->nextSubParticle]
s->p[s->nextParticle].color[1].f[s->nextSubParticle] = info->spark[i]->color[1] * (1.0f + RandBell(colorIncoherence)); - info->spark[i]->position[0];
s->p[s->nextParticle].color[2].f[s->nextSubParticle] = info->spark[i]->color[2] * (1.0f + RandBell(colorIncoherence)); dy = s->p[s->nextParticle].position[1].f[s->nextSubParticle]
s->p[s->nextParticle].color[3].f[s->nextSubParticle] = 0.85f * (1.0f + RandBell(0.5f*colorIncoherence)); - info->spark[i]->position[1];
s->p[s->nextParticle].time.f[s->nextSubParticle] = info->fTime; dz = s->p[s->nextParticle].position[2].f[s->nextSubParticle]
s->p[s->nextParticle].dead.i[s->nextSubParticle] = 0; - info->spark[i]->position[2];
s->p[s->nextParticle].animFrame.i[s->nextSubParticle] = random()&63; rsquared = (dx * dx + dy * dy + dz * dz);
s->nextSubParticle++; f = streamSpeed * streamSpeedCoherenceFactor;
if (s->nextSubParticle==4) {
s->nextParticle++; mag = f / (float)sqrt(rsquared);
s->nextSubParticle=0;
} s->p[s->nextParticle].delta[0].f[s->nextSubParticle]
if (s->nextParticle >= NUMSMOKEPARTICLES/4) { -= (dx * mag);
s->nextParticle = 0; s->p[s->nextParticle].delta[1].f[s->nextSubParticle]
s->nextSubParticle = 0; -= (dy * mag);
} s->p[s->nextParticle].delta[2].f[s->nextSubParticle]
} -= (dz * mag);
s->p[s->nextParticle].color[0].f[s->nextSubParticle]
s->lastParticleTime = info->fTime; = info->spark[i]->color[0] * (1.0f
} + RandBell(colorIncoherence));
} else { s->p[s->nextParticle].color[1].f[s->nextSubParticle]
s->lastParticleTime = info->fTime; = info->spark[i]->color[1] * (1.0f
s->firstTime = 0; + RandBell(colorIncoherence));
} s->p[s->nextParticle].color[2].f[s->nextSubParticle]
= info->spark[i]->color[2] * (1.0f
for(i=0;i<3;i++) { + RandBell(colorIncoherence));
s->old[i] = info->star->position[i]; s->p[s->nextParticle].color[3].f[s->nextSubParticle]
} = 0.85f * (1.0f + RandBell(0.5f*colorIncoherence));
s->p[s->nextParticle].time.f[s->nextSubParticle] = info->fTime;
frameRate = ((double) info->dframe)/(info->fTime); s->p[s->nextParticle].dead.i[s->nextSubParticle] = 0;
frameRateModifier = 42.5f / frameRate; s->p[s->nextParticle].animFrame.i[s->nextSubParticle]
= (random() & 63);
for(i=0;i<NUMSMOKEPARTICLES/4;i++) { s->nextSubParticle++;
for(k=0; k<4; k++) { if (s->nextSubParticle == 4) {
float dx,dy,dz; s->nextParticle++;
float f; s->nextSubParticle = 0;
float rsquared; }
float mag; if (s->nextParticle >= NUMSMOKEPARTICLES / 4) {
float deltax; s->nextParticle = 0;
float deltay; s->nextSubParticle = 0;
float deltaz; }
}
if (s->p[i].dead.i[k]) {
continue; s->lastParticleTime = info->fTime;
} }
} else {
deltax = s->p[i].delta[0].f[k]; s->lastParticleTime = info->fTime;
deltay = s->p[i].delta[1].f[k]; s->firstTime = 0;
deltaz = s->p[i].delta[2].f[k]; }
for(j=0;j<info->numStreams;j++) { for(int i = 0; i < 3; i++)
dx = s->p[i].position[0].f[k] - info->spark[j]->position[0]; s->old[i] = info->star->position[i];
dy = s->p[i].position[1].f[k] - info->spark[j]->position[1];
dz = s->p[i].position[2].f[k] - info->spark[j]->position[2]; frameRate = ((double) info->dframe) / (info->fTime);
rsquared = (dx*dx+dy*dy+dz*dz); frameRateModifier = 42.5f / frameRate;
f = (gravity/rsquared) * frameRateModifier; for(int i = 0; i < NUMSMOKEPARTICLES / 4; i++) {
for(int k = 0; k < 4; k++) {
if ((((i*4)+k) % info->numStreams) == j) { float dx;
f *= 1.0f + streamBias; float dy;
} float dz;
float f;
mag = f / (float) sqrt(rsquared); float rsquared;
float mag;
deltax -= (dx * mag); float deltax;
deltay -= (dy * mag); float deltay;
deltaz -= (dz * mag); float deltaz;
}
if (s->p[i].dead.i[k])
/* slow this particle down by info->drag */ continue;
deltax *= info->drag;
deltay *= info->drag; deltax = s->p[i].delta[0].f[k];
deltaz *= info->drag; deltay = s->p[i].delta[1].f[k];
deltaz = s->p[i].delta[2].f[k];
if((deltax*deltax+deltay*deltay+deltaz*deltaz) >= 25000000.0f) {
s->p[i].dead.i[k] = 1; for(int j = 0; j < info->numStreams; j++) {
continue; dx = s->p[i].position[0].f[k] - info->spark[j]->position[0];
} dy = s->p[i].position[1].f[k] - info->spark[j]->position[1];
dz = s->p[i].position[2].f[k] - info->spark[j]->position[2];
/* update the position */ rsquared = (dx * dx + dy * dy + dz * dz);
s->p[i].delta[0].f[k] = deltax;
s->p[i].delta[1].f[k] = deltay; f = (gravity/rsquared) * frameRateModifier;
s->p[i].delta[2].f[k] = deltaz;
for(j=0;j<3;j++) { if ((((i * 4) + k) % info->numStreams) == j)
s->p[i].oldposition[j].f[k] = s->p[i].position[j].f[k]; f *= 1.0f + streamBias;
s->p[i].position[j].f[k] += (s->p[i].delta[j].f[k])*info->fDeltaTime;
} mag = f / (float) sqrt(rsquared);
}
} deltax -= (dx * mag);
} deltay -= (dy * mag);
deltaz -= (dz * mag);
void DrawSmoke_Scalar(flurry_info_t *info, SmokeV *s, float brightness) }
{
int svi = 0; // slow this particle down by info->drag
int sci = 0; deltax *= info->drag;
int sti = 0; deltay *= info->drag;
int si = 0; deltaz *= info->drag;
float width;
float sx,sy; if ((deltax * deltax + deltay * deltay + deltaz * deltaz)
float u0,v0,u1,v1; >= 25000000.0f) {
float w,z; s->p[i].dead.i[k] = 1;
float screenRatio = info->sys_glWidth / 1024.0f; continue;
float hslash2 = info->sys_glHeight * 0.5f; }
float wslash2 = info->sys_glWidth * 0.5f;
int i,k; // update the position
s->p[i].delta[0].f[k] = deltax;
width = (streamSize+2.5f*info->streamExpansion) * screenRatio; s->p[i].delta[1].f[k] = deltay;
s->p[i].delta[2].f[k] = deltaz;
for (i=0;i<NUMSMOKEPARTICLES/4;i++) for(int j = 0; j < 3; j++) {
{ s->p[i].oldposition[j].f[k] = s->p[i].position[j].f[k];
for (k=0; k<4; k++) { s->p[i].position[j].f[k]
float thisWidth; += (s->p[i].delta[j].f[k]) * info->fDeltaTime;
float oldz; }
}
if (s->p[i].dead.i[k]) { }
continue; }
}
thisWidth = (streamSize + (info->fTime - s->p[i].time.f[k])*info->streamExpansion) * screenRatio;
if (thisWidth >= width) void
{ DrawSmoke_Scalar(flurry_info_t* info, SmokeV* s, float brightness)
s->p[i].dead.i[k] = 1; {
continue; int svi = 0;
} int sci = 0;
z = s->p[i].position[2].f[k]; int sti = 0;
sx = s->p[i].position[0].f[k] * info->sys_glWidth / z + wslash2; int si = 0;
sy = s->p[i].position[1].f[k] * info->sys_glWidth / z + hslash2; float width;
oldz = s->p[i].oldposition[2].f[k]; float sx;
if (sx > info->sys_glWidth+50.0f || sx < -50.0f || sy > info->sys_glHeight+50.0f || sy < -50.0f || z < 25.0f || oldz < 25.0f) float sy;
{ float u0;
continue; float v0;
} float u1;
float v1;
w = MAX_(1.0f,thisWidth/z); float w;
{ float z;
float oldx = s->p[i].oldposition[0].f[k]; float screenRatio = info->sys_glWidth / 1024.0f;
float oldy = s->p[i].oldposition[1].f[k]; float hslash2 = info->sys_glHeight * 0.5f;
float oldscreenx = (oldx * info->sys_glWidth / oldz) + wslash2; float wslash2 = info->sys_glWidth * 0.5f;
float oldscreeny = (oldy * info->sys_glWidth / oldz) + hslash2;
float dx = (sx-oldscreenx); width = (streamSize + 2.5f * info->streamExpansion) * screenRatio;
float dy = (sy-oldscreeny);
for (int i = 0; i < NUMSMOKEPARTICLES / 4; i++) {
float d = FastDistance2D(dx, dy); for (int k = 0; k < 4; k++) {
float thisWidth;
float sm, os, ow; float oldz;
if (d)
{ if (s->p[i].dead.i[k])
sm = w/d; continue;
}
else thisWidth = (streamSize + (info->fTime - s->p[i].time.f[k])
{ * info->streamExpansion) * screenRatio;
sm = 0.0f; if (thisWidth >= width) {
} s->p[i].dead.i[k] = 1;
ow = MAX_(1.0f,thisWidth/oldz); continue;
if (d) }
{ z = s->p[i].position[2].f[k];
os = ow/d; sx = s->p[i].position[0].f[k] * info->sys_glWidth / z + wslash2;
} sy = s->p[i].position[1].f[k] * info->sys_glWidth / z + hslash2;
else oldz = s->p[i].oldposition[2].f[k];
{ if (sx > info->sys_glWidth + 50.0f || sx < -50.0f
os = 0.0f; || sy > info->sys_glHeight+50.0f || sy < -50.0f || z < 25.0f
} || oldz < 25.0f) {
continue;
{ }
floatToVector cmv;
float cm; w = MAX_(1.0f, thisWidth / z);
float m = 1.0f + sm; {
float oldx = s->p[i].oldposition[0].f[k];
float dxs = dx*sm; float oldy = s->p[i].oldposition[1].f[k];
float dys = dy*sm; float oldscreenx = (oldx * info->sys_glWidth / oldz) + wslash2;
float dxos = dx*os; float oldscreeny = (oldy * info->sys_glWidth / oldz) + hslash2;
float dyos = dy*os; float dx = (sx-oldscreenx);
float dxm = dx*m; float dy = (sy-oldscreeny);
float dym = dy*m;
float d = FastDistance2D(dx, dy);
s->p[i].animFrame.i[k]++;
if (s->p[i].animFrame.i[k] >= 64) float sm, os, ow;
{ if (d)
s->p[i].animFrame.i[k] = 0; sm = w / d;
} else
sm = 0.0f;
u0 = (s->p[i].animFrame.i[k]&&7) * 0.125f;
v0 = (s->p[i].animFrame.i[k]>>3) * 0.125f; ow = MAX_(1.0f,thisWidth/oldz);
u1 = u0 + 0.125f; if (d)
v1 = v0 + 0.125f; os = ow / d;
u1 = u0 + 0.125f; else
v1 = v0 + 0.125f; os = 0.0f;
cm = (1.375f - thisWidth/width);
if (s->p[i].dead.i[k] == 3) {
{ floatToVector cmv;
cm *= 0.125f; float cm;
s->p[i].dead.i[k] = 1; float m = 1.0f + sm;
}
si++; float dxs = dx * sm;
cm *= brightness; float dys = dy * sm;
cmv.f[0] = s->p[i].color[0].f[k]*cm; float dxos = dx * os;
cmv.f[1] = s->p[i].color[1].f[k]*cm; float dyos = dy * os;
cmv.f[2] = s->p[i].color[2].f[k]*cm; float dxm = dx * m;
cmv.f[3] = s->p[i].color[3].f[k]*cm; float dym = dy * m;
#if 0 s->p[i].animFrame.i[k]++;
/* MDT we can't use vectors in the Scalar routine */ if (s->p[i].animFrame.i[k] >= 64)
s->seraphimColors[sci++].v = cmv.v; s->p[i].animFrame.i[k] = 0;
s->seraphimColors[sci++].v = cmv.v;
s->seraphimColors[sci++].v = cmv.v; u0 = (s->p[i].animFrame.i[k]&&7) * 0.125f;
s->seraphimColors[sci++].v = cmv.v; v0 = (s->p[i].animFrame.i[k]>>3) * 0.125f;
#else u1 = u0 + 0.125f;
{ v1 = v0 + 0.125f;
int ii, jj; u1 = u0 + 0.125f;
for (jj = 0; jj < 4; jj++) { v1 = v0 + 0.125f;
for (ii = 0; ii < 4; ii++) { cm = (1.375f - thisWidth/width);
s->seraphimColors[sci].f[ii] = cmv.f[ii]; if (s->p[i].dead.i[k] == 3) {
} cm *= 0.125f;
sci += 1; s->p[i].dead.i[k] = 1;
} }
} si++;
#endif cm *= brightness;
cmv.f[0] = s->p[i].color[0].f[k]*cm;
s->seraphimTextures[sti++] = u0; cmv.f[1] = s->p[i].color[1].f[k]*cm;
s->seraphimTextures[sti++] = v0; cmv.f[2] = s->p[i].color[2].f[k]*cm;
s->seraphimTextures[sti++] = u0; cmv.f[3] = s->p[i].color[3].f[k]*cm;
s->seraphimTextures[sti++] = v1;
#if 0
s->seraphimTextures[sti++] = u1; // MDT we can't use vectors in the Scalar routine
s->seraphimTextures[sti++] = v1; s->seraphimColors[sci++].v = cmv.v;
s->seraphimTextures[sti++] = u1; s->seraphimColors[sci++].v = cmv.v;
s->seraphimTextures[sti++] = v0; s->seraphimColors[sci++].v = cmv.v;
s->seraphimColors[sci++].v = cmv.v;
s->seraphimVertices[svi].f[0] = sx+dxm-dys; #else
s->seraphimVertices[svi].f[1] = sy+dym+dxs; {
s->seraphimVertices[svi].f[2] = sx+dxm+dys; for (int jj = 0; jj < 4; jj++) {
s->seraphimVertices[svi].f[3] = sy+dym-dxs; for (int ii = 0; ii < 4; ii++)
svi++; s->seraphimColors[sci].f[ii] = cmv.f[ii];
sci += 1;
s->seraphimVertices[svi].f[0] = oldscreenx-dxm+dyos; }
s->seraphimVertices[svi].f[1] = oldscreeny-dym-dxos; }
s->seraphimVertices[svi].f[2] = oldscreenx-dxm-dyos; #endif
s->seraphimVertices[svi].f[3] = oldscreeny-dym+dxos;
svi++; s->seraphimTextures[sti++] = u0;
} s->seraphimTextures[sti++] = v0;
} s->seraphimTextures[sti++] = u0;
} s->seraphimTextures[sti++] = v1;
}
glColorPointer(4,GL_FLOAT,0,s->seraphimColors); s->seraphimTextures[sti++] = u1;
glVertexPointer(2,GL_FLOAT,0,s->seraphimVertices); s->seraphimTextures[sti++] = v1;
glTexCoordPointer(2,GL_FLOAT,0,s->seraphimTextures); s->seraphimTextures[sti++] = u1;
glDrawArrays(GL_QUADS,0,si*4); s->seraphimTextures[sti++] = v0;
}
s->seraphimVertices[svi].f[0] = sx + dxm - dys;
s->seraphimVertices[svi].f[1] = sy + dym + dxs;
s->seraphimVertices[svi].f[2] = sx + dxm + dys;
s->seraphimVertices[svi].f[3] = sy + dym - dxs;
svi++;
s->seraphimVertices[svi].f[0] = oldscreenx - dxm + dyos;
s->seraphimVertices[svi].f[1] = oldscreeny - dym - dxos;
s->seraphimVertices[svi].f[2] = oldscreenx - dxm - dyos;
s->seraphimVertices[svi].f[3] = oldscreeny - dym + dxos;
svi++;
}
}
}
}
glColorPointer(4, GL_FLOAT, 0, s->seraphimColors);
glVertexPointer(2, GL_FLOAT, 0, s->seraphimVertices);
glTexCoordPointer(2, GL_FLOAT, 0, s->seraphimTextures);
glDrawArrays(GL_QUADS, 0, si * 4);
}
+6
View File
@@ -32,10 +32,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef _SMOKE_H_ #ifndef _SMOKE_H_
#define _SMOKE_H_ #define _SMOKE_H_
struct flurry_info_t; struct flurry_info_t;
#define NUMSMOKEPARTICLES 3600 #define NUMSMOKEPARTICLES 3600
typedef union { typedef union {
float f[4]; float f[4];
} floatToVector; } floatToVector;
@@ -44,6 +47,7 @@ typedef union {
unsigned int i[4]; unsigned int i[4];
} intToVector; } intToVector;
typedef struct SmokeParticleV typedef struct SmokeParticleV
{ {
floatToVector color[4]; floatToVector color[4];
@@ -69,8 +73,10 @@ typedef struct SmokeV
float seraphimTextures[NUMSMOKEPARTICLES*2*4]; float seraphimTextures[NUMSMOKEPARTICLES*2*4];
} SmokeV; } SmokeV;
void InitSmoke(SmokeV *s); void InitSmoke(SmokeV *s);
void UpdateSmoke_ScalarBase(flurry_info_t *flurry, SmokeV *s); void UpdateSmoke_ScalarBase(flurry_info_t *flurry, SmokeV *s);
void DrawSmoke_Scalar(flurry_info_t *flurry, SmokeV *s, float); void DrawSmoke_Scalar(flurry_info_t *flurry, SmokeV *s, float);
#endif // _SMOKE_H_ #endif // _SMOKE_H_
+297 -298
View File
@@ -1,298 +1,297 @@
/* /*
Copyright (c) 2002, Calum Robinson Copyright (c) 2002, Calum Robinson
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this * Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer. list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, * Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution. and/or other materials provided with the distribution.
* Neither the name of the author nor the names of its contributors may be used * Neither the name of the author nor the names of its contributors may be used
to endorse or promote products derived from this software without specific to endorse or promote products derived from this software without specific
prior written permission. prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "Spark.h"
#include "Shared.h"
#include "Spark.h"
#define BIGMYSTERY 1800.0 #include "Shared.h"
#define MAXANGLES 16384
#define fieldCoherence 0 #define BIGMYSTERY 1800.0
#define fieldSpeed 12.0f #define MAXANGLES 16384
#define fieldRange 1000.0f
#define fieldCoherence 0
void InitSpark(Spark *s) #define fieldSpeed 12.0f
{ #define fieldRange 1000.0f
int i;
for (i=0;i<3;i++)
{ void
s->position[i] = RandFlt(-100.0, 100.0); InitSpark(Spark* s)
} {
} for (int i = 0; i < 3; i++)
s->position[i] = RandFlt(-100.0, 100.0);
void DrawSpark(flurry_info_t *info, Spark *s) }
{
const float black[4] = {0.0f,0.0f,0.0f,1.0f};
float width,sx,sy; void DrawSpark(flurry_info_t* info, Spark* s)
float a; {
float c = 0.0625f; const float black[4] = {0.0f, 0.0f, 0.0f, 1.0f};
float screenx; float width;
float screeny; float sx;
float w,z, scale; float sy;
int k; float a;
width = 60000.0f * info->sys_glWidth / 1024.0f; float c = 0.0625f;
float screenx;
z = s->position[2]; float screeny;
sx = s->position[0] * info->sys_glWidth / z + info->sys_glWidth * 0.5f; float w;
sy = s->position[1] * info->sys_glWidth / z + info->sys_glHeight * 0.5f; float z;
w = width*4.0f / z; float scale;
width = 60000.0f * info->sys_glWidth / 1024.0f;
screenx = sx;
screeny = sy; z = s->position[2];
sx = s->position[0] * info->sys_glWidth / z + info->sys_glWidth * 0.5f;
glPushMatrix(); sy = s->position[1] * info->sys_glWidth / z + info->sys_glHeight * 0.5f;
glTranslatef(screenx,screeny,0.0f); w = width*4.0f / z;
scale = w/50.0f;
glScalef(scale,scale,0.0f); screenx = sx;
for (k=0;k<12;k++) screeny = sy;
{
a = ((float) (random() % 3600)) / 10.0f; glPushMatrix();
glRotatef(a,0.0f,0.0f,1.0f); glTranslatef(screenx,screeny,0.0f);
glBegin(GL_QUAD_STRIP); scale = w/50.0f;
glColor4fv(black); glScalef(scale,scale,0.0f);
glVertex2f(-3.0f,0.0f); for (int k = 0; k < 12; k++) {
a = 2.0f + (float) (random() & 255) * c; a = ((float)(random() % 3600)) / 10.0f;
glVertex2f(-3.0f,a); glRotatef(a,0.0f,0.0f,1.0f);
glColor4fv(s->color); glBegin(GL_QUAD_STRIP);
glVertex2f(0.0f,0.0f); glColor4fv(black);
glColor4fv(black); glVertex2f(-3.0f,0.0f);
glVertex2f(0.0f,a); a = 2.0f + (float) (random() & 255) * c;
glVertex2f(3.0f,0.0f); glVertex2f(-3.0f,a);
glVertex2f(3.0f,a); glColor4fv(s->color);
glEnd(); glVertex2f(0.0f,0.0f);
} glColor4fv(black);
glPopMatrix(); glVertex2f(0.0f,a);
} glVertex2f(3.0f,0.0f);
glVertex2f(3.0f,a);
void UpdateSparkColour(flurry_info_t *info, Spark *s) glEnd();
{ }
const float rotationsPerSecond = (float) (2.0*M_PI*fieldSpeed/MAXANGLES);
double thisPointInRadians; glPopMatrix();
double thisAngle = info->fTime*rotationsPerSecond; }
float cf;
float cycleTime = 20.0f;
float colorRot; void
float redPhaseShift; UpdateSparkColour(flurry_info_t* info, Spark* s)
float greenPhaseShift; {
float bluePhaseShift; const float rotationsPerSecond = (float)(2.0 * M_PI * fieldSpeed
float baseRed; / MAXANGLES);
float baseGreen; double thisPointInRadians;
float baseBlue; double thisAngle = info->fTime*rotationsPerSecond;
float colorTime; float cf;
float cycleTime = 20.0f;
if (info->currentColorMode == rainbowColorMode) float colorRot;
{ float redPhaseShift;
cycleTime = 1.5f; float greenPhaseShift;
} float bluePhaseShift;
else if (info->currentColorMode == tiedyeColorMode) float baseRed;
{ float baseGreen;
cycleTime = 4.5f; float baseBlue;
} float colorTime;
else if (info->currentColorMode == cyclicColorMode)
{ if (info->currentColorMode == rainbowColorMode)
cycleTime = 20.0f; cycleTime = 1.5f;
} else if (info->currentColorMode == tiedyeColorMode)
else if (info->currentColorMode == slowCyclicColorMode) cycleTime = 4.5f;
{ else if (info->currentColorMode == cyclicColorMode)
cycleTime = 120.0f; cycleTime = 20.0f;
} else if (info->currentColorMode == slowCyclicColorMode)
colorRot = (float) (2.0*M_PI/cycleTime); cycleTime = 120.0f;
redPhaseShift = 0.0f; /* cycleTime * 0.0f / 3.0f */
greenPhaseShift = cycleTime / 3.0f; colorRot = (float)(2.0 * M_PI / cycleTime);
bluePhaseShift = cycleTime * 2.0f / 3.0f ; redPhaseShift = 0.0f; /* cycleTime * 0.0f / 3.0f */
colorTime = info->fTime; greenPhaseShift = cycleTime / 3.0f;
if (info->currentColorMode == whiteColorMode) bluePhaseShift = cycleTime * 2.0f / 3.0f;
{ colorTime = info->fTime;
baseRed = 0.1875f; if (info->currentColorMode == whiteColorMode) {
baseGreen = 0.1875f; baseRed = 0.1875f;
baseBlue = 0.1875f; baseGreen = 0.1875f;
} baseBlue = 0.1875f;
else if (info->currentColorMode == multiColorMode) } else if (info->currentColorMode == multiColorMode) {
{ baseRed = 0.0625f;
baseRed = 0.0625f; baseGreen = 0.0625f;
baseGreen = 0.0625f; baseBlue = 0.0625f;
baseBlue = 0.0625f; } else if (info->currentColorMode == darkColorMode) {
} baseRed = 0.0f;
else if (info->currentColorMode == darkColorMode) baseGreen = 0.0f;
{ baseBlue = 0.0f;
baseRed = 0.0f; } else {
baseGreen = 0.0f; if (info->currentColorMode < slowCyclicColorMode)
baseBlue = 0.0f; colorTime = (info->currentColorMode / 6.0f) * cycleTime;
} else
else colorTime = info->fTime + info->randomSeed;
{
if (info->currentColorMode < slowCyclicColorMode) baseRed = 0.109375f
{ * ((float)cos((colorTime + redPhaseShift) * colorRot) + 1.0f);
colorTime = (info->currentColorMode / 6.0f) * cycleTime; baseGreen = 0.109375f
} * ((float)cos((colorTime + greenPhaseShift) * colorRot) + 1.0f);
else baseBlue = 0.109375f
{ * ((float)cos((colorTime + bluePhaseShift) * colorRot) + 1.0f);
colorTime = info->fTime + info->randomSeed; }
}
baseRed = 0.109375f * ((float) cos((colorTime+redPhaseShift)*colorRot)+1.0f); cf = ((float)(cos(7.0 * ((info->fTime) * rotationsPerSecond))
baseGreen = 0.109375f * ((float) cos((colorTime+greenPhaseShift)*colorRot)+1.0f); + cos(3.0 * ((info->fTime) * rotationsPerSecond))
baseBlue = 0.109375f * ((float) cos((colorTime+bluePhaseShift)*colorRot)+1.0f); + cos(13.0 * ((info->fTime) * rotationsPerSecond))));
} cf /= 6.0f;
cf += 2.0f;
cf = ((float) (cos(7.0*((info->fTime)*rotationsPerSecond)) + thisPointInRadians = 2.0 * M_PI * (double) s->mystery / (double) BIGMYSTERY;
cos(3.0*((info->fTime)*rotationsPerSecond)) +
cos(13.0*((info->fTime)*rotationsPerSecond)))); s->color[0] = baseRed + 0.0625f
cf /= 6.0f; * (0.5f + (float)cos((15.0 * (thisPointInRadians + 3.0*thisAngle)))
cf += 2.0f; + (float)sin((7.0 * (thisPointInRadians + thisAngle))));
thisPointInRadians = 2.0 * M_PI * (double) s->mystery / (double) BIGMYSTERY; s->color[1] = baseGreen + 0.0625f
* (0.5f + (float)sin(((thisPointInRadians) + thisAngle)));
s->color[0] = baseRed + 0.0625f * s->color[2] = baseBlue + 0.0625f
(0.5f + (float) cos((15.0 * (thisPointInRadians + 3.0*thisAngle))) + * (0.5f + (float)cos((37.0 * (thisPointInRadians + thisAngle))));
(float) sin((7.0 * (thisPointInRadians + thisAngle)))); }
s->color[1] = baseGreen + 0.0625f *
(0.5f + (float) sin(((thisPointInRadians) + thisAngle)));
s->color[2] = baseBlue + 0.0625f * void
(0.5f + (float) cos((37.0 * (thisPointInRadians + thisAngle)))); UpdateSpark(flurry_info_t* info, Spark* s)
} {
const float rotationsPerSecond = (float) (2.0*M_PI*fieldSpeed/MAXANGLES);
void UpdateSpark(flurry_info_t *info, Spark *s) double thisPointInRadians;
{ double thisAngle = info->fTime*rotationsPerSecond;
const float rotationsPerSecond = (float) (2.0*M_PI*fieldSpeed/MAXANGLES); float cf;
double thisPointInRadians; double tmpX1,tmpY1,tmpZ1;
double thisAngle = info->fTime*rotationsPerSecond; double tmpX2,tmpY2,tmpZ2;
float cf; double tmpX3,tmpY3,tmpZ3;
int i; double tmpX4,tmpY4,tmpZ4;
double tmpX1,tmpY1,tmpZ1; double rotation;
double tmpX2,tmpY2,tmpZ2; double cr;
double tmpX3,tmpY3,tmpZ3; double sr;
double tmpX4,tmpY4,tmpZ4; float cycleTime = 20.0f;
double rotation; float colorRot;
double cr; float redPhaseShift;
double sr; float greenPhaseShift;
float cycleTime = 20.0f; float bluePhaseShift;
float colorRot; float baseRed;
float redPhaseShift; float baseGreen;
float greenPhaseShift; float baseBlue;
float bluePhaseShift; float colorTime;
float baseRed;
float baseGreen; float old[3];
float baseBlue;
float colorTime; if (info->currentColorMode == rainbowColorMode)
cycleTime = 1.5f;
float old[3]; else if (info->currentColorMode == tiedyeColorMode)
cycleTime = 4.5f;
if (info->currentColorMode == rainbowColorMode) { else if (info->currentColorMode == cyclicColorMode)
cycleTime = 1.5f; cycleTime = 20.0f;
} else if (info->currentColorMode == tiedyeColorMode) { else if (info->currentColorMode == slowCyclicColorMode)
cycleTime = 4.5f; cycleTime = 120.0f;
} else if (info->currentColorMode == cyclicColorMode) {
cycleTime = 20.0f; colorRot = (float)(2.0 * M_PI / cycleTime);
} else if (info->currentColorMode == slowCyclicColorMode) { redPhaseShift = 0.0f; /* cycleTime * 0.0f / 3.0f */
cycleTime = 120.0f; greenPhaseShift = cycleTime / 3.0f;
} bluePhaseShift = cycleTime * 2.0f / 3.0f ;
colorRot = (float) (2.0*M_PI/cycleTime); colorTime = info->fTime;
redPhaseShift = 0.0f; /* cycleTime * 0.0f / 3.0f */ if (info->currentColorMode == whiteColorMode) {
greenPhaseShift = cycleTime / 3.0f; baseRed = 0.1875f;
bluePhaseShift = cycleTime * 2.0f / 3.0f ; baseGreen = 0.1875f;
colorTime = info->fTime; baseBlue = 0.1875f;
if (info->currentColorMode == whiteColorMode) { } else if (info->currentColorMode == multiColorMode) {
baseRed = 0.1875f; baseRed = 0.0625f;
baseGreen = 0.1875f; baseGreen = 0.0625f;
baseBlue = 0.1875f; baseBlue = 0.0625f;
} else if (info->currentColorMode == multiColorMode) { } else if (info->currentColorMode == darkColorMode) {
baseRed = 0.0625f; baseRed = 0.0f;
baseGreen = 0.0625f; baseGreen = 0.0f;
baseBlue = 0.0625f; baseBlue = 0.0f;
} else if (info->currentColorMode == darkColorMode) { } else {
baseRed = 0.0f; if (info->currentColorMode < slowCyclicColorMode)
baseGreen = 0.0f; colorTime = (info->currentColorMode / 6.0f) * cycleTime;
baseBlue = 0.0f; else
} else { colorTime = info->fTime + info->randomSeed;
if(info->currentColorMode < slowCyclicColorMode) {
colorTime = (info->currentColorMode / 6.0f) * cycleTime; baseRed = 0.109375f
} else { * ((float)cos((colorTime + redPhaseShift) * colorRot) + 1.0f);
colorTime = info->fTime + info->randomSeed; baseGreen = 0.109375f
} * ((float)cos((colorTime + greenPhaseShift) * colorRot) + 1.0f);
baseRed = 0.109375f * ((float) cos((colorTime+redPhaseShift)*colorRot)+1.0f); baseBlue = 0.109375f
baseGreen = 0.109375f * ((float) cos((colorTime+greenPhaseShift)*colorRot)+1.0f); * ((float)cos((colorTime + bluePhaseShift) * colorRot) + 1.0f);
baseBlue = 0.109375f * ((float) cos((colorTime+bluePhaseShift)*colorRot)+1.0f); }
}
for (int i = 0; i < 3; i++)
for (i=0;i<3;i++) { old[i] = s->position[i];
old[i] = s->position[i];
} cf = ((float)cos(7.0 * ((info->fTime) * rotationsPerSecond)
+ (float)cos(3.0 * ((info->fTime) * rotationsPerSecond))
cf = ((float) (cos(7.0*((info->fTime)*rotationsPerSecond)) + + (float)cos(13.0 * ((info->fTime) * rotationsPerSecond))));
cos(3.0*((info->fTime)*rotationsPerSecond)) + cf /= 6.0f;
cos(13.0*((info->fTime)*rotationsPerSecond)))); cf += 2.0f;
cf /= 6.0f; thisPointInRadians = 2.0 * M_PI * (double)s->mystery / (double)BIGMYSTERY;
cf += 2.0f;
thisPointInRadians = 2.0 * M_PI * (double) s->mystery / (double) BIGMYSTERY; s->color[0] = baseRed + 0.0625f
* (0.5f + (float) cos((15.0 * (thisPointInRadians + 3.0*thisAngle)))
s->color[0] = baseRed + 0.0625f * + (float) sin((7.0 * (thisPointInRadians + thisAngle))));
(0.5f + (float) cos((15.0 * (thisPointInRadians + 3.0*thisAngle))) + s->color[1] = baseGreen + 0.0625f
(float) sin((7.0 * (thisPointInRadians + thisAngle)))); * (0.5f + (float) sin(((thisPointInRadians) + thisAngle)));
s->color[1] = baseGreen + 0.0625f * s->color[2] = baseBlue + 0.0625f
(0.5f + (float) sin(((thisPointInRadians) + thisAngle))); * (0.5f + (float) cos((37.0 * (thisPointInRadians + thisAngle))));
s->color[2] = baseBlue + 0.0625f * s->position[0] = fieldRange * cf
(0.5f + (float) cos((37.0 * (thisPointInRadians + thisAngle)))); * (float)cos(11.0 * (thisPointInRadians + (3.0*thisAngle)));
s->position[0] = fieldRange * cf * s->position[1] = fieldRange * cf *
(float) cos(11.0 * (thisPointInRadians + (3.0*thisAngle))); (float) sin(12.0 * (thisPointInRadians + (4.0*thisAngle)));
s->position[1] = fieldRange * cf * s->position[2] = fieldRange *
(float) sin(12.0 * (thisPointInRadians + (4.0*thisAngle))); (float) cos((23.0 * (thisPointInRadians + (12.0*thisAngle))));
s->position[2] = fieldRange *
(float) cos((23.0 * (thisPointInRadians + (12.0*thisAngle)))); rotation = thisAngle * 0.501 + 5.01 * (double)s->mystery
/ (double)BIGMYSTERY;
rotation = thisAngle*0.501 + 5.01 * (double) s->mystery / (double) BIGMYSTERY; cr = cos(rotation);
cr = cos(rotation); sr = sin(rotation);
sr = sin(rotation); tmpX1 = s->position[0] * cr - s->position[1] * sr;
tmpX1 = s->position[0] * cr - s->position[1] * sr; tmpY1 = s->position[1] * cr + s->position[0] * sr;
tmpY1 = s->position[1] * cr + s->position[0] * sr; tmpZ1 = s->position[2];
tmpZ1 = s->position[2];
tmpX2 = tmpX1 * cr - tmpZ1 * sr;
tmpX2 = tmpX1 * cr - tmpZ1 * sr; tmpY2 = tmpY1;
tmpY2 = tmpY1; tmpZ2 = tmpZ1 * cr + tmpX1 * sr;
tmpZ2 = tmpZ1 * cr + tmpX1 * sr;
tmpX3 = tmpX2;
tmpX3 = tmpX2; tmpY3 = tmpY2 * cr - tmpZ2 * sr;
tmpY3 = tmpY2 * cr - tmpZ2 * sr; tmpZ3 = tmpZ2 * cr + tmpY2 * sr + seraphDistance;
tmpZ3 = tmpZ2 * cr + tmpY2 * sr + seraphDistance;
rotation = thisAngle * 2.501 + 85.01 * (double)s->mystery
rotation = thisAngle*2.501 + 85.01 * (double) s->mystery / (double) BIGMYSTERY; / (double)BIGMYSTERY;
cr = cos(rotation); cr = cos(rotation);
sr = sin(rotation); sr = sin(rotation);
tmpX4 = tmpX3 * cr - tmpY3 * sr; tmpX4 = tmpX3 * cr - tmpY3 * sr;
tmpY4 = tmpY3 * cr + tmpX3 * sr; tmpY4 = tmpY3 * cr + tmpX3 * sr;
tmpZ4 = tmpZ3; tmpZ4 = tmpZ3;
s->position[0] = (float) tmpX4 + RandBell(5.0f*fieldCoherence); s->position[0] = (float) tmpX4 + RandBell(5.0f*fieldCoherence);
s->position[1] = (float) tmpY4 + RandBell(5.0f*fieldCoherence); s->position[1] = (float) tmpY4 + RandBell(5.0f*fieldCoherence);
s->position[2] = (float) tmpZ4 + RandBell(5.0f*fieldCoherence); s->position[2] = (float) tmpZ4 + RandBell(5.0f*fieldCoherence);
for (i=0;i<3;i++) { for (int i = 0;i < 3; i++)
s->delta[i] = (s->position[i] - old[i])/info->fDeltaTime; s->delta[i] = (s->position[i] - old[i]) / info->fDeltaTime;
} }
}
+4
View File
@@ -32,8 +32,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef _SPARK_H_ #ifndef _SPARK_H_
#define _SPARK_H_ #define _SPARK_H_
struct flurry_info_t; struct flurry_info_t;
typedef struct Spark typedef struct Spark
{ {
float position[3]; float position[3];
@@ -42,9 +44,11 @@ typedef struct Spark
float color[4]; float color[4];
} Spark; } Spark;
void InitSpark(Spark *s); void InitSpark(Spark *s);
void DrawSpark(flurry_info_t *info, Spark *s); void DrawSpark(flurry_info_t *info, Spark *s);
void UpdateSparkColour(flurry_info_t *info, Spark *s); void UpdateSparkColour(flurry_info_t *info, Spark *s);
void UpdateSpark(flurry_info_t *info, Spark *s); void UpdateSpark(flurry_info_t *info, Spark *s);
#endif // _SPARK_H_ #endif // _SPARK_H_
+122 -102
View File
@@ -1,102 +1,122 @@
/* /*
Copyright (c) 2002, Calum Robinson Copyright (c) 2002, Calum Robinson
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this * Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer. list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, * Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution. and/or other materials provided with the distribution.
* Neither the name of the author nor the names of its contributors may be used * Neither the name of the author nor the names of its contributors may be used
to endorse or promote products derived from this software without specific to endorse or promote products derived from this software without specific
prior written permission. prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "Star.h"
#include "Shared.h"
#include "Star.h"
#define BIGMYSTERY 1800.0 #include "Shared.h"
#define MAXANGLES 16384
/* Construction/Destruction */ #define BIGMYSTERY 1800.0
void InitStar(Star *s) #define MAXANGLES 16384
{
int i;
for (i=0;i<3;i++) { // Construction/Destruction
s->position[i] = RandFlt(-10000.0, 10000.0); void
} InitStar(Star* s)
s->rotSpeed = RandFlt(0.4, 0.9); {
s->mystery = RandFlt(0.0, 10.0); for (int i=0; i < 3; i++)
} s->position[i] = RandFlt(-10000.0, 10000.0);
void UpdateStar(flurry_info_t *info, Star *s) s->rotSpeed = RandFlt(0.4, 0.9);
{ s->mystery = RandFlt(0.0, 10.0);
/* speed control */ }
float rotationsPerSecond = (float) (2.0*M_PI*12.0/MAXANGLES) * s->rotSpeed;
double thisPointInRadians;
double thisAngle = info->fTime*rotationsPerSecond; void
float cf; UpdateStar(flurry_info_t* info, Star* s)
double tmpX1,tmpY1,tmpZ1; {
double tmpX2,tmpY2,tmpZ2; /* speed control */
double tmpX3,tmpY3,tmpZ3; float rotationsPerSecond = (float)(2.0 * M_PI * 12.0 / MAXANGLES)
double tmpX4,tmpY4,tmpZ4; * s->rotSpeed;
double rotation; double thisPointInRadians;
double cr; double thisAngle = info->fTime * rotationsPerSecond;
double sr; float cf;
double tmpX1;
s->ate = 0; double tmpY1;
double tmpZ1;
cf = ((float) (cos(7.0*((info->fTime)*rotationsPerSecond)) + double tmpX2;
cos(3.0*((info->fTime)*rotationsPerSecond)) + double tmpY2;
cos(13.0*((info->fTime)*rotationsPerSecond)))); double tmpZ2;
cf /= 6.0f; double tmpX3;
cf += 0.75f; double tmpY3;
thisPointInRadians = 2.0 * M_PI * (double) s->mystery / (double) BIGMYSTERY; double tmpZ3;
double tmpX4;
s->position[0] = 250.0f * cf * (float) cos(11.0 * (thisPointInRadians + (3.0*thisAngle))); double tmpY4;
s->position[1] = 250.0f * cf * (float) sin(12.0 * (thisPointInRadians + (4.0*thisAngle))); double tmpZ4;
s->position[2] = 250.0f * (float) cos((23.0 * (thisPointInRadians + (12.0*thisAngle)))); double rotation;
double cr;
rotation = thisAngle*0.501 + 5.01 * (double) s->mystery / (double) BIGMYSTERY; double sr;
cr = cos(rotation);
sr = sin(rotation); s->ate = 0;
tmpX1 = s->position[0] * cr - s->position[1] * sr;
tmpY1 = s->position[1] * cr + s->position[0] * sr; cf = ((float)(cos(7.0 * ((info->fTime) * rotationsPerSecond))
tmpZ1 = s->position[2]; + cos(3.0 * ((info->fTime) * rotationsPerSecond))
+ cos(13.0 * ((info->fTime) * rotationsPerSecond))));
tmpX2 = tmpX1 * cr - tmpZ1 * sr; cf /= 6.0f;
tmpY2 = tmpY1; cf += 0.75f;
tmpZ2 = tmpZ1 * cr + tmpX1 * sr; thisPointInRadians = 2.0 * M_PI * (double) s->mystery / (double) BIGMYSTERY;
tmpX3 = tmpX2; s->position[0] = 250.0f * cf * (float)cos(11.0 * (thisPointInRadians
tmpY3 = tmpY2 * cr - tmpZ2 * sr; + (3.0 * thisAngle)));
tmpZ3 = tmpZ2 * cr + tmpY2 * sr + seraphDistance; s->position[1] = 250.0f * cf * (float)sin(12.0 * (thisPointInRadians
+ (4.0 * thisAngle)));
rotation = thisAngle*2.501 + 85.01 * (double) s->mystery / (double) BIGMYSTERY; s->position[2] = 250.0f * (float)cos((23.0 * (thisPointInRadians
cr = cos(rotation); + (12.0 * thisAngle))));
sr = sin(rotation);
tmpX4 = tmpX3 * cr - tmpY3 * sr; rotation = thisAngle * 0.501 + 5.01 * (double)s->mystery
tmpY4 = tmpY3 * cr + tmpX3 * sr; / (double)BIGMYSTERY;
tmpZ4 = tmpZ3; cr = cos(rotation);
sr = sin(rotation);
s->position[0] = (float) tmpX4; tmpX1 = s->position[0] * cr - s->position[1] * sr;
s->position[1] = (float) tmpY4; tmpY1 = s->position[1] * cr + s->position[0] * sr;
s->position[2] = (float) tmpZ4; tmpZ1 = s->position[2];
}
tmpX2 = tmpX1 * cr - tmpZ1 * sr;
tmpY2 = tmpY1;
tmpZ2 = tmpZ1 * cr + tmpX1 * sr;
tmpX3 = tmpX2;
tmpY3 = tmpY2 * cr - tmpZ2 * sr;
tmpZ3 = tmpZ2 * cr + tmpY2 * sr + seraphDistance;
rotation = thisAngle * 2.501 + 85.01 * (double)s->mystery
/ (double) BIGMYSTERY;
cr = cos(rotation);
sr = sin(rotation);
tmpX4 = tmpX3 * cr - tmpY3 * sr;
tmpY4 = tmpY3 * cr + tmpX3 * sr;
tmpZ4 = tmpZ3;
s->position[0] = (float)tmpX4;
s->position[1] = (float)tmpY4;
s->position[2] = (float)tmpZ4;
}
+4
View File
@@ -32,8 +32,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef _STAR_H_ #ifndef _STAR_H_
#define _STAR_H_ #define _STAR_H_
struct flurry_info_t; struct flurry_info_t;
typedef struct Star typedef struct Star
{ {
float position[3]; float position[3];
@@ -42,7 +44,9 @@ typedef struct Star
int ate; int ate;
} Star; } Star;
void InitStar(Star *s); void InitStar(Star *s);
void UpdateStar(flurry_info_t *flurry, Star *s); void UpdateStar(flurry_info_t *flurry, Star *s);
#endif // _STAR_H #endif // _STAR_H
+191 -205
View File
@@ -1,205 +1,191 @@
/* /*
Copyright (c) 2002, Calum Robinson Copyright (c) 2002, Calum Robinson
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this * Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer. list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, * Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution. and/or other materials provided with the distribution.
* Neither the name of the author nor the names of its contributors may be used * Neither the name of the author nor the names of its contributors may be used
to endorse or promote products derived from this software without specific to endorse or promote products derived from this software without specific
prior written permission. prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "Texture.h"
#include "Shared.h"
#include "Texture.h"
static GLubyte smallTextureArray[32][32]; #include "Shared.h"
static GLubyte bigTextureArray[256][256][2];
GLuint theTexture = 0;
static GLubyte smallTextureArray[32][32];
/* simple smoothing routine */ static GLubyte bigTextureArray[256][256][2];
static void SmoothTexture(void) GLuint theTexture = 0;
{
GLubyte filter[32][32];
int i,j; // simple smoothing routine
float t; static void
for (i=1;i<31;i++) SmoothTexture(void)
{ {
for (j=1;j<31;j++) GLubyte filter[32][32];
{ float t;
t = (float) smallTextureArray[i][j]*4; for (int i = 1; i < 31; i++) {
t += (float) smallTextureArray[i-1][j]; for (int j = 1; j < 31; j++) {
t += (float) smallTextureArray[i+1][j]; t = (float)smallTextureArray[i][j] * 4;
t += (float) smallTextureArray[i][j-1]; t += (float)smallTextureArray[i - 1][j];
t += (float) smallTextureArray[i][j+1]; t += (float)smallTextureArray[i + 1][j];
t /= 8.0f; t += (float)smallTextureArray[i][j - 1];
filter[i][j] = (GLubyte) t; t += (float)smallTextureArray[i][j + 1];
} t /= 8.0f;
} filter[i][j] = (GLubyte) t;
for (i=1;i<31;i++) }
{ }
for (j=1;j<31;j++)
{ for (int i = 1; i < 31; i++){
smallTextureArray[i][j] = filter[i][j]; for (int j = 1; j < 31; j++)
} smallTextureArray[i][j] = filter[i][j];
} }
} }
/* add some randomness to texture data */
static void SpeckleTexture(void) // add some randomness to texture data
{ static void
int i,j; SpeckleTexture(void)
int speck; {
float t; int speck;
for (i=2;i<30;i++) float t;
{ for (int i = 2; i < 30; i++) {
for (j=2;j<30;j++) for (int j = 2; j < 30; j++) {
{ speck = 1;
speck = 1; while (speck <= 32 && random() % 2) {
while (speck <= 32 && random() % 2) t = (float) MIN_(255, smallTextureArray[i][j] + speck);
{ smallTextureArray[i][j] = (GLubyte)t;
t = (float) MIN_(255,smallTextureArray[i][j]+speck); speck += speck;
smallTextureArray[i][j] = (GLubyte) t; }
speck+=speck; speck = 1;
} while (speck <= 32 && random() % 2) {
speck = 1; t = (float)MAX_(0, smallTextureArray[i][j] - speck);
while (speck <= 32 && random() % 2) smallTextureArray[i][j] = (GLubyte)t;
{ speck += speck;
t = (float) MAX_(0,smallTextureArray[i][j]-speck); }
smallTextureArray[i][j] = (GLubyte) t; }
speck+=speck; }
} }
}
}
} static void
MakeSmallTexture(void)
static void MakeSmallTexture(void) {
{ static int firstTime = 1;
static int firstTime = 1;
int i,j; if (firstTime) {
float r,t; firstTime = 0;
if (firstTime) for (int i = 0; i < 32; i++) {
{ for (int j = 0; j < 32; j++) {
firstTime = 0; float r = (float)sqrt((i - 15.5) * (i - 15.5) + (j - 15.5)
for (i=0;i<32;i++) * (j - 15.5));
{ if (r > 15.0f)
for (j=0;j<32;j++) smallTextureArray[i][j] = 0;
{ else {
r = (float) sqrt((i-15.5)*(i-15.5)+(j-15.5)*(j-15.5)); float t = 255.0f * (float) cos(r * M_PI / 31.0);
if (r > 15.0f) smallTextureArray[i][j] = (GLubyte)t;
{ }
smallTextureArray[i][j] = 0; }
} }
else } else {
{ for (int i = 0; i < 32; i++) {
t = 255.0f * (float) cos(r*M_PI/31.0); for (int j = 0; j < 32; j++) {
smallTextureArray[i][j] = (GLubyte) t; float t;
} float r = (float)sqrt((i - 15.5) * (i - 15.5) + (j - 15.5)
} * (j - 15.5));
} if (r > 15.0f)
} t = 0.0f;
else else
{ t = 255.0f * (float) cos(r*M_PI/31.0);
for (i=0;i<32;i++)
{ smallTextureArray[i][j]
for (j=0;j<32;j++) = (GLubyte)MIN_(255, (t + smallTextureArray[i][j]
{ + smallTextureArray[i][j]) / 3);
r = (float) sqrt((i-15.5)*(i-15.5)+(j-15.5)*(j-15.5)); }
if (r > 15.0f) }
{ }
t = 0.0f;
} SpeckleTexture();
else SmoothTexture();
{ SmoothTexture();
t = 255.0f * (float) cos(r*M_PI/31.0); }
}
smallTextureArray[i][j] = (GLubyte) MIN_(255,(t+smallTextureArray[i][j]+smallTextureArray[i][j])/3);
} static void
} CopySmallTextureToBigTexture(int k, int l)
} {
SpeckleTexture(); for (int i = 0; i < 32; i++) {
SmoothTexture(); for (int j = 0; j < 32; j++) {
SmoothTexture(); bigTextureArray[i + k][j + l][0] = smallTextureArray[i][j];
} bigTextureArray[i + k][j + l][1] = smallTextureArray[i][j];
}
static void CopySmallTextureToBigTexture(int k, int l) }
{ }
int i,j;
for (i=0;i<32;i++)
{ static void
for (j=0;j<32;j++) AverageLastAndFirstTextures(void)
{ {
bigTextureArray[i+k][j+l][0] = smallTextureArray[i][j]; for (int i = 0; i < 32; i++) {
bigTextureArray[i+k][j+l][1] = smallTextureArray[i][j]; for (int j = 0; j < 32; j++) {
} int t = (smallTextureArray[i][j] + bigTextureArray[i][j][0]) / 2;
} smallTextureArray[i][j] = (GLubyte)MIN_(255, t);
} }
}
static void AverageLastAndFirstTextures(void) }
{
int i,j;
int t; void
for (i=0;i<32;i++) MakeTexture()
{ {
for (j=0;j<32;j++) for (int i = 0; i < 8; i++) {
{ for (int j = 0; j < 8; j++) {
t = (smallTextureArray[i][j] + bigTextureArray[i][j][0]) / 2; if (i == 7 && j == 7)
smallTextureArray[i][j] = (GLubyte) MIN_(255,t); AverageLastAndFirstTextures();
} else
} MakeSmallTexture();
}
CopySmallTextureToBigTexture(i * 32, j * 32);
void MakeTexture() }
{ }
int i,j;
for (i=0;i<8;i++) glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
{
for (j=0;j<8;j++) glGenTextures(1, &theTexture);
{ glBindTexture(GL_TEXTURE_2D, theTexture);
if (i==7 && j==7)
{ // Set the tiling mode (this is generally always GL_REPEAT).
AverageLastAndFirstTextures(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
} glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
else
{ // Set the filtering.
MakeSmallTexture(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
} glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
CopySmallTextureToBigTexture(i*32,j*32); GL_LINEAR_MIPMAP_NEAREST);
}
} gluBuild2DMipmaps(GL_TEXTURE_2D, 2, 256, 256, GL_LUMINANCE_ALPHA,
GL_UNSIGNED_BYTE, bigTextureArray);
glPixelStorei(GL_UNPACK_ALIGNMENT,1); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
glGenTextures(1, &theTexture);
glBindTexture(GL_TEXTURE_2D, theTexture);
/* Set the tiling mode (this is generally always GL_REPEAT). */
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
/* Set the filtering. */
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
gluBuild2DMipmaps(GL_TEXTURE_2D, 2, 256, 256, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, bigTextureArray);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
@@ -32,6 +32,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef _TEXTURE_H_ #ifndef _TEXTURE_H_
#define _TEXTURE_H_ #define _TEXTURE_H_
void MakeTexture(); void MakeTexture();
#endif // _TEXTURE_H_ #endif // _TEXTURE_H_