Skip to content

Commit

Permalink
Made into CinderBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewfb committed Apr 20, 2013
1 parent 480d60f commit d15ecf6
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 0 deletions.
Binary file added cinderblock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions cinderblock.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>
<cinder>
<block
name="CinderFluid"
id="org.libcinder.cinderfluid"
author="Hai Nguyen"
summary="Realtime 2D fluid simulator."
>
<supports os="msw" />
<supports os="macosx" />
<includePath>src</includePath>
<source>src/cinderfx/Fluid2D.cpp</source>
<header>src/cinderfx/Clamp.h</header>
<header>src/cinderfx/Fluid2D.h</header>
<header>src/cinderfx/Grid.h</header>
</block>
<template>templates/Basic GL/template.xml</template>
</cinder>
93 changes: 93 additions & 0 deletions templates/Basic GL/src/_TBOX_PREFIX_App.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#include "cinder/app/AppNative.h"
#include "cinder/gl/gl.h"
#include "cinder/gl/GlslProg.h"
#include "cinder/gl/Texture.h"
#include "cinder/Utilities.h"

using namespace ci;
using namespace ci::app;
using namespace std;

#include "cinderfx/Fluid2D.h"
using namespace cinderfx;

class _TBOX_PREFIX_App : public ci::app::AppNative {
public:
void prepareSettings( ci::app::AppNative::Settings *settings );
void setup();
void mouseDown( ci::app::MouseEvent event );
void mouseDrag( ci::app::MouseEvent event );
void update();
void draw();

private:
float mVelScale;
float mDenScale;
ci::Vec2f mPrevPos;
cinderfx::Fluid2D mFluid2D;
ci::gl::Texture mTex;
};

void _TBOX_PREFIX_App::prepareSettings( Settings *settings )
{
settings->setWindowSize( 700, 700 );
settings->setResizable( false );
settings->setFrameRate( 1000 );
}

void _TBOX_PREFIX_App::setup()
{
glEnable( GL_TEXTURE_2D );

mDenScale = 25;

mFluid2D.set( 192, 192 );
mFluid2D.setDensityDissipation( 0.99f );
mVelScale = 3.0f*std::max( mFluid2D.resX(), mFluid2D.resY() );

mFluid2D.enableDensity();
mFluid2D.enableVorticityConfinement();
mFluid2D.initSimData();
}

void _TBOX_PREFIX_App::mouseDown( MouseEvent event )
{
mPrevPos = event.getPos();
}

void _TBOX_PREFIX_App::mouseDrag( MouseEvent event )
{
float x = (event.getX()/(float)getWindowWidth())*mFluid2D.resX();
float y = (event.getY()/(float)getWindowHeight())*mFluid2D.resY();

if( event.isLeftDown() ) {
Vec2f dv = event.getPos() - mPrevPos;
mFluid2D.splatVelocity( x, y, mVelScale*dv );
mFluid2D.splatDensity( x, y, mDenScale );
}

mPrevPos = event.getPos();
}

void _TBOX_PREFIX_App::update()
{
mFluid2D.step();
}

void _TBOX_PREFIX_App::draw()
{
// clear out the window with black
gl::clear( Color( 0, 0, 0 ) );

Channel32f chan( mFluid2D.resX(), mFluid2D.resY(), mFluid2D.resX()*sizeof(float), 1, const_cast<float*>( mFluid2D.density().data() ) );

if( ! mTex ) {
mTex = gl::Texture( chan );
} else {
mTex.update( chan );
}
gl::color( Color( 1, 1, 1 ) );
gl::draw( mTex, getWindowBounds() );
}

CINDER_APP_NATIVE( _TBOX_PREFIX_App, RendererGl )
9 changes: 9 additions & 0 deletions templates/Basic GL/template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<cinder>
<template name="CinderFluid: Basic GL" parent="org.libcinder.apptemplates.basicopengl">
<requires>org.libcinder.cinderfluid</requires>
<supports os="macosx" />
<supports os="msw" />
<source replaceContents="true" replaceName="true">src/_TBOX_PREFIX_App.cpp</source>
</template>
</cinder>

0 comments on commit d15ecf6

Please sign in to comment.