-
Notifications
You must be signed in to change notification settings - Fork 5
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
11 changed files
with
634 additions
and
0 deletions.
There are no files selected for viewing
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,5 @@ | ||
#pragma once | ||
#include "cinder/CinderResources.h" | ||
#include "Resources.h" | ||
|
||
//#define RES_MY_RES CINDER_RESOURCE( ../resources/, image_name.png, 128, IMAGE ) |
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,74 @@ | ||
#include "cinder/app/AppBasic.h" | ||
#include "cinder/gl/gl.h" | ||
#include "cinder/Rand.h" | ||
#include "Mover.h" | ||
#include "Liquid.h" | ||
|
||
using namespace ci; | ||
using namespace ci::app; | ||
using namespace std; | ||
|
||
class Exercise5App : public AppBasic { | ||
public: | ||
void setup(); | ||
void update(); | ||
void draw(); | ||
void prepareSettings(Settings *settings); | ||
|
||
vector<Mover*> mMovers; | ||
int mNumMovers; | ||
|
||
Liquid *liquid; | ||
}; | ||
|
||
void Exercise5App::prepareSettings(Settings *settings) { | ||
settings->setFullScreen(); | ||
} | ||
|
||
void Exercise5App::setup() | ||
{ | ||
mNumMovers = 20; | ||
int i = 0; | ||
while (i < mNumMovers) { | ||
mMovers.push_back(new Mover(randFloat(1.0, 5.0), randFloat(getWindowWidth()), randFloat(getWindowHeight()/2))); | ||
i++; | ||
} | ||
liquid = new Liquid(); | ||
} | ||
|
||
void Exercise5App::update() | ||
{ | ||
Vec2f wind = Vec2f(0.05, 0); | ||
for (auto mover : mMovers) { | ||
if (liquid->contains(mover->mLocation)) { | ||
mover->drag(liquid); | ||
} | ||
|
||
mover->applyForce(wind); | ||
|
||
float c = 0.01; | ||
Vec2f friction = mover->mVelocity; | ||
friction *= -1; | ||
friction.safeNormalize(); | ||
friction *= c; | ||
mover->applyForce(friction); | ||
|
||
float m = (0.1 * mover->mMass); | ||
Vec2f gravity = Vec2f(0, m); | ||
mover->applyForce(gravity); | ||
|
||
mover->update(); | ||
mover->checkEdges(); | ||
} | ||
} | ||
|
||
void Exercise5App::draw() | ||
{ | ||
gl::clear( Color( 1, 1, 1 ) ); | ||
liquid->draw(); | ||
for (auto mover : mMovers) { | ||
mover->draw(); | ||
} | ||
} | ||
|
||
CINDER_APP_BASIC( Exercise5App, RendererGl ) |
Binary file not shown.
Oops, something went wrong.