Skip to content

Commit a4ace9d

Browse files
committed
Added most of the files
1 parent b8393ee commit a4ace9d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3286
-0
lines changed

Diff for: Camera.cpp

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include "Camera.h"
2+
#include "Vector.h"
3+
#include "Vector.cpp" //TODO: something weird with linkage, needs to be fixed 3
4+
#include <GL/glu.h>
5+
#include "Math.h"
6+
7+
void Camera::orient(bool translate) const
8+
{
9+
glLoadIdentity();
10+
Point3f eye = position + forward;
11+
gluLookAt(position.getX(), position.getY(), position.getZ(), eye.getX(), eye.getY(), eye.getZ(), up.getX(), up.getY(), up.getZ());
12+
13+
if (!translate)
14+
{
15+
float mat[16];
16+
glGetFloatv(GL_MODELVIEW_MATRIX, mat);
17+
mat[12] = 0.0;
18+
mat[13] = 0.0;
19+
mat[14] = 0.0;
20+
glLoadMatrixf(mat);
21+
}
22+
}
23+
24+
void Camera::rotateX(GLfloat rot)
25+
{
26+
up = dcos(rot) * up + dcos(rot + 90.0) * forward;
27+
up.normalize();
28+
forward = dcos(90.0 - rot) * up + dcos(rot) * forward;
29+
forward.normalize();
30+
}
31+
32+
void Camera::rotateY(GLfloat rot) // counter-clockwise
33+
{
34+
right = dcos(rot) * right + dcos(rot + 90.0) * forward;
35+
right.normalize();
36+
forward = dcos(90.0 - rot) * right + dcos(rot) * forward;
37+
forward.normalize();
38+
}
39+
40+
void Camera::rotateZ(GLfloat rot)
41+
{
42+
right = dcos(rot) * right + dcos(rot + 90.0) * up;
43+
right.normalize();
44+
up = dcos(90.0 - rot) * right + dcos(rot) * up;
45+
up.normalize();
46+
}
47+
48+
void Camera::lookAt(const Point3f &p) //TODO: check to see if this works 8
49+
{
50+
forward = p - position;
51+
forward.normalize();
52+
Vector3f projection = forward;
53+
projection.setY(0.0);
54+
projection.normalize();
55+
Vector3f y_axis(0.0, 1.0, 0.0);
56+
right = -projection.cross(y_axis);
57+
right.normalize();
58+
up = forward.cross(right);
59+
up.normalize();
60+
}

Diff for: Camera.h

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#ifndef CAMERA_H
2+
#define CAMERA_H
3+
#include <GL/gl.h>
4+
#include "Vector.h"
5+
#include "Point.h"
6+
#include "Point.cpp" //TODO: fix this 3
7+
8+
class Camera
9+
{
10+
private:
11+
Point3f position;
12+
Vector3f up, forward, right;
13+
public:
14+
Camera(const Point3f &p = Point3f(0.0, 0.0, 0.0)) : position(p), up(0.0, 1.0, 0.0), forward(0.0, 0.0, -1.0), right(1.0, 0.0, 0.0) { }
15+
16+
void orient(bool translate = true) const;
17+
18+
void orientBefore() const
19+
{
20+
orient(false);
21+
}
22+
23+
void rotateX(GLfloat);
24+
void rotateY(GLfloat);
25+
void rotateZ(GLfloat);
26+
27+
void advance(GLfloat scalar)
28+
{
29+
position += forward * scalar;
30+
}
31+
32+
void moveTo(const Point3f &pos)
33+
{
34+
position = pos;
35+
}
36+
37+
void movePos(const Vector3f &vec)
38+
{
39+
position += vec;
40+
}
41+
42+
void move(const Vector3f &vec)
43+
{
44+
position += (vec.getX() * right + vec.getY() * up + vec.getZ() * forward);
45+
}
46+
47+
void lookAt(const Point3f &);
48+
49+
Point3f getPos() const
50+
{
51+
return position;
52+
}
53+
54+
Vector3f getUp() const
55+
{
56+
return up;
57+
}
58+
59+
void setUp(const Vector3f &_up)
60+
{
61+
up = _up;
62+
}
63+
64+
Vector3f getForward() const
65+
{
66+
return forward;
67+
}
68+
69+
void setForward(const Vector3f &_forward)
70+
{
71+
forward = _forward;
72+
}
73+
74+
Vector3f getRight() const
75+
{
76+
return right;
77+
}
78+
79+
void setRight(const Vector3f &_right)
80+
{
81+
right = _right;
82+
}
83+
84+
bool operator==(const Camera &cam) const
85+
{
86+
return (position == cam.position && up == cam.up && forward == cam.forward && right == cam.right);
87+
}
88+
89+
bool operator!=(const Camera &cam) const
90+
{
91+
return !(*this == cam);
92+
}
93+
};
94+
95+
#endif

0 commit comments

Comments
 (0)