#include "ofMain.h"
#include "ofApp.h"
//========================================
int main( ){
// 4K:4096x2160
// 2K:2048x1080
// FullHD:1920x1080
// HD:1440x1080
// HD720p:1280x720
// DVD:720x480
ofSetupOpenGL(1280,720, OF_WINDOW);
// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
ofRunApp( new ofApp());
}
#pragma once
#include "ofMain.h"
#include <random>
#include "Mover.hpp"
#include "Liquid.hpp"
#include "myColorLib.hpp"
class ofApp : public ofBaseApp{
public:
ofApp();
~ofApp();
void setup();
void update();
void draw();
void keyPressed(int key);
void keyReleased(int key);
void mouseMoved(int x, int y);
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void mouseEntered(int x, int y);
void mouseExited(int x, int y);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
private:
Liquid *liquid;
Mover *m[MOVER_MAX];
ofVec2f gravity;
ofVec2f wind;
myColorLib *myColLib;
};
#include "ofApp.h"
ofApp::ofApp(){
myColLib = new myColorLib(MYCOL_ALL);
liquid = new Liquid(0, ofGetHeight() / 2, ofGetWidth(), ofGetHeight() / 2, 0.1);
for (int i = 0; i < MOVER_MAX; i++) {
m[i] = new Mover(ofRandom(0.5, 2), ofRandomWidth(), ofGetHeight() / ofRandom(4, 10), myColLib->getColor(ofRandom(1)));
}
}
ofApp::~ofApp(){
for (int i = 0; i < MOVER_MAX; i++) {
if (m[i] != nullptr) {
delete m[i];
}
}
delete liquid;
delete myColLib;
}
//--------------------------------------------------------------
void ofApp::setup(){
double fps = 30;
ofSetFrameRate(fps);
ofBackground(255,255,255);
ofSetBackgroundAuto(true);
gravity = ofVec2f(0, 0);
wind = ofVec2f(0, 0);
}
//--------------------------------------------------------------
void ofApp::update(){
wind = ofVec2f(ofRandom(-0.1, 0.1), 0);
for (int i = 0; i < MOVER_MAX; i++) {
if (m[i] != nullptr) {
if (liquid->contains(*m[i])) {
ofVec2f dragForce = liquid->drag(*m[i]);
m[i]->applyForce(dragForce);
}
gravity = ofVec2f(0, 0.2 * m[i]->getMass());
m[i]->applyForce(gravity);
m[i]->applyForce(wind);
m[i]->update();
if (m[i]->getLife() == 0) {
delete m[i];
m[i] = nullptr;
}
}
}
}
//--------------------------------------------------------------
void ofApp::draw(){
liquid->display();
for (int i = 0; i < MOVER_MAX; i++) {
if (m[i] != nullptr) {
m[i]->display();
}
}
}