[work 81] Rotating triangles
![[work 81] Rotating triangles](https://i0.wp.com/tsukuru.hayato-works.com/wp-content/uploads/2019/08/outFrameImg0100.png?fit=1280%2C720&ssl=1)
Movie
Source code
about
- 大きさの違う三角形を回転させる
- 回転角速度はイージングに従う
file
- 上部にあるファイル名が表示されているボタンを押すと、表示されるファイルが切り替わります
- 別ウィンドウ表示したい時や行番号などが無いRawMode表示したい時は、コード内右上のボタンを押してください(ボタンはマウスオーバーすると表示されます)
#include "ofMain.h"
#include "ofApp.h"
//================================
int main( ){
// 4K:4096x2160
// 2K:2048x1080
// FullHD:1920x1080
// HD:1440x1080
// HD720p:1280x720
// DVD:720x480
// setup the GL context
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 "ofxEasing.h"
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:
ofCamera cam;
ofMesh mesh;
std::vector<ofVec3f> baseT;
ofVec3f axis;
int angle;
std::vector<ofxeasing::function> easings{
ofxeasing::linear::easeIn,
ofxeasing::quad::easeInOut,
ofxeasing::cubic::easeInOut,
ofxeasing::quart::easeInOut,
ofxeasing::quint::easeInOut,
ofxeasing::circ::easeInOut,
ofxeasing::sine::easeInOut,
ofxeasing::exp::easeInOut,
ofxeasing::elastic::easeInOut,
ofxeasing::bounce::easeInOut,
ofxeasing::back::easeInOut,
};
};
#include "ofApp.h"
ofApp::ofApp(){
}
ofApp::~ofApp(){
}
//--------------------------------------------------------------
void ofApp::setup(){
double fps = 30;
ofSetFrameRate(fps);
ofBackground(255);
ofSetBackgroundAuto(true);
ofSetVerticalSync(true);
cam.setGlobalPosition(glm::vec3(400, 400, 400));
cam.lookAt(glm::vec3(0, 0, 0));
ofVec3f d = ofVec3f(0, 0, 1);
float len = 30;
baseT.push_back(d);
baseT.push_back(d.rotate(120, ofVec3f(0, 1, 0)));
baseT.push_back(d.rotate(120, ofVec3f(0, 1, 0)));
axis = ofVec3f(0, 0, 1);
angle = 0;
}
//--------------------------------------------------------------
void ofApp::update(){
float ext = 30;
mesh.clear();
for (int m = 0; m < easings.size(); m++) {
float a = ofxeasing::map(angle, 0, 359, 0, 359, easings.at(m));
std::vector<ofVec3f> p = baseT;
for (int i = 0; i < p.size(); i++) {
p.at(i) *= ext * (m + 1);
p.at(i) = p.at(i).rotate(a, axis);
}
mesh.setMode(OF_PRIMITIVE_TRIANGLES);
mesh.addVertex(p.at(0));
mesh.addVertex(p.at(1));
mesh.addVertex(p.at(2));
mesh.addColor(ofColor(0));
mesh.addColor(ofColor(0));
mesh.addColor(ofColor(0));
}
angle = (angle + 1) % 360;
}
//--------------------------------------------------------------
void ofApp::draw(){
cam.begin();
mesh.drawWireframe();
cam.end();
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
if (key == 's') {
ofImage img;
img.grabScreen(0, 0, ofGetWidth(), ofGetHeight());
img.save("screenshot.png");
}
}
Link to the reference page
ソースコードで使用したAPIの中から要点になりそうなものをいくつか選んでリストアップしました。
| category | API/Lib |
| openframeworks | ofCamera |
| openframeworks | ofMesh |
| openframeworks | ofxeasing map |
Development environment
- openframeworks 0.10.1
- c++
- macOS
- Xcode