Skip to content

Commit

Permalink
orbital mode
Browse files Browse the repository at this point in the history
  • Loading branch information
JulioJPinto committed May 25, 2024
1 parent b85232a commit af33f9c
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 14 deletions.
14 changes: 14 additions & 0 deletions engine/include/Camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ class Camera {
void forwardMovement();
void backwardMovement();

private:
void backwardMovementFPS();
void backwardMovementOrbital();
void forwardMovementFPS();
void forwardMovementOrbital();
void leftMovementFPS();
void leftMovementOrbital();
void rightMovementFPS();
void rightMovementOrbital();
void upMovementFPS();
void upMovementOrbital();
void downMovementFPS();
void downMovementOrbital();

// std::string toString();
};

Expand Down
100 changes: 94 additions & 6 deletions engine/src/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Camera::Camera() {
this->fov = 0;
this->near = 0;
this->far = 0;
this->type = FPS;
}

Camera::Camera(glm::vec3 position, glm::vec3 lookAt, glm::vec3 up, int fov, float near,
Expand All @@ -25,6 +26,8 @@ Camera::Camera(glm::vec3 position, glm::vec3 lookAt, glm::vec3 up, int fov, floa
this->fov = fov;
this->near = near;
this->far = far;

this->type = FPS;
}


Expand All @@ -38,46 +41,131 @@ Camera::Camera(const Camera& other) {
this->far = other.far;
}

void Camera::backwardMovement() {
void Camera::backwardMovementFPS() {
glm::vec3 direction = glm::normalize(lookAt - position);
position += direction;
lookAt += direction;
}

void Camera::forwardMovement() {
void Camera::backwardMovementOrbital() {
glm::vec3 direction = glm::normalize(lookAt - position);
position += direction;
}

void Camera::backwardMovement() {
if(type == FPS) {
backwardMovementFPS();
} else {
backwardMovementOrbital();
}
}

void Camera::forwardMovementFPS() {
glm::vec3 direction = glm::normalize(lookAt - position);
position -= direction;
lookAt -= direction;
}

void Camera::leftMovement() {
void Camera::forwardMovementOrbital() {
glm::vec3 direction = glm::normalize(lookAt - position);
position -= direction;
}

void Camera::forwardMovement() {
if(type == FPS) {
forwardMovementFPS();
} else {
forwardMovementOrbital();
}
}

void Camera::leftMovementFPS() {
glm::vec3 direction = glm::normalize(lookAt - position);
glm::vec3 right = glm::normalize(glm::cross(up, direction));
position -= right;
lookAt -= right;
}

void Camera::rightMovement() {
void Camera::leftMovementOrbital() {
glm::vec3 direction = glm::normalize(lookAt - position);
glm::vec3 right = glm::normalize(glm::cross(up, direction));
lookAt -= right;
}

void Camera::leftMovement() {
if(type == FPS) {
leftMovementFPS();
} else {
leftMovementOrbital();
}
}

void Camera::rightMovementFPS() {
glm::vec3 direction = glm::normalize(lookAt - position);
glm::vec3 right = glm::normalize(glm::cross(up, direction));
position += right;
lookAt += right;
}

void Camera::upMovement() {
void Camera::rightMovementOrbital() {
glm::vec3 direction = glm::normalize(lookAt - position);
glm::vec3 right = glm::normalize(glm::cross(up, direction));
lookAt += right;
}

void Camera::rightMovement() {
if(type == FPS) {
rightMovementFPS();
} else {
rightMovementOrbital();
}
}

void Camera::upMovementFPS() {
glm::vec3 direction = glm::normalize(lookAt - position);
glm::vec3 right = glm::normalize(glm::cross(up, direction));
glm::vec3 up = glm::normalize(glm::cross(direction, right));
position += up;
lookAt += up;
}

void Camera::downMovement() {
void Camera::upMovementOrbital() {
glm::vec3 direction = glm::normalize(lookAt - position);
glm::vec3 right = glm::normalize(glm::cross(up, direction));
glm::vec3 up = glm::normalize(glm::cross(direction, right));
lookAt += up;
}

void Camera::upMovement() {
if(type == FPS) {
upMovementFPS();
} else {
upMovementOrbital();
}
}

void Camera::downMovementFPS() {
glm::vec3 direction = glm::normalize(lookAt - position);
glm::vec3 right = glm::normalize(glm::cross(up, direction));
glm::vec3 up = glm::normalize(glm::cross(direction, right));
position -= up;
lookAt -= up;
}

void Camera::downMovementOrbital() {
glm::vec3 direction = glm::normalize(lookAt - position);
glm::vec3 right = glm::normalize(glm::cross(up, direction));
glm::vec3 up = glm::normalize(glm::cross(direction, right));
lookAt -= up;
}

void Camera::downMovement() {
if(type == FPS) {
downMovementFPS();
} else {
downMovementOrbital();

}
}


1 change: 0 additions & 1 deletion engine/src/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ void Group::drawGroup(bool lights, const Frustsum& frustsum) {
}

if(model.bounding_sphere.isInsideFrustsum(frustsum, matrix)) {
std::cout << model.filename << std::endl;
model.drawModel();
}
}
Expand Down
18 changes: 11 additions & 7 deletions engine/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,20 @@ void processNormalKeys(unsigned char key, int x, int y) {
}
break;
case 'r':
cameraAngle = 0;
cameraAngleY = 0;
zoom = 1.0f;
camera = c.camera;
break;
case 'o':
zoom -= value;
case 'w':
camera.upMovement();
break;
case 'i':
zoom += value;
case 's':
camera.downMovement();
break;
case 't':
if(camera.type == ORBITAL) {
camera.type = FPS;
} else {
camera.type = ORBITAL;
}
case 'c':
if (wireframe) {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
Expand Down

0 comments on commit af33f9c

Please sign in to comment.