├── .gitignore ├── README.md ├── challenge1 ├── Reto1.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcuserdata │ │ │ └── wack-a-mole.xcuserdatad │ │ │ └── WorkspaceSettings.xcsettings │ └── xcuserdata │ │ └── wack-a-mole.xcuserdatad │ │ └── xcschemes │ │ ├── Reto1.xcscheme │ │ └── xcschememanagement.plist ├── Reto1 │ ├── Reto1.1 │ └── main.cpp └── pack │ ├── Andrés Mejía y Juan Pablo Pineda.zip │ ├── main.cpp │ ├── screenshot.png │ └── time.txt ├── challenge2 ├── challenge2.xcodeproj │ └── project.pbxproj ├── challenge2 │ ├── challenge2.1 │ └── main.cpp └── pack │ ├── Andrés Mejía.zip │ ├── main.cpp │ └── screenshot.png ├── challenge3 ├── .classpath ├── .project ├── README.md ├── bin │ ├── Arm.class │ ├── Bone.class │ ├── Hand.class │ ├── articulations │ │ ├── Articulation.class │ │ ├── Elbow.class │ │ ├── Shoulder.class │ │ └── Wrist.class │ └── java.policy.applet ├── pack │ ├── README.md │ ├── bin │ │ ├── Arm.class │ │ ├── Bone.class │ │ ├── Hand.class │ │ ├── articulations │ │ │ ├── Articulation.class │ │ │ ├── Elbow.class │ │ │ ├── Shoulder.class │ │ │ └── Wrist.class │ │ └── java.policy.applet │ ├── challenge3.zip │ ├── shots │ │ ├── 1.png │ │ ├── 2.png │ │ └── 3.png │ └── src │ │ ├── Arm.java │ │ ├── Bone.java │ │ ├── Hand.java │ │ └── articulations │ │ ├── Articulation.java │ │ ├── Elbow.java │ │ ├── Shoulder.java │ │ └── Wrist.java ├── shots │ ├── 1.png │ ├── 2.png │ └── 3.png └── src │ ├── Arm.java │ ├── Bone.java │ ├── Hand.java │ └── articulations │ ├── Articulation.java │ ├── Elbow.java │ ├── Shoulder.java │ └── Wrist.java ├── challenge4 ├── README.md ├── challenge4 │ ├── challenge4.xcodeproj │ │ └── project.pbxproj │ └── src │ │ ├── arm │ │ ├── challenge4.1 │ │ └── main.cpp ├── demo.mov ├── examples │ ├── cube.c │ └── robot.c ├── pack │ ├── Andrés Mejía.zip │ ├── README.txt │ ├── demo.mov │ ├── main.cpp │ └── shot.png └── shots │ └── shot.png ├── challenge5 ├── .gitignore ├── README.md ├── challenge5.xcodeproj │ └── project.pbxproj ├── input │ └── 1.txt ├── pack │ ├── Bézier.zip │ ├── README.md │ ├── demo.mov │ ├── input.txt │ ├── main.cpp │ └── shot.png └── src │ ├── bezier │ ├── challenge5.1 │ ├── example.cpp │ └── main.cpp ├── challenge6 ├── README.md ├── challenge6 │ ├── challenge6.xcodeproj │ │ └── project.pbxproj │ └── challenge6 │ │ ├── arm │ │ ├── example.cpp │ │ └── main.cpp ├── examples │ ├── cube.c │ └── robot.c ├── pack │ ├── README.txt │ ├── main.cpp │ ├── reto6.zip │ └── shots │ │ ├── Screen shot 2011-10-07 at 16.59.53.png │ │ ├── Screen shot 2011-10-07 at 17.00.00.png │ │ ├── Screen shot 2011-10-07 at 17.00.06.png │ │ ├── Screen shot 2011-10-07 at 17.00.12.png │ │ ├── Screen shot 2011-10-07 at 17.00.17.png │ │ ├── Screen shot 2011-10-07 at 17.00.20.png │ │ ├── Screen shot 2011-10-07 at 17.00.24.png │ │ ├── Screen shot 2011-10-07 at 17.00.29.png │ │ ├── Screen shot 2011-10-07 at 17.00.53.png │ │ ├── Screen shot 2011-10-07 at 17.00.59.png │ │ └── Screen shot 2011-10-07 at 17.01.09.png ├── project │ └── src │ │ ├── arm │ │ └── main.cpp └── shots │ ├── Screen shot 2011-10-07 at 16.59.53.png │ ├── Screen shot 2011-10-07 at 17.00.00.png │ ├── Screen shot 2011-10-07 at 17.00.06.png │ ├── Screen shot 2011-10-07 at 17.00.12.png │ ├── Screen shot 2011-10-07 at 17.00.17.png │ ├── Screen shot 2011-10-07 at 17.00.20.png │ ├── Screen shot 2011-10-07 at 17.00.24.png │ ├── Screen shot 2011-10-07 at 17.00.29.png │ ├── Screen shot 2011-10-07 at 17.00.53.png │ ├── Screen shot 2011-10-07 at 17.00.59.png │ └── Screen shot 2011-10-07 at 17.01.09.png └── challenge7 ├── README.md ├── challenge7 ├── challenge7.xcodeproj │ └── project.pbxproj └── src │ ├── RgbImage.cpp │ ├── RgbImage.h │ ├── arm │ ├── main.cpp │ └── tex_wood.bmp ├── example ├── Example │ ├── Example.xcodeproj │ │ └── project.pbxproj │ └── src │ │ ├── RedLeavesTexture.bmp │ │ ├── RgbImage.cpp │ │ ├── RgbImage.h │ │ ├── TextureBMP.cpp │ │ ├── TextureBMP.exe │ │ └── TextureBMP.html └── TextureBMP.zip ├── pack ├── README.txt ├── reto7.zip ├── shots │ ├── Screen shot 2011-10-19 at 20.19.57.png │ ├── Screen shot 2011-10-19 at 20.20.24.png │ ├── Screen shot 2011-10-19 at 20.20.31.png │ ├── Screen shot 2011-10-19 at 20.20.35.png │ ├── Screen shot 2011-10-19 at 20.20.43.png │ ├── Screen shot 2011-10-19 at 20.21.07.png │ ├── Screen shot 2011-10-19 at 20.21.13.png │ ├── Screen shot 2011-10-19 at 20.21.26.png │ ├── Screen shot 2011-10-19 at 20.21.33.png │ ├── Screen shot 2011-10-19 at 20.21.38.png │ ├── Screen shot 2011-10-19 at 20.21.41.png │ ├── Screen shot 2011-10-19 at 20.21.46.png │ ├── Screen shot 2011-10-19 at 20.21.54.png │ ├── Screen shot 2011-10-19 at 20.22.05.png │ └── Screen shot 2011-10-19 at 20.22.32.png └── src │ ├── RgbImage.cpp │ ├── RgbImage.h │ ├── main.cpp │ └── tex_wood.bmp └── shots ├── Screen shot 2011-10-19 at 20.19.57.png ├── Screen shot 2011-10-19 at 20.20.24.png ├── Screen shot 2011-10-19 at 20.20.31.png ├── Screen shot 2011-10-19 at 20.20.35.png ├── Screen shot 2011-10-19 at 20.20.43.png ├── Screen shot 2011-10-19 at 20.21.07.png ├── Screen shot 2011-10-19 at 20.21.13.png ├── Screen shot 2011-10-19 at 20.21.26.png ├── Screen shot 2011-10-19 at 20.21.33.png ├── Screen shot 2011-10-19 at 20.21.38.png ├── Screen shot 2011-10-19 at 20.21.41.png ├── Screen shot 2011-10-19 at 20.21.46.png ├── Screen shot 2011-10-19 at 20.21.54.png ├── Screen shot 2011-10-19 at 20.22.05.png └── Screen shot 2011-10-19 at 20.22.32.png /.gitignore: -------------------------------------------------------------------------------- 1 | *.xcuserstate 2 | xcuserdata 3 | project.xcworkspace 4 | .DS_Store 5 | build -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Computer Graphics Challenges - ST0275 2 | ===================================== 3 | 4 | These are the challenges assigned as homework in my Computer Graphics course at EAFIT University. 5 | 6 | Challenge 1 - Bresenham's algorithm 7 | ----------- 8 | [![Bresenham's algorithm](https://github.com/andmej/computer_graphics_challenges/raw/master/challenge1/pack/screenshot.png)](https://github.com/andmej/computer_graphics_challenges/blob/master/challenge1/Reto1/main.cpp) 9 | 10 | Challenge 2 - Cohen-Sutherland algorithm 11 | ---------------------------------------- 12 | Generate random line segments and use a rectangle clipping algorithm to show the parts of the lines that are inside the rectangle in a different color. 13 | 14 | [![Bresenham's algorithm](https://github.com/andmej/computer_graphics_challenges/raw/master/challenge2/pack/screenshot.png)](https://github.com/andmej/computer_graphics_challenges/blob/master/challenge2/challenge2/main.cpp) 15 | 16 | Challenge 3 - Robotic Arm in Java3D 17 | ------------------------- 18 | 19 | Create a robotic arm in Java3D with 3 articulations: shoulder, elbow and wrist. 20 | 21 | [![Screenshot 1](https://github.com/andmej/computer_graphics_challenges/blob/master/challenge3/shots/1.png?raw=true)](https://github.com/andmej/computer_graphics_challenges/tree/master/challenge3) 22 | 23 | Challenge 4 - Robotic Arm in OpenGL 24 | ------------------------- 25 | 26 | Like challenge 3, but in OpenGL. Additionally, add functionality to move the camera. 27 | 28 | [![Screenshot 1](https://github.com/andmej/computer_graphics_challenges/blob/master/challenge4/shots/shot.png?raw=true)](https://github.com/andmej/computer_graphics_challenges/tree/master/challenge4) 29 | 30 | See the [video demo on YouTube](http://www.youtube.com/watch?v=SfxGiCqAHNg). 31 | 32 | Challenge 5 - 3D Bézier surfaces 33 | --------------------------------- 34 | 35 | Render a Bézier surface based on some control points that are to be read from a text file. 36 | 37 | [![Screenshot](https://github.com/andmej/computer_graphics_challenges/blob/master/challenge5/pack/shot.png?raw=true)](https://github.com/andmej/computer_graphics_challenges/tree/master/challenge5) 38 | 39 | Challenge 6 - Robotic Arm in OpenGL with lighting 40 | ------------------------- 41 | 42 | Like challenge 4, but add lighting to the scene. 43 | 44 | [![Screenshot 1](https://github.com/andmej/computer_graphics_challenges/blob/master/challenge6/shots/Screen%20shot%202011-10-07%20at%2017.00.12.png?raw=true )](https://github.com/andmej/computer_graphics_challenges/tree/master/challenge6) 45 | 46 | Challenge 6 - Robotic Arm in OpenGL with textures 47 | ------------------------- 48 | 49 | Like challenge 6, but add textures. 50 | 51 | [![Screenshot 1](https://github.com/andmej/computer_graphics_challenges/blob/master/challenge7/shots/Screen%20shot%202011-10-19%20at%2020.20.35.png?raw=true)](https://github.com/andmej/computer_graphics_challenges/tree/master/challenge7) 52 | -------------------------------------------------------------------------------- /challenge1/Reto1.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /challenge1/Reto1.xcodeproj/project.xcworkspace/xcuserdata/wack-a-mole.xcuserdatad/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEWorkspaceUserSettings_BuildLocationStyle 6 | 0 7 | IDEWorkspaceUserSettings_BuildSubfolderNameStyle 8 | 0 9 | IDEWorkspaceUserSettings_DerivedDataLocationStyle 10 | 0 11 | IDEWorkspaceUserSettings_LiveSourceIssuesEnabled 12 | 13 | IDEWorkspaceUserSettings_SnapshotAutomaticallyBeforeSignificantChanges 14 | 15 | IDEWorkspaceUserSettings_SnapshotLocationStyle 16 | 0 17 | 18 | 19 | -------------------------------------------------------------------------------- /challenge1/Reto1.xcodeproj/xcuserdata/wack-a-mole.xcuserdatad/xcschemes/Reto1.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | 14 | 20 | 21 | 22 | 23 | 24 | 29 | 30 | 31 | 32 | 40 | 41 | 47 | 48 | 49 | 50 | 51 | 52 | 59 | 60 | 66 | 67 | 68 | 69 | 71 | 72 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /challenge1/Reto1.xcodeproj/xcuserdata/wack-a-mole.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Reto1.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 329B212013E2DF1E0061D55C 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /challenge1/Reto1/Reto1.1: -------------------------------------------------------------------------------- 1 | .\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples. 2 | .\"See Also: 3 | .\"man mdoc.samples for a complete listing of options 4 | .\"man mdoc for the short list of editing options 5 | .\"/usr/share/misc/mdoc.template 6 | .Dd 29/07/11 \" DATE 7 | .Dt Reto1 1 \" Program name and manual section number 8 | .Os Darwin 9 | .Sh NAME \" Section Header - required - don't modify 10 | .Nm Reto1, 11 | .\" The following lines are read in generating the apropos(man -k) database. Use only key 12 | .\" words here as the database is built based on the words here and in the .ND line. 13 | .Nm Other_name_for_same_program(), 14 | .Nm Yet another name for the same program. 15 | .\" Use .Nm macro to designate other names for the documented program. 16 | .Nd This line parsed for whatis database. 17 | .Sh SYNOPSIS \" Section Header - required - don't modify 18 | .Nm 19 | .Op Fl abcd \" [-abcd] 20 | .Op Fl a Ar path \" [-a path] 21 | .Op Ar file \" [file] 22 | .Op Ar \" [file ...] 23 | .Ar arg0 \" Underlined argument - use .Ar anywhere to underline 24 | arg2 ... \" Arguments 25 | .Sh DESCRIPTION \" Section Header - required - don't modify 26 | Use the .Nm macro to refer to your program throughout the man page like such: 27 | .Nm 28 | Underlining is accomplished with the .Ar macro like this: 29 | .Ar underlined text . 30 | .Pp \" Inserts a space 31 | A list of items with descriptions: 32 | .Bl -tag -width -indent \" Begins a tagged list 33 | .It item a \" Each item preceded by .It macro 34 | Description of item a 35 | .It item b 36 | Description of item b 37 | .El \" Ends the list 38 | .Pp 39 | A list of flags and their descriptions: 40 | .Bl -tag -width -indent \" Differs from above in tag removed 41 | .It Fl a \"-a flag as a list item 42 | Description of -a flag 43 | .It Fl b 44 | Description of -b flag 45 | .El \" Ends the list 46 | .Pp 47 | .\" .Sh ENVIRONMENT \" May not be needed 48 | .\" .Bl -tag -width "ENV_VAR_1" -indent \" ENV_VAR_1 is width of the string ENV_VAR_1 49 | .\" .It Ev ENV_VAR_1 50 | .\" Description of ENV_VAR_1 51 | .\" .It Ev ENV_VAR_2 52 | .\" Description of ENV_VAR_2 53 | .\" .El 54 | .Sh FILES \" File used or created by the topic of the man page 55 | .Bl -tag -width "/Users/joeuser/Library/really_long_file_name" -compact 56 | .It Pa /usr/share/file_name 57 | FILE_1 description 58 | .It Pa /Users/joeuser/Library/really_long_file_name 59 | FILE_2 description 60 | .El \" Ends the list 61 | .\" .Sh DIAGNOSTICS \" May not be needed 62 | .\" .Bl -diag 63 | .\" .It Diagnostic Tag 64 | .\" Diagnostic informtion here. 65 | .\" .It Diagnostic Tag 66 | .\" Diagnostic informtion here. 67 | .\" .El 68 | .Sh SEE ALSO 69 | .\" List links in ascending order by section, alphabetically within a section. 70 | .\" Please do not reference files that do not exist without filing a bug report 71 | .Xr a 1 , 72 | .Xr b 1 , 73 | .Xr c 1 , 74 | .Xr a 2 , 75 | .Xr b 2 , 76 | .Xr a 3 , 77 | .Xr b 3 78 | .\" .Sh BUGS \" Document known, unremedied bugs 79 | .\" .Sh HISTORY \" Document history if command behaves in a unique manner -------------------------------------------------------------------------------- /challenge1/pack/Andrés Mejía y Juan Pablo Pineda.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge1/pack/Andrés Mejía y Juan Pablo Pineda.zip -------------------------------------------------------------------------------- /challenge1/pack/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge1/pack/screenshot.png -------------------------------------------------------------------------------- /challenge1/pack/time.txt: -------------------------------------------------------------------------------- 1 | Using naive algorithm: 2 | Rendered 10100 lines. 3 | It took 711 milliseconds. 4 | 5 | Using Bresenham's algorithm: 6 | Rendered 10100 lines. 7 | It took 567 milliseconds. 8 | -------------------------------------------------------------------------------- /challenge2/challenge2.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 32F192F513EA1BC200392701 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 32F192F413EA1BC200392701 /* main.cpp */; }; 11 | 32F192FD13EA1E8C00392701 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 32F192FC13EA1E8C00392701 /* OpenGL.framework */; }; 12 | 32F192FF13EA1E9300392701 /* GLUT.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 32F192FE13EA1E9300392701 /* GLUT.framework */; }; 13 | /* End PBXBuildFile section */ 14 | 15 | /* Begin PBXCopyFilesBuildPhase section */ 16 | 32F192EE13EA1BB800392701 /* CopyFiles */ = { 17 | isa = PBXCopyFilesBuildPhase; 18 | buildActionMask = 2147483647; 19 | dstPath = /usr/share/man/man1/; 20 | dstSubfolderSpec = 0; 21 | files = ( 22 | ); 23 | runOnlyForDeploymentPostprocessing = 1; 24 | }; 25 | /* End PBXCopyFilesBuildPhase section */ 26 | 27 | /* Begin PBXFileReference section */ 28 | 32F192F013EA1BBD00392701 /* challenge2 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = challenge2; sourceTree = BUILT_PRODUCTS_DIR; }; 29 | 32F192F413EA1BC200392701 /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = ""; }; 30 | 32F192F613EA1BCB00392701 /* challenge2.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = challenge2.1; sourceTree = ""; }; 31 | 32F192FC13EA1E8C00392701 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = System/Library/Frameworks/OpenGL.framework; sourceTree = SDKROOT; }; 32 | 32F192FE13EA1E9300392701 /* GLUT.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GLUT.framework; path = System/Library/Frameworks/GLUT.framework; sourceTree = SDKROOT; }; 33 | /* End PBXFileReference section */ 34 | 35 | /* Begin PBXFrameworksBuildPhase section */ 36 | 32F192ED13EA1BB800392701 /* Frameworks */ = { 37 | isa = PBXFrameworksBuildPhase; 38 | buildActionMask = 2147483647; 39 | files = ( 40 | 32F192FF13EA1E9300392701 /* GLUT.framework in Frameworks */, 41 | 32F192FD13EA1E8C00392701 /* OpenGL.framework in Frameworks */, 42 | ); 43 | runOnlyForDeploymentPostprocessing = 0; 44 | }; 45 | /* End PBXFrameworksBuildPhase section */ 46 | 47 | /* Begin PBXGroup section */ 48 | 32F192E513EA1BAD00392701 = { 49 | isa = PBXGroup; 50 | children = ( 51 | 32F192FE13EA1E9300392701 /* GLUT.framework */, 52 | 32F192FC13EA1E8C00392701 /* OpenGL.framework */, 53 | 32F192F313EA1BBD00392701 /* challenge2 */, 54 | 32F192F113EA1BBD00392701 /* Products */, 55 | ); 56 | sourceTree = ""; 57 | }; 58 | 32F192F113EA1BBD00392701 /* Products */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 32F192F013EA1BBD00392701 /* challenge2 */, 62 | ); 63 | name = Products; 64 | sourceTree = ""; 65 | }; 66 | 32F192F313EA1BBD00392701 /* challenge2 */ = { 67 | isa = PBXGroup; 68 | children = ( 69 | 32F192F413EA1BC200392701 /* main.cpp */, 70 | 32F192F613EA1BCB00392701 /* challenge2.1 */, 71 | ); 72 | path = challenge2; 73 | sourceTree = ""; 74 | }; 75 | /* End PBXGroup section */ 76 | 77 | /* Begin PBXNativeTarget section */ 78 | 32F192EF13EA1BB800392701 /* challenge2 */ = { 79 | isa = PBXNativeTarget; 80 | buildConfigurationList = 32F192F913EA1BCB00392701 /* Build configuration list for PBXNativeTarget "challenge2" */; 81 | buildPhases = ( 82 | 32F192EC13EA1BB800392701 /* Sources */, 83 | 32F192ED13EA1BB800392701 /* Frameworks */, 84 | 32F192EE13EA1BB800392701 /* CopyFiles */, 85 | ); 86 | buildRules = ( 87 | ); 88 | dependencies = ( 89 | ); 90 | name = challenge2; 91 | productName = challenge2; 92 | productReference = 32F192F013EA1BBD00392701 /* challenge2 */; 93 | productType = "com.apple.product-type.tool"; 94 | }; 95 | /* End PBXNativeTarget section */ 96 | 97 | /* Begin PBXProject section */ 98 | 32F192E713EA1BAE00392701 /* Project object */ = { 99 | isa = PBXProject; 100 | buildConfigurationList = 32F192EA13EA1BAE00392701 /* Build configuration list for PBXProject "challenge2" */; 101 | compatibilityVersion = "Xcode 3.2"; 102 | developmentRegion = English; 103 | hasScannedForEncodings = 0; 104 | knownRegions = ( 105 | en, 106 | ); 107 | mainGroup = 32F192E513EA1BAD00392701; 108 | productRefGroup = 32F192F113EA1BBD00392701 /* Products */; 109 | projectDirPath = ""; 110 | projectRoot = ""; 111 | targets = ( 112 | 32F192EF13EA1BB800392701 /* challenge2 */, 113 | ); 114 | }; 115 | /* End PBXProject section */ 116 | 117 | /* Begin PBXSourcesBuildPhase section */ 118 | 32F192EC13EA1BB800392701 /* Sources */ = { 119 | isa = PBXSourcesBuildPhase; 120 | buildActionMask = 2147483647; 121 | files = ( 122 | 32F192F513EA1BC200392701 /* main.cpp in Sources */, 123 | ); 124 | runOnlyForDeploymentPostprocessing = 0; 125 | }; 126 | /* End PBXSourcesBuildPhase section */ 127 | 128 | /* Begin XCBuildConfiguration section */ 129 | 32F192F713EA1BCB00392701 /* Debug */ = { 130 | isa = XCBuildConfiguration; 131 | buildSettings = { 132 | ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; 133 | GCC_C_LANGUAGE_STANDARD = gnu99; 134 | GCC_OPTIMIZATION_LEVEL = 0; 135 | GCC_PREPROCESSOR_DEFINITIONS = DEBUG; 136 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 137 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0; 138 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 139 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 140 | GCC_WARN_UNUSED_VARIABLE = YES; 141 | MACOSX_DEPLOYMENT_TARGET = 10.6; 142 | ONLY_ACTIVE_ARCH = YES; 143 | SDKROOT = macosx; 144 | }; 145 | name = Debug; 146 | }; 147 | 32F192F813EA1BCB00392701 /* Release */ = { 148 | isa = XCBuildConfiguration; 149 | buildSettings = { 150 | ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; 151 | GCC_C_LANGUAGE_STANDARD = gnu99; 152 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0; 153 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 154 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 155 | GCC_WARN_UNUSED_VARIABLE = YES; 156 | MACOSX_DEPLOYMENT_TARGET = 10.6; 157 | SDKROOT = macosx; 158 | }; 159 | name = Release; 160 | }; 161 | 32F192FA13EA1BCB00392701 /* Debug */ = { 162 | isa = XCBuildConfiguration; 163 | buildSettings = { 164 | ALWAYS_SEARCH_USER_PATHS = NO; 165 | COPY_PHASE_STRIP = NO; 166 | GCC_DYNAMIC_NO_PIC = NO; 167 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 168 | PRODUCT_NAME = "$(TARGET_NAME)"; 169 | }; 170 | name = Debug; 171 | }; 172 | 32F192FB13EA1BCB00392701 /* Release */ = { 173 | isa = XCBuildConfiguration; 174 | buildSettings = { 175 | ALWAYS_SEARCH_USER_PATHS = NO; 176 | COPY_PHASE_STRIP = YES; 177 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 178 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 179 | PRODUCT_NAME = "$(TARGET_NAME)"; 180 | }; 181 | name = Release; 182 | }; 183 | /* End XCBuildConfiguration section */ 184 | 185 | /* Begin XCConfigurationList section */ 186 | 32F192EA13EA1BAE00392701 /* Build configuration list for PBXProject "challenge2" */ = { 187 | isa = XCConfigurationList; 188 | buildConfigurations = ( 189 | 32F192F713EA1BCB00392701 /* Debug */, 190 | 32F192F813EA1BCB00392701 /* Release */, 191 | ); 192 | defaultConfigurationIsVisible = 0; 193 | defaultConfigurationName = Release; 194 | }; 195 | 32F192F913EA1BCB00392701 /* Build configuration list for PBXNativeTarget "challenge2" */ = { 196 | isa = XCConfigurationList; 197 | buildConfigurations = ( 198 | 32F192FA13EA1BCB00392701 /* Debug */, 199 | 32F192FB13EA1BCB00392701 /* Release */, 200 | ); 201 | defaultConfigurationIsVisible = 0; 202 | }; 203 | /* End XCConfigurationList section */ 204 | }; 205 | rootObject = 32F192E713EA1BAE00392701 /* Project object */; 206 | } 207 | -------------------------------------------------------------------------------- /challenge2/challenge2/challenge2.1: -------------------------------------------------------------------------------- 1 | .\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples. 2 | .\"See Also: 3 | .\"man mdoc.samples for a complete listing of options 4 | .\"man mdoc for the short list of editing options 5 | .\"/usr/share/misc/mdoc.template 6 | .Dd 03/08/11 \" DATE 7 | .Dt challenge2 1 \" Program name and manual section number 8 | .Os Darwin 9 | .Sh NAME \" Section Header - required - don't modify 10 | .Nm challenge2, 11 | .\" The following lines are read in generating the apropos(man -k) database. Use only key 12 | .\" words here as the database is built based on the words here and in the .ND line. 13 | .Nm Other_name_for_same_program(), 14 | .Nm Yet another name for the same program. 15 | .\" Use .Nm macro to designate other names for the documented program. 16 | .Nd This line parsed for whatis database. 17 | .Sh SYNOPSIS \" Section Header - required - don't modify 18 | .Nm 19 | .Op Fl abcd \" [-abcd] 20 | .Op Fl a Ar path \" [-a path] 21 | .Op Ar file \" [file] 22 | .Op Ar \" [file ...] 23 | .Ar arg0 \" Underlined argument - use .Ar anywhere to underline 24 | arg2 ... \" Arguments 25 | .Sh DESCRIPTION \" Section Header - required - don't modify 26 | Use the .Nm macro to refer to your program throughout the man page like such: 27 | .Nm 28 | Underlining is accomplished with the .Ar macro like this: 29 | .Ar underlined text . 30 | .Pp \" Inserts a space 31 | A list of items with descriptions: 32 | .Bl -tag -width -indent \" Begins a tagged list 33 | .It item a \" Each item preceded by .It macro 34 | Description of item a 35 | .It item b 36 | Description of item b 37 | .El \" Ends the list 38 | .Pp 39 | A list of flags and their descriptions: 40 | .Bl -tag -width -indent \" Differs from above in tag removed 41 | .It Fl a \"-a flag as a list item 42 | Description of -a flag 43 | .It Fl b 44 | Description of -b flag 45 | .El \" Ends the list 46 | .Pp 47 | .\" .Sh ENVIRONMENT \" May not be needed 48 | .\" .Bl -tag -width "ENV_VAR_1" -indent \" ENV_VAR_1 is width of the string ENV_VAR_1 49 | .\" .It Ev ENV_VAR_1 50 | .\" Description of ENV_VAR_1 51 | .\" .It Ev ENV_VAR_2 52 | .\" Description of ENV_VAR_2 53 | .\" .El 54 | .Sh FILES \" File used or created by the topic of the man page 55 | .Bl -tag -width "/Users/joeuser/Library/really_long_file_name" -compact 56 | .It Pa /usr/share/file_name 57 | FILE_1 description 58 | .It Pa /Users/joeuser/Library/really_long_file_name 59 | FILE_2 description 60 | .El \" Ends the list 61 | .\" .Sh DIAGNOSTICS \" May not be needed 62 | .\" .Bl -diag 63 | .\" .It Diagnostic Tag 64 | .\" Diagnostic informtion here. 65 | .\" .It Diagnostic Tag 66 | .\" Diagnostic informtion here. 67 | .\" .El 68 | .Sh SEE ALSO 69 | .\" List links in ascending order by section, alphabetically within a section. 70 | .\" Please do not reference files that do not exist without filing a bug report 71 | .Xr a 1 , 72 | .Xr b 1 , 73 | .Xr c 1 , 74 | .Xr a 2 , 75 | .Xr b 2 , 76 | .Xr a 3 , 77 | .Xr b 3 78 | .\" .Sh BUGS \" Document known, unremedied bugs 79 | .\" .Sh HISTORY \" Document history if command behaves in a unique manner -------------------------------------------------------------------------------- /challenge2/challenge2/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | const int WINDOW_WIDTH = 600, WINDOW_HEIGHT = 400; 12 | const int XMIN = 100, XMAX = 500, YMIN = 100, YMAX = 300; 13 | 14 | const int LEFT = 1 << 0, RIGHT = 1 << 1, BELOW = 1 << 2, ABOVE = 1 << 3; 15 | 16 | void init (void) { 17 | glClearColor (0.0, 0.0, 0.0, 0.0); // Set display-window color to white. 18 | // Alpha 0.0 means transparency 19 | 20 | glMatrixMode (GL_PROJECTION); // Set projection parameters. 21 | // Other values are: 22 | // GL_MODELVIEW: Transform from world coordinates to camera coordinates 23 | // GL_PROJECTION: How to project from world to proection surface 24 | // GL_TEXTURE: How to map from texture to object 25 | gluOrtho2D (0.0, WINDOW_WIDTH - 1, 0.0, WINDOW_HEIGHT - 1); // Left, Right, Bottom, Top corners 26 | } 27 | 28 | void drawLine(int x0, int y0, int x1, int y1, double r = 1, double g = 1, double b = 1) { 29 | glBegin (GL_LINES); 30 | glColor3f (r, g, b); 31 | glVertex2i(x1, y1); 32 | glVertex2i(x0, y0); 33 | glEnd( ); 34 | } 35 | 36 | int code(int x, int y) { 37 | int mask = 0; 38 | if (x < XMIN) mask |= LEFT; 39 | if (x > XMAX) mask |= RIGHT; 40 | if (y < YMIN) mask |= BELOW; 41 | if (y > YMAX) mask |= ABOVE; 42 | return mask; 43 | } 44 | 45 | 46 | // Clips and draws the segment of the line that is inside the clipping area. 47 | // Returns: 48 | // 1 if the line was totally inside 49 | // 2 if the line was totally outside 50 | // 3 if the line was partially inside and partially outside 51 | 52 | int clipLine(int x0, int y0, int x1, int y1) { 53 | int c0 = code(x0, y0), c1 = code(x1, y1); 54 | if ((c0 | c1) == 0) { // both inside 55 | drawLine(x0, y0, x1, y1, 0, 1, 0); 56 | return 1; 57 | } 58 | 59 | if ((c0 & c1) != 0) { // both outside 60 | drawLine(x0, y0, x1, y1, 1, 0, 0); 61 | return 2; 62 | } 63 | 64 | int c = (c0 ? c0 : c1); // pick the code of one outer point 65 | 66 | int x, y; // Intersection point 67 | if (c & BELOW) { 68 | x = round(x0 + (YMIN - y0) * (x1 - x0) / (y1 - y0)); 69 | y = YMIN; 70 | } else if (c & ABOVE) { 71 | x = round(x0 + (YMAX - y0) * (x1 - x0) / (y1 - y0)); 72 | y = YMAX; 73 | } else if (c & LEFT) { 74 | x = XMIN; 75 | y = round(y0 + (y1 - y0) * (XMIN - x0) / (x1 - x0)); 76 | } else if (c & RIGHT) { 77 | x = XMAX; 78 | y = round(y0 + (y1 - y0) * (XMAX - x0) / (x1 - x0)); 79 | } else assert(false); 80 | c == c0 ? drawLine(x, y, x0, y0, 1, 0, 0) : drawLine(x, y, x1, y1, 1, 0, 0); 81 | return 2 | (c == c0 ? clipLine(x, y, x1, y1) : clipLine(x, y, x0, y0)); 82 | } 83 | 84 | void doEverything (void){ 85 | glClear (GL_COLOR_BUFFER_BIT); // Clear display window. 86 | 87 | // draw clipping area 88 | drawLine(XMIN, YMIN, XMAX, YMIN); 89 | drawLine(XMIN, YMAX, XMAX, YMAX); 90 | drawLine(XMAX, YMIN, XMAX, YMAX); 91 | drawLine(XMIN, YMIN, XMIN, YMAX); 92 | 93 | srand((unsigned int)time(NULL)); 94 | bool inside = false, outside = false, mixed = false; 95 | while (!inside || !outside || !mixed){ 96 | 97 | int x0 = rand() % WINDOW_WIDTH; 98 | int y0 = rand() % WINDOW_HEIGHT; 99 | 100 | int x1 = rand() % WINDOW_WIDTH; 101 | int y1 = rand() % WINDOW_HEIGHT; 102 | 103 | int where = clipLine(x0, y0, x1, y1); 104 | if (where == 1) inside = true; 105 | else if (where == 2) outside = true; 106 | else if (where == 3) mixed = true; 107 | else assert(false); 108 | } 109 | 110 | glFlush( ); // Process all OpenGL routines as quickly as possible. 111 | } 112 | 113 | int main (int argc, char** argv) { 114 | glutInit (&argc, argv); // Initialize GLUT. 115 | glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); // Set display mode. 116 | glutInitWindowPosition (50, 100); // Set top-left display-window position. 117 | glutInitWindowSize (WINDOW_WIDTH, WINDOW_HEIGHT); // Set display-window width and height. 118 | glutCreateWindow ("Cohen-Sutherland Line Clipping Algorithm"); // Create display window. 119 | 120 | init ( ); // Execute initialization procedure. 121 | glutDisplayFunc (doEverything); // Send graphics to display window. 122 | glutMainLoop ( ); // Display everything and wait. 123 | return 0; 124 | } -------------------------------------------------------------------------------- /challenge2/pack/Andrés Mejía.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge2/pack/Andrés Mejía.zip -------------------------------------------------------------------------------- /challenge2/pack/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | const int WINDOW_WIDTH = 600, WINDOW_HEIGHT = 400; 12 | const int XMIN = 100, XMAX = 500, YMIN = 100, YMAX = 300; 13 | 14 | const int LEFT = 1 << 0, RIGHT = 1 << 1, BELOW = 1 << 2, ABOVE = 1 << 3; 15 | 16 | void init (void) { 17 | glClearColor (0.0, 0.0, 0.0, 0.0); // Set display-window color to white. 18 | // Alpha 0.0 means transparency 19 | 20 | glMatrixMode (GL_PROJECTION); // Set projection parameters. 21 | // Other values are: 22 | // GL_MODELVIEW: Transform from world coordinates to camera coordinates 23 | // GL_PROJECTION: How to project from world to proection surface 24 | // GL_TEXTURE: How to map from texture to object 25 | gluOrtho2D (0.0, WINDOW_WIDTH - 1, 0.0, WINDOW_HEIGHT - 1); // Left, Right, Bottom, Top corners 26 | } 27 | 28 | void drawLine(int x0, int y0, int x1, int y1, double r = 1, double g = 1, double b = 1) { 29 | glBegin (GL_LINES); 30 | glColor3f (r, g, b); 31 | glVertex2i(x1, y1); 32 | glVertex2i(x0, y0); 33 | glEnd( ); 34 | } 35 | 36 | int code(int x, int y) { 37 | int mask = 0; 38 | if (x < XMIN) mask |= LEFT; 39 | if (x > XMAX) mask |= RIGHT; 40 | if (y < YMIN) mask |= BELOW; 41 | if (y > YMAX) mask |= ABOVE; 42 | return mask; 43 | } 44 | 45 | 46 | // Clips and draws the segment of the line that is inside the clipping area. 47 | // Returns: 48 | // 1 if the line was totally inside 49 | // 2 if the line was totally outside 50 | // 3 if the line was partially inside and partially outside 51 | 52 | int clipLine(int x0, int y0, int x1, int y1) { 53 | int c0 = code(x0, y0), c1 = code(x1, y1); 54 | if ((c0 | c1) == 0) { // both inside 55 | drawLine(x0, y0, x1, y1, 0, 1, 0); 56 | return 1; 57 | } 58 | 59 | if ((c0 & c1) != 0) { // both outside 60 | drawLine(x0, y0, x1, y1, 1, 0, 0); 61 | return 2; 62 | } 63 | 64 | int c = (c0 ? c0 : c1); // pick the code of one outer point 65 | 66 | int x, y; // Intersection point 67 | if (c & BELOW) { 68 | x = round(x0 + (YMIN - y0) * (x1 - x0) / (y1 - y0)); 69 | y = YMIN; 70 | } else if (c & ABOVE) { 71 | x = round(x0 + (YMAX - y0) * (x1 - x0) / (y1 - y0)); 72 | y = YMAX; 73 | } else if (c & LEFT) { 74 | x = XMIN; 75 | y = round(y0 + (y1 - y0) * (XMIN - x0) / (x1 - x0)); 76 | } else if (c & RIGHT) { 77 | x = XMAX; 78 | y = round(y0 + (y1 - y0) * (XMAX - x0) / (x1 - x0)); 79 | } else assert(false); 80 | c == c0 ? drawLine(x, y, x0, y0, 1, 0, 0) : drawLine(x, y, x1, y1, 1, 0, 0); 81 | return 2 | (c == c0 ? clipLine(x, y, x1, y1) : clipLine(x, y, x0, y0)); 82 | } 83 | 84 | void doEverything (void){ 85 | glClear (GL_COLOR_BUFFER_BIT); // Clear display window. 86 | 87 | // draw clipping area 88 | drawLine(XMIN, YMIN, XMAX, YMIN); 89 | drawLine(XMIN, YMAX, XMAX, YMAX); 90 | drawLine(XMAX, YMIN, XMAX, YMAX); 91 | drawLine(XMIN, YMIN, XMIN, YMAX); 92 | 93 | srand((unsigned int)time(NULL)); 94 | bool inside = false, outside = false, mixed = false; 95 | while (!inside || !outside || !mixed){ 96 | 97 | int x0 = rand() % WINDOW_WIDTH; 98 | int y0 = rand() % WINDOW_HEIGHT; 99 | 100 | int x1 = rand() % WINDOW_WIDTH; 101 | int y1 = rand() % WINDOW_HEIGHT; 102 | 103 | int where = clipLine(x0, y0, x1, y1); 104 | if (where == 1) inside = true; 105 | else if (where == 2) outside = true; 106 | else if (where == 3) mixed = true; 107 | else assert(false); 108 | } 109 | 110 | glFlush( ); // Process all OpenGL routines as quickly as possible. 111 | } 112 | 113 | int main (int argc, char** argv) { 114 | glutInit (&argc, argv); // Initialize GLUT. 115 | glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); // Set display mode. 116 | glutInitWindowPosition (50, 100); // Set top-left display-window position. 117 | glutInitWindowSize (WINDOW_WIDTH, WINDOW_HEIGHT); // Set display-window width and height. 118 | glutCreateWindow ("Cohen-Sutherland Line Clipping Algorithm"); // Create display window. 119 | 120 | init ( ); // Execute initialization procedure. 121 | glutDisplayFunc (doEverything); // Send graphics to display window. 122 | glutMainLoop ( ); // Display everything and wait. 123 | return 0; 124 | } -------------------------------------------------------------------------------- /challenge2/pack/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge2/pack/screenshot.png -------------------------------------------------------------------------------- /challenge3/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /challenge3/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Brazo 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /challenge3/README.md: -------------------------------------------------------------------------------- 1 | Challenge 3 2 | =========== 3 | 4 | Create a robotic arm with 3 articulations: shoulder, elbow and wrist. 5 | 6 | * The shoulder should rotate around the Y and Z axes. 7 | * The elbow should rotate around the Z axis. 8 | * The wrist should rotate around the X axis. 9 | 10 | Run it yourself 11 | --------------- 12 | 13 | cd src 14 | javac *.java 15 | java Arm 16 | 17 | On the window that appears, press: 18 | 19 | * `q` and `a` to increase or decrease the angle of rotation around the Y axis at the shoulder. 20 | * `w` and `s` to increase or decrease the angle of rotation around the Z axis at the shoulder. 21 | * `e` and `d` to increase or decrease the angle of rotation around the Z axis at the elbow. 22 | * `r` and `f` to increase or decrease the angle of rotation around the Z axis at the wrist. 23 | 24 | Screenshots 25 | ----------- 26 | 27 | ![Screenshot 1](https://github.com/andmej/computer_graphics_challenges/blob/master/challenge3/shots/1.png?raw=true) 28 | ![Screenshot 2](https://github.com/andmej/computer_graphics_challenges/blob/master/challenge3/shots/2.png?raw=true) 29 | ![Screenshot 3](https://github.com/andmej/computer_graphics_challenges/blob/master/challenge3/shots/3.png?raw=true) -------------------------------------------------------------------------------- /challenge3/bin/Arm.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge3/bin/Arm.class -------------------------------------------------------------------------------- /challenge3/bin/Bone.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge3/bin/Bone.class -------------------------------------------------------------------------------- /challenge3/bin/Hand.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge3/bin/Hand.class -------------------------------------------------------------------------------- /challenge3/bin/articulations/Articulation.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge3/bin/articulations/Articulation.class -------------------------------------------------------------------------------- /challenge3/bin/articulations/Elbow.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge3/bin/articulations/Elbow.class -------------------------------------------------------------------------------- /challenge3/bin/articulations/Shoulder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge3/bin/articulations/Shoulder.class -------------------------------------------------------------------------------- /challenge3/bin/articulations/Wrist.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge3/bin/articulations/Wrist.class -------------------------------------------------------------------------------- /challenge3/bin/java.policy.applet: -------------------------------------------------------------------------------- 1 | /* AUTOMATICALLY GENERATED ON Tue Apr 16 17:20:59 EDT 2002*/ 2 | /* DO NOT EDIT */ 3 | 4 | grant { 5 | permission java.security.AllPermission; 6 | }; 7 | 8 | -------------------------------------------------------------------------------- /challenge3/pack/README.md: -------------------------------------------------------------------------------- 1 | Challenge 3 - Andrés Mejía Posada 2 | ================================= 3 | 4 | Description 5 | ----------- 6 | 7 | Create a robotic arm with 3 articulations: shoulder, elbow and wrist. 8 | 9 | * The shoulder should rotate around the Y and Z axes. 10 | * The elbow should rotate around the Z axis. 11 | * The wrist should rotate around the X axis. 12 | 13 | Run it yourself 14 | --------------- 15 | 16 | cd src 17 | javac *.java 18 | java Arm 19 | 20 | On the window that appears, press: 21 | 22 | * `q` and `a` to increase or decrease the angle of rotation around the Y axis at the shoulder. 23 | * `w` and `s` to increase or decrease the angle of rotation around the Z axis at the shoulder. 24 | * `e` and `d` to increase or decrease the angle of rotation around the Z axis at the elbow. 25 | * `r` and `f` to increase or decrease the angle of rotation around the X axis at the wrist. 26 | 27 | Screenshots 28 | ----------- 29 | 30 | See the `shots` folder. -------------------------------------------------------------------------------- /challenge3/pack/bin/Arm.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge3/pack/bin/Arm.class -------------------------------------------------------------------------------- /challenge3/pack/bin/Bone.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge3/pack/bin/Bone.class -------------------------------------------------------------------------------- /challenge3/pack/bin/Hand.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge3/pack/bin/Hand.class -------------------------------------------------------------------------------- /challenge3/pack/bin/articulations/Articulation.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge3/pack/bin/articulations/Articulation.class -------------------------------------------------------------------------------- /challenge3/pack/bin/articulations/Elbow.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge3/pack/bin/articulations/Elbow.class -------------------------------------------------------------------------------- /challenge3/pack/bin/articulations/Shoulder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge3/pack/bin/articulations/Shoulder.class -------------------------------------------------------------------------------- /challenge3/pack/bin/articulations/Wrist.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge3/pack/bin/articulations/Wrist.class -------------------------------------------------------------------------------- /challenge3/pack/bin/java.policy.applet: -------------------------------------------------------------------------------- 1 | /* AUTOMATICALLY GENERATED ON Tue Apr 16 17:20:59 EDT 2002*/ 2 | /* DO NOT EDIT */ 3 | 4 | grant { 5 | permission java.security.AllPermission; 6 | }; 7 | 8 | -------------------------------------------------------------------------------- /challenge3/pack/challenge3.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge3/pack/challenge3.zip -------------------------------------------------------------------------------- /challenge3/pack/shots/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge3/pack/shots/1.png -------------------------------------------------------------------------------- /challenge3/pack/shots/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge3/pack/shots/2.png -------------------------------------------------------------------------------- /challenge3/pack/shots/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge3/pack/shots/3.png -------------------------------------------------------------------------------- /challenge3/pack/src/Arm.java: -------------------------------------------------------------------------------- 1 | /* 2 | * CuboRobot.java 3 | * Este programa demuestra el concepto de "Scenegraph". 4 | * Se arma un "dedo" articulado y el ángulo de rotación se cambia con las 5 | * flechas. 6 | */ 7 | 8 | import java.applet.Applet; 9 | import java.awt.BorderLayout; 10 | import java.awt.Frame; 11 | import java.awt.event.*; 12 | import java.awt.GraphicsConfiguration; 13 | 14 | import articulations.*; 15 | 16 | import com.sun.j3d.utils.applet.MainFrame; 17 | import com.sun.j3d.utils.universe.*; 18 | import com.sun.j3d.utils.geometry.ColorCube; 19 | import javax.media.j3d.*; 20 | import javax.vecmath.*; 21 | import java.awt.event.KeyEvent; 22 | 23 | 24 | // Este programa demuestra como usar el "scenegraph" de Java3D 25 | // para crear un "brazo" articulado de un robot. 26 | 27 | public class Arm extends Applet 28 | implements KeyListener { 29 | 30 | double increment = 4.5d*Math.PI/180d; 31 | double angulo = 0d; 32 | 33 | // Articulation 1 34 | Shoulder a1 = new Shoulder(); 35 | 36 | // Bone 1 37 | Bone s1 = new Bone(0.3d); 38 | 39 | // Articulation 2 40 | Elbow a2 = new Elbow(); 41 | 42 | // Bone 2 43 | Bone s2 = new Bone(0.3d); 44 | 45 | // Articulation 3 46 | Wrist a3 = new Wrist(); 47 | 48 | // Bone 3 49 | Bone s3 = new Hand(0.3d); 50 | 51 | public Arm() { 52 | setLayout(new BorderLayout()); 53 | GraphicsConfiguration config = 54 | SimpleUniverse.getPreferredConfiguration(); 55 | 56 | Canvas3D canvas3D = new Canvas3D(config); 57 | add("Center", canvas3D); 58 | canvas3D.addKeyListener(this); 59 | 60 | BranchGroup scene = createSceneGraph(); 61 | 62 | // SimpleUniverse is a Convenience Utility class 63 | SimpleUniverse simpleU = new SimpleUniverse(canvas3D); 64 | 65 | // This will move the ViewPlatform back a bit so the 66 | // objects in the scene can be viewed. 67 | simpleU.getViewingPlatform().setNominalViewingTransform(); 68 | 69 | simpleU.addBranchGraph(scene); 70 | } // end of HelloJava3Da (constructor) 71 | 72 | public BranchGroup createSceneGraph() { 73 | // Raiz de la escena 74 | BranchGroup objRoot = new BranchGroup(); 75 | 76 | // Subir la mitad de la longitud del primer segmento 77 | Transform3D t3d = new Transform3D(); 78 | t3d.set(new Vector3d()); 79 | TransformGroup tg0 = new TransformGroup(t3d); 80 | 81 | 82 | // Agregar la primera articulacion 83 | tg0.addChild(a1.getTransformGroup()); 84 | // Agregar el primer segmento 85 | a1.getTransformGroup().addChild(s1.getTransformGroup0()); 86 | // Agregar la segunda articulacion 87 | s1.getTransformGroup2().addChild(a2.getTransformGroup()); 88 | // Agregar el segundo segmento 89 | a2.getTransformGroup().addChild(s2.getTransformGroup0()); 90 | // Agregar la segunda articulacion 91 | s2.getTransformGroup2().addChild(a3.getTransformGroup()); 92 | // Agregar el segundo segmento 93 | a3.getTransformGroup().addChild(s3.getTransformGroup0()); 94 | // Agregar la raiz del arbol a la escena 95 | objRoot.addChild(tg0); 96 | 97 | 98 | return objRoot; 99 | } // end of CreateSceneGraph method of HelloJava3Da 100 | 101 | 102 | 103 | public void keyPressed(KeyEvent e) { 104 | 105 | if (e.getKeyCode() == KeyEvent.VK_Q) { 106 | System.out.println("Increase Y rotation at shoulder"); 107 | a1.increaseAngleY(increment); 108 | } 109 | if (e.getKeyCode() == KeyEvent.VK_A) { 110 | System.out.println("Decrease Y rotation at shoulder"); 111 | a1.increaseAngleY(-increment); 112 | } 113 | if (e.getKeyCode() == KeyEvent.VK_W) { 114 | System.out.println("Increase Z rotation at shoulder"); 115 | a1.increaseAngleZ(increment); 116 | } 117 | if (e.getKeyCode() == KeyEvent.VK_S) { 118 | System.out.println("Decrease Z rotation at shoulder"); 119 | a1.increaseAngleZ(-increment); 120 | } 121 | if (e.getKeyCode() == KeyEvent.VK_E) { 122 | System.out.println("Increase Z rotation at elbow"); 123 | a2.increaseAngleZ(increment); 124 | } 125 | if (e.getKeyCode() == KeyEvent.VK_D) { 126 | System.out.println("Decrease Z rotation at elbow"); 127 | a2.increaseAngleZ(-increment); 128 | } 129 | if (e.getKeyCode() == KeyEvent.VK_R) { 130 | System.out.println("Increase X rotation at wrist"); 131 | a3.increaseAngleX(increment); 132 | } 133 | if (e.getKeyCode() == KeyEvent.VK_F) { 134 | System.out.println("Decrease X rotation at wrist"); 135 | a3.increaseAngleX(-increment); 136 | } 137 | 138 | } 139 | 140 | public void keyReleased(KeyEvent e) { 141 | //System.out.println(e); 142 | } 143 | 144 | public void keyTyped(KeyEvent e) { 145 | //System.out.println(e); 146 | } 147 | 148 | public static void main(String[] args) { 149 | Frame frame = new MainFrame(new Arm(), 512, 512); 150 | } // end of main (method of HelloJava3Da) 151 | } 152 | -------------------------------------------------------------------------------- /challenge3/pack/src/Bone.java: -------------------------------------------------------------------------------- 1 | import javax.media.j3d.Transform3D; 2 | import javax.media.j3d.TransformGroup; 3 | import javax.vecmath.Vector3d; 4 | 5 | import com.sun.j3d.utils.geometry.ColorCube; 6 | 7 | /* 8 | * Bone 9 | * Esta clase constituye una "falange" del dedo. 10 | * tg0 es el comienzo de la falange 11 | * tg1 es el medio de la falange 12 | * tg2 es el fin de la falange 13 | */ 14 | public class Bone { 15 | double length; 16 | // tg0 es el grupo del cual se pega este segmento a la articulaci�n pap� 17 | // tg1 es el grupo al cual se pega el cubo de esta articulaci�n 18 | // tg2 es el grupo del cual se pega la articulaci�n hija 19 | TransformGroup tg0, tg1, tg2; 20 | Transform3D t3D; 21 | 22 | public Bone(double longitud) { 23 | this.length = longitud; 24 | t3D = new Transform3D(); 25 | t3D.set(new Vector3d(longitud/2d, 0d, 0d)); 26 | tg0 = new TransformGroup(); 27 | tg1 = new TransformGroup(t3D); 28 | Transform3D t3d11 = new Transform3D(); 29 | t3d11.setScale(new Vector3d(1d, .5d, .5d)); 30 | TransformGroup tg11 = new TransformGroup(t3d11); 31 | tg1.addChild(tg11); 32 | tg11.addChild(new ColorCube(longitud/2d)); 33 | tg0.addChild(tg1); 34 | tg2 = new TransformGroup(t3D); 35 | tg1.addChild(tg2); 36 | } 37 | 38 | public void setLongitud(double longitud) { 39 | this.length = longitud; 40 | } 41 | 42 | public double getLongitud() { 43 | return length; 44 | } 45 | 46 | public TransformGroup getTransformGroup0() { 47 | return tg0; 48 | } 49 | 50 | public TransformGroup getTransformGroup2() { 51 | return tg2; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /challenge3/pack/src/Hand.java: -------------------------------------------------------------------------------- 1 | import javax.media.j3d.Transform3D; 2 | import javax.media.j3d.TransformGroup; 3 | import javax.vecmath.Vector3d; 4 | 5 | import com.sun.j3d.utils.geometry.ColorCube; 6 | 7 | 8 | public class Hand extends Bone { 9 | public Hand(double length) { 10 | super(length); 11 | this.length = length; 12 | t3D = new Transform3D(); 13 | t3D.set(new Vector3d(length/2d, 0d, 0d)); 14 | 15 | tg0 = new TransformGroup(); 16 | tg1 = new TransformGroup(t3D); 17 | Transform3D t3d11 = new Transform3D(); 18 | t3d11.setScale(new Vector3d(1d, .7d, .1d)); 19 | TransformGroup tg11 = new TransformGroup(t3d11); 20 | tg1.addChild(tg11); 21 | tg11.addChild(new ColorCube(length/2d)); 22 | tg0.addChild(tg1); 23 | tg2 = new TransformGroup(t3D); 24 | tg1.addChild(tg2); 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /challenge3/pack/src/articulations/Articulation.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge3/pack/src/articulations/Articulation.java -------------------------------------------------------------------------------- /challenge3/pack/src/articulations/Elbow.java: -------------------------------------------------------------------------------- 1 | package articulations; 2 | 3 | import javax.media.j3d.Transform3D; 4 | 5 | public class Elbow extends Articulation { 6 | double angleZ; 7 | 8 | public Elbow() { 9 | super(); 10 | angleZ = 0.0; 11 | } 12 | 13 | public void setAngleZ(double newAngleZ){ 14 | angleZ = newAngleZ; 15 | updateTransform(); 16 | } 17 | 18 | public void increaseAngleZ(double by) { 19 | double newAngle = angleZ + by; 20 | newAngle = Math.max(newAngle, 0); 21 | newAngle = Math.min(newAngle, 135 * Math.PI / 180); 22 | setAngleZ(newAngle); 23 | } 24 | 25 | private void updateTransform() { 26 | t3D.rotZ(angleZ); 27 | tg.setTransform(t3D); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /challenge3/pack/src/articulations/Shoulder.java: -------------------------------------------------------------------------------- 1 | package articulations; 2 | 3 | import javax.media.j3d.Transform3D; 4 | 5 | public class Shoulder extends Articulation { 6 | double angleY, angleZ; 7 | 8 | public Shoulder() { 9 | super(); 10 | angleY = angleZ = 0.0; 11 | } 12 | 13 | public void setAngleY(double newAngleY){ 14 | angleY = newAngleY; 15 | updateTransform(); 16 | } 17 | 18 | public void setAngleZ(double newAngleZ){ 19 | angleZ = newAngleZ; 20 | updateTransform(); 21 | } 22 | 23 | public void increaseAngleY(double by) { 24 | double newAngle = angleY + by; 25 | newAngle = Math.min(newAngle, 0 * Math.PI/180); 26 | newAngle = Math.max(newAngle, -180*Math.PI/180.0); 27 | setAngleY(newAngle); 28 | } 29 | 30 | public void increaseAngleZ(double by) { 31 | double newAngle = angleZ + by; 32 | newAngle = Math.min(newAngle, 90*Math.PI/180.0); 33 | newAngle = Math.max(newAngle, -90*Math.PI/180.0); 34 | setAngleZ(newAngle); 35 | } 36 | 37 | private void updateTransform() { 38 | Transform3D y = new Transform3D(); 39 | y.rotY(angleY); 40 | Transform3D z = new Transform3D(); 41 | z.rotZ(angleZ); 42 | t3D.mul(y, z); 43 | tg.setTransform(t3D); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /challenge3/pack/src/articulations/Wrist.java: -------------------------------------------------------------------------------- 1 | package articulations; 2 | 3 | public class Wrist extends Articulation { 4 | double angleX; 5 | 6 | public Wrist() { 7 | super(); 8 | angleX = 0.0; 9 | } 10 | 11 | public void setAngleX(double newAngleX){ 12 | angleX = newAngleX; 13 | updateTransform(); 14 | } 15 | 16 | public void increaseAngleX(double by) { 17 | double newAngle = angleX + by; 18 | newAngle = Math.min(newAngle, 90 * Math.PI / 180); 19 | newAngle = Math.max(newAngle, -90 * Math.PI / 180); 20 | setAngleX(newAngle); 21 | } 22 | 23 | private void updateTransform() { 24 | t3D.rotX(angleX); 25 | tg.setTransform(t3D); 26 | } 27 | 28 | } 29 | 30 | -------------------------------------------------------------------------------- /challenge3/shots/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge3/shots/1.png -------------------------------------------------------------------------------- /challenge3/shots/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge3/shots/2.png -------------------------------------------------------------------------------- /challenge3/shots/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge3/shots/3.png -------------------------------------------------------------------------------- /challenge3/src/Arm.java: -------------------------------------------------------------------------------- 1 | /* 2 | * CuboRobot.java 3 | * Este programa demuestra el concepto de "Scenegraph". 4 | * Se arma un "dedo" articulado y el ángulo de rotación se cambia con las 5 | * flechas. 6 | */ 7 | 8 | import java.applet.Applet; 9 | import java.awt.BorderLayout; 10 | import java.awt.Frame; 11 | import java.awt.event.*; 12 | import java.awt.GraphicsConfiguration; 13 | 14 | import articulations.*; 15 | 16 | import com.sun.j3d.utils.applet.MainFrame; 17 | import com.sun.j3d.utils.universe.*; 18 | import com.sun.j3d.utils.geometry.ColorCube; 19 | import javax.media.j3d.*; 20 | import javax.vecmath.*; 21 | import java.awt.event.KeyEvent; 22 | 23 | 24 | // Este programa demuestra como usar el "scenegraph" de Java3D 25 | // para crear un "brazo" articulado de un robot. 26 | 27 | public class Arm extends Applet 28 | implements KeyListener { 29 | 30 | double increment = 4.5d*Math.PI/180d; 31 | double angulo = 0d; 32 | 33 | // Articulation 1 34 | Shoulder a1 = new Shoulder(); 35 | 36 | // Bone 1 37 | Bone s1 = new Bone(0.3d); 38 | 39 | // Articulation 2 40 | Elbow a2 = new Elbow(); 41 | 42 | // Bone 2 43 | Bone s2 = new Bone(0.3d); 44 | 45 | // Articulation 3 46 | Wrist a3 = new Wrist(); 47 | 48 | // Bone 3 49 | Bone s3 = new Hand(0.3d); 50 | 51 | public Arm() { 52 | setLayout(new BorderLayout()); 53 | GraphicsConfiguration config = 54 | SimpleUniverse.getPreferredConfiguration(); 55 | 56 | Canvas3D canvas3D = new Canvas3D(config); 57 | add("Center", canvas3D); 58 | canvas3D.addKeyListener(this); 59 | 60 | BranchGroup scene = createSceneGraph(); 61 | 62 | // SimpleUniverse is a Convenience Utility class 63 | SimpleUniverse simpleU = new SimpleUniverse(canvas3D); 64 | 65 | // This will move the ViewPlatform back a bit so the 66 | // objects in the scene can be viewed. 67 | simpleU.getViewingPlatform().setNominalViewingTransform(); 68 | 69 | simpleU.addBranchGraph(scene); 70 | } // end of HelloJava3Da (constructor) 71 | 72 | public BranchGroup createSceneGraph() { 73 | // Raiz de la escena 74 | BranchGroup objRoot = new BranchGroup(); 75 | 76 | // Subir la mitad de la longitud del primer segmento 77 | Transform3D t3d = new Transform3D(); 78 | t3d.set(new Vector3d()); 79 | TransformGroup tg0 = new TransformGroup(t3d); 80 | 81 | 82 | // Agregar la primera articulacion 83 | tg0.addChild(a1.getTransformGroup()); 84 | // Agregar el primer segmento 85 | a1.getTransformGroup().addChild(s1.getTransformGroup0()); 86 | // Agregar la segunda articulacion 87 | s1.getTransformGroup2().addChild(a2.getTransformGroup()); 88 | // Agregar el segundo segmento 89 | a2.getTransformGroup().addChild(s2.getTransformGroup0()); 90 | // Agregar la segunda articulacion 91 | s2.getTransformGroup2().addChild(a3.getTransformGroup()); 92 | // Agregar el segundo segmento 93 | a3.getTransformGroup().addChild(s3.getTransformGroup0()); 94 | // Agregar la raiz del arbol a la escena 95 | objRoot.addChild(tg0); 96 | 97 | 98 | return objRoot; 99 | } // end of CreateSceneGraph method of HelloJava3Da 100 | 101 | 102 | 103 | public void keyPressed(KeyEvent e) { 104 | 105 | if (e.getKeyCode() == KeyEvent.VK_Q) { 106 | System.out.println("Increase Y rotation at shoulder"); 107 | a1.increaseAngleY(increment); 108 | } 109 | if (e.getKeyCode() == KeyEvent.VK_A) { 110 | System.out.println("Decrease Y rotation at shoulder"); 111 | a1.increaseAngleY(-increment); 112 | } 113 | if (e.getKeyCode() == KeyEvent.VK_W) { 114 | System.out.println("Increase Z rotation at shoulder"); 115 | a1.increaseAngleZ(increment); 116 | } 117 | if (e.getKeyCode() == KeyEvent.VK_S) { 118 | System.out.println("Decrease Z rotation at shoulder"); 119 | a1.increaseAngleZ(-increment); 120 | } 121 | if (e.getKeyCode() == KeyEvent.VK_E) { 122 | System.out.println("Increase Z rotation at elbow"); 123 | a2.increaseAngleZ(increment); 124 | } 125 | if (e.getKeyCode() == KeyEvent.VK_D) { 126 | System.out.println("Decrease Z rotation at elbow"); 127 | a2.increaseAngleZ(-increment); 128 | } 129 | if (e.getKeyCode() == KeyEvent.VK_R) { 130 | System.out.println("Increase X rotation at wrist"); 131 | a3.increaseAngleX(increment); 132 | } 133 | if (e.getKeyCode() == KeyEvent.VK_F) { 134 | System.out.println("Decrease X rotation at wrist"); 135 | a3.increaseAngleX(-increment); 136 | } 137 | 138 | } 139 | 140 | public void keyReleased(KeyEvent e) { 141 | //System.out.println(e); 142 | } 143 | 144 | public void keyTyped(KeyEvent e) { 145 | //System.out.println(e); 146 | } 147 | 148 | public static void main(String[] args) { 149 | Frame frame = new MainFrame(new Arm(), 512, 512); 150 | } // end of main (method of HelloJava3Da) 151 | } 152 | -------------------------------------------------------------------------------- /challenge3/src/Bone.java: -------------------------------------------------------------------------------- 1 | import javax.media.j3d.Transform3D; 2 | import javax.media.j3d.TransformGroup; 3 | import javax.vecmath.Vector3d; 4 | 5 | import com.sun.j3d.utils.geometry.ColorCube; 6 | 7 | /* 8 | * Bone 9 | * Esta clase constituye una "falange" del dedo. 10 | * tg0 es el comienzo de la falange 11 | * tg1 es el medio de la falange 12 | * tg2 es el fin de la falange 13 | */ 14 | public class Bone { 15 | double length; 16 | // tg0 es el grupo del cual se pega este segmento a la articulaci�n pap� 17 | // tg1 es el grupo al cual se pega el cubo de esta articulaci�n 18 | // tg2 es el grupo del cual se pega la articulaci�n hija 19 | TransformGroup tg0, tg1, tg2; 20 | Transform3D t3D; 21 | 22 | public Bone(double longitud) { 23 | this.length = longitud; 24 | t3D = new Transform3D(); 25 | t3D.set(new Vector3d(longitud/2d, 0d, 0d)); 26 | tg0 = new TransformGroup(); 27 | tg1 = new TransformGroup(t3D); 28 | Transform3D t3d11 = new Transform3D(); 29 | t3d11.setScale(new Vector3d(1d, .5d, .5d)); 30 | TransformGroup tg11 = new TransformGroup(t3d11); 31 | tg1.addChild(tg11); 32 | tg11.addChild(new ColorCube(longitud/2d)); 33 | tg0.addChild(tg1); 34 | tg2 = new TransformGroup(t3D); 35 | tg1.addChild(tg2); 36 | } 37 | 38 | public void setLongitud(double longitud) { 39 | this.length = longitud; 40 | } 41 | 42 | public double getLongitud() { 43 | return length; 44 | } 45 | 46 | public TransformGroup getTransformGroup0() { 47 | return tg0; 48 | } 49 | 50 | public TransformGroup getTransformGroup2() { 51 | return tg2; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /challenge3/src/Hand.java: -------------------------------------------------------------------------------- 1 | import javax.media.j3d.Transform3D; 2 | import javax.media.j3d.TransformGroup; 3 | import javax.vecmath.Vector3d; 4 | 5 | import com.sun.j3d.utils.geometry.ColorCube; 6 | 7 | 8 | public class Hand extends Bone { 9 | public Hand(double length) { 10 | super(length); 11 | this.length = length; 12 | t3D = new Transform3D(); 13 | t3D.set(new Vector3d(length/2d, 0d, 0d)); 14 | 15 | tg0 = new TransformGroup(); 16 | tg1 = new TransformGroup(t3D); 17 | Transform3D t3d11 = new Transform3D(); 18 | t3d11.setScale(new Vector3d(1d, .7d, .1d)); 19 | TransformGroup tg11 = new TransformGroup(t3d11); 20 | tg1.addChild(tg11); 21 | tg11.addChild(new ColorCube(length/2d)); 22 | tg0.addChild(tg1); 23 | tg2 = new TransformGroup(t3D); 24 | tg1.addChild(tg2); 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /challenge3/src/articulations/Articulation.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge3/src/articulations/Articulation.java -------------------------------------------------------------------------------- /challenge3/src/articulations/Elbow.java: -------------------------------------------------------------------------------- 1 | package articulations; 2 | 3 | import javax.media.j3d.Transform3D; 4 | 5 | public class Elbow extends Articulation { 6 | double angleZ; 7 | 8 | public Elbow() { 9 | super(); 10 | angleZ = 0.0; 11 | } 12 | 13 | public void setAngleZ(double newAngleZ){ 14 | angleZ = newAngleZ; 15 | updateTransform(); 16 | } 17 | 18 | public void increaseAngleZ(double by) { 19 | double newAngle = angleZ + by; 20 | newAngle = Math.max(newAngle, 0); 21 | newAngle = Math.min(newAngle, 135 * Math.PI / 180); 22 | setAngleZ(newAngle); 23 | } 24 | 25 | private void updateTransform() { 26 | t3D.rotZ(angleZ); 27 | tg.setTransform(t3D); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /challenge3/src/articulations/Shoulder.java: -------------------------------------------------------------------------------- 1 | package articulations; 2 | 3 | import javax.media.j3d.Transform3D; 4 | 5 | public class Shoulder extends Articulation { 6 | double angleY, angleZ; 7 | 8 | public Shoulder() { 9 | super(); 10 | angleY = angleZ = 0.0; 11 | } 12 | 13 | public void setAngleY(double newAngleY){ 14 | angleY = newAngleY; 15 | updateTransform(); 16 | } 17 | 18 | public void setAngleZ(double newAngleZ){ 19 | angleZ = newAngleZ; 20 | updateTransform(); 21 | } 22 | 23 | public void increaseAngleY(double by) { 24 | double newAngle = angleY + by; 25 | newAngle = Math.min(newAngle, 0 * Math.PI/180); 26 | newAngle = Math.max(newAngle, -180*Math.PI/180.0); 27 | setAngleY(newAngle); 28 | } 29 | 30 | public void increaseAngleZ(double by) { 31 | double newAngle = angleZ + by; 32 | newAngle = Math.min(newAngle, 90*Math.PI/180.0); 33 | newAngle = Math.max(newAngle, -90*Math.PI/180.0); 34 | setAngleZ(newAngle); 35 | } 36 | 37 | private void updateTransform() { 38 | Transform3D y = new Transform3D(); 39 | y.rotY(angleY); 40 | Transform3D z = new Transform3D(); 41 | z.rotZ(angleZ); 42 | t3D.mul(y, z); 43 | tg.setTransform(t3D); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /challenge3/src/articulations/Wrist.java: -------------------------------------------------------------------------------- 1 | package articulations; 2 | 3 | public class Wrist extends Articulation { 4 | double angleX; 5 | 6 | public Wrist() { 7 | super(); 8 | angleX = 0.0; 9 | } 10 | 11 | public void setAngleX(double newAngleX){ 12 | angleX = newAngleX; 13 | updateTransform(); 14 | } 15 | 16 | public void increaseAngleX(double by) { 17 | double newAngle = angleX + by; 18 | newAngle = Math.min(newAngle, 90 * Math.PI / 180); 19 | newAngle = Math.max(newAngle, -90 * Math.PI / 180); 20 | setAngleX(newAngle); 21 | } 22 | 23 | private void updateTransform() { 24 | t3D.rotX(angleX); 25 | tg.setTransform(t3D); 26 | } 27 | 28 | } 29 | 30 | -------------------------------------------------------------------------------- /challenge4/README.md: -------------------------------------------------------------------------------- 1 | Challenge 4 2 | =========== 3 | 4 | Create a robotic arm in OpenGL with 3 articulations: shoulder, elbow and wrist. 5 | 6 | * The shoulder should rotate around the Y and Z axes. 7 | * The elbow should rotate around the Z axis. 8 | * The wrist should rotate around the X and Z axes. 9 | 10 | Run it yourself 11 | --------------- 12 | 13 | These instructions are for Mac OS X. Your mileage may vary. 14 | 15 | cd challenge4/src 16 | g++ main.cpp -framework GLUT -framework OpenGL -o arm 17 | ./arm 18 | 19 | On the window that appears, press: 20 | 21 | * `q` and `a` to increase or decrease the angle of rotation around the Y axis at the shoulder. 22 | * `w` and `s` to increase or decrease the angle of rotation around the Z axis at the shoulder. 23 | * `e` and `d` to increase or decrease the angle of rotation around the Z axis at the elbow. 24 | * `r` and `f` to increase or decrease the angle of rotation around the Z axis at the wrist. 25 | * `t` and `g` to increase or decrease the angle of rotation around the X axis at the wrist. 26 | * `↑` and `↓` to increase or decrease the camera's distance to the object. 27 | * `←` and `→` to increase or decrease the camera's angle of rotation around the Z axis. 28 | 29 | Screenshot 30 | ----------- 31 | 32 | ![Screenshot](https://github.com/andmej/computer_graphics_challenges/blob/master/challenge4/shots/shot.png?raw=true) 33 | 34 | 35 | Video demo 36 | ----------- 37 | 38 | See the [video demo on YouTube](http://www.youtube.com/watch?v=SfxGiCqAHNg). -------------------------------------------------------------------------------- /challenge4/challenge4/challenge4.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 32E661EC141D5C2900730D74 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 32E661EB141D5C2900730D74 /* main.cpp */; }; 11 | 32FFEAED141D263A00CA0312 /* GLUT.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 32FFEAEC141D263A00CA0312 /* GLUT.framework */; }; 12 | 32FFEAEF141D264300CA0312 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 32FFEAEE141D264300CA0312 /* OpenGL.framework */; }; 13 | /* End PBXBuildFile section */ 14 | 15 | /* Begin PBXCopyFilesBuildPhase section */ 16 | 32FFEADE141D25FF00CA0312 /* CopyFiles */ = { 17 | isa = PBXCopyFilesBuildPhase; 18 | buildActionMask = 2147483647; 19 | dstPath = /usr/share/man/man1/; 20 | dstSubfolderSpec = 0; 21 | files = ( 22 | ); 23 | runOnlyForDeploymentPostprocessing = 1; 24 | }; 25 | /* End PBXCopyFilesBuildPhase section */ 26 | 27 | /* Begin PBXFileReference section */ 28 | 32E661EA141D5C2900730D74 /* challenge4.1 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.man; path = challenge4.1; sourceTree = ""; }; 29 | 32E661EB141D5C2900730D74 /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = ""; }; 30 | 32FFEAE0141D25FF00CA0312 /* challenge4 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = challenge4; sourceTree = BUILT_PRODUCTS_DIR; }; 31 | 32FFEAEC141D263A00CA0312 /* GLUT.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GLUT.framework; path = System/Library/Frameworks/GLUT.framework; sourceTree = SDKROOT; }; 32 | 32FFEAEE141D264300CA0312 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = System/Library/Frameworks/OpenGL.framework; sourceTree = SDKROOT; }; 33 | /* End PBXFileReference section */ 34 | 35 | /* Begin PBXFrameworksBuildPhase section */ 36 | 32FFEADD141D25FF00CA0312 /* Frameworks */ = { 37 | isa = PBXFrameworksBuildPhase; 38 | buildActionMask = 2147483647; 39 | files = ( 40 | 32FFEAEF141D264300CA0312 /* OpenGL.framework in Frameworks */, 41 | 32FFEAED141D263A00CA0312 /* GLUT.framework in Frameworks */, 42 | ); 43 | runOnlyForDeploymentPostprocessing = 0; 44 | }; 45 | /* End PBXFrameworksBuildPhase section */ 46 | 47 | /* Begin PBXGroup section */ 48 | 32E661E9141D5C2900730D74 /* Source */ = { 49 | isa = PBXGroup; 50 | children = ( 51 | 32E661EA141D5C2900730D74 /* challenge4.1 */, 52 | 32E661EB141D5C2900730D74 /* main.cpp */, 53 | ); 54 | name = Source; 55 | path = src; 56 | sourceTree = ""; 57 | }; 58 | 32FFEAD5141D25FF00CA0312 = { 59 | isa = PBXGroup; 60 | children = ( 61 | 32E661E9141D5C2900730D74 /* Source */, 62 | 32FFEAEE141D264300CA0312 /* OpenGL.framework */, 63 | 32FFEAEC141D263A00CA0312 /* GLUT.framework */, 64 | 32FFEAE1141D25FF00CA0312 /* Products */, 65 | ); 66 | sourceTree = ""; 67 | }; 68 | 32FFEAE1141D25FF00CA0312 /* Products */ = { 69 | isa = PBXGroup; 70 | children = ( 71 | 32FFEAE0141D25FF00CA0312 /* challenge4 */, 72 | ); 73 | name = Products; 74 | sourceTree = ""; 75 | }; 76 | /* End PBXGroup section */ 77 | 78 | /* Begin PBXNativeTarget section */ 79 | 32FFEADF141D25FF00CA0312 /* challenge4 */ = { 80 | isa = PBXNativeTarget; 81 | buildConfigurationList = 32FFEAE9141D25FF00CA0312 /* Build configuration list for PBXNativeTarget "challenge4" */; 82 | buildPhases = ( 83 | 32FFEADC141D25FF00CA0312 /* Sources */, 84 | 32FFEADD141D25FF00CA0312 /* Frameworks */, 85 | 32FFEADE141D25FF00CA0312 /* CopyFiles */, 86 | ); 87 | buildRules = ( 88 | ); 89 | dependencies = ( 90 | ); 91 | name = challenge4; 92 | productName = challenge4; 93 | productReference = 32FFEAE0141D25FF00CA0312 /* challenge4 */; 94 | productType = "com.apple.product-type.tool"; 95 | }; 96 | /* End PBXNativeTarget section */ 97 | 98 | /* Begin PBXProject section */ 99 | 32FFEAD7141D25FF00CA0312 /* Project object */ = { 100 | isa = PBXProject; 101 | buildConfigurationList = 32FFEADA141D25FF00CA0312 /* Build configuration list for PBXProject "challenge4" */; 102 | compatibilityVersion = "Xcode 3.2"; 103 | developmentRegion = English; 104 | hasScannedForEncodings = 0; 105 | knownRegions = ( 106 | en, 107 | ); 108 | mainGroup = 32FFEAD5141D25FF00CA0312; 109 | productRefGroup = 32FFEAE1141D25FF00CA0312 /* Products */; 110 | projectDirPath = ""; 111 | projectRoot = ""; 112 | targets = ( 113 | 32FFEADF141D25FF00CA0312 /* challenge4 */, 114 | ); 115 | }; 116 | /* End PBXProject section */ 117 | 118 | /* Begin PBXSourcesBuildPhase section */ 119 | 32FFEADC141D25FF00CA0312 /* Sources */ = { 120 | isa = PBXSourcesBuildPhase; 121 | buildActionMask = 2147483647; 122 | files = ( 123 | 32E661EC141D5C2900730D74 /* main.cpp in Sources */, 124 | ); 125 | runOnlyForDeploymentPostprocessing = 0; 126 | }; 127 | /* End PBXSourcesBuildPhase section */ 128 | 129 | /* Begin XCBuildConfiguration section */ 130 | 32FFEAE7141D25FF00CA0312 /* Debug */ = { 131 | isa = XCBuildConfiguration; 132 | buildSettings = { 133 | ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; 134 | GCC_C_LANGUAGE_STANDARD = gnu99; 135 | GCC_OPTIMIZATION_LEVEL = 0; 136 | GCC_PREPROCESSOR_DEFINITIONS = DEBUG; 137 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 138 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0; 139 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 140 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 141 | GCC_WARN_UNUSED_VARIABLE = YES; 142 | MACOSX_DEPLOYMENT_TARGET = 10.6; 143 | ONLY_ACTIVE_ARCH = YES; 144 | SDKROOT = macosx; 145 | }; 146 | name = Debug; 147 | }; 148 | 32FFEAE8141D25FF00CA0312 /* Release */ = { 149 | isa = XCBuildConfiguration; 150 | buildSettings = { 151 | ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; 152 | GCC_C_LANGUAGE_STANDARD = gnu99; 153 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0; 154 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 155 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 156 | GCC_WARN_UNUSED_VARIABLE = YES; 157 | MACOSX_DEPLOYMENT_TARGET = 10.6; 158 | SDKROOT = macosx; 159 | }; 160 | name = Release; 161 | }; 162 | 32FFEAEA141D25FF00CA0312 /* Debug */ = { 163 | isa = XCBuildConfiguration; 164 | buildSettings = { 165 | ALWAYS_SEARCH_USER_PATHS = NO; 166 | COPY_PHASE_STRIP = NO; 167 | GCC_DYNAMIC_NO_PIC = NO; 168 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 169 | PRODUCT_NAME = "$(TARGET_NAME)"; 170 | }; 171 | name = Debug; 172 | }; 173 | 32FFEAEB141D25FF00CA0312 /* Release */ = { 174 | isa = XCBuildConfiguration; 175 | buildSettings = { 176 | ALWAYS_SEARCH_USER_PATHS = NO; 177 | COPY_PHASE_STRIP = YES; 178 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 179 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 180 | PRODUCT_NAME = "$(TARGET_NAME)"; 181 | }; 182 | name = Release; 183 | }; 184 | /* End XCBuildConfiguration section */ 185 | 186 | /* Begin XCConfigurationList section */ 187 | 32FFEADA141D25FF00CA0312 /* Build configuration list for PBXProject "challenge4" */ = { 188 | isa = XCConfigurationList; 189 | buildConfigurations = ( 190 | 32FFEAE7141D25FF00CA0312 /* Debug */, 191 | 32FFEAE8141D25FF00CA0312 /* Release */, 192 | ); 193 | defaultConfigurationIsVisible = 0; 194 | defaultConfigurationName = Release; 195 | }; 196 | 32FFEAE9141D25FF00CA0312 /* Build configuration list for PBXNativeTarget "challenge4" */ = { 197 | isa = XCConfigurationList; 198 | buildConfigurations = ( 199 | 32FFEAEA141D25FF00CA0312 /* Debug */, 200 | 32FFEAEB141D25FF00CA0312 /* Release */, 201 | ); 202 | defaultConfigurationIsVisible = 0; 203 | defaultConfigurationName = Release; 204 | }; 205 | /* End XCConfigurationList section */ 206 | }; 207 | rootObject = 32FFEAD7141D25FF00CA0312 /* Project object */; 208 | } 209 | -------------------------------------------------------------------------------- /challenge4/challenge4/src/arm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge4/challenge4/src/arm -------------------------------------------------------------------------------- /challenge4/challenge4/src/challenge4.1: -------------------------------------------------------------------------------- 1 | .\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples. 2 | .\"See Also: 3 | .\"man mdoc.samples for a complete listing of options 4 | .\"man mdoc for the short list of editing options 5 | .\"/usr/share/misc/mdoc.template 6 | .Dd 11/09/11 \" DATE 7 | .Dt challenge4 1 \" Program name and manual section number 8 | .Os Darwin 9 | .Sh NAME \" Section Header - required - don't modify 10 | .Nm challenge4, 11 | .\" The following lines are read in generating the apropos(man -k) database. Use only key 12 | .\" words here as the database is built based on the words here and in the .ND line. 13 | .Nm Other_name_for_same_program(), 14 | .Nm Yet another name for the same program. 15 | .\" Use .Nm macro to designate other names for the documented program. 16 | .Nd This line parsed for whatis database. 17 | .Sh SYNOPSIS \" Section Header - required - don't modify 18 | .Nm 19 | .Op Fl abcd \" [-abcd] 20 | .Op Fl a Ar path \" [-a path] 21 | .Op Ar file \" [file] 22 | .Op Ar \" [file ...] 23 | .Ar arg0 \" Underlined argument - use .Ar anywhere to underline 24 | arg2 ... \" Arguments 25 | .Sh DESCRIPTION \" Section Header - required - don't modify 26 | Use the .Nm macro to refer to your program throughout the man page like such: 27 | .Nm 28 | Underlining is accomplished with the .Ar macro like this: 29 | .Ar underlined text . 30 | .Pp \" Inserts a space 31 | A list of items with descriptions: 32 | .Bl -tag -width -indent \" Begins a tagged list 33 | .It item a \" Each item preceded by .It macro 34 | Description of item a 35 | .It item b 36 | Description of item b 37 | .El \" Ends the list 38 | .Pp 39 | A list of flags and their descriptions: 40 | .Bl -tag -width -indent \" Differs from above in tag removed 41 | .It Fl a \"-a flag as a list item 42 | Description of -a flag 43 | .It Fl b 44 | Description of -b flag 45 | .El \" Ends the list 46 | .Pp 47 | .\" .Sh ENVIRONMENT \" May not be needed 48 | .\" .Bl -tag -width "ENV_VAR_1" -indent \" ENV_VAR_1 is width of the string ENV_VAR_1 49 | .\" .It Ev ENV_VAR_1 50 | .\" Description of ENV_VAR_1 51 | .\" .It Ev ENV_VAR_2 52 | .\" Description of ENV_VAR_2 53 | .\" .El 54 | .Sh FILES \" File used or created by the topic of the man page 55 | .Bl -tag -width "/Users/joeuser/Library/really_long_file_name" -compact 56 | .It Pa /usr/share/file_name 57 | FILE_1 description 58 | .It Pa /Users/joeuser/Library/really_long_file_name 59 | FILE_2 description 60 | .El \" Ends the list 61 | .\" .Sh DIAGNOSTICS \" May not be needed 62 | .\" .Bl -diag 63 | .\" .It Diagnostic Tag 64 | .\" Diagnostic informtion here. 65 | .\" .It Diagnostic Tag 66 | .\" Diagnostic informtion here. 67 | .\" .El 68 | .Sh SEE ALSO 69 | .\" List links in ascending order by section, alphabetically within a section. 70 | .\" Please do not reference files that do not exist without filing a bug report 71 | .Xr a 1 , 72 | .Xr b 1 , 73 | .Xr c 1 , 74 | .Xr a 2 , 75 | .Xr b 2 , 76 | .Xr a 3 , 77 | .Xr b 3 78 | .\" .Sh BUGS \" Document known, unremedied bugs 79 | .\" .Sh HISTORY \" Document history if command behaves in a unique manner -------------------------------------------------------------------------------- /challenge4/challenge4/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace std; 12 | 13 | GLfloat cameraDistance = 12, cameraAngle = 0; 14 | 15 | // angles = { Y rotation at shoulder, Z rotation at shoulder, Z rotation at elbow, X rotation at wrist } 16 | int arm_angles[5] = {0, 0, 0, 0, 0}; 17 | enum { SHOULDER_Y, SHOULDER_Z, ELBOW_Z, WRIST_X, WRIST_Z }; 18 | 19 | void change_angle(int angle, int delta, int minimum = 0, int maximum = 180) { 20 | arm_angles[angle] = (arm_angles[angle] + delta) % 360; 21 | arm_angles[angle] = max(arm_angles[angle], minimum); 22 | arm_angles[angle] = min(arm_angles[angle], maximum); 23 | } 24 | 25 | // Desplegar la escena 3D 26 | void display(void) { 27 | glClear(GL_COLOR_BUFFER_BIT); 28 | 29 | glLoadIdentity(); 30 | GLfloat x = cameraDistance * sin(cameraAngle); 31 | GLfloat z = cameraDistance * cos(cameraAngle); 32 | gluLookAt (x, 0.0, z, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); 33 | 34 | 35 | glPushMatrix(); 36 | glRotatef((GLfloat) arm_angles[SHOULDER_Y], 0., 1., 0.); 37 | glRotatef((GLfloat) arm_angles[SHOULDER_Z], 0., 0., 1.); 38 | 39 | glTranslatef(1., 0., 0.); 40 | glPushMatrix(); 41 | glScalef(2.0, 0.4, 1.0); 42 | glColor3f(1.0f, 1.0f, 1.0f); 43 | glutWireCube(1.); // shoulder 44 | glPopMatrix(); 45 | 46 | glTranslatef(1., 0., 0.); 47 | glRotatef((GLfloat) arm_angles[ELBOW_Z], 0., 0., 1.); 48 | glTranslatef(1., 0., 0.); 49 | glPushMatrix(); 50 | glScalef(2.0, 0.4, 1.0); 51 | glColor3f(249./255., 238./255., 153./255.); 52 | glutWireCube(1.); // elbow 53 | glPopMatrix(); 54 | 55 | glTranslatef(1., 0., 0.); 56 | glRotatef((GLfloat) arm_angles[WRIST_Z], 0., 0., 1.); 57 | glRotatef((GLfloat) arm_angles[WRIST_X], 1., 0., 0.); 58 | 59 | glTranslatef(1., 0., 0.); 60 | glPushMatrix(); 61 | glScalef(2.0, 0.4, 1.0); 62 | glColor3f(207./255., 106./255., 76./255.); 63 | glutWireCube(1.); // wrist 64 | glPopMatrix(); 65 | glPopMatrix(); 66 | 67 | // Ejecutar los comandos 68 | glutSwapBuffers(); 69 | } 70 | 71 | 72 | // Se llama cuando cambia el tamaño de la ventana 73 | void reshape(GLsizei w, GLsizei h) { 74 | // Tamanyo del viewport 75 | glViewport(0, 0, w, h); 76 | 77 | glMatrixMode(GL_PROJECTION); 78 | glLoadIdentity(); 79 | 80 | glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 300.0); 81 | 82 | glMatrixMode(GL_MODELVIEW); 83 | glLoadIdentity(); 84 | } 85 | 86 | // Responder a los eventos de teclas especiales 87 | void specialKeys(int key, int x, int y) { 88 | GLfloat distanceDelta = 1.0, angleDelta = 5 * M_PI / 180.0; 89 | if(key == GLUT_KEY_UP) { 90 | cameraDistance -= distanceDelta; 91 | cameraDistance = max((GLfloat)2.0, cameraDistance); 92 | } 93 | if(key == GLUT_KEY_DOWN) { 94 | cameraDistance += distanceDelta; 95 | } 96 | if(key == GLUT_KEY_LEFT) { 97 | cameraAngle -= angleDelta; 98 | } 99 | if(key == GLUT_KEY_RIGHT) { 100 | cameraAngle += angleDelta; 101 | } 102 | glutPostRedisplay(); 103 | } 104 | 105 | void keyboard(unsigned char key, int x, int y) { 106 | int delta = 5; 107 | 108 | switch (key) { 109 | case 27: //ESC 110 | exit(0); 111 | case 'q': 112 | change_angle(SHOULDER_Y, delta, -180, 0); 113 | break; 114 | case 'a': 115 | change_angle(SHOULDER_Y, -delta, -180, 0); 116 | break; 117 | case 'w': 118 | change_angle(SHOULDER_Z, delta, -90, 90); 119 | break; 120 | case 's': 121 | change_angle(SHOULDER_Z, -delta, -90, 90); 122 | break; 123 | case 'e': 124 | change_angle(ELBOW_Z, delta, 0, 135); 125 | break; 126 | case 'd': 127 | change_angle(ELBOW_Z, -delta, 0, 135); 128 | break; 129 | case 'r': 130 | change_angle(WRIST_X, delta, -45, 45); 131 | break; 132 | case 'f': 133 | change_angle(WRIST_X, -delta, -45, 45); 134 | break; 135 | case 't': 136 | change_angle(WRIST_Z, delta, -15, 90); 137 | break; 138 | case 'g': 139 | change_angle(WRIST_Z, -delta, -15, 90); 140 | break; 141 | } 142 | glutPostRedisplay(); 143 | } 144 | 145 | 146 | // Programa Principal 147 | int main(int argc, char * argv[]) { 148 | glutInit(&argc, argv); 149 | glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); 150 | glutInitWindowSize(700, 700); 151 | glutCreateWindow("Brazo Robot"); 152 | glutDisplayFunc(display); 153 | glutReshapeFunc(reshape); 154 | glutSpecialFunc(specialKeys); 155 | glutKeyboardFunc(keyboard); 156 | 157 | // Inicialización 158 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Negro 159 | 160 | glutMainLoop(); 161 | } 162 | 163 | -------------------------------------------------------------------------------- /challenge4/demo.mov: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge4/demo.mov -------------------------------------------------------------------------------- /challenge4/examples/cube.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1993-1997, Silicon Graphics, Inc. 3 | * ALL RIGHTS RESERVED 4 | * Permission to use, copy, modify, and distribute this software for 5 | * any purpose and without fee is hereby granted, provided that the above 6 | * copyright notice appear in all copies and that both the copyright notice 7 | * and this permission notice appear in supporting documentation, and that 8 | * the name of Silicon Graphics, Inc. not be used in advertising 9 | * or publicity pertaining to distribution of the software without specific, 10 | * written prior permission. 11 | * 12 | * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" 13 | * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, 14 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR 15 | * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON 16 | * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, 17 | * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY 18 | * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, 19 | * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF 20 | * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN 21 | * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE 23 | * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. 24 | * 25 | * US Government Users Restricted Rights 26 | * Use, duplication, or disclosure by the Government is subject to 27 | * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph 28 | * (c)(1)(ii) of the Rights in Technical Data and Computer Software 29 | * clause at DFARS 252.227-7013 and/or in similar or successor 30 | * clauses in the FAR or the DOD or NASA FAR Supplement. 31 | * Unpublished-- rights reserved under the copyright laws of the 32 | * United States. Contractor/manufacturer is Silicon Graphics, 33 | * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. 34 | * 35 | * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. 36 | */ 37 | 38 | /* 39 | * cube.c 40 | * This program demonstrates a single modeling transformation, 41 | * glScalef() and a single viewing transformation, gluLookAt(). 42 | * A wireframe cube is rendered. 43 | */ 44 | #include 45 | #include 46 | 47 | GLfloat distancia = 5.0; 48 | GLfloat incremento = 0.1; 49 | GLfloat angulo = 0.0; 50 | GLfloat incrementoAngulo = 0.1; 51 | 52 | void init(void) 53 | { 54 | glClearColor (0.0, 0.0, 0.0, 0.0); 55 | glShadeModel (GL_FLAT); 56 | } 57 | 58 | void display(void) 59 | { 60 | glClear (GL_COLOR_BUFFER_BIT); 61 | glColor3f (1.0, 1.0, 1.0); 62 | glLoadIdentity (); /* clear the matrix */ 63 | /* viewing transformation */ 64 | //gluLookAt (0.0, 0.0, distancia, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); 65 | GLfloat x = distancia * sin(angulo); 66 | GLfloat z = distancia * cos(angulo); 67 | gluLookAt (x, 0.0, z, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); 68 | glPushMatrix(); 69 | glScalef (1.0, 2.0, 1.0); /* modeling transformation */ 70 | glutWireCube (1.0); 71 | //glutWireDodecahedron(); 72 | //glutSolidCube(1.0); 73 | glPopMatrix(); 74 | glFlush (); 75 | } 76 | 77 | void reshape (int w, int h) 78 | { 79 | glViewport (0, 0, (GLsizei) w, (GLsizei) h); 80 | glMatrixMode (GL_PROJECTION); 81 | glLoadIdentity (); 82 | glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0); 83 | glMatrixMode (GL_MODELVIEW); 84 | } 85 | 86 | void keyboard(unsigned char key, int x, int y) 87 | { 88 | switch (key) { 89 | case 27: 90 | exit(0); 91 | break; 92 | case 'w': 93 | //Camera.MoveForwards( -0.1 ) ; 94 | distancia -= incremento; 95 | display(); 96 | break; 97 | case 's': 98 | //Camera.MoveForwards( 0.1 ) ; 99 | distancia += incremento; 100 | display(); 101 | break; 102 | case 'a': 103 | //Camera.MoveForwards( -0.1 ) ; 104 | angulo -= incrementoAngulo; 105 | display(); 106 | break; 107 | case 'd': 108 | //Camera.MoveForwards( 0.1 ) ; 109 | angulo += incrementoAngulo; 110 | display(); 111 | break; 112 | } 113 | } 114 | 115 | int main(int argc, char** argv) 116 | { 117 | glutInit(&argc, argv); 118 | glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); 119 | glutInitWindowSize (500, 500); 120 | glutInitWindowPosition (100, 100); 121 | glutCreateWindow (argv[0]); 122 | init (); 123 | glutDisplayFunc(display); 124 | glutReshapeFunc(reshape); 125 | glutKeyboardFunc(keyboard); 126 | glutMainLoop(); 127 | return 0; 128 | } 129 | -------------------------------------------------------------------------------- /challenge4/examples/robot.c: -------------------------------------------------------------------------------- 1 | 2 | // robot.c: Adaptado de OpenGL Programming Guide (Neider, Davis, Woo) 3 | 4 | #include 5 | 6 | GLfloat angle, fAspect; 7 | static int shoulder = 0, elbow = 0; 8 | 9 | void elbowAdd() { 10 | elbow = (elbow + 5) % 360; 11 | } 12 | 13 | void elbowSubtract() { 14 | elbow = (elbow - 5) % 360; 15 | } 16 | 17 | void shoulderAdd() { 18 | shoulder = (shoulder + 5) % 360; 19 | } 20 | 21 | void shoulderSubtract() { 22 | shoulder = (shoulder - 5) % 360; 23 | } 24 | 25 | // Desplegar la escena 3D 26 | void display(void) 27 | { 28 | glClear(GL_COLOR_BUFFER_BIT); 29 | 30 | glColor3f(1.0f, 1.0f, 1.0f); 31 | 32 | glPushMatrix(); 33 | //glTranslatef(-1., 0., 0.); 34 | glRotatef((GLfloat) shoulder, 0., 0., 1.); 35 | glTranslatef(1., 0., 0.); 36 | glPushMatrix(); 37 | glScalef(2.0, 0.4, 1.0); 38 | glutWireCube(1.); // shoulder 39 | glPopMatrix(); 40 | 41 | glTranslatef(1., 0., 0.); 42 | glRotatef((GLfloat) elbow, 0., 0., 1.); 43 | glTranslatef(1., 0., 0.); 44 | glPushMatrix(); 45 | glScalef(2.0, 0.4, 1.0); 46 | glutWireCube(1.); // elbow 47 | glPopMatrix(); 48 | glPopMatrix(); 49 | // Ejecutar los comandos 50 | glutSwapBuffers(); 51 | } 52 | 53 | // Inicializar los parametros de despliegue 54 | void init (void) 55 | { 56 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 57 | angle=45; 58 | } 59 | 60 | // Especificar los parametros de visualizacion 61 | void visualizationParams(void) 62 | { 63 | // Sistema de coordenadas de proyeccion 64 | glMatrixMode(GL_PROJECTION); 65 | // Inicializa el sistema de coordenadas de la proyeccion 66 | glLoadIdentity(); 67 | 68 | // Especifica proyeccion perspectiva 69 | gluPerspective(angle,fAspect,0.1,500); 70 | 71 | // Especifica el sistema de coordenadas del modelo 72 | glMatrixMode(GL_MODELVIEW); 73 | // Inicializa el sistema de coordenadas del modelo 74 | glLoadIdentity(); 75 | 76 | // Especifica la posicion del observador 77 | // Posicion del ojo, hacia donde mira, vector arriba 78 | gluLookAt(0,0,15, 0,0,0, 0,1,0); 79 | } 80 | 81 | // Se llama cuando cambia el tamanyo de la ventana 82 | void reshape(GLsizei w, GLsizei h) 83 | { 84 | // Para prevenir division por 0 85 | if ( h == 0 ) h = 1; 86 | 87 | // Tamanyo del viewport 88 | glViewport(0, 0, w, h); 89 | 90 | // Aspect Ration 91 | fAspect = (GLfloat)w/(GLfloat)h; 92 | 93 | visualizationParams(); 94 | } 95 | 96 | // Responder a los eventos de teclas especiales 97 | void specialKeys(int key, int x, int y) 98 | { 99 | if(key == GLUT_KEY_UP) { 100 | elbowAdd(); 101 | } 102 | if(key == GLUT_KEY_DOWN) { 103 | elbowSubtract(); 104 | } 105 | if(key == GLUT_KEY_LEFT) { 106 | shoulderAdd(); 107 | } 108 | if(key == GLUT_KEY_RIGHT) { 109 | shoulderSubtract(); 110 | } 111 | glutPostRedisplay(); 112 | } 113 | // Programa Principal 114 | int main(void) 115 | { 116 | glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); 117 | glutInitWindowSize(500,500); 118 | glutCreateWindow("Brazo Robot"); 119 | glutDisplayFunc(display); 120 | glutReshapeFunc(reshape); 121 | glutSpecialFunc(specialKeys); 122 | init(); 123 | glutMainLoop(); 124 | } 125 | 126 | -------------------------------------------------------------------------------- /challenge4/pack/Andrés Mejía.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge4/pack/Andrés Mejía.zip -------------------------------------------------------------------------------- /challenge4/pack/README.txt: -------------------------------------------------------------------------------- 1 | Challenge 4 - Andrés Mejía Posada 2 | ================================= 3 | 4 | Create a robotic arm in OpenGL with 3 articulations: shoulder, elbow and wrist. 5 | 6 | * The shoulder should rotate around the Y and Z axes. 7 | * The elbow should rotate around the Z axis. 8 | * The wrist should rotate around the X and Z axes. 9 | 10 | Run it yourself 11 | --------------- 12 | 13 | These instructions are for Mac OS X. Your mileage may vary. 14 | 15 | cd challenge4/src 16 | g++ main.cpp -framework GLUT -framework OpenGL -o arm 17 | ./arm 18 | 19 | On the window that appears, press: 20 | 21 | * `q` and `a` to increase or decrease the angle of rotation around the Y axis at the shoulder. 22 | * `w` and `s` to increase or decrease the angle of rotation around the Z axis at the shoulder. 23 | * `e` and `d` to increase or decrease the angle of rotation around the Z axis at the elbow. 24 | * `r` and `f` to increase or decrease the angle of rotation around the Z axis at the wrist. 25 | * `t` and `g` to increase or decrease the angle of rotation around the X axis at the wrist. 26 | * `↑` and `↓` to increase or decrease the camera's distance to the object. 27 | * `←` and `→` to increase or decrease the camera's angle of rotation around the Z axis. 28 | 29 | Screenshot 30 | ----------- 31 | 32 | See shot.png. 33 | 34 | 35 | Video demo 36 | ----------- 37 | 38 | See the video demo on YouTube: http://www.youtube.com/watch?v=SfxGiCqAHNg -------------------------------------------------------------------------------- /challenge4/pack/demo.mov: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge4/pack/demo.mov -------------------------------------------------------------------------------- /challenge4/pack/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace std; 12 | 13 | GLfloat cameraDistance = 12, cameraAngle = 0; 14 | 15 | // angles = { Y rotation at shoulder, Z rotation at shoulder, Z rotation at elbow, X rotation at wrist } 16 | int arm_angles[5] = {0, 0, 0, 0, 0}; 17 | enum { SHOULDER_Y, SHOULDER_Z, ELBOW_Z, WRIST_X, WRIST_Z }; 18 | 19 | void change_angle(int angle, int delta, int minimum = 0, int maximum = 180) { 20 | arm_angles[angle] = (arm_angles[angle] + delta) % 360; 21 | arm_angles[angle] = max(arm_angles[angle], minimum); 22 | arm_angles[angle] = min(arm_angles[angle], maximum); 23 | } 24 | 25 | // Desplegar la escena 3D 26 | void display(void) { 27 | glClear(GL_COLOR_BUFFER_BIT); 28 | 29 | glLoadIdentity(); 30 | GLfloat x = cameraDistance * sin(cameraAngle); 31 | GLfloat z = cameraDistance * cos(cameraAngle); 32 | gluLookAt (x, 0.0, z, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); 33 | 34 | 35 | glPushMatrix(); 36 | glRotatef((GLfloat) arm_angles[SHOULDER_Y], 0., 1., 0.); 37 | glRotatef((GLfloat) arm_angles[SHOULDER_Z], 0., 0., 1.); 38 | 39 | glTranslatef(1., 0., 0.); 40 | glPushMatrix(); 41 | glScalef(2.0, 0.4, 1.0); 42 | glColor3f(1.0f, 1.0f, 1.0f); 43 | glutWireCube(1.); // shoulder 44 | glPopMatrix(); 45 | 46 | glTranslatef(1., 0., 0.); 47 | glRotatef((GLfloat) arm_angles[ELBOW_Z], 0., 0., 1.); 48 | glTranslatef(1., 0., 0.); 49 | glPushMatrix(); 50 | glScalef(2.0, 0.4, 1.0); 51 | glColor3f(249./255., 238./255., 153./255.); 52 | glutWireCube(1.); // elbow 53 | glPopMatrix(); 54 | 55 | glTranslatef(1., 0., 0.); 56 | glRotatef((GLfloat) arm_angles[WRIST_Z], 0., 0., 1.); 57 | glRotatef((GLfloat) arm_angles[WRIST_X], 1., 0., 0.); 58 | 59 | glTranslatef(1., 0., 0.); 60 | glPushMatrix(); 61 | glScalef(2.0, 0.4, 1.0); 62 | glColor3f(207./255., 106./255., 76./255.); 63 | glutWireCube(1.); // wrist 64 | glPopMatrix(); 65 | glPopMatrix(); 66 | 67 | // Ejecutar los comandos 68 | glutSwapBuffers(); 69 | } 70 | 71 | 72 | // Se llama cuando cambia el tamaño de la ventana 73 | void reshape(GLsizei w, GLsizei h) { 74 | // Tamanyo del viewport 75 | glViewport(0, 0, w, h); 76 | 77 | glMatrixMode(GL_PROJECTION); 78 | glLoadIdentity(); 79 | 80 | glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 300.0); 81 | 82 | glMatrixMode(GL_MODELVIEW); 83 | glLoadIdentity(); 84 | } 85 | 86 | // Responder a los eventos de teclas especiales 87 | void specialKeys(int key, int x, int y) { 88 | GLfloat distanceDelta = 1.0, angleDelta = 5 * M_PI / 180.0; 89 | if(key == GLUT_KEY_UP) { 90 | cameraDistance -= distanceDelta; 91 | cameraDistance = max((GLfloat)2.0, cameraDistance); 92 | } 93 | if(key == GLUT_KEY_DOWN) { 94 | cameraDistance += distanceDelta; 95 | } 96 | if(key == GLUT_KEY_LEFT) { 97 | cameraAngle -= angleDelta; 98 | } 99 | if(key == GLUT_KEY_RIGHT) { 100 | cameraAngle += angleDelta; 101 | } 102 | glutPostRedisplay(); 103 | } 104 | 105 | void keyboard(unsigned char key, int x, int y) { 106 | int delta = 5; 107 | 108 | switch (key) { 109 | case 27: //ESC 110 | exit(0); 111 | case 'q': 112 | change_angle(SHOULDER_Y, delta, -180, 0); 113 | break; 114 | case 'a': 115 | change_angle(SHOULDER_Y, -delta, -180, 0); 116 | break; 117 | case 'w': 118 | change_angle(SHOULDER_Z, delta, -90, 90); 119 | break; 120 | case 's': 121 | change_angle(SHOULDER_Z, -delta, -90, 90); 122 | break; 123 | case 'e': 124 | change_angle(ELBOW_Z, delta, 0, 135); 125 | break; 126 | case 'd': 127 | change_angle(ELBOW_Z, -delta, 0, 135); 128 | break; 129 | case 'r': 130 | change_angle(WRIST_X, delta, -45, 45); 131 | break; 132 | case 'f': 133 | change_angle(WRIST_X, -delta, -45, 45); 134 | break; 135 | case 't': 136 | change_angle(WRIST_Z, delta, -15, 90); 137 | break; 138 | case 'g': 139 | change_angle(WRIST_Z, -delta, -15, 90); 140 | break; 141 | } 142 | glutPostRedisplay(); 143 | } 144 | 145 | 146 | // Programa Principal 147 | int main(int argc, char * argv[]) { 148 | glutInit(&argc, argv); 149 | glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); 150 | glutInitWindowSize(700, 700); 151 | glutCreateWindow("Brazo Robot"); 152 | glutDisplayFunc(display); 153 | glutReshapeFunc(reshape); 154 | glutSpecialFunc(specialKeys); 155 | glutKeyboardFunc(keyboard); 156 | 157 | // Inicialización 158 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Negro 159 | 160 | glutMainLoop(); 161 | } 162 | 163 | -------------------------------------------------------------------------------- /challenge4/pack/shot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge4/pack/shot.png -------------------------------------------------------------------------------- /challenge4/shots/shot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge4/shots/shot.png -------------------------------------------------------------------------------- /challenge5/.gitignore: -------------------------------------------------------------------------------- 1 | build -------------------------------------------------------------------------------- /challenge5/README.md: -------------------------------------------------------------------------------- 1 | Challenge 5 2 | =========== 3 | 4 | Render a Bézier surface based on some control points that are to be read from a text file. 5 | 6 | Screenshot 7 | ----------- 8 | 9 | ![Screenshot](https://github.com/andmej/computer_graphics_challenges/blob/master/challenge5/pack/shot.png?raw=true) 10 | 11 | ### Legend 12 | 13 | * **Red axis**: X axis 14 | * **Green axis**: Y axis 15 | * **Blue axis**: Z axis 16 | * **Yellow mesh**: Bézier surface 17 | * **White dots**: Control points for the Bézier surface 18 | * **Gray lines**: Lines that connect all control points together. 19 | 20 | Run it yourself 21 | --------------- 22 | 23 | These instructions are for Mac OS X. Your mileage may vary. 24 | 25 | cd src 26 | g++ main.cpp -framework GLUT -framework OpenGL -o bezier 27 | ./bezier ../input/1.txt 28 | 29 | On the window that appears, press: 30 | 31 | * `a` and `d` to rotate the camera around the Y axis (the green one). 32 | * `w` and `s` to increase or decrease the camera's distance to the origin. 33 | * `q` and `e` to rotate the camera around the X axis (the red one). 34 | -------------------------------------------------------------------------------- /challenge5/input/1.txt: -------------------------------------------------------------------------------- 1 | 5 5 2 | 3 | -50 20 50 4 | -25 0 50 5 | 0 0 50 6 | 25 0 50 7 | 50 20 50 8 | 9 | -50 0 25 10 | -25 -40 25 11 | 0 0 25 12 | 25 -40 25 13 | 50 0 25 14 | 15 | -50 0 0 16 | -25 0 0 17 | 0 300 0 18 | 25 0 0 19 | 50 0 0 20 | 21 | -50 0 -25 22 | -25 -40 -25 23 | 0 0 -25 24 | 25 -40 -25 25 | 50 0 -25 26 | 27 | -50 20 -50 28 | -25 0 -50 29 | 0 0 -50 30 | 25 0 -50 31 | 50 20 -50 -------------------------------------------------------------------------------- /challenge5/pack/Bézier.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge5/pack/Bézier.zip -------------------------------------------------------------------------------- /challenge5/pack/README.md: -------------------------------------------------------------------------------- 1 | Challenge 5 - Andrés Mejía-Posada 2 | ================================= 3 | 4 | Render a Bézier surface based on some control points that are to be read from a text file. 5 | 6 | Screenshot 7 | ----------- 8 | 9 | See shot.png. 10 | 11 | ### Legend 12 | 13 | * Red axis: X axis 14 | * Green axis: Y axis 15 | * Blue axis: Z axis 16 | * Yellow mesh: Bézier surface 17 | * White dots: Control points for the Bézier surface 18 | * Gray lines: Lines that connect all control points together. 19 | 20 | Run it yourself 21 | --------------- 22 | 23 | These instructions are for Mac OS X. Your mileage may vary. 24 | 25 | cd src 26 | g++ main.cpp -framework GLUT -framework OpenGL -o bezier 27 | ./bezier ../input/1.txt 28 | 29 | On the window that appears, press: 30 | 31 | * `a` and `d` to rotate the camera around the Y axis (the green one). 32 | * `w` and `s` to increase or decrease the camera's distance to the origin. 33 | * `q` and `e` to rotate the camera around the X axis (the red one). 34 | 35 | 36 | Video demo 37 | ----------- 38 | 39 | See demo.mov. -------------------------------------------------------------------------------- /challenge5/pack/demo.mov: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge5/pack/demo.mov -------------------------------------------------------------------------------- /challenge5/pack/input.txt: -------------------------------------------------------------------------------- 1 | 5 5 2 | 3 | -50 20 50 4 | -25 0 50 5 | 0 0 50 6 | 25 0 50 7 | 50 20 50 8 | 9 | -50 0 25 10 | -25 -40 25 11 | 0 0 25 12 | 25 -40 25 13 | 50 0 25 14 | 15 | -50 0 0 16 | -25 0 0 17 | 0 300 0 18 | 25 0 0 19 | 50 0 0 20 | 21 | -50 0 -25 22 | -25 -40 -25 23 | 0 0 -25 24 | 25 -40 -25 25 | 50 0 -25 26 | 27 | -50 20 -50 28 | -25 0 -50 29 | 0 0 -50 30 | 25 0 -50 31 | 50 20 -50 -------------------------------------------------------------------------------- /challenge5/pack/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | 16 | struct point { 17 | double x, y, z; 18 | point(){} 19 | point(double x, double y, double z) : x(x), y(y), z(z) {} 20 | }; 21 | 22 | void initializeGlut(){ 23 | glClearColor(0.0, 0.0, 0.0, 0.0); 24 | } 25 | 26 | vector< vector< point > > controlPoints; 27 | vector< vector > C; 28 | 29 | double cameraDistance = 200, cameraRotationAroundY = -45.0/2, cameraRotationAroundX = 45.0/2; 30 | 31 | void readControlPoints(char * file) { 32 | printf("Will read points from %s\n", file); 33 | ifstream fin(file); 34 | controlPoints.clear(); 35 | int n, m; 36 | fin >> n >> m; 37 | printf("There are n=%d x m=%d control points\n", n, m); 38 | for (int i = 0; i < n; ++i) { 39 | controlPoints.push_back( vector() ); 40 | for (int j = 0; j < m; ++j) { 41 | double x, y, z; 42 | fin >> x >> y >> z; 43 | printf("Read control point <%lf, %lf, %lf>\n", x, y, z); 44 | controlPoints.back().push_back( point(x, y, z) ); 45 | } 46 | } 47 | assert(controlPoints.size() == n); 48 | assert(controlPoints[0].size() == m); 49 | } 50 | 51 | void precomputeBinomialCoefficients() { 52 | int n = (int)max(controlPoints.size(), controlPoints[0].size()); 53 | printf("Precomputing binomial coefficients up to n x n = %d x %d...\n", n, n); 54 | 55 | C.assign(n + 1, vector(n + 1, 0) ); // Binomial coefficients 56 | C[0][0] = 1; 57 | for (int i = 1; i <= n; ++i){ 58 | for (int j = 0; j <= n; ++j) { 59 | C[i][j] = C[i-1][j]; 60 | if (j > 0) C[i][j] += C[i-1][j-1]; 61 | } 62 | } 63 | } 64 | 65 | inline double bernstein(int n, int i, double u) { 66 | double ans = C[n][i] * pow(u, i) * pow(1.0 - u, n - i); 67 | return ans; 68 | } 69 | 70 | point P(double u, double v) { 71 | point ans(0, 0, 0); 72 | int n = (int)controlPoints.size(); 73 | int m = (int)controlPoints[0].size(); 74 | for (int i = 0; i < n; ++i) { 75 | for (int j = 0; j < m; ++j) { 76 | double k = bernstein(n - 1, i, u) * bernstein(m - 1, j, v); 77 | ans.x += k * controlPoints[i][j].x; 78 | ans.y += k * controlPoints[i][j].y; 79 | ans.z += k * controlPoints[i][j ].z; 80 | } 81 | } 82 | return ans; 83 | } 84 | 85 | void drawBezierCurveWithConstantU(double u) { 86 | glBegin(GL_LINES); 87 | double delta = 0.01; 88 | for (double v = 0.0; v < 1.0 - delta; v += delta) { 89 | point p1 = P(u, v); 90 | point p2 = P(u, v + delta); 91 | 92 | glVertex3f(p1.x, p1.y, p1.z); 93 | glVertex3f(p2.x, p2.y, p2.z); 94 | } 95 | glEnd(); 96 | } 97 | 98 | void drawBezierCurveWithConstantV(double v) { 99 | glBegin(GL_LINES); 100 | double delta = 0.01; 101 | for (double u = 0.0; u < 1.0 - delta; u += delta) { 102 | point p1 = P(u, v); 103 | point p2 = P(u + delta, v); 104 | 105 | glVertex3f(p1.x, p1.y, p1.z); 106 | glVertex3f(p2.x, p2.y, p2.z); 107 | } 108 | glEnd(); 109 | } 110 | 111 | 112 | 113 | void drawBezierSurface(){ 114 | for (int i = 0; i < controlPoints.size(); ++i){ 115 | for (int j = 0; j < controlPoints[i].size(); ++j){ 116 | // Draw straight lines between control points 117 | glBegin(GL_LINES); 118 | if (j + 1 < controlPoints[i].size()) { 119 | glVertex3i(controlPoints[i][j].x, controlPoints[i][j].y, controlPoints[i][j].z); 120 | glVertex3i(controlPoints[i][j+1].x, controlPoints[i][j+1].y, controlPoints[i][j+1].z); 121 | } 122 | if (i + 1 < controlPoints.size()) { 123 | glVertex3i(controlPoints[i][j].x, controlPoints[i][j].y, controlPoints[i][j].z); 124 | glVertex3i(controlPoints[i+1][j].x, controlPoints[i+1][j].y, controlPoints[i+1][j].z); 125 | } 126 | glEnd(); 127 | 128 | // Draw control points as little white spheres 129 | const point &p = controlPoints[i][j]; 130 | glColor3f(1.0, 1.0, 1.0); 131 | glPushMatrix(); 132 | glTranslatef(p.x, p.y, p.z); 133 | glutSolidSphere(1, 10, 10); 134 | glPopMatrix(); 135 | 136 | glColor3f(0.5, 0.5, 0.5); 137 | } 138 | } 139 | 140 | glColor3f(1, 1, 0); 141 | printf("Drawing Bézier curves with constant u...\n"); 142 | for (double u = 0; u <= 1.0; u += 0.1) { 143 | drawBezierCurveWithConstantU(u); 144 | } 145 | printf("Drawing Bézier curves with constant v...\n"); 146 | for (double v = 0; v <= 1.0; v += 0.1) { 147 | drawBezierCurveWithConstantV(v); 148 | } 149 | printf("Done!\n"); 150 | } 151 | 152 | void display(){ 153 | glClear(GL_COLOR_BUFFER_BIT); 154 | 155 | glMatrixMode(GL_MODELVIEW); 156 | glLoadIdentity(); 157 | 158 | gluLookAt(0, 0, cameraDistance, 0, 0, 0, 0, 1, 0); 159 | glRotatef(cameraRotationAroundX, 1, 0, 0); 160 | glRotatef(cameraRotationAroundY, 0, 1, 0); 161 | 162 | glBegin(GL_LINES); 163 | glColor3f(1, 0, 0); 164 | glVertex3f(0, 0, 0); 165 | glVertex3f(100, 0, 0); 166 | 167 | glColor3f(0, 1, 0); 168 | glVertex3f(0, 0, 0); 169 | glVertex3f(0, 100, 0); 170 | 171 | glColor3f(0, 0, 1); 172 | glVertex3f(0, 0, 0); 173 | glVertex3f(0, 0, 100); 174 | glEnd(); 175 | 176 | // Draw little points at the pointing end of axes 177 | glPushMatrix(); 178 | glColor3f(1, 0, 0); 179 | glTranslatef(100, 0, 0); 180 | glRotatef(90, 0, 1, 0); 181 | glutSolidCone(1, 4, 10, 10); 182 | glPopMatrix(); 183 | 184 | glPushMatrix(); 185 | glColor3f(0, 1, 0); 186 | glTranslatef(0, 100, 0); 187 | glRotatef(-90, 1, 0, 0); 188 | glutSolidCone(1, 4, 10, 10); 189 | glPopMatrix(); 190 | 191 | glPushMatrix(); 192 | glColor3f(0, 0, 1); 193 | glTranslatef(0, 0, 100); 194 | glutSolidCone(1, 4, 10, 10); 195 | glPopMatrix(); 196 | 197 | 198 | drawBezierSurface(); 199 | 200 | glutSwapBuffers(); 201 | } 202 | 203 | void reshape(int newWidth, int newHeight){ 204 | glViewport(0, 0, newWidth, newHeight); 205 | 206 | glMatrixMode(GL_PROJECTION); 207 | glLoadIdentity(); 208 | glFrustum (-1.0, 1.0, -1.0, 1.0, 1.0, 1000.0); 209 | //gluPerspective(30.0, 1.0, 1.0, 500.0); 210 | } 211 | 212 | void keyboard(unsigned char key, int x, int y){ 213 | if (key == 'w') { 214 | if (cameraDistance - 10 >= 5) cameraDistance -= 10; 215 | } else if (key == 's') { 216 | cameraDistance += 10; 217 | } else if (key == 'a') { 218 | cameraRotationAroundY -= 5; 219 | } else if (key == 'd') { 220 | cameraRotationAroundY += 5; 221 | } else if (key == 'q') { 222 | cameraRotationAroundX -= 5; 223 | } else if (key == 'e') { 224 | cameraRotationAroundX += 5; 225 | } 226 | glutPostRedisplay(); 227 | } 228 | 229 | void specialKeys(int key, int x, int y) { 230 | 231 | } 232 | 233 | int main(int argc, char **argv) { 234 | if (argc < 2){ 235 | fprintf(stderr, "You need to pass the name of the file with the control points as an argument.\n"); 236 | fprintf(stderr, " Example: %s %s\n", argv[0], "/tmp/myControlPoints.txt"); 237 | return -1; 238 | } 239 | 240 | struct stat st; 241 | if (stat(argv[1], &st) != 0) { 242 | fprintf(stderr, "The file '%s' does not exist.\n", argv[1]); 243 | return -1; 244 | } 245 | 246 | readControlPoints(argv[1]); 247 | precomputeBinomialCoefficients(); 248 | 249 | glutInit(&argc, argv); 250 | glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); 251 | glutInitWindowSize(500, 500); 252 | glutCreateWindow("Bézier Curves"); 253 | glutDisplayFunc(display); 254 | glutReshapeFunc(reshape); 255 | glutSpecialFunc(specialKeys); 256 | glutKeyboardFunc(keyboard); 257 | initializeGlut(); 258 | glutMainLoop(); 259 | return 0; 260 | } 261 | -------------------------------------------------------------------------------- /challenge5/pack/shot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge5/pack/shot.png -------------------------------------------------------------------------------- /challenge5/src/bezier: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge5/src/bezier -------------------------------------------------------------------------------- /challenge5/src/challenge5.1: -------------------------------------------------------------------------------- 1 | .\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples. 2 | .\"See Also: 3 | .\"man mdoc.samples for a complete listing of options 4 | .\"man mdoc for the short list of editing options 5 | .\"/usr/share/misc/mdoc.template 6 | .Dd 30/09/11 \" DATE 7 | .Dt challenge5 1 \" Program name and manual section number 8 | .Os Darwin 9 | .Sh NAME \" Section Header - required - don't modify 10 | .Nm challenge5, 11 | .\" The following lines are read in generating the apropos(man -k) database. Use only key 12 | .\" words here as the database is built based on the words here and in the .ND line. 13 | .Nm Other_name_for_same_program(), 14 | .Nm Yet another name for the same program. 15 | .\" Use .Nm macro to designate other names for the documented program. 16 | .Nd This line parsed for whatis database. 17 | .Sh SYNOPSIS \" Section Header - required - don't modify 18 | .Nm 19 | .Op Fl abcd \" [-abcd] 20 | .Op Fl a Ar path \" [-a path] 21 | .Op Ar file \" [file] 22 | .Op Ar \" [file ...] 23 | .Ar arg0 \" Underlined argument - use .Ar anywhere to underline 24 | arg2 ... \" Arguments 25 | .Sh DESCRIPTION \" Section Header - required - don't modify 26 | Use the .Nm macro to refer to your program throughout the man page like such: 27 | .Nm 28 | Underlining is accomplished with the .Ar macro like this: 29 | .Ar underlined text . 30 | .Pp \" Inserts a space 31 | A list of items with descriptions: 32 | .Bl -tag -width -indent \" Begins a tagged list 33 | .It item a \" Each item preceded by .It macro 34 | Description of item a 35 | .It item b 36 | Description of item b 37 | .El \" Ends the list 38 | .Pp 39 | A list of flags and their descriptions: 40 | .Bl -tag -width -indent \" Differs from above in tag removed 41 | .It Fl a \"-a flag as a list item 42 | Description of -a flag 43 | .It Fl b 44 | Description of -b flag 45 | .El \" Ends the list 46 | .Pp 47 | .\" .Sh ENVIRONMENT \" May not be needed 48 | .\" .Bl -tag -width "ENV_VAR_1" -indent \" ENV_VAR_1 is width of the string ENV_VAR_1 49 | .\" .It Ev ENV_VAR_1 50 | .\" Description of ENV_VAR_1 51 | .\" .It Ev ENV_VAR_2 52 | .\" Description of ENV_VAR_2 53 | .\" .El 54 | .Sh FILES \" File used or created by the topic of the man page 55 | .Bl -tag -width "/Users/joeuser/Library/really_long_file_name" -compact 56 | .It Pa /usr/share/file_name 57 | FILE_1 description 58 | .It Pa /Users/joeuser/Library/really_long_file_name 59 | FILE_2 description 60 | .El \" Ends the list 61 | .\" .Sh DIAGNOSTICS \" May not be needed 62 | .\" .Bl -diag 63 | .\" .It Diagnostic Tag 64 | .\" Diagnostic informtion here. 65 | .\" .It Diagnostic Tag 66 | .\" Diagnostic informtion here. 67 | .\" .El 68 | .Sh SEE ALSO 69 | .\" List links in ascending order by section, alphabetically within a section. 70 | .\" Please do not reference files that do not exist without filing a bug report 71 | .Xr a 1 , 72 | .Xr b 1 , 73 | .Xr c 1 , 74 | .Xr a 2 , 75 | .Xr b 2 , 76 | .Xr a 3 , 77 | .Xr b 3 78 | .\" .Sh BUGS \" Document known, unremedied bugs 79 | .\" .Sh HISTORY \" Document history if command behaves in a unique manner -------------------------------------------------------------------------------- /challenge5/src/example.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | GLfloat ctrlpoints[4][4][3] = 8 | { 9 | { 10 | {-1.5, -1.5, 4.0}, 11 | {-0.5, -1.5, 2.0}, 12 | {0.5, -1.5, -1.0}, 13 | {1.5, -1.5, 2.0}}, 14 | { 15 | {-1.5, -0.5, 1.0}, 16 | {-0.5, -0.5, 3.0}, 17 | {0.5, -0.5, 0.0}, 18 | {1.5, -0.5, -1.0}}, 19 | { 20 | {-1.5, 0.5, 4.0}, 21 | {-0.5, 0.5, 0.0}, 22 | {0.5, 0.5, 3.0}, 23 | {1.5, 0.5, 4.0}}, 24 | { 25 | {-1.5, 1.5, -2.0}, 26 | {-0.5, 1.5, -2.0}, 27 | {0.5, 1.5, 0.0}, 28 | {1.5, 1.5, -1.0}} 29 | }; 30 | 31 | void 32 | myDisplay(void) 33 | { 34 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 35 | glPushMatrix(); 36 | glRotatef(85.0, 1.0, 1.0, 1.0); 37 | glEvalMesh2(GL_LINE, 0, 20, 0, 20); 38 | glPopMatrix(); 39 | glFlush(); 40 | } 41 | 42 | void 43 | myinit(void) 44 | { 45 | glClearColor(0.0, 0.0, 0.0, 1.0); 46 | glEnable(GL_MAP2_VERTEX_3); 47 | glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 48 | 0, 1, 12, 4, &ctrlpoints[0][0][0]); 49 | glMapGrid2f(20, 0.0, 1.0, 20, 0.0, 1.0); 50 | } 51 | 52 | void 53 | myReshape(int w, int h) 54 | { 55 | glViewport(0, 0, w, h); 56 | glMatrixMode(GL_PROJECTION); 57 | glLoadIdentity(); 58 | if (w <= h) 59 | glOrtho(-4.0, 4.0, -4.0 * (GLfloat) h / (GLfloat) w, 60 | 4.0 * (GLfloat) h / (GLfloat) w, -4.0, 4.0); 61 | else 62 | glOrtho(-4.0 * (GLfloat) w / (GLfloat) h, 63 | 4.0 * (GLfloat) w / (GLfloat) h, -4.0, 4.0, -4.0, 4.0); 64 | glMatrixMode(GL_MODELVIEW); 65 | glLoadIdentity(); 66 | } 67 | 68 | int 69 | _main(int argc, char **argv) 70 | { 71 | glutInit(&argc, argv); 72 | glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); 73 | glutCreateWindow(argv[0]); 74 | myinit(); 75 | glutReshapeFunc(myReshape); 76 | glutDisplayFunc(myDisplay); 77 | glutMainLoop(); 78 | return 0; /* ANSI C requires main to return int. */ 79 | } 80 | -------------------------------------------------------------------------------- /challenge5/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | 16 | struct point { 17 | double x, y, z; 18 | point(){} 19 | point(double x, double y, double z) : x(x), y(y), z(z) {} 20 | }; 21 | 22 | void initializeGlut(){ 23 | glClearColor(0.0, 0.0, 0.0, 0.0); 24 | } 25 | 26 | vector< vector< point > > controlPoints; 27 | vector< vector > C; 28 | 29 | double cameraDistance = 200, cameraRotationAroundY = -45.0/2, cameraRotationAroundX = 45.0/2; 30 | 31 | void readControlPoints(char * file) { 32 | printf("Will read points from %s\n", file); 33 | ifstream fin(file); 34 | controlPoints.clear(); 35 | int n, m; 36 | fin >> n >> m; 37 | printf("There are n=%d x m=%d control points\n", n, m); 38 | for (int i = 0; i < n; ++i) { 39 | controlPoints.push_back( vector() ); 40 | for (int j = 0; j < m; ++j) { 41 | double x, y, z; 42 | fin >> x >> y >> z; 43 | printf("Read control point <%lf, %lf, %lf>\n", x, y, z); 44 | controlPoints.back().push_back( point(x, y, z) ); 45 | } 46 | } 47 | assert(controlPoints.size() == n); 48 | assert(controlPoints[0].size() == m); 49 | } 50 | 51 | void precomputeBinomialCoefficients() { 52 | int n = (int)max(controlPoints.size(), controlPoints[0].size()); 53 | printf("Precomputing binomial coefficients up to n x n = %d x %d...\n", n, n); 54 | 55 | C.assign(n + 1, vector(n + 1, 0) ); // Binomial coefficients 56 | C[0][0] = 1; 57 | for (int i = 1; i <= n; ++i){ 58 | for (int j = 0; j <= n; ++j) { 59 | C[i][j] = C[i-1][j]; 60 | if (j > 0) C[i][j] += C[i-1][j-1]; 61 | } 62 | } 63 | } 64 | 65 | inline double bernstein(int n, int i, double u) { 66 | double ans = C[n][i] * pow(u, i) * pow(1.0 - u, n - i); 67 | return ans; 68 | } 69 | 70 | point P(double u, double v) { 71 | point ans(0, 0, 0); 72 | int n = (int)controlPoints.size(); 73 | int m = (int)controlPoints[0].size(); 74 | for (int i = 0; i < n; ++i) { 75 | for (int j = 0; j < m; ++j) { 76 | double k = bernstein(n - 1, i, u) * bernstein(m - 1, j, v); 77 | ans.x += k * controlPoints[i][j].x; 78 | ans.y += k * controlPoints[i][j].y; 79 | ans.z += k * controlPoints[i][j ].z; 80 | } 81 | } 82 | return ans; 83 | } 84 | 85 | void drawBezierCurveWithConstantU(double u) { 86 | glBegin(GL_LINES); 87 | double delta = 0.01; 88 | for (double v = 0.0; v < 1.0 - delta; v += delta) { 89 | point p1 = P(u, v); 90 | point p2 = P(u, v + delta); 91 | 92 | glVertex3f(p1.x, p1.y, p1.z); 93 | glVertex3f(p2.x, p2.y, p2.z); 94 | } 95 | glEnd(); 96 | } 97 | 98 | void drawBezierCurveWithConstantV(double v) { 99 | glBegin(GL_LINES); 100 | double delta = 0.01; 101 | for (double u = 0.0; u < 1.0 - delta; u += delta) { 102 | point p1 = P(u, v); 103 | point p2 = P(u + delta, v); 104 | 105 | glVertex3f(p1.x, p1.y, p1.z); 106 | glVertex3f(p2.x, p2.y, p2.z); 107 | } 108 | glEnd(); 109 | } 110 | 111 | 112 | 113 | void drawBezierSurface(){ 114 | for (int i = 0; i < controlPoints.size(); ++i){ 115 | for (int j = 0; j < controlPoints[i].size(); ++j){ 116 | // Draw straight lines between control points 117 | glBegin(GL_LINES); 118 | if (j + 1 < controlPoints[i].size()) { 119 | glVertex3i(controlPoints[i][j].x, controlPoints[i][j].y, controlPoints[i][j].z); 120 | glVertex3i(controlPoints[i][j+1].x, controlPoints[i][j+1].y, controlPoints[i][j+1].z); 121 | } 122 | if (i + 1 < controlPoints.size()) { 123 | glVertex3i(controlPoints[i][j].x, controlPoints[i][j].y, controlPoints[i][j].z); 124 | glVertex3i(controlPoints[i+1][j].x, controlPoints[i+1][j].y, controlPoints[i+1][j].z); 125 | } 126 | glEnd(); 127 | 128 | // Draw control points as little white spheres 129 | const point &p = controlPoints[i][j]; 130 | glColor3f(1.0, 1.0, 1.0); 131 | glPushMatrix(); 132 | glTranslatef(p.x, p.y, p.z); 133 | glutSolidSphere(1, 10, 10); 134 | glPopMatrix(); 135 | 136 | glColor3f(0.5, 0.5, 0.5); 137 | } 138 | } 139 | 140 | glColor3f(1, 1, 0); 141 | printf("Drawing Bézier curves with constant u...\n"); 142 | for (double u = 0; u <= 1.0; u += 0.1) { 143 | drawBezierCurveWithConstantU(u); 144 | } 145 | printf("Drawing Bézier curves with constant v...\n"); 146 | for (double v = 0; v <= 1.0; v += 0.1) { 147 | drawBezierCurveWithConstantV(v); 148 | } 149 | printf("Done!\n"); 150 | } 151 | 152 | void display(){ 153 | glClear(GL_COLOR_BUFFER_BIT); 154 | 155 | glMatrixMode(GL_MODELVIEW); 156 | glLoadIdentity(); 157 | 158 | gluLookAt(0, 0, cameraDistance, 0, 0, 0, 0, 1, 0); 159 | glRotatef(cameraRotationAroundX, 1, 0, 0); 160 | glRotatef(cameraRotationAroundY, 0, 1, 0); 161 | 162 | glBegin(GL_LINES); 163 | glColor3f(1, 0, 0); 164 | glVertex3f(0, 0, 0); 165 | glVertex3f(100, 0, 0); 166 | 167 | glColor3f(0, 1, 0); 168 | glVertex3f(0, 0, 0); 169 | glVertex3f(0, 100, 0); 170 | 171 | glColor3f(0, 0, 1); 172 | glVertex3f(0, 0, 0); 173 | glVertex3f(0, 0, 100); 174 | glEnd(); 175 | 176 | // Draw little points at the pointing end of axes 177 | glPushMatrix(); 178 | glColor3f(1, 0, 0); 179 | glTranslatef(100, 0, 0); 180 | glRotatef(90, 0, 1, 0); 181 | glutSolidCone(1, 4, 10, 10); 182 | glPopMatrix(); 183 | 184 | glPushMatrix(); 185 | glColor3f(0, 1, 0); 186 | glTranslatef(0, 100, 0); 187 | glRotatef(-90, 1, 0, 0); 188 | glutSolidCone(1, 4, 10, 10); 189 | glPopMatrix(); 190 | 191 | glPushMatrix(); 192 | glColor3f(0, 0, 1); 193 | glTranslatef(0, 0, 100); 194 | glutSolidCone(1, 4, 10, 10); 195 | glPopMatrix(); 196 | 197 | 198 | drawBezierSurface(); 199 | 200 | glutSwapBuffers(); 201 | } 202 | 203 | void reshape(int newWidth, int newHeight){ 204 | glViewport(0, 0, newWidth, newHeight); 205 | 206 | glMatrixMode(GL_PROJECTION); 207 | glLoadIdentity(); 208 | glFrustum (-1.0, 1.0, -1.0, 1.0, 1.0, 1000.0); 209 | //gluPerspective(30.0, 1.0, 1.0, 500.0); 210 | } 211 | 212 | void keyboard(unsigned char key, int x, int y){ 213 | if (key == 'w') { 214 | if (cameraDistance - 10 >= 5) cameraDistance -= 10; 215 | } else if (key == 's') { 216 | cameraDistance += 10; 217 | } else if (key == 'a') { 218 | cameraRotationAroundY -= 5; 219 | } else if (key == 'd') { 220 | cameraRotationAroundY += 5; 221 | } else if (key == 'q') { 222 | cameraRotationAroundX -= 5; 223 | } else if (key == 'e') { 224 | cameraRotationAroundX += 5; 225 | } 226 | glutPostRedisplay(); 227 | } 228 | 229 | void specialKeys(int key, int x, int y) { 230 | 231 | } 232 | 233 | int main(int argc, char **argv) { 234 | if (argc < 2){ 235 | fprintf(stderr, "You need to pass the name of the file with the control points as an argument.\n"); 236 | fprintf(stderr, " Example: %s %s\n", argv[0], "/tmp/myControlPoints.txt"); 237 | return -1; 238 | } 239 | 240 | struct stat st; 241 | if (stat(argv[1], &st) != 0) { 242 | fprintf(stderr, "The file '%s' does not exist.\n", argv[1]); 243 | return -1; 244 | } 245 | 246 | readControlPoints(argv[1]); 247 | precomputeBinomialCoefficients(); 248 | 249 | glutInit(&argc, argv); 250 | glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); 251 | glutInitWindowSize(500, 500); 252 | glutCreateWindow("Bézier Curves"); 253 | glutDisplayFunc(display); 254 | glutReshapeFunc(reshape); 255 | glutSpecialFunc(specialKeys); 256 | glutKeyboardFunc(keyboard); 257 | initializeGlut(); 258 | glutMainLoop(); 259 | return 0; 260 | } 261 | -------------------------------------------------------------------------------- /challenge6/README.md: -------------------------------------------------------------------------------- 1 | Challenge 6 2 | =========== 3 | 4 | Like challenge 4 (create a robotic arm in OpenGL with 3 articulations) but add lighting to the scene. 5 | 6 | * The shoulder should rotate around the Y and Z axes. 7 | * The elbow should rotate around the Z axis. 8 | * The wrist should rotate around the X and Z axes. 9 | 10 | Run it yourself 11 | --------------- 12 | 13 | These instructions are for Mac OS X. Your mileage may vary. 14 | 15 | cd challenge6/challenge6 16 | g++ main.cpp -framework GLUT -framework OpenGL -o arm 17 | ./arm 18 | 19 | On the window that appears, press: 20 | 21 | * `q` and `a` to increase or decrease the angle of rotation around the Y axis at the shoulder. 22 | * `w` and `s` to increase or decrease the angle of rotation around the Z axis at the shoulder. 23 | * `e` and `d` to increase or decrease the angle of rotation around the Z axis at the elbow. 24 | * `r` and `f` to increase or decrease the angle of rotation around the Z axis at the wrist. 25 | * `t` and `g` to increase or decrease the angle of rotation around the X axis at the wrist. 26 | * `↑` and `↓` to increase or decrease the camera's distance to the object. 27 | * `←` and `→` to increase or decrease the camera's angle of rotation around the Z axis. 28 | 29 | Screenshot 30 | ----------- 31 | 32 | ![Screenshot](https://github.com/andmej/computer_graphics_challenges/blob/master/challenge6/shots/Screen shot 2011-10-07 at 17.00.12.png?raw=true) 33 | -------------------------------------------------------------------------------- /challenge6/challenge6/challenge6.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 3268AD14143FA35700AD9A93 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3268AD13143FA35700AD9A93 /* main.cpp */; }; 11 | 3268AD1C143FA39200AD9A93 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3268AD1B143FA39200AD9A93 /* OpenGL.framework */; }; 12 | 3268AD1E143FA39900AD9A93 /* GLUT.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3268AD1D143FA39900AD9A93 /* GLUT.framework */; }; 13 | 3268AD21143FA40C00AD9A93 /* example.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3268AD1F143FA40C00AD9A93 /* example.cpp */; }; 14 | /* End PBXBuildFile section */ 15 | 16 | /* Begin PBXCopyFilesBuildPhase section */ 17 | 3268AD0D143FA35700AD9A93 /* CopyFiles */ = { 18 | isa = PBXCopyFilesBuildPhase; 19 | buildActionMask = 2147483647; 20 | dstPath = /usr/share/man/man1/; 21 | dstSubfolderSpec = 0; 22 | files = ( 23 | ); 24 | runOnlyForDeploymentPostprocessing = 1; 25 | }; 26 | /* End PBXCopyFilesBuildPhase section */ 27 | 28 | /* Begin PBXFileReference section */ 29 | 3268AD0F143FA35700AD9A93 /* challenge6 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = challenge6; sourceTree = BUILT_PRODUCTS_DIR; }; 30 | 3268AD13143FA35700AD9A93 /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = ""; }; 31 | 3268AD1B143FA39200AD9A93 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = System/Library/Frameworks/OpenGL.framework; sourceTree = SDKROOT; }; 32 | 3268AD1D143FA39900AD9A93 /* GLUT.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GLUT.framework; path = System/Library/Frameworks/GLUT.framework; sourceTree = SDKROOT; }; 33 | 3268AD1F143FA40C00AD9A93 /* example.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = example.cpp; sourceTree = ""; }; 34 | /* End PBXFileReference section */ 35 | 36 | /* Begin PBXFrameworksBuildPhase section */ 37 | 3268AD0C143FA35700AD9A93 /* Frameworks */ = { 38 | isa = PBXFrameworksBuildPhase; 39 | buildActionMask = 2147483647; 40 | files = ( 41 | 3268AD1E143FA39900AD9A93 /* GLUT.framework in Frameworks */, 42 | 3268AD1C143FA39200AD9A93 /* OpenGL.framework in Frameworks */, 43 | ); 44 | runOnlyForDeploymentPostprocessing = 0; 45 | }; 46 | /* End PBXFrameworksBuildPhase section */ 47 | 48 | /* Begin PBXGroup section */ 49 | 3268AD04143FA35600AD9A93 = { 50 | isa = PBXGroup; 51 | children = ( 52 | 3268AD1D143FA39900AD9A93 /* GLUT.framework */, 53 | 3268AD1B143FA39200AD9A93 /* OpenGL.framework */, 54 | 3268AD12143FA35700AD9A93 /* challenge6 */, 55 | 3268AD10143FA35700AD9A93 /* Products */, 56 | ); 57 | sourceTree = ""; 58 | }; 59 | 3268AD10143FA35700AD9A93 /* Products */ = { 60 | isa = PBXGroup; 61 | children = ( 62 | 3268AD0F143FA35700AD9A93 /* challenge6 */, 63 | ); 64 | name = Products; 65 | sourceTree = ""; 66 | }; 67 | 3268AD12143FA35700AD9A93 /* challenge6 */ = { 68 | isa = PBXGroup; 69 | children = ( 70 | 3268AD13143FA35700AD9A93 /* main.cpp */, 71 | 3268AD1F143FA40C00AD9A93 /* example.cpp */, 72 | ); 73 | path = challenge6; 74 | sourceTree = ""; 75 | }; 76 | /* End PBXGroup section */ 77 | 78 | /* Begin PBXNativeTarget section */ 79 | 3268AD0E143FA35700AD9A93 /* challenge6 */ = { 80 | isa = PBXNativeTarget; 81 | buildConfigurationList = 3268AD18143FA35700AD9A93 /* Build configuration list for PBXNativeTarget "challenge6" */; 82 | buildPhases = ( 83 | 3268AD0B143FA35700AD9A93 /* Sources */, 84 | 3268AD0C143FA35700AD9A93 /* Frameworks */, 85 | 3268AD0D143FA35700AD9A93 /* CopyFiles */, 86 | ); 87 | buildRules = ( 88 | ); 89 | dependencies = ( 90 | ); 91 | name = challenge6; 92 | productName = challenge6; 93 | productReference = 3268AD0F143FA35700AD9A93 /* challenge6 */; 94 | productType = "com.apple.product-type.tool"; 95 | }; 96 | /* End PBXNativeTarget section */ 97 | 98 | /* Begin PBXProject section */ 99 | 3268AD06143FA35600AD9A93 /* Project object */ = { 100 | isa = PBXProject; 101 | buildConfigurationList = 3268AD09143FA35600AD9A93 /* Build configuration list for PBXProject "challenge6" */; 102 | compatibilityVersion = "Xcode 3.2"; 103 | developmentRegion = English; 104 | hasScannedForEncodings = 0; 105 | knownRegions = ( 106 | en, 107 | ); 108 | mainGroup = 3268AD04143FA35600AD9A93; 109 | productRefGroup = 3268AD10143FA35700AD9A93 /* Products */; 110 | projectDirPath = ""; 111 | projectRoot = ""; 112 | targets = ( 113 | 3268AD0E143FA35700AD9A93 /* challenge6 */, 114 | ); 115 | }; 116 | /* End PBXProject section */ 117 | 118 | /* Begin PBXSourcesBuildPhase section */ 119 | 3268AD0B143FA35700AD9A93 /* Sources */ = { 120 | isa = PBXSourcesBuildPhase; 121 | buildActionMask = 2147483647; 122 | files = ( 123 | 3268AD14143FA35700AD9A93 /* main.cpp in Sources */, 124 | 3268AD21143FA40C00AD9A93 /* example.cpp in Sources */, 125 | ); 126 | runOnlyForDeploymentPostprocessing = 0; 127 | }; 128 | /* End PBXSourcesBuildPhase section */ 129 | 130 | /* Begin XCBuildConfiguration section */ 131 | 3268AD16143FA35700AD9A93 /* Debug */ = { 132 | isa = XCBuildConfiguration; 133 | buildSettings = { 134 | ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; 135 | GCC_C_LANGUAGE_STANDARD = gnu99; 136 | GCC_OPTIMIZATION_LEVEL = 0; 137 | GCC_PREPROCESSOR_DEFINITIONS = DEBUG; 138 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 139 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0; 140 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 141 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 142 | GCC_WARN_UNUSED_VARIABLE = YES; 143 | MACOSX_DEPLOYMENT_TARGET = 10.6; 144 | ONLY_ACTIVE_ARCH = YES; 145 | SDKROOT = macosx; 146 | }; 147 | name = Debug; 148 | }; 149 | 3268AD17143FA35700AD9A93 /* Release */ = { 150 | isa = XCBuildConfiguration; 151 | buildSettings = { 152 | ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; 153 | GCC_C_LANGUAGE_STANDARD = gnu99; 154 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0; 155 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 156 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 157 | GCC_WARN_UNUSED_VARIABLE = YES; 158 | MACOSX_DEPLOYMENT_TARGET = 10.6; 159 | SDKROOT = macosx; 160 | }; 161 | name = Release; 162 | }; 163 | 3268AD19143FA35700AD9A93 /* Debug */ = { 164 | isa = XCBuildConfiguration; 165 | buildSettings = { 166 | ALWAYS_SEARCH_USER_PATHS = NO; 167 | COPY_PHASE_STRIP = NO; 168 | GCC_DYNAMIC_NO_PIC = NO; 169 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 170 | PRODUCT_NAME = "$(TARGET_NAME)"; 171 | }; 172 | name = Debug; 173 | }; 174 | 3268AD1A143FA35700AD9A93 /* Release */ = { 175 | isa = XCBuildConfiguration; 176 | buildSettings = { 177 | ALWAYS_SEARCH_USER_PATHS = NO; 178 | COPY_PHASE_STRIP = YES; 179 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 180 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 181 | PRODUCT_NAME = "$(TARGET_NAME)"; 182 | }; 183 | name = Release; 184 | }; 185 | /* End XCBuildConfiguration section */ 186 | 187 | /* Begin XCConfigurationList section */ 188 | 3268AD09143FA35600AD9A93 /* Build configuration list for PBXProject "challenge6" */ = { 189 | isa = XCConfigurationList; 190 | buildConfigurations = ( 191 | 3268AD16143FA35700AD9A93 /* Debug */, 192 | 3268AD17143FA35700AD9A93 /* Release */, 193 | ); 194 | defaultConfigurationIsVisible = 0; 195 | defaultConfigurationName = Release; 196 | }; 197 | 3268AD18143FA35700AD9A93 /* Build configuration list for PBXNativeTarget "challenge6" */ = { 198 | isa = XCConfigurationList; 199 | buildConfigurations = ( 200 | 3268AD19143FA35700AD9A93 /* Debug */, 201 | 3268AD1A143FA35700AD9A93 /* Release */, 202 | ); 203 | defaultConfigurationIsVisible = 0; 204 | }; 205 | /* End XCConfigurationList section */ 206 | }; 207 | rootObject = 3268AD06143FA35600AD9A93 /* Project object */; 208 | } 209 | -------------------------------------------------------------------------------- /challenge6/challenge6/challenge6/arm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge6/challenge6/challenge6/arm -------------------------------------------------------------------------------- /challenge6/challenge6/challenge6/example.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * pyramidWithMaterial 3 | * This program demonstrates how to create a sphere and a plane, 4 | * with color and lights. 5 | */ 6 | #include 7 | #include 8 | #include 9 | 10 | namespace Example { 11 | GLfloat distance = 5.0; 12 | GLfloat increment = 0.1; 13 | GLfloat angle = 0.0; 14 | GLfloat angleIncrement = 0.1; 15 | 16 | // Light properties 17 | GLfloat ambient[] = { 0.0, 0.0, 0.0, 0.0 }; 18 | GLfloat diffuse[] = { 1.0, 1.0, 1.0, 0.0 }; 19 | GLfloat specular[] = { 1.0, 1.0, 1.0, 0.0 }; 20 | GLfloat position[] = { 5.0, 5.0, 5.0, 0.0 }; // x, y, z, 1:directional 0:point 21 | 22 | void _init(void) 23 | { 24 | //glClearColor (0.0, 0.0, 0.0, 0.0); 25 | glClearColor(0.0, 0.1, 0.1, 0.0); 26 | glEnable(GL_DEPTH_TEST); 27 | //glShadeModel (GL_FLAT); 28 | glShadeModel(GL_SMOOTH); 29 | 30 | 31 | glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); 32 | glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); 33 | //glLightfv(GL_LIGHT0, GL_POSITION, position); // position specified here: light moves with camera 34 | 35 | glEnable(GL_LIGHTING); 36 | glEnable(GL_LIGHT0); 37 | } 38 | 39 | void _display(void) 40 | { 41 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 42 | 43 | GLfloat no_mat[] = { 0.0, 0.0, 0.0, 1.0 }; 44 | GLfloat mat_ambient[] = { 0.7, 0.7, 0.7, 1.0 }; 45 | GLfloat mat_ambient_color[] = { 0.8, 0.8, 0.2, 1.0 }; 46 | GLfloat mat_blue[] = { 0.1, 0.2, 0.8, 1.0 }; 47 | GLfloat mat_red[] = { 0.8, 0.2, 0.1, 1.0 }; 48 | GLfloat mat_green[] = { 0.1, 0.8, 0.1, 1.0 }; 49 | GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; 50 | GLfloat no_shininess[] = { 0.0 }; 51 | GLfloat low_shininess[] = { 5.0 }; 52 | GLfloat high_shininess[] = { 100.0 }; 53 | 54 | 55 | glLoadIdentity (); /* clear the matrix */ 56 | /* viewing transformation */ 57 | //gluLookAt (0.0, 0.0, distance, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); 58 | GLfloat x = distance * cos(angle); 59 | GLfloat y = distance * sin(angle); 60 | /* parameters: where is the camera, looking at vector, up vector */ 61 | gluLookAt (x, y, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0); 62 | glPushMatrix(); 63 | //glScalef (1.0, 2.0, 1.0); /* modeling transformation */ 64 | //glutWireCube (1.0); 65 | //glutWireDodecahedron(); 66 | // Materials for the SPHERE 67 | glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat); 68 | glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_blue); 69 | glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); 70 | glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess); 71 | //glutSolidCube(1.0); 72 | // Parameters: Radious, Slices, Stacks 73 | glutSolidSphere(0.7, 64, 64); 74 | 75 | //glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat); 76 | // Material for the PLANE 77 | glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_green); 78 | //glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); 79 | //glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess); 80 | 81 | /* A green rectangle */ 82 | glBegin (GL_QUADS); 83 | glNormal3f (0.0, 0.0, 1.0); 84 | glVertex3f (0.0, 0.0, 0.0); 85 | glVertex3f (2.0, 0.0, 0.0); 86 | glVertex3f (2.0, 2.0, 0.0); 87 | glVertex3f (0.0, 2.0, 0.0); 88 | glEnd ( ); 89 | 90 | /* A red pyramid */ 91 | // Materials for the Pyramid 92 | //glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat); 93 | glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_red); 94 | glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); 95 | glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess); 96 | 97 | glBegin (GL_TRIANGLES); 98 | glNormal3f (0.0, -0.5, 0.5); 99 | glVertex3f (0.0, 0.0, 0.0); 100 | glVertex3f (1.0, 0.0, 0.0); 101 | glVertex3f (0.5, 0.5, 1.0); 102 | glEnd(); 103 | glBegin (GL_TRIANGLES); 104 | glNormal3f (0.5, 0.0, 0.5); 105 | glVertex3f (1.0, 0.0, 0.0); 106 | glVertex3f (1.0, 1.0, 0.0); 107 | glVertex3f (0.5, 0.5, 1.0); 108 | glEnd(); 109 | glBegin (GL_TRIANGLES); 110 | glNormal3f (0.0, 0.5, 0.5); 111 | glVertex3f (1.0, 1.0, 0.0); 112 | glVertex3f (0.0, 1.0, 0.0); 113 | glVertex3f (0.5, 0.5, 1.0); 114 | glEnd ( ); 115 | glBegin (GL_TRIANGLES); 116 | glNormal3f (-0.5, 0.0, 0.5); 117 | glVertex3f (0.0, 1.0, 0.0); 118 | glVertex3f (0.0, 0.0, 0.0); 119 | glVertex3f (0.5, 0.5, 1.0); 120 | glEnd ( ); 121 | 122 | glPopMatrix(); 123 | 124 | glLightfv(GL_LIGHT0, GL_POSITION, position); // position specified here: light position constant in W.C. 125 | 126 | glFlush (); 127 | } 128 | 129 | void _reshape (int w, int h) 130 | { 131 | glViewport (0, 0, (GLsizei) w, (GLsizei) h); 132 | glMatrixMode (GL_PROJECTION); 133 | glLoadIdentity (); 134 | // parameters for glFrustrum: left, rigth, bottom, top, near, far 135 | glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0); 136 | glMatrixMode (GL_MODELVIEW); 137 | } 138 | 139 | void _keyboard(unsigned char key, int x, int y) 140 | { 141 | switch (key) { 142 | case 27: 143 | exit(0); 144 | break; 145 | case 'w': 146 | //Camera.MoveForwards( -0.1 ) ; 147 | distance -= increment; 148 | _display(); 149 | break; 150 | case 's': 151 | //Camera.MoveForwards( 0.1 ) ; 152 | distance += increment; 153 | _display(); 154 | break; 155 | case 'a': 156 | //Camera.turnLeft ; 157 | angle -= angleIncrement; 158 | _display(); 159 | break; 160 | case 'd': 161 | //Camera.turnRight ; 162 | angle += angleIncrement; 163 | _display(); 164 | break; 165 | } 166 | } 167 | 168 | int _main(int argc, char** argv) 169 | { 170 | glutInit(&argc, argv); 171 | glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); 172 | glutInitWindowSize (500, 500); 173 | glutInitWindowPosition (100, 100); 174 | glutCreateWindow (argv[0]); 175 | _init (); 176 | glutDisplayFunc(_display); 177 | glutReshapeFunc(_reshape); 178 | glutKeyboardFunc(_keyboard); 179 | glutMainLoop(); 180 | return 0; 181 | } 182 | } -------------------------------------------------------------------------------- /challenge6/challenge6/challenge6/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace std; 12 | 13 | // Light properties 14 | GLfloat ambientColor[] = {0.4f, 0.4f, 0.4f, 1.0f}; //Color(0.2, 0.2, 0.2) 15 | 16 | GLfloat light0color[] = { 1.0, 1.0, 1.0, 0.0 }; 17 | GLfloat light0position[] = { 15.0, 5.0, 15.0, 0.0 }; // x, y, z, 1:directional 0:point 18 | 19 | GLfloat cameraDistance = 12, cameraAngle = 0; 20 | 21 | // angles = { Y rotation at shoulder, Z rotation at shoulder, Z rotation at elbow, X rotation at wrist } 22 | int arm_angles[5] = {0, 0, 0, 0, 0}; 23 | enum { SHOULDER_Y, SHOULDER_Z, ELBOW_Z, WRIST_X, WRIST_Z }; 24 | 25 | void change_angle(int angle, int delta, int minimum = 0, int maximum = 180) { 26 | arm_angles[angle] = (arm_angles[angle] + delta) % 360; 27 | arm_angles[angle] = max(arm_angles[angle], minimum); 28 | arm_angles[angle] = min(arm_angles[angle], maximum); 29 | } 30 | 31 | // Desplegar la escena 3D 32 | void display(void) { 33 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 34 | 35 | GLfloat mat_ambient[] = { 0.4, 0.4, 0.4, 1.0 }; 36 | GLfloat mat_blue[] = { 0.1, 0.2, 0.8, 1.0 }; 37 | GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; 38 | GLfloat low_shininess[] = { 2.0 }; 39 | 40 | glLoadIdentity(); 41 | GLfloat x = cameraDistance * sin(cameraAngle); 42 | GLfloat z = cameraDistance * cos(cameraAngle); 43 | gluLookAt (x, 0.0, z, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); 44 | 45 | glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor); 46 | glLightfv(GL_LIGHT0, GL_DIFFUSE, light0color); 47 | glLightfv(GL_LIGHT0, GL_POSITION, light0position); 48 | 49 | glPushMatrix(); 50 | glRotatef((GLfloat) arm_angles[SHOULDER_Y], 0., 1., 0.); 51 | glRotatef((GLfloat) arm_angles[SHOULDER_Z], 0., 0., 1.); 52 | 53 | glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); 54 | glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_blue); 55 | glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); 56 | glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess); 57 | 58 | glTranslatef(1., 0., 0.); 59 | glPushMatrix(); 60 | glScalef(2.0, 0.4, 1.0); 61 | glColor3f(1.0f, 1.0f, 1.0f); 62 | glutSolidCube(1.); // shoulder 63 | glPopMatrix(); 64 | 65 | glTranslatef(1., 0., 0.); 66 | glRotatef((GLfloat) arm_angles[ELBOW_Z], 0., 0., 1.); 67 | glTranslatef(1., 0., 0.); 68 | glPushMatrix(); 69 | glScalef(2.0, 0.4, 1.0); 70 | glColor3f(249./255., 238./255., 153./255.); 71 | glutSolidCube(1.); // elbow 72 | glPopMatrix(); 73 | 74 | glTranslatef(1., 0., 0.); 75 | glRotatef((GLfloat) arm_angles[WRIST_Z], 0., 0., 1.); 76 | glRotatef((GLfloat) arm_angles[WRIST_X], 1., 0., 0.); 77 | 78 | glTranslatef(1., 0., 0.); 79 | glPushMatrix(); 80 | glScalef(2.0, 0.4, 1.0); 81 | glColor3f(207./255., 106./255., 76./255.); 82 | glutSolidCube(1.); // wrist 83 | glPopMatrix(); 84 | glPopMatrix(); 85 | 86 | // Ejecutar los comandos 87 | glutSwapBuffers(); 88 | } 89 | 90 | 91 | // Se llama cuando cambia el tamaño de la ventana 92 | void reshape(GLsizei w, GLsizei h) { 93 | // Tamanyo del viewport 94 | glViewport(0, 0, w, h); 95 | 96 | glMatrixMode(GL_PROJECTION); 97 | glLoadIdentity(); 98 | 99 | glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 300.0); 100 | 101 | glMatrixMode(GL_MODELVIEW); 102 | glLoadIdentity(); 103 | } 104 | 105 | // Responder a los eventos de teclas especiales 106 | void specialKeys(int key, int x, int y) { 107 | GLfloat distanceDelta = 1.0, angleDelta = 5 * M_PI / 180.0; 108 | if(key == GLUT_KEY_UP) { 109 | cameraDistance -= distanceDelta; 110 | cameraDistance = max((GLfloat)2.0, cameraDistance); 111 | } 112 | if(key == GLUT_KEY_DOWN) { 113 | cameraDistance += distanceDelta; 114 | } 115 | if(key == GLUT_KEY_LEFT) { 116 | cameraAngle -= angleDelta; 117 | } 118 | if(key == GLUT_KEY_RIGHT) { 119 | cameraAngle += angleDelta; 120 | } 121 | glutPostRedisplay(); 122 | } 123 | 124 | void keyboard(unsigned char key, int x, int y) { 125 | int delta = 5; 126 | 127 | switch (key) { 128 | case 27: //ESC 129 | exit(0); 130 | case 'q': 131 | change_angle(SHOULDER_Y, delta, -180, 0); 132 | break; 133 | case 'a': 134 | change_angle(SHOULDER_Y, -delta, -180, 0); 135 | break; 136 | case 'w': 137 | change_angle(SHOULDER_Z, delta, -90, 90); 138 | break; 139 | case 's': 140 | change_angle(SHOULDER_Z, -delta, -90, 90); 141 | break; 142 | case 'e': 143 | change_angle(ELBOW_Z, delta, 0, 135); 144 | break; 145 | case 'd': 146 | change_angle(ELBOW_Z, -delta, 0, 135); 147 | break; 148 | case 'r': 149 | change_angle(WRIST_X, delta, -45, 45); 150 | break; 151 | case 'f': 152 | change_angle(WRIST_X, -delta, -45, 45); 153 | break; 154 | case 't': 155 | change_angle(WRIST_Z, delta, -15, 90); 156 | break; 157 | case 'g': 158 | change_angle(WRIST_Z, -delta, -15, 90); 159 | break; 160 | } 161 | glutPostRedisplay(); 162 | } 163 | 164 | void init(){ 165 | glClearColor (0.0, 0.0, 0.0, 0.0); 166 | glEnable(GL_DEPTH_TEST); 167 | glShadeModel(GL_SMOOTH); 168 | glEnable(GL_LIGHTING); 169 | glEnable(GL_LIGHT0); 170 | glEnable(GL_NORMALIZE); 171 | } 172 | 173 | // Programa Principal 174 | int main(int argc, char * argv[]) { 175 | glutInit(&argc, argv); 176 | glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); 177 | glutInitWindowSize(700, 700); 178 | glutCreateWindow("Brazo Robot"); 179 | glutDisplayFunc(display); 180 | glutReshapeFunc(reshape); 181 | glutSpecialFunc(specialKeys); 182 | glutKeyboardFunc(keyboard); 183 | 184 | // Inicialización 185 | init(); 186 | glutMainLoop(); 187 | } 188 | 189 | -------------------------------------------------------------------------------- /challenge6/examples/cube.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1993-1997, Silicon Graphics, Inc. 3 | * ALL RIGHTS RESERVED 4 | * Permission to use, copy, modify, and distribute this software for 5 | * any purpose and without fee is hereby granted, provided that the above 6 | * copyright notice appear in all copies and that both the copyright notice 7 | * and this permission notice appear in supporting documentation, and that 8 | * the name of Silicon Graphics, Inc. not be used in advertising 9 | * or publicity pertaining to distribution of the software without specific, 10 | * written prior permission. 11 | * 12 | * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" 13 | * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, 14 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR 15 | * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON 16 | * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, 17 | * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY 18 | * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, 19 | * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF 20 | * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN 21 | * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE 23 | * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. 24 | * 25 | * US Government Users Restricted Rights 26 | * Use, duplication, or disclosure by the Government is subject to 27 | * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph 28 | * (c)(1)(ii) of the Rights in Technical Data and Computer Software 29 | * clause at DFARS 252.227-7013 and/or in similar or successor 30 | * clauses in the FAR or the DOD or NASA FAR Supplement. 31 | * Unpublished-- rights reserved under the copyright laws of the 32 | * United States. Contractor/manufacturer is Silicon Graphics, 33 | * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. 34 | * 35 | * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. 36 | */ 37 | 38 | /* 39 | * cube.c 40 | * This program demonstrates a single modeling transformation, 41 | * glScalef() and a single viewing transformation, gluLookAt(). 42 | * A wireframe cube is rendered. 43 | */ 44 | #include 45 | #include 46 | 47 | GLfloat distancia = 5.0; 48 | GLfloat incremento = 0.1; 49 | GLfloat angulo = 0.0; 50 | GLfloat incrementoAngulo = 0.1; 51 | 52 | void init(void) 53 | { 54 | glClearColor (0.0, 0.0, 0.0, 0.0); 55 | glShadeModel (GL_FLAT); 56 | } 57 | 58 | void display(void) 59 | { 60 | glClear (GL_COLOR_BUFFER_BIT); 61 | glColor3f (1.0, 1.0, 1.0); 62 | glLoadIdentity (); /* clear the matrix */ 63 | /* viewing transformation */ 64 | //gluLookAt (0.0, 0.0, distancia, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); 65 | GLfloat x = distancia * sin(angulo); 66 | GLfloat z = distancia * cos(angulo); 67 | gluLookAt (x, 0.0, z, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); 68 | glPushMatrix(); 69 | glScalef (1.0, 2.0, 1.0); /* modeling transformation */ 70 | glutWireCube (1.0); 71 | //glutWireDodecahedron(); 72 | //glutSolidCube(1.0); 73 | glPopMatrix(); 74 | glFlush (); 75 | } 76 | 77 | void reshape (int w, int h) 78 | { 79 | glViewport (0, 0, (GLsizei) w, (GLsizei) h); 80 | glMatrixMode (GL_PROJECTION); 81 | glLoadIdentity (); 82 | glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0); 83 | glMatrixMode (GL_MODELVIEW); 84 | } 85 | 86 | void keyboard(unsigned char key, int x, int y) 87 | { 88 | switch (key) { 89 | case 27: 90 | exit(0); 91 | break; 92 | case 'w': 93 | //Camera.MoveForwards( -0.1 ) ; 94 | distancia -= incremento; 95 | display(); 96 | break; 97 | case 's': 98 | //Camera.MoveForwards( 0.1 ) ; 99 | distancia += incremento; 100 | display(); 101 | break; 102 | case 'a': 103 | //Camera.MoveForwards( -0.1 ) ; 104 | angulo -= incrementoAngulo; 105 | display(); 106 | break; 107 | case 'd': 108 | //Camera.MoveForwards( 0.1 ) ; 109 | angulo += incrementoAngulo; 110 | display(); 111 | break; 112 | } 113 | } 114 | 115 | int main(int argc, char** argv) 116 | { 117 | glutInit(&argc, argv); 118 | glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); 119 | glutInitWindowSize (500, 500); 120 | glutInitWindowPosition (100, 100); 121 | glutCreateWindow (argv[0]); 122 | init (); 123 | glutDisplayFunc(display); 124 | glutReshapeFunc(reshape); 125 | glutKeyboardFunc(keyboard); 126 | glutMainLoop(); 127 | return 0; 128 | } 129 | -------------------------------------------------------------------------------- /challenge6/examples/robot.c: -------------------------------------------------------------------------------- 1 | 2 | // robot.c: Adaptado de OpenGL Programming Guide (Neider, Davis, Woo) 3 | 4 | #include 5 | 6 | GLfloat angle, fAspect; 7 | static int shoulder = 0, elbow = 0; 8 | 9 | void elbowAdd() { 10 | elbow = (elbow + 5) % 360; 11 | } 12 | 13 | void elbowSubtract() { 14 | elbow = (elbow - 5) % 360; 15 | } 16 | 17 | void shoulderAdd() { 18 | shoulder = (shoulder + 5) % 360; 19 | } 20 | 21 | void shoulderSubtract() { 22 | shoulder = (shoulder - 5) % 360; 23 | } 24 | 25 | // Desplegar la escena 3D 26 | void display(void) 27 | { 28 | glClear(GL_COLOR_BUFFER_BIT); 29 | 30 | glColor3f(1.0f, 1.0f, 1.0f); 31 | 32 | glPushMatrix(); 33 | //glTranslatef(-1., 0., 0.); 34 | glRotatef((GLfloat) shoulder, 0., 0., 1.); 35 | glTranslatef(1., 0., 0.); 36 | glPushMatrix(); 37 | glScalef(2.0, 0.4, 1.0); 38 | glutWireCube(1.); // shoulder 39 | glPopMatrix(); 40 | 41 | glTranslatef(1., 0., 0.); 42 | glRotatef((GLfloat) elbow, 0., 0., 1.); 43 | glTranslatef(1., 0., 0.); 44 | glPushMatrix(); 45 | glScalef(2.0, 0.4, 1.0); 46 | glutWireCube(1.); // elbow 47 | glPopMatrix(); 48 | glPopMatrix(); 49 | // Ejecutar los comandos 50 | glutSwapBuffers(); 51 | } 52 | 53 | // Inicializar los parametros de despliegue 54 | void init (void) 55 | { 56 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 57 | angle=45; 58 | } 59 | 60 | // Especificar los parametros de visualizacion 61 | void visualizationParams(void) 62 | { 63 | // Sistema de coordenadas de proyeccion 64 | glMatrixMode(GL_PROJECTION); 65 | // Inicializa el sistema de coordenadas de la proyeccion 66 | glLoadIdentity(); 67 | 68 | // Especifica proyeccion perspectiva 69 | gluPerspective(angle,fAspect,0.1,500); 70 | 71 | // Especifica el sistema de coordenadas del modelo 72 | glMatrixMode(GL_MODELVIEW); 73 | // Inicializa el sistema de coordenadas del modelo 74 | glLoadIdentity(); 75 | 76 | // Especifica la posicion del observador 77 | // Posicion del ojo, hacia donde mira, vector arriba 78 | gluLookAt(0,0,15, 0,0,0, 0,1,0); 79 | } 80 | 81 | // Se llama cuando cambia el tamanyo de la ventana 82 | void reshape(GLsizei w, GLsizei h) 83 | { 84 | // Para prevenir division por 0 85 | if ( h == 0 ) h = 1; 86 | 87 | // Tamanyo del viewport 88 | glViewport(0, 0, w, h); 89 | 90 | // Aspect Ration 91 | fAspect = (GLfloat)w/(GLfloat)h; 92 | 93 | visualizationParams(); 94 | } 95 | 96 | // Responder a los eventos de teclas especiales 97 | void specialKeys(int key, int x, int y) 98 | { 99 | if(key == GLUT_KEY_UP) { 100 | elbowAdd(); 101 | } 102 | if(key == GLUT_KEY_DOWN) { 103 | elbowSubtract(); 104 | } 105 | if(key == GLUT_KEY_LEFT) { 106 | shoulderAdd(); 107 | } 108 | if(key == GLUT_KEY_RIGHT) { 109 | shoulderSubtract(); 110 | } 111 | glutPostRedisplay(); 112 | } 113 | // Programa Principal 114 | int main(void) 115 | { 116 | glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); 117 | glutInitWindowSize(500,500); 118 | glutCreateWindow("Brazo Robot"); 119 | glutDisplayFunc(display); 120 | glutReshapeFunc(reshape); 121 | glutSpecialFunc(specialKeys); 122 | init(); 123 | glutMainLoop(); 124 | } 125 | 126 | -------------------------------------------------------------------------------- /challenge6/pack/README.txt: -------------------------------------------------------------------------------- 1 | Challenge 6 - Andrés Mejía 2 | ========================== 3 | 4 | Like challenge 4 (create a robotic arm in OpenGL with 3 articulations) but add lighting to the scene. 5 | 6 | * The shoulder should rotate around the Y and Z axes. 7 | * The elbow should rotate around the Z axis. 8 | * The wrist should rotate around the X and Z axes. 9 | 10 | Run it yourself 11 | --------------- 12 | 13 | These instructions are for Mac OS X. Your mileage may vary. 14 | 15 | cd challenge6/challenge6 16 | g++ main.cpp -framework GLUT -framework OpenGL -o arm 17 | ./arm 18 | 19 | On the window that appears, press: 20 | 21 | * `q` and `a` to increase or decrease the angle of rotation around the Y axis at the shoulder. 22 | * `w` and `s` to increase or decrease the angle of rotation around the Z axis at the shoulder. 23 | * `e` and `d` to increase or decrease the angle of rotation around the Z axis at the elbow. 24 | * `r` and `f` to increase or decrease the angle of rotation around the Z axis at the wrist. 25 | * `t` and `g` to increase or decrease the angle of rotation around the X axis at the wrist. 26 | * `↑` and `↓` to increase or decrease the camera's distance to the object. 27 | * `←` and `→` to increase or decrease the camera's angle of rotation around the Z axis. 28 | 29 | Screenshots 30 | ----------- 31 | 32 | See /shots. 33 | 34 | Source code 35 | ----------- 36 | 37 | Available at https://github.com/andmej/computer_graphics_challenges. -------------------------------------------------------------------------------- /challenge6/pack/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace std; 12 | 13 | // Light properties 14 | GLfloat ambientColor[] = {0.4f, 0.4f, 0.4f, 1.0f}; //Color(0.2, 0.2, 0.2) 15 | 16 | GLfloat light0color[] = { 1.0, 1.0, 1.0, 0.0 }; 17 | GLfloat light0position[] = { 15.0, 5.0, 15.0, 0.0 }; // x, y, z, 1:directional 0:point 18 | 19 | GLfloat cameraDistance = 12, cameraAngle = 0; 20 | 21 | // angles = { Y rotation at shoulder, Z rotation at shoulder, Z rotation at elbow, X rotation at wrist } 22 | int arm_angles[5] = {0, 0, 0, 0, 0}; 23 | enum { SHOULDER_Y, SHOULDER_Z, ELBOW_Z, WRIST_X, WRIST_Z }; 24 | 25 | void change_angle(int angle, int delta, int minimum = 0, int maximum = 180) { 26 | arm_angles[angle] = (arm_angles[angle] + delta) % 360; 27 | arm_angles[angle] = max(arm_angles[angle], minimum); 28 | arm_angles[angle] = min(arm_angles[angle], maximum); 29 | } 30 | 31 | // Desplegar la escena 3D 32 | void display(void) { 33 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 34 | 35 | GLfloat mat_ambient[] = { 0.4, 0.4, 0.4, 1.0 }; 36 | GLfloat mat_blue[] = { 0.1, 0.2, 0.8, 1.0 }; 37 | GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; 38 | GLfloat low_shininess[] = { 2.0 }; 39 | 40 | glLoadIdentity(); 41 | GLfloat x = cameraDistance * sin(cameraAngle); 42 | GLfloat z = cameraDistance * cos(cameraAngle); 43 | gluLookAt (x, 0.0, z, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); 44 | 45 | glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor); 46 | glLightfv(GL_LIGHT0, GL_DIFFUSE, light0color); 47 | glLightfv(GL_LIGHT0, GL_POSITION, light0position); 48 | 49 | glPushMatrix(); 50 | glRotatef((GLfloat) arm_angles[SHOULDER_Y], 0., 1., 0.); 51 | glRotatef((GLfloat) arm_angles[SHOULDER_Z], 0., 0., 1.); 52 | 53 | glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); 54 | glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_blue); 55 | glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); 56 | glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess); 57 | 58 | glTranslatef(1., 0., 0.); 59 | glPushMatrix(); 60 | glScalef(2.0, 0.4, 1.0); 61 | glColor3f(1.0f, 1.0f, 1.0f); 62 | glutSolidCube(1.); // shoulder 63 | glPopMatrix(); 64 | 65 | glTranslatef(1., 0., 0.); 66 | glRotatef((GLfloat) arm_angles[ELBOW_Z], 0., 0., 1.); 67 | glTranslatef(1., 0., 0.); 68 | glPushMatrix(); 69 | glScalef(2.0, 0.4, 1.0); 70 | glColor3f(249./255., 238./255., 153./255.); 71 | glutSolidCube(1.); // elbow 72 | glPopMatrix(); 73 | 74 | glTranslatef(1., 0., 0.); 75 | glRotatef((GLfloat) arm_angles[WRIST_Z], 0., 0., 1.); 76 | glRotatef((GLfloat) arm_angles[WRIST_X], 1., 0., 0.); 77 | 78 | glTranslatef(1., 0., 0.); 79 | glPushMatrix(); 80 | glScalef(2.0, 0.4, 1.0); 81 | glColor3f(207./255., 106./255., 76./255.); 82 | glutSolidCube(1.); // wrist 83 | glPopMatrix(); 84 | glPopMatrix(); 85 | 86 | // Ejecutar los comandos 87 | glutSwapBuffers(); 88 | } 89 | 90 | 91 | // Se llama cuando cambia el tamaño de la ventana 92 | void reshape(GLsizei w, GLsizei h) { 93 | // Tamanyo del viewport 94 | glViewport(0, 0, w, h); 95 | 96 | glMatrixMode(GL_PROJECTION); 97 | glLoadIdentity(); 98 | 99 | glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 300.0); 100 | 101 | glMatrixMode(GL_MODELVIEW); 102 | glLoadIdentity(); 103 | } 104 | 105 | // Responder a los eventos de teclas especiales 106 | void specialKeys(int key, int x, int y) { 107 | GLfloat distanceDelta = 1.0, angleDelta = 5 * M_PI / 180.0; 108 | if(key == GLUT_KEY_UP) { 109 | cameraDistance -= distanceDelta; 110 | cameraDistance = max((GLfloat)2.0, cameraDistance); 111 | } 112 | if(key == GLUT_KEY_DOWN) { 113 | cameraDistance += distanceDelta; 114 | } 115 | if(key == GLUT_KEY_LEFT) { 116 | cameraAngle -= angleDelta; 117 | } 118 | if(key == GLUT_KEY_RIGHT) { 119 | cameraAngle += angleDelta; 120 | } 121 | glutPostRedisplay(); 122 | } 123 | 124 | void keyboard(unsigned char key, int x, int y) { 125 | int delta = 5; 126 | 127 | switch (key) { 128 | case 27: //ESC 129 | exit(0); 130 | case 'q': 131 | change_angle(SHOULDER_Y, delta, -180, 0); 132 | break; 133 | case 'a': 134 | change_angle(SHOULDER_Y, -delta, -180, 0); 135 | break; 136 | case 'w': 137 | change_angle(SHOULDER_Z, delta, -90, 90); 138 | break; 139 | case 's': 140 | change_angle(SHOULDER_Z, -delta, -90, 90); 141 | break; 142 | case 'e': 143 | change_angle(ELBOW_Z, delta, 0, 135); 144 | break; 145 | case 'd': 146 | change_angle(ELBOW_Z, -delta, 0, 135); 147 | break; 148 | case 'r': 149 | change_angle(WRIST_X, delta, -45, 45); 150 | break; 151 | case 'f': 152 | change_angle(WRIST_X, -delta, -45, 45); 153 | break; 154 | case 't': 155 | change_angle(WRIST_Z, delta, -15, 90); 156 | break; 157 | case 'g': 158 | change_angle(WRIST_Z, -delta, -15, 90); 159 | break; 160 | } 161 | glutPostRedisplay(); 162 | } 163 | 164 | void init(){ 165 | glClearColor (0.0, 0.0, 0.0, 0.0); 166 | glEnable(GL_DEPTH_TEST); 167 | glShadeModel(GL_SMOOTH); 168 | glEnable(GL_LIGHTING); 169 | glEnable(GL_LIGHT0); 170 | glEnable(GL_NORMALIZE); 171 | } 172 | 173 | // Programa Principal 174 | int main(int argc, char * argv[]) { 175 | glutInit(&argc, argv); 176 | glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); 177 | glutInitWindowSize(700, 700); 178 | glutCreateWindow("Brazo Robot"); 179 | glutDisplayFunc(display); 180 | glutReshapeFunc(reshape); 181 | glutSpecialFunc(specialKeys); 182 | glutKeyboardFunc(keyboard); 183 | 184 | // Inicialización 185 | init(); 186 | glutMainLoop(); 187 | } 188 | 189 | -------------------------------------------------------------------------------- /challenge6/pack/reto6.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge6/pack/reto6.zip -------------------------------------------------------------------------------- /challenge6/pack/shots/Screen shot 2011-10-07 at 16.59.53.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge6/pack/shots/Screen shot 2011-10-07 at 16.59.53.png -------------------------------------------------------------------------------- /challenge6/pack/shots/Screen shot 2011-10-07 at 17.00.00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge6/pack/shots/Screen shot 2011-10-07 at 17.00.00.png -------------------------------------------------------------------------------- /challenge6/pack/shots/Screen shot 2011-10-07 at 17.00.06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge6/pack/shots/Screen shot 2011-10-07 at 17.00.06.png -------------------------------------------------------------------------------- /challenge6/pack/shots/Screen shot 2011-10-07 at 17.00.12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge6/pack/shots/Screen shot 2011-10-07 at 17.00.12.png -------------------------------------------------------------------------------- /challenge6/pack/shots/Screen shot 2011-10-07 at 17.00.17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge6/pack/shots/Screen shot 2011-10-07 at 17.00.17.png -------------------------------------------------------------------------------- /challenge6/pack/shots/Screen shot 2011-10-07 at 17.00.20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge6/pack/shots/Screen shot 2011-10-07 at 17.00.20.png -------------------------------------------------------------------------------- /challenge6/pack/shots/Screen shot 2011-10-07 at 17.00.24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge6/pack/shots/Screen shot 2011-10-07 at 17.00.24.png -------------------------------------------------------------------------------- /challenge6/pack/shots/Screen shot 2011-10-07 at 17.00.29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge6/pack/shots/Screen shot 2011-10-07 at 17.00.29.png -------------------------------------------------------------------------------- /challenge6/pack/shots/Screen shot 2011-10-07 at 17.00.53.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge6/pack/shots/Screen shot 2011-10-07 at 17.00.53.png -------------------------------------------------------------------------------- /challenge6/pack/shots/Screen shot 2011-10-07 at 17.00.59.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge6/pack/shots/Screen shot 2011-10-07 at 17.00.59.png -------------------------------------------------------------------------------- /challenge6/pack/shots/Screen shot 2011-10-07 at 17.01.09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge6/pack/shots/Screen shot 2011-10-07 at 17.01.09.png -------------------------------------------------------------------------------- /challenge6/project/src/arm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge6/project/src/arm -------------------------------------------------------------------------------- /challenge6/shots/Screen shot 2011-10-07 at 16.59.53.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge6/shots/Screen shot 2011-10-07 at 16.59.53.png -------------------------------------------------------------------------------- /challenge6/shots/Screen shot 2011-10-07 at 17.00.00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge6/shots/Screen shot 2011-10-07 at 17.00.00.png -------------------------------------------------------------------------------- /challenge6/shots/Screen shot 2011-10-07 at 17.00.06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge6/shots/Screen shot 2011-10-07 at 17.00.06.png -------------------------------------------------------------------------------- /challenge6/shots/Screen shot 2011-10-07 at 17.00.12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge6/shots/Screen shot 2011-10-07 at 17.00.12.png -------------------------------------------------------------------------------- /challenge6/shots/Screen shot 2011-10-07 at 17.00.17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge6/shots/Screen shot 2011-10-07 at 17.00.17.png -------------------------------------------------------------------------------- /challenge6/shots/Screen shot 2011-10-07 at 17.00.20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge6/shots/Screen shot 2011-10-07 at 17.00.20.png -------------------------------------------------------------------------------- /challenge6/shots/Screen shot 2011-10-07 at 17.00.24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge6/shots/Screen shot 2011-10-07 at 17.00.24.png -------------------------------------------------------------------------------- /challenge6/shots/Screen shot 2011-10-07 at 17.00.29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge6/shots/Screen shot 2011-10-07 at 17.00.29.png -------------------------------------------------------------------------------- /challenge6/shots/Screen shot 2011-10-07 at 17.00.53.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge6/shots/Screen shot 2011-10-07 at 17.00.53.png -------------------------------------------------------------------------------- /challenge6/shots/Screen shot 2011-10-07 at 17.00.59.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge6/shots/Screen shot 2011-10-07 at 17.00.59.png -------------------------------------------------------------------------------- /challenge6/shots/Screen shot 2011-10-07 at 17.01.09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge6/shots/Screen shot 2011-10-07 at 17.01.09.png -------------------------------------------------------------------------------- /challenge7/README.md: -------------------------------------------------------------------------------- 1 | Challenge 7 2 | =========== 3 | 4 | Like challenge 6 (create a robotic arm in OpenGL with 3 articulations and lighting) but add textures. 5 | 6 | * The shoulder should rotate around the Y and Z axes. 7 | * The elbow should rotate around the Z axis. 8 | * The wrist should rotate around the X and Z axes. 9 | 10 | Run it yourself 11 | --------------- 12 | 13 | These instructions are for Mac OS X. Your mileage may vary. 14 | 15 | cd challenge7/src 16 | g++ RgbImage.cpp main.cpp -framework GLUT -framework OpenGL -o arm 17 | ./arm 18 | 19 | On the window that appears, press: 20 | 21 | * `q` and `a` to increase or decrease the angle of rotation around the Y axis at the shoulder. 22 | * `w` and `s` to increase or decrease the angle of rotation around the Z axis at the shoulder. 23 | * `e` and `d` to increase or decrease the angle of rotation around the Z axis at the elbow. 24 | * `r` and `f` to increase or decrease the angle of rotation around the Z axis at the wrist. 25 | * `t` and `g` to increase or decrease the angle of rotation around the X axis at the wrist. 26 | * `↑` and `↓` to increase or decrease the camera's distance to the object. 27 | * `←` and `→` to increase or decrease the camera's angle of rotation around the Z axis. 28 | 29 | Screenshot 30 | ----------- 31 | 32 | ![Screenshot](https://github.com/andmej/computer_graphics_challenges/blob/master/challenge7/shots/Screen%20shot%202011-10-19%20at%2020.20.35.png?raw=true) 33 | -------------------------------------------------------------------------------- /challenge7/challenge7/challenge7.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 32EDCB38144F9B8A00CFCF30 /* GLUT.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 32EDCB37144F9B8A00CFCF30 /* GLUT.framework */; }; 11 | 32EDCB3A144F9B8F00CFCF30 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 32EDCB39144F9B8F00CFCF30 /* OpenGL.framework */; }; 12 | 32EDCB3F144F9C9B00CFCF30 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 32EDCB3B144F9C9B00CFCF30 /* main.cpp */; }; 13 | 32EDCB40144F9C9B00CFCF30 /* RgbImage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 32EDCB3D144F9C9B00CFCF30 /* RgbImage.cpp */; }; 14 | /* End PBXBuildFile section */ 15 | 16 | /* Begin PBXCopyFilesBuildPhase section */ 17 | 32EDCB29144F9B3000CFCF30 /* CopyFiles */ = { 18 | isa = PBXCopyFilesBuildPhase; 19 | buildActionMask = 2147483647; 20 | dstPath = /usr/share/man/man1/; 21 | dstSubfolderSpec = 0; 22 | files = ( 23 | ); 24 | runOnlyForDeploymentPostprocessing = 1; 25 | }; 26 | /* End PBXCopyFilesBuildPhase section */ 27 | 28 | /* Begin PBXFileReference section */ 29 | 32EDCB2B144F9B3000CFCF30 /* challenge7 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = challenge7; sourceTree = BUILT_PRODUCTS_DIR; }; 30 | 32EDCB37144F9B8A00CFCF30 /* GLUT.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GLUT.framework; path = System/Library/Frameworks/GLUT.framework; sourceTree = SDKROOT; }; 31 | 32EDCB39144F9B8F00CFCF30 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = System/Library/Frameworks/OpenGL.framework; sourceTree = SDKROOT; }; 32 | 32EDCB3B144F9C9B00CFCF30 /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = main.cpp; path = src/main.cpp; sourceTree = ""; }; 33 | 32EDCB3D144F9C9B00CFCF30 /* RgbImage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RgbImage.cpp; path = src/RgbImage.cpp; sourceTree = ""; }; 34 | 32EDCB3E144F9C9B00CFCF30 /* RgbImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RgbImage.h; path = src/RgbImage.h; sourceTree = ""; }; 35 | /* End PBXFileReference section */ 36 | 37 | /* Begin PBXFrameworksBuildPhase section */ 38 | 32EDCB28144F9B3000CFCF30 /* Frameworks */ = { 39 | isa = PBXFrameworksBuildPhase; 40 | buildActionMask = 2147483647; 41 | files = ( 42 | 32EDCB3A144F9B8F00CFCF30 /* OpenGL.framework in Frameworks */, 43 | 32EDCB38144F9B8A00CFCF30 /* GLUT.framework in Frameworks */, 44 | ); 45 | runOnlyForDeploymentPostprocessing = 0; 46 | }; 47 | /* End PBXFrameworksBuildPhase section */ 48 | 49 | /* Begin PBXGroup section */ 50 | 32EDCB20144F9B2F00CFCF30 = { 51 | isa = PBXGroup; 52 | children = ( 53 | 32EDCB3B144F9C9B00CFCF30 /* main.cpp */, 54 | 32EDCB3D144F9C9B00CFCF30 /* RgbImage.cpp */, 55 | 32EDCB3E144F9C9B00CFCF30 /* RgbImage.h */, 56 | 32EDCB39144F9B8F00CFCF30 /* OpenGL.framework */, 57 | 32EDCB37144F9B8A00CFCF30 /* GLUT.framework */, 58 | 32EDCB2C144F9B3000CFCF30 /* Products */, 59 | ); 60 | sourceTree = ""; 61 | }; 62 | 32EDCB2C144F9B3000CFCF30 /* Products */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | 32EDCB2B144F9B3000CFCF30 /* challenge7 */, 66 | ); 67 | name = Products; 68 | sourceTree = ""; 69 | }; 70 | /* End PBXGroup section */ 71 | 72 | /* Begin PBXNativeTarget section */ 73 | 32EDCB2A144F9B3000CFCF30 /* challenge7 */ = { 74 | isa = PBXNativeTarget; 75 | buildConfigurationList = 32EDCB34144F9B3000CFCF30 /* Build configuration list for PBXNativeTarget "challenge7" */; 76 | buildPhases = ( 77 | 32EDCB27144F9B3000CFCF30 /* Sources */, 78 | 32EDCB28144F9B3000CFCF30 /* Frameworks */, 79 | 32EDCB29144F9B3000CFCF30 /* CopyFiles */, 80 | ); 81 | buildRules = ( 82 | ); 83 | dependencies = ( 84 | ); 85 | name = challenge7; 86 | productName = challenge7; 87 | productReference = 32EDCB2B144F9B3000CFCF30 /* challenge7 */; 88 | productType = "com.apple.product-type.tool"; 89 | }; 90 | /* End PBXNativeTarget section */ 91 | 92 | /* Begin PBXProject section */ 93 | 32EDCB22144F9B2F00CFCF30 /* Project object */ = { 94 | isa = PBXProject; 95 | buildConfigurationList = 32EDCB25144F9B2F00CFCF30 /* Build configuration list for PBXProject "challenge7" */; 96 | compatibilityVersion = "Xcode 3.2"; 97 | developmentRegion = English; 98 | hasScannedForEncodings = 0; 99 | knownRegions = ( 100 | en, 101 | ); 102 | mainGroup = 32EDCB20144F9B2F00CFCF30; 103 | productRefGroup = 32EDCB2C144F9B3000CFCF30 /* Products */; 104 | projectDirPath = ""; 105 | projectRoot = ""; 106 | targets = ( 107 | 32EDCB2A144F9B3000CFCF30 /* challenge7 */, 108 | ); 109 | }; 110 | /* End PBXProject section */ 111 | 112 | /* Begin PBXSourcesBuildPhase section */ 113 | 32EDCB27144F9B3000CFCF30 /* Sources */ = { 114 | isa = PBXSourcesBuildPhase; 115 | buildActionMask = 2147483647; 116 | files = ( 117 | 32EDCB3F144F9C9B00CFCF30 /* main.cpp in Sources */, 118 | 32EDCB40144F9C9B00CFCF30 /* RgbImage.cpp in Sources */, 119 | ); 120 | runOnlyForDeploymentPostprocessing = 0; 121 | }; 122 | /* End PBXSourcesBuildPhase section */ 123 | 124 | /* Begin XCBuildConfiguration section */ 125 | 32EDCB32144F9B3000CFCF30 /* Debug */ = { 126 | isa = XCBuildConfiguration; 127 | buildSettings = { 128 | ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; 129 | GCC_C_LANGUAGE_STANDARD = gnu99; 130 | GCC_OPTIMIZATION_LEVEL = 0; 131 | GCC_PREPROCESSOR_DEFINITIONS = DEBUG; 132 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 133 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0; 134 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 135 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 136 | GCC_WARN_UNUSED_VARIABLE = YES; 137 | MACOSX_DEPLOYMENT_TARGET = 10.6; 138 | ONLY_ACTIVE_ARCH = YES; 139 | SDKROOT = macosx; 140 | }; 141 | name = Debug; 142 | }; 143 | 32EDCB33144F9B3000CFCF30 /* Release */ = { 144 | isa = XCBuildConfiguration; 145 | buildSettings = { 146 | ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; 147 | GCC_C_LANGUAGE_STANDARD = gnu99; 148 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0; 149 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 150 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 151 | GCC_WARN_UNUSED_VARIABLE = YES; 152 | MACOSX_DEPLOYMENT_TARGET = 10.6; 153 | SDKROOT = macosx; 154 | }; 155 | name = Release; 156 | }; 157 | 32EDCB35144F9B3000CFCF30 /* Debug */ = { 158 | isa = XCBuildConfiguration; 159 | buildSettings = { 160 | ALWAYS_SEARCH_USER_PATHS = NO; 161 | COPY_PHASE_STRIP = NO; 162 | GCC_DYNAMIC_NO_PIC = NO; 163 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 164 | PRODUCT_NAME = "$(TARGET_NAME)"; 165 | }; 166 | name = Debug; 167 | }; 168 | 32EDCB36144F9B3000CFCF30 /* Release */ = { 169 | isa = XCBuildConfiguration; 170 | buildSettings = { 171 | ALWAYS_SEARCH_USER_PATHS = NO; 172 | COPY_PHASE_STRIP = YES; 173 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 174 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 175 | PRODUCT_NAME = "$(TARGET_NAME)"; 176 | }; 177 | name = Release; 178 | }; 179 | /* End XCBuildConfiguration section */ 180 | 181 | /* Begin XCConfigurationList section */ 182 | 32EDCB25144F9B2F00CFCF30 /* Build configuration list for PBXProject "challenge7" */ = { 183 | isa = XCConfigurationList; 184 | buildConfigurations = ( 185 | 32EDCB32144F9B3000CFCF30 /* Debug */, 186 | 32EDCB33144F9B3000CFCF30 /* Release */, 187 | ); 188 | defaultConfigurationIsVisible = 0; 189 | defaultConfigurationName = Release; 190 | }; 191 | 32EDCB34144F9B3000CFCF30 /* Build configuration list for PBXNativeTarget "challenge7" */ = { 192 | isa = XCConfigurationList; 193 | buildConfigurations = ( 194 | 32EDCB35144F9B3000CFCF30 /* Debug */, 195 | 32EDCB36144F9B3000CFCF30 /* Release */, 196 | ); 197 | defaultConfigurationIsVisible = 0; 198 | }; 199 | /* End XCConfigurationList section */ 200 | }; 201 | rootObject = 32EDCB22144F9B2F00CFCF30 /* Project object */; 202 | } 203 | -------------------------------------------------------------------------------- /challenge7/challenge7/src/RgbImage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * RayTrace Software Package, release 1.0.4, February 2004. 4 | * 5 | * Author: Samuel R. Buss 6 | * 7 | * Software accompanying the book 8 | * 3D Computer Graphics: A Mathematical Introduction with OpenGL, 9 | * by S. Buss, Cambridge University Press, 2003. 10 | * 11 | * Software is "as-is" and carries no warranty. It may be used without 12 | * restriction, but if you modify it, please change the filenames to 13 | * prevent confusion between different versions. Please acknowledge 14 | * all use of the software in any publications or products based on it. 15 | * 16 | * Bug reports: Sam Buss, sbuss@ucsd.edu. 17 | * Web page: http://math.ucsd.edu/~sbuss/MathCG 18 | * 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | 26 | // Include the next line to turn off the routines that use OpenGL 27 | // #define RGBIMAGE_DONT_USE_OPENGL 28 | 29 | class RgbImage 30 | { 31 | public: 32 | RgbImage(); 33 | RgbImage( const char* filename ); 34 | RgbImage( int numRows, int numCols ); // Initialize a blank bitmap of this size. 35 | ~RgbImage(); 36 | 37 | bool LoadBmpFile( const char *filename ); // Loads the bitmap from the specified file 38 | bool WriteBmpFile( const char* filename ); // Write the bitmap to the specified file 39 | #ifndef RGBIMAGE_DONT_USE_OPENGL 40 | bool LoadFromOpenglBuffer(); // Load the bitmap from the current OpenGL buffer 41 | #endif 42 | 43 | int GetNumRows() const { return NumRows; } 44 | int GetNumCols() const { return NumCols; } 45 | // Rows are word aligned 46 | int GetNumBytesPerRow() const { return ((3*NumCols+3)>>2)<<2; } 47 | const void* ImageData() const { return (void*)ImagePtr; } 48 | 49 | const unsigned char* GetRgbPixel( long row, long col ) const; 50 | unsigned char* GetRgbPixel( long row, long col ); 51 | void GetRgbPixel( long row, long col, float* red, float* green, float* blue ) const; 52 | void GetRgbPixel( long row, long col, double* red, double* green, double* blue ) const; 53 | 54 | void SetRgbPixelf( long row, long col, double red, double green, double blue ); 55 | void SetRgbPixelc( long row, long col, 56 | unsigned char red, unsigned char green, unsigned char blue ); 57 | 58 | // Error reporting. (errors also print message to stderr) 59 | int GetErrorCode() const { return ErrorCode; } 60 | enum { 61 | NoError = 0, 62 | OpenError = 1, // Unable to open file for reading 63 | FileFormatError = 2, // Not recognized as a 24 bit BMP file 64 | MemoryError = 3, // Unable to allocate memory for image data 65 | ReadError = 4, // End of file reached prematurely 66 | WriteError = 5 // Unable to write out data (or no date to write out) 67 | }; 68 | bool ImageLoaded() const { return (ImagePtr!=0); } // Is an image loaded? 69 | 70 | void Reset(); // Frees image data memory 71 | 72 | private: 73 | unsigned char* ImagePtr; // array of pixel values (integers range 0 to 255) 74 | int NumRows; // number of rows in image 75 | int NumCols; // number of columns in image 76 | int ErrorCode; // error code 77 | 78 | static short readShort( FILE* infile ); 79 | static long readLong( FILE* infile ); 80 | static void skipChars( FILE* infile, int numChars ); 81 | static void writeLong( long data, FILE* outfile ); 82 | static void writeShort( short data, FILE* outfile ); 83 | 84 | static unsigned char doubleToUnsignedChar( double x ); 85 | 86 | }; 87 | 88 | inline RgbImage::RgbImage() 89 | { 90 | NumRows = 0; 91 | NumCols = 0; 92 | ImagePtr = 0; 93 | ErrorCode = 0; 94 | } 95 | 96 | inline RgbImage::RgbImage( const char* filename ) 97 | { 98 | NumRows = 0; 99 | NumCols = 0; 100 | ImagePtr = 0; 101 | ErrorCode = 0; 102 | LoadBmpFile( filename ); 103 | } 104 | 105 | inline RgbImage::~RgbImage() 106 | { 107 | delete[] ImagePtr; 108 | } 109 | 110 | // Returned value points to three "unsigned char" values for R,G,B 111 | inline const unsigned char* RgbImage::GetRgbPixel( long row, long col ) const 112 | { 113 | assert ( row 24 | #include 25 | 26 | // Include the next line to turn off the routines that use OpenGL 27 | // #define RGBIMAGE_DONT_USE_OPENGL 28 | 29 | class RgbImage 30 | { 31 | public: 32 | RgbImage(); 33 | RgbImage( const char* filename ); 34 | RgbImage( int numRows, int numCols ); // Initialize a blank bitmap of this size. 35 | ~RgbImage(); 36 | 37 | bool LoadBmpFile( const char *filename ); // Loads the bitmap from the specified file 38 | bool WriteBmpFile( const char* filename ); // Write the bitmap to the specified file 39 | #ifndef RGBIMAGE_DONT_USE_OPENGL 40 | bool LoadFromOpenglBuffer(); // Load the bitmap from the current OpenGL buffer 41 | #endif 42 | 43 | long GetNumRows() const { return NumRows; } 44 | long GetNumCols() const { return NumCols; } 45 | // Rows are word aligned 46 | long GetNumBytesPerRow() const { return ((3*NumCols+3)>>2)<<2; } 47 | const void* ImageData() const { return (void*)ImagePtr; } 48 | 49 | const unsigned char* GetRgbPixel( long row, long col ) const; 50 | unsigned char* GetRgbPixel( long row, long col ); 51 | void GetRgbPixel( long row, long col, float* red, float* green, float* blue ) const; 52 | void GetRgbPixel( long row, long col, double* red, double* green, double* blue ) const; 53 | 54 | void SetRgbPixelf( long row, long col, double red, double green, double blue ); 55 | void SetRgbPixelc( long row, long col, 56 | unsigned char red, unsigned char green, unsigned char blue ); 57 | 58 | // Error reporting. (errors also print message to stderr) 59 | int GetErrorCode() const { return ErrorCode; } 60 | enum { 61 | NoError = 0, 62 | OpenError = 1, // Unable to open file for reading 63 | FileFormatError = 2, // Not recognized as a 24 bit BMP file 64 | MemoryError = 3, // Unable to allocate memory for image data 65 | ReadError = 4, // End of file reached prematurely 66 | WriteError = 5 // Unable to write out data (or no date to write out) 67 | }; 68 | bool ImageLoaded() const { return (ImagePtr!=0); } // Is an image loaded? 69 | 70 | void Reset(); // Frees image data memory 71 | 72 | private: 73 | unsigned char* ImagePtr; // array of pixel values (integers range 0 to 255) 74 | long NumRows; // number of rows in image 75 | long NumCols; // number of columns in image 76 | int ErrorCode; // error code 77 | 78 | static short readShort( FILE* infile ); 79 | static long readLong( FILE* infile ); 80 | static void skipChars( FILE* infile, int numChars ); 81 | static void RgbImage::writeLong( long data, FILE* outfile ); 82 | static void RgbImage::writeShort( short data, FILE* outfile ); 83 | 84 | static unsigned char doubleToUnsignedChar( double x ); 85 | 86 | }; 87 | 88 | inline RgbImage::RgbImage() 89 | { 90 | NumRows = 0; 91 | NumCols = 0; 92 | ImagePtr = 0; 93 | ErrorCode = 0; 94 | } 95 | 96 | inline RgbImage::RgbImage( const char* filename ) 97 | { 98 | NumRows = 0; 99 | NumCols = 0; 100 | ImagePtr = 0; 101 | ErrorCode = 0; 102 | LoadBmpFile( filename ); 103 | } 104 | 105 | inline RgbImage::~RgbImage() 106 | { 107 | delete[] ImagePtr; 108 | } 109 | 110 | // Returned value points to three "unsigned char" values for R,G,B 111 | inline const unsigned char* RgbImage::GetRgbPixel( long row, long col ) const 112 | { 113 | assert ( row 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | #include "RgbImage.h" 31 | 32 | /* 33 | * Read a texture map from a BMP bitmap file. 34 | */ 35 | void loadTextureFromFile(char *filename) 36 | { 37 | glClearColor (0.0, 0.0, 0.0, 0.0); 38 | glShadeModel(GL_FLAT); 39 | glEnable(GL_DEPTH_TEST); 40 | 41 | RgbImage theTexMap( filename ); 42 | 43 | // Pixel alignment: each row is word aligned (aligned to a 4 byte boundary) 44 | // Therefore, no need to call glPixelStore( GL_UNPACK_ALIGNMENT, ... ); 45 | 46 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 47 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 48 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 49 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 50 | 51 | gluBuild2DMipmaps(GL_TEXTURE_2D, 3,theTexMap.GetNumCols(), theTexMap.GetNumRows(), 52 | GL_RGB, GL_UNSIGNED_BYTE, theTexMap.ImageData() ); 53 | 54 | } 55 | 56 | /* 57 | * Draw the texture in the OpenGL graphics window 58 | */ 59 | void drawScene(void) 60 | { 61 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 62 | glEnable(GL_TEXTURE_2D); 63 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 64 | 65 | glLoadIdentity(); 66 | glTranslated(0, 0, 10); 67 | glRotated(35, 0, 0, 1); 68 | glRotated(35, 1, 0, 0); 69 | 70 | glBegin(GL_QUADS); 71 | 72 | glTexCoord2f(0.0, 0.0); 73 | glVertex3f(-1.0, -1.0, 0.0); 74 | 75 | glTexCoord2f(0.0, 1.0); 76 | glVertex3f(-1.0, 1.0, 0.0); 77 | 78 | glTexCoord2f(1.0, 1.0); 79 | glVertex3f(1.0, 1.0, 0.0); 80 | 81 | glTexCoord2f(1.0, 0.0); 82 | glVertex3f(1.0, -1.0, 0.0); 83 | 84 | glEnd(); 85 | 86 | glFlush(); 87 | glDisable(GL_TEXTURE_2D); 88 | } 89 | 90 | void resizeWindow(int w, int h) 91 | { 92 | float viewWidth = 1.1; 93 | float viewHeight = 1.1; 94 | glViewport(0, 0, w, h); 95 | h = (h==0) ? 1 : h; 96 | w = (w==0) ? 1 : w; 97 | glMatrixMode(GL_PROJECTION); 98 | glLoadIdentity(); 99 | if ( h < w ) { 100 | viewWidth *= (float)w/(float)h; 101 | } 102 | else { 103 | viewHeight *= (float)h/(float)w; 104 | } 105 | glOrtho( -viewWidth, viewWidth, -viewHeight, viewHeight, -10.0, 10.0 ); 106 | 107 | glMatrixMode(GL_MODELVIEW); 108 | glLoadIdentity(); 109 | } 110 | 111 | void keyboard (unsigned char key, int x, int y) 112 | { 113 | switch (key) { 114 | case 27: 115 | exit(0); 116 | break; 117 | default: 118 | break; 119 | } 120 | } 121 | 122 | char* filename = "RedLeavesTexture.bmp"; 123 | 124 | int main(int argc, char** argv) 125 | { 126 | glutInit(&argc, argv); 127 | glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); 128 | glutInitWindowSize(240, 240); 129 | glutInitWindowPosition(100, 100); 130 | glutCreateWindow(argv[0]); 131 | 132 | loadTextureFromFile( filename ); 133 | 134 | glutDisplayFunc(drawScene); 135 | glutReshapeFunc(resizeWindow); 136 | glutKeyboardFunc(keyboard); 137 | glutMainLoop(); 138 | return 0; 139 | } 140 | -------------------------------------------------------------------------------- /challenge7/example/Example/src/TextureBMP.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge7/example/Example/src/TextureBMP.exe -------------------------------------------------------------------------------- /challenge7/example/Example/src/TextureBMP.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | TextureBMP program 5 | 6 | 7 | 8 | 9 | 10 |

TextureBMP

11 | 12 |

TextureBMP is sample C++ code illustrating the use of textures in 13 | OpenGL.   It is intended to accompany the book 3D Computer Graphics: A 14 | mathematical approach with OpenGL, by S. Buss, Cambridge University Press, 15 | 2003.   However, it can be used independently as well.

16 | 17 |

TextureBMP reads a texture map from a bitmap file (.bmp 18 | extension).  Bitmap files can be created with many standard graphics editting 19 | programs, include the PC program Paint.   These programs often 20 | allow coverting other file formats to bitmap images.   The main program is in TextureMap.cpp. 21 |   The C++ class RgbImage is used to read the image data 22 | from a bitmap file.

23 | 24 |

There are several options for downloading the files. 25 | 26 |

37 | 38 |

Things to look at: 39 | 40 |

    41 |
  1. Compile and run the program.  Note how it behaves when the window is resized larger 42 | and smaller.  Do you see an unwanted aliasing problems?
  2. 43 |
  3. Look at how texture coordinates must be explicitly given with glTexCoord2f 44 | commands as the quad is drawn.
  4. 45 |
  5. The RgbImage class returns the pixels in an array.  Each row of the array begins on 46 | a word boundary (so the rows are padded as necessary to make this work).  This is 47 | what OpenGL expects by default, otherwise, we would have had use the glPixelStore 48 | command to inform OpenGL about the row alignment.
  6. 49 |
  7. Try modifying the program to display the mirror-image of the texture.  You do not 50 | need to modify the texture, just the teture coordinates.
  8. 51 |
52 | 53 |

 

54 | 55 | 56 | -------------------------------------------------------------------------------- /challenge7/example/TextureBMP.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge7/example/TextureBMP.zip -------------------------------------------------------------------------------- /challenge7/pack/README.txt: -------------------------------------------------------------------------------- 1 | Challenge 7 - Andrés Mejía 2 | ========================== 3 | 4 | Like challenge 6 (create a robotic arm in OpenGL with 3 articulations and lighting) but add textures. 5 | 6 | * The shoulder should rotate around the Y and Z axes. 7 | * The elbow should rotate around the Z axis. 8 | * The wrist should rotate around the X and Z axes. 9 | 10 | Run it yourself 11 | --------------- 12 | 13 | These instructions are for Mac OS X. Your mileage may vary. 14 | 15 | cd challenge7/src 16 | g++ RgbImage.cpp main.cpp -framework GLUT -framework OpenGL -o arm 17 | ./arm 18 | 19 | On the window that appears, press: 20 | 21 | * `q` and `a` to increase or decrease the angle of rotation around the Y axis at the shoulder. 22 | * `w` and `s` to increase or decrease the angle of rotation around the Z axis at the shoulder. 23 | * `e` and `d` to increase or decrease the angle of rotation around the Z axis at the elbow. 24 | * `r` and `f` to increase or decrease the angle of rotation around the Z axis at the wrist. 25 | * `t` and `g` to increase or decrease the angle of rotation around the X axis at the wrist. 26 | * `↑` and `↓` to increase or decrease the camera's distance to the object. 27 | * `←` and `→` to increase or decrease the camera's angle of rotation around the Z axis. 28 | 29 | Screenshots 30 | ----------- 31 | 32 | See /shots. 33 | 34 | Source code 35 | ----------- 36 | 37 | Available at https://github.com/andmej/computer_graphics_challenges. -------------------------------------------------------------------------------- /challenge7/pack/reto7.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge7/pack/reto7.zip -------------------------------------------------------------------------------- /challenge7/pack/shots/Screen shot 2011-10-19 at 20.19.57.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge7/pack/shots/Screen shot 2011-10-19 at 20.19.57.png -------------------------------------------------------------------------------- /challenge7/pack/shots/Screen shot 2011-10-19 at 20.20.24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge7/pack/shots/Screen shot 2011-10-19 at 20.20.24.png -------------------------------------------------------------------------------- /challenge7/pack/shots/Screen shot 2011-10-19 at 20.20.31.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge7/pack/shots/Screen shot 2011-10-19 at 20.20.31.png -------------------------------------------------------------------------------- /challenge7/pack/shots/Screen shot 2011-10-19 at 20.20.35.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge7/pack/shots/Screen shot 2011-10-19 at 20.20.35.png -------------------------------------------------------------------------------- /challenge7/pack/shots/Screen shot 2011-10-19 at 20.20.43.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge7/pack/shots/Screen shot 2011-10-19 at 20.20.43.png -------------------------------------------------------------------------------- /challenge7/pack/shots/Screen shot 2011-10-19 at 20.21.07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge7/pack/shots/Screen shot 2011-10-19 at 20.21.07.png -------------------------------------------------------------------------------- /challenge7/pack/shots/Screen shot 2011-10-19 at 20.21.13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge7/pack/shots/Screen shot 2011-10-19 at 20.21.13.png -------------------------------------------------------------------------------- /challenge7/pack/shots/Screen shot 2011-10-19 at 20.21.26.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge7/pack/shots/Screen shot 2011-10-19 at 20.21.26.png -------------------------------------------------------------------------------- /challenge7/pack/shots/Screen shot 2011-10-19 at 20.21.33.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge7/pack/shots/Screen shot 2011-10-19 at 20.21.33.png -------------------------------------------------------------------------------- /challenge7/pack/shots/Screen shot 2011-10-19 at 20.21.38.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge7/pack/shots/Screen shot 2011-10-19 at 20.21.38.png -------------------------------------------------------------------------------- /challenge7/pack/shots/Screen shot 2011-10-19 at 20.21.41.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge7/pack/shots/Screen shot 2011-10-19 at 20.21.41.png -------------------------------------------------------------------------------- /challenge7/pack/shots/Screen shot 2011-10-19 at 20.21.46.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge7/pack/shots/Screen shot 2011-10-19 at 20.21.46.png -------------------------------------------------------------------------------- /challenge7/pack/shots/Screen shot 2011-10-19 at 20.21.54.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge7/pack/shots/Screen shot 2011-10-19 at 20.21.54.png -------------------------------------------------------------------------------- /challenge7/pack/shots/Screen shot 2011-10-19 at 20.22.05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge7/pack/shots/Screen shot 2011-10-19 at 20.22.05.png -------------------------------------------------------------------------------- /challenge7/pack/shots/Screen shot 2011-10-19 at 20.22.32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mejibyte/computer_graphics_challenges/b99c4b10582d14ef2d52f2bb676784c4493829b1/challenge7/pack/shots/Screen shot 2011-10-19 at 20.22.32.png -------------------------------------------------------------------------------- /challenge7/pack/src/RgbImage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * RayTrace Software Package, release 1.0.4, February 2004. 4 | * 5 | * Author: Samuel R. Buss 6 | * 7 | * Software accompanying the book 8 | * 3D Computer Graphics: A Mathematical Introduction with OpenGL, 9 | * by S. Buss, Cambridge University Press, 2003. 10 | * 11 | * Software is "as-is" and carries no warranty. It may be used without 12 | * restriction, but if you modify it, please change the filenames to 13 | * prevent confusion between different versions. Please acknowledge 14 | * all use of the software in any publications or products based on it. 15 | * 16 | * Bug reports: Sam Buss, sbuss@ucsd.edu. 17 | * Web page: http://math.ucsd.edu/~sbuss/MathCG 18 | * 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | 26 | // Include the next line to turn off the routines that use OpenGL 27 | // #define RGBIMAGE_DONT_USE_OPENGL 28 | 29 | class RgbImage 30 | { 31 | public: 32 | RgbImage(); 33 | RgbImage( const char* filename ); 34 | RgbImage( int numRows, int numCols ); // Initialize a blank bitmap of this size. 35 | ~RgbImage(); 36 | 37 | bool LoadBmpFile( const char *filename ); // Loads the bitmap from the specified file 38 | bool WriteBmpFile( const char* filename ); // Write the bitmap to the specified file 39 | #ifndef RGBIMAGE_DONT_USE_OPENGL 40 | bool LoadFromOpenglBuffer(); // Load the bitmap from the current OpenGL buffer 41 | #endif 42 | 43 | int GetNumRows() const { return NumRows; } 44 | int GetNumCols() const { return NumCols; } 45 | // Rows are word aligned 46 | int GetNumBytesPerRow() const { return ((3*NumCols+3)>>2)<<2; } 47 | const void* ImageData() const { return (void*)ImagePtr; } 48 | 49 | const unsigned char* GetRgbPixel( long row, long col ) const; 50 | unsigned char* GetRgbPixel( long row, long col ); 51 | void GetRgbPixel( long row, long col, float* red, float* green, float* blue ) const; 52 | void GetRgbPixel( long row, long col, double* red, double* green, double* blue ) const; 53 | 54 | void SetRgbPixelf( long row, long col, double red, double green, double blue ); 55 | void SetRgbPixelc( long row, long col, 56 | unsigned char red, unsigned char green, unsigned char blue ); 57 | 58 | // Error reporting. (errors also print message to stderr) 59 | int GetErrorCode() const { return ErrorCode; } 60 | enum { 61 | NoError = 0, 62 | OpenError = 1, // Unable to open file for reading 63 | FileFormatError = 2, // Not recognized as a 24 bit BMP file 64 | MemoryError = 3, // Unable to allocate memory for image data 65 | ReadError = 4, // End of file reached prematurely 66 | WriteError = 5 // Unable to write out data (or no date to write out) 67 | }; 68 | bool ImageLoaded() const { return (ImagePtr!=0); } // Is an image loaded? 69 | 70 | void Reset(); // Frees image data memory 71 | 72 | private: 73 | unsigned char* ImagePtr; // array of pixel values (integers range 0 to 255) 74 | int NumRows; // number of rows in image 75 | int NumCols; // number of columns in image 76 | int ErrorCode; // error code 77 | 78 | static short readShort( FILE* infile ); 79 | static long readLong( FILE* infile ); 80 | static void skipChars( FILE* infile, int numChars ); 81 | static void writeLong( long data, FILE* outfile ); 82 | static void writeShort( short data, FILE* outfile ); 83 | 84 | static unsigned char doubleToUnsignedChar( double x ); 85 | 86 | }; 87 | 88 | inline RgbImage::RgbImage() 89 | { 90 | NumRows = 0; 91 | NumCols = 0; 92 | ImagePtr = 0; 93 | ErrorCode = 0; 94 | } 95 | 96 | inline RgbImage::RgbImage( const char* filename ) 97 | { 98 | NumRows = 0; 99 | NumCols = 0; 100 | ImagePtr = 0; 101 | ErrorCode = 0; 102 | LoadBmpFile( filename ); 103 | } 104 | 105 | inline RgbImage::~RgbImage() 106 | { 107 | delete[] ImagePtr; 108 | } 109 | 110 | // Returned value points to three "unsigned char" values for R,G,B 111 | inline const unsigned char* RgbImage::GetRgbPixel( long row, long col ) const 112 | { 113 | assert ( row