My Project
camera.cpp
Go to the documentation of this file.
1 #include "stdafx.h"
2 #include "../stdafx.h"
3 #include "../geometry\gmatrix.h"
4 #include "camera.h"
5 #include "cameramodification.h"
6 
8 {
9 }
10 
12 {
13  this->position = position;
14  this->target = target;
15 
16  this->right[0] = 1;
17  this->right[1] = 0;
18  this->right[2] = 0;
19  this->right[3] = 1;
20 
21  this->up[0] = 0;
22  this->up[1] = 1;
23  this->up[2] = 0;
24  this->up[3] = 1;
25 
26  this->direction = this->position - this->target;
27 
28  //this->direction[0] = 0;
29  //this->direction[1] = 0;
30  //this->direction[2] = 1;
31  //this->direction[3] = 1;
32 }
33 
35 {
36  GMatrix rotation = matrixrotation(this->right[0], this->right[1], this->right[2], angle);
37  this->up = this->up * rotation;
38  this->direction = this->direction * rotation;
39  GMatrix movement = matrixmovement(this->target[0], this->target[1], this->target[2]);
40  this->position = this->position * (-movement) * rotation * movement;
41 }
42 
44 {
45  GMatrix rotation = matrixrotation(this->up[0], this->up[1], this->up[2], angle);
46  this->right = this->right * rotation;
47  this->direction = this->direction * rotation;
48  GMatrix movement = matrixmovement(this->target[0], this->target[1], this->target[2]);
49  this->position = this->position * (-movement) * rotation * movement;
50 }
51 
53 {
54  this->direction.normalize();
55  if (this->direction == this->right || this->direction == this->right * (-1))
56  {
57  this->right = GVector::cross(this->up, this->direction).normalize();
58  this->up = GVector::cross(this->direction, this->right).normalize();
59  }
60  else
61  {
62  this->up = GVector::cross(this->direction, this->right).normalize();
63  this->right = GVector::cross(this->up, this->direction).normalize();
64  }
65  double X = -GVector::scalar(this->right, this->position);
66  double Y = -GVector::scalar(this->up, this->position);
67  double Z = -GVector::scalar(this->direction, this->position);
68 
69  GVector t(X, Y, Z, 1);
70 
71  GMatrix view;
72  for (int i = 0; i < 4; i++)
73  {
74  view[i][0] = this->right[i];
75  view[i][1] = this->up[i];
76  view[i][2] = this->direction[i];
77  view[i][3] = t[i];
78  }
79 
80  /*GVector z = (this->position - this->target).normalize();
81  GVector x = GVector::cross(this->up, z).normalize();
82  GVector y = GVector::cross(z, x).normalize();
83 
84  GMatrix Minv;
85  GMatrix Tr;
86 
87  for (int i = 0; i < 4; i++)
88  {
89  for (int j = 0; j < 4; j++)
90  if (i == j)
91  {
92  Minv[i][j] = 1;
93  Tr[i][j] = 1;
94  }
95  else
96  {
97  Minv[i][j] = 0;
98  Tr[i][j] = 0;
99  }
100  }
101 
102  for (int i = 0; i < 3; i++)
103  {
104  Minv[0][i] = x[i];
105  Minv[1][i] = y[i];
106  Minv[2][i] = z[i];
107  Tr[i][3] = (this->target[i]) * (-1);
108  }
109  GMatrix view = Minv * Tr;*/
110 
111  return view;
112 }
GVector normalize()
Definition: gvector.cpp:115
GMatrix matrixrotation(double X, double Y, double Z, double angle)
Camera object.
double angle
Definition: listener.cpp:17
Define geometric vector.
Definition: gvector.h:26
GVector target
Definition: camera.h:58
GMatrix matrixmovement(double X, double Y, double Z)
GVector position
Definition: camera.h:57
GMatrix cameraview()
Definition: camera.cpp:52
Camera()
Definition: camera.cpp:7
void rotateHorizontalSphere(double angle)
Definition: camera.cpp:34
static GVector cross(GVector first, GVector second)
Definition: gvector.cpp:132
Modidy camera.
void rotateVerticalSphere(double angle)
Definition: camera.cpp:43
static double scalar(GVector first, GVector second)
Definition: gvector.cpp:143
Define geometric matrix.
Definition: gmatrix.h:24