Skip to content

Commit

Permalink
added a working update for camera
Browse files Browse the repository at this point in the history
  • Loading branch information
abdelrahim-hentabli committed May 19, 2024
1 parent be1054d commit 870017e
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion include/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Camera {
int j = pixel_index[1];
colors[j * number_pixels[0] + i] = color;
}
void Update(float deltaT);
void Update(double deltaT);

};
#endif
2 changes: 1 addition & 1 deletion include/objects/mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Mesh : public Object {
bool Intersect_Triangle(const Ray &ray, int tri, double &dist) const;
void Read_Obj(const char *file);
Box Bounding_Box(int part) const override;
void Update(float deltaT) override;
void Update(double deltaT) override;

};

Expand Down
2 changes: 1 addition & 1 deletion include/objects/object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Object {
// If part>=0, return the bounding box for the specified part.
// If part<0, return the bounding box for the whole object.
virtual Box Bounding_Box(int part) const = 0;
virtual void Update(float deltaT) = 0;
virtual void Update(double deltaT) = 0;

};

Expand Down
2 changes: 1 addition & 1 deletion include/objects/plane.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Plane : public Object {
virtual Hit Intersection(const Ray &ray, int part) const override;
virtual vec3 Normal(const vec3 &point, int part) const override;
virtual Box Bounding_Box(int part) const override;
void Update(float deltaT) override;
void Update(double deltaT) override;

};

Expand Down
2 changes: 1 addition & 1 deletion include/objects/sphere.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Sphere : public Object {
virtual Hit Intersection(const Ray &ray, int part) const override;
virtual vec3 Normal(const vec3 &point, int part) const override;
virtual Box Bounding_Box(int part) const override;
void Update(float deltaT) override;
void Update(double deltaT) override;

};

Expand Down
2 changes: 1 addition & 1 deletion include/render_world.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ class Render_World {
vec3 Cast_Ray(const Ray &ray, int recursion_depth);
Hit Closest_Intersection(const Ray &ray);

void Update(float deltaT);
void Update(double deltaT);
};
#endif
5 changes: 3 additions & 2 deletions src/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ vec3 Camera::World_Position(const ivec2 &pixel_index) {
return result;
}

void Camera::Update(float deltaT) {

void Camera::Update(double deltaT) {
position += deltaT * velocity;
velocity += deltaT * acceleration;
}
2 changes: 1 addition & 1 deletion src/objects/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,6 @@ Box Mesh::Bounding_Box(int part) const {
return b;
}

void Mesh::Update(float deltaT) {
void Mesh::Update(double deltaT) {

}
2 changes: 1 addition & 1 deletion src/objects/plane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ Box Plane::Bounding_Box(int part) const {
return b;
}

void Plane::Update(float deltaT) {
void Plane::Update(double deltaT) {

}
2 changes: 1 addition & 1 deletion src/objects/sphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ Box Sphere::Bounding_Box(int part) const {
return box;
}

void Sphere::Update(float deltaT) {
void Sphere::Update(double deltaT) {

}
7 changes: 5 additions & 2 deletions src/render_world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,13 @@ void Render_World::Clear_Hierarchy() {
hierarchy.tree.clear();
}

void Render_World::Update(float deltaT) {
void Render_World::Update(double deltaT) {
if (abs(deltaT) < std::numeric_limits<double>::epsilon()) {
return;
}
camera.Update(deltaT);
for (Object *object: objects) {
object->Update(deltaT);
}
camera.Update(deltaT);
hierarchy.Update();
}
2 changes: 1 addition & 1 deletion tools/demos/image/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ int main(int argc, char **argv) {

// Parse commandline options
while (1) {
int opt = getopt(argc, argv, "s:i:m:o:x:y:h");
int opt = getopt(argc, argv, "s:i:o:x:y:h");
if (opt == -1) break;
switch (opt) {
case 's':
Expand Down

0 comments on commit 870017e

Please sign in to comment.