diff --git a/Computer-Graphics-lab-master/.gitattributes b/Computer-Graphics-lab-master/.gitattributes new file mode 100644 index 0000000..bdb0cab --- /dev/null +++ b/Computer-Graphics-lab-master/.gitattributes @@ -0,0 +1,17 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/Computer-Graphics-lab-master/.gitignore b/Computer-Graphics-lab-master/.gitignore new file mode 100644 index 0000000..96374c4 --- /dev/null +++ b/Computer-Graphics-lab-master/.gitignore @@ -0,0 +1,43 @@ +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# ========================= +# Operating System Files +# ========================= + +# OSX +# ========================= + +.DS_Store +.AppleDouble +.LSOverride + +# Thumbnails +._* + +# Files that might appear on external disk +.Spotlight-V100 +.Trashes + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk diff --git a/Computer-Graphics-lab-master/Tajmahal_cg/Tajmahal_cg.cbp b/Computer-Graphics-lab-master/Tajmahal_cg/Tajmahal_cg.cbp new file mode 100644 index 0000000..1661cd4 --- /dev/null +++ b/Computer-Graphics-lab-master/Tajmahal_cg/Tajmahal_cg.cbp @@ -0,0 +1,51 @@ + + + + + + diff --git a/Computer-Graphics-lab-master/Tajmahal_cg/Tajmahal_cg.depend b/Computer-Graphics-lab-master/Tajmahal_cg/Tajmahal_cg.depend new file mode 100644 index 0000000..4dbddff --- /dev/null +++ b/Computer-Graphics-lab-master/Tajmahal_cg/Tajmahal_cg.depend @@ -0,0 +1,250 @@ +# depslib dependency file v1.0 +1441643058 source:c:\users\sanim\desktop\thesis\tajmahal_cg\main.cpp + + + "imageloader.h" + "color.h" + +1434386397 c:\program files\codeblocks-ep\mingw\include\gl\glut.h + + + + + +1258799516 c:\program files\codeblocks-ep\mingw\include\windows.h + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +1258799516 c:\program files\codeblocks-ep\mingw\include\winresrc.h + + + + + + + +1258799516 c:\program files\codeblocks-ep\mingw\include\winuser.h + +1258799516 c:\program files\codeblocks-ep\mingw\include\winnt.h + + + + + + +1258799516 c:\program files\codeblocks-ep\mingw\include\winerror.h + +1259406758 c:\program files\codeblocks-ep\mingw\include\string.h + <_mingw.h> + + +1259406752 c:\program files\codeblocks-ep\mingw\include\_mingw.h + +1258799502 c:\program files\codeblocks-ep\mingw\include\basetsd.h + +1258799510 c:\program files\codeblocks-ep\mingw\include\pshpack4.h + +1258799510 c:\program files\codeblocks-ep\mingw\include\poppack.h + +1258799516 c:\program files\codeblocks-ep\mingw\include\winver.h + +1258799502 c:\program files\codeblocks-ep\mingw\include\dde.h + +1258799504 c:\program files\codeblocks-ep\mingw\include\dlgs.h + +1258799502 c:\program files\codeblocks-ep\mingw\include\commctrl.h + + +1258799510 c:\program files\codeblocks-ep\mingw\include\prsht.h + +1258799516 c:\program files\codeblocks-ep\mingw\include\windef.h + + +1258799516 c:\program files\codeblocks-ep\mingw\include\wincon.h + +1258799516 c:\program files\codeblocks-ep\mingw\include\winbase.h + +1258799516 c:\program files\codeblocks-ep\mingw\include\wingdi.h + +1258799516 c:\program files\codeblocks-ep\mingw\include\winnls.h + +1258799516 c:\program files\codeblocks-ep\mingw\include\winnetwk.h + +1258799516 c:\program files\codeblocks-ep\mingw\include\winreg.h + +1258799516 c:\program files\codeblocks-ep\mingw\include\winsvc.h + +1258799502 c:\program files\codeblocks-ep\mingw\include\cderr.h + +1258799502 c:\program files\codeblocks-ep\mingw\include\ddeml.h + +1258799504 c:\program files\codeblocks-ep\mingw\include\imm.h + +1258799508 c:\program files\codeblocks-ep\mingw\include\lzexpand.h + +1258799508 c:\program files\codeblocks-ep\mingw\include\mmsystem.h + +1258799508 c:\program files\codeblocks-ep\mingw\include\nb30.h + +1258799512 c:\program files\codeblocks-ep\mingw\include\rpc.h + + + + + + + +1258799512 c:\program files\codeblocks-ep\mingw\include\rpcdce.h + + + +1258799502 c:\program files\codeblocks-ep\mingw\include\basetyps.h + +1258799512 c:\program files\codeblocks-ep\mingw\include\rpcdcep.h + +1258799512 c:\program files\codeblocks-ep\mingw\include\rpcnsi.h + +1258799512 c:\program files\codeblocks-ep\mingw\include\rpcnterr.h + +1259406754 c:\program files\codeblocks-ep\mingw\include\excpt.h + <_mingw.h> + + +1258799514 c:\program files\codeblocks-ep\mingw\include\shellapi.h + + + +1258799510 c:\program files\codeblocks-ep\mingw\include\pshpack2.h + +1258799516 c:\program files\codeblocks-ep\mingw\include\winperf.h + +1258799502 c:\program files\codeblocks-ep\mingw\include\commdlg.h + + + +1258799514 c:\program files\codeblocks-ep\mingw\include\unknwn.h + + + + +1258799510 c:\program files\codeblocks-ep\mingw\include\objfwd.h + + +1258799518 c:\program files\codeblocks-ep\mingw\include\wtypes.h + + + +1258799512 c:\program files\codeblocks-ep\mingw\include\rpcndr.h + + + +1258799512 c:\program files\codeblocks-ep\mingw\include\rpcnsip.h + +1258799516 c:\program files\codeblocks-ep\mingw\include\winspool.h + +1258799516 c:\program files\codeblocks-ep\mingw\include\winsock2.h + + +1258799516 c:\program files\codeblocks-ep\mingw\include\winsock.h + + + +1258799508 c:\program files\codeblocks-ep\mingw\include\mswsock.h + +1258799510 c:\program files\codeblocks-ep\mingw\include\ole2.h + + + + + + +1258799510 c:\program files\codeblocks-ep\mingw\include\objbase.h + + + + + + + + + +1259406758 c:\program files\codeblocks-ep\mingw\include\stdlib.h + <_mingw.h> + + +1258799510 c:\program files\codeblocks-ep\mingw\include\objidl.h + + +1258799502 c:\program files\codeblocks-ep\mingw\include\cguid.h + +1258799510 c:\program files\codeblocks-ep\mingw\include\olectlid.h + +1258799510 c:\program files\codeblocks-ep\mingw\include\oleauto.h + + +1258799510 c:\program files\codeblocks-ep\mingw\include\oaidl.h + + + +1258799510 c:\program files\codeblocks-ep\mingw\include\oleidl.h + + +1258799518 c:\program files\codeblocks-ep\mingw\include\gl\gl.h + +1258799518 c:\program files\codeblocks-ep\mingw\include\gl\glu.h + + + +1259406756 c:\program files\codeblocks-ep\mingw\include\stdio.h + <_mingw.h> + + + + +1259406760 c:\program files\codeblocks-ep\mingw\include\sys\types.h + <_mingw.h> + + +1259406756 c:\program files\codeblocks-ep\mingw\include\math.h + <_mingw.h> + +1441554913 c:\users\sanim\desktop\thesis\tajmahal_cg\imageloader.h + + + +1259406752 c:\program files\codeblocks-ep\mingw\include\assert.h + <_mingw.h> + +1439186349 c:\users\sanim\desktop\thesis\tajmahal_cg\vec3f.h + + + "vec3f.h" + +1374680643 c:\users\sanim\desktop\thesis\tajmahal_cg\color.h + diff --git a/Computer-Graphics-lab-master/Tajmahal_cg/Tajmahal_cg.layout b/Computer-Graphics-lab-master/Tajmahal_cg/Tajmahal_cg.layout new file mode 100644 index 0000000..d3dd98f --- /dev/null +++ b/Computer-Graphics-lab-master/Tajmahal_cg/Tajmahal_cg.layout @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Computer-Graphics-lab-master/Tajmahal_cg/color.h b/Computer-Graphics-lab-master/Tajmahal_cg/color.h new file mode 100644 index 0000000..7d75929 --- /dev/null +++ b/Computer-Graphics-lab-master/Tajmahal_cg/color.h @@ -0,0 +1,111 @@ +#define Red 1.0,0.0,0.0 +#define Green 0.0,1.0,0.0 +#define Blue 0.0,0.0,1.0 +#define Yellow 1.0,1.0,0.0 +#define Cyan 0.0,1.0,1.0 +#define Magenta 1.0,0.0,1.0 +#define White 1.0,1.0,1.0 +#define Black 0.0,0.0,0.0 + +#define GoldPole 0.627451,0.627451,0 + +#define DimGray 0.329412,0.329412,0.329412 +#define Gray 0.752941,0.752941,0.752941 +#define LightGray 0.658824,0.658824,0.658824 +#define VLightGray 0.80,0.80,0.80 + +#define Aquamarine 0.439216,0.858824,0.576471 +#define BlueViolet 0.62352,0.372549,0.623529 +#define Brown 0.647059,0.164706,0.164706 +#define CadetBlue 0.372549,0.623529,0.623529 +#define Coral 1.0,0.498039,0.0 +#define CornflowerBlue 0.258824,0.258824,0.435294 +#define DarkGreen 0.184314,0.309804,0.184314 +#define DarkOliveGreen 0.309804,0.309804,0.184314 +#define DarkOrchid 0.6,0.196078,0.8 +#define DarkSlateBlue 0.419608,0.137255,0.556863 +#define DarkSlateGray 0.184314,0.309804,0.309804 +#define DarkSlateGrey 0.184314,0.309804,0.309804 +#define DarkTurquoise 0.439216,0.576471,0.858824 +#define Firebrick 0.556863,0.137255,0.137255 +#define ForestGreen 0.137255,0.556863,0.137255 +#define Gold 0.8,0.498039,0.196078 +#define Goldenrod 0.858824,0.858824,0.439216 +#define GreenYellow 0.576471,0.858824,0.439216 +#define IndianRed 0.309804,0.184314,0.184314 +#define Khaki 0.623529,0.623529,0.372549 +#define LightBlue 0.74902,0.847059,0.847059 +#define LightSteelBlue 0.560784,0.560784,0.737255 +#define LimeGreen 0.196078,0.8,0.196078 +#define Maroon 0.556863,0.137255,0.419608 +#define MediumAquamarine 0.196078,0.8,0.6 +#define MediumBlue 0.196078,0.196078,0.8 +#define MediumForestGreen 0.419608,0.556863,0.137255 +#define MediumGoldenrod 0.917647,0.917647,0.678431 +#define MediumOrchid 0.576471,0.439216,0.858824 +#define MediumSeaGreen 0.258824,0.435294,0.258824 +#define MediumSlateBlue 0.498039,1.0 +#define MediumSpringGreen 0.498039,1.0 +#define MediumTurquoise 0.439216,0.858824,0.858824 +#define MediumVioletRed 0.858824,0.439216,0.576471 +#define MidnightBlue 0.184314,0.184314,0.309804 +#define Navy 0.137255,0.137255,0.556863 +#define NavyBlue 0.137255,0.137255,0.556863 +#define Orange 1,0.5,0.0 +#define OrangeRed 1.0,0.25 +#define Orchid 0.858824,0.439216,0.858824 +#define PaleGreen 0.560784,0.737255,0.560784 +#define Pink 0.737255,0.560784,0.560784 +#define Plum 0.917647,0.678431,0.917647 +#define Salmon 0.435294,0.258824,0.258824 +#define SeaGreen 0.137255,0.556863,0.419608 +#define Sienna 0.556863,0.419608,0.137255 +#define SkyBlue 0.196078,0.6,0.8 +#define SlateBlue = color,0.498039,1.0 +#define SpringGreen = color,1.0,0.498039 +#define SteelBlue 0.137255,0.419608,0.556863 +#define Tan 0.858824,0.576471,0.439216 +#define Thistle 0.847059,0.74902,0.847059 +#define Turquoise 0.678431,0.917647,0.917647 +#define Violet 0.309804,0.184314,0.309804 +#define VioletRed 0.8,0.196078,0.6 +#define Wheat 0.847059,0.847059,0.74902 +#define YellowGreen 0.6,0.8,0.196078 +#define SummerSky 0.22,0.69,0.87 +#define RichBlue 0.35,0.35,0.67 +#define Brass 0.71,0.65,0.26 +#define Copper 0.72,0.45,0.20 +#define Bronze 0.55,0.47,0.14 +#define Bronze2 0.65,0.49,0.24 +#define Silver 0.90,0.91,0.98 +#define BrightGold 0.85,0.85,0.10 +#define OldGold 0.81,0.71,0.23 +#define Feldspar 0.82,0.57,0.46 +#define Quartz 0.85,0.85,0.95 +// #define Mica = color Black // needed in textures.inc +#define NeonPink 1.00,0.43,0.78 +#define DarkPurple 0.53,0.12,0.47 +#define NeonBlue 0.30,0.30,1.00 +#define CoolCopper 0.85,0.53,0.10 +#define MandarinOrange 0.89,0.47,0.20 +#define LightWood 0.91,0.76,0.65 +#define MediumWood 0.65,0.50,0.39 +#define DarkWood 0.52,0.37,0.26 +#define SpicyPink 1.00,0.11,0.68 +#define SemiSweetChoc 0.42,0.26,0.15 +#define BakersChoc 0.36,0.20,0.09 +#define Flesh 0.96,0.80,0.69 +#define NewTan 0.92,0.78,0.62 +#define NewMidnightBlue 0.00,0.00,0.61 +#define VeryDarkBrown 0.35,0.16,0.14 +#define DarkBrown 0.36,0.25,0.20 +#define DarkTan 0.59,0.41,0.31 +#define GreenCopper 0.32,0.49,0.46 +#define DkGreenCopper 0.29,0.46,0.43 +#define DustyRose 0.52,0.39,0.39 +#define HuntersGreen 0.13,0.37,0.31 +#define Scarlet 0.55,0.09,0.09 + +#define MedPurple 0.73,0.16,0.96 +#define LightPurple 0.87,0.58,0.98 +#define VeryLightPurple 0.94,0.81,0.99 diff --git a/Computer-Graphics-lab-master/Tajmahal_cg/imageloader.h b/Computer-Graphics-lab-master/Tajmahal_cg/imageloader.h new file mode 100644 index 0000000..53e77f1 --- /dev/null +++ b/Computer-Graphics-lab-master/Tajmahal_cg/imageloader.h @@ -0,0 +1,221 @@ +/* Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above notice and this permission notice shall be included in all copies + * or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* File for "Terrain" lesson of the OpenGL tutorial on + * www.videotutorialsrock.com + */ + + + +#ifndef IMAGE_LOADER_H_INCLUDED +#define IMAGE_LOADER_H_INCLUDED +#include +#include + +using namespace std; +//Represents an image +class Image { + public: + Image(char* ps, int w, int h); + ~Image(); + + /* An array of the form (R1, G1, B1, R2, G2, B2, ...) indicating the + * color of each pixel in image. Color components range from 0 to 255. + * The array starts the bottom-left pixel, then moves right to the end + * of the row, then moves up to the next column, and so on. This is the + * format in which OpenGL likes images. + */ + char* pixels; + int width; + int height; +}; + + + +Image::Image(char* ps, int w, int h) : pixels(ps), width(w), height(h) { + +} + +Image::~Image() { + delete[] pixels; +} + +namespace { + //Converts a four-character array to an integer, using little-endian form + int toInt(const char* bytes) { + return (int)(((unsigned char)bytes[3] << 24) | + ((unsigned char)bytes[2] << 16) | + ((unsigned char)bytes[1] << 8) | + (unsigned char)bytes[0]); + } + + //Converts a two-character array to a short, using little-endian form + short toShort(const char* bytes) { + return (short)(((unsigned char)bytes[1] << 8) | + (unsigned char)bytes[0]); + } + + //Reads the next four bytes as an integer, using little-endian form + int readInt(ifstream &input) { + char buffer[4]; + input.read(buffer, 4); + return toInt(buffer); + } + + //Reads the next two bytes as a short, using little-endian form + short readShort(ifstream &input) { + char buffer[2]; + input.read(buffer, 2); + return toShort(buffer); + } + + //Just like auto_ptr, but for arrays + template + class auto_array { + private: + T* array; + mutable bool isReleased; + public: + explicit auto_array(T* array_ = NULL) : + array(array_), isReleased(false) { + } + + auto_array(const auto_array &aarray) { + array = aarray.array; + isReleased = aarray.isReleased; + aarray.isReleased = true; + } + + ~auto_array() { + if (!isReleased && array != NULL) { + delete[] array; + } + } + + T* get() const { + return array; + } + + T &operator*() const { + return *array; + } + + void operator=(const auto_array &aarray) { + if (!isReleased && array != NULL) { + delete[] array; + } + array = aarray.array; + isReleased = aarray.isReleased; + aarray.isReleased = true; + } + + T* operator->() const { + return array; + } + + T* release() { + isReleased = true; + return array; + } + + void reset(T* array_ = NULL) { + if (!isReleased && array != NULL) { + delete[] array; + } + array = array_; + } + + T* operator+(int i) { + return array + i; + } + + T &operator[](int i) { + return array[i]; + } + }; +} + +Image* loadBMP(const char* filename) { + ifstream input; + input.open(filename, ifstream::binary); + assert(!input.fail() || !"Could not find file"); + char buffer[2]; + input.read(buffer, 2); + assert(buffer[0] == 'B' && buffer[1] == 'M' || !"Not a bitmap file"); + input.ignore(8); + int dataOffset = readInt(input); + + //Read the header + int headerSize = readInt(input); + int width; + int height; + switch(headerSize) { + case 40: + //V3 + width = readInt(input); + height = readInt(input); + input.ignore(2); + assert(readShort(input) == 24 || !"Image is not 24 bits per pixel"); + assert(readShort(input) == 0 || !"Image is compressed"); + break; + case 12: + //OS/2 V1 + width = readShort(input); + height = readShort(input); + input.ignore(2); + assert(readShort(input) == 24 || !"Image is not 24 bits per pixel"); + break; + case 64: + //OS/2 V2 + assert(!"Can't load OS/2 V2 bitmaps"); + break; + case 108: + //Windows V4 + assert(!"Can't load Windows V4 bitmaps"); + break; + case 124: + //Windows V5 + assert(!"Can't load Windows V5 bitmaps"); + break; + default: + assert(!"Unknown bitmap format"); + } + + //Read the data + int bytesPerRow = ((width * 3 + 3) / 4) * 4 - (width * 3 % 4); + int size = bytesPerRow * height; + auto_array pixels(new char[size]); + input.seekg(dataOffset, ios_base::beg); + input.read(pixels.get(), size); + //cout << height << " " << width << endl; + + //Get the data into the right format + auto_array pixels2(new char[width * height * 3]); + for(int y = 0; y < height; y++) { + for(int x = 0; x < width; x++) { + for(int c = 0; c < 3; c++) { + pixels2[3 * (width * y + x) + c] = + pixels[bytesPerRow * y + 3 * x + (2 - c)]; + } + } + } + + input.close(); + return new Image(pixels2.release(), width, height); +} +#endif diff --git a/Computer-Graphics-lab-master/Tajmahal_cg/main.cpp b/Computer-Graphics-lab-master/Tajmahal_cg/main.cpp new file mode 100644 index 0000000..fc3797b --- /dev/null +++ b/Computer-Graphics-lab-master/Tajmahal_cg/main.cpp @@ -0,0 +1,602 @@ + +/* +Author :: MD. Musfiqur Rahman Sanim +Aust cse 28th Batch +ID:11.02.04.097 +*/ + + +//{ Template +using namespace std; +//{ headers +#include +//} +//{ Loops +#define forab(i,a,b) for (__typeof(b) i = (a); i <= (b); ++i) +#define rep(i,n) forab (i, 0, (n) - 1) +#define For(i,n) forab (i, 1, n) +#define rofba(i,a,b) for (__typeof(b) i = (b); i >= (a); --i) +#define per(i,n) rofba (i, 0, (n) - 1) +#define rof(i,n) rofba (i, 1, n) +#define forstl(i,s) for (__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i) +//} +//{ Floating-points +#define EPS 1e-7 +#define abs(x) (((x) < 0) ? - (x) : (x)) +#define zero(x) (abs (x) < EPS) +#define equal(a,b) (zero ((a) - (b))) +#define PI 2*acos (0.0) +//} +typedef long long int64; +typedef unsigned long long int64u; +#define memo(a,v) memset(a,v,sizeof(a)) +#define all(a) a.begin(),a.end() +#define db double +#define pb push_back +#define eb emplace_back +#define pii pair +#define NL puts("") +#define ff first +#define ss second +//{ +//Intput_Output +#define gc getchar +#define II ({ int a; read(a); a;}) +#define IL ({ int64 a; read(a); a;}) +#define ID ({ db a; scanf("%lf",&a); a;}) +#define IC ({ char a; scanf("%c",&a); a;}) +#define IS ({ string a; cin >> a; a;}) +#define OC printf("Case %d:",cs); +//} +//} +#define _stl(x) {__stl_print__(x);} +#define __(args...) {dbg,args; cerr<inline bool read(T &x){int c=gc();int sgn=1;while(~c&&c<'0'|c>'9'){if(c=='-')sgn=-1;c=gc();}for(x=0;~c&&'0'<=c&&c<='9';c=gc())x=x*10+c-'0';x*=sgn;return ~c;} +struct debugger{template debugger& operator , (const T& v){cerr< void __stl_print__ (T &x) { // for all STL containers + cerr << "["; forstl (i, x) cerr << (i != x.begin () ? ", " : "") << *i; cerr << "]" << endl; +} +template inline T max (T &a, U &b) +{ + return a > b ? a : b; +} +template inline T min (T &a, U &b) +{ + return a < b ? a : b; +} +template inline T swap (T &a, U &b) +{ + T tmp = a; + a = b; + b = tmp; +} + + +#include +#include "imageloader.h" +#include "color.h" + +using namespace std; + +const float BOX_SIZE = 15.0f; +const float h = 1.f; //The length of each side of the cube +float _angle = 0; //The rotation of the box +GLuint _textureId,_textureId1,_textureId2,_textureId3; //The OpenGL id of the texture +GLUquadricObj *quad = gluNewQuadric(); +GLUquadricObj *quad1 = gluNewQuadric(); +void handleKeypress(unsigned char key, int x, int y) { + switch (key) { + case 27: //Escape key + exit(0); + } +} + +//Makes the image into a texture, and returns the id of the texture +GLuint loadTexture(Image* image) { + GLuint textureId; + glGenTextures(1, &textureId); + glBindTexture(GL_TEXTURE_2D, textureId); + glTexImage2D(GL_TEXTURE_2D, + 0, + GL_RGB, + image->width, image->height, + 0, + GL_RGB, + GL_UNSIGNED_BYTE, + image->pixels); + return textureId; +} + +void initRendering() { + glEnable(GL_DEPTH_TEST); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_NORMALIZE); + glEnable(GL_COLOR_MATERIAL); + + Image* image = loadBMP("C:\\Users\\Sanim\\Desktop\\thesis\\Tajmahal_cg\\1.bmp"); + _textureId = loadTexture(image); + delete image; + + image = loadBMP("C:\\Users\\Sanim\\Desktop\\thesis\\Tajmahal_cg\\2.bmp"); + _textureId1 = loadTexture(image); + delete image; + + image = loadBMP("C:\\Users\\Sanim\\Desktop\\thesis\\Tajmahal_cg\\3.bmp"); + _textureId2 = loadTexture(image); + delete image; + + image = loadBMP("C:\\Users\\Sanim\\Desktop\\thesis\\Tajmahal_cg\\4.bmp"); + _textureId3 = loadTexture(image); + delete image; + + //Image* image = loadBMP("aust.bmp"); + //_textureId = loadTexture(image); + //delete image; +} + +void handleResize(int w, int h) { + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(45.0, (float)w / (float)h, 1.0, 200.0); +} + +void TajFloor() { + glColor3d(White); + glBegin(GL_QUADS); + //Top face + glNormal3f(0.0, 1.0f, 0.0f); + glVertex3f(-BOX_SIZE / 2, h / 2, -BOX_SIZE / 2); + glVertex3f(-BOX_SIZE / 2, h / 2, BOX_SIZE / 2); + glVertex3f(BOX_SIZE / 2, h / 2, BOX_SIZE / 2); + glVertex3f(BOX_SIZE / 2, h / 2, -BOX_SIZE / 2); + + //Bottom face + + glNormal3f(0.0, -1.0f, 0.0f); + glVertex3f(-BOX_SIZE / 2, -h / 2, -BOX_SIZE / 2); + glVertex3f(BOX_SIZE / 2, -h / 2, -BOX_SIZE / 2); + glVertex3f(BOX_SIZE / 2, -h / 2, BOX_SIZE / 2); + glVertex3f(-BOX_SIZE / 2, -h / 2, BOX_SIZE / 2); + + //Left face + glNormal3f(-1.0, 0.0f, 0.0f); + glVertex3f(-BOX_SIZE / 2, -h / 2, -BOX_SIZE / 2); + glVertex3f(-BOX_SIZE / 2, -h / 2, BOX_SIZE / 2); + glVertex3f(-BOX_SIZE / 2, h / 2, BOX_SIZE / 2); + glVertex3f(-BOX_SIZE / 2, h / 2, -BOX_SIZE / 2); + + //Right face + glNormal3f(1.0, 0.0f, 0.0f); + glVertex3f(BOX_SIZE / 2, -h / 2, -BOX_SIZE / 2); + glVertex3f(BOX_SIZE / 2, h / 2, -BOX_SIZE / 2); + glVertex3f(BOX_SIZE / 2, h / 2, BOX_SIZE / 2); + glVertex3f(BOX_SIZE / 2, -h / 2, BOX_SIZE / 2); + + + + //Front face + glNormal3f(0.0, 0.0f, 1.0f); + glVertex3f(-BOX_SIZE / 2, -h / 2, BOX_SIZE / 2); + glVertex3f(BOX_SIZE / 2, -h / 2, BOX_SIZE / 2); + glVertex3f(BOX_SIZE / 2, h / 2, BOX_SIZE / 2); + glVertex3f(-BOX_SIZE / 2, h / 2, BOX_SIZE / 2); + + //Back face + glNormal3f(0.0, 0.0f, -1.0f); + glVertex3f(-BOX_SIZE / 2, -h / 2, -BOX_SIZE / 2); + glVertex3f(-BOX_SIZE / 2, h / 2, -BOX_SIZE / 2); + glVertex3f(BOX_SIZE / 2, h / 2, -BOX_SIZE / 2); + glVertex3f(BOX_SIZE / 2, -h / 2, -BOX_SIZE / 2); + glEnd(); +} + +void minarCenterCylinder(float a,float b) { + glEnable(GL_TEXTURE_2D); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glBindTexture(GL_TEXTURE_2D, _textureId3); + gluQuadricOrientation(quad, GLU_OUTSIDE); + gluQuadricNormals(quad, true); + gluQuadricTexture(quad, true); + glPushMatrix(); + glTranslated(a,0.0,b); + glRotated(90.,-1.,0.,0.); + gluCylinder(quad,0.8,0.6,7,8,1); + glPopMatrix(); +} + +void minarRings(float a,float b,float c) { + glPushMatrix(); + glTranslated(a,c,b); + glRotated(90.,-1.,0.,0.); + gluCylinder(quad,0.9,0.9,.25,8,1); + gluDisk(quad,0,0.9,50,1); + glPopMatrix(); + + glPushMatrix(); + glTranslated(a,c+.25,b); + glRotated(90.,-1.,0.,0.); + gluDisk(quad,0,0.9,50,1); + glPopMatrix(); +} + +void minarHead(float a,float b) { + glEnable(GL_TEXTURE_2D); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glBindTexture(GL_TEXTURE_2D, _textureId2); + gluQuadricOrientation(quad1, GLU_OUTSIDE); + gluQuadricNormals(quad1, true); + gluQuadricTexture(quad1, true); + glPushMatrix(); + glTranslated(a,7,b); + glRotated(90.,-1.,0.,0.); + gluCylinder(quad1,0.6,0.6,1.25,8,1); + glPopMatrix(); + + + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + gluQuadricOrientation(quad, GLU_OUTSIDE); + gluQuadricNormals(quad, true); + gluQuadricTexture(quad, true); + glPushMatrix(); + glTranslated(a,8.25,b); + glRotated(90.,-1.,0.,0.); + gluDisk(quad,0,0.6,50,1); + glPopMatrix(); + + glPushMatrix(); + glTranslated(a,8.25,b); + glRotated(90.,-1.,0.,0.); + glutSolidSphere(0.6,50,50); + glPopMatrix(); + + glBindTexture(GL_TEXTURE_2D, _textureId3); + gluQuadricOrientation(quad, GLU_OUTSIDE); + gluQuadricNormals(quad, true); + gluQuadricTexture(quad, true); + glPushMatrix(); + glTranslated(a,8,b); + glRotated(90.,-1.,0.,0.); + glutSolidCone(0.9,.25,50,50); + gluDisk(quad,0,0.9,50,1); + glPopMatrix(); + + glBindTexture(GL_TEXTURE_2D, _textureId3); + gluQuadricOrientation(quad, GLU_OUTSIDE); + gluQuadricNormals(quad, true); + gluQuadricTexture(quad, true); + glPushMatrix(); + glColor3d(Gold); + glTranslated(a,8.25+.6,b); + glRotated(90.,-1.,0.,0.); + gluCylinder(quad,0.1,0.1,.25,8,1); + glPopMatrix(); + glColor3d(White); +} + + +void minar() { + + minarCenterCylinder(BOX_SIZE/2-.8,BOX_SIZE/2-.8); + minarRings(BOX_SIZE/2-.8,BOX_SIZE/2-.8,2.33); + minarRings(BOX_SIZE/2-.8,BOX_SIZE/2-.8,2.33*2); + minarRings(BOX_SIZE/2-.8,BOX_SIZE/2-.8,2.33*3); + minarHead(BOX_SIZE/2-.8,BOX_SIZE/2-.8); + + + minarCenterCylinder(-BOX_SIZE/2+.8,BOX_SIZE/2-.8); + minarRings(-BOX_SIZE/2+.8,BOX_SIZE/2-.8,2.33); + minarRings(-BOX_SIZE/2+.8,BOX_SIZE/2-.8,2.33*2); + minarRings(-BOX_SIZE/2+.8,BOX_SIZE/2-.8,2.33*3); + minarHead(-BOX_SIZE/2+.8,BOX_SIZE/2-.8); + + minarCenterCylinder(-BOX_SIZE/2+.8,-BOX_SIZE/2+.8); + minarRings(-BOX_SIZE/2+.8,-BOX_SIZE/2+.8,2.33); + minarRings(-BOX_SIZE/2+.8,-BOX_SIZE/2+.8,2.33*2); + minarRings(-BOX_SIZE/2+.8,-BOX_SIZE/2+.8,2.33*3); + minarHead(-BOX_SIZE/2+.8,-BOX_SIZE/2+.8); + + minarCenterCylinder(BOX_SIZE/2-.8,-BOX_SIZE/2+.8); + minarRings(BOX_SIZE/2-.8,-BOX_SIZE/2+.8,2.33); + minarRings(BOX_SIZE/2-.8,-BOX_SIZE/2+.8,2.33*2); + minarRings(BOX_SIZE/2-.8,-BOX_SIZE/2+.8,2.33*3); + minarHead(BOX_SIZE/2-.8,-BOX_SIZE/2+.8); + +} +double x = 6,y = 6; +void wall1() { + + glEnable(GL_TEXTURE_2D); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glBindTexture(GL_TEXTURE_2D, _textureId); + glBegin(GL_QUADS); + glNormal3f(0.0, 1.0f, 0.0f); + glTexCoord2f(0.f, 0.0f); + glVertex3f(-BOX_SIZE / 2 + x, h / 2 , BOX_SIZE / 2 - x); + glTexCoord2f(1.f, 0.f); + glVertex3f(-BOX_SIZE / 2 + x, h / 2 + y-1, BOX_SIZE / 2 - x); + glTexCoord2f(1.f, 1.f); + glVertex3f(BOX_SIZE / 2 - x, h / 2 + y-1, BOX_SIZE / 2 - x); + glTexCoord2f(0.f, 1.f); + glVertex3f(BOX_SIZE / 2 - x, h / 2, BOX_SIZE / 2 - x); + glEnd(); + + glPushMatrix(); + glTranslated(-BOX_SIZE / 2 + x+.1, h / 2+ y-1 , BOX_SIZE / 2 - x); + glColor3d(Gold); + glRotated(90.,-1.,0.,0.); + gluCylinder(quad,0.05,0.05,.50,8,1); + glColor3d(White); + glPopMatrix(); + + glPushMatrix(); + glTranslated(BOX_SIZE / 2 - x-.1, h / 2 + y-1, BOX_SIZE / 2 - x); + glColor3d(Gold); + glRotated(90.,-1.,0.,0.); + gluCylinder(quad,0.05,0.05,.50,8,1); + glColor3d(White); + glPopMatrix(); +} +double z = 2; +double _w2; +void wall2() { + glEnable(GL_TEXTURE_2D); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glBindTexture(GL_TEXTURE_2D, _textureId1); + glBegin(GL_QUADS); + glNormal3f(0.0, 1.0f, 0.0f); + glTexCoord2f(0.f, 0.0f); + glVertex3f(-BOX_SIZE / 2 + x, h / 2 , BOX_SIZE / 2 - x); + + glTexCoord2f(1.f, 0.0f); + glVertex3f(-BOX_SIZE / 2 + x, h / 2 + y - z, BOX_SIZE / 2 - x); + + glTexCoord2f(1.f, 1.0f); + glVertex3f(-BOX_SIZE / 2 + .75*x, h / 2 + y - z, BOX_SIZE / 2 - x); + //__(-BOX_SIZE / 2 + .75*x, h / 2 + y - z, BOX_SIZE / 2 - x); + + glTexCoord2f(0.f, 1.0f); + glVertex3f(-BOX_SIZE / 2 + .75*x, h / 2, BOX_SIZE / 2 - x); + glEnd(); +} + +void wall3() { + + glBindTexture(GL_TEXTURE_2D, _textureId1); + glBegin(GL_QUADS); + glNormal3f(0.0, 1.0f, 0.0f); + + glTexCoord2f(0.f, 0.0f); + glVertex3f(-BOX_SIZE / 2 + .75*x, h / 2, BOX_SIZE / 2 - x); + + glTexCoord2f(1.f, 0.0f); + glVertex3f(-BOX_SIZE / 2 + .75*x, h / 2 + y - z, BOX_SIZE / 2 - x); + + glTexCoord2f(1.f, 1.0f); + glVertex3f(-BOX_SIZE / 3.25 , h / 2 + y - z, BOX_SIZE / 2 - 1.25*x); + + + glTexCoord2f(0.f, 1.0f); + glVertex3f(-BOX_SIZE / 3.25, h / 2 , BOX_SIZE / 2 - 1.25*x); + + glEnd(); + + glPushMatrix(); + glTranslated(-BOX_SIZE / 2 + .75*x, h / 2 + y - z, BOX_SIZE / 2 - x-.1); + glColor3d(Gold); + glRotated(90.,-1.,0.,0.); + gluCylinder(quad,0.05,0.05,.50,8,1); + glColor3d(White); + glPopMatrix(); + + glPushMatrix(); + glTranslated(-BOX_SIZE / 3.25 , h / 2 + y - z, BOX_SIZE / 2 - 1.25*x-.1); + glColor3d(Gold); + glRotated(90.,-1.,0.,0.); + gluCylinder(quad,0.05,0.05,.50,8,1); + glColor3d(White); + glPopMatrix(); +} + +void centerBig(){ + glPushMatrix(); + glTranslated(0,5,-BOX_SIZE/5); + gluSphere(quad,2,50,50); + glBindTexture(GL_TEXTURE_2D, _textureId3); + gluQuadricOrientation(quad, GLU_OUTSIDE); + gluQuadricNormals(quad, true); + gluQuadricTexture(quad, true); + glTranslated(0,2,0); + glColor3d(Gold); + glRotated(90.,-1.,0.,0.); + gluCylinder(quad,0.05,0.05,.50,8,1); + glColor3d(White); + glPopMatrix(); +} + +void side(){ + + glPushMatrix(); + glTranslated(-3,4.75,-BOX_SIZE/2.75); + gluSphere(quad,1,50,50); + glTranslated(0,1,0); + glColor3d(Gold); + glRotated(90.,-1.,0.,0.); + gluCylinder(quad,0.05,0.05,.50,8,1); + glColor3d(White); + glPopMatrix(); + + glPushMatrix(); + glTranslated(BOX_SIZE/2.75,0,0); + glTranslated(-3,4.75,-BOX_SIZE/2.75); + gluSphere(quad,1,50,50); + glTranslated(0,1,0); + glColor3d(Gold); + glRotated(90.,-1.,0.,0.); + gluCylinder(quad,0.05,0.05,.25,8,1); + glColor3d(White); + glPopMatrix(); + + glPushMatrix(); + glTranslated(0,0,BOX_SIZE/2.75); + glTranslated(-3,4.75,-BOX_SIZE/2.75); + gluSphere(quad,1,50,50); + glTranslated(0,1,0); + glColor3d(Gold); + glRotated(90.,-1.,0.,0.); + gluCylinder(quad,0.05,0.05,.25,8,1); + glColor3d(White); + glPopMatrix(); + + glPushMatrix(); + glTranslated(BOX_SIZE/2.75,0,BOX_SIZE/2.75); + glTranslated(-3,4.75,-BOX_SIZE/2.75); + gluSphere(quad,1,50,50); + glTranslated(0,1,0); + glColor3d(Gold); + glRotated(90.,-1.,0.,0.); + gluCylinder(quad,0.05,0.05,.25,8,1); + glColor3d(White); + glPopMatrix(); + + +} + + +void house() { + + glPushMatrix(); + glTranslated(0,0,2); + wall1(); + wall2(); + glPushMatrix(); + glTranslated(BOX_SIZE/3.35,0,0); + wall2(); + glPopMatrix(); + + glPushMatrix(); + wall3(); + glPopMatrix(); + + glPushMatrix(); + rep(i,3) { + glTranslated(-3,0,-3); + glRotated(-90.,0,1,0); + wall1(); + wall2(); + glPushMatrix(); + glTranslated(BOX_SIZE/3.35,0,0); + wall2(); + glPopMatrix(); + wall3(); + } + glPopMatrix(); + glBindTexture(GL_TEXTURE_2D, _textureId3); + gluQuadricOrientation(quad, GLU_OUTSIDE); + gluQuadricNormals(quad, true); + gluQuadricTexture(quad, true); + centerBig(); + side(); + glPopMatrix(); + +} + +void dd(){ + glPushMatrix(); + glBegin(GL_QUADS); + glVertex3f(-BOX_SIZE/3.35 , h / 2 + y - z, BOX_SIZE / 6.45); + glVertex3f(BOX_SIZE / 3.35, h / 2 + y - z, BOX_SIZE / 6.45); + glVertex3f(BOX_SIZE/3.35, h / 2 + y - z, -BOX_SIZE / 3.5); + glVertex3f(-BOX_SIZE/3.35 , h / 2 + y - z, -BOX_SIZE /3.5); + glEnd(); + + glBegin(GL_QUADS); + glVertex3f(-BOX_SIZE/3.35 , h / 2 + y - z, BOX_SIZE / 6.45); + glVertex3f(BOX_SIZE / 3.35, h / 2 + y - z, BOX_SIZE / 6.45); + glVertex3f(BOX_SIZE / 2 - .75*x, h / 2 + y - z, BOX_SIZE / 4.35); + glVertex3f(-BOX_SIZE / 2 + .75*x, h / 2 + y - z , BOX_SIZE / 4.35); + glEnd(); + + glPushMatrix(); + + glTranslated(0,0,-BOX_SIZE/8); + glRotated(-180,0,1,0); + glBegin(GL_QUADS); + glVertex3f(-BOX_SIZE/3.35 , h / 2 + y - z, BOX_SIZE / 6.45); + glVertex3f(BOX_SIZE / 3.35, h / 2 + y - z, BOX_SIZE / 6.45); + glVertex3f(BOX_SIZE / 2 - .75*x, h / 2 + y - z, BOX_SIZE / 4.35); + glVertex3f(-BOX_SIZE / 2 + .75*x, h / 2 + y - z , BOX_SIZE / 4.35); + glEnd(); + glPopMatrix(); + + glPopMatrix(); +} + +void front(){ + +} + +void drawScene() { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glTranslatef(0.0f, 0.0f, -40.0f); + + GLfloat ambientLight[] = {0.3f, 0.3f, 0.3f, 1.0f}; + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight); + + GLfloat lightColor[] = {0.7f, 0.7f, 0.7f, 1.0f}; + GLfloat lightPos[] = {-2 * BOX_SIZE, BOX_SIZE, 4 * BOX_SIZE, 1.0f}; + glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor); + glLightfv(GL_LIGHT0, GL_POSITION, lightPos); + + glEnable(GL_TEXTURE_2D); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glRotatef(-_angle, 0.0f, 1.0f, 0.0f); + TajFloor(); + minar(); + house(); + dd(); + + glutSwapBuffers(); +} + + +void update(int value) { + _angle += 1.0f; + if (_angle > 360) { + _angle -= 360; + } + glutPostRedisplay(); + glutTimerFunc(10, update, 0); +} + + +int main(int argc, char** argv) { + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); + glutInitWindowSize(800, 800); + + glutCreateWindow("Tajmahal"); + initRendering(); + + glutDisplayFunc(drawScene); + glutKeyboardFunc(handleKeypress); + glutReshapeFunc(handleResize); + glutTimerFunc(25, update, 0); + + glutMainLoop(); + return 0; +} + + diff --git a/Computer-Graphics-lab-master/Tajmahal_cg/obj/Debug/main.o b/Computer-Graphics-lab-master/Tajmahal_cg/obj/Debug/main.o new file mode 100644 index 0000000..a83c63b Binary files /dev/null and b/Computer-Graphics-lab-master/Tajmahal_cg/obj/Debug/main.o differ diff --git a/Computer-Graphics-lab-master/Tajmahal_cg/vec3f.h b/Computer-Graphics-lab-master/Tajmahal_cg/vec3f.h new file mode 100644 index 0000000..7179625 --- /dev/null +++ b/Computer-Graphics-lab-master/Tajmahal_cg/vec3f.h @@ -0,0 +1,163 @@ +/* Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above notice and this permission notice shall be included in all copies + * or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* File for "Terrain" lesson of the OpenGL tutorial on + * www.videotutorialsrock.com + */ + + + +#ifndef VEC3F_H_INCLUDED +#define VEC3F_H_INCLUDED + +#include + +class Vec3f { + private: + float v[3]; + public: + Vec3f(); + Vec3f(float x, float y, float z); + + float &operator[](int index); + float operator[](int index) const; + + Vec3f operator*(float scale) const; + Vec3f operator/(float scale) const; + Vec3f operator+(const Vec3f &other) const; + Vec3f operator-(const Vec3f &other) const; + Vec3f operator-() const; + + const Vec3f &operator*=(float scale); + const Vec3f &operator/=(float scale); + const Vec3f &operator+=(const Vec3f &other); + const Vec3f &operator-=(const Vec3f &other); + + float magnitude() const; + float magnitudeSquared() const; + Vec3f normalize() const; + float dot(const Vec3f &other) const; + Vec3f cross(const Vec3f &other) const; +}; + +#include + +#include "vec3f.h" + +using namespace std; + +Vec3f::Vec3f() { + +} + +Vec3f::Vec3f(float x, float y, float z) { + v[0] = x; + v[1] = y; + v[2] = z; +} + +float &Vec3f::operator[](int index) { + return v[index]; +} + +float Vec3f::operator[](int index) const { + return v[index]; +} + +Vec3f Vec3f::operator*(float scale) const { + return Vec3f(v[0] * scale, v[1] * scale, v[2] * scale); +} + +Vec3f Vec3f::operator/(float scale) const { + return Vec3f(v[0] / scale, v[1] / scale, v[2] / scale); +} + +Vec3f Vec3f::operator+(const Vec3f &other) const { + return Vec3f(v[0] + other.v[0], v[1] + other.v[1], v[2] + other.v[2]); +} + +Vec3f Vec3f::operator-(const Vec3f &other) const { + return Vec3f(v[0] - other.v[0], v[1] - other.v[1], v[2] - other.v[2]); +} + +Vec3f Vec3f::operator-() const { + return Vec3f(-v[0], -v[1], -v[2]); +} + +const Vec3f &Vec3f::operator*=(float scale) { + v[0] *= scale; + v[1] *= scale; + v[2] *= scale; + return *this; +} + +const Vec3f &Vec3f::operator/=(float scale) { + v[0] /= scale; + v[1] /= scale; + v[2] /= scale; + return *this; +} + +const Vec3f &Vec3f::operator+=(const Vec3f &other) { + v[0] += other.v[0]; + v[1] += other.v[1]; + v[2] += other.v[2]; + return *this; +} + +const Vec3f &Vec3f::operator-=(const Vec3f &other) { + v[0] -= other.v[0]; + v[1] -= other.v[1]; + v[2] -= other.v[2]; + return *this; +} + +float Vec3f::magnitude() const { + return sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); +} + +float Vec3f::magnitudeSquared() const { + return v[0] * v[0] + v[1] * v[1] + v[2] * v[2]; +} + +Vec3f Vec3f::normalize() const { + float m = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); + return Vec3f(v[0] / m, v[1] / m, v[2] / m); +} + +float Vec3f::dot(const Vec3f &other) const { + return v[0] * other.v[0] + v[1] * other.v[1] + v[2] * other.v[2]; +} + +Vec3f Vec3f::cross(const Vec3f &other) const { + return Vec3f(v[1] * other.v[2] - v[2] * other.v[1], + v[2] * other.v[0] - v[0] * other.v[2], + v[0] * other.v[1] - v[1] * other.v[0]); +} + +Vec3f operator*(float scale, const Vec3f &v) { + return v * scale; +} + +ostream &operator<<(ostream &output, const Vec3f &v) { + cout << '(' << v[0] << ", " << v[1] << ", " << v[2] << ')'; + return output; +} + + +#endif