-
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
583 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,48 @@ | ||
#include "cinder/app/AppBasic.h" | ||
#include "cinder/gl/gl.h" | ||
#include "cinder/Rand.h" | ||
#include "Attractor.h" | ||
#include "Mover.h" | ||
|
||
|
||
using namespace ci; | ||
using namespace ci::app; | ||
using namespace std; | ||
|
||
class Example6App : public AppBasic { | ||
public: | ||
void setup(); | ||
void update(); | ||
void draw(); | ||
void prepareSettings(Settings *settings); | ||
|
||
MoverRef mMover; | ||
AttractorRef mAttractor; | ||
}; | ||
|
||
void Example6App::prepareSettings(Settings *settings) { | ||
settings->setFullScreen(); | ||
} | ||
|
||
void Example6App::setup() | ||
{ | ||
mMover = MoverRef(new Mover()); | ||
mAttractor = AttractorRef(new Attractor()); | ||
} | ||
|
||
void Example6App::update() | ||
{ | ||
Vec2f force = mAttractor->attract(mMover); | ||
mMover->applyForce(force); | ||
mMover->update(); | ||
} | ||
|
||
void Example6App::draw() | ||
{ | ||
gl::clear( Color( 1, 1, 1 ) ); | ||
|
||
mAttractor->draw(); | ||
mMover->draw(); | ||
} | ||
|
||
CINDER_APP_BASIC( Example6App, 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,42 @@ | ||
/* | ||
* Attractor.cpp | ||
* Example6 | ||
* | ||
* Created by Nathan Koch on 1/4/13 | ||
* Copyright 2013 __MyCompanyName__. All rights reserved. | ||
* | ||
*/ | ||
|
||
// header files | ||
#include "cinder/app/AppBasic.h" | ||
#include "cinder/CinderMath.h" | ||
#include "Mover.h" | ||
#include "Attractor.h" | ||
|
||
// namespaces | ||
using namespace ci; | ||
|
||
|
||
Attractor::Attractor( ) { | ||
mLocation = (Vec2f)app::getWindowCenter(); | ||
mMass = 20.0f; | ||
mG = 0.4f; | ||
} | ||
|
||
|
||
void Attractor::draw( ) { | ||
gl::color(0.68, 0.68, 0.68); | ||
gl::drawSolidCircle(mLocation, mMass*2); | ||
gl::color(0, 0, 0); | ||
gl::drawStrokedCircle(mLocation, mMass*2); | ||
} | ||
|
||
Vec2f Attractor::attract(MoverRef m) { | ||
Vec2f force = mLocation - m->mLocation; | ||
float distance = force.length(); | ||
distance = math<float>::clamp(distance, 5.0f, 25.0f); | ||
float strength = (mG * mMass * mMass) / ( distance * distance ); | ||
force.safeNormalize(); | ||
force *= strength; | ||
return force; | ||
} |
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,25 @@ | ||
/* | ||
* Attractor.h | ||
* Example6 | ||
* | ||
* Created by Nathan Koch on 1/4/13 | ||
* Copyright 2013 __MyCompanyName__. All rights reserved. | ||
* | ||
*/ | ||
#include "Mover.h" | ||
#pragma once | ||
|
||
typedef std::shared_ptr<class Attractor> AttractorRef; | ||
class Attractor { | ||
|
||
public: | ||
|
||
Attractor(); | ||
|
||
void draw(); | ||
ci::Vec2f attract(MoverRef m); | ||
|
||
float mMass; | ||
float mG; | ||
ci::Vec2f mLocation; | ||
}; |
Binary file not shown.
Oops, something went wrong.