Skip to content

Commit

Permalink
feat: rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
JulioJPinto committed Mar 4, 2024
1 parent 6752039 commit 260f466
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions engine/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
#include "draw.hpp"
#include "parse.hpp"

float cameraAngle = 90.0f;
float cameraAngle = 0.0f;
float cameraAngleY = 0.0f;

Configuration c;

void reshape(int w, int h) {
float aspect_ratio = (float)w / (float)h;

Expand All @@ -28,26 +29,28 @@ void reshape(int w, int h) {
// Reset the modelview matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

}

void drawAxis(void) {

glBegin(GL_LINES);
// x-axis (red)
glColor3f(50.0f, 0.0f, 0.0f);
glVertex3f(-50.0f, 0.0f, 0.0f);
glVertex3f(50.0f, 0.0f, 0.0f);
glVertex3f(-500.0f, 0.0f, 0.0f);
glVertex3f(500.0f, 0.0f, 0.0f);
// y-axis (green)
glColor3f(0.0f, 50.0f, 0.0f);
glVertex3f(0.0f, -50.0f, 0.0f);
glVertex3f(0.0f, 50.0f, 0.0f);
glVertex3f(0.0f, -500.0f, 0.0f);
glVertex3f(0.0f, 500.0f, 0.0f);
// z-axis (blue)
glColor3f(0.0f, 0.0f, 50.0f);
glVertex3f(0.0f, 0.0f, -50.0f);
glVertex3f(0.0f, 0.0f, 50.0f);
glVertex3f(0.0f, 0.0f, -500.0f);
glVertex3f(0.0f, 0.0f, 500.0f);
glEnd();

}

void renderScene(void) {
// clear buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Expand All @@ -58,10 +61,12 @@ void renderScene(void) {
c.camera.lookAt.x, c.camera.lookAt.y, c.camera.lookAt.z,
c.camera.up.x, c.camera.up.y, c.camera.up.z);

glRotatef(cameraAngleY, 0.0f, 1.0f, 0.0f);
glRotatef(cameraAngle, 1.0f, 0.0f, 0.0f);
// put drawing instructions here
drawAxis();

glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glPolygonMode(GL_FRONT, GL_LINE);
for (std::string model : c.models) {
drawFile(model.data());
}
Expand All @@ -73,16 +78,16 @@ void renderScene(void) {
void processSpecialKeys(int key, int xx, int yy) {
switch (key) {
case GLUT_KEY_LEFT:
cameraAngle -= 0.1f;
cameraAngle -= 1.0f;
break;
case GLUT_KEY_RIGHT:
cameraAngle += 0.1f;
cameraAngle += 1.0f;
break;
case GLUT_KEY_UP:
cameraAngleY += 0.1f;
cameraAngleY += 1.0f;
break;
case GLUT_KEY_DOWN:
cameraAngleY -= 0.1f;
cameraAngleY -= 1.0f;
break;
default:
break;
Expand Down

0 comments on commit 260f466

Please sign in to comment.