Skip to content

Commit 0599c08

Browse files
committed
S13 - rotation
1 parent bef8941 commit 0599c08

File tree

2 files changed

+12
-21
lines changed

2 files changed

+12
-21
lines changed

s13_casa/house.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,9 @@ void House::draw() {
387387
// save origina matrix
388388
glm::mat4 ori{modelview};
389389

390-
glTranslatef(_translationX, _translationY, _translationZ);
391-
glRotatef(_rotationX, 0.0f, 1.0f, 0.0f);
390+
modelview = glm::translate(modelview, glm::vec3(-_translationX, _translationY, _translationZ));
391+
modelview = glm::rotate(modelview, _rotationX, glm::vec3(0.0f, 1.0f, 0.0f));
392+
glUniformMatrix4fv(modelviewPos, 1, GL_FALSE, &modelview[0][0]);
392393

393394
drawFloor();
394395
drawLateralWalls();

s13_casa/main.cpp

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,14 @@
3434

3535
#define MNU_SAVE_BMP 17
3636
#define MNU_TOGGLE_CLIPPLANE 16
37-
#define MNU_LIGHT_POS_2REL 15
38-
#define MNU_LIGHT_POS_1REL 14
39-
#define MNU_LIGHT_POS_2ABS 13
40-
#define MNU_TOGGLE_LIGHT2 12
41-
#define MNU_TOGGLE_LIGHT1 11
4237
#define MNU_RESET 10
43-
#define MNU_ORTHO 9
44-
#define MNU_PERSPECTIVE 8
45-
#define MNU_TOGGLE_WIND 7
46-
#define MNU_CHANGE_COLOR 6
4738
#define MNU_OPENCLOSE_DOOR 5
4839
#define MNU_STOP_HOUSE_ROTATION 4
4940
#define MNU_START_HOUSE_ROTATION 3
50-
#define MNU_TOGGLE_WIREFRAME 2
51-
#define MNU_TOGGLE_AXIS 1
52-
#define PROJ_ORTHOGRAPHIC 'a'
53-
#define PROJ_PERSPECTIVE 'p'
5441

5542
const int WINDOW_WIDTH = 800;
5643
const int WINDOW_HEIGHT = 600;
57-
const int ANIM_MSEC = 50;
44+
const int ANIM_MSEC = 10;
5845
const int WIND_MSEC = 5000;
5946
const char ESCAPE = 27;
6047

@@ -66,7 +53,7 @@ struct AppGlobals {
6653
// global variables
6754
GLfloat windAngle = 0.0;
6855
int mainWindowID = 0;
69-
GLfloat fovy = 30;
56+
GLfloat fovy = 45;
7057

7158
Texture texture;
7259

@@ -93,7 +80,6 @@ void displayCallback() {
9380
// draw house
9481
_app->house.draw();
9582

96-
9783
glClipPlane (GL_CLIP_PLANE0, _app->clip_plane_0);
9884
glutSwapBuffers();
9985
}
@@ -116,10 +102,14 @@ void animationCallback(int value) {
116102

117103
void reshapeCallback(int w, int h) {
118104
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
105+
reshape(w, h);
106+
}
107+
108+
void reshape(int w, int h) {
119109
GLfloat aspect = (GLfloat)w/(h==0 ? 1.0 : h);
120110
// Imposta la matrice di proiezione di tipo prospettica
121111
// notare che l'angolo va passato in radianti
122-
_app->projection = glm::perspective(_app->fovy / 180.0f * glm::pi<float>(), aspect, 1.0f, 10.0f);
112+
_app->projection = glm::perspective(_app->fovy / 180.0f * glm::pi<float>(), aspect, 1.0f, 100.0f);
123113
glUniformMatrix4fv(_app->projectionPos, 1, GL_FALSE, &_app->projection[0][0]);
124114
}
125115

@@ -176,12 +166,12 @@ void specialKeyCallback(int key, int x, int y) {
176166
case GLUT_KEY_F9:
177167
_app->fovy -= 1;
178168
log("fovy=" + std::to_string(_app->fovy));
179-
//TODO reshape(glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));
169+
reshape(glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));
180170
break;
181171
case GLUT_KEY_F10:
182172
_app->fovy += 1;
183173
log("fovy=" + std::to_string(_app->fovy));
184-
//TODO reshape(glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));
174+
reshape(glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));
185175
break;
186176

187177
case GLUT_KEY_PAGE_DOWN:

0 commit comments

Comments
 (0)