summaryrefslogtreecommitdiff
path: root/rayhit/src
diff options
context:
space:
mode:
Diffstat (limited to 'rayhit/src')
-rw-r--r--rayhit/src/main.cpp16
-rw-r--r--rayhit/src/testApp.cpp109
-rw-r--r--rayhit/src/testApp.h37
3 files changed, 162 insertions, 0 deletions
diff --git a/rayhit/src/main.cpp b/rayhit/src/main.cpp
new file mode 100644
index 0000000..6a32c6a
--- /dev/null
+++ b/rayhit/src/main.cpp
@@ -0,0 +1,16 @@
+#include "ofMain.h"
+#include "testApp.h"
+#include "ofAppGlutWindow.h"
+
+//========================================================================
+int main( ){
+
+ ofAppGlutWindow window;
+ ofSetupOpenGL(&window, 1024,768, OF_WINDOW); // <-------- setup the GL context
+
+ // this kicks off the running of my app
+ // can be OF_WINDOW or OF_FULLSCREEN
+ // pass in width and height too:
+ ofRunApp( new testApp());
+
+}
diff --git a/rayhit/src/testApp.cpp b/rayhit/src/testApp.cpp
new file mode 100644
index 0000000..750287c
--- /dev/null
+++ b/rayhit/src/testApp.cpp
@@ -0,0 +1,109 @@
+#include "testApp.h"
+
+//--------------------------------------------------------------
+void testApp::setup(){
+ ofVec3f centre=ofVec3f(ofGetWidth()/2,ofGetHeight(),0);
+ ofVec3f normal=ofVec3f(0,0,1);
+ ray=ofRay();
+ plane=ofPlane(centre,normal);
+
+ projector=ofProjector(ofGetWidth(),ofGetHeight());
+
+ pos=ofVec3f(ofGetWidth()/2,ofGetHeight()/2,0);
+}
+
+//--------------------------------------------------------------
+void testApp::update(){
+
+
+
+}
+
+//--------------------------------------------------------------
+void testApp::draw(){
+ ofBackground(0,0,0);
+ plane.draw();
+
+ float gap=ofGetHeight()-ofGetWidth();
+
+ ofPushMatrix();
+
+ ofTranslate(0,ofGetHeight(),0);
+ ofRotate(cam_angle,1,0,0);
+ ofTranslate(0,-ofGetHeight(),0);
+
+ for (float i=0;i<ofGetWidth();i+=ofGetWidth()/10) {
+ glBegin(GL_LINES);
+ glVertex3f(i,gap,0);
+ glVertex3f(i,ofGetHeight(),0);
+ glEnd();
+ glBegin(GL_LINES);
+ glVertex3f(0,i+gap,0);
+ glVertex3f(ofGetWidth(),i+gap,0);
+ glEnd();
+ }
+
+ ofPopMatrix();
+
+ ofSphere(pos.x,pos.y,pos.z,20);
+
+}
+
+//--------------------------------------------------------------
+void testApp::keyPressed(int key){
+
+ switch (key){
+ case 'a':
+ cam_angle+=1;
+ break;
+ case 'z':
+ cam_angle-=1;
+ break;
+ }
+ plane.setNormal(ofVec3f(0,sin(cam_angle),cos(cam_angle)));
+}
+
+//--------------------------------------------------------------
+void testApp::keyReleased(int key){
+
+}
+
+//--------------------------------------------------------------
+void testApp::mouseMoved(int x, int y ){
+
+}
+
+//--------------------------------------------------------------
+void testApp::mouseDragged(int x, int y, int button){
+
+}
+
+//--------------------------------------------------------------
+void testApp::mousePressed(int x, int y, int button){
+
+}
+
+//--------------------------------------------------------------
+void testApp::mouseReleased(int x, int y, int button){
+ ray=projector.castPixel(x,(ofGetHeight()-y));
+ bool hit = plane.intersect(ray,pos);
+ pos=ofVec3f(pos.x*2,pos.y*2,pos.z*2);
+ if (hit) printf("ray:%i,%i hit plane:%f,%f,%f\n",x,y,pos.x,pos.y,pos.z);
+ else printf("ray:%i,%i missed plane\n",x,y);
+
+}
+
+//--------------------------------------------------------------
+void testApp::windowResized(int w, int h){
+
+}
+
+//--------------------------------------------------------------
+void testApp::gotMessage(ofMessage msg){
+
+}
+
+//--------------------------------------------------------------
+void testApp::dragEvent(ofDragInfo dragInfo){
+
+}
diff --git a/rayhit/src/testApp.h b/rayhit/src/testApp.h
new file mode 100644
index 0000000..e5a035d
--- /dev/null
+++ b/rayhit/src/testApp.h
@@ -0,0 +1,37 @@
+#pragma once
+
+#include "ofMain.h"
+
+#include "ofxOpenCv.h"
+#include "ofxRay.h"
+
+//#define _USE_LIVE_VIDEO // uncomment this to use a live camera
+ // otherwise, we'll use a movie file
+
+class testApp : public ofBaseApp{
+
+ public:
+ 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 windowResized(int w, int h);
+ void dragEvent(ofDragInfo dragInfo);
+ void gotMessage(ofMessage msg);
+
+ float cam_angle;
+
+ ofRay ray;
+ ofPlane plane;
+ ofProjector projector;
+
+ ofVec3f pos;
+
+};
+