Gravity: Live update settings and cleanup
Now that this screensaver shows a preview, update the settings live so that the display updates immediately. Since this didn't work before this screensaver took a shortcut and only updated the settings when the saver started. Some other changes include: * Update copyright header, add myself to the authors list. * Convert Particle from using a BList to a BObjectList and remove casts. * Use switch statement to set particle color that has a default case for blue. * Initialize member variables to a default value in the constructor. * Remove Constants.h, the remaining constants are in ConfigView.cpp * Convert deprecated GroupLayoutBuilder to a LayoutBuilder template instance * Convert GravitySource from a class to a struct since all members are public. * Simplify realCount calculation to just a single left shift. * A bunch of style fixes - lots of whitespace fixes - rename rect to frame in GravityView and ConfigView - reorder the frame parameter first in GravityView and ConfigView - curly brace goes on same line as class or struct declaration This turned out to be a bigger change than I originally intended to make.
This commit is contained in:
@@ -1,47 +1,48 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2013 Tri-Edge AI <[email protected]>
|
* Copyright 2012-2013 Tri-Edge AI <[email protected]>
|
||||||
* All rights reserved. Distributed under the terms of the MIT license.
|
* Copyright 2014 Haiku, Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the terms of the MIT license.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Tri-Edge AI
|
||||||
|
* John Scipione, [email protected]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "ConfigView.h"
|
#include "ConfigView.h"
|
||||||
|
|
||||||
#include "Constants.h"
|
#include <LayoutBuilder.h>
|
||||||
#include "Gravity.h"
|
|
||||||
|
|
||||||
#include <GroupLayoutBuilder.h>
|
|
||||||
#include <ListView.h>
|
#include <ListView.h>
|
||||||
#include <ScrollView.h>
|
#include <ScrollView.h>
|
||||||
#include <Slider.h>
|
#include <Slider.h>
|
||||||
#include <StringView.h>
|
#include <StringView.h>
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
|
#include "Gravity.h"
|
||||||
|
|
||||||
ConfigView::ConfigView(Gravity* parent, BRect rect)
|
|
||||||
|
static const int32 kMsgSize = 'size';
|
||||||
|
static const int32 kMsgShade = 'shad';
|
||||||
|
|
||||||
|
|
||||||
|
ConfigView::ConfigView(BRect frame, Gravity* parent)
|
||||||
:
|
:
|
||||||
BView(rect, B_EMPTY_STRING, B_FOLLOW_ALL_SIDES, B_WILL_DRAW)
|
BView(frame, B_EMPTY_STRING, B_FOLLOW_ALL_SIDES, B_WILL_DRAW),
|
||||||
|
fParent(parent),
|
||||||
|
fTitleString(new BStringView(B_EMPTY_STRING, "OpenGL Gravity Effect")),
|
||||||
|
fAuthorString(new BStringView(B_EMPTY_STRING, "by Tri-Edge AI")),
|
||||||
|
fCountSlider(new BSlider(B_EMPTY_STRING, "Particle Count: ",
|
||||||
|
new BMessage(kMsgSize), 0, 4, B_HORIZONTAL, B_BLOCK_THUMB,
|
||||||
|
B_NAVIGABLE | B_WILL_DRAW)),
|
||||||
|
fShadeString(new BStringView(B_EMPTY_STRING, "Shade: ")),
|
||||||
|
fShadeList(new BListView(B_EMPTY_STRING, B_SINGLE_SELECTION_LIST,
|
||||||
|
B_WILL_DRAW | B_NAVIGABLE))
|
||||||
{
|
{
|
||||||
fParent = parent;
|
|
||||||
|
|
||||||
SetLayout(new BGroupLayout(B_HORIZONTAL));
|
SetLayout(new BGroupLayout(B_HORIZONTAL));
|
||||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
|
||||||
fTitleString = new BStringView(RECT_0, B_EMPTY_STRING,
|
fShadeList->SetSelectionMessage(new BMessage(kMsgShade));
|
||||||
"OpenGL Gravity Effect", B_FOLLOW_LEFT);
|
|
||||||
|
|
||||||
fAuthorString = new BStringView(RECT_0, B_EMPTY_STRING,
|
|
||||||
"by Tri-Edge AI", B_FOLLOW_LEFT);
|
|
||||||
|
|
||||||
fCountSlider = new BSlider(RECT_0, B_EMPTY_STRING, "Particle Count: ",
|
|
||||||
new BMessage(MSG_COUNT), 0, 4, B_BLOCK_THUMB);
|
|
||||||
|
|
||||||
fShadeString = new BStringView(RECT_0, B_EMPTY_STRING, "Shade: ",
|
|
||||||
B_FOLLOW_LEFT);
|
|
||||||
|
|
||||||
fShadeList = new BListView(RECT_0, B_EMPTY_STRING, B_SINGLE_SELECTION_LIST,
|
|
||||||
B_FOLLOW_ALL);
|
|
||||||
|
|
||||||
fShadeList->SetSelectionMessage(new BMessage(MSG_SHADE));
|
|
||||||
|
|
||||||
fShadeList->AddItem(new BStringItem("Red"));
|
fShadeList->AddItem(new BStringItem("Red"));
|
||||||
fShadeList->AddItem(new BStringItem("Green"));
|
fShadeList->AddItem(new BStringItem("Green"));
|
||||||
@@ -59,22 +60,18 @@ ConfigView::ConfigView(Gravity* parent, BRect rect)
|
|||||||
fCountSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
|
fCountSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
|
||||||
fCountSlider->SetHashMarkCount(5);
|
fCountSlider->SetHashMarkCount(5);
|
||||||
fCountSlider->SetLimitLabels("128", "2048");
|
fCountSlider->SetLimitLabels("128", "2048");
|
||||||
|
fCountSlider->SetModificationMessage(new BMessage(kMsgSize));
|
||||||
fCountSlider->SetValue(parent->Config.ParticleCount);
|
fCountSlider->SetValue(parent->Config.ParticleCount);
|
||||||
|
|
||||||
AddChild(BGroupLayoutBuilder(B_VERTICAL, B_USE_DEFAULT_SPACING)
|
AddChild(BLayoutBuilder::Group<>(B_VERTICAL, B_USE_DEFAULT_SPACING)
|
||||||
.Add(BGroupLayoutBuilder(B_VERTICAL, 0)
|
.AddGroup(B_VERTICAL, 0)
|
||||||
.Add(fTitleString)
|
.Add(fTitleString)
|
||||||
.Add(fAuthorString)
|
.Add(fAuthorString)
|
||||||
)
|
.End()
|
||||||
.Add(fShadeString)
|
.Add(fShadeString)
|
||||||
.Add(fShadeScroll)
|
.Add(fShadeScroll)
|
||||||
.Add(fCountSlider)
|
.Add(fCountSlider)
|
||||||
.SetInsets(B_USE_DEFAULT_SPACING,
|
.SetInsets(B_USE_DEFAULT_SPACING));
|
||||||
B_USE_DEFAULT_SPACING,
|
|
||||||
B_USE_DEFAULT_SPACING,
|
|
||||||
B_USE_DEFAULT_SPACING)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -90,11 +87,11 @@ void
|
|||||||
ConfigView::MessageReceived(BMessage* message)
|
ConfigView::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case MSG_COUNT:
|
case kMsgSize:
|
||||||
fParent->Config.ParticleCount = fCountSlider->Value();
|
fParent->Config.ParticleCount = fCountSlider->Value();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSG_SHADE:
|
case kMsgShade:
|
||||||
fParent->Config.ShadeID = fShadeList->CurrentSelection();
|
fParent->Config.ShadeID = fShadeList->CurrentSelection();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2013 Tri-Edge AI <[email protected]>
|
* Copyright 2012-2013 Tri-Edge AI <[email protected]>
|
||||||
* All rights reserved. Distributed under the terms of the MIT license.
|
* Copyright 2014 Haiku, Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the terms of the MIT license.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Tri-Edge AI
|
||||||
|
* John Scipione, [email protected]
|
||||||
*/
|
*/
|
||||||
#ifndef GRAVITY_CONFIG_VIEW_H
|
#ifndef GRAVITY_CONFIG_VIEW_H
|
||||||
#define GRAVITY_CONFIG_VIEW_H
|
#define GRAVITY_CONFIG_VIEW_H
|
||||||
@@ -8,6 +14,7 @@
|
|||||||
|
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
|
|
||||||
class Gravity;
|
class Gravity;
|
||||||
|
|
||||||
class BListView;
|
class BListView;
|
||||||
@@ -15,27 +22,26 @@ class BScrollView;
|
|||||||
class BSlider;
|
class BSlider;
|
||||||
class BStringView;
|
class BStringView;
|
||||||
|
|
||||||
class ConfigView : public BView
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ConfigView(Gravity* parent, BRect rect);
|
|
||||||
|
|
||||||
void AttachedToWindow();
|
class ConfigView : public BView {
|
||||||
void MessageReceived(BMessage* message);
|
public:
|
||||||
|
ConfigView(BRect frame, Gravity* parent);
|
||||||
|
|
||||||
|
void AttachedToWindow();
|
||||||
|
void MessageReceived(BMessage* message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Gravity* fParent;
|
Gravity* fParent;
|
||||||
|
|
||||||
BStringView* fTitleString;
|
BStringView* fTitleString;
|
||||||
BStringView* fAuthorString;
|
BStringView* fAuthorString;
|
||||||
|
|
||||||
BListView* fShadeList;
|
BSlider* fCountSlider;
|
||||||
BStringView* fShadeString;
|
|
||||||
BScrollView* fShadeScroll;
|
|
||||||
|
|
||||||
BSlider* fCountSlider;
|
|
||||||
|
|
||||||
|
BStringView* fShadeString;
|
||||||
|
BListView* fShadeList;
|
||||||
|
BScrollView* fShadeScroll;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif // GRAVITY_CONFIG_VIEW_H
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2013 Tri-Edge AI <[email protected]>
|
|
||||||
* All rights reserved. Distributed under the terms of the MIT license.
|
|
||||||
*/
|
|
||||||
#ifndef CONSTANTS_H
|
|
||||||
#define CONSTANTS_H
|
|
||||||
|
|
||||||
|
|
||||||
#define MSG_SHADE 'm000'
|
|
||||||
#define MSG_COUNT 'm001'
|
|
||||||
|
|
||||||
#define RECT_0 BRect(0, 0, 0, 0)
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,6 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2013 Tri-Edge AI <[email protected]>
|
* Copyright 2012-2013 Tri-Edge AI <[email protected]>
|
||||||
* All rights reserved. Distributed under the terms of the MIT license.
|
* Copyright 2014 Haiku, Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the terms of the MIT license.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Tri-Edge AI
|
||||||
|
* John Scipione, [email protected]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -14,9 +20,12 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
Gravity::Gravity(BMessage* prefs, image_id imageID)
|
Gravity::Gravity(BMessage* prefs, image_id imageID)
|
||||||
:
|
:
|
||||||
BScreenSaver(prefs, imageID)
|
BScreenSaver(prefs, imageID),
|
||||||
|
fGravityView(NULL),
|
||||||
|
fConfigView(NULL)
|
||||||
{
|
{
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
|
|
||||||
@@ -45,7 +54,8 @@ Gravity::SaveState(BMessage* prefs) const
|
|||||||
void
|
void
|
||||||
Gravity::StartConfig(BView* view)
|
Gravity::StartConfig(BView* view)
|
||||||
{
|
{
|
||||||
view->AddChild(new ConfigView(this, view->Bounds()));
|
fConfigView = new ConfigView(view->Bounds(), this);
|
||||||
|
view->AddChild(fConfigView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -54,8 +64,8 @@ Gravity::StartSaver(BView* view, bool preview)
|
|||||||
{
|
{
|
||||||
SetTickSize((1000 / 20) * 1000);
|
SetTickSize((1000 / 20) * 1000);
|
||||||
// ~20 FPS
|
// ~20 FPS
|
||||||
fView = new GravityView(this, view->Bounds());
|
fGravityView = new GravityView(view->Bounds(), this);
|
||||||
view->AddChild(fView);
|
view->AddChild(fGravityView);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -64,17 +74,17 @@ Gravity::StartSaver(BView* view, bool preview)
|
|||||||
void
|
void
|
||||||
Gravity::StopSaver()
|
Gravity::StopSaver()
|
||||||
{
|
{
|
||||||
if (fView != NULL)
|
if (fGravityView != NULL)
|
||||||
fView->EnableDirectMode(false);
|
fGravityView->EnableDirectMode(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Gravity::DirectConnected(direct_buffer_info* info)
|
Gravity::DirectConnected(direct_buffer_info* info)
|
||||||
{
|
{
|
||||||
if (fView != NULL) {
|
if (fGravityView != NULL) {
|
||||||
fView->DirectConnected(info);
|
fGravityView->DirectConnected(info);
|
||||||
fView->EnableDirectMode(true);
|
fGravityView->EnableDirectMode(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,5 +92,5 @@ Gravity::DirectConnected(direct_buffer_info* info)
|
|||||||
void
|
void
|
||||||
Gravity::DirectDraw(int32 frame)
|
Gravity::DirectDraw(int32 frame)
|
||||||
{
|
{
|
||||||
fView->DirectDraw();
|
fGravityView->DirectDraw();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2013 Tri-Edge AI <[email protected]>
|
* Copyright 2012-2013 Tri-Edge AI <[email protected]>
|
||||||
* All rights reserved. Distributed under the terms of the MIT license.
|
* Copyright 2014 Haiku, Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the terms of the MIT license.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Tri-Edge AI
|
||||||
|
* John Scipione, [email protected]
|
||||||
*/
|
*/
|
||||||
#ifndef GRAVITY_SCREEN_SAVER_H
|
#ifndef GRAVITY_SCREEN_SAVER_H
|
||||||
#define GRAVITY_SCREEN_SAVER_H
|
#define GRAVITY_SCREEN_SAVER_H
|
||||||
@@ -8,36 +14,37 @@
|
|||||||
|
|
||||||
#include <ScreenSaver.h>
|
#include <ScreenSaver.h>
|
||||||
|
|
||||||
class GravityView;
|
|
||||||
|
|
||||||
class BMessage;
|
class BMessage;
|
||||||
class BView;
|
class BView;
|
||||||
|
|
||||||
|
class ConfigView;
|
||||||
|
class GravityView;
|
||||||
|
|
||||||
class Gravity : public BScreenSaver
|
|
||||||
{
|
class Gravity : public BScreenSaver {
|
||||||
public:
|
public:
|
||||||
struct
|
struct {
|
||||||
{
|
|
||||||
int32 ShadeID;
|
int32 ShadeID;
|
||||||
int32 ParticleCount;
|
int32 ParticleCount;
|
||||||
} Config;
|
} Config;
|
||||||
|
|
||||||
Gravity(BMessage* prefs, image_id imageID);
|
Gravity(BMessage* prefs, image_id imageID);
|
||||||
|
|
||||||
status_t SaveState(BMessage* prefs) const;
|
status_t SaveState(BMessage* prefs) const;
|
||||||
|
|
||||||
void StartConfig(BView* view);
|
void StartConfig(BView* view);
|
||||||
|
|
||||||
status_t StartSaver(BView* view, bool preview);
|
status_t StartSaver(BView* view, bool preview);
|
||||||
void StopSaver();
|
void StopSaver();
|
||||||
|
|
||||||
void DirectConnected(direct_buffer_info* info);
|
void DirectConnected(direct_buffer_info* info);
|
||||||
void DirectDraw(int32 frame);
|
void DirectDraw(int32 frame);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GravityView* fView;
|
GravityView* fGravityView;
|
||||||
|
ConfigView* fConfigView;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif // GRAVITY_SCREEN_SAVER_H
|
||||||
|
|||||||
@@ -1,9 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2013 Tri-Edge AI <[email protected]>
|
* Copyright 2012-2013 Tri-Edge AI <[email protected]>
|
||||||
* All rights reserved. Distributed under the terms of the MIT license.
|
* Copyright 2014 Haiku, Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the terms of the MIT license.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Tri-Edge AI
|
||||||
|
* John Scipione, [email protected]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "GravitySource.h"
|
#include "GravitySource.h"
|
||||||
|
|
||||||
#include "Particle.h"
|
#include "Particle.h"
|
||||||
@@ -59,7 +66,7 @@ GravitySource::Tick()
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int32 i = 0; i < Particle::list->CountItems(); i++) {
|
for (int32 i = 0; i < Particle::list->CountItems(); i++) {
|
||||||
Particle* p = (Particle*)Particle::list->ItemAt(i);
|
Particle* p = Particle::list->ItemAt(i);
|
||||||
dx = x - p->x;
|
dx = x - p->x;
|
||||||
dy = y - p->y;
|
dy = y - p->y;
|
||||||
dz = z - p->z;
|
dz = z - p->z;
|
||||||
|
|||||||
@@ -1,34 +1,36 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2013 Tri-Edge AI <[email protected]>
|
* Copyright 2012-2013 Tri-Edge AI <[email protected]>
|
||||||
* All rights reserved. Distributed under the terms of the MIT license.
|
* Copyright 2014 Haiku, Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the terms of the MIT license.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Tri-Edge AI
|
||||||
|
* John Scipione, [email protected]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef GRAVITY_SOURCE_H
|
#ifndef GRAVITY_SOURCE_H
|
||||||
#define GRAVITY_SOURCE_H
|
#define GRAVITY_SOURCE_H
|
||||||
|
|
||||||
|
|
||||||
class GravitySource
|
struct GravitySource {
|
||||||
{
|
float x;
|
||||||
public:
|
float y;
|
||||||
float x;
|
float z;
|
||||||
float y;
|
|
||||||
float z;
|
|
||||||
float r;
|
float r;
|
||||||
|
|
||||||
float vx;
|
float vx;
|
||||||
float vy;
|
float vy;
|
||||||
float vz;
|
float vz;
|
||||||
|
|
||||||
float tx;
|
float tx;
|
||||||
float ty;
|
float ty;
|
||||||
float tz;
|
float tz;
|
||||||
|
|
||||||
GravitySource();
|
GravitySource();
|
||||||
|
|
||||||
void Tick();
|
void Tick();
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif // GRAVITY_SOURCE_H
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2013 Tri-Edge AI <[email protected]>
|
* Copyright 2012-2013 Tri-Edge AI <[email protected]>
|
||||||
* All rights reserved. Distributed under the terms of the MIT license.
|
* Copyright 2014 Haiku, Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the terms of the MIT license.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Tri-Edge AI
|
||||||
|
* John Scipione, [email protected]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -13,29 +19,16 @@
|
|||||||
#include <GL/glu.h>
|
#include <GL/glu.h>
|
||||||
|
|
||||||
|
|
||||||
GravityView::GravityView(Gravity* parent, BRect rect)
|
GravityView::GravityView(BRect frame, Gravity* parent)
|
||||||
:
|
:
|
||||||
BGLView(rect, B_EMPTY_STRING, B_FOLLOW_NONE, 0,
|
BGLView(frame, B_EMPTY_STRING, B_FOLLOW_NONE, 0,
|
||||||
BGL_RGB | BGL_DEPTH | BGL_DOUBLE)
|
BGL_RGB | BGL_DEPTH | BGL_DOUBLE),
|
||||||
|
fParent(parent),
|
||||||
|
fGravitySource(new GravitySource()),
|
||||||
|
fSize(128 << parent->Config.ParticleCount),
|
||||||
|
fShade(parent->Config.ShadeID)
|
||||||
{
|
{
|
||||||
fParent = parent;
|
Particle::Initialize(fSize, fShade);
|
||||||
|
|
||||||
int realCount;
|
|
||||||
|
|
||||||
if (parent->Config.ParticleCount == 0)
|
|
||||||
realCount = 128;
|
|
||||||
else if (parent->Config.ParticleCount == 1)
|
|
||||||
realCount = 256;
|
|
||||||
else if (parent->Config.ParticleCount == 2)
|
|
||||||
realCount = 512;
|
|
||||||
else if (parent->Config.ParticleCount == 3)
|
|
||||||
realCount = 1024;
|
|
||||||
else if (parent->Config.ParticleCount == 4)
|
|
||||||
realCount = 2048;
|
|
||||||
else
|
|
||||||
realCount = 128;
|
|
||||||
|
|
||||||
Particle::Initialize(realCount, parent->Config.ShadeID);
|
|
||||||
|
|
||||||
LockGL();
|
LockGL();
|
||||||
|
|
||||||
@@ -46,7 +39,7 @@ GravityView::GravityView(Gravity* parent, BRect rect)
|
|||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluPerspective(45.0f, rect.Width() / rect.Height(), 2.0f, 20000.0f);
|
gluPerspective(45.0f, frame.Width() / frame.Height(), 2.0f, 20000.0f);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
@@ -55,15 +48,13 @@ GravityView::GravityView(Gravity* parent, BRect rect)
|
|||||||
glDepthMask(GL_FALSE);
|
glDepthMask(GL_FALSE);
|
||||||
|
|
||||||
UnlockGL();
|
UnlockGL();
|
||||||
|
|
||||||
fGravSource = new GravitySource();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GravityView::~GravityView()
|
GravityView::~GravityView()
|
||||||
{
|
{
|
||||||
Particle::Terminate();
|
Particle::Terminate();
|
||||||
delete fGravSource;
|
delete fGravitySource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -79,13 +70,29 @@ GravityView::AttachedToWindow()
|
|||||||
void
|
void
|
||||||
GravityView::DirectDraw()
|
GravityView::DirectDraw()
|
||||||
{
|
{
|
||||||
|
int32 size = 128 << fParent->Config.ParticleCount;
|
||||||
|
int32 shade = fParent->Config.ShadeID;
|
||||||
|
|
||||||
|
// resize particle list if needed
|
||||||
|
if (size > fSize)
|
||||||
|
Particle::AddParticles(size, shade);
|
||||||
|
else if (size < fSize)
|
||||||
|
Particle::RemoveParticles(size, shade);
|
||||||
|
|
||||||
|
// recolor particles if needed
|
||||||
|
if (shade != fShade)
|
||||||
|
Particle::ColorParticles(size, shade);
|
||||||
|
|
||||||
|
fSize = size;
|
||||||
|
fShade = shade;
|
||||||
|
|
||||||
LockGL();
|
LockGL();
|
||||||
|
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
Particle::Tick();
|
Particle::Tick();
|
||||||
fGravSource->Tick();
|
fGravitySource->Tick();
|
||||||
|
|
||||||
SwapBuffers();
|
SwapBuffers();
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2013 Tri-Edge AI <[email protected]>
|
* Copyright 2012-2013 Tri-Edge AI <[email protected]>
|
||||||
* All rights reserved. Distributed under the terms of the MIT license.
|
* Copyright 2014 Haiku, Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the terms of the MIT license.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Tri-Edge AI
|
||||||
|
* John Scipione, [email protected]
|
||||||
*/
|
*/
|
||||||
#ifndef GRAVITY_VIEW_H
|
#ifndef GRAVITY_VIEW_H
|
||||||
#define GRAVITY_VIEW_H
|
#define GRAVITY_VIEW_H
|
||||||
@@ -12,21 +18,23 @@
|
|||||||
class Gravity;
|
class Gravity;
|
||||||
class GravitySource;
|
class GravitySource;
|
||||||
|
|
||||||
class GravityView : public BGLView
|
|
||||||
{
|
class GravityView : public BGLView {
|
||||||
public:
|
public:
|
||||||
GravityView(Gravity* parent, BRect rect);
|
GravityView(BRect frame, Gravity* parent);
|
||||||
~GravityView();
|
~GravityView();
|
||||||
|
|
||||||
void AttachedToWindow();
|
void AttachedToWindow();
|
||||||
|
|
||||||
void DirectDraw();
|
void DirectDraw();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Gravity* fParent;
|
Gravity* fParent;
|
||||||
GravitySource* fGravSource;
|
GravitySource* fGravitySource;
|
||||||
|
|
||||||
|
int32 fSize;
|
||||||
|
int32 fShade;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif // GRAVITY_VIEW_H
|
||||||
|
|||||||
@@ -1,101 +1,81 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2013 Tri-Edge AI <[email protected]>
|
* Copyright 2012-2013 Tri-Edge AI <[email protected]>
|
||||||
* All rights reserved. Distributed under the terms of the MIT license.
|
* Copyright 2014 Haiku, Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the terms of the MIT license.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Tri-Edge AI
|
||||||
|
* John Scipione, [email protected]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "Particle.h"
|
#include "Particle.h"
|
||||||
|
|
||||||
#include <List.h>
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
#define frand() ((float)rand() / (float)RAND_MAX)
|
#define frand() ((float)rand() / (float)RAND_MAX)
|
||||||
|
|
||||||
|
|
||||||
BList* Particle::list;
|
BObjectList<Particle>* Particle::list;
|
||||||
|
|
||||||
|
|
||||||
void
|
/*static*/ void
|
||||||
Particle::Initialize(int32 size, int32 shade)
|
Particle::Initialize(int32 size, int32 shade)
|
||||||
{
|
{
|
||||||
list = new BList();
|
list = new BObjectList<Particle>(2048);
|
||||||
|
|
||||||
for (int32 i = 0; i < size; i++) {
|
for (int32 i = 0; i < size; i++) {
|
||||||
Particle* p = new Particle();
|
Particle* p = new Particle();
|
||||||
|
Particle::_FillParticle(p, size, shade);
|
||||||
p->x = frand() * 30.0f - 15.0f;
|
|
||||||
p->y = frand() * 30.0f - 15.0f;
|
|
||||||
p->z = frand() * 5.0f;
|
|
||||||
p->r = frand() * 360.0f;
|
|
||||||
|
|
||||||
p->vx = frand() - 0.5f;
|
|
||||||
p->vy = frand() - 0.5f;
|
|
||||||
p->vz = frand() - 0.5f;
|
|
||||||
p->vr = (frand() - 0.5f) * 180.0f;
|
|
||||||
|
|
||||||
if (shade == 0) {
|
|
||||||
// Red
|
|
||||||
p->red = 0.1f + frand() * 0.2f;
|
|
||||||
p->green = 0.0f;
|
|
||||||
p->blue = frand() * 0.05f;
|
|
||||||
} else if (shade == 1) {
|
|
||||||
// Green
|
|
||||||
p->red = 0;
|
|
||||||
p->green = 0.1f + frand() * 0.2f;
|
|
||||||
p->blue = frand() * 0.05f;
|
|
||||||
} else if (shade == 2) {
|
|
||||||
// Blue
|
|
||||||
p->red = 0;
|
|
||||||
p->green = frand() * 0.05f;
|
|
||||||
p->blue = 0.1f + frand() * 0.2f;
|
|
||||||
} else if (shade == 3) {
|
|
||||||
// Orange
|
|
||||||
p->red = 0.1f + frand() * 0.1f;
|
|
||||||
p->green = 0.05f + frand() * 0.1f;
|
|
||||||
p->blue = 0.0f;
|
|
||||||
} else if (shade == 4) {
|
|
||||||
// Purple
|
|
||||||
p->red = 0.1f + frand() * 0.2f;
|
|
||||||
p->green = 0.0f;
|
|
||||||
p->blue = 0.1f + frand() * 0.2f;
|
|
||||||
} else if (shade == 5) {
|
|
||||||
// White
|
|
||||||
p->red = p->green = p->blue = 0.1f + frand() * 0.2f;
|
|
||||||
} else if (shade == 6) {
|
|
||||||
// Rainbow
|
|
||||||
p->red = 0.1f + frand() * 0.2f;
|
|
||||||
p->green = 0.1f + frand() * 0.2f;
|
|
||||||
p->blue = 0.1f + frand() * 0.2f;
|
|
||||||
} else {
|
|
||||||
// Man, this shouldn't even happen.. Blue.
|
|
||||||
p->red = 0;
|
|
||||||
p->green = frand() * 0.05f;
|
|
||||||
p->blue = 0.1f + frand() * 0.2f;
|
|
||||||
}
|
|
||||||
|
|
||||||
list->AddItem(p);
|
list->AddItem(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
/*static*/ void
|
||||||
|
Particle::AddParticles(int32 size, int32 shade)
|
||||||
|
{
|
||||||
|
for (int32 i = list->CountItems(); i < size; i++) {
|
||||||
|
Particle* p = new Particle();
|
||||||
|
Particle::_FillParticle(p, size, shade);
|
||||||
|
list->AddItem(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*static*/ void
|
||||||
|
Particle::RemoveParticles(int32 size, int32 shade)
|
||||||
|
{
|
||||||
|
while (list->CountItems() > size)
|
||||||
|
delete list->RemoveItemAt(list->CountItems() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*static*/ void
|
||||||
|
Particle::ColorParticles(int32 size, int32 shade)
|
||||||
|
{
|
||||||
|
for (int32 i = 0; i < size; i++) {
|
||||||
|
Particle* p = list->ItemAt(i);
|
||||||
|
Particle::_ColorParticle(p, size, shade);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*static*/ void
|
||||||
Particle::Terminate()
|
Particle::Terminate()
|
||||||
{
|
{
|
||||||
for (int32 i = 0; i < list->CountItems(); i++)
|
|
||||||
delete (Particle*)list->ItemAt(i);
|
|
||||||
|
|
||||||
list->MakeEmpty();
|
list->MakeEmpty();
|
||||||
delete list;
|
delete list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
/*static*/ void
|
||||||
Particle::Tick()
|
Particle::Tick()
|
||||||
{
|
{
|
||||||
for (int32 i = 0; i < list->CountItems(); i++) {
|
for (int32 i = 0; i < list->CountItems(); i++) {
|
||||||
Particle* p = (Particle*)list->ItemAt(i);
|
Particle* p = list->ItemAt(i);
|
||||||
p->_Logic();
|
p->_Logic();
|
||||||
p->_Render();
|
p->_Render();
|
||||||
}
|
}
|
||||||
@@ -134,3 +114,74 @@ Particle::_Render() const
|
|||||||
glEnd();
|
glEnd();
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*static*/ void
|
||||||
|
Particle::_FillParticle(Particle* p, int32 size, int32 shade)
|
||||||
|
{
|
||||||
|
p->x = frand() * 30.0f - 15.0f;
|
||||||
|
p->y = frand() * 30.0f - 15.0f;
|
||||||
|
p->z = frand() * 5.0f;
|
||||||
|
p->r = frand() * 360.0f;
|
||||||
|
|
||||||
|
p->vx = frand() - 0.5f;
|
||||||
|
p->vy = frand() - 0.5f;
|
||||||
|
p->vz = frand() - 0.5f;
|
||||||
|
p->vr = (frand() - 0.5f) * 180.0f;
|
||||||
|
|
||||||
|
Particle::_ColorParticle(p, size, shade);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*static*/ void
|
||||||
|
Particle::_ColorParticle(Particle* p, int32 size, int32 shade)
|
||||||
|
{
|
||||||
|
switch(shade) {
|
||||||
|
case 0:
|
||||||
|
// Red
|
||||||
|
p->red = 0.1f + frand() * 0.2f;
|
||||||
|
p->green = 0.0f;
|
||||||
|
p->blue = frand() * 0.05f;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
// Green
|
||||||
|
p->red = 0;
|
||||||
|
p->green = 0.1f + frand() * 0.2f;
|
||||||
|
p->blue = frand() * 0.05f;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
default:
|
||||||
|
// Blue
|
||||||
|
p->red = 0;
|
||||||
|
p->green = frand() * 0.05f;
|
||||||
|
p->blue = 0.1f + frand() * 0.2f;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
// Orange
|
||||||
|
p->red = 0.1f + frand() * 0.1f;
|
||||||
|
p->green = 0.05f + frand() * 0.1f;
|
||||||
|
p->blue = 0.0f;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
// Purple
|
||||||
|
p->red = 0.1f + frand() * 0.2f;
|
||||||
|
p->green = 0.0f;
|
||||||
|
p->blue = 0.1f + frand() * 0.2f;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
// White
|
||||||
|
p->red = p->green = p->blue = 0.1f + frand() * 0.2f;
|
||||||
|
|
||||||
|
case 6:
|
||||||
|
// Rainbow
|
||||||
|
p->red = 0.1f + frand() * 0.2f;
|
||||||
|
p->green = 0.1f + frand() * 0.2f;
|
||||||
|
p->blue = 0.1f + frand() * 0.2f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,44 +1,55 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2013 Tri-Edge AI <[email protected]>
|
* Copyright 2012-2013 Tri-Edge AI <[email protected]>
|
||||||
* All rights reserved. Distributed under the terms of the MIT license.
|
* Copyright 2014 Haiku, Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the terms of the MIT license.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Tri-Edge AI
|
||||||
|
* John Scipione, [email protected]
|
||||||
*/
|
*/
|
||||||
#ifndef PARTICLE_H
|
#ifndef PARTICLE_H
|
||||||
#define PARTICLE_H
|
#define PARTICLE_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <ObjectList.h>
|
||||||
#include <GLView.h>
|
#include <GLView.h>
|
||||||
|
|
||||||
class BList;
|
|
||||||
|
|
||||||
|
class Particle {
|
||||||
class Particle
|
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
static BList* list;
|
static BObjectList<Particle>* list;
|
||||||
|
|
||||||
static void Initialize(int32 size, int32 shade);
|
static void Initialize(int32 size, int32 shade);
|
||||||
static void Terminate();
|
static void AddParticles(int32 size, int32 shade);
|
||||||
static void Tick();
|
static void RemoveParticles(int32 size, int32 shade);
|
||||||
|
static void ColorParticles(int32 size, int32 shade);
|
||||||
|
static void Terminate();
|
||||||
|
static void Tick();
|
||||||
|
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
float z;
|
float z;
|
||||||
float r;
|
float r;
|
||||||
|
|
||||||
float vx;
|
float vx;
|
||||||
float vy;
|
float vy;
|
||||||
float vz;
|
float vz;
|
||||||
float vr;
|
float vr;
|
||||||
|
|
||||||
float red;
|
float red;
|
||||||
float green;
|
float green;
|
||||||
float blue;
|
float blue;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _Logic();
|
void _Logic();
|
||||||
void _Render() const;
|
void _Render() const;
|
||||||
|
|
||||||
|
static void _FillParticle(Particle* p, int32 size,
|
||||||
|
int32 shade);
|
||||||
|
static void _ColorParticle(Particle* p, int32 size,
|
||||||
|
int32 shade);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif // PARTICLE_H
|
||||||
|
|||||||
Reference in New Issue
Block a user