-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |