-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcameraFirst.cpp
More file actions
136 lines (99 loc) · 2.8 KB
/
cameraFirst.cpp
File metadata and controls
136 lines (99 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include "cameraFirst.h"
#include <QtOpenGL/qgl.h>
#include <GL/glu.h>
cameraFirst::cameraFirst() { }
cameraFirst::cameraFirst(ObjectInstance* viewer) : viewer(viewer) { }
void cameraFirst::computeDefaultCamera(double radi, const Point& centreEscena)
{
//VRP = Point(viewer->pos.x, 0, viewer->pos.z);
//this->radi = radi;
//dist = 2*radi;
//TODO: BEFORE THIS, HAVE TO LOOK AND CLEAN
anterior = 2.;
posterior = 2*radi+5;
zoom=0;
anglecam=90;
Box b = viewer -> getTransformedBox();
altura = (b.maxb.y);
if(altura < 0) altura *= -1;
angleY=0;
angleX=0;
}
void cameraFirst::setModelview()
{
glMatrixMode(GL_MODELVIEW); //Modifiquem matriu ModelView (Camera)
glLoadIdentity(); //Coloquem camera a l'origent (punt per defecte)
int n = 4;
float orien = viewer->getOrientation();
float orienX = viewer->getOrienX();
//VRP en la posicio mitja del dofi
VRP.x=viewer->pos.x-n*(-sin(angle2rad(orien)))*(-cos(angle2rad(orienX+90)));
VRP.y=viewer->pos.y-n*(-cos(angle2rad(orienX)));
VRP.z=viewer->pos.z-n*(-cos(angle2rad(orien)))*(-cos(angle2rad(orienX+90)));
//lookat amb la direccio de visio del dofi
double lookAtX = viewer->pos.x-(n+1)*sin(angle2rad(orien+angleX));
double lookAtY = viewer->pos.y-(n+1)*cos(angle2rad(180+orienX+angleY));
double lookAtZ = viewer->pos.z-(n+1)*cos(angle2rad(orien+angleX));
gluLookAt(VRP.x, VRP.y, VRP.z,
lookAtX, lookAtY, lookAtZ,
0, 1, 0); // UP vector
}
void cameraFirst::setProjection(int width, int height)
{
float aspect=float(width)/float(height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(anglecam,aspect,anterior,posterior);
}
void cameraFirst::resetOrientation() {
angleX=0;
}
void cameraFirst::resetCam()
{
angleY=viewer->orienX+90;
this->resetOrientation();
anglecam = 90;
}
void cameraFirst::userRotate(double anglex, double angley) {
//distancia en x = rotacio sobre l'eix y, i a l'inreves
angleY = angleY + angley;
angleX = angleX + anglex;
this->setModelview();
}
void cameraFirst::userZoom(double zoom) {
anglecam = anglecam + zoom;
if(anglecam<1) anglecam = 1;
if(anglecam>100) anglecam = 100;
this->setModelview();
}
void cameraFirst::iniciTGModelat()
{
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
}
void cameraFirst::identitat()
{
glLoadIdentity();
}
void cameraFirst::fiTGModelat()
{
glPopMatrix();
}
void cameraFirst::trasllada(float tx, float ty, float tz)
{
glTranslatef(tx, ty, tz);
}
void cameraFirst::escala(float sx, float sy, float sz)
{
glScalef(sx, sy, sz);
}
void cameraFirst::rota(float graus, float rx, float ry, float rz)
{
glRotatef(graus, rx, ry, rz);
}
double cameraFirst::rad2angle(double rad) {
return (rad * 180 / M_PI);
}
double cameraFirst::angle2rad(double angle) {
return (angle * M_PI / 180);
}