1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
#include "testApp.h"
//--------------------------------------------------------------
void testApp::setup(){
ofVec3f centre=ofVec3f(ofGetWidth()/2,0,0); //ofGetHeight(),0);
ofVec3f normal=ofVec3f(0,0,-1);
ray=ofRay();
plane=ofPlane(centre,normal,normal,ofVec2f(ofGetWidth(),ofGetWidth()));
plane.color=ofColor(255,255,255);
//setup that works for a new camera. but can we match the existing camera, must be possible!
/*
projector=ofProjector(1.535f, ofVec2f(0.0f, 0.5f),ofGetWidth(),ofGetHeight());
projector.setPosition(ofGetWidth()/2,ofGetHeight()/2,ofGetHeight());
*/
//Projector::Projector(float throwRatio, const ofVec2f& lensOffset, int width, int height)
projector=ofProjector(2.0f, ofVec2f(0.0f, 0.0f),ofGetWidth(),ofGetHeight()); //1.535f
projector.setPosition(ofGetWidth()/2,ofGetHeight()/2,-ofGetWidth());
projector.lookAt(ofVec3f(ofGetWidth()/2,ofGetHeight()/2,0),ofVec3f(0, -1, 0));
pos=ofVec3f(ofGetWidth()/2,ofGetHeight()/2,0);
cam=ofCamera();
//cam defaults to (0,0,0);
cam.setPosition(ofGetWidth()/2,ofGetHeight()/2,-ofGetWidth());
//cam.setOrientation(ofVec3f(0,0,1));
cam.lookAt(ofVec3f(ofGetWidth()/2,ofGetHeight()/2,0),ofVec3f(0, -1, 0));
cam.setFov(42.0); //39.85); //53.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(){
}
//--------------------------------------------------------------
void testApp::draw(){
ofBackground(0,0,0);
cam.begin();
plane.draw();
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,0,0);
glVertex3f(i,ofGetWidth(),0);
glEnd();
glBegin(GL_LINES);
glVertex3f(0,i,0);
glVertex3f(ofGetWidth(),i,0);
glEnd();
}
ofPopMatrix();
ofSphere(pos.x,pos.y,pos.z,20);
/*
for (int j=0;j<ofGetWidth();j+=64){
for (int k=0;k<ofGetHeight();k+=64){
ofSphere(j,k,5);
}
}
*/
cam.end();
}
//--------------------------------------------------------------
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*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
}
//--------------------------------------------------------------
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){
}
//--------------------------------------------------------------
/*
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,y); //+(ofGetHeight()/2)); //(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){
}
|