Skip to content

Instantly share code, notes, and snippets.

@loveandsheep
Forked from tado/ofApp.cpp
Last active November 11, 2016 11:33
Show Gist options
  • Save loveandsheep/90f01c0dc0ae789b4e640f9d7a060ede to your computer and use it in GitHub Desktop.
Save loveandsheep/90f01c0dc0ae789b4e640f9d7a060ede to your computer and use it in GitHub Desktop.
3次元空間の2つの点から平面の角度を計算
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
ofBackground(0);
ofSetDepthTest(true);
ofSetRectMode(OF_RECTMODE_CENTER);
posA.set(-80, -90, -200); // 開始点を設定
posB.set(100, 120, 130); // 終了点を設定
//開始点と終了点の中間の点を算出
posC = posA;
posC.interpolate(posB, 0.5);
}
//--------------------------------------------------------------
void ofApp::update(){
node_C.setGlobalPosition(posC);//ノードの位置を中点に設定
node_C.lookAt(posA);//ノードを開始点の方向に向ける
node_C.pan(90);//向くのがZ軸方向なので、Y軸を90度回す
}
//--------------------------------------------------------------
void ofApp::draw(){
cam.begin();
//全体の枠を描画
ofNoFill();
ofDrawBox(0, 0, 0, 500, 500, 500);
ofFill();
//開始点、終了点、中間点を描画
ofSetColor(0, 0, 255);
ofDrawSphere(posA, 5);
ofDrawSphere(posB, 5);
ofSetColor(255, 0, 0);
node_C.draw();
//面を描画
ofPushMatrix();
//ノードの行列を適用
ofMultMatrix(node_C.getGlobalTransformMatrix());
ofSetColor(255);
ofDrawRectangle(0, 0, 500, 50);
ofPopMatrix();
cam.end();
}
#pragma once
#include "ofMain.h"
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
ofVec3f posA; //開始点
ofVec3f posB; //終了点
ofVec3f posC; //AとBの中間点
ofNode node_C; //位置と向きを保存するノード
ofEasyCam cam; //カメラ
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment