Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do i find the world position of the input pixel..language is c++ // Find the world position of the input pixel vec3 Camera:: World_Position(const

How do i find the world position of the input pixel..language is c++

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

// Find the world position of the input pixel vec3 Camera:: World_Position(const ivec2& pixel_index) { vec3 result; TODO; return result; 4 5 #include #include "vec.h" #include "misc.h" 6 typedef unsigned int Pixel; 7 8 9 10 11 12 13 inline Pixel Pixel_Color(const vec3& color) { unsigned int r=std::min(color[@],1.0) *255; unsigned int g=std::min(color[1],1.0)*255; unsigned int b=std::min(color[2],1.0)*255; return (r>24, (color>>16)&Oxff, (color>>8)&Oxff)/255.; } 19 20 21 22 23 24 25 26 27 class Camera { public: // Describes camera in space vec3 position; // camera position vec3 film_position; // where (0.0, 0.0) in the image plane is located in space vec3 look_vector; // points from the position to the focal point - normalized vec3 vertical_vector; // point up in the image plane normalized vec3 horizontal_vector; I points to the right on the image plane - normalized 28 29 30 31 32 33 34 // Describes the coordinate system of the image plane vec2 min,max; // coordinates of film corners: min = (left, bottom), max = (right, top) vec2 image_size; // physical dimensions of film vec2 pixel size; // physical dimensions of a pixel 35 36 37 38 39 40 41 // Describes the pixels of the image ivec2 number_pixels; // number of pixels: x and y direction Pixel* colors; // Pixel data; row-major order 42 Camera(); Camera(); 43 44 45 46 47 // Used for setting up camera parameters void Position_And_Aim_Camera(const vec3& position_input, const vec3& look_at_point,const vec3& pseudo_up_vector); void Focus_Camera(double focal_distance, double aspect_ratio, double field_of_view); void Set_Resolution(const ivec2& number_pixels_input); 48 49 50 51 52 53 - 54 55 // Used for determining the where pixels are vec3 World_Position(const ivec2& pixel_index); vec2 Cell_Center(const ivec2& index) const { return min+(vec2(index)+vec2(-5,.5))*pixel_size; } 56 57 58 59 60 61 // Call to set the color of a pixel void Set_Pixel(const ivec2& pixel_index,const Pixel& color) { int i=pixel_index[0]; int j=pixel_index[1]; colors[j*number_pixels[@]+i)=color; 62 63 64 65 66 67 }; #endif #include "camera.h" 1 2 3 4 5 Camera::Camera() :colors() 6 7 8 Camera::~Camera() { delete[] colors; } void Camera::Position_And_Aim_Camera(const vec3& position_input, const vec3& look_at_point,const vec3& pseudo_up_vector) { position=position_input; look_vector=(look_at_point-position).normalized(); horizontal_vector=cross (look_vector, pseudo_up_vector).normalized(); vertical_vector=cross (horizontal_vector, look_vector).normalized(); } void Camera::Focus_Camera(double focal_distance, double aspect_ratio, E double field_of_view) { film_position=position+look_vector*focal_distance; double width=2.0*focal_distance*tan(.5*field_of_view); double height=width/aspect_ratio; image_size=vec2(width, height); 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 void Camera::Set_Resolution(const ivec2& number_pixels_input) { number_pixels=number_pixels_input; if(colors) delete[] colors; colors=new Pixel[number_pixels[@]*number_pixels[1]]; min=-0.5*image_size; max=0.5* image_size; pixel_size = image_size/vec2(number_pixels); // Find the world position of the input pixel Svec3 Camera:: World_Position(const ivec2& pixel_index) { vec3 result; TODO; return result; Ir = 0; for(int i = 0; i vec cross(const vec & u, const vec & v) { return vec ( u[1] * V[2] - u[2] * v[1], u[2] * V[@] - u[@] * V[2], u[@] * v[1] - u[1] * v[@]); } template vec componentwise_max(const vec& a, const vec& b) { vec r; for(int i=0; i vec componentwise_min(const vec& a, const vec& b) { vec r; for(int i=0; i std::ostream& operator &u) { for(int i = 0; i Estd::istream& operator >> (std::istream& in, vec & u) { for(int i = 0; i> u[i]; } return in; typedef vec double, 2> vec2; typedef vec double,3> vec3; typedef vec ivec2; typedef vec ivec3; #endif<><><>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management An Organizational Perspective

Authors: Richard T. Watson

1st Edition

0471305340, 978-0471305347

Students also viewed these Databases questions

Question

1. Who is responsible for resolving this dilemma?

Answered: 1 week ago