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
+64 -60
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,7 +306,8 @@ 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), :
BScreenSaver(archive, imageId),
fFlurryView(NULL) fFlurryView(NULL)
{ {
struct timeval tv; struct timeval tv;
@@ -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;
+129 -108
View File
@@ -29,12 +29,15 @@ 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.
*/ */
#include "Smoke.h" #include "Smoke.h"
#include "Shared.h" #include "Shared.h"
#include "Star.h" #include "Star.h"
#include "Spark.h" #include "Spark.h"
#define MAXANGLES 16384 #define MAXANGLES 16384
#define NOT_QUITE_DEAD 3 #define NOT_QUITE_DEAD 3
@@ -46,51 +49,58 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define streamSize 25000.0f #define streamSize 25000.0f
#define colorIncoherence 0.15f #define colorIncoherence 0.15f
static float FastDistance2D(float x, float y)
{
/* this function computes the distance from 0,0 to x,y with ~3.5% error */
float mn;
/* first compute the absolute value of x,y */ static float
FastDistance2D(float x, float y)
{
// this function computes the distance from 0,0 to x,y with ~3.5% error
// first compute the absolute value of x,y
x = (x < 0.0f) ? -x : x; x = (x < 0.0f) ? -x : x;
y = (y < 0.0f) ? -y : y; y = (y < 0.0f) ? -y : y;
/* compute the minimum of x,y */ // compute the minimum of x,y
mn = x<y?x:y; float mn = x < y ? x : y;
/* return the distance */ // return the distance
return(x+y-(mn*0.5f)-(mn*0.25f)+(mn*0.0625f)); return x + y - (mn * 0.5f) - (mn * 0.25f) + (mn * 0.0625f);
} }
void InitSmoke(SmokeV *s)
void
InitSmoke(SmokeV* s)
{ {
int i;
s->nextParticle = 0; s->nextParticle = 0;
s->nextSubParticle = 0; s->nextSubParticle = 0;
s->lastParticleTime = 0.25f; s->lastParticleTime = 0.25f;
s->firstTime = 1; s->firstTime = 1;
s->frame = 0; s->frame = 0;
for (i=0;i<3;i++) {
for (int i = 0; i < 3; i++)
s->old[i] = RandFlt(-100.0, 100.0); s->old[i] = RandFlt(-100.0, 100.0);
}
} }
void UpdateSmoke_ScalarBase(flurry_info_t *info, SmokeV *s)
void
UpdateSmoke_ScalarBase(flurry_info_t* info, SmokeV* s)
{ {
int i,j,k;
float sx = info->star->position[0]; float sx = info->star->position[0];
float sy = info->star->position[1]; float sy = info->star->position[1];
float sz = info->star->position[2]; float sz = info->star->position[2];
double frameRate; double frameRate;
double frameRateModifier; double frameRateModifier;
s->frame++; s->frame++;
if(!s->firstTime) { if (!s->firstTime) {
/* release 12 puffs every frame */ /* release 12 puffs every frame */
if(info->fTime - s->lastParticleTime >= 1.0f / 121.0f) { if (info->fTime - s->lastParticleTime >= 1.0f / 121.0f) {
float dx,dy,dz,deltax,deltay,deltaz; float dx;
float dy;
float dz;
float deltax;
float deltay;
float deltaz;
float f; float f;
float rsquared; float rsquared;
float mag; float mag;
@@ -102,7 +112,7 @@ void UpdateSmoke_ScalarBase(flurry_info_t *info, SmokeV *s)
deltax = (dx * mag); deltax = (dx * mag);
deltay = (dy * mag); deltay = (dy * mag);
deltaz = (dz * mag); deltaz = (dz * mag);
for(i=0;i<info->numStreams;i++) { for(int i=0; i < info->numStreams; i++) {
float streamSpeedCoherenceFactor; float streamSpeedCoherenceFactor;
s->p[s->nextParticle].delta[0].f[s->nextSubParticle] = deltax; s->p[s->nextParticle].delta[0].f[s->nextSubParticle] = deltax;
@@ -114,31 +124,46 @@ void UpdateSmoke_ScalarBase(flurry_info_t *info, SmokeV *s)
s->p[s->nextParticle].oldposition[0].f[s->nextSubParticle] = sx; s->p[s->nextParticle].oldposition[0].f[s->nextSubParticle] = sx;
s->p[s->nextParticle].oldposition[1].f[s->nextSubParticle] = sy; s->p[s->nextParticle].oldposition[1].f[s->nextSubParticle] = sy;
s->p[s->nextParticle].oldposition[2].f[s->nextSubParticle] = sz; s->p[s->nextParticle].oldposition[2].f[s->nextSubParticle] = sz;
streamSpeedCoherenceFactor = MAX_(0.0f,1.0f + RandBell(0.25f*incohesion)); streamSpeedCoherenceFactor = MAX_(0.0f,1.0f
dx = s->p[s->nextParticle].position[0].f[s->nextSubParticle] - info->spark[i]->position[0]; + RandBell(0.25f * incohesion));
dy = s->p[s->nextParticle].position[1].f[s->nextSubParticle] - info->spark[i]->position[1]; dx = s->p[s->nextParticle].position[0].f[s->nextSubParticle]
dz = s->p[s->nextParticle].position[2].f[s->nextSubParticle] - info->spark[i]->position[2]; - info->spark[i]->position[0];
rsquared = (dx*dx+dy*dy+dz*dz); dy = s->p[s->nextParticle].position[1].f[s->nextSubParticle]
- info->spark[i]->position[1];
dz = s->p[s->nextParticle].position[2].f[s->nextSubParticle]
- info->spark[i]->position[2];
rsquared = (dx * dx + dy * dy + dz * dz);
f = streamSpeed * streamSpeedCoherenceFactor; f = streamSpeed * streamSpeedCoherenceFactor;
mag = f / (float) sqrt(rsquared); mag = f / (float)sqrt(rsquared);
s->p[s->nextParticle].delta[0].f[s->nextSubParticle] -= (dx * mag); s->p[s->nextParticle].delta[0].f[s->nextSubParticle]
s->p[s->nextParticle].delta[1].f[s->nextSubParticle] -= (dy * mag); -= (dx * mag);
s->p[s->nextParticle].delta[2].f[s->nextSubParticle] -= (dz * mag); s->p[s->nextParticle].delta[1].f[s->nextSubParticle]
s->p[s->nextParticle].color[0].f[s->nextSubParticle] = info->spark[i]->color[0] * (1.0f + RandBell(colorIncoherence)); -= (dy * mag);
s->p[s->nextParticle].color[1].f[s->nextSubParticle] = info->spark[i]->color[1] * (1.0f + RandBell(colorIncoherence)); s->p[s->nextParticle].delta[2].f[s->nextSubParticle]
s->p[s->nextParticle].color[2].f[s->nextSubParticle] = info->spark[i]->color[2] * (1.0f + RandBell(colorIncoherence)); -= (dz * mag);
s->p[s->nextParticle].color[3].f[s->nextSubParticle] = 0.85f * (1.0f + RandBell(0.5f*colorIncoherence)); s->p[s->nextParticle].color[0].f[s->nextSubParticle]
= info->spark[i]->color[0] * (1.0f
+ RandBell(colorIncoherence));
s->p[s->nextParticle].color[1].f[s->nextSubParticle]
= info->spark[i]->color[1] * (1.0f
+ RandBell(colorIncoherence));
s->p[s->nextParticle].color[2].f[s->nextSubParticle]
= info->spark[i]->color[2] * (1.0f
+ RandBell(colorIncoherence));
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; s->p[s->nextParticle].time.f[s->nextSubParticle] = info->fTime;
s->p[s->nextParticle].dead.i[s->nextSubParticle] = 0; s->p[s->nextParticle].dead.i[s->nextSubParticle] = 0;
s->p[s->nextParticle].animFrame.i[s->nextSubParticle] = random()&63; s->p[s->nextParticle].animFrame.i[s->nextSubParticle]
= (random() & 63);
s->nextSubParticle++; s->nextSubParticle++;
if (s->nextSubParticle==4) { if (s->nextSubParticle == 4) {
s->nextParticle++; s->nextParticle++;
s->nextSubParticle=0; s->nextSubParticle = 0;
} }
if (s->nextParticle >= NUMSMOKEPARTICLES/4) { if (s->nextParticle >= NUMSMOKEPARTICLES / 4) {
s->nextParticle = 0; s->nextParticle = 0;
s->nextSubParticle = 0; s->nextSubParticle = 0;
} }
@@ -151,16 +176,17 @@ void UpdateSmoke_ScalarBase(flurry_info_t *info, SmokeV *s)
s->firstTime = 0; s->firstTime = 0;
} }
for(i=0;i<3;i++) { for(int i = 0; i < 3; i++)
s->old[i] = info->star->position[i]; s->old[i] = info->star->position[i];
}
frameRate = ((double) info->dframe)/(info->fTime); frameRate = ((double) info->dframe) / (info->fTime);
frameRateModifier = 42.5f / frameRate; frameRateModifier = 42.5f / frameRate;
for(i=0;i<NUMSMOKEPARTICLES/4;i++) { for(int i = 0; i < NUMSMOKEPARTICLES / 4; i++) {
for(k=0; k<4; k++) { for(int k = 0; k < 4; k++) {
float dx,dy,dz; float dx;
float dy;
float dz;
float f; float f;
float rsquared; float rsquared;
float mag; float mag;
@@ -168,25 +194,23 @@ void UpdateSmoke_ScalarBase(flurry_info_t *info, SmokeV *s)
float deltay; float deltay;
float deltaz; float deltaz;
if (s->p[i].dead.i[k]) { if (s->p[i].dead.i[k])
continue; continue;
}
deltax = s->p[i].delta[0].f[k]; deltax = s->p[i].delta[0].f[k];
deltay = s->p[i].delta[1].f[k]; deltay = s->p[i].delta[1].f[k];
deltaz = s->p[i].delta[2].f[k]; deltaz = s->p[i].delta[2].f[k];
for(j=0;j<info->numStreams;j++) { for(int j = 0; j < info->numStreams; j++) {
dx = s->p[i].position[0].f[k] - info->spark[j]->position[0]; 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]; 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]; dz = s->p[i].position[2].f[k] - info->spark[j]->position[2];
rsquared = (dx*dx+dy*dy+dz*dz); rsquared = (dx * dx + dy * dy + dz * dz);
f = (gravity/rsquared) * frameRateModifier; f = (gravity/rsquared) * frameRateModifier;
if ((((i*4)+k) % info->numStreams) == j) { if ((((i * 4) + k) % info->numStreams) == j)
f *= 1.0f + streamBias; f *= 1.0f + streamBias;
}
mag = f / (float) sqrt(rsquared); mag = f / (float) sqrt(rsquared);
@@ -195,57 +219,64 @@ void UpdateSmoke_ScalarBase(flurry_info_t *info, SmokeV *s)
deltaz -= (dz * mag); deltaz -= (dz * mag);
} }
/* slow this particle down by info->drag */ // slow this particle down by info->drag
deltax *= info->drag; deltax *= info->drag;
deltay *= info->drag; deltay *= info->drag;
deltaz *= info->drag; deltaz *= info->drag;
if((deltax*deltax+deltay*deltay+deltaz*deltaz) >= 25000000.0f) { if ((deltax * deltax + deltay * deltay + deltaz * deltaz)
>= 25000000.0f) {
s->p[i].dead.i[k] = 1; s->p[i].dead.i[k] = 1;
continue; continue;
} }
/* update the position */ // update the position
s->p[i].delta[0].f[k] = deltax; s->p[i].delta[0].f[k] = deltax;
s->p[i].delta[1].f[k] = deltay; s->p[i].delta[1].f[k] = deltay;
s->p[i].delta[2].f[k] = deltaz; s->p[i].delta[2].f[k] = deltaz;
for(j=0;j<3;j++) { for(int j = 0; j < 3; j++) {
s->p[i].oldposition[j].f[k] = s->p[i].position[j].f[k]; s->p[i].oldposition[j].f[k] = s->p[i].position[j].f[k];
s->p[i].position[j].f[k] += (s->p[i].delta[j].f[k])*info->fDeltaTime; s->p[i].position[j].f[k]
+= (s->p[i].delta[j].f[k]) * info->fDeltaTime;
} }
} }
} }
} }
void DrawSmoke_Scalar(flurry_info_t *info, SmokeV *s, float brightness)
void
DrawSmoke_Scalar(flurry_info_t* info, SmokeV* s, float brightness)
{ {
int svi = 0; int svi = 0;
int sci = 0; int sci = 0;
int sti = 0; int sti = 0;
int si = 0; int si = 0;
float width; float width;
float sx,sy; float sx;
float u0,v0,u1,v1; float sy;
float w,z; float u0;
float v0;
float u1;
float v1;
float w;
float z;
float screenRatio = info->sys_glWidth / 1024.0f; float screenRatio = info->sys_glWidth / 1024.0f;
float hslash2 = info->sys_glHeight * 0.5f; float hslash2 = info->sys_glHeight * 0.5f;
float wslash2 = info->sys_glWidth * 0.5f; float wslash2 = info->sys_glWidth * 0.5f;
int i,k;
width = (streamSize+2.5f*info->streamExpansion) * screenRatio; width = (streamSize + 2.5f * info->streamExpansion) * screenRatio;
for (i=0;i<NUMSMOKEPARTICLES/4;i++) for (int i = 0; i < NUMSMOKEPARTICLES / 4; i++) {
{ for (int k = 0; k < 4; k++) {
for (k=0; k<4; k++) {
float thisWidth; float thisWidth;
float oldz; float oldz;
if (s->p[i].dead.i[k]) { if (s->p[i].dead.i[k])
continue; continue;
}
thisWidth = (streamSize + (info->fTime - s->p[i].time.f[k])*info->streamExpansion) * screenRatio; thisWidth = (streamSize + (info->fTime - s->p[i].time.f[k])
if (thisWidth >= width) * info->streamExpansion) * screenRatio;
{ if (thisWidth >= width) {
s->p[i].dead.i[k] = 1; s->p[i].dead.i[k] = 1;
continue; continue;
} }
@@ -253,12 +284,13 @@ void DrawSmoke_Scalar(flurry_info_t *info, SmokeV *s, float brightness)
sx = s->p[i].position[0].f[k] * info->sys_glWidth / z + wslash2; 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; sy = s->p[i].position[1].f[k] * info->sys_glWidth / z + hslash2;
oldz = s->p[i].oldposition[2].f[k]; oldz = s->p[i].oldposition[2].f[k];
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) 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) {
continue; continue;
} }
w = MAX_(1.0f,thisWidth/z); w = MAX_(1.0f, thisWidth / z);
{ {
float oldx = s->p[i].oldposition[0].f[k]; float oldx = s->p[i].oldposition[0].f[k];
float oldy = s->p[i].oldposition[1].f[k]; float oldy = s->p[i].oldposition[1].f[k];
@@ -271,40 +303,31 @@ void DrawSmoke_Scalar(flurry_info_t *info, SmokeV *s, float brightness)
float sm, os, ow; float sm, os, ow;
if (d) if (d)
{ sm = w / d;
sm = w/d;
}
else else
{
sm = 0.0f; sm = 0.0f;
}
ow = MAX_(1.0f,thisWidth/oldz); ow = MAX_(1.0f,thisWidth/oldz);
if (d) if (d)
{ os = ow / d;
os = ow/d;
}
else else
{
os = 0.0f; os = 0.0f;
}
{ {
floatToVector cmv; floatToVector cmv;
float cm; float cm;
float m = 1.0f + sm; float m = 1.0f + sm;
float dxs = dx*sm; float dxs = dx * sm;
float dys = dy*sm; float dys = dy * sm;
float dxos = dx*os; float dxos = dx * os;
float dyos = dy*os; float dyos = dy * os;
float dxm = dx*m; float dxm = dx * m;
float dym = dy*m; float dym = dy * m;
s->p[i].animFrame.i[k]++; s->p[i].animFrame.i[k]++;
if (s->p[i].animFrame.i[k] >= 64) if (s->p[i].animFrame.i[k] >= 64)
{
s->p[i].animFrame.i[k] = 0; s->p[i].animFrame.i[k] = 0;
}
u0 = (s->p[i].animFrame.i[k]&&7) * 0.125f; u0 = (s->p[i].animFrame.i[k]&&7) * 0.125f;
v0 = (s->p[i].animFrame.i[k]>>3) * 0.125f; v0 = (s->p[i].animFrame.i[k]>>3) * 0.125f;
@@ -313,8 +336,7 @@ void DrawSmoke_Scalar(flurry_info_t *info, SmokeV *s, float brightness)
u1 = u0 + 0.125f; u1 = u0 + 0.125f;
v1 = v0 + 0.125f; v1 = v0 + 0.125f;
cm = (1.375f - thisWidth/width); cm = (1.375f - thisWidth/width);
if (s->p[i].dead.i[k] == 3) if (s->p[i].dead.i[k] == 3) {
{
cm *= 0.125f; cm *= 0.125f;
s->p[i].dead.i[k] = 1; s->p[i].dead.i[k] = 1;
} }
@@ -326,18 +348,16 @@ void DrawSmoke_Scalar(flurry_info_t *info, SmokeV *s, float brightness)
cmv.f[3] = s->p[i].color[3].f[k]*cm; cmv.f[3] = s->p[i].color[3].f[k]*cm;
#if 0 #if 0
/* MDT we can't use vectors in the Scalar routine */ // MDT we can't use vectors in the Scalar routine
s->seraphimColors[sci++].v = cmv.v; s->seraphimColors[sci++].v = cmv.v;
s->seraphimColors[sci++].v = cmv.v; s->seraphimColors[sci++].v = cmv.v;
s->seraphimColors[sci++].v = cmv.v; s->seraphimColors[sci++].v = cmv.v;
s->seraphimColors[sci++].v = cmv.v; s->seraphimColors[sci++].v = cmv.v;
#else #else
{ {
int ii, jj; for (int jj = 0; jj < 4; jj++) {
for (jj = 0; jj < 4; jj++) { for (int ii = 0; ii < 4; ii++)
for (ii = 0; ii < 4; ii++) {
s->seraphimColors[sci].f[ii] = cmv.f[ii]; s->seraphimColors[sci].f[ii] = cmv.f[ii];
}
sci += 1; sci += 1;
} }
} }
@@ -353,23 +373,24 @@ void DrawSmoke_Scalar(flurry_info_t *info, SmokeV *s, float brightness)
s->seraphimTextures[sti++] = u1; s->seraphimTextures[sti++] = u1;
s->seraphimTextures[sti++] = v0; s->seraphimTextures[sti++] = v0;
s->seraphimVertices[svi].f[0] = sx+dxm-dys; s->seraphimVertices[svi].f[0] = sx + dxm - dys;
s->seraphimVertices[svi].f[1] = sy+dym+dxs; s->seraphimVertices[svi].f[1] = sy + dym + dxs;
s->seraphimVertices[svi].f[2] = sx+dxm+dys; s->seraphimVertices[svi].f[2] = sx + dxm + dys;
s->seraphimVertices[svi].f[3] = sy+dym-dxs; s->seraphimVertices[svi].f[3] = sy + dym - dxs;
svi++; svi++;
s->seraphimVertices[svi].f[0] = oldscreenx-dxm+dyos; s->seraphimVertices[svi].f[0] = oldscreenx - dxm + dyos;
s->seraphimVertices[svi].f[1] = oldscreeny-dym-dxos; s->seraphimVertices[svi].f[1] = oldscreeny - dym - dxos;
s->seraphimVertices[svi].f[2] = oldscreenx-dxm-dyos; s->seraphimVertices[svi].f[2] = oldscreenx - dxm - dyos;
s->seraphimVertices[svi].f[3] = oldscreeny-dym+dxos; s->seraphimVertices[svi].f[3] = oldscreeny - dym + dxos;
svi++; svi++;
} }
} }
} }
} }
glColorPointer(4,GL_FLOAT,0,s->seraphimColors);
glVertexPointer(2,GL_FLOAT,0,s->seraphimVertices); glColorPointer(4, GL_FLOAT, 0, s->seraphimColors);
glTexCoordPointer(2,GL_FLOAT,0,s->seraphimTextures); glVertexPointer(2, GL_FLOAT, 0, s->seraphimVertices);
glDrawArrays(GL_QUADS,0,si*4); 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_
+86 -87
View File
@@ -29,9 +29,12 @@ 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.
*/ */
#include "Spark.h" #include "Spark.h"
#include "Shared.h" #include "Shared.h"
#define BIGMYSTERY 1800.0 #define BIGMYSTERY 1800.0
#define MAXANGLES 16384 #define MAXANGLES 16384
@@ -39,25 +42,28 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define fieldSpeed 12.0f #define fieldSpeed 12.0f
#define fieldRange 1000.0f #define fieldRange 1000.0f
void InitSpark(Spark *s)
void
InitSpark(Spark* s)
{ {
int i; for (int i = 0; i < 3; i++)
for (i=0;i<3;i++)
{
s->position[i] = RandFlt(-100.0, 100.0); s->position[i] = RandFlt(-100.0, 100.0);
}
} }
void DrawSpark(flurry_info_t *info, Spark *s)
void DrawSpark(flurry_info_t* info, Spark* s)
{ {
const float black[4] = {0.0f,0.0f,0.0f,1.0f}; const float black[4] = {0.0f, 0.0f, 0.0f, 1.0f};
float width,sx,sy; float width;
float sx;
float sy;
float a; float a;
float c = 0.0625f; float c = 0.0625f;
float screenx; float screenx;
float screeny; float screeny;
float w,z, scale; float w;
int k; float z;
float scale;
width = 60000.0f * info->sys_glWidth / 1024.0f; width = 60000.0f * info->sys_glWidth / 1024.0f;
z = s->position[2]; z = s->position[2];
@@ -72,9 +78,8 @@ void DrawSpark(flurry_info_t *info, Spark *s)
glTranslatef(screenx,screeny,0.0f); glTranslatef(screenx,screeny,0.0f);
scale = w/50.0f; scale = w/50.0f;
glScalef(scale,scale,0.0f); glScalef(scale,scale,0.0f);
for (k=0;k<12;k++) for (int k = 0; k < 12; k++) {
{ a = ((float)(random() % 3600)) / 10.0f;
a = ((float) (random() % 3600)) / 10.0f;
glRotatef(a,0.0f,0.0f,1.0f); glRotatef(a,0.0f,0.0f,1.0f);
glBegin(GL_QUAD_STRIP); glBegin(GL_QUAD_STRIP);
glColor4fv(black); glColor4fv(black);
@@ -89,12 +94,16 @@ void DrawSpark(flurry_info_t *info, Spark *s)
glVertex2f(3.0f,a); glVertex2f(3.0f,a);
glEnd(); glEnd();
} }
glPopMatrix(); glPopMatrix();
} }
void UpdateSparkColour(flurry_info_t *info, Spark *s)
void
UpdateSparkColour(flurry_info_t* info, Spark* s)
{ {
const float rotationsPerSecond = (float) (2.0*M_PI*fieldSpeed/MAXANGLES); const float rotationsPerSecond = (float)(2.0 * M_PI * fieldSpeed
/ MAXANGLES);
double thisPointInRadians; double thisPointInRadians;
double thisAngle = info->fTime*rotationsPerSecond; double thisAngle = info->fTime*rotationsPerSecond;
float cf; float cf;
@@ -109,82 +118,69 @@ void UpdateSparkColour(flurry_info_t *info, Spark *s)
float colorTime; float colorTime;
if (info->currentColorMode == rainbowColorMode) if (info->currentColorMode == rainbowColorMode)
{
cycleTime = 1.5f; cycleTime = 1.5f;
}
else if (info->currentColorMode == tiedyeColorMode) else if (info->currentColorMode == tiedyeColorMode)
{
cycleTime = 4.5f; cycleTime = 4.5f;
}
else if (info->currentColorMode == cyclicColorMode) else if (info->currentColorMode == cyclicColorMode)
{
cycleTime = 20.0f; cycleTime = 20.0f;
}
else if (info->currentColorMode == slowCyclicColorMode) else if (info->currentColorMode == slowCyclicColorMode)
{
cycleTime = 120.0f; cycleTime = 120.0f;
}
colorRot = (float) (2.0*M_PI/cycleTime); colorRot = (float)(2.0 * M_PI / cycleTime);
redPhaseShift = 0.0f; /* cycleTime * 0.0f / 3.0f */ redPhaseShift = 0.0f; /* cycleTime * 0.0f / 3.0f */
greenPhaseShift = cycleTime / 3.0f; greenPhaseShift = cycleTime / 3.0f;
bluePhaseShift = cycleTime * 2.0f / 3.0f ; bluePhaseShift = cycleTime * 2.0f / 3.0f;
colorTime = info->fTime; colorTime = info->fTime;
if (info->currentColorMode == whiteColorMode) if (info->currentColorMode == whiteColorMode) {
{
baseRed = 0.1875f; baseRed = 0.1875f;
baseGreen = 0.1875f; baseGreen = 0.1875f;
baseBlue = 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) {
else if (info->currentColorMode == darkColorMode)
{
baseRed = 0.0f; baseRed = 0.0f;
baseGreen = 0.0f; baseGreen = 0.0f;
baseBlue = 0.0f; baseBlue = 0.0f;
} } else {
else
{
if (info->currentColorMode < slowCyclicColorMode) if (info->currentColorMode < slowCyclicColorMode)
{
colorTime = (info->currentColorMode / 6.0f) * cycleTime; colorTime = (info->currentColorMode / 6.0f) * cycleTime;
}
else else
{
colorTime = info->fTime + info->randomSeed; colorTime = info->fTime + info->randomSeed;
}
baseRed = 0.109375f * ((float) cos((colorTime+redPhaseShift)*colorRot)+1.0f); baseRed = 0.109375f
baseGreen = 0.109375f * ((float) cos((colorTime+greenPhaseShift)*colorRot)+1.0f); * ((float)cos((colorTime + redPhaseShift) * colorRot) + 1.0f);
baseBlue = 0.109375f * ((float) cos((colorTime+bluePhaseShift)*colorRot)+1.0f); baseGreen = 0.109375f
* ((float)cos((colorTime + greenPhaseShift) * colorRot) + 1.0f);
baseBlue = 0.109375f
* ((float)cos((colorTime + bluePhaseShift) * colorRot) + 1.0f);
} }
cf = ((float) (cos(7.0*((info->fTime)*rotationsPerSecond)) + cf = ((float)(cos(7.0 * ((info->fTime) * rotationsPerSecond))
cos(3.0*((info->fTime)*rotationsPerSecond)) + + cos(3.0 * ((info->fTime) * rotationsPerSecond))
cos(13.0*((info->fTime)*rotationsPerSecond)))); + cos(13.0 * ((info->fTime) * rotationsPerSecond))));
cf /= 6.0f; cf /= 6.0f;
cf += 2.0f; cf += 2.0f;
thisPointInRadians = 2.0 * M_PI * (double) s->mystery / (double) BIGMYSTERY; thisPointInRadians = 2.0 * M_PI * (double) s->mystery / (double) BIGMYSTERY;
s->color[0] = baseRed + 0.0625f * s->color[0] = baseRed + 0.0625f
(0.5f + (float) cos((15.0 * (thisPointInRadians + 3.0*thisAngle))) + * (0.5f + (float)cos((15.0 * (thisPointInRadians + 3.0*thisAngle)))
(float) sin((7.0 * (thisPointInRadians + thisAngle)))); + (float)sin((7.0 * (thisPointInRadians + thisAngle))));
s->color[1] = baseGreen + 0.0625f * s->color[1] = baseGreen + 0.0625f
(0.5f + (float) sin(((thisPointInRadians) + thisAngle))); * (0.5f + (float)sin(((thisPointInRadians) + thisAngle)));
s->color[2] = baseBlue + 0.0625f * s->color[2] = baseBlue + 0.0625f
(0.5f + (float) cos((37.0 * (thisPointInRadians + thisAngle)))); * (0.5f + (float)cos((37.0 * (thisPointInRadians + thisAngle))));
} }
void UpdateSpark(flurry_info_t *info, Spark *s)
void
UpdateSpark(flurry_info_t* info, Spark* s)
{ {
const float rotationsPerSecond = (float) (2.0*M_PI*fieldSpeed/MAXANGLES); const float rotationsPerSecond = (float) (2.0*M_PI*fieldSpeed/MAXANGLES);
double thisPointInRadians; double thisPointInRadians;
double thisAngle = info->fTime*rotationsPerSecond; double thisAngle = info->fTime*rotationsPerSecond;
float cf; float cf;
int i;
double tmpX1,tmpY1,tmpZ1; double tmpX1,tmpY1,tmpZ1;
double tmpX2,tmpY2,tmpZ2; double tmpX2,tmpY2,tmpZ2;
double tmpX3,tmpY3,tmpZ3; double tmpX3,tmpY3,tmpZ3;
@@ -204,16 +200,16 @@ void UpdateSpark(flurry_info_t *info, Spark *s)
float old[3]; float old[3];
if (info->currentColorMode == rainbowColorMode) { if (info->currentColorMode == rainbowColorMode)
cycleTime = 1.5f; cycleTime = 1.5f;
} else if (info->currentColorMode == tiedyeColorMode) { else if (info->currentColorMode == tiedyeColorMode)
cycleTime = 4.5f; cycleTime = 4.5f;
} else if (info->currentColorMode == cyclicColorMode) { else if (info->currentColorMode == cyclicColorMode)
cycleTime = 20.0f; cycleTime = 20.0f;
} else if (info->currentColorMode == slowCyclicColorMode) { else if (info->currentColorMode == slowCyclicColorMode)
cycleTime = 120.0f; cycleTime = 120.0f;
}
colorRot = (float) (2.0*M_PI/cycleTime); colorRot = (float)(2.0 * M_PI / cycleTime);
redPhaseShift = 0.0f; /* cycleTime * 0.0f / 3.0f */ redPhaseShift = 0.0f; /* cycleTime * 0.0f / 3.0f */
greenPhaseShift = cycleTime / 3.0f; greenPhaseShift = cycleTime / 3.0f;
bluePhaseShift = cycleTime * 2.0f / 3.0f ; bluePhaseShift = cycleTime * 2.0f / 3.0f ;
@@ -231,42 +227,45 @@ void UpdateSpark(flurry_info_t *info, Spark *s)
baseGreen = 0.0f; baseGreen = 0.0f;
baseBlue = 0.0f; baseBlue = 0.0f;
} else { } else {
if(info->currentColorMode < slowCyclicColorMode) { if (info->currentColorMode < slowCyclicColorMode)
colorTime = (info->currentColorMode / 6.0f) * cycleTime; colorTime = (info->currentColorMode / 6.0f) * cycleTime;
} else { else
colorTime = info->fTime + info->randomSeed; colorTime = info->fTime + info->randomSeed;
}
baseRed = 0.109375f * ((float) cos((colorTime+redPhaseShift)*colorRot)+1.0f); baseRed = 0.109375f
baseGreen = 0.109375f * ((float) cos((colorTime+greenPhaseShift)*colorRot)+1.0f); * ((float)cos((colorTime + redPhaseShift) * colorRot) + 1.0f);
baseBlue = 0.109375f * ((float) cos((colorTime+bluePhaseShift)*colorRot)+1.0f); baseGreen = 0.109375f
* ((float)cos((colorTime + greenPhaseShift) * colorRot) + 1.0f);
baseBlue = 0.109375f
* ((float)cos((colorTime + bluePhaseShift) * colorRot) + 1.0f);
} }
for (i=0;i<3;i++) { for (int i = 0; i < 3; i++)
old[i] = s->position[i]; old[i] = s->position[i];
}
cf = ((float) (cos(7.0*((info->fTime)*rotationsPerSecond)) + cf = ((float)cos(7.0 * ((info->fTime) * rotationsPerSecond)
cos(3.0*((info->fTime)*rotationsPerSecond)) + + (float)cos(3.0 * ((info->fTime) * rotationsPerSecond))
cos(13.0*((info->fTime)*rotationsPerSecond)))); + (float)cos(13.0 * ((info->fTime) * rotationsPerSecond))));
cf /= 6.0f; cf /= 6.0f;
cf += 2.0f; cf += 2.0f;
thisPointInRadians = 2.0 * M_PI * (double) s->mystery / (double) BIGMYSTERY; thisPointInRadians = 2.0 * M_PI * (double)s->mystery / (double)BIGMYSTERY;
s->color[0] = baseRed + 0.0625f * s->color[0] = baseRed + 0.0625f
(0.5f + (float) cos((15.0 * (thisPointInRadians + 3.0*thisAngle))) + * (0.5f + (float) cos((15.0 * (thisPointInRadians + 3.0*thisAngle)))
(float) sin((7.0 * (thisPointInRadians + thisAngle)))); + (float) sin((7.0 * (thisPointInRadians + thisAngle))));
s->color[1] = baseGreen + 0.0625f * s->color[1] = baseGreen + 0.0625f
(0.5f + (float) sin(((thisPointInRadians) + thisAngle))); * (0.5f + (float) sin(((thisPointInRadians) + thisAngle)));
s->color[2] = baseBlue + 0.0625f * s->color[2] = baseBlue + 0.0625f
(0.5f + (float) cos((37.0 * (thisPointInRadians + thisAngle)))); * (0.5f + (float) cos((37.0 * (thisPointInRadians + thisAngle))));
s->position[0] = fieldRange * cf * s->position[0] = fieldRange * cf
(float) cos(11.0 * (thisPointInRadians + (3.0*thisAngle))); * (float)cos(11.0 * (thisPointInRadians + (3.0*thisAngle)));
s->position[1] = fieldRange * cf * s->position[1] = fieldRange * cf *
(float) sin(12.0 * (thisPointInRadians + (4.0*thisAngle))); (float) sin(12.0 * (thisPointInRadians + (4.0*thisAngle)));
s->position[2] = fieldRange * s->position[2] = fieldRange *
(float) cos((23.0 * (thisPointInRadians + (12.0*thisAngle)))); (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;
@@ -281,7 +280,8 @@ void UpdateSpark(flurry_info_t *info, Spark *s)
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 / (double) BIGMYSTERY; rotation = thisAngle * 2.501 + 85.01 * (double)s->mystery
/ (double)BIGMYSTERY;
cr = cos(rotation); cr = cos(rotation);
sr = sin(rotation); sr = sin(rotation);
tmpX4 = tmpX3 * cr - tmpY3 * sr; tmpX4 = tmpX3 * cr - tmpY3 * sr;
@@ -292,7 +292,6 @@ void UpdateSpark(flurry_info_t *info, Spark *s)
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_
+43 -23
View File
@@ -29,52 +29,71 @@ 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.
*/ */
#include "Star.h" #include "Star.h"
#include "Shared.h" #include "Shared.h"
#define BIGMYSTERY 1800.0 #define BIGMYSTERY 1800.0
#define MAXANGLES 16384 #define MAXANGLES 16384
/* Construction/Destruction */
void InitStar(Star *s) // Construction/Destruction
void
InitStar(Star* s)
{ {
int i; for (int i=0; i < 3; i++)
for (i=0;i<3;i++) {
s->position[i] = RandFlt(-10000.0, 10000.0); s->position[i] = RandFlt(-10000.0, 10000.0);
}
s->rotSpeed = RandFlt(0.4, 0.9); s->rotSpeed = RandFlt(0.4, 0.9);
s->mystery = RandFlt(0.0, 10.0); s->mystery = RandFlt(0.0, 10.0);
} }
void UpdateStar(flurry_info_t *info, Star *s)
void
UpdateStar(flurry_info_t* info, Star* s)
{ {
/* speed control */ /* speed control */
float rotationsPerSecond = (float) (2.0*M_PI*12.0/MAXANGLES) * s->rotSpeed; float rotationsPerSecond = (float)(2.0 * M_PI * 12.0 / MAXANGLES)
* s->rotSpeed;
double thisPointInRadians; double thisPointInRadians;
double thisAngle = info->fTime*rotationsPerSecond; double thisAngle = info->fTime * rotationsPerSecond;
float cf; float cf;
double tmpX1,tmpY1,tmpZ1; double tmpX1;
double tmpX2,tmpY2,tmpZ2; double tmpY1;
double tmpX3,tmpY3,tmpZ3; double tmpZ1;
double tmpX4,tmpY4,tmpZ4; double tmpX2;
double tmpY2;
double tmpZ2;
double tmpX3;
double tmpY3;
double tmpZ3;
double tmpX4;
double tmpY4;
double tmpZ4;
double rotation; double rotation;
double cr; double cr;
double sr; double sr;
s->ate = 0; s->ate = 0;
cf = ((float) (cos(7.0*((info->fTime)*rotationsPerSecond)) + cf = ((float)(cos(7.0 * ((info->fTime) * rotationsPerSecond))
cos(3.0*((info->fTime)*rotationsPerSecond)) + + cos(3.0 * ((info->fTime) * rotationsPerSecond))
cos(13.0*((info->fTime)*rotationsPerSecond)))); + cos(13.0 * ((info->fTime) * rotationsPerSecond))));
cf /= 6.0f; cf /= 6.0f;
cf += 0.75f; cf += 0.75f;
thisPointInRadians = 2.0 * M_PI * (double) s->mystery / (double) BIGMYSTERY; thisPointInRadians = 2.0 * M_PI * (double) s->mystery / (double) BIGMYSTERY;
s->position[0] = 250.0f * cf * (float) cos(11.0 * (thisPointInRadians + (3.0*thisAngle))); s->position[0] = 250.0f * cf * (float)cos(11.0 * (thisPointInRadians
s->position[1] = 250.0f * cf * (float) sin(12.0 * (thisPointInRadians + (4.0*thisAngle))); + (3.0 * thisAngle)));
s->position[2] = 250.0f * (float) cos((23.0 * (thisPointInRadians + (12.0*thisAngle)))); s->position[1] = 250.0f * cf * (float)sin(12.0 * (thisPointInRadians
+ (4.0 * thisAngle)));
s->position[2] = 250.0f * (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;
@@ -89,14 +108,15 @@ void UpdateStar(flurry_info_t *info, Star *s)
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 / (double) BIGMYSTERY; rotation = thisAngle * 2.501 + 85.01 * (double)s->mystery
/ (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; s->position[0] = (float)tmpX4;
s->position[1] = (float) tmpY4; s->position[1] = (float)tmpY4;
s->position[2] = (float) tmpZ4; 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
+83 -97
View File
@@ -29,177 +29,163 @@ 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.
*/ */
#include "Texture.h" #include "Texture.h"
#include "Shared.h" #include "Shared.h"
static GLubyte smallTextureArray[32][32]; static GLubyte smallTextureArray[32][32];
static GLubyte bigTextureArray[256][256][2]; static GLubyte bigTextureArray[256][256][2];
GLuint theTexture = 0; GLuint theTexture = 0;
/* simple smoothing routine */
static void SmoothTexture(void) // simple smoothing routine
static void
SmoothTexture(void)
{ {
GLubyte filter[32][32]; GLubyte filter[32][32];
int i,j;
float t; float t;
for (i=1;i<31;i++) for (int i = 1; i < 31; i++) {
{ for (int j = 1; j < 31; j++) {
for (j=1;j<31;j++) t = (float)smallTextureArray[i][j] * 4;
{ t += (float)smallTextureArray[i - 1][j];
t = (float) smallTextureArray[i][j]*4; t += (float)smallTextureArray[i + 1][j];
t += (float) smallTextureArray[i-1][j]; t += (float)smallTextureArray[i][j - 1];
t += (float) smallTextureArray[i+1][j]; t += (float)smallTextureArray[i][j + 1];
t += (float) smallTextureArray[i][j-1];
t += (float) smallTextureArray[i][j+1];
t /= 8.0f; t /= 8.0f;
filter[i][j] = (GLubyte) t; filter[i][j] = (GLubyte) t;
} }
} }
for (i=1;i<31;i++)
{ for (int i = 1; i < 31; i++){
for (j=1;j<31;j++) for (int j = 1; j < 31; j++)
{
smallTextureArray[i][j] = filter[i][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
SpeckleTexture(void)
{ {
int i,j;
int speck; int speck;
float t; float t;
for (i=2;i<30;i++) for (int i = 2; i < 30; i++) {
{ for (int j = 2; j < 30; j++) {
for (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);
t = (float) MIN_(255,smallTextureArray[i][j]+speck); smallTextureArray[i][j] = (GLubyte)t;
smallTextureArray[i][j] = (GLubyte) t; speck += speck;
speck+=speck;
} }
speck = 1; speck = 1;
while (speck <= 32 && random() % 2) while (speck <= 32 && random() % 2) {
{ t = (float)MAX_(0, smallTextureArray[i][j] - speck);
t = (float) MAX_(0,smallTextureArray[i][j]-speck); smallTextureArray[i][j] = (GLubyte)t;
smallTextureArray[i][j] = (GLubyte) t; speck += speck;
speck+=speck;
} }
} }
} }
} }
static void MakeSmallTexture(void)
static void
MakeSmallTexture(void)
{ {
static int firstTime = 1; static int firstTime = 1;
int i,j;
float r,t; if (firstTime) {
if (firstTime)
{
firstTime = 0; firstTime = 0;
for (i=0;i<32;i++) for (int i = 0; i < 32; i++) {
{ for (int j = 0; j < 32; j++) {
for (j=0;j<32;j++) float r = (float)sqrt((i - 15.5) * (i - 15.5) + (j - 15.5)
{ * (j - 15.5));
r = (float) sqrt((i-15.5)*(i-15.5)+(j-15.5)*(j-15.5));
if (r > 15.0f) if (r > 15.0f)
{
smallTextureArray[i][j] = 0; smallTextureArray[i][j] = 0;
} else {
else float t = 255.0f * (float) cos(r * M_PI / 31.0);
{ smallTextureArray[i][j] = (GLubyte)t;
t = 255.0f * (float) cos(r*M_PI/31.0);
smallTextureArray[i][j] = (GLubyte) t;
} }
} }
} }
} } else {
else for (int i = 0; i < 32; i++) {
{ for (int j = 0; j < 32; j++) {
for (i=0;i<32;i++) float t;
{ float r = (float)sqrt((i - 15.5) * (i - 15.5) + (j - 15.5)
for (j=0;j<32;j++) * (j - 15.5));
{
r = (float) sqrt((i-15.5)*(i-15.5)+(j-15.5)*(j-15.5));
if (r > 15.0f) if (r > 15.0f)
{
t = 0.0f; t = 0.0f;
}
else else
{
t = 255.0f * (float) cos(r*M_PI/31.0); t = 255.0f * (float) cos(r*M_PI/31.0);
}
smallTextureArray[i][j] = (GLubyte) MIN_(255,(t+smallTextureArray[i][j]+smallTextureArray[i][j])/3); smallTextureArray[i][j]
= (GLubyte)MIN_(255, (t + smallTextureArray[i][j]
+ smallTextureArray[i][j]) / 3);
} }
} }
} }
SpeckleTexture(); SpeckleTexture();
SmoothTexture(); SmoothTexture();
SmoothTexture(); SmoothTexture();
} }
static void CopySmallTextureToBigTexture(int k, int l)
static void
CopySmallTextureToBigTexture(int k, int l)
{ {
int i,j; for (int i = 0; i < 32; i++) {
for (i=0;i<32;i++) for (int j = 0; j < 32; j++) {
{ bigTextureArray[i + k][j + l][0] = smallTextureArray[i][j];
for (j=0;j<32;j++) bigTextureArray[i + k][j + l][1] = smallTextureArray[i][j];
{
bigTextureArray[i+k][j+l][0] = smallTextureArray[i][j];
bigTextureArray[i+k][j+l][1] = smallTextureArray[i][j];
} }
} }
} }
static void AverageLastAndFirstTextures(void)
static void
AverageLastAndFirstTextures(void)
{ {
int i,j; for (int i = 0; i < 32; i++) {
int t; for (int j = 0; j < 32; j++) {
for (i=0;i<32;i++) int t = (smallTextureArray[i][j] + bigTextureArray[i][j][0]) / 2;
{ smallTextureArray[i][j] = (GLubyte)MIN_(255, t);
for (j=0;j<32;j++)
{
t = (smallTextureArray[i][j] + bigTextureArray[i][j][0]) / 2;
smallTextureArray[i][j] = (GLubyte) MIN_(255,t);
} }
} }
} }
void MakeTexture()
void
MakeTexture()
{ {
int i,j; for (int i = 0; i < 8; i++) {
for (i=0;i<8;i++) for (int j = 0; j < 8; j++) {
{ if (i == 7 && j == 7)
for (j=0;j<8;j++)
{
if (i==7 && j==7)
{
AverageLastAndFirstTextures(); AverageLastAndFirstTextures();
}
else else
{
MakeSmallTexture(); MakeSmallTexture();
}
CopySmallTextureToBigTexture(i*32,j*32); CopySmallTextureToBigTexture(i * 32, j * 32);
} }
} }
glPixelStorei(GL_UNPACK_ALIGNMENT,1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &theTexture); glGenTextures(1, &theTexture);
glBindTexture(GL_TEXTURE_2D, theTexture); glBindTexture(GL_TEXTURE_2D, theTexture);
/* Set the tiling mode (this is generally always GL_REPEAT). */ // 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_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
/* Set the filtering. */ // Set the filtering.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); 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); gluBuild2DMipmaps(GL_TEXTURE_2D, 2, 256, 256, GL_LUMINANCE_ALPHA,
GL_UNSIGNED_BYTE, bigTextureArray);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 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_