Skip to content
Permalink
Browse files

refine code finished

  • Loading branch information...
shinabebel committed Dec 13, 2015
1 parent fa8ad18 commit b73f7648aa8395b847176e776176496c9e7fd298
Showing with 25 additions and 18 deletions.
  1. +1 −1 samples/Plexus/src/PlexusApp.cpp
  2. +22 −17 src/Plexus.cpp
  3. +2 −0 src/Plexus.h
@@ -47,7 +47,7 @@ void PlexusApp::setup()

gl::Fbo::Format format;
format.setSamples(4);
mFbo = gl::Fbo::create(1280, 1280, format);
mFbo = gl::Fbo::create(1920, 1920, format);

cam.setPerspective(30.0f, mFbo->getAspectRatio(), 0.1f, 2000.0f);
vec3 camEye = vec3(0.0, 0.0, 1000.0f);
@@ -26,14 +26,18 @@ Plexus::Plexus(size_t numLine, size_t numSegment, bool bLine, bool bTriangle)
bTriRenderer = bTriangle;
// triRenderer.setup(numLine*numPoint);

loadShaders();
// loadShaders();
mSeed = Rand::randFloat(1000);

}

void Plexus::update(vec3 eyePosition)
{
updateBuffer();
updateLineBuffer();
updateTriBuffer();
if (bLineRenderer)
updateLineBuffer();
if (bTriRenderer)
updateTriBuffer();

for (size_t i = 0; i < numLine; i++)
{
@@ -87,13 +91,12 @@ void Plexus::draw()
{
const gl::ScopedColor white(Color::white());

gl::draw(triMesh);
if (bTriRenderer)
gl::draw(triMesh);

if (bLineRenderer)
{
//const gl::ScopedDepth scpDepth(true);
const gl::ScopedBlendAdditive scpBlend;
//const gl::ScopedBlendAlpha scpBlend;

gl::draw(lineMesh);
}

@@ -115,7 +118,7 @@ void Plexus::updateBuffer()
for (size_t j = 0; j < numSegment; j++)
{
float a = time + mTimeOffset * j + i * 123.456;
auto pos = vec3(mPerlin.noise(0.1, a), mPerlin.noise(1.2, a), mPerlin.noise(2.3, a)) * mRadius;
auto pos = vec3(mPerlin.noise(0.1, a, mSeed), mPerlin.noise(1.2, a, mSeed), mPerlin.noise(2.3, a, mSeed)) * mRadius;
points.emplace_back(pos);
if (j == 0)
points.emplace_back(pos);
@@ -203,19 +206,21 @@ void Plexus::updateTriBuffer()
for (size_t n = 2; n < b2.size() - 2; n++)
{
auto& p2 = b2[n];
auto d1 = glm::distance(p1, p2);
if (d1 < mMinDistance || d1 > mMaxDistance)
continue;
auto d12 = glm::distance(p1, p2);
for (size_t o = 2; o < b3.size() - 2; o++)
{
auto& p3 = b3[o];
auto d2 = glm::distance(p2, p3);
auto d3 = glm::distance(p3, p1);
if (d2 < mMinDistance || d2 > mMaxDistance || d3 < mMinDistance || d3 > mMaxDistance)
auto d23 = glm::distance(p2, p3);
auto d31 = glm::distance(p3, p1);
int err = 0;
if (d12 < mMinDistance || d12 > mMaxDistance) err += 1;
if (d23 < mMinDistance || d23 > mMaxDistance) err += 1;
if (d31 < mMinDistance || d31 > mMaxDistance) err += 1;
if (err > 1)
continue;
auto a1 = 1.f - (d1 - mMinDistance) / (mMaxDistance - mMinDistance);
auto a2 = 1.f - (d2 - mMinDistance) / (mMaxDistance - mMinDistance);
auto a3 = 1.f - (d3 - mMinDistance) / (mMaxDistance - mMinDistance);
auto a1 = 1.f - (d23 - mMinDistance) / (mMaxDistance - mMinDistance);
auto a2 = 1.f - (d31 - mMinDistance) / (mMaxDistance - mMinDistance);
auto a3 = 1.f - (d12 - mMinDistance) / (mMaxDistance - mMinDistance);
std::lock_guard<mutex> guard(mMutex);
mTriBuffer.emplace_back(make_pair(p1, vec4(a1, a1, a1, 1)));
mTriBuffer.emplace_back(make_pair(p2, vec4(a2, a2, a2, 1)));
@@ -45,6 +45,8 @@ namespace hb
bool bLineRenderer;
bool bTriRenderer;

float mSeed;

/////////////////////
size_t numLine;
size_t numSegment;

0 comments on commit b73f764

Please sign in to comment.
You can’t perform that action at this time.