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)) {
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;
vec3 dir = normalize(lookAt -position);
verticalAngle = asinf(dir.y);
......@@ -63,3 +63,76 @@ void Camera::applyMatrix()
gluLookAt(position.x, position.y, position.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 @@
class Camera
{
public:
private:
glm::vec3 direction;
glm::vec3 position;
glm::vec3 up;
......@@ -22,13 +22,26 @@ public:
float horizontalAngle = (float) -M_PI/2;
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(glm::vec3 position);
Camera(glm::vec3 position, glm::vec3 lookAt);
~Camera();
void move(glm::vec3 relative);
void rotate(int dx, int dy);
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 mouseMove(int x, int y);
void tick();
void applyMatrix();;
......
......@@ -47,7 +47,6 @@ bool frameValidPoints[width*height];
std::vector<glm::vec3> points;
std::vector<unsigned char> colors;
// Kinect Variables
IKinectSensor* sensor; // Kinect sensor
IMultiSourceFrameReader* reader; // Kinect data source
......@@ -56,7 +55,7 @@ ICoordinateMapper* mapper; // Converts between depth, color, and 3d coor
SteamTracking* steamTracking = nullptr;
glm::mat4x4* currentControlerPos = nullptr;
Camera mainCam;
glm::vec3 cameraMove;
static bool writeFile = false;
static bool captureFrame = false;
......@@ -277,7 +276,7 @@ void drawElementArray(drawData data, GLenum mode) {
void mainRenderLoop() {
steamTracking->processEvents();
mainCam.move(cameraMove);
mainCam.tick();
//get controler pos
......@@ -344,6 +343,7 @@ void mainRenderLoop() {
void keyPressed(unsigned char key, int x, int y)
{
mainCam.keyPressed(key, x, y);
switch (key) {
case 'y':
std::cout << "Capturing Frame Keyboard"<< std::endl;
......@@ -353,24 +353,6 @@ void keyPressed(unsigned char key, int x, int y)
std::cout << "writing File" << std::endl;
writeFile = true;
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
exit(0);
break;
......@@ -383,42 +365,15 @@ void keyPressed(unsigned char key, int x, int y)
}
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;
}
mainCam.keyReleased(key, x, y);
}
void mouseButton(int button, int state, int x, int y) {
lastX = x;
lastY = y;
mainCam.mouseButton(button, state, x, y);
}
void mouseMove(int x, int y) {
mainCam.rotate(lastX-x, lastY-y);
lastX = x;
lastY = y;
mainCam.mouseMove(x, y);
}
void captureNextFrame(vr::VREvent_t event)
......@@ -431,7 +386,6 @@ void captureNextFrame(vr::VREvent_t event)
int main(int argc, char* argv[]) {
cameraMove = glm::vec3(0.0f, 0.0f, 0.0f);
std::cout << "Starting Kinect VR Point Cloud creator\n";
if (!init(argc, argv)) 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