Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment #6 #3

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
**Dealine**: 6.12.2020

Please put your name here:
**Name:** .......

*SHROROUK G. AWWAD*
## Problem 1
### Shearing Transform (Points 10 + 10)
Now the framework includes the **Tranform.h** file which contains the ```CTransform``` class. This class implements most of the affine transormations discussed at the lectures (when studying the class please pay extra attention to the rotation transoform). The main goal of this class is to deliver the transformation matrix with ```CTransform::get()```. Within this problem we will implement shear transform. Proceed as follows:
Expand Down
Binary file added rendered_img/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 12 additions & 1 deletion src/CameraPerspective.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,18 @@ class CCameraPerspective : public ICamera
virtual ~CCameraPerspective(void) = default;

// --- PUT YOUR CODE HERE ---

virtual void setPosition(const Vec3f& NewPos) { m_pos = NewPos; }

Vec3f getPosition(void) const { return m_pos; }

virtual void setDirection(const Vec3f& NewDir) { m_dir = NewDir; }

Vec3f getDirection(void) const { return m_dir; }

virtual void setAngle(float NewAngle) { m_focus = 1.0f / tanf(NewAngle * Pif / 360); }

float getAngle(void) const { return (360 / Pif) * atan(1 / m_focus); }

virtual void InitRay(Ray& ray, int x, int y, const Vec2f& sample = Vec2f::all(0.5f)) override
{
float dx = sample[0]; // x-shift to the center of the pixel
Expand Down
12 changes: 10 additions & 2 deletions src/CameraTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@
class CCameraTarget : public CCameraPerspective {
public:
// --- PUT YOUR CODE HERE ---
//CCameraTarget(Size resolution, const Vec3f& pos, const Vec3f& target, const Vec3f& up, float angle) ...

CCameraTarget(Size resolution, const Vec3f& pos, const Vec3f& target, const Vec3f& up, float angle) : CCameraPerspective(resolution, pos, normalize(target - pos), up, angle)
{
m_target = target;
}

// virtual void setPosition(const Vec3f& pos) override { pos = m_target; }

virtual void setTarget(const Vec3f& target) { m_target = target; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to update direction also here


Vec3f getTarget(void) const { return m_target; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to override method setPosition() because it affects direction of the target camera

private:
Vec3f m_target; ///< Camera target point in WCS
}
17 changes: 17 additions & 0 deletions src/Transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,23 @@ class CTransform {
}

// --- PUT YOUR CODE HERE ---
//inspired from the class tutoial
CTransform shear(float h_xy, float h_xz, float h_yx, float h_yz, float h_zx, float h_zy) const {
Mat t = Mat::eye(4, 4, CV_32FC1);
t.at<float>(0, 0) = 1;
t.at<float>(0, 1) = h_xy;
t.at<float>(0, 2) = h_xz;

t.at<float>(1, 0) = h_yx;
t.at<float>(1, 1) = 1;
t.at<float>(1, 2) = h_yz;

t.at<float>(2, 0) = h_zx;
t.at<float>(2, 1) = h_zy;
t.at<float>(2, 2) = 1;

return CTransform(t * m_t);
}

/**
* @brief Adds rotation around axis \b v by angle \b theta
Expand Down
15 changes: 8 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,8 @@ Mat RenderFrame(void)
scene.add(cam1);
scene.add(cam2);

#ifdef WIN32
const std::string dataPath = "../data/";
#else
const std::string dataPath = "../../../data/";
#endif


// Textures
Mat imgEarth = imread(dataPath + "earth_8k.jpg");
Expand Down Expand Up @@ -99,8 +96,10 @@ Mat RenderFrame(void)

// --- PUT YOUR CODE HERE ---
// derive the transormation matrices here
Mat earthTransform = Mat::eye(4, 4, CV_32FC1);
Mat moonTransform = Mat::eye(4, 4, CV_32FC1);

CTransform T;
Mat earthTransform = transform.rotate(Vec3f(0.399f, 0.917, 0), 360.0f / nFrames).get();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From where did you take these numbers? What does they mean?

Mat moonTransform = transform.rotate(Vec3f(0, 1, 0), 13.2f / nFrames).get();

for (size_t frame = 0; frame < nFrames; frame++) {
// Build BSPTree
Expand All @@ -127,8 +126,10 @@ Mat RenderFrame(void)

// --- PUT YOUR CODE HERE ---
// Apply transforms here
Mat rotationAroundTheSun = Mat::eye(4, 4, CV_32FC1);
Vec3f earthPivot = earth.getPivot();
Mat rotationAroundTheSun = transform.translate(earthPivot).rotate(Vec3f(0, 1, 0), 1.0f / nFrames).translate(-earthPivot).get();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does 1.0f / nFrames mean? How did you achieve this formula?

earth.transform(rotationAroundTheSun * earthTransform);
moon.setPivot(earth.getPivot());
moon.transform(rotationAroundTheSun * moonTransform);

// --- PUT YOUR CODE HERE ---
Expand Down