summaryrefslogtreecommitdiff
path: root/rayhit/src/testApp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rayhit/src/testApp.cpp')
-rw-r--r--rayhit/src/testApp.cpp109
1 files changed, 109 insertions, 0 deletions
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){
+
+}