Commit f3db4192 by Kai Westerkamp

move to camera

parent 642265e6
...@@ -17,7 +17,7 @@ Camera::Camera(vec3 position) : Camera(position, vec3(0.0f, 0.0f, 0.0f)) { ...@@ -17,7 +17,7 @@ Camera::Camera(vec3 position) : Camera(position, vec3(0.0f, 0.0f, 0.0f)) {
Camera::Camera(vec3 position, vec3 lookAt) Camera::Camera(vec3 position, vec3 lookAt)
{ {
// rotation = glm::gtx::quaternion::angleAxis(degrees(45), RotationAxis); cameraMove = glm::vec3(0.0f, 0.0f, 0.0f);
this->position = position; this->position = position;
vec3 dir = normalize(lookAt -position); vec3 dir = normalize(lookAt -position);
verticalAngle = asinf(dir.y); verticalAngle = asinf(dir.y);
...@@ -63,3 +63,76 @@ void Camera::applyMatrix() ...@@ -63,3 +63,76 @@ void Camera::applyMatrix()
gluLookAt(position.x, position.y, position.z, gluLookAt(position.x, position.y, position.z,
p.x, p.y, p.z, up.x, up.y, up.z); p.x, p.y, p.z, up.x, up.y, up.z);
} }
void Camera::mouseButton(int button, int state, int x, int y) {
lastX = x;
lastY = y;
}
void Camera::mouseMove(int x, int y) {
rotate(lastX - x, lastY - y);
lastX = x;
lastY = y;
}
void Camera::keyPressed(unsigned char key, int x, int y)
{
switch (key) {
case 'w':
cameraMove += (glm::vec3(1.0f, 0.0f, 0.0f));
break;
case 's':
cameraMove += (glm::vec3(-1.0f, 0.0f, 0.0f));
break;
case 'a':
cameraMove += (glm::vec3(0.0f, 0.0f, -1.0f));
break;
case 'd':
cameraMove += (glm::vec3(0.0f, 0.0f, 1.0f));
break;
case 'q':
cameraMove += (glm::vec3(0.0f, 1.0f, 0.0f));
break;
case 'e':
cameraMove += (glm::vec3(0.0f, -1.0f, 0.0f));
break;
}
}
void Camera::keyReleased(unsigned char key, int x, int y) {
switch (key) {
case 'w':
cameraMove -= (glm::vec3(1.0f, 0.0f, 0.0f));
break;
case 's':
cameraMove -= (glm::vec3(-1.0f, 0.0f, 0.0f));
break;
case 'a':
cameraMove -= (glm::vec3(0.0f, 0.0f, -1.0f));
break;
case 'd':
cameraMove -= (glm::vec3(0.0f, 0.0f, 1.0f));
break;
case 'q':
cameraMove -= (glm::vec3(0.0f, 1.0f, 0.0f));
break;
case 'e':
cameraMove -= (glm::vec3(0.0f, -1.0f, 0.0f));
break;
}
}
void Camera::tick()
{
/*
int timeSinceStart = glutGet(GLUT_ELAPSED_TIME);
int deltaTime = timeSinceStart - oldTimeSinceStart;
oldTimeSinceStart = timeSinceStart;
*/
move(cameraMove);
}
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
class Camera class Camera
{ {
public: private:
glm::vec3 direction; glm::vec3 direction;
glm::vec3 position; glm::vec3 position;
glm::vec3 up; glm::vec3 up;
...@@ -22,13 +22,26 @@ public: ...@@ -22,13 +22,26 @@ public:
float horizontalAngle = (float) -M_PI/2; float horizontalAngle = (float) -M_PI/2;
float verticalAngle = (float) -M_PI/8; float verticalAngle = (float) -M_PI/8;
void move(glm::vec3 relative);
void rotate(int dx, int dy);
//glut tracking
glm::vec3 cameraMove;
int lastX, lastY;
public:
Camera(); Camera();
Camera(glm::vec3 position); Camera(glm::vec3 position);
Camera(glm::vec3 position, glm::vec3 lookAt); Camera(glm::vec3 position, glm::vec3 lookAt);
~Camera(); ~Camera();
void move(glm::vec3 relative); void keyPressed(unsigned char key, int x, int y);
void rotate(int dx, int dy); void keyReleased(unsigned char key, int x, int y);
void mouseButton(int button, int state, int x, int y);
void mouseMove(int x, int y);
void tick();
void applyMatrix();; void applyMatrix();;
......
...@@ -47,7 +47,6 @@ bool frameValidPoints[width*height]; ...@@ -47,7 +47,6 @@ bool frameValidPoints[width*height];
std::vector<glm::vec3> points; std::vector<glm::vec3> points;
std::vector<unsigned char> colors; std::vector<unsigned char> colors;
// Kinect Variables // Kinect Variables
IKinectSensor* sensor; // Kinect sensor IKinectSensor* sensor; // Kinect sensor
IMultiSourceFrameReader* reader; // Kinect data source IMultiSourceFrameReader* reader; // Kinect data source
...@@ -56,7 +55,7 @@ ICoordinateMapper* mapper; // Converts between depth, color, and 3d coor ...@@ -56,7 +55,7 @@ ICoordinateMapper* mapper; // Converts between depth, color, and 3d coor
SteamTracking* steamTracking = nullptr; SteamTracking* steamTracking = nullptr;
glm::mat4x4* currentControlerPos = nullptr; glm::mat4x4* currentControlerPos = nullptr;
Camera mainCam; Camera mainCam;
glm::vec3 cameraMove;
static bool writeFile = false; static bool writeFile = false;
static bool captureFrame = false; static bool captureFrame = false;
...@@ -277,7 +276,7 @@ void drawElementArray(drawData data, GLenum mode) { ...@@ -277,7 +276,7 @@ void drawElementArray(drawData data, GLenum mode) {
void mainRenderLoop() { void mainRenderLoop() {
steamTracking->processEvents(); steamTracking->processEvents();
mainCam.move(cameraMove); mainCam.tick();
//get controler pos //get controler pos
...@@ -344,6 +343,7 @@ void mainRenderLoop() { ...@@ -344,6 +343,7 @@ void mainRenderLoop() {
void keyPressed(unsigned char key, int x, int y) void keyPressed(unsigned char key, int x, int y)
{ {
mainCam.keyPressed(key, x, y);
switch (key) { switch (key) {
case 'y': case 'y':
std::cout << "Capturing Frame Keyboard"<< std::endl; std::cout << "Capturing Frame Keyboard"<< std::endl;
...@@ -353,24 +353,6 @@ void keyPressed(unsigned char key, int x, int y) ...@@ -353,24 +353,6 @@ void keyPressed(unsigned char key, int x, int y)
std::cout << "writing File" << std::endl; std::cout << "writing File" << std::endl;
writeFile = true; writeFile = true;
break; break;
case 'w':
cameraMove += (glm::vec3(1.0f,0.0f,0.0f));
break;
case 's':
cameraMove += (glm::vec3(-1.0f, 0.0f, 0.0f));
break;
case 'a':
cameraMove += (glm::vec3(0.0f, 0.0f, -1.0f));
break;
case 'd':
cameraMove += (glm::vec3(0.0f, 0.0f, 1.0f));
break;
case 'q':
cameraMove += (glm::vec3(0.0f, 1.0f, 0.0f));
break;
case 'e':
cameraMove += (glm::vec3(0.0f, -1.0f, 0.0f));
break;
case 27: // Escape key case 27: // Escape key
exit(0); exit(0);
break; break;
...@@ -383,42 +365,15 @@ void keyPressed(unsigned char key, int x, int y) ...@@ -383,42 +365,15 @@ void keyPressed(unsigned char key, int x, int y)
} }
void keyReleased(unsigned char key, int x, int y) { void keyReleased(unsigned char key, int x, int y) {
switch (key) { mainCam.keyReleased(key, x, y);
case 'w':
cameraMove -= (glm::vec3(1.0f, 0.0f, 0.0f));
break;
case 's':
cameraMove -= (glm::vec3(-1.0f, 0.0f, 0.0f));
break;
case 'a':
cameraMove -= (glm::vec3(0.0f, 0.0f, -1.0f));
break;
case 'd':
cameraMove -= (glm::vec3(0.0f, 0.0f, 1.0f));
break;
case 'q':
cameraMove -= (glm::vec3(0.0f, 1.0f, 0.0f));
break;
case 'e':
cameraMove -= (glm::vec3(0.0f, -1.0f, 0.0f));
break;
default:
break;
}
} }
void mouseButton(int button, int state, int x, int y) { void mouseButton(int button, int state, int x, int y) {
lastX = x; mainCam.mouseButton(button, state, x, y);
lastY = y;
} }
void mouseMove(int x, int y) { void mouseMove(int x, int y) {
mainCam.rotate(lastX-x, lastY-y); mainCam.mouseMove(x, y);
lastX = x;
lastY = y;
} }
void captureNextFrame(vr::VREvent_t event) void captureNextFrame(vr::VREvent_t event)
...@@ -431,7 +386,6 @@ void captureNextFrame(vr::VREvent_t event) ...@@ -431,7 +386,6 @@ void captureNextFrame(vr::VREvent_t event)
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
cameraMove = glm::vec3(0.0f, 0.0f, 0.0f);
std::cout << "Starting Kinect VR Point Cloud creator\n"; std::cout << "Starting Kinect VR Point Cloud creator\n";
if (!init(argc, argv)) return 1; if (!init(argc, argv)) return 1;
if (!initKinect()) return 1; if (!initKinect()) return 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment