├── .gitignore ├── AllGems.TOC ├── CMakeLists.txt ├── Errata.GraphicsGems ├── Errata.GraphicsGemsII ├── Errata.GraphicsGemsIII ├── Errata.GraphicsGemsIV ├── Errata.GraphicsGemsV ├── GraphicsGems.c ├── GraphicsGems.h ├── LICENSE.md ├── README.md ├── allgems.zip ├── authors.html ├── category.html ├── fakeirisgl.c ├── fakeirisgl.h ├── gems.html ├── gems.zip ├── gems ├── 2DClip │ ├── CMakeLists.txt │ ├── Makefile │ ├── bio.c │ ├── box.h │ ├── clip.c │ ├── cross.c │ └── line.h ├── AALines │ ├── 00README │ ├── AALines.c │ ├── AALines.h │ ├── AAMain.c │ ├── AATables.c │ ├── CMakeLists.txt │ ├── FastMatMul.c │ ├── LongConst.h │ ├── Makefile │ ├── utah.c │ └── utah.h ├── AAPolyScan.c ├── Albers.c ├── AllGems.TOC ├── BinRec.c ├── BoundSphere.c ├── BoxSphere.c ├── CMakeLists.txt ├── CircleRect.c ├── ConcaveScan.c ├── DigitalLine.c ├── Dissolve.c ├── DoubleLine.c ├── Errata.GraphicsGems ├── FastJitter.c ├── FitCurves.c ├── FixedTrig.c ├── Forms.c ├── GGVecLib.c ├── GraphicsGems.h ├── HSLtoRGB.c ├── Hash3D.c ├── HypotApprox.c ├── Interleave.c ├── Label.c ├── LineEdge.c ├── MANIFEST ├── Makefile ├── MatrixInvert.c ├── MatrixInvert.h ├── MatrixOrtho.c ├── MatrixPost.c ├── Median.c ├── NearestPoint.c ├── OrderDither.c ├── PixelInteger.c ├── PntOnLine.c ├── PolyScan │ ├── CMakeLists.txt │ ├── Makefile │ ├── fancytest.c │ ├── poly.c │ ├── poly.h │ ├── poly_clip.c │ ├── poly_scan.c │ └── scantest.c ├── Quaternions.c ├── README ├── RGBTo4Bits.c ├── RayBox.c ├── RayPolygon.c ├── Roots3And4.c ├── SeedFill.c ├── SquareRoot.c ├── Sturm │ ├── CMakeLists.txt │ ├── Makefile │ ├── main.c │ ├── solve.h │ ├── sturm.c │ ├── sturm.h │ └── util.c ├── TransBox.c ├── TriPoints.c └── ViewTrans.c ├── gemsii ├── AllGems.TOC ├── BitCounting │ ├── CMakeLists.txt │ ├── Makefile │ ├── bit32.c │ └── test.c ├── CMakeLists.txt ├── Errata.GraphicsGemsII ├── FastUpdate.c ├── GGVecLib.c ├── GraphicsGems.h ├── Hilbert.c ├── InterPhong.c ├── Makefile ├── Peano │ ├── CMakeLists.txt │ ├── Makefile │ ├── main.c │ ├── mapply.c │ ├── peano.c │ └── types.h ├── README ├── RayCPhdron.c ├── RealPixels │ ├── CMakeLists.txt │ ├── Makefile │ ├── color.c │ ├── color.h │ ├── colrops.c │ ├── colrops.h │ ├── header.c │ ├── header.h │ ├── ra_pr24.c │ ├── rasterfile.h │ ├── resolu.c │ └── resolu.h ├── TOC ├── VoxelCache.c ├── c_format.c ├── dither │ ├── CMakeLists.txt │ ├── Makefile │ ├── dither.3 │ └── dither.c ├── hot.c ├── intersect │ ├── CMakeLists.txt │ ├── Makefile │ ├── intsph.c │ └── inttor.c ├── inv_cmap │ ├── CMakeLists.txt │ ├── Makefile │ ├── inv_cmap.3 │ └── inv_cmap.c ├── inverse.c ├── noise3.c ├── quantizer.c ├── radiosity │ ├── CMakeLists.txt │ ├── Makefile │ ├── README │ ├── draw.c │ ├── rad.c │ ├── rad.h │ └── room.c ├── ran_ramp.c ├── rotate.c ├── rotate8x8.c ├── sparse.c ├── unmatrix.c ├── unmatrix.h ├── vector.h ├── viewcorr │ ├── CMakeLists.txt │ ├── Makefile │ ├── matrix.c │ ├── matrix.h │ ├── viewcorr.c │ ├── viewcorr.h │ └── viewfind.c └── xlines.c ├── gemsiii ├── 3d.c ├── AllGems.TOC ├── CMakeLists.txt ├── Errata.GraphicsGemsIII ├── GraphicsGems.c ├── GraphicsGems.h ├── Makefile ├── PIR.c ├── Polyintr.c ├── README ├── accForm.c ├── accurate_scan │ ├── CMakeLists.txt │ ├── Makefile │ ├── dblfixpoint.c │ ├── exhaust.c │ ├── fixpoint.c │ ├── fixpoint.h │ ├── test.c │ ├── tri.c │ └── tri.data ├── alloc │ ├── CMakeLists.txt │ ├── Makefile │ ├── alloc.c │ └── alloc.h ├── bezierTri.C ├── bitmap.c ├── bounding_volumes.c ├── bsp.c ├── bzrinter.c ├── circlexc.c ├── con2d.c ├── contour.c ├── cyclic.c ├── cyclic.h ├── defs.h ├── edgeCalc.c ├── exttest │ ├── CMakeLists.txt │ ├── Makefile │ ├── ehtest1.C │ ├── exthit.C │ └── exthit.h ├── fastBitmap.c ├── fastLinear.c ├── fastSpan.c ├── fillet.c ├── filter.c ├── filter_rcg.c ├── forfac.c ├── hemis.c ├── insectc.c ├── intell.c ├── interval.C ├── intqdr.c ├── luminaire │ ├── CMakeLists.txt │ ├── Makefile │ ├── geometry_object.C │ ├── geometry_object.h │ ├── special_instruction │ ├── sphere_luminaire.C │ ├── sphere_luminaire.h │ ├── triangle_luminaire.C │ ├── triangle_luminaire.h │ └── utility.h ├── motblur.c ├── ndline.c ├── newell.c ├── panorama.c ├── parelarc.c ├── partition3d │ ├── CMakeLists.txt │ ├── Makefile │ ├── main.c │ ├── partition.c │ └── partition.h ├── pl2plane.c ├── planeSets.c ├── pt2plane.c ├── quatspin.c ├── rand_rotation.c ├── rgbvary.c ├── rgbvaryW.c ├── scallops8.c ├── simplex │ ├── CMakeLists.txt │ ├── Makefile │ ├── recur.C │ └── symm.C ├── sqfinal.c ├── sqrt.c ├── triangleCube.c ├── unmatrix.c ├── urot.c ├── vector.h └── zdepth.c ├── gemsiv ├── AllGems.TOC ├── CMakeLists.txt ├── Errata.GraphicsGemsIV ├── GraphicsGems.c ├── GraphicsGems.h ├── README ├── arcball │ ├── Ball.c │ ├── Ball.h │ ├── BallAux.c │ ├── BallAux.h │ ├── BallMath.c │ ├── BallMath.h │ ├── Body.c │ ├── Body.h │ ├── CMakeLists.txt │ ├── Demo.c │ ├── Makefile │ └── README ├── centroid.c ├── clahe.c ├── collide.c ├── convex_test │ ├── CMakeLists.txt │ ├── convex.c │ └── convex_opt.c ├── convolve.c ├── coons_warp.c ├── curve_isect │ ├── Bezier.cc │ ├── Bezier.h │ ├── CMakeLists.txt │ ├── README │ ├── makefile │ ├── test.cc │ ├── testout.ps │ └── vector.h ├── data_smooth │ ├── CMakeLists.txt │ ├── README │ ├── smooth1.c │ ├── smooth2.c │ └── smooth3.c ├── delaunay │ ├── CMakeLists.txt │ ├── Makefile │ ├── README │ ├── geom2d.h │ ├── quadedge.C │ ├── quadedge.h │ └── test.C ├── dist_fast.c ├── dyn_range │ ├── CMakeLists.txt │ ├── Makefile │ ├── README │ ├── hdp.c │ ├── hdp.h │ └── test_hdp.c ├── emboss.c ├── euler_angle │ ├── CMakeLists.txt │ ├── EulerAngles.c │ ├── EulerAngles.h │ ├── EulerSample.c │ ├── Makefile │ ├── QuatTypes.h │ └── README ├── gemsiv.bib ├── graph_layout │ ├── CMakeLists.txt │ ├── Makefile │ ├── README │ ├── defines.h │ ├── fileio.C │ ├── fileio.hxx │ ├── g.dat │ ├── g20.dat │ ├── graph.C │ ├── graph.hxx │ ├── graph.mak │ ├── layout.C │ ├── mswin.gen │ ├── mswindow.C │ ├── mswindow.hxx │ ├── vector.C │ ├── vector.hxx │ ├── window.C │ └── window.hxx ├── implicit.c ├── interp_fast.c ├── inv_fast.c ├── minray │ ├── CMakeLists.txt │ ├── README │ ├── minray.c │ ├── minray.card.c │ ├── minray.post │ ├── minray.ps │ └── ray.h ├── mrsfoley.im ├── multi_jitter │ ├── CMakeLists.txt │ ├── Makefile │ ├── README │ ├── multi.c │ └── test.c ├── nurb_polyg │ ├── CMakeLists.txt │ ├── FakeWindow.c │ ├── GraphicsGems.h │ ├── Main.c │ ├── NurbEval.c │ ├── NurbRefine.c │ ├── NurbSubdiv.c │ ├── NurbUtils.c │ ├── README │ ├── drawing.h │ ├── makefile │ └── nurbs.h ├── outcode │ ├── CMakeLists.txt │ ├── README │ ├── outcode2.c │ ├── outcode4.c │ ├── xcc2d.c │ ├── xcc4d.c │ ├── xf1.c │ ├── xf2.c │ ├── xf3.c │ └── xf4.c ├── patch_conv.C ├── polar_decomp │ ├── CMakeLists.txt │ ├── Decompose.c │ ├── Decompose.h │ ├── Makefile │ └── README ├── ptpoly_haines │ ├── CMakeLists.txt │ ├── Makefile │ ├── README │ ├── p_test.cpp │ ├── point_in_poly.sln │ ├── point_in_poly.vcxproj │ ├── ptinpoly.cpp │ ├── ptinpoly.h │ ├── statrun.tst │ └── table.awk ├── ptpoly_weiler │ ├── CMakeLists.txt │ ├── polygon.h │ └── pt_poly.c ├── ray_cyl.c ├── sph_poly.c ├── thin_image.c ├── trilerp.c ├── vec_mat │ ├── CMakeLists.txt │ ├── README │ ├── algebra3.cpp │ ├── algebra3.h │ └── ray │ │ ├── CMakeLists.txt │ │ ├── Camera.cpp │ │ ├── Camera.h │ │ ├── Light.cpp │ │ ├── Light.h │ │ ├── Makefile │ │ ├── Object3D.cpp │ │ ├── Object3D.h │ │ ├── Polyhedron.cpp │ │ ├── Polyhedron.h │ │ ├── Primitive.cpp │ │ ├── Primitive.h │ │ ├── README │ │ ├── Scene3D.cpp │ │ ├── Scene3D.h │ │ ├── Sphere.cpp │ │ ├── Sphere.h │ │ ├── algebra3.cpp │ │ ├── algebra3.h │ │ ├── example.data │ │ ├── example.tiff │ │ ├── main.cpp │ │ ├── solver.cpp │ │ └── solver.h ├── vert_norm │ ├── CMakeLists.txt │ ├── Makefile │ ├── smooth.c │ ├── smooth.h │ └── test.c └── vox_traverse.c ├── gemsv ├── AllGems.TOC ├── CMakeLists.txt ├── Errata.GraphicsGemsV ├── GemsV.TOC ├── ch1-1 │ ├── CMakeLists.txt │ └── quarcube.c ├── ch1-2 │ ├── CMakeLists.txt │ └── invsqrt.c ├── ch1-3 │ ├── CMakeLists.txt │ └── fixsqrt.c ├── ch1-4 │ ├── CMakeLists.txt │ ├── rat.c │ └── rat.h ├── ch2-2 │ ├── CMakeLists.txt │ ├── ptinply3.c │ └── rev.c ├── ch2-6 │ ├── CMakeLists.txt │ └── conmat.c ├── ch2-7 │ ├── CMakeLists.txt │ ├── len4.c │ └── testlen4.c ├── ch3-3 │ ├── CMakeLists.txt │ └── tricubic.c ├── ch3-4 │ ├── CMakeLists.txt │ └── xcoord.c ├── ch3-5 │ ├── CMakeLists.txt │ ├── README │ ├── bsp.h │ ├── bsp.make │ ├── bspAlloc.c │ ├── bspCollide.c │ ├── bspMemory.c │ ├── bspPartition.c │ ├── bspTree.c │ ├── bspUtility.c │ ├── foo.dat │ └── mainBsp.c ├── ch3-6 │ ├── CMakeLists.txt │ ├── README │ ├── axd.c │ └── axd.h ├── ch4-3 │ ├── CMakeLists.txt │ └── arcdivid.c ├── ch4-4 │ ├── CMakeLists.txt │ └── aspc.c ├── ch4-5 │ ├── CMakeLists.txt │ ├── Makefile │ ├── ellihelp.c │ ├── ellipsoid.c │ ├── ellipsoid.h │ └── timing.c ├── ch4-7 │ ├── BezierCode.h │ ├── CMakeLists.txt │ └── bezlen.c ├── ch4-8 │ ├── CMakeLists.txt │ └── qbezier.c ├── ch4-9 │ ├── CMakeLists.txt │ ├── lincrv.c │ ├── lincrv.h │ └── lincrvte.c ├── ch5-2 │ ├── CMakeLists.txt │ ├── README │ ├── quad.c │ ├── quad.h │ ├── quad_gg.c │ └── quad_gg.h ├── ch5-3 │ ├── CMakeLists.txt │ ├── rayscan.cc │ ├── vector-bookver.h │ └── vector.h ├── ch5-4 │ ├── CMakeLists.txt │ ├── poly.cpp │ ├── poly.h │ └── sweep.cpp ├── ch5-5 │ ├── CMakeLists.txt │ ├── camera.cxx │ ├── csg.cxx │ ├── finish.cxx │ ├── finite.cxx │ ├── global.h │ ├── infinite.cxx │ ├── lightsrc.cxx │ ├── main.cxx │ ├── makefile │ ├── misc.cxx │ ├── normal.cxx │ ├── patch.cxx │ ├── pigment.cxx │ ├── pov.l │ ├── pov.y │ ├── random.pov │ ├── readme.txt │ ├── show.c │ ├── show.m │ ├── test.pov │ ├── texture.cxx │ ├── voronoi.cxx │ └── voronoi.h ├── ch6-2 │ ├── CMakeLists.txt │ └── halfadap.c ├── ch6-3 │ ├── CMakeLists.txt │ └── pclipper.c ├── ch6-4 │ ├── CMakeLists.txt │ ├── Makefile │ ├── README │ ├── bitmap_1 │ ├── bitmap_2 │ ├── bitmap_3 │ ├── chainCode.C │ ├── chainCode.h │ ├── pt2.C │ ├── pt2.h │ ├── test.C │ └── vectorize.C ├── ch6-5 │ ├── CMakeLists.txt │ ├── revfit.c │ └── revfit.h ├── ch6-7 │ ├── CMakeLists.txt │ └── sampat.c ├── ch7-1 │ ├── CMakeLists.txt │ ├── wave.c │ └── wave.h ├── ch7-2 │ ├── CMakeLists.txt │ ├── fpcube.c │ ├── makefile │ ├── pcube.c │ ├── pcube.h │ ├── readme │ ├── test.c │ └── vec.h ├── ch7-3 │ ├── CMakeLists.txt │ └── collide.cc ├── ch7-4 │ ├── CMakeLists.txt │ ├── Makefile │ ├── basic.h │ ├── dedge.cc │ ├── dedge.h │ ├── list.cc │ ├── list.h │ ├── main.cc │ ├── plane.cc │ ├── plane.h │ ├── point.h │ ├── polygon.cc │ ├── polygon.h │ └── vector.h ├── ch7-5 │ ├── CMakeLists.txt │ ├── README │ ├── basic.h │ ├── construct.c │ ├── data_1 │ ├── makefile │ ├── misc.c │ ├── monotone.c │ └── tri.c ├── ch7-6 │ ├── CMakeLists.txt │ ├── Makefile │ ├── NFF │ ├── ZRendv10.c │ ├── ZRendv10.h │ ├── ZRendv10Announce │ ├── sx11 │ │ ├── CMakeLists.txt │ │ ├── Makefile │ │ └── sx11.c │ ├── tga │ │ ├── CMakeLists.txt │ │ ├── Makefile │ │ ├── README │ │ ├── alias.h │ │ ├── bitmap.c │ │ ├── cnv.c │ │ ├── dither.c │ │ ├── encodgif.c │ │ ├── error.c │ │ ├── general.c │ │ ├── gif.c │ │ ├── hsl.c │ │ ├── in_out.c │ │ ├── lug.h │ │ ├── lugconf.h │ │ ├── lugfnts.h │ │ ├── memory.c │ │ ├── rla.h │ │ ├── targa.h │ │ ├── tga.c │ │ ├── tobw.c │ │ └── x11.c │ └── tpot1l.nff └── ch7-7 │ ├── CMakeLists.txt │ ├── GG4D │ ├── CMakeLists.txt │ ├── GGems.h │ ├── GGems4d.h │ ├── Makefile │ ├── VecLib.c │ ├── VecLib4d.c │ └── example.c │ ├── README │ ├── libgm │ ├── CMakeLists.txt │ ├── Imakefile │ ├── gm.h │ ├── gmConst.h │ ├── gmMat3.cc │ ├── gmMat3.h │ ├── gmMat4.cc │ ├── gmMat4.h │ ├── gmUtils.h │ ├── gmVec2.h │ ├── gmVec3.h │ ├── gmVec4.h │ ├── libgm.ps │ └── libgm.tex │ ├── mactbox │ ├── mat2.h │ ├── mat3.h │ ├── mat4.h │ ├── real.h │ ├── sint.h │ ├── tool.h │ ├── uint.h │ ├── vec2.h │ ├── vec3.h │ └── vec4.h │ └── vec-h │ ├── CMakeLists.txt │ ├── README │ ├── vec.h │ └── vec_h.c ├── getopt.c ├── getopt.h ├── index.html └── math.c /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | .DS_Store 3 | FakeIrisGL.dir 4 | GetOpt.dir 5 | GraphicsGems.dir 6 | m.dir 7 | x64 8 | *.zip 9 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(GraphicsGems) 4 | 5 | if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") 6 | set(CMAKE_CXX_STANDARD 11) 7 | add_definitions(-Werror) 8 | endif() 9 | if(CMAKE_COMPILER_IS_GNUCC) 10 | add_definitions(-DGCC) 11 | endif() 12 | 13 | if(MSVC) 14 | add_definitions(-D_CRT_SECURE_NO_WARNINGS=1) 15 | endif() 16 | 17 | if(APPLE) 18 | add_definitions(-DAPPLE) 19 | endif() 20 | 21 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) 22 | 23 | include_directories(.) 24 | 25 | add_library(FakeIrisGL fakeirisgl.h fakeirisgl.c) 26 | add_library(GraphicsGems GraphicsGems.h GraphicsGems.c) 27 | add_library(GetOpt getopt.h getopt.c) 28 | if(MSVC) 29 | add_library(m math.c) 30 | endif() 31 | 32 | target_link_libraries(GraphicsGems m) 33 | 34 | add_subdirectory(gems) 35 | add_subdirectory(gemsii) 36 | add_subdirectory(gemsiii) 37 | add_subdirectory(gemsiv) 38 | add_subdirectory(gemsv) 39 | 40 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | LICENSE 2 | 3 | This code repository predates the concept of Open Source, and predates most licenses along such lines. As such, the official license truly is: 4 | 5 | EULA: The Graphics Gems code is copyright-protected. In other words, you cannot claim the text of the code as your own and resell it. Using the code is permitted in any program, product, or library, non-commercial or commercial. Giving credit is not required, though is a nice gesture. The code comes as-is, and if there are any flaws or problems with any Gems code, nobody involved with Gems - authors, editors, publishers, or webmasters - are to be held responsible. Basically, don't be a jerk, and remember that anything free comes with no guarantee. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This is the code repository for the "Graphics Gems" series of books. The permanent home for the repository has been at [http://graphicsgems.org](http://graphicsgems.org). To make it easier to accept code fixes, I've put the code on Github. Please contact me if you have any questions. 2 | 3 | [Eric Haines](mailto:erich@acm.org) -------------------------------------------------------------------------------- /allgems.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erich666/GraphicsGems/6bd96c311d77db5dc750e850167c76c5f45af4c1/allgems.zip -------------------------------------------------------------------------------- /authors.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erich666/GraphicsGems/6bd96c311d77db5dc750e850167c76c5f45af4c1/authors.html -------------------------------------------------------------------------------- /category.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erich666/GraphicsGems/6bd96c311d77db5dc750e850167c76c5f45af4c1/category.html -------------------------------------------------------------------------------- /fakeirisgl.c: -------------------------------------------------------------------------------- 1 | #include "fakeirisgl.h" 2 | 3 | void pushmatrix() {} 4 | void popmatrix() {} 5 | void loadmatrix() {} 6 | void scale() {} 7 | void ortho2(float a, float b, float c, float d) {} 8 | void RGBcolor(int r, int g, int b) {} 9 | void circ() {} 10 | void v3f() {} 11 | void endline() {} 12 | void bgnpolygon() {} 13 | void v4f() {} 14 | void endpolygon() {} 15 | void multmatrix(float m[4][4]) {} 16 | void clear() {} 17 | void keepaspect(int x, int y) {} 18 | void prefposition(int a, int b, int c, int d) {} 19 | void doublebuffer() {} 20 | void RGBmode() {} 21 | void gconfig() {} 22 | void qdevice(int i) {} 23 | void ortho(float a, float b, float c, float d, float e, float f) {} 24 | void translate(float a, float b, float c) {} 25 | void getsize(long* a, long* b) {} 26 | void getorigin(long* a, long* b) {} 27 | int qtest() { return 0; } 28 | int qread(short* sp) { return 0; } 29 | void gexit() {} 30 | void reshapeviewport() {} 31 | void swapbuffers() {} 32 | void bgnline() {} 33 | void v2d(double* d) {} 34 | void v2i(int* i) {} 35 | void prefsize(int i, int j) {} 36 | int winopen(const char* cp) { return 0; } 37 | void cpack(int i) {} 38 | int getvaluator(int i) { return 0; } 39 | void qreset() {} 40 | void qenter(int i, short s) {} 41 | void winset(int i) {} 42 | void winclose(int i) {} 43 | //void drawbody(float m[4][4]) {} 44 | void foreground() {} 45 | 46 | -------------------------------------------------------------------------------- /gems.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erich666/GraphicsGems/6bd96c311d77db5dc750e850167c76c5f45af4c1/gems.html -------------------------------------------------------------------------------- /gems.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erich666/GraphicsGems/6bd96c311d77db5dc750e850167c76c5f45af4c1/gems.zip -------------------------------------------------------------------------------- /gems/2DClip/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(2DClip bio.c box.h clip.c cross.c line.h) 2 | 3 | -------------------------------------------------------------------------------- /gems/2DClip/Makefile: -------------------------------------------------------------------------------- 1 | LIBFILE = ../gemslib.a 2 | 3 | CFLAGS = $(GENCFLAGS) -I.. 4 | 5 | OFILES = clip.o bio.o cross.o 6 | 7 | $(LIBFILE): $(OFILES) 8 | ar rcs $(LIBFILE) $(OFILES) 9 | 10 | clean: 11 | /bin/rm -f clip.o bio.o cross.o 12 | 13 | $(OFILES): line.h ../GraphicsGems.h 14 | -------------------------------------------------------------------------------- /gems/2DClip/box.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * file box.h 4 | * a short include file is better then no include file 5 | */ 6 | typedef struct { /* guess what this is */ 7 | long _lowx; 8 | long _lowy; 9 | long _highx; 10 | long _highy; 11 | } BOX; 12 | 13 | 14 | -------------------------------------------------------------------------------- /gems/AALines/00README: -------------------------------------------------------------------------------- 1 | This group of files is a simple demonstration of an anti-aliased line 2 | renderer from _Graphics_Gems_. Files in the release are: 3 | 4 | 00README -- This information file. 5 | 6 | Makefile -- Makefile for creating the demo executable. 7 | 8 | AALines.h -- Include file for demo source files. 9 | 10 | AALines.c -- Rendering code from _Graphics_Gems_ pages 690-693. 11 | 12 | AATables.c -- Initialization code for frame buffer and lookup tables. 13 | 14 | AAMain.c -- Calling routine for the renderer. 15 | 16 | utah.h -- Include file for friendly Utah RLE front end. 17 | 18 | utah.c -- Source for friendly Utah RLE front end. 19 | 20 | As it is written, the program dumps its frame buffer to a Utah RLE 21 | file. You need to obtain the Utah RLE library from another source; 22 | try the following FTP sites: 23 | 24 | cs.utah.edu (128.110.4.21) 25 | weedeater.math.yale.edu (130.132.23.17) 26 | freebie.engin.umich.edu (35.2.68.23) 27 | 28 | It should be fairly easy to dump the frame buffer to another type 29 | of file, or straight to a display device. See AAMain.c. 30 | 31 | Have fun. 32 | 33 | -- Kelvin Thompson, 18 August 1990 34 | kelvin@cs.utexas.edu 35 | -------------------------------------------------------------------------------- /gems/AALines/AALines.h: -------------------------------------------------------------------------------- 1 | /* FILENAME: AALines.h [revised 17 AUG 90] 2 | 3 | AUTHOR: Kelvin Thompson 4 | 5 | DESCRIPTION: Symbols and globals for the anti-aliased line 6 | renderer. 7 | 8 | #INCLUDED IN: 9 | AAMain.c -- Calling routine for renderer. 10 | AATables.c -- Initialization routines for lookup tables. 11 | AALines.c -- Rendering code. 12 | */ 13 | 14 | /* frame buffer to hold the anti-aliased line */ 15 | #define xpix 60 16 | #define ypix 60 17 | extern char *fbuff; 18 | 19 | /* macros to access the frame buffer */ 20 | #define PIXADDR(xx,yy) (fbuff+(yy)*xpix+(xx)) 21 | #define PIXINC(dx,dy) ((dy)*xpix+(dx)) 22 | 23 | /* fixed-point data types and macros */ 24 | typedef int FX; 25 | typedef unsigned int UFX; 26 | #define FX_FRACBITS 16 /* bits of fraction in FX format */ 27 | #define FX_0 0 /* zero in fixed-point format */ 28 | #define FLOAT_TO_FX(flt) ((FX)((flt)*(1<> sqrtshift ]) 39 | 40 | /* AA globals */ 41 | extern float line_r; /* line radius */ 42 | extern float pix_r; /* pixel radius */ 43 | extern FX *coverage; 44 | extern int covercells; 45 | extern int covershift; 46 | #define COVERAGE(fxval) (coverage[ (fxval) >> covershift ]) 47 | -------------------------------------------------------------------------------- /gems/AALines/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # rle.h and rle_config.h from github.com/sarnold/urt 2 | 3 | add_definitions(-DUSE_STRING_H) 4 | add_library(AALines AALines.c AALines.h AAMain.c AATables.c FastMatMul.c LongConst.h utah.c utah.h) 5 | 6 | -------------------------------------------------------------------------------- /gems/AALines/LongConst.h: -------------------------------------------------------------------------------- 1 | /* FILENAME: LongConst.h [revised 18 AUG 90] 2 | 3 | AUTHOR: Kelvin Thompson 4 | 5 | DESCRIPTION: High-precision constants. If this file is included 6 | in the same file as GraphicsGems.h, this file must come *after* 7 | GraphicsGems.h. (It's okay to use this file without GraphicsGems.h.) 8 | 9 | The standard _Graphics_Gems_ include file has some constants 10 | that do not have full double-precision accuracy. This file 11 | has the constants to a ridiculously high precision. See pages 12 | 434-435 of _Graphics_Gems_. I got the constants from Mathematica. 13 | 14 | Also, this file has a constant and macro for finding the base-two 15 | logarithm of a number. 16 | */ 17 | 18 | /* prevent multiple inclusion */ 19 | #ifndef __LONGCONST_H__ 20 | #define __LONGCONST_H__ 21 | 22 | /* first get rid of stuff from GraphicsGems.h */ 23 | #undef PI 24 | #undef PITIMES2 25 | #undef PIOVER2 26 | #undef E 27 | #undef SQRT2 28 | #undef SQRT3 29 | #undef GOLDEN 30 | #undef DTOR 31 | #undef RTOD 32 | 33 | /* re-define basic constants with high precision */ 34 | #define PI 3.141592653589793238462643383279502884197169399375105820975 35 | #define E 2.718281828459045235360287471352662497757247093699959574967 36 | #define SQRT2 1.414213562373095048801688724209698078569671875376948073177 37 | #define SQRT3 1.732050807568877293527446341505872366942805253810380628056 38 | #define GOLDEN 1.618033988749894848204586834365638117720309179805762862135 39 | 40 | /* re-define derived constants */ 41 | #define PITIMES2 (2.0*PI) 42 | #define PIOVER2 (0.5*PI) 43 | #define DTOR (PI/180.0) 44 | #define RTOD (180.0/PI) 45 | 46 | /* macro and constant for base 2 logarithm */ 47 | #define LN2 0.693147180559945309417232121458176568075500134360255254121 48 | #define LOG2(val) (log(val)*(1.0/LN_2)) 49 | 50 | #endif /* __LONGCONST_H__ */ 51 | -------------------------------------------------------------------------------- /gems/AALines/Makefile: -------------------------------------------------------------------------------- 1 | # FILENAME: Makefile [revised 18 AUG 90] 2 | # 3 | # AUTHOR: Kelvin Thompson 4 | # 5 | # DESCRIPTION: Makefile for anti-aliased line rendering demo. 6 | 7 | # locations of Utah RLE information 8 | UTAH_RLE_INCLUDE_DIR = /usr/contrib/include 9 | UTAH_RLE_LIB_FILE = /usr/contrib/lib/librle.a 10 | 11 | CFLAGS = -I$(UTAH_RLE_INCLUDE_DIR) 12 | 13 | OBJS = AAMain.o AALines.o AATables.o utah.o 14 | 15 | .o : .c 16 | $(CC) -c $(CFLAGS) $(CPPFLAGS) $< 17 | 18 | AALine : $(OBJS) 19 | cc $(CFLAGS) -o $@ $(OBJS) $(UTAH_RLE_LIB_FILE) -lm 20 | 21 | clean: 22 | /bin/rm -f $(OBJS) AALine 23 | -------------------------------------------------------------------------------- /gems/AALines/utah.h: -------------------------------------------------------------------------------- 1 | /* 2 | file: utah.h 3 | description: interface to Utah RLE toolkit 4 | author: A. T. Campbell 5 | date: October 30, 1989 6 | */ 7 | 8 | #ifndef UTAH_H 9 | #define UTAH_H 10 | 11 | /******************************************************************************/ 12 | 13 | /* include files */ 14 | /* You will have to get these from the ancient Utah Raster Toolkit, 15 | http://www.cs.utah.edu/gdc/projects/urt/ - best of luck! */ 16 | //#include "rle.h" 17 | // fake rle 18 | typedef struct rle_hdr { 19 | int xmax; 20 | FILE* rle_file; 21 | int xmin; 22 | int ymin; 23 | int ymax; 24 | int alpha; 25 | } rle_hdr; 26 | typedef unsigned char rle_pixel; 27 | rle_hdr rle_dflt_hdr; 28 | int rle_get_setup(); 29 | void rle_getrow(); 30 | void rle_puteof(); 31 | void rle_put_setup(); 32 | void rle_putrow(); 33 | 34 | /******************************************************************************/ 35 | 36 | /* type definitions */ 37 | typedef rle_hdr UTAH_FILE; 38 | 39 | /******************************************************************************/ 40 | 41 | /* return values */ 42 | extern int utah_read_close(); 43 | extern UTAH_FILE *utah_read_init(); 44 | extern int utah_read_pixels(); 45 | extern int utah_read_rgb(); 46 | extern int utah_write_close(); 47 | extern UTAH_FILE *utah_write_init(); 48 | extern int utah_write_pixels(); 49 | extern int utah_write_rgb(); 50 | 51 | /******************************************************************************/ 52 | 53 | #endif //UTAH_H 54 | -------------------------------------------------------------------------------- /gems/BinRec.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Recording Animation in Binary Order for Progressive Temporal Refinement 3 | * by Paul Heckbert 4 | * from "Graphics Gems", Academic Press, 1990 5 | */ 6 | 7 | /* 8 | * binrec.c: demonstrate binary recording order 9 | * 10 | * Paul Heckbert Jan 90 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | 17 | /* 18 | * inside_out: turn a number "inside-out": a generalization of bit-reversal. 19 | * For n = power of two, this is equivalent to bit-reversal. 20 | * 21 | * Turn the number a inside-out, yielding b. If 0<=a=m) { 33 | if (*b==0) *r = k; 34 | *b += k; 35 | a -= (m+1)>>1; 36 | m >>= 1; 37 | } 38 | else m = (m+1)>>1; 39 | if (*r>n-*b) *r = n-*b; 40 | } 41 | 42 | int main(int ac, char** av) 43 | { 44 | int nframes, i, start_frame, repeat_count; 45 | if (ac!=2) { 46 | fprintf(stderr, "Usage: binrec \n"); 47 | exit(1); 48 | } 49 | nframes = atoi(av[1]); 50 | 51 | printf("step startframe repeatcount\n"); 52 | for (i=0; imax.x -= C->x; R->max.y -= C->y; 19 | R->min.x -= C->x; R->min.y -= C->y; 20 | 21 | if (R->max.x < 0) /* R to left of circle center */ 22 | if (R->max.y < 0) /* R in lower left corner */ 23 | return ((R->max.x * R->max.x + R->max.y * R->max.y) < Rad2); 24 | else if (R->min.y > 0) /* R in upper left corner */ 25 | return ((R->max.x * R->max.x + R->min.y * R->min.y) < Rad2); 26 | else /* R due West of circle */ 27 | return(ABS(R->max.x) < Rad); 28 | else if (R->min.x > 0) /* R to right of circle center */ 29 | if (R->max.y < 0) /* R in lower right corner */ 30 | return ((R->min.x * R->min.x + R->max.y * R->max.y) < Rad2); 31 | else if (R->min.y > 0) /* R in upper right corner */ 32 | return ((R->min.x * R->min.x + R->min.y * R->min.y) < Rad2); 33 | else /* R due East of circle */ 34 | return (R->min.x < Rad); 35 | else /* R on circle vertical centerline */ 36 | if (R->max.y < 0) /* R due South of circle */ 37 | return (ABS(R->max.y) < Rad); 38 | else if (R->min.y > 0) /* R due North of circle */ 39 | return (R->min.y < Rad); 40 | else /* R contains circle centerpoint */ 41 | return(TRUE); 42 | } 43 | -------------------------------------------------------------------------------- /gems/DigitalLine.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Digital Line Drawing 3 | * by Paul Heckbert 4 | * from "Graphics Gems", Academic Press, 1990 5 | */ 6 | 7 | /* 8 | * digline: draw digital line from (x1,y1) to (x2,y2), 9 | * calling a user-supplied procedure at each pixel. 10 | * Does no clipping. Uses Bresenham's algorithm. 11 | * 12 | * Paul Heckbert 3 Sep 85 13 | */ 14 | 15 | #include "GraphicsGems.h" 16 | 17 | void digline(int x1, int y1, int x2, int y2, void (*dotproc)(int, int)) 18 | { 19 | int d, x, y, ax, ay, sx, sy, dx, dy; 20 | 21 | dx = x2-x1; ax = ABS(dx)<<1; sx = SGN(dx); 22 | dy = y2-y1; ay = ABS(dy)<<1; sy = SGN(dy); 23 | 24 | x = x1; 25 | y = y1; 26 | if (ax>ay) { /* x dominant */ 27 | d = ay-(ax>>1); 28 | for (;;) { 29 | dotproc(x, y); 30 | if (x==x2) return; 31 | if (d>=0) { 32 | y += sy; 33 | d -= ax; 34 | } 35 | x += sx; 36 | d += ay; 37 | } 38 | } 39 | else { /* y dominant */ 40 | d = ax-(ay>>1); 41 | for (;;) { 42 | (*dotproc)(x, y); 43 | if (y==y2) return; 44 | if (d>=0) { 45 | x += sx; 46 | d -= ay; 47 | } 48 | y += sy; 49 | d += ax; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /gems/Hash3D.c: -------------------------------------------------------------------------------- 1 | /* 2 | A 3D Grid Hashing Function 3 | by Brian Wyvill 4 | from "Graphics Gems", Academic Press, 1990 5 | */ 6 | 7 | /* Test Program for 3D hash function. 8 | In C the hash function can be defined in a macro which 9 | avoids a function call 10 | and the bit operations are defined in the language. 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include "GraphicsGems.h" 17 | 18 | #define RANGE 256 19 | #define NBITS 4 20 | #define RBITS 4 21 | #define MASK 0360 22 | #define HASH(a,b,c) ((((a&MASK)<>RBITS) 23 | #define HSIZE 1<= RANGE) 46 | fprintf(stderr,"%f out of range\n",z), exit(1); 47 | } 48 | 49 | double getcoord() 50 | { 51 | char buf[80]; 52 | double z; 53 | scanf("%s",buf); 54 | z = atof(buf); 55 | checkrange(z); 56 | return z; 57 | } 58 | 59 | int main() 60 | { 61 | Triple a; 62 | while (TRUE) { 63 | printf("Enter object position x y z ===> "); 64 | a.x = getcoord(); 65 | a.y = getcoord(); 66 | a.z = getcoord(); 67 | printf("\ncoord: %d %d %d Hashes to %d\n",IABS(a.x),IABS(a.y),IABS(a.z), 68 | HASH(IABS(a.x), IABS(a.y), IABS(a.z) )); 69 | }; 70 | } 71 | -------------------------------------------------------------------------------- /gems/HypotApprox.c: -------------------------------------------------------------------------------- 1 | /* 2 | A Fast Approximation to the Hypotenuse 3 | by Alan Paeth 4 | from "Graphics Gems", Academic Press, 1990 5 | */ 6 | 7 | int idist(int x1, int y1, int x2, int y2) 8 | { 9 | /* 10 | * gives approximate distance from (x1,y1) to (x2,y2) 11 | * with only overestimations, and then never by more 12 | * than (9/8) + one bit uncertainty. 13 | */ 14 | if ((x2 -= x1) < 0) x2 = -x2; 15 | if ((y2 -= y1) < 0) y2 = -y2; 16 | return (x2 + y2 - (((x2>y2) ? y2 : x2) >> 1) ); 17 | } 18 | 19 | int PntOnCirc(int xp, int yp, int xc, int yc, int r) 20 | { 21 | /* returns true IFF a test point (xp, yp) is to within a 22 | * pixel of the circle of center (xc, yc) and radius r. 23 | * "d" is an approximate length to circle's center, with 24 | * 1.0*r < dist < 1.12*r < (9/8)*r used for coarse testing. 25 | * The 9/8 ratio suggests the code: (x)<<3 and ((x)<<3)-(x). 26 | * Variables xp, yp, r and d should be of 32-bit precision. 27 | * 28 | * Note: (9/8) forms a very tight, proper inner bound but 29 | * must be slackened by one pixel for the outside test (#2) 30 | * to account for the -1/2 pixel absolute error introduced 31 | * when "idist" halves an odd integer; else rough clipping 32 | * will trim occasional points on the circle's perimeter. 33 | */ 34 | int d = idist(xp, yp, xc, yc); 35 | if ( r > d) return(0); /* far-in */ 36 | if (9*r < 8*(d-1)) return(0); /* far-out */ 37 | /* full test: r < hypot(xp-xc,yp-yc) < r+1 */ 38 | xp -= xc; 39 | yp -= yc; 40 | d = xp*xp + yp*yp; 41 | if (d < r*r) return(0); /* near-in */ 42 | r += 1; 43 | if (d > r*r) return(0); /* near-out */ 44 | return(1); /* WITHIN */ 45 | } 46 | -------------------------------------------------------------------------------- /gems/MatrixInvert.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | double det4x4(Matrix4* m); 4 | void inverse(Matrix4* in, Matrix4* out); 5 | -------------------------------------------------------------------------------- /gems/PixelInteger.c: -------------------------------------------------------------------------------- 1 | /* 2 | Proper Treatment of Pixels as Integers 3 | by Alan Paeth 4 | from "Graphics Gems", Academic Press, 1990 5 | */ 6 | 7 | #define Min code[2] 8 | #define Med code[1] 9 | #define Max code[0] 10 | #define NCODE 3 11 | 12 | #include /* or */ 13 | 14 | /* 15 | * A call to getplanes of the form: 16 | * getplanes(&red, &green, &blue, 256, "grb"); 17 | * 18 | * fills the first three integer pointers with (near) identical 19 | * values which maximize red*green*blue <= 256. The final parameter 20 | * string defines tie-break order, here green>=red>=blue (the usual 21 | * default). The present code procedure calls "err(string, arg)" 22 | * given bad parameters; it is a simple task to rewrite the code as 23 | * a function which returns a success/failure code(s), as needed. 24 | * 25 | * In the example given above the code fills in the values 26 | * red = 6, green = 7, blue = 6. 27 | */ 28 | 29 | void err(const char* msg, ...) {} 30 | 31 | void getplanes(int* r, int* g, int* b, int n, char* bias) 32 | { 33 | int i, code[NCODE]; 34 | if(strlen(bias) != NCODE ) 35 | err("bias string \"%s\" wrong length",bias); 36 | Min = Med = Max = 0; 37 | *r = *g = *b = 0; 38 | while(Min*Min*Min <= n) Min++; 39 | Min--; 40 | while(Med*Med*Min <= n) Med++; 41 | Med--; 42 | Max = n/(Min*Med); 43 | for( i = 0; i < NCODE; i++ ) 44 | { 45 | switch(bias[i]) 46 | { 47 | case 'r': case 'R': *r = code[i]; break; 48 | case 'g': case 'G': *g = code[i]; break; 49 | case 'b': case 'B': *b = code[i]; break; 50 | default: err("bad bias character: \'%c\'",bias[i]); break; 51 | } 52 | } 53 | if (!(*r && *g && *b)) err("bias string \"%s\" deficient", bias); 54 | } 55 | 56 | -------------------------------------------------------------------------------- /gems/PolyScan/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(PolyScan fancytest.c poly.c poly.h poly_clip.c poly_scan.c scantest.c) 2 | target_link_libraries(PolyScan m) 3 | 4 | -------------------------------------------------------------------------------- /gems/PolyScan/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for scantest, test program for generic convex polygon scan conversion 2 | # 3 | # Note: fancytest.c needs a main routine and several auxiliary routines 4 | # in order to be compiled. 5 | 6 | CFLAGS = $(GENCFLAGS) 7 | 8 | scantest: scantest.o poly_scan.o poly.o 9 | $(CC) $(CFLAGS) -o scantest scantest.o poly_scan.o poly.o -lm 10 | 11 | clean: 12 | /bin/rm -f scantest.o poly_clip.o poly_scan.o poly.o scantest 13 | -------------------------------------------------------------------------------- /gems/README: -------------------------------------------------------------------------------- 1 | 2 | This directory contains source code related to the book 3 | "Graphics Gems" (editor, Andrew S. Glassner, published by 4 | Academic Press, Cambridge, MA, 1990, ISBN 0-12-286165-5, 833 pgs.). 5 | 6 | The authors and the publisher hold no copyright restrictions 7 | on any of these files; this source code is public domain, and 8 | is freely available to the entire computer graphics community 9 | for study, use, and modification. We do request that the 10 | comment at the top of each file, identifying the original 11 | author and its original publication in the book Graphics 12 | Gems, be retained in all programs that use these files. 13 | 14 | The original source files are stored in a plain text format; you 15 | may download them without any special techniques (i.e. you need 16 | not enable binary transfer, or have a special formatter to 17 | read and use the code). The updated source files in the "src" 18 | directory should be downloaded using binary transfer mode. 19 | 20 | Additional submissions (bug fixes, skeleton programs, auxiliary 21 | routines, etc.) may be directed to the site administrator, 22 | Craig Kolb (cek@cs.princeton.edu). He will determine on a case-by-case 23 | basis if a particular submission should be included in this archive. 24 | If accepted, these routines will be made available in a companion 25 | directory. 26 | 27 | src/ The most up-to-date version of each gem. 28 | See src/README for details. 29 | 30 | original/ Source code as printed in "Graphics Gems". 31 | See original/README for details. 32 | 33 | patches/ Patches to the original source code. 34 | -------------------------------------------------------------------------------- /gems/RGBTo4Bits.c: -------------------------------------------------------------------------------- 1 | /* 2 | Mapping RGB Triples onto Four Bits 3 | by Alan Paeth 4 | from "Graphics Gems", Academic Press, 1990 5 | */ 6 | 7 | int remap8(R, G, B, R2, G2, B2) 8 | float R, G, B, *R2, *G2, *B2; 9 | { 10 | /* 11 | * remap8 maps floating (R,G,B) triples onto quantized 12 | * (R2,B2,B2) triples and returns the code (vertex) 13 | * value/color table entry for the quantization. The 14 | * points (eight) are the vertices of the cube. 15 | */ 16 | int code; 17 | *R2 = *G2 = *B2 = 0.0; 18 | code = 0; 19 | if (R >= 0.5) { *R2 = 1.0; code |= 1; } 20 | if (G >= 0.5) { *G2 = 1.0; code |= 2; } 21 | if (B >= 0.5) { *B2 = 1.0; code |= 4; } 22 | return(code); 23 | } 24 | 25 | /* 26 | * remap14 maps floating (R,G,B) triples onto quantized 27 | * (R2,B2,B2) triples and returns the code (vertex) 28 | * value/color table entry for the quantization. The 29 | * points (fourteen) are the vertices of the cuboctahedron. 30 | */ 31 | 32 | float rval[] = { 0.,.5 ,.5 , 1.,.0 , 0., 0.,.5, 33 | .5 , 1., 1., 1., 0.,.5 ,.5 , 1.}; 34 | float gval[] = { 0.,.5 , 0., 0.,.5 , 1., 0.,.5, 35 | .5 , 1., 0.,.5 , 1., 1.,.5 , 1.}; 36 | float bval[] = { 0., 0.,.5 , 0.,.5 , 0., 1.,.5, 37 | .5 , 0., 1.,.5 , 1.,.5 , 1., 1.}; 38 | 39 | int remap14(R, G, B, R2, G2, B2) 40 | float R, G, B, *R2, *G2, *B2; 41 | { 42 | int code = 0; 43 | if ( R + G + B > 1.5) code |= 8; 44 | if (-R + G + B > 0.5) code |= 4; 45 | if ( R - G + B > 0.5) code |= 2; 46 | if ( R + G - B > 0.5) code |= 1; 47 | *R2 = rval[code]; 48 | *G2 = gval[code]; 49 | *B2 = bval[code]; 50 | return(code); 51 | } 52 | -------------------------------------------------------------------------------- /gems/Sturm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(Sturm main.c solve.h sturm.c util.c) 2 | 3 | -------------------------------------------------------------------------------- /gems/Sturm/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile 3 | # 4 | # command file for make to compile the solver. 5 | 6 | solve: main.o sturm.o util.o 7 | cc -o solve main.o sturm.o util.o -lm 8 | 9 | clean: 10 | /bin/rm -f main.o sturm.o util.o solve 11 | 12 | main.o sturm.o util.o: solve.h 13 | -------------------------------------------------------------------------------- /gems/Sturm/solve.h: -------------------------------------------------------------------------------- 1 | /* 2 | * solve.h 3 | * 4 | * some useful constants and types. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #define MAX_ORDER 12 12 | /* maximum order for a polynomial */ 13 | 14 | #define RELERROR 1.0e-14 15 | /* smallest relative error we want */ 16 | 17 | #define MAXPOW 32 18 | /* max power of 10 we wish to search to */ 19 | 20 | #define MAXIT 800 21 | /* max number of iterations */ 22 | 23 | /* a coefficient smaller than SMALL_ENOUGH is considered to 24 | be zero (0.0). */ 25 | 26 | #define SMALL_ENOUGH 1.0e-12 27 | 28 | 29 | /* 30 | * structure type for representing a polynomial 31 | */ 32 | typedef struct p { 33 | int ord; 34 | double coef[MAX_ORDER+1]; 35 | } poly; 36 | 37 | extern int modrf(); 38 | extern int numroots(); 39 | extern int numchanges(); 40 | extern ptrdiff_t buildsturm(); 41 | 42 | extern double evalpoly(); 43 | 44 | 45 | -------------------------------------------------------------------------------- /gems/Sturm/sturm.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "solve.h" 4 | 5 | void sbisect(int np, poly* sseq, double min, double max, int atmin, int atmax, double* roots); 6 | -------------------------------------------------------------------------------- /gemsii/BitCounting/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(BitCounting bit32.c test.c) 2 | 3 | -------------------------------------------------------------------------------- /gemsii/BitCounting/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -g 2 | 3 | tester : test.c bit32.o 4 | $(CC) $(CFLAGS) test.c -o tester bit32.o 5 | 6 | bit32.o : bit32.c 7 | $(CC) -c $(CFLAGS) bit32.c -o bit32.o 8 | 9 | clean: 10 | /bin/rm -f bit32.o tester 11 | -------------------------------------------------------------------------------- /gemsii/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_library(c_format c_format.c) 3 | add_library(FastUpdate FastUpdate.c) 4 | add_library(Hilbert Hilbert.c) 5 | add_library(hot hot.c) 6 | add_library(InterPhong InterPhong.c) 7 | add_library(inverse inverse.c) 8 | add_library(noise3 noise3.c) 9 | add_library(quantizer quantizer.c) 10 | add_library(ran_ramp ran_ramp.c) 11 | add_library(RayCPhdron RayCPhdron.c) 12 | add_library(rotate rotate.c) 13 | add_library(rotate8x8 rotate8x8.c) 14 | add_library(sparse sparse.c) 15 | add_library(unmatrix unmatrix.c) 16 | add_library(VoxelCache VoxelCache.c) 17 | add_library(xlines xlines.c) 18 | 19 | add_subdirectory(BitCounting) 20 | add_subdirectory(dither) 21 | add_subdirectory(intersect) 22 | add_subdirectory(inv_cmap) 23 | add_subdirectory(Peano) 24 | add_subdirectory(radiosity) 25 | add_subdirectory(RealPixels) 26 | add_subdirectory(viewcorr) 27 | 28 | target_link_libraries(c_format GetOpt) 29 | 30 | set_property(TARGET 31 | 32 | c_format FastUpdate Hilbert hot InterPhong inverse noise3 quantizer 33 | ran_ramp RayCPhdron rotate rotate8x8 sparse unmatrix VoxelCache xlines 34 | 35 | BitCounting dither intersect inv_cmap Peano PeanoMain PeanoMapply radiosity RealPixels viewcorr 36 | 37 | PROPERTY FOLDER "GraphicsGems II") 38 | -------------------------------------------------------------------------------- /gemsii/FastUpdate.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Author: Filippo Tampieri 4 | */ 5 | 6 | #define FALSE 0 7 | #define TRUE 1 8 | #define DOT(A,B) (A[0] * B[0] + A[1] * B[1] + A[2] * B[2]) 9 | 10 | /* 11 | vertexIsBehindPlane returns TRUE if point P is behind the 12 | plane of normal N and coefficient d, FALSE otherwise. 13 | */ 14 | int vertexIsBehindPlane(float P[3], float N[3], int d) 15 | { 16 | return(DOT(N, P) + d <= 0. ? TRUE : FALSE); 17 | } 18 | 19 | /* 20 | boxIsBehindPlane returns TRUE if the axis-aligned box of 21 | minimum corner Cmin and maximum corner Cmax is behind the 22 | plane of normal N and coefficient d, FALSE otherwise. 23 | */ 24 | int boxIsBehindPlane(float Cmin[3], float Cmax[3], float N[3], int d) 25 | { 26 | register int i; 27 | float P[3]; 28 | 29 | /* 30 | assign to P the corner further away 31 | along the direction of normal N 32 | */ 33 | for(i = 0; i < 3; i++) 34 | P[i] = N[i] >= 0. ? Cmax[i] : Cmin[i]; 35 | 36 | /* test P against the input plane */ 37 | return(vertexIsBehindPlane(P, N, d)); 38 | } 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /gemsii/Peano/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(Peano peano.c) 2 | add_executable(PeanoMain main.c) 3 | target_link_libraries(PeanoMain Peano m) 4 | add_executable(PeanoMapply mapply.c) 5 | target_link_libraries(PeanoMapply Peano) 6 | 7 | -------------------------------------------------------------------------------- /gemsii/Peano/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -O 2 | LIBES = -lm 3 | PROG = peano 4 | 5 | all: $(PROG) mapply 6 | 7 | # compile main program 8 | $(PROG): peano.o main.o 9 | cc peano.o main.o $(CFLAGS) -o $(PROG) $(LIBES) 10 | 11 | # dependencies on #include files 12 | peano.o main.o : types.h 13 | 14 | mapply: mapply.c types.h 15 | cc mapply.c $(CFLAGS) -o mapply $(LIBES) 16 | 17 | 18 | clean: 19 | /bin/rm -f peano.o main.o peano mapply 20 | -------------------------------------------------------------------------------- /gemsii/Peano/types.h: -------------------------------------------------------------------------------- 1 | /* types.h */ 2 | /* types and #define's for peano curve algorithm */ 3 | 4 | /* copyright Ken Musgrave */ 5 | /* June 1986 */ 6 | 7 | 8 | #define FB_SIZE 1024 /* frame buffer size */ 9 | 10 | #define MAX_DIMENSIONS 5 /* dimensionality of space */ 11 | #define MAX_PRECISION 11 /* number of bits/dimension -1 */ 12 | 13 | #define ODD(x) ( ( (x) & 0x1 ) ? 1 : 0 ) 14 | 15 | /* right circular shift */ 16 | #define RT_CSHFT( byte, shift, dimensions, bytemask ) \ 17 | ((((byte) >> (shift)) | ((byte) << (dimensions - (shift)))) & bytemask) 18 | 19 | 20 | typedef char byte; /* size must be >= MAX_PRECISION */ 21 | 22 | typedef int vector[MAX_DIMENSIONS]; /* n-space vector */ 23 | 24 | typedef byte r_array[MAX_PRECISION]; /* vector of type "r" in algo */ 25 | 26 | 27 | /* global variable section */ 28 | 29 | extern int J[MAX_PRECISION]; /* storage for principal positions */ 30 | 31 | /* global arrays */ 32 | extern r_array rho, sigma, tau, tilde_sigma, tilde_tau, omega, alpha; 33 | 34 | extern byte bitmask[MAX_DIMENSIONS]; /* to be filled with bit masks */ 35 | 36 | extern int dimensions; /* number of dimensions being filled */ 37 | extern int precision; /* number of bits of precision used */ 38 | extern byte bytemask; /* masks "dimensions" bits */ 39 | 40 | void peano(vector coord, int point); 41 | -------------------------------------------------------------------------------- /gemsii/RealPixels/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(RealPixels color.h color.c colrops.c header.c ra_pr24.c resolu.c) 2 | 3 | -------------------------------------------------------------------------------- /gemsii/RealPixels/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -g 2 | LIBS = -lm 3 | 4 | ra_pr24: color.o colrops.o header.o resolu.o rasterfile.h color.h 5 | cc $(CFLAGS) ra_pr24.c -o ra_pr24 \ 6 | color.o colrops.o header.o resolu.o $(LIBS) 7 | 8 | color.o: color.c color.h 9 | cc $(CFLAGS) -c color.c -o color.o 10 | 11 | colrops.o: colrops.c color.h 12 | cc $(CFLAGS) -c colrops.c -o colrops.o 13 | 14 | header.o: header.c 15 | cc $(CFLAGS) -c header.c -o header.o 16 | 17 | resolu.o: resolu.c color.h 18 | cc $(CFLAGS) -c resolu.c -o resolu.o 19 | 20 | clean: 21 | /bin/rm -f color.o colrops.o header.o ra_pr24 resolu.o 22 | -------------------------------------------------------------------------------- /gemsii/RealPixels/colrops.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "color.h" 4 | 5 | void shiftcolrs(COLR* scan, int len, int adjust); 6 | void colrs_gambs(COLR* scan, int len); 7 | void setcolrgam(double g); 8 | -------------------------------------------------------------------------------- /gemsii/RealPixels/header.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void printargs(int ac, char** av, FILE* fp); 4 | void fputformat(char* s, FILE* fp); 5 | int checkheader(FILE* fin, char* fmt, FILE* fout); 6 | -------------------------------------------------------------------------------- /gemsii/RealPixels/resolu.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Read and write image resolutions. 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | #include "color.h" 9 | 10 | 11 | void fputresolu(int ord, int xres, int yres, FILE* fp) /* put x and y resolution */ 12 | { 13 | if (ord&YMAJOR) 14 | fprintf(fp, "%cY %d %cX %d\n", 15 | ord&YDECR ? '-' : '+', yres, 16 | ord&XDECR ? '-' : '+', xres); 17 | else 18 | fprintf(fp, "%cX %d %cY %d\n", 19 | ord&XDECR ? '-' : '+', xres, 20 | ord&YDECR ? '-' : '+', yres); 21 | } 22 | 23 | 24 | int fgetresolu(int* xrp, int* yrp, FILE* fp) /* get x and y resolution */ 25 | { 26 | char buf[64], *xndx, *yndx; 27 | register char *cp; 28 | register int ord; 29 | 30 | if (fgets(buf, sizeof(buf), fp) == NULL) 31 | return(-1); 32 | xndx = yndx = NULL; 33 | for (cp = buf+1; *cp; cp++) 34 | if (*cp == 'X') 35 | xndx = cp; 36 | else if (*cp == 'Y') 37 | yndx = cp; 38 | if (xndx == NULL || yndx == NULL) 39 | return(-1); 40 | ord = 0; 41 | if (xndx > yndx) ord |= YMAJOR; 42 | if (xndx[-1] == '-') ord |= XDECR; 43 | if (yndx[-1] == '-') ord |= YDECR; 44 | if ((*xrp = atoi(xndx+1)) <= 0) 45 | return(-1); 46 | if ((*yrp = atoi(yndx+1)) <= 0) 47 | return(-1); 48 | return(ord); 49 | } 50 | -------------------------------------------------------------------------------- /gemsii/RealPixels/resolu.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void fputresolu(int ord, int xres, int yres, FILE* fp); 4 | int fgetresolu(int* xrp, int* yrp, FILE* fp); 5 | -------------------------------------------------------------------------------- /gemsii/dither/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(dither dither.c) 2 | 3 | -------------------------------------------------------------------------------- /gemsii/dither/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -g 2 | 3 | dither.o: dither.c 4 | cc $(CFLAGS) -c dither.c -o dither.o 5 | 6 | clean: 7 | /bin/rm -f dither.o 8 | -------------------------------------------------------------------------------- /gemsii/intersect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(intersect intsph.c inttor.c) 2 | 3 | -------------------------------------------------------------------------------- /gemsii/intersect/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -g -I.. 2 | 3 | all: intsph.o inttor.o 4 | 5 | intsph.o: intsph.c 6 | cc $(CFLAGS) -c intsph.c -o intsph.o 7 | 8 | inttor.o: inttor.c 9 | cc $(CFLAGS) -c inttor.c -o inttor.o 10 | 11 | clean: 12 | /bin/rm -f intsph.o inttor.o 13 | -------------------------------------------------------------------------------- /gemsii/inv_cmap/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(inv_cmap inv_cmap.c) 2 | 3 | -------------------------------------------------------------------------------- /gemsii/inv_cmap/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -g 2 | 3 | inv_cmap.o: inv_cmap.c 4 | cc $(CFLAGS) -c inv_cmap.c -o inv_cmap.o 5 | 6 | clean: 7 | /bin/rm -f inv_cmap.o 8 | -------------------------------------------------------------------------------- /gemsii/radiosity/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(radiosity draw.c rad.c room.c) 2 | 3 | -------------------------------------------------------------------------------- /gemsii/radiosity/Makefile: -------------------------------------------------------------------------------- 1 | # -Aa is HPUX's way of invoking ANSI C 2 | CFLAGS = -g -Aa 3 | 4 | all: draw.o rad.o room.o 5 | 6 | draw.o: draw.o rad.h 7 | cc $(CFLAGS) -c draw.c -o draw.o 8 | 9 | rad.o: rad.o rad.h 10 | cc $(CFLAGS) -c rad.c -o rad.o 11 | 12 | room.o: room.o rad.h 13 | cc $(CFLAGS) -c room.c -o room.o 14 | 15 | clean: 16 | /bin/rm -f draw.o rad.o room.o 17 | -------------------------------------------------------------------------------- /gemsii/radiosity/README: -------------------------------------------------------------------------------- 1 | 2 | 3 | The source is Copyright (c) 1990-1991 by Apple Computer, Inc. You may not use 4 | it in anything for which you charge money, beyond reasonable fees to cover 5 | duplication and handling. If you give your software away, feel free to use 6 | this source. 7 | 8 | The source is the implementation of a gem, "Implementing Progressive Radiosity 9 | with User-Provided Polygon Display Routines," that I wrote for Graphics Gems II. 10 | A hard copy of the source can be found in Appendix II of Graphics Gems II. 11 | The source included here is a newer version than the one in the book 12 | and should replace it. For more details on the source and radiosity methods, 13 | please refer to the book. 14 | 15 | No warranties expressed, implied, or even hinted at. 16 | 17 | The source is written in ANSI C and is C++ friendly (you can include the 18 | .h files in C++ programs). 19 | 20 | Please send bug reports and/or enhancements to the author "chense@apple.com". 21 | I would also like to hear any system that you have ported the source to. 22 | However, please don't ask me for technical support on the source. 23 | 24 | 25 | -------------------------------------------------------------------------------- /gemsii/radiosity/draw.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * draw.c 3 | * 4 | * This is a skeleton polygon drawing program 5 | * 6 | * Copyright (C) 1990-1991 Apple Computer, Inc. 7 | * All rights reserved. 8 | * 9 | * 8/27/1991 S. Eric Chen 10 | ******************************************************************************/ 11 | #include "rad.h" 12 | 13 | void BeginDraw(TView *view, unsigned long color) 14 | { 15 | /* first time this view is drawn */ 16 | if (view->wid==0) 17 | { 18 | /* open a new window if you want to display it on the screen */ 19 | /* assign the window id or pointer to view->wid */ 20 | /* the window id cannot be zero */ 21 | /* do all the necessary initialization here too */ 22 | } 23 | 24 | /* make view->wid the current window */ 25 | 26 | /* set up view transformation from the parameters in view */ 27 | 28 | /* clear the frame buffer with color */ 29 | } 30 | 31 | void DrawPolygon(int nPts, TPoint3f *pts, TVector3f* n, unsigned long color) 32 | { 33 | /* draw a polygon with the given color */ 34 | /* buffer the polygon if you are drawing in a display list mode */ 35 | } 36 | 37 | void EndDraw() 38 | { 39 | /* finish the drawing of all polygons */ 40 | /* display the contents of view->buffer to the current window if necessary */ 41 | 42 | } 43 | 44 | 45 | -------------------------------------------------------------------------------- /gemsii/unmatrix.h: -------------------------------------------------------------------------------- 1 | /* 2 | * unmatrix.h - Definitions for using unmatrix 3 | * 4 | * Author: Spencer W. Thomas 5 | * University of Michigan 6 | */ 7 | 8 | /* The unmatrix subroutine fills in a vector of floating point 9 | * values. These symbols make it easier to get the data back out. 10 | */ 11 | 12 | enum unmatrix_indices { 13 | U_SCALEX, 14 | U_SCALEY, 15 | U_SCALEZ, 16 | U_SHEARXY, 17 | U_SHEARXZ, 18 | U_SHEARYZ, 19 | U_ROTATEX, 20 | U_ROTATEY, 21 | U_ROTATEZ, 22 | U_TRANSX, 23 | U_TRANSY, 24 | U_TRANSZ, 25 | U_PERSPX, 26 | U_PERSPY, 27 | U_PERSPZ, 28 | U_PERSPW 29 | }; 30 | 31 | typedef struct { 32 | double x,y,z,w; 33 | } Vector4; 34 | 35 | Matrix4 *TransposeMatrix4(); 36 | Vector4 *V4MulPointByMatrix(); 37 | -------------------------------------------------------------------------------- /gemsii/viewcorr/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(viewcorr matrix.c viewcorr.c viewfind.c) 2 | 3 | -------------------------------------------------------------------------------- /gemsii/viewcorr/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -g -I.. 2 | 3 | all: matrix.o viewcorr.o viewfind.o 4 | 5 | matrix.o: matrix.o matrix.h 6 | cc $(CFLAGS) -c matrix.c -o matrix.o 7 | 8 | viewcorr.o: viewcorr.o matrix.h viewcorr.h 9 | cc $(CFLAGS) -c viewcorr.c -o viewcorr.o 10 | 11 | viewfind.o: viewfind.o matrix.h viewcorr.h 12 | cc $(CFLAGS) -c viewfind.c -o viewfind.o 13 | 14 | clean: 15 | /bin/rm -f matrix.o viewcorr.o viewfind.o 16 | -------------------------------------------------------------------------------- /gemsii/viewcorr/matrix.h: -------------------------------------------------------------------------------- 1 | /* matrix.h 2 | * The type and externs for matrix routines. 3 | */ 4 | 5 | typedef double ** Matrix; 6 | 7 | Matrix NewMatrix(int cols, int rows); 8 | void FreeMatrix(Matrix mat, int rows); 9 | double InvertMatrix(Matrix mat, int actual_size); 10 | void TransposeMatrix(Matrix inM, Matrix outM, int cols, int rows); 11 | void MultMatrix(Matrix firstM, Matrix secondM, Matrix outM, int firstrows, int cols, int secondcols); 12 | -------------------------------------------------------------------------------- /gemsii/viewcorr/viewcorr.h: -------------------------------------------------------------------------------- 1 | /* viewcorr.h 2 | * The global types for view correlation routines. 3 | */ 4 | 5 | typedef struct ViewParmsStruct { 6 | Point3 eye; /* projection point */ 7 | Matrix3 view; /* 3x3 rotation matrix */ 8 | Matrix3 viewinv; /* 3x3 inverse rotation matrix */ 9 | double d_over_s; /* distance to screen / half screen width */ 10 | double aspect; /* aspect ratio (for non-square pixels) */ 11 | double halfx, halfy; /* half of screen resolutions */ 12 | double xcenter, ycenter; /* center of image */ 13 | } ViewParms; 14 | 15 | typedef struct ViewDataStruct { 16 | int numpts; /* number of data points */ 17 | Point3 *pts; /* array of three D data points */ 18 | Point2 *scrpts; /* array of screen data points */ 19 | } ViewData; 20 | 21 | /* If you cannot handle arbitrary aspect ratios, change the following define 22 | * to an undef. The iteration will happen with the aspect ratio given in 23 | * the initial set of ViewParms. 24 | */ 25 | #define ITERATE_ASPECT_RATIO 26 | 27 | #ifdef ITERATE_ASPECT_RATIO 28 | #define NUM_VIEW_PARMS 10 29 | #else 30 | #define NUM_VIEW_PARMS 9 31 | #endif 32 | 33 | void propagate_rotate_change(ViewParms* view_parms); 34 | void iterate_view_parms(ViewData* datapts, ViewParms* view_parms, int num_iterations); 35 | -------------------------------------------------------------------------------- /gemsiii/accurate_scan/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(accurate_scan dblfixpoint.c fixpoint.c tri.c) 2 | add_executable(accurate_exhaust exhaust.c) 3 | target_link_libraries(accurate_exhaust accurate_scan m) 4 | add_executable(accurate_test test.c) 5 | target_link_libraries(accurate_test accurate_scan m) 6 | 7 | -------------------------------------------------------------------------------- /gemsiii/accurate_scan/fixpoint.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* Requires: LOBITS to be divisible by 2, HIBITS<=16, and LOBITS <=16. */ 4 | 5 | #define HIBITS 16 6 | #define LOBITS 16 7 | 8 | #define LOMASK (~(0xffffffff << LOBITS)) 9 | #define HIMASK ((~(0xffffffff << HIBITS)) << LOBITS) 10 | #define SIGNBIT (1 << (HIBITS+LOBITS-1)) 11 | #define OVERFLOWMASK (SIGNBIT | ~(HIMASK | LOMASK)) 12 | 13 | typedef int fixpoint; 14 | #include 15 | typedef struct { int64_t hi, lo, neg;} dblfixpoint; 16 | 17 | extern int fp_error; 18 | extern fixpoint fp_max(); 19 | extern fixpoint fp_min(); 20 | extern int fp_integer(); 21 | extern int fp_fraction(); 22 | extern double fp_fraction_double(); 23 | 24 | extern fixpoint fp_multiply(); 25 | extern void fp_print(); 26 | extern fixpoint fp_fix(); 27 | extern double fp_double(fixpoint x); 28 | 29 | extern uint64_t fp_dblnegative(); 30 | extern dblfixpoint fp_dblnegate(); 31 | extern dblfixpoint fp_dblmultiply(); 32 | extern int fp_dbllessthan(); 33 | extern dblfixpoint fp_dbladd(); 34 | extern fixpoint fp_trunc(); 35 | 36 | fixpoint fp_floor(fixpoint x); 37 | fixpoint fp_floor_div(fixpoint x, fixpoint y); 38 | -------------------------------------------------------------------------------- /gemsiii/accurate_scan/tri.data: -------------------------------------------------------------------------------- 1 | 0.0 1 3 2 | 0 0 3 | 0 1 4 | 1 0 5 | 0 1 2 6 | -------------------------------------------------------------------------------- /gemsiii/alloc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(alloc alloc.c) 2 | -------------------------------------------------------------------------------- /gemsiii/alloc/Makefile: -------------------------------------------------------------------------------- 1 | # -Aa is HPUX's way of invoking ANSI C 2 | CFLAGS = -g -Aa 3 | 4 | alloc.o: alloc.o alloc.h 5 | cc $(CFLAGS) -c alloc.c -o alloc.o 6 | 7 | clean: 8 | rm -rf alloc.o 9 | -------------------------------------------------------------------------------- /gemsiii/alloc/alloc.h: -------------------------------------------------------------------------------- 1 | /* alloc.h 2 | * 3 | * Header for alloc.c 4 | * 5 | * The type alloc_handle_t provides an opaque reference to the 6 | * alloc pool - only the alloc routines know its structure. 7 | */ 8 | 9 | typedef 10 | struct { int dummy; } 11 | alloc_handle_t; 12 | 13 | -------------------------------------------------------------------------------- /gemsiii/defs.h: -------------------------------------------------------------------------------- 1 | /* Dummy include file of definitions to make rolling-ball compile. */ 2 | 3 | #define Button1 1 4 | #define ERASE 0 5 | #define DRAW 3 6 | 7 | typedef struct { 8 | char *name; 9 | double frame[4][4]; 10 | } Polyhedron; 11 | 12 | typedef struct { 13 | char *name; 14 | int id; 15 | } Display; 16 | -------------------------------------------------------------------------------- /gemsiii/exttest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(exttest ehtest1.C exthit.C) 2 | 3 | -------------------------------------------------------------------------------- /gemsiii/exttest/Makefile: -------------------------------------------------------------------------------- 1 | # code is C++ 2 | CFLAGS = 3 | 4 | ehtest1: ehtest1.C exthit.o exthit.h 5 | CC $(CFLAGS) -o ehtest1 ehtest1.C exthit.o 6 | 7 | exthit.o: exthit.C exthit.h 8 | CC $(CFLAGS) -c exthit.C -o exthit.o 9 | 10 | clean: 11 | rm -rf ehtest1 exthit.o 12 | -------------------------------------------------------------------------------- /gemsiii/exttest/ehtest1.C: -------------------------------------------------------------------------------- 1 | // 2 | // ExtHit minimal tester 3 | // 4 | // Len Wanger - Fri Aug 30 10:07:01 PDT 1991 5 | // 6 | 7 | #include 8 | #include "exthit.h" 9 | 10 | using std::cout; 11 | 12 | void func_tst (Ptr data, Ptr p1, Ptr p2 ) 13 | { 14 | cout << "Objects " << (Ptr) p1 << " and " << (Ptr) p2 << " intersect.\n"; 15 | } 16 | 17 | int main() 18 | { 19 | ExtHit eh(5); 20 | Extent ext; 21 | Ptr ptr; 22 | 23 | ext.min[0] = 1; ext.max[0] = 3; 24 | ext.min[1] = 2; ext.max[1] = 4; 25 | ext.min[2] = 4; ext.max[2] = 6; 26 | ext.min[3] = 2; ext.max[3] = 8; 27 | 28 | ptr = (Ptr) 0x1; 29 | 30 | if ( ! eh.add ( ext, ptr ) ) 31 | cout << "Fillnext failed\n";; 32 | 33 | ext.min[0] = 5; ext.max[0] = 7; 34 | ext.min[1] = 6; ext.max[1] = 8; 35 | ext.min[2] = 2; ext.max[2] = 8; 36 | ext.min[3] = 1; ext.max[3] = 3; 37 | 38 | ptr = (Ptr) 0x2; 39 | 40 | if ( ! eh.add ( ext, ptr ) ) 41 | cout << "Fillnext failed\n";; 42 | 43 | ext.min[0] = 2; ext.max[0] = 6; 44 | ext.min[1] = 3; ext.max[1] = 7; 45 | ext.min[2] = 7; ext.max[2] = 7; 46 | ext.min[3] = 2; ext.max[3] = 4; 47 | 48 | ptr = (Ptr) 0x3; 49 | 50 | if ( ! eh.add ( ext, ptr ) ) 51 | cout << "Fillnext failed\n";; 52 | 53 | ext.min[0] = 2; ext.max[0] = 6; 54 | ext.min[1] = 5; ext.max[1] = 5; 55 | ext.min[2] = 1; ext.max[2] = 5; 56 | ext.min[3] = 1; ext.max[3] = 5; 57 | 58 | ptr = (Ptr) 0x4; 59 | 60 | if ( ! eh.add ( ext, ptr ) ) 61 | cout << "Fillnext failed\n";; 62 | 63 | eh.test ( func_tst, (Ptr) 0x5); 64 | } 65 | 66 | -------------------------------------------------------------------------------- /gemsiii/fastBitmap.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erich666/GraphicsGems/6bd96c311d77db5dc750e850167c76c5f45af4c1/gemsiii/fastBitmap.c -------------------------------------------------------------------------------- /gemsiii/luminaire/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(luminaire geometry_object.C sphere_luminaire.C triangle_luminaire.C) 2 | 3 | -------------------------------------------------------------------------------- /gemsiii/luminaire/Makefile: -------------------------------------------------------------------------------- 1 | # code is C++ 2 | CFLAGS = 3 | 4 | all: geometry_object.o sphere_luminaire.o triangle_luminaire.o 5 | 6 | geometry_object.o: geometry_object.C geometry_object.h utility.h 7 | CC $(CFLAGS) -c geometry_object.C -o geometry_object.o -lm 8 | 9 | sphere_luminaire.o: sphere_luminaire.C sphere_luminaire.h utility.h 10 | CC $(CFLAGS) -c sphere_luminaire.C -o sphere_luminaire.o -lm 11 | 12 | triangle_luminaire.o: triangle_luminaire.C triangle_luminaire.h utility.h 13 | CC $(CFLAGS) -c triangle_luminaire.C -o triangle_luminaire.o -lm 14 | 15 | clean: 16 | rm -rf geometry_object.o sphere_luminaire.o triangle_luminaire.o 17 | -------------------------------------------------------------------------------- /gemsiii/luminaire/geometry_object.C: -------------------------------------------------------------------------------- 1 | // ****************************************************************** 2 | // 3 | // Physically Correct Direct Lighting For Distribution Ray Tracing 4 | // by Changyaw Wang 5 | // 6 | // geometry_object.c 7 | // 8 | // ****************************************************************** 9 | 10 | #include "utility.h" 11 | 12 | void geom_obj::select_visible_point( 13 | const point&, // not used 14 | const double, // not used 15 | const double, // not used 16 | point&, // not used 17 | double&) // not used 18 | { } 19 | 20 | -------------------------------------------------------------------------------- /gemsiii/luminaire/geometry_object.h: -------------------------------------------------------------------------------- 1 | // ****************************************************************** 2 | // 3 | // Physically Correct Direct Lighting For Distribution Ray Tracing 4 | // by Changyaw Wang 5 | // 6 | // geometry_object.h 7 | // 8 | // ****************************************************************** 9 | 10 | // Abstract class geom_obj may be subclassed to a particular type of 11 | // object such as a sphere, or a triangle. 12 | 13 | class point; 14 | 15 | class geom_obj { 16 | public: 17 | 18 | // Selects a point visible from x given (r1,r2). 19 | // Here, visible means not SELF-shadowed. 20 | 21 | virtual void select_visible_point( 22 | const point& x, // viewpoint 23 | const double r1, // random number 24 | const double r2, // random number 25 | point& on_light, // point corresponding to (r1,r2) 26 | double& prob); // probability of selecting on_light 27 | }; 28 | 29 | -------------------------------------------------------------------------------- /gemsiii/luminaire/special_instruction: -------------------------------------------------------------------------------- 1 | // ****************************************************************** 2 | // 3 | // The following C++ code computes a sample point and its probability 4 | // on the spherical or triangular luminaire according to the solid 5 | // angle from the view point. These are the center part of the direct 6 | // lighting computation via Monte Carlo integration. 7 | // 8 | // The function hit() is assumed to exist. It returns the intersection 9 | // point of a ray and a luminaire. 10 | // 11 | // Use the command, CC -c *.C -lm, to compile (not link). The code 12 | // needs to be combined with a ray tracer to complete. 13 | // ****************************************************************** 14 | 15 | -------------------------------------------------------------------------------- /gemsiii/luminaire/sphere_luminaire.h: -------------------------------------------------------------------------------- 1 | // ****************************************************************** 2 | // 3 | // Physically Correct Direct Lighting For DistribOAution Ray Tracing 4 | // by Changyaw Wang 5 | // 6 | // sphere_luminaire.h 7 | // 8 | // ****************************************************************** 9 | 10 | class sphere : public geom_obj { 11 | public: 12 | point center; 13 | double radius; 14 | 15 | void hit(const point& x, // viewpoint 16 | const vector& v, // viewing direction 17 | const point on_light); // hit point 18 | 19 | // Selects a point visible from x given (r1,r2). 20 | // Here, visible means not SELF-shadowed. 21 | 22 | virtual void select_visible_point( 23 | const point& x, // viewpoint 24 | const double r1, // random number 25 | const double r2, // random number 26 | point& on_light, // point corresponding to (r1,r2) 27 | double& prob); // probability of selecting on_light 28 | }; 29 | 30 | -------------------------------------------------------------------------------- /gemsiii/luminaire/triangle_luminaire.C: -------------------------------------------------------------------------------- 1 | // ****************************************************************** 2 | // 3 | // Physically Correct Direct Lighting For Distribution Ray Tracing 4 | // by Changyaw Wang 5 | // 6 | // triangle_luminaire.c 7 | // 8 | // ****************************************************************** 9 | 10 | #include "utility.h" 11 | 12 | // Selects a point visible from x given (r1,r2). 13 | // Here, visible means not SELF-shadowed. 14 | 15 | void triangle::select_visible_point( 16 | const point& x, // viewpoint 17 | const double r1, // random number 18 | const double r2, // random number 19 | point& on_light, // point corresponding to (r1,r2) 20 | double& prob) // probability of selecting on_light 21 | { 22 | point pt, pt1, pt2, pt3; 23 | vector v1, v2, v3, psi, temp1, temp2; 24 | double u, v, area; 25 | 26 | v1 = p1 - x; 27 | v1.normalize(); 28 | pt1 = x + v1; 29 | v2 = p2 - x; 30 | v2.normalize(); 31 | pt2 = x + v2; 32 | v3 = p3 - x; 33 | v3.normalize(); 34 | pt3 = x + v3; 35 | u = 1.0 - sqrt(1.0 - r1); 36 | v = r2 * sqrt(1.0 - r1); 37 | 38 | pt = pt1 + u*(pt2 - pt1) + v*(pt3 - pt1); 39 | psi = pt - x; 40 | psi.normalize(); 41 | hit(x, psi, on_light); 42 | temp1 = pt2 - pt1; 43 | temp2 = pt3 - pt1; 44 | temp1 = cross(temp1,temp2); 45 | // area is the area of pt1,pt2,pt3 46 | area = 0.5 * sqrt(dot(temp1, temp1)); 47 | temp1.normalize(); 48 | prob = distance_squared(x,pt)*dot(-1.0*psi,normal) / 49 | (distance_squared(x,on_light)*dot(-1.0*psi,temp1)*area); 50 | } 51 | 52 | -------------------------------------------------------------------------------- /gemsiii/luminaire/triangle_luminaire.h: -------------------------------------------------------------------------------- 1 | // ****************************************************************** 2 | // 3 | // Physically Correct Direct Lighting For Distribution Ray Tracing 4 | // by Changyaw Wang 5 | // 6 | // triangle_luminaire.h 7 | // 8 | // ****************************************************************** 9 | 10 | class triangle : public geom_obj { 11 | public: 12 | point p1; // vertex 13 | point p2; // vertex 14 | point p3; // vertex 15 | vector normal; // normal vector 16 | 17 | void hit(const point& x, // viewpoint 18 | const vector& v, // viewing direction 19 | const point on_light); // hit point 20 | 21 | // Selects a point visible from x given (r1,r2). 22 | // Here, visible means not SELF-shadowed. 23 | 24 | virtual void select_visible_point( 25 | const point& x, // viewpoint 26 | const double r1, // random number 27 | const double r2, // random number 28 | point& on_light, // point corresponding to (r1,r2) 29 | double& prob); // probability of selecting on_light 30 | }; 31 | 32 | -------------------------------------------------------------------------------- /gemsiii/partition3d/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(partition3d main.c partition.c) 2 | 3 | -------------------------------------------------------------------------------- /gemsiii/partition3d/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -I.. 2 | 3 | main: main.c partition.o partition.h 4 | cc $(CFLAGS) -o main main.c partition.o -lm 5 | 6 | partition.o: partition.c partition.h 7 | cc $(CFLAGS) -c partition.c -o partition.o 8 | 9 | clean: 10 | rm -rf main partition.o 11 | -------------------------------------------------------------------------------- /gemsiii/partition3d/partition.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | /* partition.h: header file for partition module. 19 | * Copyright (c) Norman Chin 20 | */ 21 | #ifndef _PARTITION_INCLUDED 22 | #define _PARTITION_INCLUDED 23 | 24 | typedef enum { ZERO, NEGATIVE, POSITIVE } SIGN; 25 | 26 | typedef struct vertexTag { 27 | double xx,yy,zz; /* 3D coordinates of vertex */ 28 | 29 | struct vertexTag *vnext; /* ptr to next vertex */ 30 | } VERTEX; 31 | #define NULL_VERTEX ((VERTEX *) NULL) 32 | 33 | typedef struct { 34 | int someInfo; /* some face info goes here, ie. material properties */ 35 | 36 | VERTEX *vhead; /* ptr to first vertex of face */ 37 | } FACE; 38 | #define NULL_FACE ((FACE *) NULL) 39 | 40 | #define TOLER 0.000001 41 | #define ISDOUBLE_EQ(a,b) ((fabs((a)-(b)) >= (double) TOLER) ? 0 : 1) 42 | 43 | #define ISVERTEX_EQ(v1,v2) \ 44 | (ISDOUBLE_EQ((v1)->xx,(v2)->xx) && \ 45 | ISDOUBLE_EQ((v1)->yy,(v2)->yy) && \ 46 | ISDOUBLE_EQ((v1)->zz,(v2)->zz)) 47 | #define FREEVERTEX(v) (free((char *) (v))) 48 | 49 | /* external functions */ 50 | void partitionFaceWithPlane(/* double aa, double bb, double cc, double dd, 51 | FACE *face, FACE **faceOn, 52 | FACE **faceNeg, FACE **facePos 53 | */ 54 | ); 55 | #endif //_PARTITION_INCLUDED 56 | 57 | 58 | -------------------------------------------------------------------------------- /gemsiii/pt2plane.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Signed Distance from Point to Plane 3 | Author: Priamos Georgiades 4 | ******************************************************************************/ 5 | #include 6 | 7 | typedef struct vect3str { 8 | float x, y, z; 9 | } vect3; 10 | typedef struct vect4str { 11 | float x, y, z, w; 12 | } vect4; 13 | 14 | #define Vect3Dot(v1, v2) ((v1).x * (v2).x + (v1).y * (v2).y + (v1).z * (v2).z) 15 | 16 | /* 17 | Compute the distance from a point to a plane. The plane is 18 | pleq->x * X + pleq->y * Y + pleq->z * Z + pleq->w = 0. 19 | The distance is positive if on same side as the normal, otherwise negative. 20 | Assume the plane normal to be of unit length. 21 | */ 22 | float Pt2Plane(vect3 *pt, vect4 *pleq) 23 | { 24 | float dist; 25 | 26 | dist = Vect3Dot(*pleq, *pt) + pleq->w; 27 | return(dist); 28 | } 29 | 30 | -------------------------------------------------------------------------------- /gemsiii/quatspin.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Spherical linear interpolation of unit quaternions with spins 3 | */ 4 | #define _USE_MATH_DEFINES 5 | #include 6 | 7 | #define EPSILON 1.0E-6 /* a tiny number */ 8 | #define TRUE 1 9 | #define FALSE 0 10 | 11 | typedef struct { /* quaternion type */ 12 | double w, x, y, z; 13 | } Quaternion; 14 | 15 | void slerp(alpha, a, b, q, spin) 16 | double alpha; /* interpolation parameter (0 to 1) */ 17 | Quaternion *a, *b; /* start and end unit quaternions */ 18 | Quaternion *q; /* output interpolated quaternion */ 19 | int spin; /* number of extra spin rotations */ 20 | { 21 | double beta; /* complementary interp parameter */ 22 | double theta; /* angle between A and B */ 23 | double sin_t, cos_t; /* sine, cosine of theta */ 24 | double phi; /* theta plus spins */ 25 | int bflip; /* use negation of B? */ 26 | 27 | /* cosine theta = dot product of A and B */ 28 | cos_t = a->x*b->x + a->y*b->y + a->z*b->z + a->w*b->w; 29 | 30 | /* if B is on opposite hemisphere from A, use -B instead */ 31 | if (cos_t < 0.0) { 32 | cos_t = -cos_t; 33 | bflip = TRUE; 34 | } else 35 | bflip = FALSE; 36 | 37 | /* if B is (within precision limits) the same as A, 38 | * just linear interpolate between A and B. 39 | * Can't do spins, since we don't know what direction to spin. 40 | */ 41 | if (1.0 - cos_t < EPSILON) { 42 | beta = 1.0 - alpha; 43 | } else { /* normal case */ 44 | theta = acos(cos_t); 45 | phi = theta + spin * M_PI; 46 | sin_t = sin(theta); 47 | beta = sin(theta - alpha*phi) / sin_t; 48 | alpha = sin(alpha*phi) / sin_t; 49 | } 50 | 51 | if (bflip) 52 | alpha = -alpha; 53 | 54 | /* interpolate */ 55 | q->x = beta*a->x + alpha*b->x; 56 | q->y = beta*a->y + alpha*b->y; 57 | q->z = beta*a->z + alpha*b->z; 58 | q->w = beta*a->w + alpha*b->w; 59 | } 60 | 61 | -------------------------------------------------------------------------------- /gemsiii/simplex/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(simplex recur.C symm.C) 2 | 3 | -------------------------------------------------------------------------------- /gemsiii/simplex/Makefile: -------------------------------------------------------------------------------- 1 | # code is C++ 2 | CFLAGS = 3 | 4 | recur.o: recur.C 5 | CC $(CFLAGS) -c recur.C -o recur.o 6 | 7 | symm.o: symm.C 8 | CC $(CFLAGS) -c symm.C -o symm.o 9 | 10 | clean: 11 | rm -rf recur.o symm.o 12 | -------------------------------------------------------------------------------- /gemsiii/simplex/recur.C: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | Given an s-simplex (with s+1 vertexes) in n dimensions, 3 | calculate the vertexes of the kth (0 <= k < (1<>= 1; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /gemsiii/simplex/symm.C: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | Given an s-simplex (with s+1 vertexes) in n dimensions, 3 | calculate the vertexes of the kth (0 <= k < (1<>= 1; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /gemsiii/urot.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erich666/GraphicsGems/6bd96c311d77db5dc750e850167c76c5f45af4c1/gemsiii/urot.c -------------------------------------------------------------------------------- /gemsiv/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | add_library(centroid centroid.c) 4 | add_library(clahe clahe.c) 5 | add_executable(collide collide.c) 6 | add_executable(convolve convolve.c) 7 | add_library(coons_warp coons_warp.c) 8 | add_library(dist_fast dist_fast.c) 9 | add_library(emboss emboss.c) 10 | add_executable(implicit implicit.c) 11 | add_executable(interp_fast interp_fast.c) 12 | add_library(inv_fast inv_fast.c) 13 | add_library(ray_cyl ray_cyl.c) 14 | add_library(sph_poly sph_poly.c) 15 | add_library(thin_image thin_image.c) 16 | add_library(trilerp trilerp.c) 17 | add_library(vo_traverse vox_traverse.c) 18 | 19 | add_subdirectory(arcball) 20 | add_subdirectory(convex_test) 21 | add_subdirectory(curve_isect) 22 | add_subdirectory(data_smooth) 23 | add_subdirectory(delaunay) 24 | add_subdirectory(dyn_range) 25 | add_subdirectory(euler_angle) 26 | add_subdirectory(graph_layout) 27 | add_subdirectory(minray) 28 | add_subdirectory(multi_jitter) 29 | add_subdirectory(nurb_polyg) 30 | add_subdirectory(outcode) 31 | add_subdirectory(polar_decomp) 32 | add_subdirectory(ptpoly_haines) 33 | add_subdirectory(ptpoly_weiler) 34 | add_subdirectory(vec_mat) 35 | add_subdirectory(vert_norm) 36 | 37 | set_property(TARGET 38 | centroid clahe collide convolve coons_warp dist_fast emboss 39 | implicit interp_fast inv_fast ray_cyl sph_poly thin_image trilerp vo_traverse 40 | arcball convex_test curve_isect data_smooth delaunay dyn_range euler_angle 41 | graph_layout minray multi_jitter nurb_polyg outcode xcc2d xcc4d polar_decomp 42 | ptpoly_haines ptpoly_weiler vec_mat ray vert_norm 43 | PROPERTY FOLDER "GraphicsGems IV") 44 | 45 | if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") 46 | target_link_libraries(collide m) 47 | target_link_libraries(implicit m) 48 | endif() 49 | 50 | -------------------------------------------------------------------------------- /gemsiv/arcball/Ball.h: -------------------------------------------------------------------------------- 1 | /***** Ball.h *****/ 2 | #ifndef _H_Ball 3 | #define _H_Ball 4 | #include "BallAux.h" 5 | 6 | typedef enum AxisSet{NoAxes, CameraAxes, BodyAxes, OtherAxes, NSets} AxisSet; 7 | typedef float *ConstraintSet; 8 | typedef struct { 9 | HVect center; 10 | float radius; 11 | Quat qNow, qDown, qDrag; 12 | HVect vNow, vDown, vFrom, vTo, vrFrom, vrTo; 13 | HMatrix mNow, mDown; 14 | Bool showResult, dragging; 15 | ConstraintSet sets[NSets]; 16 | int setSizes[NSets]; 17 | AxisSet axisSet; 18 | int axisIndex; 19 | } BallData; 20 | 21 | /* Public routines */ 22 | void Ball_Init(BallData *ball); 23 | void Ball_Place(BallData *ball, HVect center, float radius); 24 | void Ball_Mouse(BallData *ball, HVect vNow); 25 | void Ball_UseSet(BallData *ball, AxisSet axisSet); 26 | void Ball_ShowResult(BallData *ball); 27 | void Ball_HideResult(BallData *ball); 28 | void Ball_Update(BallData *ball); 29 | void Ball_Value(BallData *ball, HMatrix mNow); 30 | void Ball_BeginDrag(BallData *ball); 31 | void Ball_EndDrag(BallData *ball); 32 | void Ball_Draw(BallData *ball); 33 | /* Private routines */ 34 | void DrawAnyArc(HVect vFrom, HVect vTo); 35 | void DrawHalfArc(HVect n); 36 | void Ball_DrawConstraints(BallData *ball); 37 | void Ball_DrawDragArc(BallData *ball); 38 | void Ball_DrawResultArc(BallData *ball); 39 | #endif 40 | -------------------------------------------------------------------------------- /gemsiv/arcball/BallAux.h: -------------------------------------------------------------------------------- 1 | /***** BallAux.h - Vector and quaternion routines for Arcball. *****/ 2 | #ifndef _H_BallAux 3 | #define _H_BallAux 4 | 5 | typedef int Bool; 6 | typedef struct {float x, y, z, w;} Quat; 7 | enum QuatPart {X, Y, Z, W, QuatLen}; 8 | typedef Quat HVect; 9 | typedef float HMatrix[QuatLen][QuatLen]; 10 | 11 | extern Quat qOne; 12 | HMatrix *Qt_ToMatrix(Quat q, HMatrix* out); 13 | Quat Qt_Conj(Quat q); 14 | Quat Qt_Mul(Quat qL, Quat qR); 15 | HVect V3_(float x, float y, float z); 16 | float V3_Norm(HVect v); 17 | HVect V3_Unit(HVect v); 18 | HVect V3_Scale(HVect v, float s); 19 | HVect V3_Negate(HVect v); 20 | HVect V3_Sub(HVect v1, HVect v2); 21 | float V3_Dot(HVect v1, HVect v2); 22 | HVect V3_Cross(HVect v1, HVect v2); 23 | HVect V3_Bisect(HVect v0, HVect v1); 24 | #endif 25 | -------------------------------------------------------------------------------- /gemsiv/arcball/BallMath.h: -------------------------------------------------------------------------------- 1 | /***** BallMath.h - Essential routines for Arcball. *****/ 2 | #ifndef _H_BallMath 3 | #define _H_BallMath 4 | #include "BallAux.h" 5 | 6 | HVect MouseOnSphere(HVect mouse, HVect ballCenter, float ballRadius); 7 | HVect ConstrainToAxis(HVect loose, HVect axis); 8 | int NearestConstraintAxis(HVect loose, HVect *axes, int nAxes); 9 | Quat Qt_FromBallPoints(HVect from, HVect to); 10 | void Qt_ToBallPoints(Quat q, HVect *arcFrom, HVect *arcTo); 11 | #endif 12 | -------------------------------------------------------------------------------- /gemsiv/arcball/Body.h: -------------------------------------------------------------------------------- 1 | /**** Body.h ****/ 2 | #ifndef _H_Body 3 | #define _H_Body 4 | //#include 5 | typedef float Matrix[4][4]; 6 | void drawbody(Matrix Rot); 7 | #endif 8 | -------------------------------------------------------------------------------- /gemsiv/arcball/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(arcball Ball.c Ball.h BallAux.c BallAux.h BallMath.c BallMath.h Body.c Body.h Demo.c) 2 | if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") 3 | target_link_libraries(arcball FakeIrisGL m) 4 | else() 5 | target_link_libraries(arcball FakeIrisGL) 6 | endif() 7 | 8 | -------------------------------------------------------------------------------- /gemsiv/arcball/Makefile: -------------------------------------------------------------------------------- 1 | Demo: Demo.o Body.o Ball.o BallMath.o BallAux.o 2 | cc -o Demo Demo.o Body.o Ball.o BallMath.o BallAux.o -lgl_s -lm 3 | 4 | clean: 5 | rm -f *.o Demo 6 | -------------------------------------------------------------------------------- /gemsiv/arcball/README: -------------------------------------------------------------------------------- 1 | ANSI C code from the article 2 | "Arcball Rotation Control" 3 | by Ken Shoemake, shoemake@graphics.cis.upenn.edu 4 | in "Graphics Gems IV", Academic Press, 1994 5 | 6 | "Demo.c" is an interactive SGI program for Arcball. 7 | Much of the rest of the code is portable to other machines. 8 | -------------------------------------------------------------------------------- /gemsiv/centroid.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ANSI C code from the article 3 | * "Centroid of a Polygon" 4 | * by Gerard Bashein and Paul R. Detmer, 5 | (gb@locke.hs.washington.edu, pdetmer@u.washington.edu) 6 | * in "Graphics Gems IV", Academic Press, 1994 7 | */ 8 | 9 | /********************************************************************* 10 | polyCentroid: Calculates the centroid (xCentroid, yCentroid) and area 11 | of a polygon, given its vertices (x[0], y[0]) ... (x[n-1], y[n-1]). It 12 | is assumed that the contour is closed, i.e., that the vertex following 13 | (x[n-1], y[n-1]) is (x[0], y[0]). The algebraic sign of the area is 14 | positive for counterclockwise ordering of vertices in x-y plane; 15 | otherwise negative. 16 | 17 | Returned values: 0 for normal execution; 1 if the polygon is 18 | degenerate (number of vertices < 3); and 2 if area = 0 (and the 19 | centroid is undefined). 20 | **********************************************************************/ 21 | int polyCentroid(double x[], double y[], int n, 22 | double *xCentroid, double *yCentroid, double *area) 23 | { 24 | register int i, j; 25 | double ai, atmp = 0, xtmp = 0, ytmp = 0; 26 | if (n < 3) return 1; 27 | for (i = n-1, j = 0; j < n; i = j, j++) 28 | { 29 | ai = x[i] * y[j] - x[j] * y[i]; 30 | atmp += ai; 31 | xtmp += (x[j] + x[i]) * ai; 32 | ytmp += (y[j] + y[i]) * ai; 33 | } 34 | *area = atmp / 2; 35 | if (atmp != 0) 36 | { 37 | *xCentroid = xtmp / (3 * atmp); 38 | *yCentroid = ytmp / (3 * atmp); 39 | return 0; 40 | } 41 | return 2; 42 | } 43 | -------------------------------------------------------------------------------- /gemsiv/convex_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(convex_test convex.c convex_opt.c) 2 | 3 | -------------------------------------------------------------------------------- /gemsiv/curve_isect/Bezier.h: -------------------------------------------------------------------------------- 1 | #ifndef _BEZIER_INCLUDED_ 2 | #include "vector.h" 3 | class Bezier { 4 | public: 5 | point *p0, *p1, *p2, *p3; 6 | Bezier() 7 | { 8 | p0 = 0; p1 = 0; p2 = 0; p3 = 0; 9 | } 10 | Bezier( point *_p0, point *_p1, point *_p2, point *_p3 ) 11 | { 12 | p0 = _p0; p1 = _p1; p2 = _p2; p3 = _p3; 13 | } 14 | Bezier * Split( ); 15 | void ParameterSplitLeft( double t, Bezier &result ); 16 | 17 | // Intersect with another curve. Return two 10-elt arrays. Array 0 18 | // contains fragments of self. Array 1 contains fragments of other curve. 19 | // Fragments continue until one with nil pointers pointing at point data. 20 | Bezier **Intersect( Bezier B ); 21 | ~Bezier() 22 | { 23 | if( --p0->refcount <= 0 ) delete p0; 24 | if( --p1->refcount <= 0 ) delete p1; 25 | if( --p2->refcount <= 0 ) delete p2; 26 | if( --p3->refcount <= 0 ) delete p3; 27 | } 28 | }; 29 | #define _BEZIER_INCLUDED_ 30 | #endif 31 | -------------------------------------------------------------------------------- /gemsiv/curve_isect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(curve_isect Bezier.cc Bezier.h test.cc vector.h) 2 | 3 | -------------------------------------------------------------------------------- /gemsiv/curve_isect/README: -------------------------------------------------------------------------------- 1 | C++ code from the article 2 | "Intersecting Parametric Cubic Curves by Midpoint Subdivision" 3 | by R. Victor Klassen, klassen.wbst128@xerox.com 4 | in "Graphics Gems IV", Academic Press, 1994 5 | 6 | files: 7 | Bezier.cc - C++ source for cubic Bezier curve intersection 8 | Bezier.h - header file for " 9 | makefile 10 | test.cc - test program that prints out Postscript of curve intersection 11 | testout.ps - color Postscript output of test program 12 | vector.h - floating point vector library 13 | -------------------------------------------------------------------------------- /gemsiv/curve_isect/makefile: -------------------------------------------------------------------------------- 1 | test: Bezier.cc Bezier.h vector.h test.cc 2 | CC Bezier.cc test.cc -o test -lm 3 | ./test | diff - testout.ps 4 | -------------------------------------------------------------------------------- /gemsiv/data_smooth/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(data_smooth smooth1.c smooth2.c smooth3.c) 2 | 3 | -------------------------------------------------------------------------------- /gemsiv/data_smooth/README: -------------------------------------------------------------------------------- 1 | ANSI C code from the article 2 | "Smoothing and Interpolation with Finite Differences" 3 | by Paul H. C. Eilers, paul@dcmr.nl 4 | in "Graphics Gems IV", Academic Press, 1994 5 | 6 | files: 7 | smooth1.c: Smoothing and interpolation with first differences. 8 | smooth2.c: Smoothing and interpolation with second differences. 9 | smooth3.c: Smoothing and interpolation with any difference equation. 10 | -------------------------------------------------------------------------------- /gemsiv/data_smooth/smooth1.c: -------------------------------------------------------------------------------- 1 | /* Program 1. Smoothing and interpolation with first differences. */ 2 | /* Contribution to Graphic Gems IV */ 3 | 4 | /* Paul H. C. Eilers, DCMR Milieudienst Rijnmond, 's-Gravelandseweg 565, 5 | 3119 XT Schiedam, The Netherlands, E-Mail: paul@dcmr.nl */ 6 | 7 | #define MMAX 100 /* choose the right length for your application */ 8 | 9 | typedef float vec[MMAX + 1]; 10 | 11 | void smooth1(vec w, vec y, vec z, float lambda, int m) 12 | /* Smoothing and interpolation with first differences. 13 | Input: weights (w), data (y): vector from 1 to m. 14 | Input: smoothing parameter (lambda), length (m). 15 | Output: smoothed vector (z): vector from 1 to m. */ 16 | { 17 | int i, i1; 18 | vec c, d; 19 | d[1] = w[1] + lambda; 20 | c[1] = -lambda / d[1]; 21 | z[1] = w[1] * y[1]; 22 | for (i = 2; i < m; i++) { 23 | i1 = i - 1; 24 | d[i]= w[i] + 2 * lambda - c[i1] * c[i1] * d[i1]; 25 | c[i] = -lambda / d[i]; 26 | z[i] = w[i] * y[i] - c[i1] * z[i1]; 27 | } 28 | d[m] = w[m] + lambda - c[m - 1] * c[m - 1] * d[m - 1]; 29 | z[m] = (w[m] * y[m] - c[m - 1] * z[m - 1]) / d[m]; 30 | for (i = m - 1; 1 <= i; i--) z[i] = z[i] / d[i] - c[i] * z[i + 1]; 31 | } 32 | -------------------------------------------------------------------------------- /gemsiv/delaunay/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(delaunay geom2d.h quadedge.C quadedge.h test.C) 2 | target_link_libraries(delaunay FakeIrisGL) 3 | 4 | -------------------------------------------------------------------------------- /gemsiv/delaunay/Makefile: -------------------------------------------------------------------------------- 1 | delaunay: test.o quadedge.o 2 | CC -o delaunay test.o quadedge.o -lgl_s -lX11 -lm 3 | 4 | test.o: geom2d.h quadedge.h test.C 5 | CC -I. -c test.C 6 | 7 | quadedge.o: geom2d.h quadedge.h quadedge.C 8 | CC -I. -c quadedge.C 9 | -------------------------------------------------------------------------------- /gemsiv/delaunay/README: -------------------------------------------------------------------------------- 1 | C++ code from the article 2 | "Incremental Delaunay Triangulation" 3 | by Dani Lischinski, danix@graphics.cornell.edu 4 | in "Graphics Gems IV", Academic Press, 1994 5 | 6 | 7 | test.C contains an interactive test program for Delaunay triangulation. 8 | The program should compile and run on SGI workstations. 9 | Use left-mouse to add new points. 10 | 11 | The rest of the code is more portable (not limited to SGIs). 12 | -------------------------------------------------------------------------------- /gemsiv/dist_fast.c: -------------------------------------------------------------------------------- 1 | /* 2 | * C code from the article 3 | * "Fast Linear Approximations of Euclidean Distance in Higher Dimensions" 4 | * by Yoshikazu Ohashi, yoshi@cognex.com 5 | * in "Graphics Gems IV", Academic Press, 1994 6 | */ 7 | 8 | 9 | /* 10 | * 2-D Euclidean distance approximation 11 | * c1 = 123/128, c2 = 51 /128 and max(e) = 4.0 % 12 | * 13 | */ 14 | 15 | int veclen2 (ix,iy) 16 | int ix,iy; 17 | { 18 | int t; 19 | 20 | ix= (ix<0 ? -ix : ix); /* absolute values */ 21 | iy= (iy<0 ? -iy : iy); 22 | 23 | if(ix>1); 31 | 32 | return (ix - (ix>>5) - (ix>>7) + (t>>2) + (t>>6)); 33 | } 34 | 35 | /* 36 | * 3-D Euclidean distance approximation 37 | * c1 = 15/16 , c2 = c3 = 3/8 and max(e) = 7.7 % 38 | * 39 | */ 40 | 41 | int veclen3 (ix,iy,iz) 42 | int ix,iy,iz; 43 | { 44 | int t; 45 | 46 | ix= (ix<0 ? -ix : ix); /* absolute values */ 47 | iy= (iy<0 ? -iy : iy); 48 | iz= (iz<0 ? -iz : iz); 49 | 50 | if(ix>4) + (t>>2) + (t>>3)); 68 | 69 | } 70 | -------------------------------------------------------------------------------- /gemsiv/dyn_range/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(dyn_range hdp.c hdp.h test_hdp.c) 2 | 3 | -------------------------------------------------------------------------------- /gemsiv/dyn_range/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | 3 | test_hdp: test_hdp.o hdp.o 4 | $(CC) -o test_hdp test_hdp.o hdp.o 5 | 6 | clean: 7 | rm -f *.o test_hdp 8 | -------------------------------------------------------------------------------- /gemsiv/dyn_range/README: -------------------------------------------------------------------------------- 1 | C code from the article 2 | "High Dynamic Range Pixels" 3 | by Christophe Schlick, schlick@labri.u-bordeaux.fr 4 | in "Graphics Gems IV", Academic Press, 1994 5 | 6 | files: 7 | Makefile 8 | hdp.c - C source file 9 | hdp.h - header file 10 | test_hdp.c - test program 11 | -------------------------------------------------------------------------------- /gemsiv/dyn_range/hdp.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** HDP.H : Encoding and Decoding of High Dynamic Range Pixels 3 | */ 4 | 5 | /* 6 | ** Encoding and Decoding Types 7 | */ 8 | typedef unsigned char byte; 9 | typedef float real; /* change to "double" if you work with double precision */ 10 | 11 | typedef byte bytecolor[3]; 12 | typedef real realcolor[3]; 13 | 14 | /* 15 | ** Encoding and Decoding Tables 16 | */ 17 | extern byte *EncodeLut; 18 | extern real *DecodeLut; 19 | extern real LutScale; 20 | 21 | /* 22 | ** Encoding and Decoding Functions 23 | */ 24 | extern int init_HDP_encode (real,real,int); 25 | extern int init_HDP_decode (real,real,real); 26 | extern void exit_HDP_encode (void); 27 | extern void exit_HDP_decode (void); 28 | 29 | /* 30 | ** Encoding and Decoding Macros 31 | */ 32 | #define HDP_ENCODE(RealColor,ByteColor) ( \ 33 | ByteColor[0] = EncodeLut [(int) (RealColor[0] * LutScale + 0.5)], \ 34 | ByteColor[1] = EncodeLut [(int) (RealColor[1] * LutScale + 0.5)], \ 35 | ByteColor[2] = EncodeLut [(int) (RealColor[2] * LutScale + 0.5)]) 36 | 37 | #define HDP_DECODE(ByteColor,RealColor) ( \ 38 | RealColor[0] = DecodeLut [ByteColor[0]], \ 39 | RealColor[1] = DecodeLut [ByteColor[1]], \ 40 | RealColor[2] = DecodeLut [ByteColor[2]]) 41 | -------------------------------------------------------------------------------- /gemsiv/dyn_range/test_hdp.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** TEST_HDP.C : Simple testing program for the HDP routines 3 | */ 4 | 5 | #include 6 | 7 | #include "hdp.h" 8 | 9 | int main (void) 10 | { 11 | realcolor RealColor; 12 | bytecolor ByteColor; 13 | real LoVal, HiVal, Bright; 14 | int Index, NbTst, NbVal; 15 | 16 | /* Dynamic range of 4000 (try also larger or smaller values) */ 17 | LoVal = 0.25; 18 | HiVal = 1000.0; 19 | 20 | /* Memory for encoding LUT = 8 Kbytes */ 21 | NbVal = 8192; 22 | 23 | /* Construction of the encoding LUT */ 24 | init_HDP_encode (LoVal, HiVal, NbVal); 25 | 26 | /* No brightness modification (try also negative and positive values) */ 27 | Bright = 0.0; 28 | 29 | /* Construction of the decoding LUT */ 30 | init_HDP_decode (LoVal, HiVal, Bright); 31 | 32 | /* 33 | Test NbTst sample values (ranging from 0 to HiVal) 34 | before and after a coding/decoding sequence 35 | */ 36 | NbTst = (int)(HiVal / LoVal); 37 | for (Index = 0; Index <= NbTst; Index++) { 38 | RealColor[0] = RealColor[1] = RealColor[2] = Index * HiVal / NbTst; 39 | printf ("Before = %.2f\t", RealColor[0]); 40 | HDP_ENCODE (RealColor, ByteColor); 41 | printf ("Coded value = %d\t", ByteColor[0]); 42 | HDP_DECODE (ByteColor, RealColor); 43 | printf ("After = %.2f\n", RealColor[0]); 44 | } 45 | 46 | /* Destruction of the look-up tables */ 47 | exit_HDP_encode (); 48 | exit_HDP_decode (); 49 | } 50 | -------------------------------------------------------------------------------- /gemsiv/euler_angle/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(euler_angle EulerAngles.c EulerAngles.h EulerSample.c QuatTypes.h) 2 | if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") 3 | target_link_libraries(euler_angle m) 4 | endif() 5 | 6 | -------------------------------------------------------------------------------- /gemsiv/euler_angle/EulerSample.c: -------------------------------------------------------------------------------- 1 | /* EulerSample.c - Read angles as quantum mechanics, write as aerospace */ 2 | #include 3 | #include "EulerAngles.h" 4 | int main(void) 5 | { 6 | EulerAngles outAngs, inAngs = {0,0,0,EulOrdXYXr}; 7 | HMatrix R; 8 | printf("Phi Theta Psi (radians): "); 9 | scanf("%f %f %f",&inAngs.x,&inAngs.y,&inAngs.z); 10 | Eul_ToHMatrix(inAngs, R); 11 | outAngs = Eul_FromHMatrix(R, EulOrdXYZs); 12 | printf(" Roll Pitch Yaw (radians)\n"); 13 | printf("%6.3f %6.3f %6.3f\n", outAngs.x, outAngs.y, outAngs.z); 14 | } 15 | -------------------------------------------------------------------------------- /gemsiv/euler_angle/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | 3 | EulerSample: EulerSample.o EulerAngles.o 4 | $(CC) -o EulerSample EulerSample.o EulerAngles.o -lm 5 | 6 | clean: 7 | rm -f *.o EulerSample 8 | 9 | EulerAngles.o: EulerAngles.h QuatTypes.h 10 | EulerSample.o: EulerAngles.h QuatTypes.h 11 | -------------------------------------------------------------------------------- /gemsiv/euler_angle/QuatTypes.h: -------------------------------------------------------------------------------- 1 | /**** QuatTypes.h - Basic type declarations ****/ 2 | #ifndef _H_QuatTypes 3 | #define _H_QuatTypes 4 | /*** Definitions ***/ 5 | typedef struct {float x, y, z, w;} Quat; /* Quaternion */ 6 | enum QuatPart {X, Y, Z, W}; 7 | typedef float HMatrix[4][4]; /* Right-handed, for column vectors */ 8 | typedef Quat EulerAngles; /* (x,y,z)=ang 1,2,3, w=order code */ 9 | #endif 10 | -------------------------------------------------------------------------------- /gemsiv/euler_angle/README: -------------------------------------------------------------------------------- 1 | ANSI C code from the article 2 | "Euler Angle Conversion" 3 | by Ken Shoemake, shoemake@graphics.cis.upenn.edu 4 | in "Graphics Gems IV", Academic Press, 1994 5 | -------------------------------------------------------------------------------- /gemsiv/graph_layout/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(graph_layout defines.h fileio.C layout.C graph.C vector.C) 2 | 3 | -------------------------------------------------------------------------------- /gemsiv/graph_layout/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # makefile to build program graph layout 3 | # 4 | 5 | .C.o: 6 | $(CC) -c $(CFLAGS) $< 7 | 8 | # 9 | # Define Objects 10 | # 11 | OBJS= window.o graph.o layout.o vector.o fileio.o 12 | 13 | # 14 | # define build flags 15 | # 16 | CC = gcc 17 | INCLUDES= -I/usr/include/X11R4 18 | CFLAGS = -g $(INCLUDES) 19 | LDFLAGS= -L/usr/lib/X11R4 20 | LIBS= -lX11 -lm 21 | 22 | # 23 | # Dependencies 24 | # 25 | all : graph 26 | 27 | window.o: window.C window.hxx 28 | 29 | graph.o: graph.C window.hxx vector.hxx defines.h graph.hxx 30 | 31 | layout.o: layout.C window.hxx vector.hxx defines.h graph.hxx 32 | 33 | vector.o: vector.C vector.hxx 34 | 35 | fileio.o: fileio.C window.hxx vector.hxx defines.h graph.hxx fileio.hxx 36 | 37 | graph: $(OBJS) 38 | $(CC) $(LDFLAGS) $(OBJS) $(LIBS) -o $@ 39 | -------------------------------------------------------------------------------- /gemsiv/graph_layout/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** TEST FILE FOR graph (Dynamic Layout Alg) 3 | ** 4 | ** HEADER - DEFINITION OF CONSTANTS 5 | ** 6 | ** Author: dr. Szirmay-Kalos Laszlo (szirmay@fsz.bme.hu) 7 | ** Technical University of Budapest, Hungary 8 | *****************************************************************************/ 9 | /* 10 | * DEFINITION OF OBJECT WINDOW PARAMETERS 11 | */ 12 | #define OVERWINDOW_X 1000.0 13 | #define OVERWINDOW_Y 1000.0 14 | #define WALL_MARGIN (OVERWINDOW_X / 10.0) 15 | 16 | /* 17 | * MAXIMAL ALLOWABLE RELATION OF TWO NODES 18 | */ 19 | #define MAXRELATION 10.0 20 | /* 21 | * RETURN OF THE LAYOUT ALGORITHM 22 | */ 23 | #define STOPPED 0 24 | #define INSTABLE 1 25 | #define TOO_LONG 2 26 | 27 | /* 28 | * TYPE OF NODES 29 | */ 30 | #define MOVEABLE_NODE 0 31 | #define FIXED_NODE 1 32 | 33 | #define ALL_NODES -1 34 | 35 | /* 36 | * LOOK OF NODES 37 | */ 38 | #define NODESIZE_X 30 39 | #define NODESIZE_Y 30 40 | 41 | /* 42 | * MAXIMAL SIZE OF STRINGS 43 | */ 44 | #define MAXNAME 10 45 | #define MAXSTRING 10 46 | 47 | /* 48 | * RETURN OF SEARCH FUNCTIONS 49 | */ 50 | #define EMPTY_LIST 0 51 | #define FIRST_FOUND 1 52 | #define FOUND 2 53 | #define NOT_FOUND 3 54 | -------------------------------------------------------------------------------- /gemsiv/graph_layout/fileio.hxx: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | ** TEST FILE FOR graph (Dynamic Layout Alg) 3 | ** 4 | ** HEADER - BUFFERED FILE INPUT WITH SYNTAX CHECK 5 | ** AND NOT BUFFERED FILE OUTPUT 6 | ** 7 | ** Author: dr. Szirmay-Kalos Laszlo (szirmay@fsz.bme.hu) 8 | ** Technical University of Budapest, Hungary 9 | *****************************************************************************/ 10 | 11 | #ifdef MSWINDOWS 12 | #include "graph.hxx" 13 | #else 14 | #include "graph.hxx" 15 | #endif 16 | 17 | #define BUFFERSIZE 2048 18 | #define MAXLINE 80 19 | 20 | 21 | class FileIO { 22 | FILE * file; // file descriptor 23 | char operation[4]; // operation for open 24 | int line_count; // number of inputed lines 25 | char s[MAXLINE + 1]; // last string 26 | int buffpt; // buffer indes 27 | int nbytes; // number of valid bytes in buffer 28 | char buffer[BUFFERSIZE]; // io buffer 29 | protected: 30 | BOOL Get( pchar ); // get char and advance 31 | void UnGet( void ) { buffpt--; } // unget last char 32 | public: 33 | FileIO(const char * op ) { strcpy( operation, op ); } 34 | BOOL OpenFile ( cpchar ); // open file having that name 35 | BOOL GetString ( pchar, int ); // get a string from the file 36 | BOOL GetKeyWord ( cpchar ); // get a string and compare to a key 37 | BOOL GetKeyAgain ( cpchar ); // get last string again and compare 38 | BOOL GetVariable ( double *, double, double ); // get a double variable 39 | BOOL GetOperator ( char ); // get a char and compare to the given char 40 | int GetLineNum ( void ) { return line_count; } 41 | BOOL PutString ( cpchar ); // write string to the file 42 | void CloseFile ( void ); // close file 43 | }; 44 | -------------------------------------------------------------------------------- /gemsiv/graph_layout/g.dat: -------------------------------------------------------------------------------- 1 | # 2 | # DEMO RELATION GROUP - I am a comment 3 | # 4 | 5 | # 6 | # DECLARATIONS OF NODES 7 | # 8 | NAME = n1 POSITION = 764.2 216.0 TYPE = FIXED 9 | NAME = n2 POSITION = 131.3 858.6 TYPE = FIXED 10 | NAME = n3 TYPE = MOVEABLE # POSITION = x,y is optional 11 | NAME = n4 TYPE = MOVEABLE 12 | NAME = n5 TYPE = MOVEABLE 13 | NAME = n6 TYPE = MOVEABLE 14 | NAME = n7 TYPE = MOVEABLE 15 | NAME = n8 TYPE = MOVEABLE 16 | NAME = n9 POSITION = 688.0 587.1 TYPE = MOVEABLE 17 | 18 | # 19 | # DECLARATIONS OF RELATIONS 20 | # 21 | RELATIONS OF n1 NODE 22 | RELATION r17 : RELATED TO n7 WITH INTENSITY 3.000000 23 | END 24 | 25 | RELATIONS OF n2 NODE 26 | RELATION r26 : RELATED TO n6 WITH INTENSITY 2.000000 27 | END 28 | 29 | RELATIONS OF n3 NODE 30 | RELATION r31 : RELATED TO n1 WITH INTENSITY 6.000000 31 | END 32 | 33 | RELATIONS OF n4 NODE 34 | RELATION r42 : RELATED TO n2 WITH INTENSITY 4.000000 35 | RELATION r46 : RELATED TO n6 WITH INTENSITY 1.000000 36 | END 37 | 38 | RELATIONS OF n5 NODE 39 | RELATION r53 : RELATED TO n3 WITH INTENSITY 3.000000 40 | # 41 | # * relation name means no name 42 | # 43 | RELATION * : RELATED TO n8 WITH INTENSITY 3.000000 44 | RELATION * : RELATED TO n6 WITH INTENSITY 1.000000 45 | RELATION * : RELATED TO n4 WITH INTENSITY 3.000000 46 | END 47 | 48 | RELATIONS OF n7 NODE # empty relation is also allowed 49 | END 50 | 51 | RELATIONS OF n9 NODE 52 | # 53 | # * relation name means no name 54 | # 55 | RELATION * : RELATED TO n8 WITH INTENSITY 3.000000 56 | END 57 | -------------------------------------------------------------------------------- /gemsiv/graph_layout/graph.mak: -------------------------------------------------------------------------------- 1 | .AUTODEPEND 2 | 3 | .PATH.obj = . 4 | 5 | # *Translator Definitions* 6 | CC = bcc -v -W -vi- -wpro -weas -wpre -n. -I$(INCLUDEPATH) -L$(LIBPATH) 7 | TASM = TASM 8 | TLIB = tlib 9 | TLINK = tlink 10 | LIBPATH = C:\BORLANDC\LIB 11 | INCLUDEPATH = C:\BORLANDC\INCLUDE 12 | 13 | 14 | # *Implicit Rules* 15 | .cpp.obj: 16 | $(CC) -c -DMSWINDOWS {$< } 17 | 18 | # *List Macros* 19 | 20 | OBJS = fileio.obj layout.obj graph.obj mswindow.obj vector.obj 21 | 22 | # *Explicit Rules* 23 | graph: $(OBJS) 24 | $(TLINK) /v/x/c/P-/Twe/L$(LIBPATH) @&&| 25 | c0ws.obj+ 26 | fileio.obj+ 27 | layout.obj+ 28 | graph.obj+ 29 | mswindow.obj+ 30 | vector.obj 31 | graph 32 | # no map file 33 | mathws.lib+ 34 | import.lib+ 35 | cws.lib 36 | 37 | | 38 | RC .\graph.exe 39 | 40 | 41 | # *Individual File Dependencies* 42 | mswindow.obj: mswindow.cpp 43 | 44 | fileio.obj: fileio.cpp mswindow.hxx vector.hxx defines.h graph.hxx fileio.hxx 45 | 46 | graph.obj: graph.cpp mswindow.hxx vector.hxx defines.h graph.hxx 47 | 48 | layout.obj: layout.cpp mswindow.hxx vector.hxx defines.h graph.hxx 49 | 50 | vector.obj: vector.cpp vector.hxx 51 | 52 | -------------------------------------------------------------------------------- /gemsiv/graph_layout/mswin.gen: -------------------------------------------------------------------------------- 1 | mkdir $1 2 | cp defines.h $1/defines.h 3 | cp layout.C $1/layout.cpp 4 | cp fileio.C $1/fileio.cpp 5 | cp graph.C $1/graph.cpp 6 | cp mswindow.C $1/mswindow.cpp 7 | cp fileio.hxx $1/fileio.hxx 8 | cp graph.hxx $1/graph.hxx 9 | cp vector.C $1/vector.cpp 10 | cp mswindow.hxx $1/mswindow.hxx 11 | cp vector.hxx $1/vector.hxx 12 | cp g.dat $1/g.dat 13 | cp g20.dat $1/g20.dat 14 | cp README $1/README 15 | cp graph.mak $1/graph.mak 16 | echo "files are generated in directory:" $1 17 | -------------------------------------------------------------------------------- /gemsiv/graph_layout/vector.hxx: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** TEST FILE FOR graph (Dynamic Layout Alg) 3 | ** 4 | ** HEADER - 2D VECTOR OPERATIONS 5 | ** 6 | ** Author: dr. Szirmay-Kalos Laszlo (szirmay@fsz.bme.hu) 7 | ** Technical University of Budapest, Hungary 8 | *****************************************************************************/ 9 | /* 10 | * VECTOR - 2D GEOMETRIC VECTOR TYPE 11 | */ 12 | class vector { 13 | double x; // coordinates 14 | double y; 15 | public: 16 | vector() { x = 0.0; y = 0.0; } 17 | vector(double x0, double y0) { x = x0; y = y0; } 18 | void operator=(const vector& a) { x = a.x; y = a.y; } 19 | void operator+=(const vector& a) { x += a.x; y += a.y; } 20 | void operator/=(double d) { if (d != 0.0) {x /= d; y /= d;}} 21 | void operator*=(double d) { x *= d; y *= d; } 22 | double X() { return x; } 23 | double Y() { return y; } 24 | double Size(); 25 | 26 | // FRIENDS 27 | friend vector operator+(const vector&, const vector&); 28 | friend vector operator-(const vector&, const vector&); 29 | friend vector operator-(vector&); 30 | friend vector operator*(double, const vector&); 31 | friend vector operator*(double, vector&); 32 | }; 33 | -------------------------------------------------------------------------------- /gemsiv/minray/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(minray ray.h minray.c) 2 | if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") 3 | target_link_libraries(minray m) 4 | endif() 5 | 6 | -------------------------------------------------------------------------------- /gemsiv/minray/README: -------------------------------------------------------------------------------- 1 | C code from the article 2 | "A Minimal Ray Tracer" 3 | by Paul S. Heckbert, ph@cs.cmu.edu 4 | in "Graphics Gems IV", Academic Press, 1994 5 | 6 | files: 7 | README - this file 8 | minray.c - "readable" minimal ray tracer 9 | minray.card.c - minimal ray tracer for business card 10 | ray.h - header file for test scene 11 | minray.ps - John Hartman's postscript ray tracer 12 | (on UNIX, run "gs" or "lpr" on it) 13 | 14 | minray.post - messages posted to comp.graphics announcing contest 15 | and results. Contains three shell archives of 16 | all the contest entries. 17 | 18 | Note that there may be some tricks used in this code that are not 19 | portable to your machine! 20 | -------------------------------------------------------------------------------- /gemsiv/minray/minray.card.c: -------------------------------------------------------------------------------- 1 | typedef struct{double x,y,z}vec;vec U,black,amb={.02,.02,.02};struct sphere{ 2 | vec cen,color;double rad,kd,ks,kt,kl,ir}*s,*best,sph[]={0.,6.,.5,1.,1.,1.,.9, 3 | .05,.2,.85,0.,1.7,-1.,8.,-.5,1.,.5,.2,1.,.7,.3,0.,.05,1.2,1.,8.,-.5,.1,.8,.8, 4 | 1.,.3,.7,0.,0.,1.2,3.,-6.,15.,1.,.8,1.,7.,0.,0.,0.,.6,1.5,-3.,-3.,12.,.8,1., 5 | 1.,5.,0.,0.,0.,.5,1.5,};yx;double u,b,tmin,sqrt(),tan();double vdot(A,B)vec A 6 | ,B;{return A.x*B.x+A.y*B.y+A.z*B.z;}vec vcomb(a,A,B)double a;vec A,B;{B.x+=a* 7 | A.x;B.y+=a*A.y;B.z+=a*A.z;return B;}vec vunit(A)vec A;{return vcomb(1./sqrt( 8 | vdot(A,A)),A,black);}struct sphere*intersect(P,D)vec P,D;{best=0;tmin=1e30;s= 9 | sph+5;while(s-->sph)b=vdot(D,U=vcomb(-1.,P,s->cen)),u=b*b-vdot(U,U)+s->rad*s 10 | ->rad,u=u>0?sqrt(u):1e31,u=b-u>1e-7?b-u:b+u,tmin=u>=1e-7&&uir;d= -vdot(D,N=vunit(vcomb(-1.,P=vcomb(tmin,D,P),s->cen 14 | )));if(d<0)N=vcomb(-1.,N,black),eta=1/eta,d= -d;l=sph+5;while(l-->sph)if((e=l 15 | ->kl*vdot(N,U=vunit(vcomb(-1.,P,l->cen))))>0&&intersect(P,U)==l)color=vcomb(e 16 | ,l->color,color);U=s->color;color.x*=U.x;color.y*=U.y;color.z*=U.z;e=1-eta* 17 | eta*(1-d*d);return vcomb(s->kt,e>0?trace(level,P,vcomb(eta,D,vcomb(eta*d-sqrt 18 | (e),N,black))):black,vcomb(s->ks,trace(level,P,vcomb(2*d,N,D)),vcomb(s->kd, 19 | color,vcomb(s->kl,U,black))));}main(){printf("%d %d\n",32,32);while(yx<32*32) 20 | U.x=yx%32-32/2,U.z=32/2-yx++/32,U.y=32/2/tan(25/114.5915590261),U=vcomb(255., 21 | trace(3,black,vunit(U)),black),printf("%.0f %.0f %.0f\n",U);}/*minray!*/ 22 | -------------------------------------------------------------------------------- /gemsiv/minray/ray.h: -------------------------------------------------------------------------------- 1 | /* ray.h for test1, first test scene */ 2 | 3 | #pragma once 4 | 5 | #define DEPTH 3 /* max ray tree depth */ 6 | #define SIZE 32 /* resolution of picture in x and y */ 7 | #define AOV 25 /* total angle of view in degrees */ 8 | #define NSPHERE 5 /* number of spheres */ 9 | 10 | AMBIENT = { .02, .02, .02 }; /* ambient light color */ 11 | 12 | /* sphere: x y z r g b rad kd ks kt kl ir */ 13 | SPHERE = { 14 | {{0., 6., .5}, {1., 1., 1.}, .9, .05, .2, .85, 0., 1.7}, 15 | {{-1., 8., -.5}, {1., .5, .2}, 1., .7, .3, 0., .05, 1.2}, 16 | {{1., 8., -.5}}, {{.1, .8, .8}}, {{1., .3, .7}}, {{0., 0., 1.2}}, 17 | {{3., -6., 15.}}, {{1., .8, 1.}}, {{7., 0., 0.}}, {{0., .6, 1.5}}, 18 | {{-3., -3., 12.}}, {{.8, 1., 1.}}, {{5., 0., 0.}}, {{0., .5, 1.5}}, 19 | }; 20 | -------------------------------------------------------------------------------- /gemsiv/mrsfoley.im: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erich666/GraphicsGems/6bd96c311d77db5dc750e850167c76c5f45af4c1/gemsiv/mrsfoley.im -------------------------------------------------------------------------------- /gemsiv/multi_jitter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(multi_jitter multi.c test.c) 2 | 3 | -------------------------------------------------------------------------------- /gemsiv/multi_jitter/Makefile: -------------------------------------------------------------------------------- 1 | multi: 2 | gcc -o multi test.c multi.c -lm 3 | -------------------------------------------------------------------------------- /gemsiv/multi_jitter/README: -------------------------------------------------------------------------------- 1 | C code from the article 2 | "Multi-Jittered Sampling" 3 | by Kenneth Chiu, Peter Shirley, and Changyaw Wang, 4 | (chiuk@cs.indiana.edu, shirley@iuvax.cs.indiana.edu, 5 | and wangc@iuvax.cs.indiana.edu) 6 | in "Graphics Gems IV", Academic Press, 1994 7 | 8 | files: 9 | multi.c - source file 10 | Makefile - make file; creates executable called "multi" 11 | test.c - test program that performs consistency checks on 12 | the generated sampling pattern 13 | 14 | The makefile uses 'gcc' as the compiler, but any ANSI compatible compiler 15 | should do. 16 | 17 | To run the test program, give it three arguments. The first two are 18 | 'm' and 'n' (as described in the gem), and the last one is a seed 19 | to the random number generator. 20 | 21 | Kenneth Chiu 22 | -------------------------------------------------------------------------------- /gemsiv/nurb_polyg/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(nurb_polyg drawing.h nurbs.h FakeWindow.c Main.c NurbEval.c NurbRefine.c NurbSubdiv.c NurbUtils.c) 2 | if(CMAKE_COMPILER_IS_GNUCC) 3 | target_link_libraries(nurb_polyg GraphicsGems m) 4 | else() 5 | target_link_libraries(nurb_polyg GraphicsGems) 6 | endif() 7 | 8 | -------------------------------------------------------------------------------- /gemsiv/nurb_polyg/FakeWindow.c: -------------------------------------------------------------------------------- 1 | /* This is a fake version, used to test on other machines. */ 2 | 3 | #include 4 | 5 | extern void MakeWindow(void); 6 | 7 | void MakeWindow() 8 | {} 9 | 10 | extern void MoveTo( short, short ); 11 | extern void LineTo( short, short ); 12 | 13 | 14 | 15 | void LineTo( short x, short y ) 16 | { 17 | printf("L %3d, %3d\n", (int) x, (int) y ); 18 | } 19 | void MoveTo( short x, short y ) 20 | { 21 | printf("M %3d, %3d\n", (int) x, (int) y ); 22 | } 23 | -------------------------------------------------------------------------------- /gemsiv/nurb_polyg/README: -------------------------------------------------------------------------------- 1 | ANSI C code from the article 2 | "Tessellation of NURB Surfaces" 3 | by John W. Peterson, jp@blowfish.taligent.com 4 | in "Graphics Gems IV", Academic Press, 1994 5 | -------------------------------------------------------------------------------- /gemsiv/nurb_polyg/drawing.h: -------------------------------------------------------------------------------- 1 | /* 2 | * These routines need to be provided by your rendering package 3 | */ 4 | 5 | extern void FastTriangle( SurfSample *, SurfSample *, SurfSample * ); 6 | extern void SlowTriangle( SurfSample *, SurfSample *, SurfSample * ); 7 | 8 | extern void (*DrawTriangle)( SurfSample *, SurfSample *, SurfSample * ); 9 | 10 | extern void ScreenProject( Point4 *, Point3 * ); 11 | -------------------------------------------------------------------------------- /gemsiv/nurb_polyg/makefile: -------------------------------------------------------------------------------- 1 | OBJS = NurbRefine.o NurbSubdiv.o NurbUtils.o NurbEval.o GGVecLib.o Main.o \ 2 | FakeWindow.o 3 | 4 | nurb_polyg: $(OBJS) 5 | $(CC) -o $@ $(OBJS) -lm 6 | 7 | .c.o: 8 | $(CC) -c $< 9 | 10 | NurbRefine.c: nurbs.h GraphicsGems.h 11 | NurbSubdiv.c: nurbs.h drawing.h GraphicsGems.h 12 | NurbUtils.c: nurbs.h GraphicsGems.h 13 | NurbEval.c: nurbs.h GraphicsGems.h 14 | GGVecLib.c: GraphicsGems.h 15 | Main.c: nurbs.h drawing.h GraphicsGems.h 16 | -------------------------------------------------------------------------------- /gemsiv/outcode/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(outcode outcode2.c outcode4.c xf1.c xf2.c xf3.c xf4.c) 2 | add_executable(xcc2d xcc2d.c) 3 | target_link_libraries(xcc2d outcode) 4 | add_executable(xcc4d xcc4d.c) 5 | target_link_libraries(xcc4d outcode) 6 | 7 | -------------------------------------------------------------------------------- /gemsiv/outcode/README: -------------------------------------------------------------------------------- 1 | C code from the article 2 | "Direct Outcode Calculation for Faster Clip Testing" 3 | by Walt Donovan and Tim Van Hook, 4 | (donovan@eng.sun.com, tvh@sgi.com) 5 | in "Graphics Gems IV", Academic Press, 1994 6 | 7 | 8 | The files outcode2.c and outcode4.c are C code fragments for 2D and 9 | 4D outcode calculation that were extracted from the paper, which you 10 | can insert in your own code. 11 | 12 | 13 | The following test programs demonstrate the performance gains from using the 14 | direct outcode method. 15 | 16 | For a SuperSparc (SS10), we get the following figures: 17 | 18 | xcc2d1: ~27 clocks (would be faster with overlap) 19 | xcc2d2: ~40 clocks 20 | 21 | xcc4d1: ~54 clocks (the paper says 50, but that's with a 22 | more tightly written version than here) 23 | xcc4d2: ~94 clocks (ditto) 24 | 25 | All of the routines were run several times, and the lowest figure 26 | reported. 27 | 28 | -- walt donovan 29 | donovan@eng.sun.com 30 | -------------------------------------------------------------------------------- /gemsiv/outcode/outcode2.c: -------------------------------------------------------------------------------- 1 | /* Direct calculation of 2D outcodes, C code fragment */ 2 | 3 | /* number of bits in a word */ 4 | #define NUMBITS sizeof(long)*8 5 | 6 | /* get the integral form of a floating point number */ 7 | #define v(x) *(long *) &(x) 8 | 9 | /* get the sign bit of an integer as a value 0 or 1 */ 10 | #define s(x) (((unsigned long)(x)) >> (NUMBITS-1)) 11 | 12 | /* get the absolute value of a floating point number in integral form */ 13 | #define a(x) ((x) & ~((long)1 << (NUMBITS-1))) 14 | 15 | void test() { 16 | float x = 0.f, y = 0.f, xmin = 0.f, xmax = 0.f, ymin = 0.f, ymax = 0.f; 17 | long int iy, ixmin, ixmax, iymin, iymax, ix, ax, ay; 18 | unsigned long outcode; 19 | 20 | /* these values typically would be calculated once and cached */ 21 | ixmin = v(xmin); 22 | ixmax = v(xmax); 23 | iymin = v(ymin); 24 | iymax = v(ymax); 25 | 26 | /* get the bits and absolute value */ 27 | ix = v(x); ax = a(ix); 28 | /* put the sign bit in bit 0 */ 29 | outcode = s(ix | (ax - ixmin)); 30 | 31 | /* put the sign bit in bit 1 */ 32 | outcode |= s(~ix & (ixmax - ax)) << 1; 33 | 34 | /* do the same for y */ 35 | iy = v(y); 36 | ay = a(iy); 37 | outcode |= s(iy | (ay - iymin)) << 2; 38 | outcode |= s(~iy & (iymax - ay)) << 3; 39 | } 40 | -------------------------------------------------------------------------------- /gemsiv/outcode/outcode4.c: -------------------------------------------------------------------------------- 1 | /* Direct calculation of 4D outcodes, C code fragment */ 2 | 3 | /* number of bits in a word */ 4 | #define NUMBITS sizeof(long)*8 5 | 6 | /* get the integral form of a floating point number */ 7 | #define v(x) *(long *) &(x) 8 | 9 | /* get the sign bit of an integer as a value 0 or 1 */ 10 | #define s(x) (((unsigned long)(x)) >> (NUMBITS-1)) 11 | 12 | /* get the absolute value of a floating point number in integral form */ 13 | #define a(x) ((x) & ~((long)1 << (NUMBITS-1))) 14 | 15 | void test4() { 16 | 17 | long int iw = 0, ix = 0, iy = 0, iz = 0; 18 | float x = 0.f, y = 0.f, z = 0.f, w = 0.f; 19 | long abs_w; 20 | unsigned long outcode, diff, t; 21 | 22 | iw = v(w); 23 | abs_w = a(iw); 24 | outcode = s(iw); /* 0 or 1 per w's sign */ 25 | 26 | ix = v(x); 27 | diff = s(abs_w - a(ix)); 28 | t = s(ix) + 1; 29 | outcode |= diff << t; /* 0, 2, or 4 or'd with outcode */ 30 | 31 | iy = v(y); 32 | diff = s(abs_w - a(iy)); 33 | t = s(iy) + 3; 34 | outcode |= diff << t; /* 0, 8, or 16 or'd with outcode */ 35 | 36 | iz = v(z); 37 | diff = s(abs_w - a(iz)); 38 | t = s(iz) + 5; 39 | outcode |= diff << t; /* 0, 32, or 64 or'd with outcode */ 40 | } 41 | -------------------------------------------------------------------------------- /gemsiv/outcode/xf4.c: -------------------------------------------------------------------------------- 1 | /* 2D transform and clip test a vertex list */ 2 | 3 | /* oflo and division traps should be disabled, by the way */ 4 | 5 | #define FI(x) (*(int *)&x) 6 | 7 | /********************************************************/ 8 | void xform_ctp4(vc, vpi, vpo, visiz, vosiz, mtx, prj, pf, pa) 9 | int vc ; /* vertex count */ 10 | int visiz; /* input vertex array stride */ 11 | int vosiz; /* output vertex array stride */ 12 | int *pf; /* flag array */ 13 | int *pa; /* 2 element - global or_flag, and_flag */ 14 | float *vpi, *vpo, *mtx, *prj; 15 | { 16 | register int flag, flag_or, flag_and; 17 | 18 | /* flpt registers, total 32 */ 19 | register float xx, xy, xt; /* transformation matrix */ 20 | register float yx, yy, yt; 21 | register float xo, yo; /* output vertex */ 22 | register float xi, yi; /* temps */ 23 | 24 | /* load up local transform matrix */ 25 | xx = *(mtx+0 ); xy = *(mtx+1 ); xt = *(mtx+2 ); 26 | yx = *(mtx+4 ); yy = *(mtx+5 ); yt = *(mtx+6 ); 27 | 28 | /* initialize accumulated flags */ 29 | flag_or = 0; 30 | flag_and = -1; 31 | 32 | do { 33 | xi = vpi[0]; /* xi */ 34 | yi = vpi[1]; /* yi */ 35 | 36 | xo = xi * xx + yi * xy + xt; 37 | yo = xi * yx + yi * yy + yt; 38 | 39 | /* let's try branches for comparison purposes */ 40 | flag = 0; 41 | 42 | #define CXMIN 1 43 | #define CXMAX 2 44 | #define CYMIN 4 45 | #define CYMAX 8 46 | 47 | #define XMIN 0 48 | #define XMAX 1279 49 | #define YMIN 0 50 | #define YMAX 1023 51 | 52 | if (xo < XMIN) flag |= CXMIN; 53 | if (xo > XMAX) flag |= CXMAX; 54 | if (yo < YMIN) flag |= CYMIN; 55 | if (yo > YMAX) flag |= CYMAX; 56 | 57 | flag_or |= flag; 58 | flag_and &= flag; 59 | 60 | *(vpo+0) = xo; 61 | *(vpo+1) = yo; 62 | *pf = flag; 63 | 64 | vpi += visiz; 65 | vpo += vosiz; 66 | pf++; 67 | } while (--vc > 0); 68 | 69 | *(pa+0) = flag_or; 70 | *(pa+1) = flag_and; 71 | 72 | return; 73 | } 74 | -------------------------------------------------------------------------------- /gemsiv/polar_decomp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(polar_decomp Decompose.h Decompose.c) 2 | -------------------------------------------------------------------------------- /gemsiv/polar_decomp/Decompose.h: -------------------------------------------------------------------------------- 1 | /**** Decompose.h - Basic declarations ****/ 2 | #ifndef _H_Decompose 3 | #define _H_Decompose 4 | typedef struct {float x, y, z, w;} Quat; /* Quaternion */ 5 | enum QuatPart {X, Y, Z, W}; 6 | typedef Quat HVect; /* Homogeneous 3D vector */ 7 | typedef float HMatrix[4][4]; /* Right-handed, for column vectors */ 8 | typedef struct { 9 | HVect t; /* Translation components */ 10 | Quat q; /* Essential rotation */ 11 | Quat u; /* Stretch rotation */ 12 | HVect k; /* Stretch factors */ 13 | float f; /* Sign of determinant */ 14 | } AffineParts; 15 | float polar_decomp(HMatrix M, HMatrix Q, HMatrix S); 16 | HVect spect_decomp(HMatrix S, HMatrix U); 17 | Quat snuggle(Quat q, HVect *k); 18 | void decomp_affine(HMatrix A, AffineParts *parts); 19 | void invert_affine(AffineParts *parts, AffineParts *inverse); 20 | #endif 21 | -------------------------------------------------------------------------------- /gemsiv/polar_decomp/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | 3 | Decompose.o: Decompose.h 4 | -------------------------------------------------------------------------------- /gemsiv/polar_decomp/README: -------------------------------------------------------------------------------- 1 | ANSI C code from the article 2 | "Polar Matrix Decomposition" 3 | by Ken Shoemake, shoemake@graphics.cis.upenn.edu 4 | in "Graphics Gems IV", Academic Press, 1994 5 | -------------------------------------------------------------------------------- /gemsiv/ptpoly_haines/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(ptpoly_haines ptinpoly.h p_test.cpp ptinpoly.cpp) 2 | if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") 3 | target_link_libraries(ptpoly_haines FakeIrisGL m) 4 | else() 5 | target_link_libraries(ptpoly_haines FakeIrisGL) 6 | endif() 7 | 8 | -------------------------------------------------------------------------------- /gemsiv/ptpoly_haines/Makefile: -------------------------------------------------------------------------------- 1 | # Valid options: -DTIMER -DDISPLAY -DCONVEX -DHYBRID -DSORT -DRANDOM -DWINDING 2 | # You can define $MAKEOPTS outside the program for testing purposes. 3 | # 4 | # for testing purposes we leave all options off and invoke through $MAKEOPTS 5 | CCFLAGS=-O 6 | # good default if not testing: 7 | # CCFLAGS=-O -DTIMER -DDISPLAY -DSORT -DRANDOM 8 | 9 | 10 | # use this one for making one which will display the tests being done on an HP 11 | # and do: 12 | # export LDOPTS="-a shared" 13 | 14 | p_test: ptinpoly.o ptinpoly.h p_test.cpp 15 | cc -o p_test p_test.cpp $(CCFLAGS) $(MAKEOPTS) ptinpoly.o -lm 16 | # include these lines for linking in HP Starbase, for display version 17 | # -L /usr/lib/X11R4 \ 18 | # -lXwindow \ 19 | # -lsb \ 20 | # -lXhp11 -lX11 -ldld \ 21 | # -lm 22 | 23 | ptinpoly.o: ptinpoly.cpp ptinpoly.h 24 | cc -o ptinpoly.o -c ptinpoly.c $(CCFLAGS) $(MAKEOPTS) 25 | 26 | clean: 27 | rm -f ptinpoly.o p_test 28 | -------------------------------------------------------------------------------- /gemsiv/ptpoly_haines/README: -------------------------------------------------------------------------------- 1 | ANSI C code from the article 2 | "Point in Polygon Strategies" 3 | by Eric Haines, erich@eye.com 4 | in "Graphics Gems IV", Academic Press, 1994 5 | 6 | files: 7 | Makefile - makefile for code (probably needs updating) 8 | ptinpoly.h ptinpoly.cpp p_test.cpp - the distribution code 9 | statrun.tst - the basic set of tests run for the book 10 | table.awk - an awk processor for the output files from statrun.tst 11 | -------------------------------------------------------------------------------- /gemsiv/ptpoly_haines/point_in_poly.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29609.76 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "point_in_poly", "point_in_poly.vcxproj", "{B483A9BB-B602-4C4B-B5E3-333554186699}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {B483A9BB-B602-4C4B-B5E3-333554186699}.Debug|x64.ActiveCfg = Debug|x64 17 | {B483A9BB-B602-4C4B-B5E3-333554186699}.Debug|x64.Build.0 = Debug|x64 18 | {B483A9BB-B602-4C4B-B5E3-333554186699}.Debug|x86.ActiveCfg = Debug|Win32 19 | {B483A9BB-B602-4C4B-B5E3-333554186699}.Debug|x86.Build.0 = Debug|Win32 20 | {B483A9BB-B602-4C4B-B5E3-333554186699}.Release|x64.ActiveCfg = Release|x64 21 | {B483A9BB-B602-4C4B-B5E3-333554186699}.Release|x64.Build.0 = Release|x64 22 | {B483A9BB-B602-4C4B-B5E3-333554186699}.Release|x86.ActiveCfg = Release|Win32 23 | {B483A9BB-B602-4C4B-B5E3-333554186699}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {E98294B1-131F-48F2-90B2-D397B0E30957} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /gemsiv/ptpoly_haines/table.awk: -------------------------------------------------------------------------------- 1 | # Run results from statrun.tst through this script, e.g. 2 | # table.awk *.stats 3 | # to generate tables of timings 4 | 5 | for dog in $* 6 | do 7 | cat $dog | awk ' 8 | BEGIN { 9 | count = -1 10 | } 11 | { 12 | if ( $1 == "Polygons" ) { 13 | count++ 14 | if ( !count ) { 15 | title = $0 16 | title_on = 1 17 | } 18 | if ( $4 == "to" ) { 19 | nv[count] = $3"-"$5 20 | } else { 21 | nv[count] = $3 22 | } 23 | } else if ( title_on ) { 24 | if ( !count ) { 25 | if ( $1 == "Testing" ) { 26 | title_on = 0 27 | } else { 28 | title = title "\n" $0 29 | } 30 | } 31 | } else if ( $3 == "time:" ) { 32 | t[$1,count] = $4 33 | found[$1] = 1 34 | } else if ( $2 == "%" ) { 35 | pc[count] = $1 36 | } 37 | } 38 | END { 39 | print title 40 | 41 | printf( "\n\t\t Number of vertices\n\t" ) 42 | for ( i = 0 ; i <= count ; i++ ) { 43 | printf( "\t %s",nv[i] ) 44 | } 45 | printf( "\n\n" ) ; 46 | 47 | for ( name in found ) { 48 | printf( "%s\t", name ) 49 | if ( length( name ) < 8 ) { 50 | printf( "\t" ) 51 | } 52 | for ( i = 0 ; i <= count ; i++ ) { 53 | printf( "%8.1f",t[name,i] ) 54 | } 55 | printf( "\n" ) ; 56 | } 57 | 58 | printf( "\ninside %\t" ) 59 | for ( i = 0 ; i <= count ; i++ ) { 60 | printf( "%8.1f",pc[i] ) 61 | } 62 | printf( "\n\n\n" ) ; 63 | }' 64 | done 65 | -------------------------------------------------------------------------------- /gemsiv/ptpoly_weiler/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(ptpoly_weiler polygon.h pt_poly.c) 2 | -------------------------------------------------------------------------------- /gemsiv/ptpoly_weiler/polygon.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* polygon vertex definition */ 4 | typedef struct vertex_struct { 5 | double x,y; /* coordinate values */ 6 | struct vertex_struct *next; /* circular singly linked list from poly */ 7 | } vtx, *vtx_ptr; 8 | 9 | /* polygon definition */ 10 | typedef struct polygon_struct { 11 | vtx_ptr last; /* pointer to end of circular vertex list */ 12 | } polygon, *polygon_ptr; 13 | 14 | /* return next vertex in polygon list of vertices */ 15 | #define polygon_get_vertex(poly, vertex) \ 16 | ((vertex == NULL) ? poly->last->next : vertex->next) 17 | 18 | /* create and insert new polygon vertex */ 19 | #define polygon_new_vertex(vertex, poly, xx, yy, new_vertex) { \ 20 | new_vertex = (vtx_ptr) malloc (sizeof(vtx)); \ 21 | new_vertex->x = xx; \ 22 | new_vertex->y = yy; \ 23 | if (poly->last != NULL) { \ 24 | new_vertex->next = poly->last->next; \ 25 | poly->last->next = new_vertex; \ 26 | } \ 27 | else { \ 28 | new_vertex->next = new_vertex; \ 29 | } \ 30 | poly->last = new_vertex; \ 31 | } 32 | 33 | /* create new polygon */ 34 | #define polygon_create(poly) \ 35 | poly = (polygon_ptr) malloc(sizeof (polygon)); \ 36 | poly->last = NULL; 37 | -------------------------------------------------------------------------------- /gemsiv/vec_mat/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(vec_mat algebra3.h algebra3.cpp) 2 | add_subdirectory(ray) 3 | 4 | -------------------------------------------------------------------------------- /gemsiv/vec_mat/README: -------------------------------------------------------------------------------- 1 | C++ code from the article 2 | "C++ Vector and Matrix Algebra Routines" 3 | by Jean-Francois Doue, h058@frhec1.hec.fr 4 | in "Graphics Gems IV", Academic Press, 1994 5 | 6 | algebra3.[CH] - the subroutine library 7 | ray/ - subdirectory containing a ray caster built on this library 8 | -------------------------------------------------------------------------------- /gemsiv/vec_mat/ray/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(ray algebra3.h Camera.h Light.h Object3D.h Polyhedron.h Primitive.h Scene3D.h solver.h Sphere.h algebra3.cpp Camera.cpp Light.cpp main.cpp Object3D.cpp Polyhedron.cpp Primitive.cpp Scene3D.cpp solver.cpp Sphere.cpp) 2 | -------------------------------------------------------------------------------- /gemsiv/vec_mat/ray/Camera.cpp: -------------------------------------------------------------------------------- 1 | #include "Camera.h" 2 | 3 | /************************************************************************ 4 | * * 5 | * These methods set the field of view of the camera. They transform * 6 | * the field of view between a user representation (2 angles specified * 7 | * in degrees) an internal representation (the size of the film square). * 8 | * * 9 | ************************************************************************/ 10 | 11 | void Camera::setFieldOfView(vec2& v) 12 | { film_size = (v * (M_PI / 360.0)).apply(&tan); } 13 | 14 | vec2 Camera::fieldOfView() 15 | { return (360.0 * M_1_PI) * (vec2(film_size).apply(&atan)); } 16 | 17 | /************************************************************************ 18 | * * 19 | * This method transforms a 2D point located on the film plane into a * 20 | * normalized ray. The method only returns the direction of the ray. * 21 | * The origin can be found by asking the camera its position. * 22 | * * 23 | ************************************************************************/ 24 | 25 | vec3 Camera::pointToRay(vec2& p) 26 | { return orient * vec3(prod(film_size, p), -1.0).normalize(); } 27 | 28 | /************************************************************************ 29 | * * 30 | * Input from stream. * 31 | * * 32 | ************************************************************************/ 33 | 34 | std::istream& operator >> (std::istream& s, Camera& a) 35 | { 36 | vec2 fov; 37 | 38 | s >> *((Object3D*) &a); 39 | s >> fov; 40 | a.setFieldOfView(fov); 41 | return s; 42 | } 43 | -------------------------------------------------------------------------------- /gemsiv/vec_mat/ray/Camera.h: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * CLASS: Camera * 4 | * AUTHOR: Jean-Francois DOUE * 5 | * LAST MODIFICATION: 12 Oct 1993 * 6 | * * 7 | * This class implements a simple model of 3D camera. The camera can * 8 | * be positioned and rotated arbitrarily in space. Its focal length is * 9 | * always equal to 1. * 10 | * This camera is a simplified version of the model proposed by * 11 | * Foley, Van Dam, Feiner, Hughes in "Computer Graphics, Principles and * 12 | * Practice". The following diagram shows what conventions are used: * 13 | * * 14 | * * 15 | * y * 16 | * x | ^ * 17 | * \ | | * 18 | * \ | | y film_size target object * 19 | * \ | | ____ * 20 | * \| | / \ * 21 | * z <----+-----------| v | | * 22 | * <---- 1 ----> \____/ * 23 | * focal position * 24 | * point (PRP) (VRP) * 25 | * * 26 | * The field of view of the camera can be easily specified by passing * 27 | * the camera opening angles along the x and y axes (in degree). This * 28 | * system is similar to the one used in Renderman. * 29 | * * 30 | ************************************************************************/ 31 | 32 | #ifndef Camera_h 33 | #define Camera_h 1 34 | #include "Object3D.h" 35 | 36 | class Camera: public Object3D 37 | { 38 | protected: 39 | vec2 film_size; 40 | 41 | public: 42 | 43 | void setFieldOfView(vec2& v); 44 | vec2 fieldOfView(); 45 | vec3 pointToRay(vec2& p); 46 | 47 | // friends 48 | friend std::istream& operator >> (std::istream& s, Camera& a); 49 | }; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /gemsiv/vec_mat/ray/Light.cpp: -------------------------------------------------------------------------------- 1 | #include "Light.h" 2 | 3 | std::istream& operator >> (std::istream& s, Light& a) 4 | { 5 | s >> *((Object3D*) &a); 6 | s >> a.col; 7 | return s; 8 | } 9 | -------------------------------------------------------------------------------- /gemsiv/vec_mat/ray/Light.h: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * CLASS: Light * 4 | * AUTHOR: Jean-Francois DOUE * 5 | * LAST MODIFICATION: 12 Oct 1993 * 6 | * * 7 | * This class implements a simple point light source. * 8 | * It just contains the color of the light source. * 9 | * * 10 | ************************************************************************/ 11 | 12 | #ifndef Light_h 13 | #define Light_h 1 14 | #include "Object3D.h" 15 | 16 | class Light: public Object3D 17 | { 18 | protected: 19 | vec3 col; // color of the light source 20 | 21 | public: 22 | 23 | vec3 color() { return col; }; 24 | friend std::istream& operator >> (std::istream& s, Light& a); 25 | }; 26 | 27 | #endif -------------------------------------------------------------------------------- /gemsiv/vec_mat/ray/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # NeXT Makefile for test (a program to test the algebra3 C++ routines) 3 | # Requires libg++ and a c++ compiler. See README file 4 | # 5 | 6 | CC = cc++ 7 | CFLAGS = -g -I/usr/local/lib/g++-include -L/usr/local/lib 8 | LIBS = -lg++ 9 | OBJS = algebra3.o Camera.o Light.o Object3D.o Polyhedron.o Primitive.o \ 10 | Scene3D.o solver.o Sphere.o main.o 11 | 12 | .c.o: 13 | $(CC) -c $@ $(CFLAGS) $*.c 14 | ray: $(OBJS) 15 | $(CC) -o $@ $(CFLAGS) $(OBJS) $(LIBS) 16 | -------------------------------------------------------------------------------- /gemsiv/vec_mat/ray/Object3D.cpp: -------------------------------------------------------------------------------- 1 | #include "Object3D.h" 2 | 3 | /************************************************************************ 4 | * * 5 | * Input from stream. * 6 | * * 7 | ************************************************************************/ 8 | 9 | std::istream& operator >> (std::istream& s, Object3D& a) 10 | { 11 | s >> a.pos; 12 | s >> a.orient; 13 | return s; 14 | } 15 | -------------------------------------------------------------------------------- /gemsiv/vec_mat/ray/Object3D.h: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * CLASS: Object3D * 4 | * AUTHOR: Jean-Francois DOUE * 5 | * LAST MODIFICATION: 12 Oct 1993 * 6 | * * 7 | * This class is an abstract root class for all the 3D objects. * 8 | * It stores the position an the orientation of the object * 9 | * * 10 | ************************************************************************/ 11 | 12 | #ifndef Object3D_h 13 | #define Object3D_h 1 14 | #include "algebra3.h" 15 | 16 | class Object3D 17 | { 18 | protected: 19 | vec3 pos; 20 | mat4 orient; 21 | 22 | public: 23 | 24 | void setPosition(vec3& p) { pos = p; }; 25 | vec3 position() { return pos; }; 26 | void setOrientation(mat4& o) { orient = o; }; 27 | mat4 orientation() { return orient; }; 28 | 29 | // friends 30 | friend std::istream& operator >> (std::istream& s, Object3D& a); 31 | }; 32 | 33 | #endif -------------------------------------------------------------------------------- /gemsiv/vec_mat/ray/Polyhedron.h: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * CLASS: Polyhedron * 4 | * AUTHOR: Jean-Francois DOUE * 5 | * LAST MODIFICATION: 12 Oct 1993 * 6 | * * 7 | * This class implements a 3D concave polyhedron. * 8 | * The polyhedron is defined by the following elements: * 9 | * + an array which contains the its vertices (vList). * 10 | * + an array of "facets" (iList). Each facet is itself defined as an * 11 | * array of integer. The first one is the number of points composing * 12 | * the facet. The other ones are the indices of these vertices in the * 13 | * vList array. * 14 | * + an array of dimension 4 vectors, which stores the equations of the * 15 | * planes on which the facets lie. * 16 | * * 17 | ************************************************************************/ 18 | 19 | #ifndef Polyhedron_h 20 | #define Polyhedron_h 1 21 | #include "Primitive.h" 22 | 23 | class Polyhedron : public Primitive 24 | { 25 | protected: 26 | vec3 *vList; // vertices of the polyhedron 27 | vec4 *pList; // equations for the planes supporting the facets 28 | int vertexN, // number of vertices of the polyhedron 29 | facetN, // number of facets of the polyhedron 30 | **iList; // lists of the vertex indices which define the facets 31 | 32 | public: 33 | 34 | // Constructors and destructors 35 | ~Polyhedron(); 36 | 37 | // virtual methods 38 | double intersect(const vec3& ray_org, const vec3& ray_dir); 39 | vec3 normalAt(const vec3& p); 40 | 41 | // friends 42 | friend std::istream& operator >> (std::istream& s, Polyhedron& a); 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /gemsiv/vec_mat/ray/Primitive.cpp: -------------------------------------------------------------------------------- 1 | #include "Primitive.h" 2 | 3 | Primitive::~Primitive(){}; 4 | 5 | /************************************************************************ 6 | * * 7 | * This method receives as parameter a list of intersections and the * 8 | * number of intersections in the list. It scans the list and returns * 9 | * the closest positive intersection, or 0.0 if no such intersection * 10 | * exists. * 11 | * * 12 | ************************************************************************/ 13 | 14 | double Primitive::closest_intersection(double *x, int x_num) 15 | { 16 | int i; 17 | double x_min = (x_num) ? x[0] : 0.0; 18 | 19 | for (i=1; i> (std::istream& s, Primitive& a) 32 | { 33 | s >> *((Object3D*) &a); 34 | s >> a.col; 35 | s >> a.ph; 36 | return s; 37 | } 38 | -------------------------------------------------------------------------------- /gemsiv/vec_mat/ray/Primitive.h: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * CLASS: Primitive * 4 | * AUTHOR: Jean-Francois DOUE * 5 | * LAST MODIFICATION: 12 Oct 1993 * 6 | * * 7 | * This class is an abstract class which defines the basic methods * 8 | * to which every ray-traceable object (primitive) will have to respond. * 9 | * It also stores the color and the phong coefficients of the primitive * 10 | * * 11 | ************************************************************************/ 12 | 13 | #ifndef Primitive_h 14 | #define Primitive_h 1 15 | #include "Object3D.h" 16 | 17 | class Primitive: public Object3D 18 | { 19 | protected: 20 | vec3 col; // color of the primitive 21 | vec4 ph; // phong coefficients of the object 22 | 23 | public: 24 | 25 | vec3 color() { return col; }; 26 | double phong(int i) { return ph[i]; }; 27 | double closest_intersection(double *x, int x_num); 28 | 29 | // virtual methods 30 | virtual ~Primitive(); 31 | virtual double intersect(const vec3& ray_org, const vec3& ray_dir) = 0; 32 | virtual vec3 normalAt(const vec3& p) = 0; 33 | 34 | // friends 35 | friend std::istream& operator >> (std::istream& s, Primitive& a); 36 | }; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /gemsiv/vec_mat/ray/Scene3D.h: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * CLASS: Scene3D * 4 | * AUTHOR: Jean-Francois DOUE * 5 | * LAST MODIFICATION: 12 Oct 1993 * 6 | * * 7 | * This class implements a 3D scene. * 8 | * The scene is composed of a camera, a collection of light sources * 9 | * and a collection of primitives to render. * 10 | * The scene is capable of ray-tracing itself. * 11 | * Scenes are typically parsed from a text file description. (see the * 12 | * README file for a description of the format). * 13 | * * 14 | ************************************************************************/ 15 | 16 | #include "Camera.h" 17 | #include "Light.h" 18 | #include "Primitive.h" 19 | 20 | class Scene3D 21 | { 22 | protected: 23 | Camera *camera; // a camera 24 | Light **lList; // a list of point lights 25 | Primitive **pList; // a list of primitives 26 | int lightN, // number of light sources in the list 27 | primitiveN; // number of primitives in the scene 28 | public: 29 | Scene3D(); 30 | ~Scene3D(); 31 | char* rayTrace(vec2 res); 32 | 33 | // friends 34 | friend std::istream& operator >> (std::istream& s, Scene3D& a); 35 | }; 36 | -------------------------------------------------------------------------------- /gemsiv/vec_mat/ray/Sphere.cpp: -------------------------------------------------------------------------------- 1 | #include "Sphere.h" 2 | #include "solver.h" 3 | 4 | /************************************************************************ 5 | * * 6 | * This method computes the intersection between a ray and the sphere. * 7 | * It returns the distance between the origin of the ray and the closest * 8 | * point of intersection (or 0.0 if no intersection occurs). * 9 | * * 10 | ************************************************************************/ 11 | 12 | double Sphere::intersect(const vec3& ray_org, const vec3& ray_dir) 13 | { 14 | double c[3], // coefficients of the quadric equation. 15 | s[2]; // solutions of the quadric equation 16 | vec3 d = ray_org - pos; // vector from the center of the sphere to 17 | // the origin of the ray. 18 | 19 | // compute the coefficients of the resolvent equation 20 | c[2] = 1.0; 21 | c[1] = 2.0 * ray_dir * d; 22 | c[0] = d * d - radius * radius; 23 | 24 | // return the closest intersection point 25 | return closest_intersection(s, solveQuadric(c, s)); 26 | } 27 | 28 | /************************************************************************ 29 | * * 30 | * This method computes the normal vector to the sphere at the point of * 31 | * intersection. (NB: normalization is "built-in" for the sphere). * 32 | * * 33 | ************************************************************************/ 34 | 35 | vec3 Sphere::normalAt(const vec3& p) 36 | { return (p - pos) / radius; } 37 | 38 | /************************************************************************ 39 | * * 40 | * Input from stream. * 41 | * * 42 | ************************************************************************/ 43 | 44 | std::istream& operator >> (std::istream& s, Sphere& a) 45 | { 46 | s >> *((Primitive*) &a); 47 | s >> a.radius; 48 | return s; 49 | } 50 | -------------------------------------------------------------------------------- /gemsiv/vec_mat/ray/Sphere.h: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * CLASS: Sphere * 4 | * AUTHOR: Jean-Francois DOUE * 5 | * LAST MODIFICATION: 12 Oct 1993 * 6 | * * 7 | * This class implements a sphere. * 8 | * * 9 | ************************************************************************/ 10 | 11 | #ifndef Sphere_h 12 | #define Sphere_h 1 13 | #include "Primitive.h" 14 | 15 | class Sphere : public Primitive 16 | { 17 | protected: 18 | double radius; 19 | 20 | public: 21 | 22 | // virtual methods 23 | double intersect(const vec3& ray_org, const vec3& ray_dir); 24 | vec3 normalAt(const vec3& p); 25 | 26 | // friends 27 | friend std::istream& operator >> (std::istream& s, Sphere& a); 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /gemsiv/vec_mat/ray/example.data: -------------------------------------------------------------------------------- 1 | % 2 | % Camera placement 3 | % 4 | 5 | Camera 6 | | 2.146539 2.827176 3.467622 | 7 | 8 | | 0.851829 -0.294472 0.433212 0.000000 | 9 | | 0.000000 0.827026 0.562164 0.000000 | 10 | | -0.523819 -0.478868 0.704485 0.000000 | 11 | | 0.000000 0.000000 0.000000 1.000000 | 12 | 13 | | 57.509806 57.509806 | 14 | 15 | 16 | % 17 | % Light sources 18 | % 19 | 20 | Light 21 | | 0.0 0.5 4.0 | 22 | | 1.0 0.0 0.0 0.0 | 23 | | 0.0 1.0 0.0 0.0 | 24 | | 0.0 0.0 1.0 0.0 | 25 | | 0.0 0.0 0.0 1.0 | 26 | | 0.5 0.5 0.5 | 27 | 28 | Light 29 | | 3.08 0.0 0.0 | 30 | | 1.0 0.0 0.0 0.0 | 31 | | 0.0 1.0 0.0 0.0 | 32 | | 0.0 0.0 1.0 0.0 | 33 | | 0.0 0.0 0.0 1.0 | 34 | | 0.5 0.5 0.5 | 35 | 36 | Light 37 | | 3.08 3.35 5.55 | 38 | | 1.0 0.0 0.0 0.0 | 39 | | 0.0 1.0 0.0 0.0 | 40 | | 0.0 0.0 1.0 0.0 | 41 | | 0.0 0.0 0.0 1.0 | 42 | | 1.0 1.0 1.0 | 43 | 44 | 45 | % 46 | % Description of the objects 47 | % 48 | 49 | Polyhedron 50 | | 0.0 0.0 0.0 | 51 | | 1.0 0.0 0.0 0.0 | 52 | | 0.0 1.0 0.0 0.0 | 53 | | 0.0 0.0 1.0 0.0 | 54 | | 0.0 0.0 0.0 1.0 | 55 | | 1.0 1.0 1.0 | 56 | | 0.1 0.48 0.7 20.0 | 57 | 10 58 | | -1.0 -1.0 -1.0 | 59 | | 1.0 -1.0 -1.0 | 60 | | 1.0 1.0 -1.0 | 61 | | -1.0 1.0 -1.0 | 62 | | -1.0 -1.0 1.0 | 63 | | 1.0 -1.0 1.0 | 64 | | 1.0 1.0 1.0 | 65 | | -1.0 1.0 1.0 | 66 | | 0.0 1.8 -1.0 | 67 | | 0.0 1.8 1.0 | 68 | 7 69 | 5 0 3 8 2 1 70 | 5 4 5 6 9 7 71 | 4 0 1 5 4 72 | 4 1 2 6 5 73 | 4 2 8 9 6 74 | 4 3 7 9 8 75 | 4 0 4 7 3 76 | 77 | Sphere 78 | | 1.0 -0.2 1.0 | 79 | | 1.0 0.0 0.0 0.0 | 80 | | 0.0 1.0 0.0 0.0 | 81 | | 0.0 0.0 1.0 0.0 | 82 | | 0.0 0.0 0.0 1.0 | 83 | | 1.0 1.0 1.0 | 84 | | 0.1 0.48 0.7 20.0 | 85 | 0.8 86 | 87 | -------------------------------------------------------------------------------- /gemsiv/vec_mat/ray/example.tiff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erich666/GraphicsGems/6bd96c311d77db5dc750e850167c76c5f45af4c1/gemsiv/vec_mat/ray/example.tiff -------------------------------------------------------------------------------- /gemsiv/vec_mat/ray/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Scene3D.h" 3 | 4 | int main(int, char**) 5 | { 6 | char script[1024], 7 | *image; 8 | Scene3D scene; 9 | vec2 res; 10 | 11 | std::cout << "\nSimple Ray-Tracer v1.0\nby Jean-Francois Doue\n\nenter a script name:"; 12 | std::cin >> script; 13 | std::ifstream s(script, std::ios::in); 14 | s >> scene; 15 | std::cout << "\nResolution of the rendering (x y):"; 16 | std::cin >> res; 17 | image = scene.rayTrace(res); 18 | 19 | // put some code here to save the image in your preferred format 20 | 21 | delete image; 22 | return 1; 23 | } -------------------------------------------------------------------------------- /gemsiv/vec_mat/ray/solver.h: -------------------------------------------------------------------------------- 1 | /**************************************************************** 2 | * * 3 | * Polynomial root finder (polynoms up to degree 4) * 4 | * AUTHOR: Jochen SCHARZE (See 'Cubic & Quartic Roots' in * 5 | * 'Graphics Gems 1', AP) * 6 | * * 7 | ****************************************************************/ 8 | 9 | #include 10 | #define EQN_EPS 1e-9 11 | 12 | int isZero(double x); 13 | int solveQuadric(double c[3], double s[2]); 14 | int solveCubic(double c[4], double s[3]); 15 | int solveQuartic(double c[5], double s[4]); 16 | -------------------------------------------------------------------------------- /gemsiv/vert_norm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_definitions(-DSTANDALONE_TEST) 2 | add_executable(vert_norm smooth.h smooth.c test.c) 3 | if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") 4 | target_link_libraries(vert_norm m) 5 | endif() 6 | 7 | -------------------------------------------------------------------------------- /gemsiv/vert_norm/Makefile: -------------------------------------------------------------------------------- 1 | CC = cc 2 | CFLAGS = -I/usr/ph/include -DSTANDALONE_TEST 3 | 4 | test: test.o smooth.o 5 | $(CC) -o test test.o smooth.o -lm 6 | 7 | clean: 8 | rm -f *.o test 9 | 10 | smooth.o: smooth.h 11 | test.o: smooth.h 12 | -------------------------------------------------------------------------------- /gemsiv/vox_traverse.c: -------------------------------------------------------------------------------- 1 | /* 2 | * C code from the article 3 | * "Voxel Traversal along a 3D Line" 4 | * by Daniel Cohen, danny@bengus.bgu.ac.il 5 | * in "Graphics Gems IV", Academic Press, 1994 6 | */ 7 | 8 | /* The following C subroutine visits all voxels along the line 9 | segment from (x, y, z) and (x + dx, y + dy, z + dz) */ 10 | 11 | #include 12 | #include 13 | 14 | int sgn(int x) { 15 | return (x > 0) - (x < 0); 16 | } 17 | 18 | void VisitVoxel(int x, int y, int z) {} 19 | 20 | void Line (int x, int y, int z, int dx, int dy, int dz) 21 | { 22 | int n, sx, sy, sz, exy, exz, ezy, ax, ay, az, bx, by, bz; 23 | 24 | sx = sgn(dx); sy = sgn(dy); sz = sgn(dz); 25 | ax = abs(dx); ay = abs(dy); az = abs(dz); 26 | bx = 2*ax; by = 2*ay; bz = 2*az; 27 | exy = ay-ax; exz = az-ax; ezy = ay-az; 28 | n = ax+ay+az; 29 | while ( n-- ) { 30 | VisitVoxel ( x, y, z ); 31 | if ( exy < 0 ) { 32 | if ( exz < 0 ) { 33 | x += sx; 34 | exy += by; exz += bz; 35 | } 36 | else { 37 | z += sz; 38 | exz -= bx; ezy += by; 39 | } 40 | } 41 | else { 42 | if ( ezy < 0 ) { 43 | z += sz; 44 | exz -= bx; ezy += by; 45 | } 46 | else { 47 | y += sy; 48 | exy -= bx; ezy -= bz; 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /gemsv/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(ch1-1) 2 | add_subdirectory(ch1-2) 3 | add_subdirectory(ch1-3) 4 | add_subdirectory(ch1-4) 5 | add_subdirectory(ch2-2) 6 | add_subdirectory(ch2-6) 7 | add_subdirectory(ch2-7) 8 | add_subdirectory(ch3-3) 9 | add_subdirectory(ch3-4) 10 | add_subdirectory(ch3-5) 11 | add_subdirectory(ch3-6) 12 | add_subdirectory(ch4-3) 13 | add_subdirectory(ch4-4) 14 | add_subdirectory(ch4-5) 15 | add_subdirectory(ch4-7) 16 | add_subdirectory(ch4-8) 17 | add_subdirectory(ch4-9) 18 | add_subdirectory(ch5-2) 19 | add_subdirectory(ch5-3) 20 | add_subdirectory(ch5-4) 21 | add_subdirectory(ch5-5) 22 | add_subdirectory(ch6-2) 23 | add_subdirectory(ch6-3) 24 | add_subdirectory(ch6-4) 25 | add_subdirectory(ch6-5) 26 | add_subdirectory(ch6-7) 27 | add_subdirectory(ch7-1) 28 | add_subdirectory(ch7-2) 29 | add_subdirectory(ch7-3) 30 | add_subdirectory(ch7-4) 31 | add_subdirectory(ch7-5) 32 | add_subdirectory(ch7-6) 33 | add_subdirectory(ch7-7) 34 | 35 | set_property(TARGET 36 | quarcube invsqrt fixsqrt rat rev conmat len4 tricubic xcoord bsp5 axd 37 | arcdivid aspc ellipsoid bezlen qbezier lincrv quad rayscan poly oopov 38 | halfadap pclipper vectorize revfit sampat wave pcube collide5 partition 39 | triangulation ZRendv10 xs11 tga cg4d gm vec_h 40 | 41 | oopov_show 42 | 43 | PROPERTY FOLDER "GraphicsGems V") 44 | -------------------------------------------------------------------------------- /gemsv/ch1-1/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(quarcube quarcube.c) 2 | 3 | -------------------------------------------------------------------------------- /gemsv/ch1-2/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(invsqrt invsqrt.c) 2 | 3 | -------------------------------------------------------------------------------- /gemsv/ch1-3/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(fixsqrt fixsqrt.c) 2 | -------------------------------------------------------------------------------- /gemsv/ch1-3/fixsqrt.c: -------------------------------------------------------------------------------- 1 | /* The definitions below yield 2 integer bits, 30 fractional bits */ 2 | #define FRACBITS 30 /* Must be even! */ 3 | #define ITERS (15 + (FRACBITS >> 1)) 4 | typedef long TFract; 5 | 6 | TFract 7 | FFracSqrt(TFract x) 8 | { 9 | register unsigned long root, remHi, remLo, testDiv, count; 10 | 11 | root = 0; /* Clear root */ 12 | remHi = 0; /* Clear high part of partial remainder */ 13 | remLo = x; /* Get argument into low part of partial remainder */ 14 | count = ITERS; /* Load loop counter */ 15 | 16 | do { 17 | remHi = (remHi << 2) | (remLo >> 30); remLo <<= 2; /* get 2 bits of arg */ 18 | root <<= 1; /* Get ready for the next bit in the root */ 19 | testDiv = (root << 1) + 1; /* Test radical */ 20 | if (remHi >= testDiv) { 21 | remHi -= testDiv; 22 | root += 1; 23 | } 24 | } while (count-- != 0); 25 | 26 | return(root); 27 | } 28 | -------------------------------------------------------------------------------- /gemsv/ch1-4/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(rat rat.c) 2 | -------------------------------------------------------------------------------- /gemsv/ch1-4/rat.h: -------------------------------------------------------------------------------- 1 | /****** rat.h ******/ 2 | /* Ken Shoemake, 1994 */ 3 | 4 | #ifndef _H_rat 5 | #define _H_rat 6 | 7 | #include 8 | typedef int BOOL; 9 | #define TRUE 1 10 | #define FALSE 0 11 | #define BITS (32-1) 12 | #if (INT_MAX>=2147483647) 13 | typedef int INT32; 14 | typedef unsigned int UINT32; 15 | #else 16 | typedef long INT32; 17 | typedef unsigned long UINT32; 18 | #endif 19 | typedef struct {INT32 numer,denom;} Rational; 20 | 21 | Rational ratapprox(float x, INT32 limit); 22 | #endif 23 | -------------------------------------------------------------------------------- /gemsv/ch2-2/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(rev rev.c ptinply3.c) 2 | -------------------------------------------------------------------------------- /gemsv/ch2-2/rev.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Revisions to Spherical Polygon Area (GG vol.IV entry II.4 [page 136]) 3 | * as described in GG vol.V entry II.2 (page 45, bottom; 46, top). 4 | */ 5 | 6 | /* OLD */ 7 | /* if (Lam2 < Lam1) Excess = - Excess; */ 8 | 9 | /* NEW */ 10 | #if 0 11 | double Lam; 12 | Lam = (Lam2 - Lam1 > 0) ? Lam2 - Lam1 : Lam2 - Lam1 + 4*HalfPi; 13 | if (Lam > 2*HalfPi) Excess= -Excess; 14 | #endif 15 | -------------------------------------------------------------------------------- /gemsv/ch2-6/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(conmat conmat.c) 2 | -------------------------------------------------------------------------------- /gemsv/ch2-7/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(len4 len4.c testlen4.c) 2 | -------------------------------------------------------------------------------- /gemsv/ch2-7/testlen4.c: -------------------------------------------------------------------------------- 1 | /* 2 | * testlen4.c - len4 exerciser 3 | * 4 | * % cc -g testlen4.c len4.c -lm -o testlen4 5 | * % ./testlen4 2 1 1 1 6 | * % ./testlen4 60000000 25000000 19000000 16000000 7 | */ 8 | 9 | #include 10 | #include /* for atoi() */ 11 | #include 12 | 13 | long int len4(long int a, long int b, long int c, long int d); 14 | 15 | int main(int argc, char** argv) 16 | { 17 | long a, b, c, d, l; 18 | double l2; 19 | a = atoi(argv[1]); 20 | b = atoi(argv[2]); 21 | c = atoi(argv[3]); 22 | d = atoi(argv[4]); 23 | l = len4(a,b,c,d); 24 | l2 = hypot(hypot((double)(a),(double)(b)), 25 | hypot((double)(c),(double)(d))); 26 | printf("(%ld,%ld,%ld,%ld) = %ld (%g)\n", a, b, c, d, l, l/l2); 27 | } 28 | -------------------------------------------------------------------------------- /gemsv/ch3-3/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(tricubic tricubic.c) 2 | -------------------------------------------------------------------------------- /gemsv/ch3-4/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(xcoord xcoord.c) 2 | -------------------------------------------------------------------------------- /gemsv/ch3-5/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(bsp5 bspAlloc.c bspCollide.c bspMemory.c bspPartition.c bspTree.c bspUtility.c mainBsp.c) 2 | -------------------------------------------------------------------------------- /gemsv/ch3-5/README: -------------------------------------------------------------------------------- 1 | # Instructions for making/compiling the BSP-tree code 2 | # as appearing throughout "A Walk Through BSP Trees", 3 | # in _Graphics Gems V_, pages 121-138. 4 | 5 | $ rm *.o 6 | $ make -f bsp.make 7 | $ bsp foo.dat 8 | -------------------------------------------------------------------------------- /gemsv/ch3-5/bsp.make: -------------------------------------------------------------------------------- 1 | # bsp.make 2 | # 3 | HEADERS = bsp.h GraphicsGems.h 4 | OBJS = bspAlloc.o bspCollide.o bspPartition.o \ 5 | bspTree.o bspUtility.o mainBsp.o bspMemory.o 6 | 7 | OPT = -g 8 | LIBS = -lm 9 | BSP = bsp 10 | # ANSI-C: Use CC on Suns. Use cc -Aa on HPs. 11 | CC = CC 12 | 13 | $(BSP) : $(OBJS) 14 | $(CC) $(OPT) $(OBJS) $(LIBS) -o $(BSP) 15 | 16 | bspAlloc.o : $(HEADERS) bspAlloc.c 17 | $(CC) $(OPT) -c bspAlloc.c 18 | bspCollide.o : $(HEADERS) bspCollide.c 19 | $(CC) $(OPT) -c bspCollide.c 20 | bspPartition.o : $(HEADERS) bspPartition.c 21 | $(CC) $(OPT) -c bspPartition.c 22 | bspTree.o : $(HEADERS) bspTree.c 23 | $(CC) $(OPT) -c bspTree.c 24 | bspUtility.o : $(HEADERS) bspUtility.c 25 | $(CC) $(OPT) -c bspUtility.c 26 | bspMemory.o : $(HEADERS) bspMemory.c 27 | $(CC) $(OPT) -c bspMemory.c 28 | mainBsp.o : $(HEADERS) mainBsp.c 29 | $(CC) $(OPT) -c mainBsp.c 30 | # bsp.make 31 | -------------------------------------------------------------------------------- /gemsv/ch3-5/bspMemory.c: -------------------------------------------------------------------------------- 1 | /* bspMemory.c: module to allocate and free memory and also to count them. 2 | * Copyright (c) Norman Chin 3 | */ 4 | #include "bsp.h" 5 | #include 6 | 7 | static long memoryCount= 0L; 8 | 9 | /* Allocates memory of num bytes */ 10 | char *MYMALLOC(unsigned num) 11 | { 12 | char *memory= malloc(num); /* checked for null by caller */ 13 | 14 | ++memoryCount; /* increment memory counter for debugging */ 15 | return(memory); 16 | } /* myMalloc() */ 17 | 18 | /* Frees memory pointed to by ptr */ 19 | void MYFREE(char *ptr) 20 | { 21 | --memoryCount; /* decrement memory counter for debugging */ 22 | free(ptr); 23 | } /* myFree() */ 24 | 25 | /* Returns how many memory blocks are still allocated up to this point */ 26 | long MYMEMORYCOUNT(void) 27 | { 28 | return(memoryCount); 29 | } /* myMemoryCount() */ 30 | 31 | /*** bspMemory.c ***/ 32 | 33 | -------------------------------------------------------------------------------- /gemsv/ch3-5/foo.dat: -------------------------------------------------------------------------------- 1 | ;this is a comment 2 | f 0.0 1.0 0.0 3 | v 2.250000 0.000000 -2.000000 4 | v 4.250000 0.000000 -2.000000 5 | v 4.250000 7.000000 -2.000000 6 | v 2.250000 7.000000 -2.000000 7 | ; 8 | f 0.0 1.0 0.0 9 | v 4.250000 0.000000 -2.000000 10 | v 4.250000 0.000000 -4.000000 11 | v 4.250000 7.000000 -4.000000 12 | v 4.250000 7.000000 -2.000000 13 | ; 14 | f 0.0 1.0 0.0 15 | v 4.250000 0.000000 -4.000000 16 | v 2.250000 0.000000 -4.000000 17 | v 2.250000 7.000000 -4.000000 18 | v 4.250000 7.000000 -4.000000 19 | ; 20 | f 0.0 1.0 0.0 21 | v 2.250000 0.000000 -4.000000 22 | v 2.250000 0.000000 -2.000000 23 | v 2.250000 7.000000 -2.000000 24 | v 2.250000 7.000000 -4.000000 25 | ; 26 | f 0.0 1.0 0.0 27 | v 2.250000 7.000000 -2.000000 28 | v 4.250000 7.000000 -2.000000 29 | v 4.250000 7.000000 -4.000000 30 | v 2.250000 7.000000 -4.000000 31 | ;white floor 32 | f 1.0 1.0 1.0 33 | v -12.000000 0.000000 9.000000 34 | v 9.000000 0.000000 9.000000 35 | v 9.000000 0.000000 -9.000000 36 | v -12.000000 0.000000 -9.000000 37 | -------------------------------------------------------------------------------- /gemsv/ch3-6/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(axd axd.c ) 2 | -------------------------------------------------------------------------------- /gemsv/ch3-6/README: -------------------------------------------------------------------------------- 1 | NOTE: These routines use the include files found in 2 | ../ch7-7/mactbox/real.h 3 | ../ch7-7/mactbox/mat.h 4 | -------------------------------------------------------------------------------- /gemsv/ch3-6/axd.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- *\ 2 | AXD.H : 3 | 4 | This package provides an implementation of 6 different algorithms 5 | for doing procedural axial deformations. 6 | 7 | by Carole Blanc (4 June 1994) 8 | 9 | "A Generic Implementation of Axial Deformation Techniques" 10 | in Graphics Gems V (edited by A. Paeth), Academic Press 11 | \* ------------------------------------------------------------------------- */ 12 | 13 | #ifndef _AXD_ 14 | #define _AXD_ 15 | 16 | /* 17 | ** This package uses the "Toolbox of Macros Functions for Computer Graphics" 18 | ** which provides files : tool.h, real.h, uint.h, sint.h, vec?.h and mat?.h 19 | */ 20 | 21 | #include "../ch7-7/mactbox/real.h" 22 | 23 | typedef real (*shape) (real); 24 | 25 | extern void local_pinch (rv3 *Point, shape Shape, real Ampli); 26 | extern void world_pinch (rv3 *Point, frame3 Frame, shape Shape, real Ampli); 27 | extern void local_taper (rv3 *Point, shape Shape, real Ampli); 28 | extern void world_taper (rv3 *Point, frame3 Frame, shape Shape, real Ampli); 29 | extern void local_mould (rv3 *Point, shape Shape, real Ampli); 30 | extern void world_mould (rv3 *Point, frame3 Frame, shape Shape, real Ampli); 31 | extern void local_twist (rv3 *Point, shape Shape, real Ampli); 32 | extern void world_twist (rv3 *Point, frame3 Frame, shape Shape, real Ampli); 33 | extern void local_shear (rv3 *Point, shape Shape, real Ampli); 34 | extern void world_shear (rv3 *Point, frame3 Frame, shape Shape, real Ampli); 35 | extern void local_bend (rv3 *Point, shape Shape, real Ampli); 36 | extern void world_bend (rv3 *Point, frame3 Frame, shape Shape, real Ampli); 37 | 38 | #endif 39 | 40 | /* ------------------------------------------------------------------------- */ 41 | -------------------------------------------------------------------------------- /gemsv/ch4-3/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(arcdivid arcdivid.c ) 2 | -------------------------------------------------------------------------------- /gemsv/ch4-3/arcdivid.c: -------------------------------------------------------------------------------- 1 | /* arcdivide.c - recursive circular arc subdivision (FP version) */ 2 | 3 | #define DMAX 0.5 /* max chordal deviation = 1/2 pixel */ 4 | 5 | #include 6 | #include "../ch7-7/GG4D/GGems.h" 7 | 8 | /* Function prototype for externally defined functions */ 9 | void DrawLine(Point2 p0, Point2 p1); 10 | 11 | void 12 | DrawArc(Point2 p0, Point2 p1, double d) 13 | { 14 | if (fabs(d) <= DMAX) DrawLine(p0, p1); 15 | else { 16 | Vector2 v; 17 | Point2 pm, pb; 18 | double dSub; 19 | 20 | v.x = p1.x - p0.x; /* vector from p0 to p1 */ 21 | v.y = p1.y - p0.y; 22 | 23 | pm.x = p0.x + 0.5 * v.x; /* midpoint */ 24 | pm.y = p0.y + 0.5 * v.y; 25 | 26 | dSub = d / 4; 27 | V2Scale(&v, dSub); /* subdivided vector */ 28 | 29 | pb.x = pm.x - v.y; /* bisection point */ 30 | pb.y = pm.y + v.x; 31 | 32 | DrawArc(p0, pb, dSub); /* first half arc */ 33 | DrawArc(pb, p1, dSub); /* second half arc */ 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /gemsv/ch4-4/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(aspc aspc.c ) 2 | -------------------------------------------------------------------------------- /gemsv/ch4-4/aspc.c: -------------------------------------------------------------------------------- 1 | /* aspc.c -- generic adaptive sampling of parametric curves */ 2 | #include 3 | #include 4 | 5 | typedef struct point { double t,x,y,z; } Point; 6 | 7 | #define T(p) ((p)->t) 8 | #define X(p) ((p)->x) 9 | #define Y(p) ((p)->y) 10 | #define Z(p) ((p)->z) 11 | 12 | extern void gammad(Point* p); /* user supplied */ 13 | extern void line(Point* p, Point* q); /* user supplied */ 14 | 15 | static int flat(Point* p, Point* q, Point* r); 16 | 17 | static void sample(Point* p, Point* q) 18 | { 19 | Point rr, *r=&rr; 20 | double t = 0.45 + 0.1 * (rand()/(double) RAND_MAX); 21 | T(r) = T(p) + t*(T(q)-T(p)); 22 | gammad(r); 23 | if (flat(p,q,r)) line(p,q); else { sample(p,r); sample(r,q); } 24 | } 25 | 26 | static int flat(Point* p, Point* q, Point* r) 27 | { 28 | extern double tol; /* user supplied */ 29 | double xp = X(p)-X(r); double yp = Y(p)-Y(r); double zp = Z(p)-Z(r); 30 | double xq = X(q)-X(r); double yq = Y(q)-Y(r); double zq = Z(q)-Z(r); 31 | double x = yp*zq-yq*zp; 32 | double y = xp*zq-xq*zp; 33 | double z = xp*yq-xq*yp; 34 | return (x*x+y*y+z*z) < tol; /* |pr x qr|^2 < tol */ 35 | } 36 | 37 | void aspc(double a, double b) /* entry point */ 38 | { 39 | Point pp, *p = &pp; 40 | Point qq, *q = &qq; 41 | srand((unsigned int)time(0)); /* randomize */ 42 | T(p)= a; gammad(p); T(q)=b; gammad(q); /* set up */ 43 | sample(p,q); /* sample */ 44 | } 45 | -------------------------------------------------------------------------------- /gemsv/ch4-5/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(ellipsoid ellihelp.c ellipsoid.c timing.c ) 2 | -------------------------------------------------------------------------------- /gemsv/ch4-5/Makefile: -------------------------------------------------------------------------------- 1 | timing: 2 | cc -O -pca -c ellipsoid_par_help.c 3 | cc -O -c ellipsoid.c 4 | cc -O -c timing.c 5 | cc -O -pca -o timing ellipsoid_par_help.o ellipsoid.o timing.o -lsphere -lmalloc -lgl_s -lm -s 6 | -------------------------------------------------------------------------------- /gemsv/ch4-5/ellipsoid.h: -------------------------------------------------------------------------------- 1 | /* ellipsoid.h */ 2 | 3 | #ifndef ellipsoid_H 4 | #define ellipsoid_H 5 | 6 | typedef struct point { float x, y, z; } point; 7 | typedef struct vertex { 8 | point p, n; /* point and unit normal */ 9 | } vertex; 10 | typedef struct face { 11 | int v0, v1, v2; /* indices of vertex array for a triangular face */ 12 | } face; 13 | typedef struct object { 14 | int nv, nf; /* numbers of elements in v and f */ 15 | vertex *v; face *f; /* arrays of vertices and faces */ 16 | } object; 17 | 18 | void ellipsoid_init (int n); 19 | void ellipsoid_seq (object *ellipsoid, int n, float a, float b, float c); 20 | void ellipsoid_par (object *ellipsoid, int n, float a, float b, float c); 21 | void ellipsoid_print (object *ellipsoid); 22 | void ellipsoid_done (void); 23 | void ellipsoid_free (object *ellipsoid); 24 | 25 | #endif /* ellipsoid_H */ 26 | -------------------------------------------------------------------------------- /gemsv/ch4-7/BezierCode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef struct { int i; } BezierCurve; -------------------------------------------------------------------------------- /gemsv/ch4-7/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(bezlen BezierCode.h bezlen.c ) 2 | 3 | -------------------------------------------------------------------------------- /gemsv/ch4-8/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(qbezier qbezier.c ) 2 | -------------------------------------------------------------------------------- /gemsv/ch4-9/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(lincrv lincrv.c lincrvte.c ) 2 | -------------------------------------------------------------------------------- /gemsv/ch4-9/lincrv.h: -------------------------------------------------------------------------------- 1 | /****** lincrv.h ******/ 2 | /* Ken Shoemake, 1994 */ 3 | 4 | #define MAXDIM 2 5 | typedef float Vect[MAXDIM]; 6 | typedef float Knot; 7 | typedef int Bool; 8 | 9 | int DialASpline(Knot t, Knot a[], Vect p[], int m, int n, Vect work[], 10 | int Cn, Bool interp, Vect val); 11 | 12 | -------------------------------------------------------------------------------- /gemsv/ch4-9/lincrvte.c: -------------------------------------------------------------------------------- 1 | /*** lincrvtest.c ***/ 2 | 3 | #include 4 | #include 5 | #include 6 | #include "lincrv.h" 7 | 8 | #define TRUE 1 9 | #define FALSE 0 10 | #define BIG (1.0e12f) 11 | 12 | static Vect work[4]; 13 | static Vect ctlPts[] = { {0,0}, {1,1}, {1,0}, {0,0}, }; 14 | static float *knots; 15 | static float bezKts[] = {0, 0, 0, 1, 1, 1, BIG}; 16 | static float lagKts[] = {0.00, 0.25, 0.75, 1.00, BIG}; 17 | static float catKts[] = {-1, 0, 1, 2, BIG}; 18 | static float bspKts[] = {-2, -1, 0, 1, 2, 3, BIG}; 19 | static int m = MAXDIM; 20 | static int n = 3; 21 | static int Cn = 1; 22 | static Bool interp = FALSE; 23 | static Vect val = {0.84375, 0.0}; 24 | static float t = 0; 25 | static int eh = 0; 26 | 27 | enum Flavor{PLY, LAG, BEZ, CAT, BSP, NFLAVORS}; 28 | char fnames[][4] = {"PLY", "LAG", "BEZ", "CAT", "BSP"}; 29 | 30 | int main(void) 31 | { 32 | int i; 33 | int flavor = PLY; 34 | 35 | for (flavor=0; flavor 14 | #include "../ch7-7/mactbox/tool.h" 15 | #include "../ch7-7/mactbox/real.h" 16 | #include "../ch7-7/mactbox/vec2.h" 17 | #include "../ch7-7/mactbox/vec3.h" 18 | 19 | 20 | /* 21 | ** Type definitions 22 | */ 23 | typedef struct { 24 | realvec3 A,B,C,D; /* Vertices in counter clockwise order */ 25 | realvec3 Normal; /* Normal vector pointing outwards */ 26 | } QUAD; 27 | 28 | typedef struct { 29 | realvec3 Point; /* Ray origin */ 30 | realvec3 Vector; /* Ray direction */ 31 | } RAY; 32 | 33 | typedef struct { 34 | realvec3 Point; /* Intersection point */ 35 | real Distance; /* Distance from ray origin to intersection point */ 36 | real u, v; /* Parametric coordinates of the intersection point */ 37 | } HIT; 38 | 39 | /* 40 | ** External declarations 41 | */ 42 | extern bool ray_hit_quad (RAY *, QUAD *, HIT *); 43 | 44 | #endif 45 | 46 | /* ------------------------------------------------------------------------- */ 47 | -------------------------------------------------------------------------------- /gemsv/ch5-2/quad_gg.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- *\ 2 | QUAD_GG.H : 3 | 4 | by Christophe Schlick and Gilles Subrenat (15 May 1994) 5 | 6 | "Ray Intersection of Tessellated Surfaces : Quadrangles versus Triangles" 7 | in Graphics Gems V (edited by A. Paeth), Academic Press 8 | \* ------------------------------------------------------------------------- */ 9 | 10 | #ifndef _QUAD_GG_ 11 | #define _QUAD_GG_ 12 | 13 | #include 14 | #include "../ch7-7/GG4D/GGems.h" 15 | 16 | /* 17 | ** Type definitions 18 | */ 19 | typedef double REAL; 20 | 21 | typedef struct { 22 | Point3 A,B,C,D; /* Vertices in counter clockwise order */ 23 | Vector3 Normal; /* Normal vector pointing outwards */ 24 | } QUAD; 25 | 26 | typedef struct { 27 | Point3 Point; /* Ray origin */ 28 | Vector3 Vector; /* Ray direction */ 29 | } RAY; 30 | 31 | typedef struct { 32 | Point3 Point; /* Intersection point */ 33 | REAL Distance; /* Distance from ray origin to intersection point */ 34 | REAL u, v; /* Parametric coordinates of the intersection point */ 35 | } HIT; 36 | 37 | /* 38 | ** External declarations 39 | */ 40 | extern boolean ray_hit_quad (RAY *, QUAD *, HIT *); 41 | 42 | #endif 43 | 44 | /* ------------------------------------------------------------------------- */ 45 | -------------------------------------------------------------------------------- /gemsv/ch5-3/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(rayscan vector.h rayscan.cc ) 2 | -------------------------------------------------------------------------------- /gemsv/ch5-4/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(poly poly.h poly.cpp sweep.cpp) 2 | -------------------------------------------------------------------------------- /gemsv/ch5-4/poly.h: -------------------------------------------------------------------------------- 1 | /************************************************* 2 | * POLY.H 3 | * Andreas Leipelt, "Ray Tracing a Swept Sphere" 4 | * from "Graphics Gems", Academic Press 5 | * 6 | */ 7 | 8 | #ifndef POLY_CLASS 9 | #define POLY_CLASS 10 | 11 | #define MAX_DEGREE 10 12 | #define polyeps 1E-10 // tolerance for polynomial coefficients 13 | 14 | class polynomial { 15 | public: 16 | 17 | int deg; 18 | double coef[MAX_DEGREE+1]; 19 | 20 | polynomial(); 21 | double eval(double); 22 | int roots_between(double,double,double*); 23 | double min(double,double); 24 | double max(double,double); 25 | polynomial derivative(); 26 | }; 27 | 28 | polynomial operator+(const polynomial&, const polynomial&); 29 | polynomial operator-(const polynomial&, const polynomial&); 30 | polynomial operator*(const polynomial&, const polynomial&); 31 | polynomial operator*(double, const polynomial&); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /gemsv/ch5-5/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(oopov global.h voronoi.h camera.cxx csg.cxx finish.cxx finite.cxx infinite.cxx lightsrc.cxx main.cxx misc.cxx normal.cxx pigment.cxx texture.cxx voronoi.cxx ) 2 | add_executable(oopov_show show.c) 3 | target_link_libraries(oopov_show oopov) 4 | -------------------------------------------------------------------------------- /gemsv/ch5-5/camera.cxx: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "global.h" 4 | 5 | std::ostream& operator<<(std::ostream& o, camera& c) { 6 | o<<"camera {\n"; 7 | o<<"location "< 2 | 3 | #include "global.h" 4 | 5 | std::ostream& operator<<(std::ostream& o, csg& c) {c.out(o); return o;} 6 | std::ostream& operator<<(std::ostream& o, csguni& c) {c.out(o); return o;} 7 | std::ostream& operator<<(std::ostream& o, csgmer& c) {c.out(o); return o;} 8 | std::ostream& operator<<(std::ostream& o, csgint& c) {c.out(o); return o;} 9 | std::ostream& operator<<(std::ostream& o, csgdif& c) {c.out(o); return o;} 10 | 11 | -------------------------------------------------------------------------------- /gemsv/ch5-5/finite.cxx: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "global.h" 5 | 6 | std::ostream& operator<<(std::ostream& o, sphere& s) {s.out(o); return o;} 7 | 8 | list *sphere::shape(ray& r) { 9 | list *l=new list; 10 | double b=r.d%(r.o-this->c); 11 | double C=(r.o-this->c)%(r.o-this->c)-this->r*this->r; 12 | double d=b*b-C; 13 | if(d<0.) return l; 14 | d=sqrt(d); double t1=(-b-d); double t2=(-b+d); 15 | if(t1>EPS) { 16 | intersect* i=new intersect; i->t=t1; i->p=r.o+r.d*t1; 17 | i->n=norm(i->p-this->c); i->o=this; 18 | *l+=i; 19 | } 20 | if(t2>EPS) { 21 | intersect* i=new intersect; i->t=t2; i->p=r.o+r.d*t2; 22 | i->n=norm(i->p-this->c); i->o=this; 23 | *l+=i; 24 | } 25 | return l; 26 | } 27 | -------------------------------------------------------------------------------- /gemsv/ch5-5/infinite.cxx: -------------------------------------------------------------------------------- 1 | #if 0 2 | #include 3 | #include 4 | 5 | #include "global.h" 6 | 7 | static list li; 8 | 9 | #endif -------------------------------------------------------------------------------- /gemsv/ch5-5/lightsrc.cxx: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "global.h" 4 | 5 | 6 | std::ostream& operator<<(std::ostream& o, lightsource& l) {l.out(o); return o;} 7 | std::ostream& operator<<(std::ostream& o, spotlight& l) {l.out(o); return o;} 8 | 9 | list lightsources; 10 | -------------------------------------------------------------------------------- /gemsv/ch5-5/makefile: -------------------------------------------------------------------------------- 1 | CC = g++ -g 2 | 3 | .cxx.o: 4 | $(CC) -c $< 5 | 6 | PROG = oopov 7 | HEADER = global.h 8 | OBJS = camera.o csg.o finish.o finite.o infinite.o lightsrc.o main.o \ 9 | misc.o normal.o parser.o pigment.o texture.o voronoi.o 10 | LEX = pov 11 | YACC = pov 12 | 13 | $(PROG) : $(OBJS) 14 | $(CC) -o $(PROG) -L/usr/local/lib $(OBJS) -ll -ly -lm -lg++ 15 | 16 | voronoi.o : voronoi.cxx voronoi.h $(HEADER) 17 | 18 | $(OBJS) : $$(@:.o=.cxx) $(HEADER) 19 | 20 | parser.cxx : y.tab.c lex.yy.c 21 | cat y.tab.c lex.yy.c > parser.cxx 22 | touch parser.cxx 23 | 24 | y.tab.c: $(YACC).y $(HEADER) 25 | yacc $(YACC).y 26 | 27 | lex.yy.c: $(LEX).l 28 | lex $(LEX).l 29 | -------------------------------------------------------------------------------- /gemsv/ch5-5/misc.cxx: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "global.h" 4 | 5 | list objects; 6 | 7 | std::ostream& operator<<(std::ostream& o, vector& v) { 8 | o<<"<"<"; 9 | return o; 10 | } 11 | vector operator-(const vector& v) {return vector(-v.x,-v.y,-v.z);} 12 | std::ostream& operator<<(std::ostream& o, xform& T) { 13 | o<<"xform {\n"; 14 | o<<"\t"<<"orientation {\n"; 15 | o<<"\t"<<"\t"<"; 26 | return o; 27 | } 28 | std::ostream& operator<<(std::ostream& o, intensity& i) { 29 | o<<""; 30 | return o; 31 | } 32 | std::ostream& operator<<(std::ostream& o, object& p) {p.out(o); return o;} 33 | 34 | vector norm(vector& v) {return v*(1./sqrt(v%v));} 35 | -------------------------------------------------------------------------------- /gemsv/ch5-5/normal.cxx: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "global.h" 4 | 5 | std::ostream& operator<<(std::ostream& o, normal& n) { 6 | o<<"normal {\n"; 7 | n.out(o); 8 | o<<"turbulence "< 2 | 3 | #include "global.h" 4 | 5 | 6 | -------------------------------------------------------------------------------- /gemsv/ch5-5/pigment.cxx: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "global.h" 5 | 6 | std::ostream& operator<<(std::ostream& o, pigment& p) { 7 | o<<"pigment {\n"; 8 | p.out(o); 9 | o<<"turbulence "< 2 | #declare Red=color rgb<1,0,0> 3 | #declare White=color rgb<1,1,1> 4 | #declare Yellow=color rgb<1,1,0> 5 | #declare Blue=color rgb<0,0,1> 6 | 7 | camera{location<0,0,-4> direction<0,0,1> right<1,0,0> up<0,1,0>} 8 | light_source{<0,0,-4> color White } 9 | 10 | background {color Black} 11 | 12 | sphere {5*z,3 pigment {color Yellow} finish {phong 0.9 phong_size 60 metallic}} 13 | sphere {<0,0,3>,2 rotate <0,45,0> pigment {checker color Red color Yellow} finish{diffuse .9}} 14 | sphere {<-2,-1,2> ,2 pigment {color Blue} normal {bumps 0.7 scale 0.8} finish{ phong 0.9 phong_size 80}} 15 | 16 | sphere {<0,0,10>,.5 pigment {color White} finish{diffuse .7}} 17 | sphere {<5,0,10>,.5 pigment {color White} finish{diffuse .7}} 18 | sphere {<0,5,10>,.5 pigment {color White} finish{diffuse .7}} 19 | sphere {<6,6,10>,.5 pigment {color White} finish{diffuse .7}} 20 | sphere {<7,4,10>,.5 pigment {color White} finish{diffuse .7}} 21 | sphere {<4,8,10>,.5 pigment {color White} finish{diffuse .7}} 22 | sphere {<3,3,10>,.5 pigment {color White} finish{diffuse .7}} 23 | sphere {<2,5,10>,.5 pigment {color White} finish{diffuse .7}} 24 | sphere {<5,1,10>,.5 pigment {color White} finish{diffuse .7}} 25 | sphere {<2,2,10>,.5 pigment {color White} finish{diffuse .7}} 26 | sphere {<3,-3,10>,.5 pigment {color White} finish{diffuse .7}} 27 | -------------------------------------------------------------------------------- /gemsv/ch5-5/texture.cxx: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "global.h" 4 | 5 | std::ostream& operator<<(std::ostream& o, texture& t) {t.out(o); return o;} 6 | -------------------------------------------------------------------------------- /gemsv/ch6-2/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(halfadap halfadap.c ) 2 | -------------------------------------------------------------------------------- /gemsv/ch6-3/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(pclipper pclipper.c ) 2 | -------------------------------------------------------------------------------- /gemsv/ch6-4/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(vectorize chainCode.C pt2.C test.C vectorize.C ) 2 | -------------------------------------------------------------------------------- /gemsv/ch6-4/Makefile: -------------------------------------------------------------------------------- 1 | # TEST FILE FOR vectorize, NOT FOR BOOK 2 | # 3 | # UNIX makefile for 'vectorize' 4 | # AUTHOR: Jean-Francois DOUE 5 | # LAST MODIFICATION: July 27, 1993 6 | # 7 | 8 | CC = gcc 9 | 10 | C_FLAGS = -g -O 11 | 12 | H_FILES = pt2.h chainCode.h 13 | C_FILES = test.C chainCode.C vectorize.C pt2.C 14 | O_FILES = test.o chainCode.o vectorize.o pt2.o 15 | 16 | .SUFFIXES : .o .c .C 17 | 18 | .C.o: 19 | $(CC) $(C_FLAGS) -c $@ $*.C 20 | 21 | vectorize: $(O_FILES) 22 | $(CC) $(C_FLAGS) -o $@ $(O_FILES) 23 | -------------------------------------------------------------------------------- /gemsv/ch6-4/README: -------------------------------------------------------------------------------- 1 | This directory contains the files necessary to vectorize a 2D shape. 2 | 3 | vectorize.C /* main routine */ 4 | test.C /* interface for the prog */ 5 | pt2D.h /* a header */ 6 | pt2D.C /* a 2D point package */ 7 | chainCode.h /* a header */ 8 | chainCode.C /* a chain code class */ 9 | Makefile /* the makefile */ 10 | bitmap_1 /* a test file */ 11 | bitmap_2 /* another test file */ 12 | bitmap_3 /* a third test file */ 13 | 14 | The program is written in C++. I used gcc2.1 to compile it. 15 | To run the demo, simply type: 16 | 17 | >> make 18 | >> vectorize some_file 19 | 20 | 21 | 22 | You can view the bitmap files by typing: 23 | >> cat some_file 24 | 25 | since the files are encoded in text. The program will display the results 26 | and save them in '.vec' file. You can get more explanations by simply 27 | typing 'vectorize' without arguments. As you will notice, the file does not 28 | use GraphicsGems.m. This is because the programs needs 2D integer operations 29 | and GraphicsGems.m only provides 2D floating point operations through the 30 | Point2 type. 31 | 32 | Only the 5 files: 33 | vectorize.C 34 | pt2D.h 35 | pt2D.C 36 | chainCode.h 37 | chainCode.C 38 | 39 | are meant to make it for the book and the disk accompanying it. 40 | 41 | 42 | JFD. 43 | -------------------------------------------------------------------------------- /gemsv/ch6-4/bitmap_1: -------------------------------------------------------------------------------- 1 | 5 7 2 | 00100 3 | 01100 4 | 10100 5 | 00100 6 | 00100 7 | 00100 8 | 11111 9 | % TEST FILE FOR vectorize, NOT FOR THE BOOK % -------------------------------------------------------------------------------- /gemsv/ch6-4/bitmap_2: -------------------------------------------------------------------------------- 1 | 10 10 2 | 0001001000 3 | 0001001000 4 | 0001001000 5 | 1111111111 6 | 0001001000 7 | 0001001000 8 | 1111111111 9 | 0001001000 10 | 0001001000 11 | 0001001000 12 | % TEST FILE FOR vectorize, NOT FOR THE BOOK % -------------------------------------------------------------------------------- /gemsv/ch6-4/bitmap_3: -------------------------------------------------------------------------------- 1 | 40 40 2 | 0000000000000000000000000000000000000000 3 | 0000000000001111111111110000000000000000 4 | 0000000001111000000000011111000000000000 5 | 0000000110000000000000000000111000000000 6 | 0000001000000000000000000000001110000000 7 | 0000010000000000000000000000000011000000 8 | 0000100000000000000000000000000001000000 9 | 0000100000000000000000000000000000110000 10 | 0001000000000000000000000000000000011000 11 | 0001000000000000000000000000000000001000 12 | 0010000000000000000000000000000000000100 13 | 0010000000000000000000000000000000000100 14 | 0010000000000000000000000000000000000110 15 | 0010000000000000000000000000000000000010 16 | 0010000000000000000000000000000000000010 17 | 0010000000000000000000000000000000000010 18 | 0010000000000000000000000000000000000110 19 | 0010000000000000000000000000000000000100 20 | 0010000000000000000000000000000000000100 21 | 0010000000000000000000000000000000000100 22 | 0010000000000000000000000000000000000100 23 | 0010000000000000000000000000000000000100 24 | 0010000000000000000000000000000000001000 25 | 0010000000000000000000000000000000001000 26 | 0010000000000000000000000000000000001000 27 | 0011000000000000000000000000000000010000 28 | 0001000000000000000000000000000000010000 29 | 0000100000000000000000000000000000110000 30 | 0000110000000000000000000000000000100000 31 | 0000010000000000000000000000000000100000 32 | 0000011000000000000000000000000001000000 33 | 0000001100000000000000000000000011000000 34 | 0000000111000000000000000000001110000000 35 | 0000000001110000000000000000011000000000 36 | 0000000000001111000000000011110000000000 37 | 0000000000000000111111111110000000000000 38 | 0000000000000000000000000000000000000000 39 | 0000000000000000000000000000000000000000 40 | 0000000000000000000000000000000000000000 41 | 0000000000000000000000000000000000000000 42 | % TEST FILE FOR vectorize, NOT FOR THE BOOK % 43 | -------------------------------------------------------------------------------- /gemsv/ch6-4/chainCode.h: -------------------------------------------------------------------------------- 1 | #define DEFAULT_CODE_LENGTH 512 2 | #define SCALE 4 3 | 4 | class chainCode{ 5 | public: 6 | char* code; 7 | int length; 8 | 9 | chainCode(); 10 | ~chainCode(); 11 | void add(char c); 12 | chainCode* postProcess(); 13 | void printSelf(); 14 | }; 15 | 16 | 17 | -------------------------------------------------------------------------------- /gemsv/ch6-4/pt2.C: -------------------------------------------------------------------------------- 1 | #include "pt2.h" 2 | 3 | /*************************************************************/ 4 | /* */ 5 | /* Two utility functions to add and subtract 2D integer */ 6 | /* points. */ 7 | /* */ 8 | /*************************************************************/ 9 | 10 | pt2* addPt2(pt2 *a, pt2 *b, pt2 *c) 11 | { 12 | c->x = a->x + b->x; 13 | c->y = a->y + b->y; 14 | return c; 15 | } 16 | 17 | pt2* subPt2(pt2 *a, pt2 *b, pt2 *c) 18 | { 19 | c->x = a->x - b->x; 20 | c->y = a->y - b->y; 21 | return c; 22 | } 23 | -------------------------------------------------------------------------------- /gemsv/ch6-4/pt2.h: -------------------------------------------------------------------------------- 1 | typedef struct pt2Struct{ 2 | int x,y; 3 | } pt2; 4 | 5 | extern pt2* addPt2(pt2 *a, pt2 *b, pt2 *c); 6 | extern pt2* subPt2(pt2 *a, pt2 *b, pt2 *c); 7 | -------------------------------------------------------------------------------- /gemsv/ch6-5/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(revfit revfit.c ) 2 | -------------------------------------------------------------------------------- /gemsv/ch6-5/revfit.h: -------------------------------------------------------------------------------- 1 | /* revfit.h: definitions for reversible straight line reconstruction routines */ 2 | #include "../ch7-7/GG4D/GGems.h" 3 | #define HRZ 1 4 | #define VRT 2 5 | /* Watch out for the precision of `int' type. Make sure that the max */ 6 | /* coordinate value * SUBPIXRES can be stored in an `int'. */ 7 | #define SUBPIXRES 32 8 | 9 | /************************************************************************/ 10 | /* typedef for Edgelist: the list of edges where lines are to be fitted */ 11 | /************************************************************************/ 12 | typedef struct { 13 | int x,y; /* in bitmap resolution +ve */ 14 | int dir; /* --- <-- H edge ^ */ 15 | } PixelEdge; /* (x,y)--> * | <-- V edge | --> +ve */ 16 | 17 | typedef struct { 18 | int Nedges; /* number of edges in the list */ 19 | int current; /* current edge being visited */ 20 | PixelEdge *list; /* the list of edges found from the pixmap */ 21 | } Edgelist; 22 | 23 | int fitlines(Edgelist el, boolean Pretest, boolean TryAllEndPts, 24 | IntPoint2 *lines, int MaxLines); 25 | void linestojagged(int Nlines, IntPoint2 *lines); 26 | -------------------------------------------------------------------------------- /gemsv/ch6-7/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(sampat sampat.c ) 2 | -------------------------------------------------------------------------------- /gemsv/ch7-1/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(wave wave.c ) 2 | -------------------------------------------------------------------------------- /gemsv/ch7-1/wave.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- *\ 2 | WAVE.H : 3 | 4 | This package provides 3 routines for generating rectangular-like, 5 | triangular-like and sine-like waves including specific features. 6 | 7 | by Christophe Schlick (10 September 1993) 8 | 9 | "Wave Generators for Procedural Techniques in Computer Graphics" 10 | in Graphics Gems V (edited by A. Paeth), Academic Press 11 | \* ------------------------------------------------------------------------- */ 12 | 13 | #ifndef _WAVE_ 14 | #define _WAVE_ 15 | 16 | extern double Rwave (register double t, double s, double Fvar, double Avar); 17 | extern double Twave (register double t, double s, double Fvar, double Avar); 18 | extern double Swave (register double t, double s, double Fvar, double Avar); 19 | 20 | #endif 21 | 22 | /* ------------------------------------------------------------------------- */ 23 | -------------------------------------------------------------------------------- /gemsv/ch7-2/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(pcube fpcube.c pcube.c test.c ) 2 | -------------------------------------------------------------------------------- /gemsv/ch7-2/makefile: -------------------------------------------------------------------------------- 1 | 2 | CC=CC # can be C++ or C compiler 3 | 4 | OBJS= \ 5 | pcube.o \ 6 | fpcube.o \ 7 | test.o 8 | 9 | .c.o: 10 | $(CC) -O -c $< -I. 11 | 12 | all: test 13 | 14 | test: $(OBJS) 15 | $(CC) -o test $(OBJS) -lm 16 | 17 | clean: 18 | rm -f $(OBJS) test 19 | -------------------------------------------------------------------------------- /gemsv/ch7-3/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(collide5 collide.cc ) 2 | -------------------------------------------------------------------------------- /gemsv/ch7-4/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(partition dedge.cc list.cc main.cc plane.cc polygon.cc ) 2 | -------------------------------------------------------------------------------- /gemsv/ch7-4/Makefile: -------------------------------------------------------------------------------- 1 | # -*- Makefile -*- 2 | # based on gnu's make 3 | 4 | .SUFFIXES: .cc .h 5 | 6 | GPP = g++ 7 | # Compiler options, such as -g or -O : 8 | COPTS = -O2 9 | # Linker/loader options, such as -s : 10 | LOPTS = -s 11 | LIBS = -lm 12 | 13 | MOBJS = main.o polygon.o dedge.o plane.o list.o 14 | SRCS = ${MOBJS:.o=.cc} 15 | 16 | .cc.o:; $(GPP) -c $(COPTS) $*.cc 17 | 18 | ptest: $(MOBJS) 19 | $(GPP) $(COPTS) $(LOPTS) -o $@ $(MOBJS) $(LIBS) 20 | 21 | # ------------------------------------ 22 | clean:; $(RM) Makefile.bak *.o *~ a.out core errs TAGS 23 | 24 | depend: 25 | /usr/local/X11/makedepend $(SRCS) 26 | # DO NOT DELETE THIS LINE -- make depend depends on it. 27 | 28 | main.o: polygon.h list.h plane.h vector.h point.h dedge.h 29 | polygon.o: /usr/include/assert.h polygon.h list.h plane.h vector.h point.h 30 | polygon.o: dedge.h 31 | dedge.o: /usr/include/stdlib.h /usr/include/sys/feature_tests.h 32 | dedge.o: /usr/include/assert.h dedge.h 33 | plane.o: plane.h vector.h point.h /usr/include/assert.h 34 | list.o: list.h 35 | -------------------------------------------------------------------------------- /gemsv/ch7-4/basic.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // basic.h by George Vanecek, Jr. June 1994 3 | 4 | #ifndef _BASIC_H_ 5 | #define _BASIC_H_ 6 | 7 | #ifndef _IOSTREAM_H 8 | //#include 9 | #endif 10 | 11 | #ifndef __MATH_H__ 12 | #include 13 | #endif 14 | 15 | #ifndef _ASSERT_H_ 16 | #include 17 | #endif 18 | 19 | typedef int Counter; // 0,1,2,... 20 | typedef int Index; // Array Index: 0,1,2,... 21 | enum Boolean { FALSE, TRUE }; 22 | enum Where { // Point/Plane Classification 23 | NOWHERE, 24 | ABOVE = 0x01, 25 | ON = 0x02, 26 | ONABOVE = 0x03, // ON | ABOVE 27 | BELOW = 0x04, 28 | ABOVEBELOW = 0x05, // ABOVE | BELOW 29 | ONBELOW = 0x06, // ON | BELOW 30 | CROSS = 0x07 // ABOVE | ON | BELOW 31 | }; 32 | 33 | template 34 | inline void swap( Type& a, Type& b ) 35 | { 36 | const Type c = a; 37 | a = b; 38 | b = c; 39 | } 40 | 41 | #ifndef NULL 42 | #define NULL 0 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /gemsv/ch7-4/dedge.cc: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // dedge.cc by George Vanecek Jr. June 1994 3 | // 4 | 5 | #include 6 | #include 7 | #include "dedge.h" 8 | 9 | DEdge::DEdge( const Point& srcP, DEdge* const last ) 10 | : nxt(NULL), sP(srcP), sPW(NOWHERE) 11 | { 12 | last->nxt = this; 13 | prv = last; 14 | } 15 | 16 | void DEdge::closeCycle( DEdge* const first, DEdge* const last ) 17 | { 18 | first->prv = last; 19 | last->nxt = first; 20 | } 21 | 22 | void DEdge::split( const Point& p ) 23 | { 24 | DEdge* const n = next(); 25 | DEdge* const d = new DEdge( p, this ); 26 | closeCycle( n, d ); 27 | } 28 | -------------------------------------------------------------------------------- /gemsv/ch7-4/dedge.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // dedge.h by George Vanecek Jr, June 1994 3 | 4 | #ifndef _DEDGE_H_ 5 | #define _DEDGE_H_ 6 | 7 | #ifndef _POINT_H_ 8 | #include "point.h" 9 | #endif 10 | 11 | class DEdge { // Directed Edge 12 | public: 13 | DEdge ( const Point& srcP ) 14 | : nxt(this), prv(this), sP(srcP), sPW(NOWHERE) { } 15 | DEdge* next( ) const { return nxt; } 16 | DEdge* prev( ) const { return prv; } 17 | const Point& srcPoint( ) const { return sP; } 18 | const Point& dstPoint( ) const { return nxt->sP; } 19 | Where& srcWhere( ) { return sPW; } 20 | Where& dstWhere( ) { return nxt->sPW; } 21 | Where where( ) const { return Where( sPW | nxt->sPW ); } 22 | double& distFromRefP( ) { return t; } 23 | 24 | private: 25 | DEdge ( const Point& srcP, DEdge* const last ); 26 | static void closeCycle( DEdge* const first, DEdge* const last ); 27 | void split ( const Point& ); 28 | 29 | DEdge* nxt; // Next DEdge on cycle 30 | DEdge* prv; // Previous DEdge on cycle 31 | const Point sP; // Source Point 32 | Where sPW; // Where is Source Point? 33 | double t; // Related to sP. Used in complexCut(...) 34 | 35 | friend class Polygon; 36 | }; 37 | 38 | typedef DEdge* DEdgePtr; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /gemsv/ch7-4/list.cc: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // 3 | // list.cc 4 | // by George Vanecek, 1994 5 | // This List template is used frequently, and consequently, we 6 | // want to improve its performance. Since memory allocation and 7 | // dealocation is very time consuming, we keep a stack of free ListNodes, 8 | // and reuse them. 9 | 10 | #include "list.h" 11 | 12 | ListNode* ListNode::freeList = NULL; 13 | 14 | // Allocate ListNode first from our free list, then from system heap. 15 | void* ListNode::operator new( size_t s ) 16 | { 17 | if( freeList ) { 18 | ListNode* const n = freeList; 19 | freeList = freeList->nxt; 20 | return n; 21 | } 22 | return ::operator new(s); 23 | } 24 | 25 | // Delete node by placing it on our free list. 26 | void ListNode::operator delete( void* p ) 27 | { 28 | ListNode* const n = (ListNode*)p; 29 | n->nxt = freeList; 30 | freeList = n; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /gemsv/ch7-4/list.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // list.h by George Vanecek Jr. June 1994 3 | 4 | #ifndef _LIST_H_ 5 | #define _LIST_H_ 6 | 7 | #ifndef __STDLIB_H__ 8 | #include 9 | #endif 10 | 11 | #ifndef _BASIC_H_ 12 | #include "basic.h" 13 | #endif 14 | 15 | class ListNode { 16 | public: 17 | ListNode( void* const t, ListNode* const n ) : val(t), nxt(n) {} 18 | void* value ( ) const { return val; } 19 | ListNode* next ( ) { return nxt; } 20 | void* operator new ( size_t ); 21 | void operator delete( void* ); 22 | 23 | private: 24 | void* const val; 25 | ListNode* nxt; 26 | static ListNode* freeList; 27 | }; 28 | 29 | template 30 | class List { 31 | public: 32 | List( ) : anchor(NULL), nNodes(0) { } 33 | Boolean empty ( ) const { return Boolean( anchor == NULL ); } 34 | T* first ( ) const { return (T*)(anchor->value()); } 35 | ListNode* head ( ) const { return anchor; } 36 | Counter size ( ) const { return nNodes; } 37 | void operator <<( T* const ); // insert (i.e. push) 38 | Boolean operator >>( T*& ); // remove (i.e. pop) 39 | 40 | private: 41 | ListNode* anchor; // Start of List 42 | Counter nNodes; // Number of Nodes on list 43 | }; 44 | 45 | template 46 | void List::operator <<( T* const t ) 47 | { 48 | anchor = new ListNode( t, anchor ); 49 | ++nNodes; 50 | } 51 | 52 | template 53 | Boolean List::operator >>( T*& t ) 54 | { 55 | if( empty() ) { 56 | t = NULL; 57 | return FALSE; 58 | } 59 | t = first(); 60 | ListNode* f = anchor; 61 | anchor = f->next(); 62 | delete f; 63 | --nNodes; 64 | return TRUE; 65 | } 66 | 67 | #define forEachItemOnList(p) \ 68 | for( ListNode* pp = p.head(); pp != NULL; pp = pp->next() ) 69 | 70 | #define getItem(Type) \ 71 | (Type*)(pp->value()) 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /gemsv/ch7-4/main.cc: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // Gems V: Spatial Partitioning of a Polygon by a Plane 3 | // by George Vanecek Jr, Sept. 1994 4 | 5 | #include 6 | #include "polygon.h" 7 | 8 | static void printPolys( const char* const label, const List& pL ) 9 | { 10 | if( pL.size() ) { 11 | std::cout << "----------" << std::endl 12 | << pL.size() << " polygon(s) " << label << std::endl; 13 | forEachItemOnList( pL ) { 14 | std::cout << " Polygon:" << std::endl; 15 | const Polygon* const g = getItem(Polygon); 16 | forEachDEdgeOfPoly(d1,g) { 17 | const Point& p = d1->srcPoint(); 18 | std::cout << " " << p.x() << ' ' << p.y() << ' ' << p.z() << std::endl; 19 | } 20 | } 21 | } 22 | } 23 | 24 | int main( ) 25 | { 26 | // Sample polygon shown in Figure 1(a) of the Gems V article. 27 | const Point pts[] = { 28 | Point( 0,0,0), Point( 2,0,0), Point( 3,3,0), 29 | Point( 4,0,0), Point( 9,0,0), Point( 9,3,0), 30 | Point(10,3,0), Point(10,0,0), Point(13,0,0), 31 | Point(13,3,0), Point(14,3,0), Point(14,6,0), 32 | Point( 6,6,0), Point( 6,2,0), Point( 7,2,0), 33 | Point( 7,5,0), Point(12,5,0), Point(12,1,0), 34 | Point(11,1,0), Point(11,4,0), Point( 8,4,0), 35 | Point( 8,1,0), Point( 5,1,0), Point( 5,3,0), 36 | Point( 4,3,0), Point( 4,6,0), Point( 3,6,0), 37 | Point( 2,3,0), Point( 1,6,0), Point( 0,6,0) 38 | }; 39 | Polygon* g = new Polygon( 30, pts ); 40 | std::cout << "Before:" << std::endl; 41 | forEachDEdgeOfPoly(d1,g) 42 | std::cout << d1->srcPoint() << std::endl; 43 | List above; 44 | List on; 45 | List below; 46 | split( g, Plane(Vector(0.0,1.0,0.0),-3.0), above, on, below); 47 | printPolys( "Above", above); 48 | printPolys( "On", on); 49 | printPolys( "Below", below); 50 | } 51 | -------------------------------------------------------------------------------- /gemsv/ch7-4/plane.cc: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // plane.cc by George Vanecek Jr., June 1994 3 | // 4 | // bug fixes 2016.1.21 Glenn Burkhardt 5 | // - fix index out of bounds error 6 | // - correct computation of epsilon; need 'n' and 'd' before computing 7 | // 8 | 9 | #include "plane.h" 10 | 11 | // Computes the plane equation using Newell's averaging algorithm. 12 | Plane::Plane( const Counter nPoints, const Point points[] ) 13 | : n(0.0,0.0,0.0), d(0.0), eps(0.0) 14 | { 15 | assert( nPoints > 2 ); 16 | Vector avrPnt = Point(0,0,0); 17 | for( Index i = 0; i < nPoints; ++i ) { 18 | avrPnt += points[i]; 19 | n += Vector(points[i]) ^ Vector(points[(i+1) % nPoints]); 20 | } 21 | 22 | n.normalize(); 23 | d = normal() * ((-1.0 / nPoints) * avrPnt ); 24 | 25 | for( Index i = 0; i < nPoints; ++i ) 26 | updateEpsilon( points[i] ); 27 | } 28 | 29 | // Compute the intersection point with the transversal line (p,q). 30 | Point Plane::onPoint( const Point &p, const Point &q ) const 31 | { 32 | const Vector v(q - p); 33 | const double c = normal() * v; 34 | assert( c != 0.0 ); 35 | const double t = -sDistance(p) / c; 36 | return p + t * v; 37 | } 38 | 39 | void Plane::updateEpsilon ( const Point& p ) 40 | { 41 | double d = sDistance(p); 42 | if( d < 0.0 ) 43 | d = -d; 44 | if( d > eps) 45 | eps = d; 46 | } 47 | 48 | -------------------------------------------------------------------------------- /gemsv/ch7-4/plane.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // 3 | // plane.h by George Vanecek Jr. June 1994 4 | 5 | #ifndef _PLANE_H_ 6 | #define _PLANE_H_ 7 | 8 | #ifndef _VECTOR_H_ 9 | #include "vector.h" 10 | #endif 11 | 12 | // Provide a minimal 3D plane support sufficine for the Gem. 13 | // 14 | // Any point p that is known topologically to lie on a plane pN+d~0 15 | // is included in the plane by enlarging the epsilon, so the 16 | // equation |pN+d| <= eps holds. The point/plane relationship must 17 | // be established by the application code. 18 | 19 | class Plane 20 | { 21 | public: 22 | Plane ( const Counter nPoints, const Point[] ); 23 | Plane ( const Vector& v, double x ) : n(v), d(x), eps(0.0) { } 24 | Plane ( const Plane& pl ) : n(pl.n), d(pl.d), eps(pl.eps) { } 25 | 26 | const Vector& normal( ) const { return n; } 27 | 28 | // The point is topologically known to lie in the plane, so check 29 | // and update epsilon accordingly: 30 | void updateEpsilon( const Point& ); 31 | 32 | // Signed distance from the point to the plane. 33 | double sDistance( const Point& p ) const { return Vector(p) * n + d; } 34 | 35 | // Intersection point between this Plane and transversal line. 36 | Point onPoint( const Point&, const Point& ) const; 37 | 38 | // Which side of the plane is this point on? 39 | Where whichSide( const Point& ) const; 40 | 41 | private: 42 | Vector n; // unit normal vector 43 | double d; // shortest distance from origin 44 | double eps; // point/plane distance epsilon 45 | }; 46 | 47 | inline Where Plane::whichSide( const Point& p ) const 48 | { const double d = sDistance( p ); 49 | return d < -eps ? BELOW : (d > eps ? ABOVE : ON); 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /gemsv/ch7-4/point.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // point.h by George Vanecek Jr. June 1994 3 | 4 | #ifndef _POINT_H_ 5 | #define _POINT_H_ 6 | 7 | #include 8 | 9 | #ifndef _BASIC_H_ 10 | #include "basic.h" 11 | #endif 12 | 13 | class Point 14 | { 15 | public: 16 | Point ( const double x, const double y, const double z) 17 | : _x(x), _y(y), _z(z) { } 18 | 19 | double x() const { return _x; } 20 | double y() const { return _y; } 21 | double z() const { return _z; } 22 | Point& operator +=( const Point& p); 23 | 24 | protected: 25 | double _x, _y, _z; // Point Coordinates 26 | double& x() { return _x; } 27 | double& y() { return _y; } 28 | double& z() { return _z; } 29 | }; 30 | 31 | inline Point& Point::operator +=( const Point& p ) 32 | { x() += p.x(), y() += p.y(), z() += p.z(); return *this; } 33 | 34 | inline std::ostream& operator << ( std::ostream& outs, const Point& p ) 35 | { 36 | outs << '(' << p.x() << ' ' << p.y() << ' ' << p.z() << ')'; 37 | return outs; 38 | } 39 | 40 | 41 | #endif 42 | 43 | 44 | -------------------------------------------------------------------------------- /gemsv/ch7-4/vector.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | // vector.h by George Vanecek Jr. June 1994 3 | // 4 | // bug fixes 2016.1.21 Glenn Burkhardt 5 | // - correct 'normalize', use sqrt(magnitude) instead of square 6 | // 7 | 8 | #ifndef _VECTOR_H_ 9 | #define _VECTOR_H_ 10 | 11 | #include 12 | 13 | #ifndef _POINT_H_ 14 | #include "point.h" 15 | #endif 16 | 17 | class Vector : public Point { 18 | public: 19 | Vector( const Point& p ) : Point(p) {} 20 | Vector( double a, double b, double c ) : Point(a, b, c) {} 21 | inline double operator * ( const Vector& v ) const; 22 | inline Vector operator ^ ( const Vector& v ) const; 23 | void normalize ( ); 24 | }; 25 | 26 | inline Vector operator + ( const Point& p, const Point& q ) 27 | { return Point(p.x()+q.x(), p.y()+q.y(), p.z()+q.z()); } 28 | 29 | inline Vector operator - ( const Point& p, const Point& q ) 30 | { return Point(p.x()-q.x(), p.y()-q.y(), p.z()-q.z()); } 31 | 32 | inline Vector operator * ( const double s, const Vector& v ) 33 | { return Vector( s*v.x(), s*v.y(), s*v.z() ); } 34 | 35 | // Vector Dot Product. 36 | inline double Vector::operator * ( const Vector& v ) const 37 | { return x() * v.x() + y() * v.y() + z() * v.z(); } 38 | 39 | // Vector Cross product. 40 | inline Vector Vector::operator ^ ( const Vector& v ) const 41 | { return Vector(y() * v.z() - z() * v.y(), 42 | z() * v.x() - x() * v.z(), 43 | x() * v.y() - y() * v.x()); 44 | } 45 | 46 | inline void Vector::normalize() 47 | { 48 | const double n = sqrt(*this * *this); 49 | assert( n != 0.0 ); 50 | x() /= n; 51 | y() /= n; 52 | z() /= n; 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /gemsv/ch7-5/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(triangulation construct.c misc.c monotone.c tri.c) 2 | 3 | -------------------------------------------------------------------------------- /gemsv/ch7-5/data_1: -------------------------------------------------------------------------------- 1 | 0.0 0.0 2 | 10.0 0.0 3 | 20.0 0.0 4 | 20 5.0 5 | 20.0 20.0 6 | 0.0 20.0 7 | 5.0 10.0 8 | -------------------------------------------------------------------------------- /gemsv/ch7-5/makefile: -------------------------------------------------------------------------------- 1 | inclpath = . 2 | 3 | CC=gcc 4 | 5 | CFLAGS= -UCHOOSE_MANUAL -UDEBUG -USIMPLE -DSTANDALONE -UCLOCK\ 6 | -I$(inclpath) -L/lib/pa1.1 -g 7 | 8 | 9 | # DEBUG: turn on debugging output 10 | # CLOCK: time the triangulation process 11 | # 12 | # STANDALONE: run as a separate program. read data from file. 13 | # If this flag is False, then use the interface procedure 14 | # triangulate_polygon() instead. 15 | # 16 | # SIMPLE: if defined, turn off randomization 17 | # 18 | 19 | 20 | LDFLAGS= -lm 21 | 22 | objects= construct.o misc.o monotone.o tri.o 23 | executable = triangulate 24 | 25 | $(executable): $(objects) 26 | rm -f $(executable) 27 | $(CC) $(CFLAGS) $(objects) $(LDFLAGS) -o $(executable) 28 | 29 | $(objects): $(inclpath)/basic.h 30 | 31 | clean: 32 | rm -f $(objects) 33 | 34 | -------------------------------------------------------------------------------- /gemsv/ch7-6/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_subdirectory(sx11) 3 | add_subdirectory(tga) 4 | 5 | add_library(ZRendv10 ZRendv10.h ZRendv10.c ) 6 | -------------------------------------------------------------------------------- /gemsv/ch7-6/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | 3 | PROG=ZRendv10 4 | 5 | GCCFLAGS = -fpcc-struct-return 6 | CFLAGS = -ansi -O2 7 | 8 | INCLUDE = -I/usr/X11R5/include -I./tga 9 | 10 | LDLIBS = -lX11 -lm -ltga 11 | 12 | LDFLAGS = -L/usr/X11R5/lib -L./tga 13 | 14 | $(PROG): $(PROG).c $(PROG).h 15 | (cd tga; make) 16 | (cd sx11; make) 17 | $(CC) $(GCCFLAGS) $(CFLAGS) $(INCLUDE) $(PROG).c \ 18 | $(LDFLAGS) $(LDLIBS) -o $(PROG) 19 | 20 | -------------------------------------------------------------------------------- /gemsv/ch7-6/sx11/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(xs11 sx11.c ) 2 | -------------------------------------------------------------------------------- /gemsv/ch7-6/sx11/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | 3 | PROG=sx11 4 | 5 | GCCFLAGS = -fpcc-struct-return 6 | CFLAGS = -O2 7 | 8 | INCLUDE = -I/usr/X11R5/include -I../tga 9 | 10 | LDLIBS = -lX11 -ltga -lm 11 | 12 | LDFLAGS = -L/usr/X11R5/lib -L../tga 13 | 14 | 15 | $(PROG): 16 | $(CC) $(GCCFLAGS) $(INCLUDE) $(CFLAGS) $(PROG).c \ 17 | $(LDFLAGS) $(LDLIBS) -o $(PROG) 18 | -------------------------------------------------------------------------------- /gemsv/ch7-6/tga/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(tga bitmap.c cnv.c dither.c encodgif.c error.c general.c gif.c hsl.c in_out.c memory.c tga.c tobw.c x11.c ) 2 | -------------------------------------------------------------------------------- /gemsv/ch7-6/tga/Makefile: -------------------------------------------------------------------------------- 1 | # An ANSI C compiler: gnu's "gcc" 2 | CC = gcc 3 | 4 | # The UNIX flag must be defined for UNIX implementations 5 | #CPPFLAGS = -DUNIX -DX11 -I. 6 | 7 | # Very important! The first flag (struct-return) makes it safe to link 8 | # gcc objects with cc objects. 9 | GCCFLAGS = -fpcc-struct-return 10 | 11 | # Object files wiil go in this subdirectory 12 | OBJ_DIR = . 13 | 14 | # User-defined; to pass options in to the compilation, say things 15 | # like 'make CFLAGS=-g'. Put flags here to make them permanent. 16 | 17 | CFLAGS = -O2 18 | 19 | ##################################################################### 20 | 21 | TARGET = libtga.a 22 | 23 | #HFILES = alias.h lug.h lugconf.h lugfnts.h rla.h targa.h tga.h 24 | 25 | OBJECTS = \ 26 | bitmap.o \ 27 | tga.o \ 28 | in_out.o \ 29 | memory.o \ 30 | error.o \ 31 | general.o \ 32 | cnv.o \ 33 | hsl.o \ 34 | x11.o \ 35 | dither.o \ 36 | gif.o \ 37 | encodgif.o \ 38 | tobw.o \ 39 | ##################################################################### 40 | 41 | 42 | PATH_OBJECTS = $(OBJECTS:%=$(OBJ_DIR)/%) 43 | 44 | $(OBJ_DIR)/%.o: %.c 45 | $(CC) $(GCCFLAGS) $(CFLAGS) -c -o $(OBJ_DIR)/$*.o $*.c 46 | 47 | $(TARGET): $(PATH_OBJECTS) 48 | echo $(PATH_OBJECTS) 49 | ar rv $(TARGET) $(PATH_OBJECTS) 50 | ranlib $(TARGET) 51 | 52 | remove: 53 | /bin/rm -f $(PATH_OBJECTS) 54 | /bin/rm -f *~ 55 | 56 | clean: remove $(TARGET) 57 | 58 | #$(PATH_OBJECTS): $(HFILES) 59 | -------------------------------------------------------------------------------- /gemsv/ch7-6/tga/README: -------------------------------------------------------------------------------- 1 | This code is obtained from the LUG library due to Raul Rivero. 2 | -------------------------------------------------------------------------------- /gemsv/ch7-6/tga/alias.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is copyrighted as noted below. It may be freely copied, 3 | * modified, and redistributed, provided that the copyright notice is 4 | * preserved on all copies. 5 | * 6 | * There is no warranty or other guarantee of fitness for this software, 7 | * it is provided solely "as is". Bug reports or fixes may be sent 8 | * to the author, who may or may not act on them as he desires. 9 | * 10 | * You may not include this software in a program or other software product 11 | * without supplying the source, or without informing the end-user that the 12 | * source is available for no extra charge. 13 | * 14 | * If you modify this software, you should include a notice giving the 15 | * name of the person performing the modification, the date of modification, 16 | * and the reason for such modification. 17 | */ 18 | /* 19 | * rla.h - type define to Alias "pix" format. 20 | * 21 | * Author: Raul Rivero 22 | * Mathematics Dept. 23 | * University of Oviedo 24 | * Date: Wed Jan 22 1992 25 | * Copyright (c) 1992, Raul Rivero 26 | * 27 | */ 28 | 29 | #ifndef MY_ALIAS 30 | 31 | #define MY_ALIAS 32 | 33 | typedef struct { 34 | short xsize, ysize; 35 | short xinit, yinit; 36 | short depth; 37 | } alias_hdr; 38 | 39 | #endif /* MY_ALIAS */ 40 | -------------------------------------------------------------------------------- /gemsv/ch7-6/tga/memory.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is copyrighted as noted below. It may be freely copied, 3 | * modified, and redistributed, provided that the copyright notice is 4 | * preserved on all copies. 5 | * 6 | * There is no warranty or other guarantee of fitness for this software, 7 | * it is provided solely "as is". Bug reports or fixes may be sent 8 | * to the author, who may or may not act on them as he desires. 9 | * 10 | * You may not include this software in a program or other software product 11 | * without supplying the source, or without informing the end-user that the 12 | * source is available for no extra charge. 13 | * 14 | * If you modify this software, you should include a notice giving the 15 | * name of the person performing the modification, the date of modification, 16 | * and the reason for such modification. 17 | */ 18 | /* 19 | * memory.c - allocate mamory. 20 | * 21 | * Author: Raul Rivero 22 | * Mathematics Dept. 23 | * University of Oviedo 24 | * Date: Sat Jan 4 1992 25 | * Copyright (c) 1992, Raul Rivero 26 | * 27 | */ 28 | 29 | #include "lug.h" 30 | 31 | extern int stop_on_error; 32 | void Error(int); 33 | 34 | char *Malloc(long int size) 35 | { 36 | char *ptr; 37 | 38 | if ((ptr = (char *) malloc(size)) == NULL) { 39 | stop_on_error = 1; 40 | Error( 2 ); 41 | } 42 | 43 | /* 44 | * Usually compilers fill buffers with zeros, 45 | * but ... 46 | */ 47 | bzero( ptr, size ); 48 | return ptr; 49 | } 50 | 51 | void Free(void* ptr ) 52 | { 53 | if ( ptr != NULL ) 54 | free( ptr ); 55 | } 56 | -------------------------------------------------------------------------------- /gemsv/ch7-6/tga/targa.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is copyrighted as noted below. It may be freely copied, 3 | * modified, and redistributed, provided that the copyright notice is 4 | * preserved on all copies. 5 | * 6 | * There is no warranty or other guarantee of fitness for this software, 7 | * it is provided solely "as is". Bug reports or fixes may be sent 8 | * to the author, who may or may not act on them as he desires. 9 | * 10 | * You may not include this software in a program or other software product 11 | * without supplying the source, or without informing the end-user that the 12 | * source is available for no extra charge. 13 | * 14 | * If you modify this software, you should include a notice giving the 15 | * name of the person performing the modification, the date of modification, 16 | * and the reason for such modification. 17 | */ 18 | /* 19 | * targa.h - type define to Targa format. 20 | * 21 | * Author: Raul Rivero 22 | * Mathematics Dept. 23 | * University of Oviedo 24 | * Date: Wed Jan 22 1992 25 | * Copyright (c) 1992, Raul Rivero 26 | * 27 | */ 28 | 29 | #ifndef MY_TGA 30 | 31 | #define MY_TGA 32 | 33 | #define TGA_INTERLACED(a) ( (a) & 0xc0 ) 34 | #define TGA_FLIP(a) ( ((a) & 0x20) ? 0 : 1) 35 | #define TGA_MAPPED 1 36 | #define TGA_RGB 2 37 | #define TGA_RLE_MAPPED 9 38 | #define TGA_RLE_RGB 10 39 | 40 | /* 41 | * Targa header. 42 | */ 43 | typedef struct { 44 | byte num_id; 45 | byte cmap_type; 46 | byte image_type; 47 | ushort cmap_orign; 48 | ushort cmap_length; 49 | byte cmap_entry_size; 50 | ushort xorig, yorig; 51 | ushort xsize, ysize; 52 | byte pixel_size; 53 | byte image_descriptor; 54 | } tga_hdr; 55 | 56 | #endif /* MY_TGA */ 57 | -------------------------------------------------------------------------------- /gemsv/ch7-7/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(GG4D) 2 | add_subdirectory(libgm) 3 | add_subdirectory(vec-h) 4 | -------------------------------------------------------------------------------- /gemsv/ch7-7/GG4D/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(cg4d example.c VecLib.c VecLib4d.c ) 2 | -------------------------------------------------------------------------------- /gemsv/ch7-7/GG4D/GGems4d.h: -------------------------------------------------------------------------------- 1 | #ifndef GG4D_H 2 | #define GG4D_H 1 3 | 4 | /*********************/ 5 | /* 4d geometry types */ 6 | /*********************/ 7 | 8 | /* Point4, Vector4 9 | * 10 | * 4-space point and vector types 11 | */ 12 | 13 | typedef struct Point4Struct 14 | { 15 | double x, y, z, w; 16 | } 17 | Point4; 18 | 19 | typedef Point4 Vector4; 20 | 21 | /* IntPoint4 22 | * 23 | * Integer 4-space point. 24 | */ 25 | 26 | typedef struct IntPoint4Struct 27 | { 28 | int x, y, z, w; 29 | } 30 | IntPoint4; 31 | 32 | /* Matrix5 33 | * 34 | * 5x5 matrix for general linear 4-space transformations 35 | */ 36 | 37 | typedef struct Matrix5Struct 38 | { 39 | double element[5][5]; 40 | } 41 | Matrix5; 42 | 43 | /* Box4 44 | * 45 | * A bounding box for four dimensions. 46 | */ 47 | 48 | typedef struct Box4dStruct 49 | { 50 | Point4 min, max; 51 | } 52 | Box4; 53 | 54 | /* See C file for function elaboration. 55 | */ 56 | 57 | extern double V4SquaredLength(), V4Length(); 58 | extern double V4Dot(), V4DistanceBetween2Points(); 59 | extern Vector4 *V4Negate(), *V4Normalize(), *V4Scale(), *V4Add(), *V4Sub(); 60 | extern Vector4 *V4Lerp(), *V4Combine(), *V4Mul(), *V4Cross(); 61 | extern Vector4 *V4New(), *V4Duplicate(); 62 | extern Point4 *V4MulPointByMatrix(), *V4MulPointByProjMatrix(); 63 | extern Matrix5 *V4MatMul(); 64 | 65 | extern void V4MatPrint(); 66 | extern Matrix5 *V4MatCopy(), *V4MatMul(), *V4MatMul2(); 67 | extern Matrix5 *V4MatZero(), *V4MatIdentity(); 68 | extern Matrix5 *V4MatRotationXY(), *V4MatRotationXW(), *V4MatRotationYZ(); 69 | extern Matrix5 *V4MatRotationYW(), *V4MatRotationZX(), *V4MatRotationZW(); 70 | extern Matrix5 *V4MatTranslation(), *V4MatScaling(); 71 | extern Matrix5 *V4MatRotateXY(), *V4MatRotateXW(), *V4MatRotateYZ(); 72 | extern Matrix5 *V4MatRotateYW(), *V4MatRotateZX(), *V4MatRotateZW(); 73 | extern Matrix5 *V4MatTranslate(), *V4MatScale(); 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /gemsv/ch7-7/GG4D/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | 3 | example: example.o VecLib.o VecLib4d.o 4 | $(CC) -o example example.o VecLib.o VecLib4d.o -lm 5 | 6 | -------------------------------------------------------------------------------- /gemsv/ch7-7/README: -------------------------------------------------------------------------------- 1 | Dir Name (dim) Author(s) Desc (Gems vol.V, page 403) 2 | -------------------------------------------------------------- 3 | libgm 3+ Scheepers & May "The compleat C++ graphics library" 4 | mactbox 3+ C. Schlick "Elegant macros are gentle on the eyes" 5 | vec-h N+ D. Hatch "C/C++ macros to go in any dimension" 6 | GG4D 4+ S. Hill "The 4D tour de force (includes projections)" 7 | -------------------------------------------------------------------------------- /gemsv/ch7-7/libgm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(gm gm.h gmConst.h gmMat3.h gmMat4.h gmUtils.h gmVec2.h gmVec3.h gmVec4.h gmMat3.cc gmMat4.cc ) 2 | -------------------------------------------------------------------------------- /gemsv/ch7-7/libgm/Imakefile: -------------------------------------------------------------------------------- 1 | CC = CC 2 | CCOPTIONS = 3 | CCINCLUDES = $(STD_INCLUDES) -I/usr/include/CC -I. 4 | EXTRA_DEFINES = 5 | EXTRA_LIBRARIES = 6 | 7 | .SUFFIXES: .C $(SUFFIXES) 8 | 9 | LIBNAME = gm++ 10 | 11 | SRCS = gmMatrix3.C gmMatrix4.C 12 | OBJS = $(SRCS:.C=.o) 13 | 14 | .C.o: 15 | $(CC) $(CDEBUGFLAGS) -c $(CCOPTIONS) $(EXTRA_DEFINES) $< $(CCINCLUDES) 16 | 17 | NormalLibraryTarget($(LIBNAME), $(OBJS)) 18 | 19 | -------------------------------------------------------------------------------- /gemsv/ch7-7/libgm/gm.h: -------------------------------------------------------------------------------- 1 | // gm.h - library header 2 | // 3 | // libgm++: Graphics Math Library 4 | // Ferdi Scheepers and Stephen F May 5 | // 15 June 1994 6 | 7 | #ifndef GM_H 8 | #define GM_H 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #endif 20 | 21 | 22 | -------------------------------------------------------------------------------- /gemsv/ch7-7/libgm/gmConst.h: -------------------------------------------------------------------------------- 1 | // gmConst.h - graphics math constants 2 | // 3 | // libgm++: Graphics Math Library 4 | // Ferdi Scheepers and Stephen F May 5 | // 15 June 1994 6 | 7 | #ifndef GMCONST_H 8 | #define GMCONST_H 9 | 10 | // USEFUL CONSTANTS 11 | 12 | float const gm2PI = 6.28318530717958623200f; 13 | float const gmDEGTORAD = 0.01745329251994329547f; 14 | float const gmE = 2.71828182845904553488f; 15 | float const gmEEXPPI = 23.14069263277927390732f; 16 | float const gmGOLDEN = 1.61803398874989490253f; 17 | float const gmINVPI = 0.31830988618379069122f; 18 | float const gmLN10 = 2.30258509299404590109f; 19 | float const gmLN2 = 0.69314718055994528623f; 20 | float const gmLOG10E = 0.43429448190325187218f; 21 | float const gmLOG2E = 1.44269504088896338700f; 22 | float const gmPI = 3.14159265358979323846f; 23 | float const gmPIDIV2 = 1.57079632679489655800f; 24 | float const gmPIDIV4 = 0.78539816339744827900f; 25 | float const gmRADTODEG = 57.29577951308232286465f; 26 | float const gmSQRT2 = 1.41421356237309514547f; 27 | float const gmSQRT2PI = 2.50662827463100024161f; 28 | float const gmSQRT3 = 1.73205080756887719318f; 29 | float const gmSQRT10 = 3.16227766016837952279f; 30 | float const gmSQRTE = 1.64872127070012819416f; 31 | float const gmSQRTHALF = 0.70710678118654757274f; 32 | float const gmSQRTLN2 = 0.83255461115769768821f; 33 | float const gmSQRTPI = 1.77245385090551588192f; 34 | float const gmEPSILON = 1.0e-10f; 35 | float const gmGOOGOL = 1.0e20f; 36 | 37 | #endif 38 | 39 | 40 | -------------------------------------------------------------------------------- /gemsv/ch7-7/vec-h/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(vec_h vec_h.c ) 2 | -------------------------------------------------------------------------------- /gemsv/ch7-7/vec-h/README: -------------------------------------------------------------------------------- 1 | README this file 2 | vec_h.c library (.h file) generator 3 | vec.h as produced by "cc vec_h.c -o vec_h; ./vec_h 4 >vec.h" 4 | -------------------------------------------------------------------------------- /getopt.h: -------------------------------------------------------------------------------- 1 | #ifndef GETOPT_H 2 | #define GETOPT_H 3 | 4 | int getopt(int nargc, char * const nargv[], const char *ostr) ; 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /math.c: -------------------------------------------------------------------------------- 1 | // On OS X and Linux libm.so has to be linked but it doesn't exist on Windows. 2 | 3 | int dummy; --------------------------------------------------------------------------------