summaryrefslogtreecommitdiff
path: root/rayhit/src
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2012-03-22 17:44:49 +0000
committerTim Redfern <tim@eclectronics.org>2012-03-22 17:44:49 +0000
commit3badbcdf8d8a0005543521849694fa481dfce628 (patch)
tree8c8102e95b4b5c687e477057c8813f83f3d67190 /rayhit/src
parentb7e30249fc262d6f0b018417934f6cf13e924240 (diff)
ray hit working
Diffstat (limited to 'rayhit/src')
-rw-r--r--rayhit/src/testApp.cpp84
-rw-r--r--rayhit/src/testApp.h8
2 files changed, 66 insertions, 26 deletions
diff --git a/rayhit/src/testApp.cpp b/rayhit/src/testApp.cpp
index 750287c..78a3890 100644
--- a/rayhit/src/testApp.cpp
+++ b/rayhit/src/testApp.cpp
@@ -2,19 +2,34 @@
//--------------------------------------------------------------
void testApp::setup(){
- ofVec3f centre=ofVec3f(ofGetWidth()/2,ofGetHeight(),0);
- ofVec3f normal=ofVec3f(0,0,1);
+ ofVec3f centre=ofVec3f(ofGetWidth()/2,0,0);
+ ofVec3f normal=ofVec3f(0,0,-1);
ray=ofRay();
plane=ofPlane(centre,normal);
-
- projector=ofProjector(ofGetWidth(),ofGetHeight());
-
+ plane.color=ofColor(255,255,255);
+
+ //Projector::Projector(float throwRatio, const ofVec2f& lensOffset, int width, int height)
+ projector=ofProjector(1.535f, ofVec2f(0.0f, 0.5f),ofGetWidth(),ofGetHeight());
+ projector.setPosition(ofGetWidth()/2,ofGetHeight()/2,ofGetHeight());
+
pos=ofVec3f(ofGetWidth()/2,ofGetHeight()/2,0);
+
+ cam=ofCamera();
+ //cam defaults to (0,0,0);
+ cam.setPosition(ofGetWidth()/2,ofGetHeight()/2,ofGetHeight());
+ //cam.setOrientation(ofVec3f(0,0,1));
+ cam.lookAt(ofVec3f(ofGetWidth()/2,ofGetHeight()/2,0));
+ cam.setFov(54.13);
+ //ofVec3f campoint=cam.getLookAtDir();
+ //printf("camera at %f,%f,%f looking %f,%f,%f\n",cam.getX(),cam.getY(),cam.getZ(),campoint.x,campoint.y,campoint.z);
+ cam_angle=0;
+
+ //projector=ofProjector(cam.getProjectionMatrix(ofRectangle(0,0,ofGetWidth(),ofGetHeight())),ofGetWidth(),ofGetHeight());
}
//--------------------------------------------------------------
void testApp::update(){
-
+
}
@@ -22,30 +37,41 @@ void testApp::update(){
//--------------------------------------------------------------
void testApp::draw(){
ofBackground(0,0,0);
+
+ cam.begin();
+
plane.draw();
-
- float gap=ofGetHeight()-ofGetWidth();
-
+
ofPushMatrix();
- ofTranslate(0,ofGetHeight(),0);
+ //ofTranslate(0,ofGetHeight(),0);
ofRotate(cam_angle,1,0,0);
- ofTranslate(0,-ofGetHeight(),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);
+ glVertex3f(i,0,0);
+ glVertex3f(i,ofGetWidth(),0);
glEnd();
glBegin(GL_LINES);
- glVertex3f(0,i+gap,0);
- glVertex3f(ofGetWidth(),i+gap,0);
+ glVertex3f(0,i,0);
+ glVertex3f(ofGetWidth(),i,0);
glEnd();
}
-
+
ofPopMatrix();
-
- ofSphere(pos.x,pos.y,pos.z,20);
+
+ ofSphere(pos.x,pos.y,pos.z,2);
+
+ /*
+ for (int j=0;j<ofGetWidth();j+=64){
+ for (int k=0;k<ofGetHeight();k+=64){
+ ofSphere(j,k,5);
+ }
+ }
+ */
+
+ cam.end();
}
@@ -60,7 +86,9 @@ void testApp::keyPressed(int key){
cam_angle-=1;
break;
}
- plane.setNormal(ofVec3f(0,sin(cam_angle),cos(cam_angle)));
+ plane.setNormal(ofVec3f(0,sin(cam_angle*0.01745329),-cos(cam_angle*0.01745329)));
+ printf("plane normal:0,%f,%f\n",sin(cam_angle*0.01745329),-cos(cam_angle*0.01745329));
+ //degrees to radians
}
//--------------------------------------------------------------
@@ -70,7 +98,7 @@ void testApp::keyReleased(int key){
//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){
-
+
}
//--------------------------------------------------------------
@@ -84,13 +112,23 @@ void testApp::mousePressed(int x, int y, int button){
}
//--------------------------------------------------------------
+/*
+2 things appear to be wrong
+
+-angle wrong
+degrees to radians 1 thing - how to match the drawn grid
+why won't the plane draw!
+
+-in any case the ray hit should always place the sphere under the mouse
+
+*/
void testApp::mouseReleased(int x, int y, int button){
- ray=projector.castPixel(x,(ofGetHeight()-y));
+ ray=projector.castPixel(x,y+(ofGetHeight()/2)); //(ofGetHeight()-y));
bool hit = plane.intersect(ray,pos);
- pos=ofVec3f(pos.x*2,pos.y*2,pos.z*2);
+ //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);
-
+
}
//--------------------------------------------------------------
diff --git a/rayhit/src/testApp.h b/rayhit/src/testApp.h
index e5a035d..e9ec1a3 100644
--- a/rayhit/src/testApp.h
+++ b/rayhit/src/testApp.h
@@ -26,11 +26,13 @@ class testApp : public ofBaseApp{
void gotMessage(ofMessage msg);
float cam_angle;
-
+
+ ofCamera cam;
+
ofRay ray;
ofPlane plane;
- ofProjector projector;
-
+ ofProjector projector;
+
ofVec3f pos;
};