Commit 642265e6 by Kai Westerkamp

camera smooth

parent 8cad1c31
...@@ -35,6 +35,9 @@ Camera::~Camera() ...@@ -35,6 +35,9 @@ Camera::~Camera()
void Camera::move(glm::vec3 relative) void Camera::move(glm::vec3 relative)
{ {
if (length(relative) < 0.001f) return;
relative = normalize(relative);
glm::vec3 right = cross(direction, up); glm::vec3 right = cross(direction, up);
vec3 uplocal = cross(right, direction); vec3 uplocal = cross(right, direction);
......
...@@ -15,9 +15,14 @@ bool init(int argc, char* argv[]) { ...@@ -15,9 +15,14 @@ bool init(int argc, char* argv[]) {
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(width,height); glutInitWindowSize(width,height);
glutCreateWindow("Kinect VR Point Cloud"); glutCreateWindow("Kinect VR Point Cloud");
glutKeyboardFunc(keyPressed); glutKeyboardFunc(keyPressed);
glutIgnoreKeyRepeat(1);
glutKeyboardUpFunc(keyReleased);
glutMouseFunc(mouseButton); glutMouseFunc(mouseButton);
glutMotionFunc(mouseMove); glutMotionFunc(mouseMove);
glutDisplayFunc(draw); glutDisplayFunc(draw);
glutIdleFunc(draw); glutIdleFunc(draw);
glewInit(); glewInit();
......
...@@ -56,7 +56,7 @@ ICoordinateMapper* mapper; // Converts between depth, color, and 3d coor ...@@ -56,7 +56,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,6 +277,9 @@ void drawElementArray(drawData data, GLenum mode) { ...@@ -277,6 +277,9 @@ void drawElementArray(drawData data, GLenum mode) {
void mainRenderLoop() { void mainRenderLoop() {
steamTracking->processEvents(); steamTracking->processEvents();
mainCam.move(cameraMove);
//get controler pos //get controler pos
delete currentControlerPos; delete currentControlerPos;
currentControlerPos = steamTracking->getTransformationForDevice(1); currentControlerPos = steamTracking->getTransformationForDevice(1);
...@@ -351,22 +354,22 @@ void keyPressed(unsigned char key, int x, int y) ...@@ -351,22 +354,22 @@ void keyPressed(unsigned char key, int x, int y)
writeFile = true; writeFile = true;
break; break;
case 'w': case 'w':
mainCam.move(glm::vec3(1.0f,0.0f,0.0f)); cameraMove += (glm::vec3(1.0f,0.0f,0.0f));
break; break;
case 's': case 's':
mainCam.move(glm::vec3(-1.0f, 0.0f, 0.0f)); cameraMove += (glm::vec3(-1.0f, 0.0f, 0.0f));
break; break;
case 'a': case 'a':
mainCam.move(glm::vec3(0.0f, 0.0f, -1.0f)); cameraMove += (glm::vec3(0.0f, 0.0f, -1.0f));
break; break;
case 'd': case 'd':
mainCam.move(glm::vec3(0.0f, 0.0f, 1.0f)); cameraMove += (glm::vec3(0.0f, 0.0f, 1.0f));
break; break;
case 'q': case 'q':
mainCam.move(glm::vec3(0.0f, 1.0f, 0.0f)); cameraMove += (glm::vec3(0.0f, 1.0f, 0.0f));
break; break;
case 'e': case 'e':
mainCam.move(glm::vec3(0.0f, -1.0f, 0.0f)); cameraMove += (glm::vec3(0.0f, -1.0f, 0.0f));
break; break;
case 27: // Escape key case 27: // Escape key
exit(0); exit(0);
...@@ -379,6 +382,32 @@ void keyPressed(unsigned char key, int x, int y) ...@@ -379,6 +382,32 @@ void keyPressed(unsigned char key, int x, int y)
instantly */ instantly */
} }
void 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;
default:
break;
}
}
void mouseButton(int button, int state, int x, int y) { void mouseButton(int button, int state, int x, int y) {
lastX = x; lastX = x;
lastY = y; lastY = y;
...@@ -402,6 +431,7 @@ void captureNextFrame(vr::VREvent_t event) ...@@ -402,6 +431,7 @@ 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;
......
...@@ -8,6 +8,7 @@ const int colorheight = 1080; ...@@ -8,6 +8,7 @@ const int colorheight = 1080;
void mainRenderLoop(); void mainRenderLoop();
void keyPressed(unsigned char key, int x, int y); void keyPressed(unsigned char key, int x, int y);
void keyReleased(unsigned char key, int x, int y);
void mouseButton(int button, int state, int x, int y); void mouseButton(int button, int state, int x, int y);
void mouseMove(int x, int y); void mouseMove(int x, int y);
......
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