-
-
Save loveandsheep/90f01c0dc0ae789b4e640f9d7a060ede to your computer and use it in GitHub Desktop.
3次元空間の2つの点から平面の角度を計算
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
#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(); | |
} |
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
#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