2 * Copyright 2012-2013 Tri-Edge AI <triedgeai@gmail.com>
3 * Copyright 2014 Haiku, Inc. All rights reserved.
5 * Distributed under the terms of the MIT license.
9 * John Scipione, jscipione@gmail.com
13 #include "GravityView.h"
16 #include "GravitySource.h"
22 GravityView::GravityView(BRect frame
, Gravity
* parent
)
24 BGLView(frame
, B_EMPTY_STRING
, B_FOLLOW_NONE
, 0,
25 BGL_RGB
| BGL_DEPTH
| BGL_DOUBLE
),
27 fGravitySource(new GravitySource()),
28 fSize(128 << parent
->Config
.ParticleCount
),
29 fShade(parent
->Config
.ShadeID
)
31 Particle::Initialize(fSize
, fShade
);
35 GravityView::~GravityView()
37 Particle::Terminate();
38 delete fGravitySource
;
43 GravityView::AttachedToWindow()
46 BGLView::AttachedToWindow();
51 glBlendFunc(GL_SRC_ALPHA
, GL_ONE
);
53 glMatrixMode(GL_PROJECTION
);
55 gluPerspective(45.0f
, Bounds().Width() / Bounds().Height(), 2.0f
, 20000.0f
);
56 glMatrixMode(GL_MODELVIEW
);
59 glTranslatef(0.0f
, 0.0f
, -30.0f
);
61 glDepthMask(GL_FALSE
);
68 GravityView::DirectDraw()
70 int32 size
= 128 << fParent
->Config
.ParticleCount
;
71 int32 shade
= fParent
->Config
.ShadeID
;
73 // resize particle list if needed
75 Particle::AddParticles(size
, shade
);
76 else if (size
< fSize
)
77 Particle::RemoveParticles(size
, shade
);
79 // recolor particles if needed
81 Particle::ColorParticles(size
, shade
);
88 glClearColor(0.0f
, 0.0f
, 0.0f
, 0.0f
);
89 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
92 fGravitySource
->Tick();