From a727e1e56cdcecd32a07f301316875c6517b3d17 Mon Sep 17 00:00:00 2001 From: Gabriel Dunne Date: Wed, 30 Dec 2009 17:03:57 -0800 Subject: [PATCH] first checkin --- Makefile | 25 + SConstruct | 141 ++ intern/.sconsign | Bin 0 -> 15839 bytes intern/Global.cpp | 119 ++ intern/Global.h | 37 + intern/JChain.cpp | 119 ++ intern/JChain.h | 34 + intern/JImage.cpp | 125 ++ intern/JImage.h | 26 + intern/JMass.cpp | 39 + intern/JMass.h | 30 + intern/JPath.cpp | 161 ++ intern/JPath.h | 39 + intern/JPoint.cpp | 146 ++ intern/JPoint.h | 36 + intern/JoshFont.cpp | 1 + intern/JoshFont.h | 83 + intern/Thingy.cpp | 108 ++ intern/Thingy.h | 28 + intern/gl_et_al.h | 13 + intern/jttoolkit.cpp | 1 + intern/jttoolkit.h | 299 ++++ intern/project.cpp | 1 + intern/project.h | 0 intern/quadstretch.h | 27 + intern_disabled/ArrowVector.cpp | 157 ++ intern_disabled/ArrowVector.h | 27 + intern_disabled/Athletes.cpp | 48 + intern_disabled/Athletes.h | 22 + intern_disabled/BallPathTracer.cpp | 120 ++ intern_disabled/BallPathTracer.h | 32 + intern_disabled/BallPointer.cpp | 106 ++ intern_disabled/BallPointer.h | 24 + intern_disabled/Client.cpp | 73 + intern_disabled/Client.h | 34 + intern_disabled/Clover.cpp | 127 ++ intern_disabled/Clover.h | 34 + intern_disabled/DieingParent.cpp | 21 + intern_disabled/DieingParent.h | 30 + intern_disabled/Edie.cpp | 28 + intern_disabled/Edie.h | 24 + intern_disabled/FXImg.cpp | 183 ++ intern_disabled/FXImg.h | 30 + intern_disabled/FluxDiagram.cpp | 36 + intern_disabled/FluxDiagram.h | 23 + intern_disabled/GameGrid.cpp | 145 ++ intern_disabled/GameGrid.h | 29 + intern_disabled/Guy.cpp | 68 + intern_disabled/Guy.h | 31 + intern_disabled/GuyConnectors.cpp | 81 + intern_disabled/GuyConnectors.h | 23 + intern_disabled/GuyPointer.cpp | 31 + intern_disabled/GuyPointer.h | 21 + intern_disabled/JImageSequence.cpp | 56 + intern_disabled/JImageSequence.h | 30 + intern_disabled/JRect.cpp | 46 + intern_disabled/JRect.h | 25 + intern_disabled/NetTicket.cpp | 90 + intern_disabled/NetTicket.h | 35 + intern_disabled/NeuralHanger.cpp | 64 + intern_disabled/NeuralHanger.h | 42 + intern_disabled/OrniArrow1.cpp | 33 + intern_disabled/OrniArrow1.h | 24 + intern_disabled/OrniBubbleRing1.cpp | 36 + intern_disabled/OrniBubbleRing1.h | 24 + intern_disabled/OrniBubbleRing2.cpp | 35 + intern_disabled/OrniBubbleRing2.h | 24 + intern_disabled/OrniTriangle1.cpp | 41 + intern_disabled/OrniTriangle1.h | 24 + intern_disabled/Raster2Vector.cpp | 300 ++++ intern_disabled/Raster2Vector.h | 66 + intern_disabled/Satellite.cpp | 18 + intern_disabled/Satellite.h | 17 + intern_disabled/ShotProfile.cpp | 62 + intern_disabled/ShotProfile.h | 40 + intern_disabled/StatSign.cpp | 108 ++ intern_disabled/StatSign.h | 28 + intern_disabled/TheBall.cpp | 93 + intern_disabled/TheBall.h | 31 + intern_disabled/TreeNode.cpp | 99 ++ intern_disabled/TreeNode.h | 37 + intern_disabled/TreeOrniment.cpp | 39 + intern_disabled/TreeOrniment.h | 20 + intern_disabled/equationlayouts.h | 157 ++ intern_disabled/gl2ps.c | 2298 +++++++++++++++++++++++++ intern_disabled/gl2ps.h | 1 + intern_disabled/obj.cpp | 330 ++++ intern_disabled/obj.h | 95 + intern_disabled/quadstretch.cpp | 263 +++ intern_disabled/server_internals.c | 112 ++ intern_disabled/server_internals.h | 42 + intern_disabled/server_internals2.cpp | 88 + script/Info.plist.template.xml | 24 + script/appIt | 33 + script/bundle_depends.py | 77 + script/cpptemplate.cpp | 21 + script/create | 37 + script/findReplace.py | 10 + script/generate | 29 + script/headertemplate.h | 24 + script/objectsbuild_generated.mk | 72 + script/objectslist_generated.mk | 2 + script/objectslistbuild_generated.mk | 2 + 103 files changed, 8550 insertions(+) create mode 100755 Makefile create mode 100755 SConstruct create mode 100755 intern/.sconsign create mode 100755 intern/Global.cpp create mode 100755 intern/Global.h create mode 100755 intern/JChain.cpp create mode 100755 intern/JChain.h create mode 100755 intern/JImage.cpp create mode 100755 intern/JImage.h create mode 100755 intern/JMass.cpp create mode 100755 intern/JMass.h create mode 100755 intern/JPath.cpp create mode 100755 intern/JPath.h create mode 100755 intern/JPoint.cpp create mode 100755 intern/JPoint.h create mode 100755 intern/JoshFont.cpp create mode 100755 intern/JoshFont.h create mode 100644 intern/Thingy.cpp create mode 100644 intern/Thingy.h create mode 100755 intern/gl_et_al.h create mode 100755 intern/jttoolkit.cpp create mode 100755 intern/jttoolkit.h create mode 100755 intern/project.cpp create mode 100755 intern/project.h create mode 100755 intern/quadstretch.h create mode 100755 intern_disabled/ArrowVector.cpp create mode 100755 intern_disabled/ArrowVector.h create mode 100755 intern_disabled/Athletes.cpp create mode 100755 intern_disabled/Athletes.h create mode 100755 intern_disabled/BallPathTracer.cpp create mode 100755 intern_disabled/BallPathTracer.h create mode 100755 intern_disabled/BallPointer.cpp create mode 100755 intern_disabled/BallPointer.h create mode 100755 intern_disabled/Client.cpp create mode 100755 intern_disabled/Client.h create mode 100755 intern_disabled/Clover.cpp create mode 100755 intern_disabled/Clover.h create mode 100755 intern_disabled/DieingParent.cpp create mode 100755 intern_disabled/DieingParent.h create mode 100755 intern_disabled/Edie.cpp create mode 100755 intern_disabled/Edie.h create mode 100755 intern_disabled/FXImg.cpp create mode 100755 intern_disabled/FXImg.h create mode 100755 intern_disabled/FluxDiagram.cpp create mode 100755 intern_disabled/FluxDiagram.h create mode 100755 intern_disabled/GameGrid.cpp create mode 100755 intern_disabled/GameGrid.h create mode 100755 intern_disabled/Guy.cpp create mode 100755 intern_disabled/Guy.h create mode 100755 intern_disabled/GuyConnectors.cpp create mode 100755 intern_disabled/GuyConnectors.h create mode 100755 intern_disabled/GuyPointer.cpp create mode 100755 intern_disabled/GuyPointer.h create mode 100755 intern_disabled/JImageSequence.cpp create mode 100755 intern_disabled/JImageSequence.h create mode 100755 intern_disabled/JRect.cpp create mode 100755 intern_disabled/JRect.h create mode 100755 intern_disabled/NetTicket.cpp create mode 100755 intern_disabled/NetTicket.h create mode 100755 intern_disabled/NeuralHanger.cpp create mode 100755 intern_disabled/NeuralHanger.h create mode 100755 intern_disabled/OrniArrow1.cpp create mode 100755 intern_disabled/OrniArrow1.h create mode 100755 intern_disabled/OrniBubbleRing1.cpp create mode 100755 intern_disabled/OrniBubbleRing1.h create mode 100755 intern_disabled/OrniBubbleRing2.cpp create mode 100755 intern_disabled/OrniBubbleRing2.h create mode 100755 intern_disabled/OrniTriangle1.cpp create mode 100755 intern_disabled/OrniTriangle1.h create mode 100755 intern_disabled/Raster2Vector.cpp create mode 100755 intern_disabled/Raster2Vector.h create mode 100755 intern_disabled/Satellite.cpp create mode 100755 intern_disabled/Satellite.h create mode 100755 intern_disabled/ShotProfile.cpp create mode 100755 intern_disabled/ShotProfile.h create mode 100755 intern_disabled/StatSign.cpp create mode 100755 intern_disabled/StatSign.h create mode 100755 intern_disabled/TheBall.cpp create mode 100755 intern_disabled/TheBall.h create mode 100755 intern_disabled/TreeNode.cpp create mode 100755 intern_disabled/TreeNode.h create mode 100755 intern_disabled/TreeOrniment.cpp create mode 100755 intern_disabled/TreeOrniment.h create mode 100755 intern_disabled/equationlayouts.h create mode 100755 intern_disabled/gl2ps.c create mode 100755 intern_disabled/gl2ps.h create mode 100755 intern_disabled/obj.cpp create mode 100755 intern_disabled/obj.h create mode 100755 intern_disabled/quadstretch.cpp create mode 100755 intern_disabled/server_internals.c create mode 100755 intern_disabled/server_internals.h create mode 100755 intern_disabled/server_internals2.cpp create mode 100755 script/Info.plist.template.xml create mode 100755 script/appIt create mode 100755 script/bundle_depends.py create mode 100755 script/cpptemplate.cpp create mode 100755 script/create create mode 100755 script/findReplace.py create mode 100755 script/generate create mode 100755 script/headertemplate.h create mode 100755 script/objectsbuild_generated.mk create mode 100755 script/objectslist_generated.mk create mode 100755 script/objectslistbuild_generated.mk diff --git a/Makefile b/Makefile new file mode 100755 index 0000000..d9dbc71 --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +all: + scons + +clean: + scons -c;\ + figlet CLEAN ; + + +run: + make run_`uname` + + +debug: + make debug_`uname` + + +run_Darwin: + ./mouseamations + +run_CYGWIN_NT-5.1: + ./mouseamations.exe + +debug_CYGWIN_NT-5.1: + gdb ./mouseamations.exe + diff --git a/SConstruct b/SConstruct new file mode 100755 index 0000000..57addc9 --- /dev/null +++ b/SConstruct @@ -0,0 +1,141 @@ +import os,string,sys + +def framework(a): + return '/System/Library/Frameworks/'+a+'.framework/'+a + + +#load the list of used classes +sourcelist = [] +sl=os.listdir('./intern') +for i in sl: + s = string.split(i,'.') + if(s[1]=='cpp' or s[1]=='c'): + sourcelist = sourcelist + [i] + +for i in range(0,len(sourcelist)): + sourcelist[i]="intern/"+sourcelist[i] + +# look here for headers +cpppath=[ + '.', + '/usr/local/include', + '/opt/local/include', + '/opt/local/include/GraphicsMagick', + '/opt/local/include/libpng12', + '/opt/local/include/freetype2/', + '/opt/local/include/freetype2/', + '/usr/include/GraphicsMagick', + '/System/Library/Frameworks/ApplicationServices.framework/Headers', + '/cygdrive/c/Program Files/fmodapi375win/api/inc', + 'extern/myron/source', + 'extern/myron/ezcam', + ] + +# look here for libs +libpath = [ + '/usr/local/lib', + '/opt/local/lib', + '/usr/lib', +# '/sw/lib/freetype2/lib', +# '/sw/lib', + '/cygdrive/c/Program Files/fmodapi375win/api/lib', + 'extern/myron/ezcam', + ] + +# DLLs +if(sys.platform=='darwin'): + sourcelist += [ + framework('OpenGL'), + framework('GLUT'), + framework('Foundation'), + framework('ApplicationServices'), + framework('Carbon'), + framework('CoreServices'), + framework('QuickTime'), + '/opt/local/lib/libGraphicsMagick++.dylib', + '/opt/local/lib/libfreetype.6.dylib', + '/usr/lib/libz.1.1.3.dylib', + ] +else: + sourcelist += [ + '/usr/lib/libGraphicsMagick++.dll.a', + 'extern/myron/ezcam/myron_ezcam.dll', + 'extern/myron/myron.o', +] + +# static link libs (preferrable, add to conf check) +libs = [] + +# compiler args +ccflags=[ + "-Wno-deprecated", #don't warn about deprecated + "-w", #no warnings + ] + +if(sys.platform=='darwin'): + #OS-specific define until i find one already provided + ccflags.append( "-D__DARWIN__ -arch i386") + +#make new scons instance +env = Environment(CCFLAGS=ccflags,CPPPATH=cpppath,LIBS=libs,LIBPATH=libpath) + +#configure checks +conf = Configure(env) + +if(sys.platform=='darwin'): + pass +# if not conf.CheckLibWithHeader('freetype','freetype/freetype.h','c','',1): +# print 'freetype2 must be installed!' +# Exit(1) +else: #windows, so far + if not conf.CheckLibWithHeader('freetype','ft2build.h','c','',1): + print 'freetype2 must be installed!' + Exit(1) + if not conf.CheckLibWithHeader('opengl32','GL/gl.h','c','',1): + print 'OpenGL must be installed!' + Exit(1) + if not conf.CheckLibWithHeader('glut32','GL/glut.h','c','',1): + print 'OpenGL must be installed!' + Exit(1) + if not conf.CheckLibWithHeader('glu32','GL/glu.h','c','',1): + print 'OpenGL must be installed!' + Exit(1) + +if not conf.CheckCXXHeader('Magick++.h'): + print 'GraphicsMagick must be installed!' + Exit(1) + +if not conf.CheckLibWithHeader('png12','png.h','c++','',1): + print 'libpng12 must be installed!' + Exit(1) + + + +if not conf.CheckCXXHeader('openal/al.h'): + print 'try this: sudo port install openal' + Exit(1) + +#if not conf.CheckLibWithHeader('fmod','fmod.h','c','',1): +# print 'fmod must be installed!' +# Exit(1) + + +if not conf.CheckLibWithHeader('curl','curl/curl.h','c++','',1): + print 'libcurl must be installed!' + Exit(1) + + +env = conf.Finish() + +#the app +env.Program(target='mouseamations',source=sourcelist) + +#mac bundle post step +if(sys.platform=='darwin'): + env.AddPostAction('mouseamations', Action('script/appIt $TARGET')) +# env.AddPostAction('mouseamations', Action('script/bundle_depends.py $TARGET\.app/Contents/MacOS/$TARGET')) +# env.AddPostAction('mouseamations', Action('script/findReplace.py $TARGET\.app/Contents/MacOS/libGraphicsMagick.1.dylib /opt/local/share/GraphicsMagick-1.1.7/config/ ./././././././././././././././././././config/')) +# env.AddPostAction('mouseamations', Action('cp -r /opt/local/share/GraphicsMagick-1.1.7/config $TARGET\.app/Contents/Resources/config')) + env.Clean('mouseamations','mouseamations.app') + + diff --git a/intern/.sconsign b/intern/.sconsign new file mode 100755 index 0000000000000000000000000000000000000000..57cc950d64ec66f002e50d6d5a2f4ac2b811ae14 GIT binary patch literal 15839 zcmbuGcYq{Eb;bpVQ;rA_NWdUKS|QzS=OD7~B%wtD!QGGtQC(fNJ;&b8cI}*!8L)8x zV@$LGgXJtFKwvOQ2yAe`0Y@A#ID>HjY_M^{Heml=&CYDld1q|@Gt=R{*VR=o)q7u$ z+IuZ@PdIY38?5eY+IuhPgZl@o>-(NMsLj4B51xGa(f&$(^{O45+}>x<9zSaDyU;yp z*gs;{hw8{$yJzVOul)M{?(urPzucbC?Sw%Q#IY*NLTjB>MIPIzOmv(VIttRTY)?E| zbx&S8ba2h}hi2cPJ!zpq?#ZL}l!fl`l}I_Y+ljN#R%IMp8~cGI5OJ$vKg;o)#FSb0%@$Sa;@x+hk( zSu?BkdV6-Syjg>ENL%EE>=GkFD}s_V4OgHQ*mOsgP_llH;gj!`DHMPxIj zb(Ps9ip!L{D#(Mx>MCl_GfWGEY0vK_%a>fz+54>3!Cpr1j8;QaclO@c*{eHy2c7AA zZ#mR!YwbgL+x5Xwr_Fl%&|dqn?)`R7lu&gPv#>!Xuki3*dqKBjgDTRdN;4B=DpA%H zVWL^$IIVS|tDt>^VmVJ*bA!W14_VDe`qg~YsJ(Eqniuhoablt$#(AKtT(OWzUA2kYSdz3G?Ybn> zdFf1!WU8|*3zGNRV*0XMiOL=8aapf@3>p;`O4ntnO)&7&_2PAIu4&XxTYv%YAL3~II3kMs1#{^}w}i~UvYuVQWc zyN~<7a9(em8@P1@9O#~BZt|AxebnMuNf##$>x%A~)4^V&DzgI1mECiu*A8koSXsGT zIj&#Tz5n$3A%tFj6t^H=@5#+sQO&8p$haubFoZJ&z2R7sR& zTIaF0Wu>gjqO6Qm5ZGK*X_2%~!+y##h{Gx_0~1x&hDlH+xY!~MYjG`MdmTz!2Z>Tf zRgtQrDzTLcle{!6Z<1#^h}x&)$kH$=bXJCCj^$OB!J^z%U8Y7cwy=E$Dv~5QhN@K= z^O!P>W87Yy6)H5gRH|qX;+@MxnNr7986@HiiZIL~n_HXJQIyrTJ=C1Xh)Nsd))Jei zRh?Q}2a!!pfhksL#q_n^=E0^pzZ>joLK9WSy?Ip>1A1nIAA8mohd;gZY}Meno`d7c zR2`R99M+W~a>P}kVigDIewi?UqJ6G6l*`r1%03bKJZ~t^AGN)OX3x^s-g5DQhG1rb zA_~g7O2j@wTk6Wz8AnWT93@rUzF>>BHSP6Y$O}iU5+N77ZY*S`7E}m1Z8Jd0aI}|H zk6N=W*xIExyj5SZ5p0)PESnbi0#%7`(iuKYCo!=pBSa;ov2BCsQ#M5p+P)Wjc+|dV z;-6Q#oiqzFA=hb@mz9aFOk1pzBFa(n%C<+g`sdYNJD9qxP1#Mmw$(qkz1D5_&+EN* zxapsdVjd>URi^P<8AA^9GSqot3$!M#lRPx-4LkkwjlK4!IsEg@6aRcmH``UYHb+0` zY#z%3eA^Zu{o-CbntF%rWG~s_rC-`>znx_T>Bsm!XE;dZksw7h=tTIKaO#2;P z`JPG09Ee+bnO~Ie9JSvidh_Ms^;d}U=~&_2(~6jDg0w~vlYrbINzg-GWJ&woqI?@d z2JQEFAuk`buUKeUQ=O+tXu~wDg3{*N!W8DU3F|P|RcNyIdm9$=l~YeY9nANshP8WD z!*YFp!zvlP((OZuaA9P2u1U)``QubE@KuT{-0Gpv2`Hl2+FS&G*+ zEWqoh*1qM=8&t!D{{R|cOi7%NGn?AHiUX_Sq$o)sO{`Us*6k0K4{tNqTbHV{A8}yATz>>Ri&6pQ`#t}TgizcSZqezDl*;Gm@QwAAV zv7Dr6e^Mg&PaPwI-!@g@tq*A0xBZ_Z`|bbV$bQG}k^Sw*i0tq9pCb4>kLi-`oWAt- zsQ#|0I!&|YrhT^$^gk_u{yh@tBa_r5{WZ#-um>S`l?=YrmQ0vvT($3&K>suI1p4>Q z5m?_pM>6n%Ig)`7GV)o;z=!5Y2JV_8(0`cm%-X=*&3I;|0w0-Uv-D9(7B1V>pKsM{ zzYCfgl33}_O4{&q-3Lrlz)d@o+aL3}!^gXw%p@ic%ZQ9fMQKoEX=zeZ^)EB$h04+*uJW)TG6ZF+bxAT(u|2L!QmXb> z#JyZQIJ$1GJG!=JhQ>&I_*F0c*GBCp7n)m_PW<8p2O9AvX-d!}O^lN$A)$=wBunGK zu$N7(Np<_{#}GDXf5Qv=%~AVXK28LYDT<=1*etQf%aSZhYxbQs!?ke3w7)HJ;&&Fh z58RlxdyMW=&27z{&F#${&D)!IG;eF(*}SX4ln5ffD?#M!UaOk&PQ-^Mx;=VxZze=h4du9qCVd3|V(_>A>0ys*!W+RraEcIj&upMRhs zBUC{~e5a65CUwp>C9tMS(2q)G3eAYyzeL#C$9VTIcyWIk82^LJLV5 zdz6$7Pa^p<=|`N!DJfc!6nXnMh&y>{u-;rbSe4q!-+D1$9JOB(F<+8Y1~II+Ei&R9 z`xf>+N~wndnwlAWa7sFr zXDRViwO^IU_YVtb<2$$Mqt`}uaQ`Td{cGab^C)3Im4+ez#AKT$HG|VpXp6k6t!e*B z9Q!{nplKi8rfXi)&hI{US54dg8thwkBn$r{Zs=d9_H>W?|K|PB*XKwV{#|tJ%DuaW?(`;V14tN9{KzIsP|M3{~;c5fc`&i!9=Z)RKJyo7tkSWUKJ4tvUXG z_1tmyI_|iIV+B=rFYZi-zvJnRySLoEaPjE6lPbW<(b_Ct<YhXA* z7%rKM;qsM11;>f=zsdf=itGj4Ny4%?*Fz3Cb)%|Q%D{j(eZP=HxhdX8d zhh1d`N6gUO4A-f`wQsJ6T|L$Sm`)R>a4x1pH?Ns%c~)P;cl!Kqwx5c%lS(ygXUspw zYw=uTEjm+}7IqsW>LwaYiHm2PCFIc@D|6nwPpXX`IEwZ> z>HPV5R?PC4=OMx~&ooTC13c)V!ZeTC)OZuI=PK$GuBGUzi}Pmm}f!FYNJ-Q zy#2$4Wggx1MPL{%5QdB9P=0$8)Q=GAdF*(ZT&i)8oOd*RUR{R&C}EgqPFMQtGD8>6 zJD!z+xQC189gklL7#4(Ko;4dU9UK?W%`vEt`UvxA;h1NYj|^7(zO3ag`CqVXc;HKg zWgf*?Q{!A=uQ1GG%>9)9@~Rph^-oEKX`U&QW{VO-%;p`J zw4Y^M`Ml#AI<>lP2Tq<+2-7^8e011f=?^92Dd%Om!MOEtYIPYbTl&oIF`W0@V@1%` zZnJxwzy5f+KIu8TC&*bR2x*)Yb(RHTkh1v+G)HAY507$rQWx%tLbkp0?4IPsUCu9i z=~>lGx8FaA#vk3;Fe*c;8#I2D(o&oVqEaU+3yeG9$tYgr5lyKo%HVaSs(wKcMIrs#}mDj7+f z^9*;DCo9=e(-dGTELBcg8);#(9JVY{sfh#kWKTu|G|DaAD!Mxq8cad4oQ`@GSw^{}V%N?*mh53oq8MRBDZ8w~D%Zv>d9r{uov9-m<(g(%UdBvCE&v2NW72(d zPw`}l^js;Z$92Se(Q68ot!TVODK!=9JnkA#7V(TSOyVlgNtL7}TiCLy>MEdFQ?iuq zT2Dr2xekho5;0wa2wAaIifei?8BID9yQg}xk`he?0)k#)t!N;c9vgkVEYg<3Swf?ax~Z~xM)N~a5}``s4tlZz zT?hdI)D#!uuuv4QEE7j#q6nDw#2xZvtZq`VO{K{|7d56rRc2O0o`#IE2wm5cWkt$r z=K)O$XrnmDa~(w{sAyhRabn#wJz2yESa?b!Z15RZm@o!YD(W_>)M@FS<;g%b#F~+Z zyla%Dwu%c&{Ua|Z&)GWF?%AHqq7s?Tr5hV3NnD_jfD34e7C}xMwsg-KOUp`%98|dC zM5UM%SORb@kW)*HQy%(UPnMSm&~$rIkXZ0D86{@gE4oZ5%w?H-o+nGB>l#S?j2dE& zdSI=k36sPGVVa{M&mWV~apwJWSTh%4n(~T(HmcO3sI(i5>v=Maz|5U?ggF<9m>H^)Jee9hIz~}#+Oqys0;K;yX(i&Qd-kR09;20wxVp5gKyEi zY7u8?kYw(KV`)rm6kz6c#ki6(FX++=m?2ZNq>I8SPlmrsY>4g}hQmALih{PlZcykT z4oX*fvJ}rqcc-8-l?1W^biN^un2V?ctm3pML(}MuqmX5SK~syiIZCRkoWd(0l-kvv zEY7I!($m&8waJ`HZH@2YC1}>;z>3ltPsXcV<}k@8Qe}0yS^tg3B5VWJhZ)--->2G1E<)G?WXv?*d6v{pm%6(#JKIO zWI=FN8NFBnO`t4&%Fw;YlcjMSVV=gu(p&;>P^EMtc~^^LryuB6JXu|rAx&{Q|78#e zR3J7vF1Q8-M&q+A-4Rcg#Js40s7mR?gK#j3j*QI`%BIrvb*r8%3ec;F$e>uFJi;q+ zm{C}zfEj|hasy9>lLdv5Q2(YKhO?^^!9DPc6VM&Z&26Q5*F3AaGb01eO*$3x*{SqA4kSq3z##&KiPG^~-A*SNZ}%rjF}WtzD4 z@k1%JraDWR2EZKjUV(3fIBe_-^Ru}ddNNQEFsJm{4S}jw0FdDX` zf-+DhLRk%dqD~{sfa0A7m4(l9H;l4l)zo4naXkryrFeBdNRzofY9Vg zP~-hr3lMslNr6Y;k@MQ!jia1fVEYNK4j2b& z2Z#i(7rPfjwti$Y0RGK-Zd5dThvs+;<88w!-gOPi=KLxUd zd4?)Q2|(Z|@NBdlGN!I5MKzNmbFYAs%D4Mo;n-|zPD}FcmE72o?OSKekSbfWI60ag zknMh-Fl^u6PRO=043}4KUIQZKUNzSPhQn1bX?>~Zd_N4*Yjv;YfU3NEjr!A~%Nk-O3+dW3FrS$~7#Y#TS zUrK0qZ}4Q;O;QkdQNvP@Pq^tS2fRVM4iAzA?gu;>p)yS4nw2cclo+3(-%|na0BZrP zvvfZQne-}Wz%?f;M5A(YC>r@jxaknMH_5}MP|d9rZ|08l2;2_|Nk`lomW;p2O5&19 zv0bv#0#C!c+04B~=tbQ&p%d<{T=VMo!yJs@o=sp&5X08i9RHvxKBR%-y@86#M;Y&+!ggS00Dp-XqtsjrYnw zwqa?VqHRo}K}m@?0h=b0p#pbFC@9>|2qCudJ}>Al8dtt!zB@v7`U3Q+HdpffA_^V+ z0RPh#&{l#Ea>J|OhlHXtb7}7qdhhY3C_eXLu6Y%_n}d=2h(En`>5U&7w;tJkfiKL^ zV@#LHXJ-Ixkt_&*NSdMDM`1wZ8C#qFqBTD|k^6IA?#DLdzWesE8qVtOyN{3MPS>_^ zKR=Q93tr+c`qMp2UlGNofjbLU>3(S}@r>Y z@sH!qv^BsLWcxvMB)3UZlAIKECIzEg?S2FGpPYS8UGyS>;%E#u&=Q0 z_e3n<8Z3#8s|DB!)>T5NR|2RJKv>~^UkE|Z%mUT9KM=xAY{A`Qbiw)E$M4$n z-9Gh$&h~TB%1?`2OzIE$@1DD5QMNm#&v4rt)@Oxowj=r@p~njLY^>xTbMB4mPdFI4 zKlP`#E=^qK%z64V7!Y^rwvhDa6QO_Mg??^B=%l+pGXQ;lEOdwdH|{Sda=+l^{?&%u zZ+v>gQfDd2UvJ3WitUoQ{+o&1zx8sz=ubZ}4sM`ufIuoLA#6lJxkf>bdFcu`13HAV z7Pb4*SnlRmDvkT{MC9Ljk$>+`_bgqw57-4RVAhu&?ki)F<7FDSuTI4MgBSOY{uIk+ z+n-ZBAs1Is0j`%lB}Jh^@US{pk#=8$QY`4?2Cq!emDem8d5bOLp|8p4AzeA=-a4y}|CcH)tI@4(WAMy|^;6LRd zlMf80cfa9flGJ=tZqJVG-x7K>^|Y;v-?;zcve*CP?k)O%FMhXTYG(n_+`VDgDRtoP zBDvi!^EE2%(P71(oubVXD#z5Jo+BD*w2O85lcv8f2zG2CzH|Jo=h#fVFAGNyBJy6ItzbSI(a^7 zCJ*M~7T~%&&y$`nq}vMh5AoL@D%Yol`iIF`hqW;=*%@W)1UOLuUOEOCMmaB~RvyN# zBV;=Y^$+*rF7N`>tdjX7AltySyGIJkzFjSEV;(!>e_6Lj3Df2__d-s4?jpH3`FLiN zc7e+~cDEOM`bP^rxt_w2Q2eFBP1%YnG1WofiDwS{19vIc{i^Qe zVC44s(-ryFk8j=BUP-+@puB7O3W0n_=U~j)$0TkMNYu_go_XfD$S7R&1$DHhNSSs78@H6odsT#28&sxl{;m?758p1^J|< zE@&{Md}1Nx!MscW|~nzD4@mNp=8_MaM0OyD$82R<6hiz zm+?PEWZi@6G29j0qI;~6&4dWL#|gbG;5KMl;~vj-zkpBRVC0_YPxma{^~rG>JnO3< z_aqoL&Af4!Pvq_Q@(#%9mQPFF6Q;AbWPT6ZPq=wDRRtx#-zr0GGCo_0p5bLvk7 za@rW~D#&=u9-r|J+>=GD6jrY0VC0tkDWR56g6M?!Z5dx$CKc&rnb6J(OZKEj#qKFk zN~pcYbKKtCao8u%cQ&^j_IdF(v@22fTA?TEK2`pSy7Up~(4ZE&0+A`-cF`LWpl+b~ zyerJy(}a+yd!2s(h}OeCoxQtx-(jDHZo{|Einimo^@*q7;XYl26K$Wt|I{WtktohV zuKG0dkldd6os;Vd{XJ~DanIzspWJ70FmliKr*`R8=X`6wpiyVq%X45r>`9y6=eZM! z&+`(WFQpX8vjGNm{crty|LV#*vQ7cU?To{ zFaCv_;*a~>R6Kaukc|xLAO&w(E;ieS%B9ixb($G!EdJE##{)8_)kL)RqHBM8>(WOB qnM+M!)~B@2jD?Q%wsCeMZrO`#{3&0Ry>z = ((rnd[i+7]-.5)*1000000); + } +} + + + +Global::~Global(){ +} + + +void Global::loop(){ + vector::iterator it; + + + int cnt=0; + /* + for(it=thingies.begin();it!=thingies.end();it++){ + + (*it)->step(); + (*it)->draw(); + (*it)->x = rnd[cnt] * width(); + (*it)->y = rnd[cnt] * height(); + (*it)->z = 0; //(rnd[cnt]-.5)*1000; // ( ((rnd[cnt]-.5)*10) + ( (mouseX()-(width()/2)) * .085 ) ); + //(*it)->dest.z = (rnd[cnt]-.5)*1000; //( ((rnd[cnt]-.5)*10) + ( (mouseX()-(width()/2) ) * .085 ) ); + cnt++; +} +*/ + + for(int i=0; ix = rnd[i]*width(); + thingies[i]->y = rnd[i+3]*height(); + + + thingies[i]->z += ((mouseX()-(width()/2))*.04); + + thingies[i]->step(); + thingies[i]->draw(); + } + + + + glColor4f(1,1,1, 0.1); + glBegin(GL_LINE_STRIP); + for(it=thingies.begin();it!=thingies.end();it++){ + (*it)->glVertex(); + } + glEnd(); + + + + glColor4f(1,1,1, 1); + glBegin(GL_POINTS); + for(it=thingies.begin();it!=thingies.end();it++){ + (*it)->glVertex(); + } + glEnd(); + + + + +} + + +void Global::keyDown(int k,int special){ + char s[256]; + sprintf(s, "god.%04i.png", ticks()); + cout << s << endl; + saveScreen(s); + +} + + +void Global::mouseDown(){ + rnd.clear(); + for(int i=0;i<1000;i++){ + rnd.push_back(randomFloat()); + } + vector::iterator it; + + int cnt = 0; + for(it=thingies.begin();it!=thingies.end();it++){ + (*it)->resetRandoms(); + (*it)->z = ((rnd[cnt+7]-.5)*9000000); + cnt++; + } + +} +void Global::mouseUp(){ +} + diff --git a/intern/Global.h b/intern/Global.h new file mode 100755 index 0000000..5d89516 --- /dev/null +++ b/intern/Global.h @@ -0,0 +1,37 @@ +#ifndef _Global_H_ +#define _Global_H_ + +#include +#include +#include +#include "JImage.h" +#include "JMass.h" +#include "JPath.h" +#include "JChain.h" +#include "Thingy.h" + +using namespace std; +using namespace Magick; + +class Global{ + public: + + /** + the one and only static global instance of the Global object. + refer to me as `Global::instance` + */ + + + static Global*instance; + vectorthingies; + vector rnd; + void loop(); + void keyDown(int k,int special); + void mouseDown(); + void mouseUp(); + Global(); + ~Global(); +}; + +#endif + diff --git a/intern/JChain.cpp b/intern/JChain.cpp new file mode 100755 index 0000000..24c752c --- /dev/null +++ b/intern/JChain.cpp @@ -0,0 +1,119 @@ +#include "JChain.h" +#include "JPath.h" +#include "jttoolkit.h" +#include "Global.h" + +JChain::JChain(deque m,float v){ + strength=v; + src=new JPoint(); + dst= new JPoint(); + deque::iterator it; + for(it=m.begin();it!=m.end();it++){ + masses.push_back(*it); + } +} + +JChain::JChain(float v){ + strength=v; + src=new JPoint(); + dst= new JPoint(); +} + + + + +JChain::~JChain(){ + delete src; + delete dst; +} + +void JChain::step(){ + + for(int i=0;ispringTo(*src,strength); + else masses[i]->springTo(*masses[i-1],strength); + } + for(int i=masses.size()-1;i>=0;i--){ + if(i==masses.size()-1)masses[i]->springTo(*dst,strength); + else masses[i]->springTo(*masses[i+1],strength); + } + +} + +void JChain::draw(int type){ + glBegin(type); + src->glVertex(); + for(int i=0;iglVertex(); + } + dst->glVertex(); + glEnd(); +} + + +// smooth with JPath +// added by g-done +void JChain::drawSmooth(int type, int v){ + + JPath smoothed(masses); + + smoothed.smooth(v); + + glBegin(type); + src->glVertex(); + smoothed.glVertex(); + dst->glVertex(); + glEnd(); +} + +void JChain::drawScrewey(int type, int v, float rnd){ + + JPath smoothed(masses); + + smoothed.smooth(1); + + glBegin(type); + src->glVertex(); + + deque::iterator it; + int i=0; + for(it=smoothed.points.begin(); it!=smoothed.points.end();it++){ + + float xx = (*it)->x + (Global::instance->rnd[i]-.5) * v * rnd; + float yy = (*it)->y + (Global::instance->rnd[i]-.5) * v * rnd; + float zz = (*it)->z + (Global::instance->rnd[i]-.5) * v * rnd; + glVertex3f(xx,yy,zz); + i++; + } + + dst->glVertex(); + glEnd(); +} + + + + + +void JChain::jitterFluff(float s, float r){ + + deque::iterator it; + + int i=0; + + for(it=masses.begin(); it!=masses.end(); it++){ + + float ox = (*it)->x; + float oy = (*it)->y; + + (*it)->x += sin(ticks()*s*Global::instance->rnd[i]) * r; + (*it)->y += cos(ticks()*s*Global::instance->rnd[i]) * r; + + i++; + + } +} + + + + + diff --git a/intern/JChain.h b/intern/JChain.h new file mode 100755 index 0000000..873e13f --- /dev/null +++ b/intern/JChain.h @@ -0,0 +1,34 @@ +#ifndef _JChain_H_ +#define _JChain_H_ + + +#include "JMass.h" +#include +#include + +using namespace std; + +class JChain{ + public: + float strength; + JPoint *src; + JPoint *dst; + deque masses; + JChain(deque,float); + JChain(float); + ~JChain(); + + JChain* makeSmooth(int); + + void step(); + void draw(int); + void drawSmooth(int,int); + void drawScrewey(int,int,float); // draw type, variance, individual random + void jitterFluff(float,float); + +}; + + + +#endif + diff --git a/intern/JImage.cpp b/intern/JImage.cpp new file mode 100755 index 0000000..17b993b --- /dev/null +++ b/intern/JImage.cpp @@ -0,0 +1,125 @@ +#include "JImage.h" +#include "gl_et_al.h" +#include "jttoolkit.h" + + +void JImage::initMem(){ + listID=0; +} + + +void JImage::load(char *fname){ + read(fname); + modifyImage(); + type(TrueColorType); + pixels = getPixels(0,0,columns(),rows()); + update(); +} + +JImage::JImage(){ + initMem(); +} + +JImage::JImage(char *file){ + initMem(); + load(file); +} + +void JImage::update(){ + update(false); +} + +void JImage::update(int alphaOnly){ + syncPixels(); + //kill it first if needed + deleteGLResources(); + + //RE-ORDER THE PIXELS FOR OPENGL + GLfloat *f = new GLfloat[columns()*rows()*4]; + + if(!alphaOnly){ + + for(int y=0;y +#include "jttoolkit.h" + +using namespace Magick; +using namespace std; + +class JImage : public Image{ + private: + void deleteGLResources(); + public: + PixelPacket *pixels; + GLuint textureID; + GLuint listID; + void update(); + void initMem(); + void load(char *); + void update(int alphaOnlyBool); + void drawList(); + JImage(); + JImage(char *filename); + ~JImage(); +}; +#endif diff --git a/intern/JMass.cpp b/intern/JMass.cpp new file mode 100755 index 0000000..ce87597 --- /dev/null +++ b/intern/JMass.cpp @@ -0,0 +1,39 @@ +#include "JMass.h" +#include "jttoolkit.h" +#include "Global.h" + +JPoint JMass::friction(0.99,0.99,0.99); +JPoint JMass::gravity(0,1,0); + +JMass::JMass(float xx,float yy,float zz):JPoint(xx,yy,zz){ +} + +JMass::JMass(JPoint p):JPoint(p){ +} + +JMass::JMass():JPoint(0){ +} + +JMass::~JMass(){ + +} + +void JMass::step(){ + (*this)+=force; + force+=gravity; + force*=friction; +} + +void JMass::draw(){ +} + + +void JMass::applyForce(JPoint that){ + force += that; +} + + +void JMass::springTo(JPoint that,float strength){ + applyForce((that-(*this))*strength); + +} diff --git a/intern/JMass.h b/intern/JMass.h new file mode 100755 index 0000000..dda1dd8 --- /dev/null +++ b/intern/JMass.h @@ -0,0 +1,30 @@ +#ifndef _JMass_H_ +#define _JMass_H_ + + +#include "JPoint.h" +#include + +using namespace std; + +class JMass : public JPoint{ + public: + static JPoint friction; + static JPoint gravity; + + JPoint force; + JMass(float,float,float); + JMass(JPoint); + JMass(); + ~JMass(); + + void step(); + void draw(); + void applyForce(JPoint p); + void springTo(JPoint p,float strength); +}; + + + +#endif + diff --git a/intern/JPath.cpp b/intern/JPath.cpp new file mode 100755 index 0000000..96e0031 --- /dev/null +++ b/intern/JPath.cpp @@ -0,0 +1,161 @@ +/** + JPath + by Josh Nimoy + for Gabe Dunne + 23 jan 2007 +*/ + +#include "JPath.h" +#include "JMass.h" +#include "jttoolkit.h" +#include "Global.h" + +JPath::JPath(dequep){ + //make a deep copy of that vector + deque::iterator it; + for(it=p.begin();it!=p.end();it++){ + points.push_back(new JPoint(**it)); + } +} +JPath::JPath(vectorp){ + //make a deep copy of that vector + vector::iterator it; + for(it=p.begin();it!=p.end();it++){ + points.push_back(new JPoint(**it)); + } +} +JPath::JPath(dequep){ + //make a deep copy of that vector + deque::iterator it; + for(it=p.begin();it!=p.end();it++){ + points.push_back(new JPoint(**it)); + } +} + + + + +JPath::~JPath(){ + deque::iterator it; + for(it=points.begin();it!=points.end();it++){ + delete *it; + } +} + +/** + divide all edges in 2. +*/ +void JPath::subdiv(){ + dequedest; + deque::iterator it; + int i=0; + for(it=points.begin();it!=points.end();it++){ + dest.push_back(*it); + if(ilerpTo(**(it+1),0.5) )); + } + i++; + } + + + + + + //ok, now copy dest back into points + points.clear(); + for(it=dest.begin();it!=dest.end();it++){ + points.push_back(*it); + } + +} + + +/** + loop through all the verts and call glVertex3f(x,y,z); +*/ +void JPath::glVertex(){ + deque::iterator it; + /** + JPath + by Josh Nimoy + for Gabe Dunne + 23 jan 2007 +*/ + + +#ifndef _JPath_H_ +#define _JPath_H_ + +#include "JPoint.h" +#include "JMass.h" +#include +#include + +using namespace std; + +class JPath{ + public: + dequepoints; + + + JPath(vector); + JPath(deque); + JPath(deque); + + ~JPath(); + + void melt(float heat); + void subdiv(); + void glVertex(); + void smooth(int val); +}; + + + +#endif + + for(it=points.begin();it!=points.end();it++){ + (*it)->glVertex(); + } + +} + + +/* + lerping towards the previous and next points, we are effectively + melting the geometry toward the center. +*/ +void JPath::melt(float heat){ + //draw handles + + deque::iterator it; + int i=0; + + for(it=points.begin();it!=points.end();it++){ + + JPoint *curr = *it; + JPoint *prev; + JPoint *next; + + if(i>0)prev=*(it-1); + else prev=curr; + + if(ilerpSelfTo(*prev,heat); + curr->lerpSelfTo(*next,heat); + + i++; //keep this close to the end curly bracket. + } + + + +} + +void JPath::smooth(int val){ + for(int i=0;i +#include + +using namespace std; + +class JPath{ + public: + dequepoints; + + + JPath(vector); + JPath(deque); + JPath(deque); + + ~JPath(); + + void melt(float heat); + void subdiv(); + void glVertex(); + void smooth(int val); +}; + + + +#endif + diff --git a/intern/JPoint.cpp b/intern/JPoint.cpp new file mode 100755 index 0000000..4d1cf1d --- /dev/null +++ b/intern/JPoint.cpp @@ -0,0 +1,146 @@ +#include "JPoint.h" +#include "gl_et_al.h" +#include "math.h" + +#include +using namespace std; + +JPoint JPoint::rotateZ(float deg,JPoint pivot){ + float r = distanceFrom(pivot); + float theta = pivot.thetaFrom(*this) + deg; + return JPoint( + r*cos(theta), + r*sin(theta), + 0 + ); +} + +JPoint JPoint::lerpTo(JPoint p,float lerpVal){ + cout << p.x << ' ' << p.y << ' ' << p.z < 2 ){ texturesize = 4; } else if(lettersize<= 8 &&lettersize> 4 ){ texturesize = 8; } else if(lettersize<= 16 &&lettersize> 8 ){ texturesize = 16; } else if(lettersize<= 32 &&lettersize> 16 ){ texturesize = 32; } else if(lettersize<= 64 &&lettersize> 32 ){ texturesize = 64; } else if(lettersize<= 128 &&lettersize> 64 ){ texturesize = 128; } else if(lettersize<= 256 &&lettersize> 128 ){ texturesize = 256; } else if(lettersize<= 512 &&lettersize> 256 ){ texturesize = 512; } else { texturesize = 1024; } base = glGenLists(256); //load the images into textures and make them into gllists. int err = FT_Init_FreeType(&ft_library); if(err){ printf("error initializing freetype2: %i\n",err); exit(0); } err = FT_New_Face(ft_library,file,0,&ft_face); if(err==FT_Err_Unknown_File_Format){ printf("error: the font file could be\ opened and read, but it appears that its font format is unsupported\n"); return err; } else if(err){ printf("error opening font: %i\n",err); return err; } //report // printf("font info:\n",0); // printf(" num_faces: %i\n",ft_face->num_faces); // printf(" num_glyphs: %i\n",ft_face->num_glyphs); // printf(" units_per_EM: %i\n",ft_face->units_per_EM); // printf(" size: %i\n",ft_face->size); //generate a sample bitmap err = FT_Set_Pixel_Sizes(ft_face,0,lettersize); if(err)printf("there was an error\n: %i\n",err); units_per_EM = ft_face->units_per_EM; ascender = ft_face->ascender; descender = ft_face->descender; //now render all 256 characters for(int i=0;i<256;i++){ //err = FT_Load_Char(ft_face,'4',FT_LOAD_RENDER); int glyph_index = FT_Get_Char_Index(ft_face, i); err = FT_Load_Glyph(ft_face,glyph_index,FT_LOAD_DEFAULT ); if(err)printf("there was an error\n: %i\n",err); #if defined(__DARWIN__) #define RENDER_NORMAL FT_RENDER_MODE_NORMAL #else #define RENDER_NORMAL ft_render_mode_normal #endif FT_Glyph g; FT_Get_Glyph (ft_face->glyph, &g); err = FT_Render_Glyph(ft_face->glyph,RENDER_NORMAL); if(err)printf("there was an error\n: %i\n",err); FT_GlyphSlot slot = ft_face->glyph; //printf("rows: %i\n",slot->bitmap.rows); //printf("width: %i\n",slot->bitmap.width); //printf("pitch: %i\n",slot->bitmap.pitch); if( ft_glyph_format_outline != g->format){ //printf("not outline format\n"); } else { //printf("yes outline format\n"); } //do something with the vectors. FT_OutlineGlyph outline = (FT_OutlineGlyph)g; FT_Outline ftOutline = outline->outline; //make tex from loading the bitmap buffer into openGL. if(!antialiased){ //do a posterize filter on the bitmap. for(ii=0;iibitmap.rows*slot->bitmap.width;ii++){ if(slot->bitmap.buffer[ii]>128){ slot->bitmap.buffer[ii] = 255; } else { slot->bitmap.buffer[ii] = 0; } } } //record kerning info. charWidths[i] = ((float)(slot->metrics.width)/(float)((texturesize*64))); charHeights[i] = ((float)(slot->metrics.height)/(float)((texturesize*64))); charHoriBearingYs[i] = ((float)(slot->metrics.horiBearingY)/(float)((texturesize*64))); charHoriBearingXs[i] = ((float)(slot->metrics.horiBearingX)/(float)((texturesize*64))); charHoriAdvances[i] = ((float)(slot->metrics.horiAdvance)/(float)((texturesize*64))); if(i=='\t')charHoriAdvances[i] = 4; charVertBearingYs[i] = ((float)(slot->metrics.vertBearingY)/(float)((texturesize*64))); charVertBearingXs[i] = ((float)(slot->metrics.vertBearingX)/(float)((texturesize*64))); charVertAdvances[i] = ((float)(slot->metrics.vertAdvance)/(float)((texturesize*64))); //printf("%c %f\n",i,charHoriBearingYs[i]); int tex; if(renderstyle==JF_BITMAP){ tex = loadBitmapCharRAWFromMemory(slot->bitmap.buffer, texturesize,texturesize,slot->bitmap.width, slot->bitmap.rows,mipmap); }else if(renderstyle==JF_VECTOR){ tex = 0; } //int tex = 0; //persisPts = new Vector(); glNewList(base+i,GL_COMPILE); float trans = -1.0; if(renderstyle==JF_BITMAP){ //textures[i] = tex; if(tex!=0){ glTranslatef(0,trans,0); glBindTexture(GL_TEXTURE_2D,tex); glBegin(GL_QUADS); glTexCoord2f(0,0); glVertex2f(0,0); glTexCoord2f(1,0); glVertex2f(1,0); glTexCoord2f(1,1); glVertex2f(1,1); glTexCoord2f(0,1); glVertex2f(0,1); glEnd(); glBindTexture(GL_TEXTURE_2D,0); glTranslatef(0,-trans,0); } } //debugging tool // if(0){ // if(ftOutline.n_points>0){ // glBindTexture(GL_TEXTURE_2D,0); // //glColor3f(0,0,0); // glDisable(GL_BLEND); // JTTessBegin(); // if(ftOutline.n_contours>0){ // int curContourIndex=0; // int curCloser = ftOutline.contours[0]; // for(int cii=0;ciiglyph, &g); //err = FT_Render_Glyph(ft_face->glyph,RENDER_NORMAL); //if(err)printf("there was an error\n: %i\n",err); FT_GlyphSlot slot = ft_face->glyph; // printf("rows: %i\n",slot->bitmap.rows); // printf("width: %i\n",slot->bitmap.width); // printf("pitch: %i\n",slot->bitmap.pitch); if( ft_glyph_format_outline != g->format){ //printf("not outline format\n"); } else { //printf("yes outline format\n"); } //do something with the vectors. FT_OutlineGlyph outline = (FT_OutlineGlyph)g; FT_Outline ftOutline = outline->outline; //debugging incompat btwn tess and font paths. //now this is the VECTOR VERSION of the preceding rendering routine! glBindTexture(GL_TEXTURE_2D,0); //glColor3f(0,0,0); //glDisable(GL_BLEND); JTTessBegin(); //printf("contours:%i\n", ftOutline.n_points); if(ftOutline.n_contours>0){ //first copy all the points into their own gluTess compatible persistent points. float w = ascender/(64.0*lettersize)-charHoriBearingYs[i]; //glPushMatrix(); //glTranslatef(0,w,0); //GLUtesselator*tess = getTessObj(); ///gluTessBeginPolygon(tess,NULL); //gluTessBeginContour(tess); //for(int j=0;j<5;j++){ //} int curContourIndex=0; int curContour=ftOutline.contours[0]; int bezcount = 0; int bezaccum[64]; for(int ii=0;ii0)?(ftOutline.contours[curContourIndex-1]+1):0); if (thisp==virtualfirst) {//the one after the last contour's end, or the very first one in the whole array. controlPoints[0][0] = ftOutline.points[curContour].x; controlPoints[0][1] = ftOutline.points[curContour].y; controlPoints[2][0] = ftOutline.points[thisp+1].x; controlPoints[2][1] = ftOutline.points[thisp+1].y; } else if (thisp==curContour) { controlPoints[0][0] = ftOutline.points[thisp-1].x; controlPoints[0][1] = ftOutline.points[thisp-1].y; controlPoints[2][0] = ftOutline.points[virtualfirst].x; controlPoints[2][1] = ftOutline.points[virtualfirst].y; } else { controlPoints[0][0] = ftOutline.points[thisp-1].x; controlPoints[0][1] = ftOutline.points[thisp-1].y; controlPoints[2][0] = ftOutline.points[thisp+1].x; controlPoints[2][1] = ftOutline.points[thisp+1].y; } for( unsigned int bi = 0; bi <= ( 1.0f / BEZIER_STEP_SIZE); bi++){ float t = static_cast(bi) * BEZIER_STEP_SIZE; bezierValues[0][0] = (1.0f - t) * controlPoints[0][0] + t * controlPoints[1][0]; bezierValues[0][1] = (1.0f - t) * controlPoints[0][1] + t * controlPoints[1][1]; bezierValues[1][0] = (1.0f - t) * controlPoints[1][0] + t * controlPoints[2][0]; bezierValues[1][1] = (1.0f - t) * controlPoints[1][1] + t * controlPoints[2][1]; bezierValues[0][0] = (1.0f - t) * bezierValues[0][0] + t * bezierValues[1][0]; bezierValues[0][1] = (1.0f - t) * bezierValues[0][1] + t * bezierValues[1][1]; //AddPoint( bezierValues[0][0], bezierValues[0][1]); GLdouble d[12]; d[0] = (bezierValues[0][0]/(64.0*lettersize)+0.000001); d[1] = -(bezierValues[0][1]/(64.0*lettersize))-w; d[2] = 0; d[3] = 0; //persisPts->push((long)d); JTTessVertex(d[0],d[1],0); }//end of beszier function /* GLdouble d[12]; d[0] = (ftOutline.points[thisp].x/(64.0*lettersize)+ii*0.0001); d[1] = -(ftOutline.points[thisp].y/(64.0*lettersize)+ii*0.0001)-w; d[2] = 0; d[3] = 0; JTTessVertex(d[0],d[1],0); */ //add a moveTo if(curContour==thisp){ //persisPts->push(0); JTTessNewContour(); curContourIndex++; curContour=ftOutline.contours[curContourIndex]; } // }//end of looping through all the involved conic pts in this path chunk. } bezcount = 0; //then finally take care of this on-point. GLdouble d[12]; d[0] = (ftOutline.points[ii].x/(64.0*lettersize)+ii*0.0001); d[1] = -(ftOutline.points[ii].y/(64.0*lettersize)+ii*0.0001)-w; d[2] = 0; d[3] = 0; //persisPts->push((long)d); JTTessVertex(d[0],d[1],0); if(curContour==ii){ //persisPts->push(0); JTTessNewContour(); curContourIndex++; curContour=ftOutline.contours[curContourIndex]; } } else { if(ftOutline.tags[ii]!=FT_Curve_Tag_Conic){ printf("encountered a non-FT_Curve_Tag_Conic\n",0); } bezaccum[bezcount]=ii; bezcount++; } } //one last checl for the chunks if(bezcount!=0){ //new mutli bez event. for(int thisB=0;thisB0)?(ftOutline.contours[curContourIndex-1]+1):0); if (thisp==virtualfirst) {//the one after the last contour's end, or the very first one in the whole array. controlPoints[0][0] = ftOutline.points[curContour].x; controlPoints[0][1] = ftOutline.points[curContour].y; controlPoints[2][0] = ftOutline.points[thisp+1].x; controlPoints[2][1] = ftOutline.points[thisp+1].y; } else if (thisp==curContour) { controlPoints[0][0] = ftOutline.points[thisp-1].x; controlPoints[0][1] = ftOutline.points[thisp-1].y; controlPoints[2][0] = ftOutline.points[virtualfirst].x; controlPoints[2][1] = ftOutline.points[virtualfirst].y; } else { controlPoints[0][0] = ftOutline.points[thisp-1].x; controlPoints[0][1] = ftOutline.points[thisp-1].y; controlPoints[2][0] = ftOutline.points[thisp+1].x; controlPoints[2][1] = ftOutline.points[thisp+1].y; } for( unsigned int bi = 0; bi <= ( 1.0f / BEZIER_STEP_SIZE); bi++){ float t = static_cast(bi) * BEZIER_STEP_SIZE; bezierValues[0][0] = (1.0f - t) * controlPoints[0][0] + t * controlPoints[1][0]; bezierValues[0][1] = (1.0f - t) * controlPoints[0][1] + t * controlPoints[1][1]; bezierValues[1][0] = (1.0f - t) * controlPoints[1][0] + t * controlPoints[2][0]; bezierValues[1][1] = (1.0f - t) * controlPoints[1][1] + t * controlPoints[2][1]; bezierValues[0][0] = (1.0f - t) * bezierValues[0][0] + t * bezierValues[1][0]; bezierValues[0][1] = (1.0f - t) * bezierValues[0][1] + t * bezierValues[1][1]; //AddPoint( bezierValues[0][0], bezierValues[0][1]); GLdouble d[12]; d[0] = (bezierValues[0][0]/(64.0*lettersize)+thisp*0.000001); d[1] = -(bezierValues[0][1]/(64.0*lettersize))-w; d[2] = 0; d[3] = 0; //persisPts->push((long)d); JTTessVertex(d[0],d[1],0); }//end of beszier function /* GLdouble d[12]; d[0] = (ftOutline.points[thisp].x/(64.0*lettersize)+ii*0.0001); d[1] = -(ftOutline.points[thisp].y/(64.0*lettersize)+ii*0.0001)-w; d[2] = 0; d[3] = 0; JTTessVertex(d[0],d[1],0); */ //add a moveTo if(curContour==thisp){ //persisPts->push(0); JTTessNewContour(); curContourIndex++; curContour=ftOutline.contours[curContourIndex]; } // }//end of looping through all the involved conic pts in this path chunk. } bezcount = 0; //end lasst chunk check } //glPopMatrix(); //---------------------now actually draw the processed vertexes. /* GLUtesselator*tess = getTessObj(); gluTessBeginPolygon(tess,NULL); gluTessBeginContour(tess); for(int ii=0;iicount;ii++){ GLdouble *pi = (GLdouble*)persisPts->get(ii); if(pi==0){ gluTessEndContour(tess); //gluTessEndPolygon(tess); //empty space //gluTessBeginPolygon(tess,NULL); gluTessBeginContour(tess); } else { gluTessVertex(tess,pi,pi); } } gluTessEndContour(tess); gluTessEndPolygon(tess); */ /* for(int ii=0;iicount;ii++){ GLdouble *pi = (GLdouble*)persisPts->get(ii); if(pi==0){ JTTessNewContour(); } else { JTTessVertex(pi[0], pi[0],0); } } */ JTTessEnd(); } } void JoshFont::drawStringFittedBox(char *inputstr,float right,float bottom){ glPushMatrix(); glScalef((right/getStringWidth(inputstr,1)),(bottom/charHeights['H']),0); glTranslatef(0,charHeights['H']*2.38,0); drawString(inputstr,1,0); glPopMatrix(); } void JoshFont::drawString(char *inputstr,float size,float tracking){ glPushMatrix(); glPushMatrix(); glScalef(size,size,0); //glTranslatef( -(1.0-offx/255.0) , -(1.0-offy/255.0) , 0 ); int lineno = 1; for(int i=0;idrawChar(inputstr[i]); glPopMatrix(); glTranslatef( (float)(charHoriAdvances[inputstr[i]]) ,0,0); } } glPopMatrix(); glPopMatrix(); } void JoshFont::drawStringBoxWrap(char *inputstr,float size,float tracking, float right,float bottom,int quickrender){ glPushMatrix(); glTranslatef(0,round(tracking*size)*2,0); glPushMatrix(); glScalef(size,size,0); //glTranslatef( -(1.0-offx/255.0) , -(1.0-offy/255.0) , 0 ); int lineno = 1; float lineadvance = 0; int line_wordcount=0; int strln = strlen(inputstr); for(int i=0;iright||curPlace>=strln){ // break; // } else { // theoretical_line += theoretical_word; // } // } // //now we have the current line. How much longer is the full width of the box? // thisFJ = (right-theoretical_line*size)/(float)wordcount; if(thisChar==13||thisChar==10){ glPopMatrix(); lineno++; glTranslatef(0,round(tracking*size),0); glPushMatrix(); glScalef(size,size,0); lineadvance=0; line_wordcount=0; } else { //calculate the would-be resultant adanvace of the current word. float theoretical_advance = lineadvance; int curPlace = i-1; while(1){ curPlace++; //break if we got too far. if(!(curPlaceright && line_wordcount>0 ){//shall we soft-wrap? glPopMatrix(); lineno++; glTranslatef(0,round(tracking*size),0); glPushMatrix(); glScalef(size,size,0); lineadvance=0; line_wordcount=0; } glPushMatrix(); if(quickrender){ if(thisChar!=' '&&thisChar!='\t'){ glTranslatef(charHoriBearingXs[thisChar], -(float)tracking,0); glBegin(GL_LINES); glVertex3f(0,0,0); glVertex3f(1,1,0); glVertex3f(1,0,0); glVertex3f(0,1,0); glEnd(); } } else{ glTranslatef(charHoriBearingXs[thisChar], -(float)charHoriBearingYs[thisChar],0); //glScalef(i*0.05,i*0.05,1); this->drawChar(inputstr[i]); if(thisChar==' '||thisChar=='-'||thisChar=='\t'){ line_wordcount++; } } glPopMatrix(); // if(thisChar==' '){ // glTranslatef( (float)charHoriAdvances[thisChar]+round(thisFJ) ,0,0); // lineadvance+= (float)charHoriAdvances[thisChar]+round(thisFJ); // } else { glTranslatef( (float)charHoriAdvances[thisChar] ,0,0); lineadvance+= (float)charHoriAdvances[thisChar]; // } } } glPopMatrix(); glPopMatrix(); } float JoshFont::getStringWidth(char *inputstr,int size){ float strw=0; int strln = strlen(inputstr); for(int i=0;idrawChar(inputstr[i]); if(i==strln-1){ strw+=size*(charWidths[inputstr[i]]+charHoriBearingXs[inputstr[i]]); } else { strw+=size*(float)charHoriAdvances[inputstr[i]] ; } } return strw; } int JoshFont::loadBitmapCharRAWFromMemory(void*buffer, int imageWidth, int imageHeight, int srcWidth, int srcHeight,int mipmap){ unsigned char *f = (unsigned char*)buffer; if(buffer==0){ return 0; } unsigned char *f_alphad = new unsigned char[imageWidth*imageHeight*4]; int gutter=3; for(int y=0;y=gutter && x>=gutter){ f_alphad[(y)*imageWidth*4+4*(x )] = 255; f_alphad[(y)*imageWidth*4+4*(x)+1] = 255; f_alphad[(y)*imageWidth*4+4*(x)+2] = 255; f_alphad[(y)*imageWidth*4+4*(x)+3] = f[(y-gutter)*srcWidth+(x-gutter)];//this will differ depending on the ink being used. } else { f_alphad[(y)*imageWidth*4+4*(x )] = 0; f_alphad[(y)*imageWidth*4+4*(x)+1] = 0; f_alphad[(y)*imageWidth*4+4*(x)+2] = 0; f_alphad[(y)*imageWidth*4+4*(x)+3] = 0; } } } GLuint t; glGenTextures(1,&t); glBindTexture(GL_TEXTURE_2D, t); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); if(mipmap){ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); gluBuild2DMipmaps( GL_TEXTURE_2D, 4, imageWidth,imageHeight,GL_RGBA, GL_UNSIGNED_BYTE, f_alphad ); }else{ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP); glTexImage2D(GL_TEXTURE_2D, 0,4, imageWidth, imageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, f_alphad); //#if defined(__DARWIN__) delete f_alphad; //delete f; //#endif return t; } float JoshFont::randomFloat(){ return ((float)rand())/((float)RAND_MAX); } \ No newline at end of file diff --git a/intern/JoshFont.h b/intern/JoshFont.h new file mode 100755 index 0000000..3837801 --- /dev/null +++ b/intern/JoshFont.h @@ -0,0 +1,83 @@ +#ifndef _JOSHFONT_H_ +#define _JOSHFONT_H_ + +#include +#include +#include +#include +//#include "joshfix.h" + + +#if defined(__DARWIN__) +#include +#include +#include +#include +#include +#elif defined(linux) +#include +#else +#include +#include +#include +#include FT_FREETYPE_H +#include +#include +#endif + + +#include + +#define JF_VECTOR 0 +#define JF_BITMAP 1 + + +class JoshFont{ +public: + + JoshFont(char file[], int lettersize,int renderstyle, int antialiased,int mipmap); + ~JoshFont(); + + //int offx; + //int offy; + + int base; + int textures[256]; + float charWidths[256]; + float charHeights[256]; + float charHoriBearingYs[256]; + float charHoriBearingXs[256]; + float charHoriAdvances[256]; + float charVertBearingYs[256]; + float charVertBearingXs[256]; + float charVertAdvances[256]; + float*feedbackBuffers[256]; + int feedbackSizes[256]; + float units_per_EM; + float ascender; + float descender; + float text_height; + float initsize; + int rendermode; + FT_Library ft_library; + FT_Face ft_face; + float feedbackScale;//used to store initial window values. + void drawTriangleChar(char c,float size); + void initFeedback(); + int open(char file[], int lettersize,int renderStyle, int antialiased,int mipmap); + + void drawChar(char c); + void tessChar(char c,float lettersize); + void feedbackChar(char c,float lettersize); + void drawString(char *inputstr,float size,float tracking); + void drawStringBoxWrap(char *inputstr,float size,float tracking,float right,float bottom,int quickrender); + void drawStringFittedBox(char *inputstr,float right,float bottom); + float getStringWidth(char *inputstr, int size); + int loadBitmapCharRAWFromMemory(void*buffer, + int imageWidth, int imageHeight, + int srcWidth, int srcHeight,int mipmap); + float randomFloat(); +}; + +#endif + diff --git a/intern/Thingy.cpp b/intern/Thingy.cpp new file mode 100644 index 0000000..225777a --- /dev/null +++ b/intern/Thingy.cpp @@ -0,0 +1,108 @@ +#include "Thingy.h" +#include "jttoolkit.h" +#include "Global.h" + +#define RAND_COUNT 10 + +Thingy::Thingy(){ + + for(int i=0;icopyFrom(dest); +} + +void Thingy::resetRandoms(){ + rnd.clear(); + for(int i=0;i +#include "JMass.h" + +using namespace std; + +class Thingy : public JMass{ + public: + JPoint dest; + float size; + float destSize; + vector rnd; + Thingy(); + ~Thingy(); + + void reset(); + void step(); + void draw(); + void resetRandoms(); +}; + + + +#endif + diff --git a/intern/gl_et_al.h b/intern/gl_et_al.h new file mode 100755 index 0000000..079b926 --- /dev/null +++ b/intern/gl_et_al.h @@ -0,0 +1,13 @@ +/** + wrapper include for openGL interested includers. + so i don't have to multiply update all opengl includings each time i switch plats. +*/ + +#if defined(__DARWIN__) + #include + #include +#else + #include + #include +#endif + diff --git a/intern/jttoolkit.cpp b/intern/jttoolkit.cpp new file mode 100755 index 0000000..59b8901 --- /dev/null +++ b/intern/jttoolkit.cpp @@ -0,0 +1 @@ +#include "jttoolkit.h" #include #include #include #include #include #define INIT_WINDOW_X 100 #define INIT_WINDOW_Y 100 #define INIT_WINDOW_WIDTH 810 #define INIT_WINDOW_HEIGHT 510 //#include "gl2ps.h" #if defined (__DARWIN__) #include #endif #define use_perspective #define VERBOSE 0 //turn this on and off for speed //---- user-global access functions int ticks(){return _ticks;} int width(){return _width;} int height(){return _height;} int mouseX(){return _mouseX;} int mouseY(){return _mouseY;} void setMouseX(long xx){_mouseX = xx;} void setMouseY(long yy){_mouseY = yy;} void ignoreMouse(int state){_ignoreMouse = state;} //-------------- void *threadFunc(void*stuff){ } //------------------------------------------------------------------------ void initfmod(){ /* if (FSOUND_GetVersion() < FMOD_VERSION){ printf("Error : You are using the wrong DLL version! You should be using FMOD %.02f\n", FMOD_VERSION); exit(1); } if(!FSOUND_Init(48000, 1024, FSOUND_INIT_GLOBALFOCUS)){ printf("%s\n",FMOD_ErrorString(FSOUND_GetError())); } */ } //------------------------------------------------------------------------ float friction(){return _friction;} void setFriction(float f){_friction = f;} float frequencyRange(){return _frequencyRange;} void setFrequencyRange(float f){_frequencyRange = f;} void drawUnitSquare(){ glBegin(GL_QUADS); glTexCoord2f(0,0);glVertex2f(0,0); glTexCoord2f(1,0);glVertex2f(1,0); glTexCoord2f(1,1);glVertex2f(1,1); glTexCoord2f(0,1);glVertex2f(0,1); glEnd(); } void drawUnitSquareSlightlySmaller(){ glBegin(GL_QUADS); glTexCoord2f(0.01,0.01);glVertex2f(0,0); glTexCoord2f(0.99,0.01);glVertex2f(1,0); glTexCoord2f(0.99,0.99);glVertex2f(1,1); glTexCoord2f(0.01,0.99);glVertex2f(0,1); glEnd(); } void toggleFullScreen(){ fullscreenmode=!fullscreenmode; if(fullscreenmode){ glutFullScreen(); } else { glutReshapeWindow(INIT_WINDOW_WIDTH,INIT_WINDOW_HEIGHT); glutPositionWindow(0,10); } } char* trimLeft(char*buff){ //count how many to offset backward int whiteCount = 0; for(int i=0;i0){ for(int b=0;b frameRate){ _execute_frame(); lastGlutFrameTime = glutGet(GLUT_ELAPSED_TIME); } */ } void timerFunc(int v) { //if(glutGet(GLUT_ELAPSED_TIME) - lastGlutFrameTime > frameRate){ _execute_frame(); //} glutTimerFunc(frameRate,timerFunc,0); } void preKeyDown(unsigned char k, int special){ if(special){ if(k==11){ toggleFullScreen(); } } else { //non special if(k==27){ //exit(0); }else if (k==KEY_DELETE || k==KEY_BACKSPACE){ } else if (k==6){//ctrl+f on a mac toggleFullScreen(); } else { } } } void keyboardDown(unsigned char k,int x,int y){ if(!_ignoreMouse){ _mouseX=x; _mouseY=y; } preKeyDown(k,0); jttoolkit_keyDown(k,0); } void keyboardUp(unsigned char k,int x,int y){ if(!_ignoreMouse){ _mouseX=x; _mouseY=y; } //printf("keyboardUp: %c %i\n",k); jttoolkit_keyUp(k,0); } void specialFunc(int k,int x,int y){ if(!_ignoreMouse){ _mouseX=x; _mouseY=y; } preKeyDown(k,1); jttoolkit_keyDown(k,1); } void mouseMotionFunc(int x, int y){ if(!_ignoreMouse){ _mouseX=x; _mouseY=y; }else{ ignored_mouseMove(x,y); } } void mousePassiveMotionFunc(int x, int y){ if(!_ignoreMouse){ _mouseX=x; _mouseY=y; }else{ ignored_mouseMove(x,y); } // printf("%i %i\n",_mouseX,_mouseY); } void mouseFunc(int button, int state, int x, int y){ if(!_ignoreMouse){ _mouseX=x; _mouseY=y; if(state==GLUT_DOWN){ jttoolkit_mouseDown(); } else { jttoolkit_mouseUp(); } }else{ if(state==GLUT_DOWN){ ignored_mouseDown(x,y); } else { ignored_mouseUp(x,y); } } } void viewPerspective(float angle){ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(angle,(float)width()/(float)height(),0.0001,10000); //glFrustum(-2, 2, -2, 2, 1.0f, 100.0f); glMatrixMode(GL_MODELVIEW); } void viewOrtho(){ glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,width(),-height(),0,-10000,10000); glMatrixMode(GL_MODELVIEW); } void reshape(int w,int h){ // if(glutGetWindow()==MainWindowID){ if(1){ _width = w; _height = h; // to keep it propertional & let the window stretch // glMatrixMode(GL_PROJECTION); // glLoadIdentity(); glViewport(0,0,w,h); // if(wdraw(); viewPerspective(90); glLoadIdentity(); } else { //then i can assume for now that it was the output console window. glViewport(0,0,w,h); float r = ((float)w/(float)h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); //#if defined(use_perspective) //gluPerspective(90,(float)w/(float)h,0.0001,10000); //#else glOrtho(0,w,h,0,-10000,10000); //#endif //glFrustum(-2, 2, -2, 2, 1.0f, 100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } // jt_resizeDrawBuffer(); } void jt_resizeDrawBuffer(){ // delete [] drawbuffer; // drawbuffer = new unsigned char[width()*height()*4]; } int main(int argc,char** argv){ glutInit(&argc,argv); glutInitDisplayMode (GLUT_DOUBLE|GLUT_RGBA); glutInitWindowSize (INIT_WINDOW_WIDTH,INIT_WINDOW_HEIGHT); glutInitWindowPosition (INIT_WINDOW_X,INIT_WINDOW_Y); int gameMode = 0; if(argc>1){ for(int i=0;ipush((long)p); } void JTTessEnd(){ //FLUSH IT! tobj = gluNewTess(); _tessBind(); if(tesscache!=0){ gluTessBeginPolygon(tobj,NULL); gluTessBeginContour(tobj); for(int i=tessBase;icount ;i++){ // long t = tesscache->get(i); // switch(t){ // case TESSCACHE_NEWCONTOUR:break; // default: //printf("%i\n",t); //printf("%i\n",((GLdouble*)(t))[0]); //delete [] (GLdouble*)t;//i'm leaving this all in memory, but it's dangerous! //tessfreemem->push(t); //break; // } //} //delete tesscache; //tesscache = new Vector(); } else { //it WAS zero. //tesscache = new Vector(); } tessBase += tessPtr;//advance forward. tessPtr = 0; */ } void doTessErrorCheck(){ if(tessPtr+tessBase>tessmax){ printf("error:not enough memory allocated to JTTess",0); exit(0); } } void _tessBind(){ //#if defined (__DARWIN__) //#define TESSTYPE (GLvoid (*)(...)) //#else //typedef GLvoid ( *GluTessCallbackType)(...); //#define TESSTYPE reinterpret_cast //#endif /* gluTessCallback(tobj, GLU_TESS_VERTEX, TESSTYPE(glVertex3dv)); gluTessCallback(tobj, GLU_TESS_BEGIN, TESSTYPE(JTTess_beginCallback)); gluTessCallback(tobj, GLU_TESS_END, TESSTYPE(&JTTess_endCallback)); gluTessCallback(tobj, GLU_TESS_ERROR, TESSTYPE(JTTess_errorCallback)); gluTessCallback(tobj, GLU_TESS_COMBINE, TESSTYPE(JTTess_combineCallback)); gluTessProperty(tobj, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE); */ } /* the callback routines registered by gluTessCallback() */ void JTTESSCALLBACK JTTess_combineCallback(GLdouble coords[3], GLdouble *vertex_data[4], GLfloat weight[4], GLdouble **dataOut ){ GLdouble *vertex; int i; doTessErrorCheck(); vertex = tesscache[tessBase+tessPtr];//(GLdouble *) malloc(6 * sizeof(GLdouble)); tessPtr++; vertex[0] = coords[0]; vertex[1] = coords[1]; vertex[2] = coords[2]; for (i = 3; i < 7; i++) vertex[i] = weight[0] * vertex_data[0][i] + weight[1] * vertex_data[1][i] + weight[2] * vertex_data[2][i] + weight[3] * vertex_data[3][i]; *dataOut = vertex; } void JTTESSCALLBACK JTTess_beginCallback(GLenum which){ glBegin(which); } void JTTESSCALLBACK JTTess_endCallback(void) { glEnd(); } void JTTESSCALLBACK JTTess_errorCallback(GLenum errorCode) { const GLubyte *estring; estring = gluErrorString(errorCode); fprintf (stderr, "Tessellation Error: %s\n", estring); exit (0); } /* new callback routines registered by these calls */ void JTTESSCALLBACK JTTess_vertexCallback(GLvoid *vertex){ const GLdouble *pointer; pointer = (GLdouble *) vertex; glColor3dv(pointer+3); glVertex3dv((const GLdouble*)vertex); } JoshFont *getFont(){ return font; } JPoint mouse(){ return JPoint(mouseX(),mouseY(),0); } /** saves the screen to a file. format support provided by image magick. supported formats: http://www.imagemagick.org/script/formats.php */ void saveScreen(char *filename){ using namespace Magick; if(rawpixels==NULL){ rawpixels = new unsigned char[width()*height()*3]; } glReadPixels(0,0,width(),height(), GL_RGB , GL_UNSIGNED_BYTE ,rawpixels); /* //reverse the alpha vals. for(int i=0;iflip(); return image; } /* allocates new storage for an 8-bit image of the specified dimensions */ png_bytep* make_pixels(int width, int height) { int pixel_size = 3; //printf("debug debug debug 1\n",0); png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (png_ptr == NULL) { return NULL; } //printf("debug debug debug 2\n",0); png_bytep *row_pointers = (unsigned char **)png_malloc(png_ptr, height*sizeof(png_bytep)); for (int i = 0; i < height; i++) row_pointers[i] = (unsigned char *)png_malloc(png_ptr, width*pixel_size); //printf("debug debug debug 3\n",0); return row_pointers; } //-------------------------------------------------------------------------------------------- void jt_frameRate(unsigned long f){ frameRate = f; } void roundedRect(int gl_style,float x1,float y1,float x2,float y2,float radius,int steps){ float inc = (PI*0.5)/steps; glBegin(gl_style); //draw a quarter circle here. for(int i=0;i +#include +#include +#include + +#if defined(__DARWIN__) +#include "png.h" +#elif defined(linux) +#include +#else +#define NOMINMAX +#include +#include +// +#endif + +#define PI 3.141592653 +#include "gl_et_al.h" + +#include + +#include +#include "Vector.h" +//#include +//#include + +#include "project.h" +#include +#include "quadstretch.h" +#include "JoshFont.h" +#include "JPoint.h" + + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + + + +#if defined(__DARWIN__) +#define KEY_BACKSPACE 65 +#else +#define KEY_BACKSPACE 8 +#endif +#define KEY_DELETE 127 + + +using namespace Magick; + +//------------ user event prototypes ------------------------------ + +void setup(); +void stop(); +void loop(); +void jttoolkit_keyDown(int key,int special); +void jttoolkit_keyUp(int key,int special); +void jttoolkit_mouseDown(); +void jttoolkit_mouseUp(); + +// ----------------- user tool function prototypes ------------------------ + +extern "C"{ + + void generateNumberSwarmString(int treatmentID , float rnd, char *strBuff, float num); + + int main(int ,char**); + char* trimLeft(char*buff); + void drawUnitSquare(); + void drawUnitSquareSlightlySmaller(); + + void viewPerspective(float angle); + void viewOrtho(); + + void roundedRect(int gl_style,float x1,float y1,float x2,float y2,float radius,int steps); + + //void postQuit(JTScene *newScene); + //tells the system to quit out of the scene while the scene is not executing any events! + int jttoolkit_init(); + void toggleFullScreen(); + + void exportPostscript(char *filename); + //exports the current frame to EPS vector-based file format. + + void fileFromString( char *fname, char *data, long datasize); + //writes the bytes in null-terminated data string to file fname. + + unsigned char* stringFromFile(char *fname); + //returns a file pointer to the contents of the file. + //when you are done using this string, free it using free(ptr); + + long getFileSize( char *fname); + //returns the size of a file in bytes. + + void getFile( char *filename, unsigned char *buff, int length); + //gets the contents of a file and stores it into a string. + + void hideMouse(); + //hides the mouse + + void showMouse(); + //shows the mouse + + int buildScreenFont(char *fontName,int size); + //loads a font and returns the ID + + void drawScreenFont(int fontID,char*text,int tracking); + //draws the font to the screen as text + + void killScreenFont(int fontID); + //unloads the fontID (i've never needed to call this) + + float randomFloat(); + // gives you a random float between 0.0 and 1.0 + + void lights(); + // enables GL lighting (defaultly off) + + void nolights(); + //disables GL lighting + + float getDist(float x1,float y1,float x2,float y2); + void polar2rect(double r,double theta,double returnPair[2]); + void rect2polar(double x,double y,double returnPair[2]); + + + void line(JPoint p1,JPoint p2); + void bezier(JPoint p1,JPoint p2,JPoint p3,JPoint p4,int steps); + void interpolateBezier(float P0X,float P0Y,float P0Z, + float P1X,float P1Y,float P1Z, + float P2X,float P2Y,float P2Z, + float P3X,float P3Y,float P3Z, + int segs,float Xs[],float Ys[],float Zs[]); + float absf(float a); + + png_bytep* make_pixels(int width, int height) ; + + //removed when i went to imagemagick + //void saveScreenToTGAFile(char *filename); + //void init_saveScreen(); + + + static unsigned char*rawpixels = NULL; + void saveScreen(char *filename); + + + + //------------------------ internal prototypes------------------------------- + + + void display(); + void idle(); + void timerFunc(int v); + void keyboardDown(unsigned char k,int x,int y); + void keyboardUp (unsigned char k,int x, int y); + void specialFunc(int k, int x,int y); + void mouseMotionFunc(int x, int y); + void mousePassiveMotionFunc(int x, int y); + void mouseFunc(int state, int button, int x, int y); + void reshape(int w,int h); + void _draw_single_screenFont(int fontID, char*text); + void writeps(int format, int sort, int options, int nbcol, char *file); + void _execute_frame();//the actual frame call. +}; + +//----------------- useful globals for high level programmers ----------------- + +static unsigned long _ticks = 0; +int ticks(); + +static unsigned long _width = 0; +int width(); + +static unsigned long _height = 0; +int height(); + + +void ignoreMouse(int state); +static int _ignoreMouse = 0; + +static unsigned long _mouseX = DEFAULT_MOUSEX; +int mouseX(); +void setMouseX(long); + +static unsigned long _mouseY = DEFAULT_MOUSEY; +int mouseY(); +void setMouseY(long); + +static float _friction = 0.99997f; +float friction(); +void setFriction(float f); + +static float _frequencyRange = 50000; +float frequencyRange(); +void setFrequencyRange(float f); + + +//tess + +/// adding tesselation functionality +#if defined(__DARWIN__) +#define JTTESSCALLBACK +#else +#define JTTESSCALLBACK __stdcall +#endif + +#define TESSCACHE_NEWCONTOUR 1 + +//-some tesselation globals +static GLdouble **tesscache; +//static Vector*tessfreemem=0; +static int tessPtr = 0; +static int tessmax = 0; +static int tessBase = 0; +static GLUtesselator* tobj=0; + + + +void JTTessVertex(float x,float y, float z); +void JTTessEnd(); +void JTTessInit(int memsize); +void JTTessNewContour(); +void JTTessBegin(); +void doTessErrorCheck(); + +void _tessBind(); + +void JTTESSCALLBACK JTTess_combineCallback(GLdouble coords[3], + GLdouble *vertex_data[4], + GLfloat weight[4], GLdouble **dataOut ); + + + + +void JTTESSCALLBACK JTTess_vertexCallback(GLvoid *vertex); +void JTTESSCALLBACK JTTess_errorCallback(GLenum errorCode); +void JTTESSCALLBACK JTTess_endCallback(void); +void JTTESSCALLBACK JTTess_beginCallback(GLenum which); + +//-----------------internal globals-------------------------------------------- + +static int penta_firstloop=1; +static unsigned long frameRate = 24; +void jt_frameRate(unsigned long f); +//this is misleading. it's actually the pause time in milliseconds. +static char drawScreenFont_buff[1024*256];//text max +static int lastGlutFrameTime=0; +static unsigned char *drawbuffer; + +static int fullscreenmode = 0; + +void jt_resizeDrawBuffer(); + +#if defined(__DARWIN__) +//MAC CLASSIC +#elif defined(linux) +#else +//WINDOWS +static HWND theHwnd=0; +#endif + +static JoshFont *font; +JoshFont *getFont(); +JPoint mouse(); +Image* getPixels(); + + +void stopDemo(); +void loadByNumber(int num); + +void ignored_mouseMove(int x,int y); +void ignored_mouseDown(int x,int y); +void ignored_mouseUp(int x,int y); +void keep_the_party_going(); +//----------------------------------------------------------------------------- +#endif + diff --git a/intern/project.cpp b/intern/project.cpp new file mode 100755 index 0000000..75cbcc2 --- /dev/null +++ b/intern/project.cpp @@ -0,0 +1 @@ +#define VERSION 215 #include "jttoolkit.h" #include "Global.h" #include "JImage.h" using namespace std; Global *instance; void setup(){ glutSwapBuffers();//a little trick to make the window go black while it waits. instance = new Global(); } void loop(){ instance->loop(); } void jttoolkit_keyDown(int k,int special){ if(k==27){ exit(0); } instance->keyDown(k,special); } void jttoolkit_keyUp(int k,int special){} void jttoolkit_mouseDown(){ instance->mouseDown(); } void jttoolkit_mouseUp(){ instance->mouseUp(); } void stop(){ } void ignored_mouseMove(int x,int y){ } void ignored_mouseDown(int x,int y){ } void ignored_mouseUp(int x,int y){ } \ No newline at end of file diff --git a/intern/project.h b/intern/project.h new file mode 100755 index 0000000..e69de29 diff --git a/intern/quadstretch.h b/intern/quadstretch.h new file mode 100755 index 0000000..3fd8d1a --- /dev/null +++ b/intern/quadstretch.h @@ -0,0 +1,27 @@ +#ifndef _QUADSTRETCH_H_ +#define QUADSTRETCH_H_ + + +void intersect_lines2(float x0,float y0,float x1,float y1,float x2,float y2,float x3,float y3,float &xi,float &yi); + +void interpolatePoints2(float x1,float y1,float x2,float y2,float i,float &x,float &y); + +void quadstretch(float x,float y,float l,float t, + float w,float h,float *qx,float *qy,float *ret); + + +void quadStretch2(float x,float y,float l,float t,float w,float h,float *q,float &newx,float &newy); + +void interpolatePoints(float x1,float y1, + float x2,float y2,float i,float *ret); + +void intersect_lines(float x0,float y0,float x1, + float y1,float x2,float y2, + float x3,float y3,float *ret); + +int intersectLineSegs(float x1,float y1, + float x2,float y2, + float x3,float y3, + float x4,float y4); + +#endif diff --git a/intern_disabled/ArrowVector.cpp b/intern_disabled/ArrowVector.cpp new file mode 100755 index 0000000..4a48b72 --- /dev/null +++ b/intern_disabled/ArrowVector.cpp @@ -0,0 +1,157 @@ +#include "ArrowVector.h" +#include "jttoolkit.h" +#include "Global.h" + +ArrowVector::ArrowVector(float xx,float yy,float zz){ + this->x = xx; + this->y = yy; + this->z = zz; + theta=0; + destTheta=0; + radius=40; + destRadius = 40; + glLineWidth(3); + for(int i=0;i<10;i++){ + rnd.push_back(randomFloat()); + } + lowerHalf = ((900-x) < y*1.2); +} + + +void ArrowVector::reset(){ + theta=0; + destTheta=0; + radius=30; + destRadius=30; +} + +ArrowVector::~ArrowVector(){ + +} + +void ArrowVector::draw(){ + + //am i in the upper triangle or the lower? + + + //i was going to record a nice mouse track for this + //cout << mouseX() << ' ' << mouseY() << endl; + + glColor4f(1,1,1,0.3); + //step + + //get thetas for everyone. + + float accum = 0; + for(int i=0;iedies.size();i++){ + float d = this->distanceFrom(*Global::instance->edies[i]); + //d = 1-d*0.001; + accum += this->thetaFrom(*Global::instance->edies[i]); + } + destTheta = accum/Global::instance->edies.size(); + //flip around fixits + + if(destTheta-theta>(PI))theta+=PI*2.0; + else if(theta-destTheta>(PI))theta-=PI*2.0; + + + float faultStrength; + + faultStrength = fmax(0.01,(1-fabs(y-(1280-x-400))*0.0005)); + + + //overshooting to make conical effect + float spreadAmount = 0.1; + if(lowerHalf){ + destTheta -= pow(faultStrength,4)*spreadAmount; + }else{ + destTheta += pow(faultStrength,4)*spreadAmount; + } + + + + + theta += (destTheta-theta)*pow(faultStrength,4)*0.5; + + + radius += (destRadius-radius)*faultStrength*0.05; + // * (theta+PI/2)/(PI*2) * 200 * rnd[0]; + + JPoint tip; + + tip.x = x + cos(theta)*radius; + tip.y = y + sin(theta)*radius; + tip.z = z; + + float headSize = 0.45; + + + float r = 40;//radius softening + + JPoint arrowEdge1; + arrowEdge1.x = tip.x + cos(PI+theta-0.5)*r*headSize; + arrowEdge1.y = tip.y + sin(PI+theta-0.5)*r*headSize; + arrowEdge1.z = tip.z; + + + JPoint arrowEdge2; + arrowEdge2.x = tip.x + cos(PI+theta+0.5)*r*headSize; + arrowEdge2.y = tip.y + sin(PI+theta+0.5)*r*headSize; + arrowEdge2.z = tip.z; + + JPoint arrowPoint; + arrowPoint.x = tip.x + cos(PI+theta)*(r*headSize - 22); + arrowPoint.y = tip.y + sin(PI+theta)*(r*headSize - 22); + arrowPoint.z = tip.z; + + Edie *e = Global::instance->edies[0]; + active = ((e->x)+e->y)*10.5-8000 < (x+(1000-y)); + + + //affected by the wind screen yet? + destRadius += ( (60+faultStrength) - destRadius)*0.2;//snapping back + if(active && e->x > 0){ + destRadius += rnd[0]*400*pow(faultStrength,4);//random radius variance per arrow fingerprint - scaled by a time-based backward pull + } + + float gradient_alpha; + + if(active){ + gradient_alpha = pow(faultStrength,3); + }else{ + gradient_alpha = 1; + } + glColor4f(1,1, (theta+PI/2)/(PI*2) ,gradient_alpha); + old_active=active; + + //draw + + glPushMatrix(); + + + glBegin(GL_LINES); + glVertex(); + tip.glVertex(); + glEnd(); + + + glBegin(GL_POLYGON); + arrowPoint.glVertex(); + arrowEdge1.glVertex(); + arrowEdge2.glVertex(); + glEnd(); + + + glPushMatrix(); + (tip+JPoint(80,200,0)).glTranslate(); + JoshFont*f=getFont(); + char s[64]; + sprintf(s,"%2.2f",theta); + if(x>900 || y > 831)f->drawString(s,75,1); + + glPopMatrix(); + + + + glPopMatrix(); +} diff --git a/intern_disabled/ArrowVector.h b/intern_disabled/ArrowVector.h new file mode 100755 index 0000000..ac29579 --- /dev/null +++ b/intern_disabled/ArrowVector.h @@ -0,0 +1,27 @@ +#ifndef _ArrowVector_H_ +#define _ArrowVector_H_ +#include "JPoint.h" +#include + +using namespace std; + +class ArrowVector:public JPoint{ + public: + bool active; + bool old_active; + bool lowerHalf; + vector rnd; + float destTheta; + float theta; + float radius; + float destRadius; + ArrowVector(float ,float ,float); + ~ArrowVector(); + void draw(); + void reset(); +}; + + + +#endif + diff --git a/intern_disabled/Athletes.cpp b/intern_disabled/Athletes.cpp new file mode 100755 index 0000000..bbb106c --- /dev/null +++ b/intern_disabled/Athletes.cpp @@ -0,0 +1,48 @@ +#include "Athletes.h" +#include "Global.h" +#include "gl_et_al.h" +#include "Guy.h" +#include "obj.h" +#include "JPoint.h" + +using namespace obj4gl; + + +Athletes::Athletes(){ + //load the OBJ + OBJ *obj = new OBJ("media/footBall_objs/footballman4.obj"); + int list = glGenLists(1); + glNewList(list,GL_COMPILE); + obj->outlineFaces(); + glEndList(); + + //make new guys + JPoint p; + for(int i=0;i<22;i++){ + Global::instance->field.randomPoint(&p); + guys.push_back(Guy(list,p.x,p.y,i>11,i)); + } +} + +Athletes::~Athletes(){ + +} + +void Athletes::step(){ + deque::iterator iter; + for(iter=guys.begin();iter!=guys.end();iter++){ + (*iter).step(); + } +} + + +void Athletes::draw(){ + + deque::iterator iter; + for(iter=guys.begin();iter!=guys.end();iter++){ + glPushMatrix(); + (*iter).draw(); + glPopMatrix(); + } +} + diff --git a/intern_disabled/Athletes.h b/intern_disabled/Athletes.h new file mode 100755 index 0000000..6c12e6a --- /dev/null +++ b/intern_disabled/Athletes.h @@ -0,0 +1,22 @@ +#ifndef _Athletes_H_ +#define _Athletes_H_ +#include "Satellite.h" +#include "Guy.h" +#include + +using namespace std; + +class Athletes : public Satellite { + public: + deque guys; + Athletes(); + ~Athletes(); + void step(); + void draw(); + +}; + + + +#endif + diff --git a/intern_disabled/BallPathTracer.cpp b/intern_disabled/BallPathTracer.cpp new file mode 100755 index 0000000..869bd10 --- /dev/null +++ b/intern_disabled/BallPathTracer.cpp @@ -0,0 +1,120 @@ +#include "BallPathTracer.h" +#include "jttoolkit.h" + +BallPathTracer::BallPathTracer(){ + +} + +BallPathTracer::~BallPathTracer(){ + +} + +void BallPathTracer::step(){ + path.push_back(JPoint(Global::instance->ball->x,Global::instance->ball->y,Global::instance->ball->z)); + if(path.size()>100){ + JPoint p = path.front(); + path.pop_front(); + if(p.z==0)killThese.push_back(p); + } + + + //grow the upcoming signs + vector dropflags; + if(path.size()>0){ + for(int i=0;i0){ + if(flagMap[killThese.front()]<1){ + flagMap[killThese.front()]=0; + killThese.pop_front(); + } + } +} + +void BallPathTracer::draw(){ + + vector dropflags; + + glColor4f(1,1,1,0.5); + glEnable(GL_LINE_STIPPLE); + glLineStipple(Global::instance->worldScale*3,0x5555); + glBegin(GL_LINE_STRIP); + + if(path.size()>0){ + for(int i=0;itumbleY,0,1,0);//auto-orient , billboard, lookAtCamera + //glRectf(-2,-2,2,2); + + JoshFont *f = getFont(); + glTranslatef(-1,-1,0); + glRotatef(180,0,0,1); + glRotatef(180,0,1,0); + + char txt[64]; + sprintf(txt,"%i",(int)p.y); + + f->drawString(txt,2,5); + glPopMatrix(); + + //draw arrow + glPushMatrix(); + glTranslatef(p.x,p.y,p.z+10); + glRotatef(Global::instance->tumbleY+90,0,0,1);//auto-orient , billboard, lookAtCamera + glBegin(GL_POLYGON); + glVertex3f(0,0,0); + glVertex3f(0,-1,2); + glVertex3f(0,0,1); + glVertex3f(0,1,2); + glEnd(); + glPopMatrix(); + +} diff --git a/intern_disabled/BallPathTracer.h b/intern_disabled/BallPathTracer.h new file mode 100755 index 0000000..5a5146e --- /dev/null +++ b/intern_disabled/BallPathTracer.h @@ -0,0 +1,32 @@ +#ifndef _BallPathTracer_H_ +#define _BallPathTracer_H_ + +#include "JPoint.h" +#include "Global.h" +#include "Satellite.h" +#include + +//some rules for the map +struct ltjpoint{ + bool operator()(const JPoint s1,const JPoint s2)const{ + return (s1.x*100 + s1.y*50 + s1.z) > (s2.x*100 + s2.y*50 + s2.z); + } +}; + + +class BallPathTracer : public Satellite { + public: + map flagMap; + dequekillThese; + deque path; + BallPathTracer(); + ~BallPathTracer(); + void step(); + void draw(); + void drawFlag(JPoint p); +}; + + + +#endif + diff --git a/intern_disabled/BallPointer.cpp b/intern_disabled/BallPointer.cpp new file mode 100755 index 0000000..52e22c6 --- /dev/null +++ b/intern_disabled/BallPointer.cpp @@ -0,0 +1,106 @@ +#include "BallPointer.h" + +#include "Global.h" +#include "gl_et_al.h" +#include "jttoolkit.h" + +BallPointer::BallPointer(){ + x = Global::instance->ball->x; + y = Global::instance->ball->y; + z = Global::instance->ball->z; + +} + +BallPointer::~BallPointer(){ + +} + + +void BallPointer::step(){ + + x += (Global::instance->ball->x - x)*0.05; + y += (Global::instance->ball->y - y)*0.05; + z += (Global::instance->ball->z - z)*0.05; + +} + +void BallPointer::draw(){ + + glEnable(GL_LINE_SMOOTH); + glLineWidth(10); + //draw the line - one part lags behind. + glColor4f(1,1,1,0.05); + glBegin(GL_LINE_STRIP); + glVertex3f( + Global::instance->ball->x, + Global::instance->ball->y, + Global::instance->ball->z + 5); + glVertex3f( + Global::instance->ball->x, + Global::instance->ball->y, + Global::instance->ball->z + 50); + glVertex3f(x,y,z + 90); + glEnd(); + + + + + //draw circle around ball + glPushMatrix(); + glTranslatef(Global::instance->ball->x, + Global::instance->ball->y, + Global::instance->ball->z); + + glRotatef(90,1,0,0); + glRotatef(Global::instance->tumbleY,0,1,0);//auto-orient , billboard, lookAtCamera + glBegin(GL_LINE_LOOP); + float rad = 5; + float steps = 45; + float inc = (PI*2)/steps; + for(int i=0;itumbleY+180,0,-1,0);//auto-orient , billboard, lookAtCamera + glTranslatef(-3,13,0); + char s[256]; + sprintf(s,"Ball\nX=%1.1f\nY=%1.1f\nZ=%1.1f", + Global::instance->ball->x, + Global::instance->ball->y, + Global::instance->ball->z); + glColor4f(1,1,1,0.4); + f->drawString(s,2,0.7); + glPopMatrix(); + + + + + glLineWidth(1); + // //draw a rect around the info box. + // glPushMatrix(); + // glTranslatef(x,y,z + 90); + // glRotatef(90,1,0,0); + // glRotatef(Global::instance->tumbleY,0,1,0);//auto-orient , billboard, lookAtCamera + // glTranslatef(-20,0,0); + // glBegin(GL_LINE_LOOP); + // glVertex2f(0,0); + // glVertex2f(50,0); + // glVertex2f(50,50); + // glVertex2f(0,50); + // glEnd(); + // glPopMatrix(); +} + diff --git a/intern_disabled/BallPointer.h b/intern_disabled/BallPointer.h new file mode 100755 index 0000000..18f34c9 --- /dev/null +++ b/intern_disabled/BallPointer.h @@ -0,0 +1,24 @@ +#ifndef _BallPointer_H_ +#define _BallPointer_H_ + +#include "Satellite.h" + +class BallPointer:public Satellite { + public: + + float x; + float y; + float z; + + BallPointer(); + ~BallPointer(); + + void step(); + void draw(); + +}; + + + +#endif + diff --git a/intern_disabled/Client.cpp b/intern_disabled/Client.cpp new file mode 100755 index 0000000..2780633 --- /dev/null +++ b/intern_disabled/Client.cpp @@ -0,0 +1,73 @@ +#include "Client.h" + +Client::Client(){ + state=0; + shape =randomFloat(); + size = randomFloat(); + rotation = randomFloat(); + interp=0; + spinX=randomFloat(); + spinY=randomFloat(); + spinZ=randomFloat(); + drawMode=randomFloat(); + + spokeCount = randomFloat(); + radius = randomFloat(); + +} + +Client::~Client(){ + +} + +void Client::draw(){ + if(state==2){ + interp += ( 0 - interp) * 0.1; + }else{ + interp += ( 1 - interp) * 0.1; + } + + glScalef(interp*size*max_size,interp*size*max_size,0); + glRotatef(spinX*ticks()*spin_scalar,1,0,0); + glRotatef(spinY*ticks()*spin_scalar,0,1,0); + glRotatef(spinZ*ticks()*spin_scalar,0,0,1); + + if(drawMode>0.0 && drawMode<=0.3){ + glBegin(GL_LINE_LOOP); + }else if(drawMode>0.3 && drawMode<=0.7){ + glBegin(GL_TRIANGLE_FAN); + }else if(drawMode>0.7 && drawMode>=1){ + glBegin(GL_POINTS); + } + + + int steps = round(shape*10); + float inc = (PI*2)/steps; + float r = interp*size; + for(int i=0;i Clover::phrases; + +Clover::Clover(GameGrid *_parent){ + parent = _parent; + size=0; + lag_rotateX=0; + lag_rotateY=0; + rotateX=0; + rotateY=0; + counter=0; + for(int i=0;i<10;i++){ + rnd.push_back(randomFloat()); + } + label[0]=0; +} + +void Clover::syncDest(){ + dest.x=x; + dest.y=y; + dest.z=z; +} + +Clover::~Clover(){ + +} + +void Clover::softReset(){ + dest.y = 0; + rotateX = 0; + rotateY = 0; +} + +void Clover::step(){ + lag_rotateX+=(rotateX-lag_rotateX)*0.3; + lag_rotateY+=(rotateY-lag_rotateY)*0.3; + + (*this)+=(dest-(*this))*0.4;//move towards destx + + if(counter% (int)( rnd[0]*500+1 )==0){ + rotateX = round(randomFloat()*8-4)*90; + rotateY = round(randomFloat()*8-4)*90; + if(randomFloat()>0.5){ + dest.y += (randomFloat()-0.5)*10; + }else{ + dest.y = parent->slide; + } + } + + + counter++; +} + + +float Clover::getActivity(){ + JPoint p = (*this)-dest; + float drx = fabs(rotateX-lag_rotateX); + float dry = fabs(rotateY-lag_rotateY); + return p.x+p.y+p.z+drx+dry ; +} + +void Clover::draw(int listID){ + glPushMatrix(); + glTranslate(); + + float act = getActivity(); + act*=0.01; + if(act<1)act=1; + + glScalef(size,size,size); + glRotatef(90,1,0,0); + glRotatef(lag_rotateX,0,1,0); + glRotatef(lag_rotateY,1,0,0); + + //draw the clover. + glPushMatrix(); + glScalef(act,act,act); + glCallList(listID); + glPopMatrix(); + + + //draw the cros hair thing + glColor4f(1,1,1,0.2); + float s = 3; + glBegin(GL_LINES); + glVertex3f(-s,0,0); + glVertex3f(s,0,0); + glVertex3f(0,-s,0); + glVertex3f(0,s,0); + glEnd(); + + + + //draw the glass pain + s= 5; + glColor4f(1,1,1,0.03); + glBegin(GL_POLYGON); + glVertex3f(-s,-s,0); + glVertex3f( s,-s,0); + glVertex3f( s, s,0); + glVertex3f(-s, s,0); + glEnd(); + + + //draw some text + glColor4f(1,1,1,0.5); + JoshFont *f = getFont(); + glRotatef(180,0,0,1); + glTranslatef(-5,2,0); + + char *thisPhrase = phrases[rnd[1]*phrases.size()]; + sprintf(label,"%s",thisPhrase); + label[counter%strlen(thisPhrase)] = 0; + f->drawString(label,1,0); + + + glPopMatrix(); + + + //connect the clover to lense + Global::instance->lenseLine((*this),1,1,1,0.05); + +} diff --git a/intern_disabled/Clover.h b/intern_disabled/Clover.h new file mode 100755 index 0000000..857efea --- /dev/null +++ b/intern_disabled/Clover.h @@ -0,0 +1,34 @@ +#ifndef _Clover_H_ +#define _Clover_H_ + +#include "JPoint.h" +#include "jttoolkit.h" + +class GameGrid; + +class Clover : public JPoint{ + public: + static vector phrases; + float size; + float rotateX; + float rotateY; + float lag_rotateX; + float lag_rotateY; + char label[256]; + vector rnd; + JPoint dest; + GameGrid *parent; + int counter; + Clover(GameGrid *_parent); + ~Clover(); + void step(); + void syncDest(); + void draw(int listID); + void softReset(); + float getActivity(); +}; + + + +#endif + diff --git a/intern_disabled/DieingParent.cpp b/intern_disabled/DieingParent.cpp new file mode 100755 index 0000000..52cc836 --- /dev/null +++ b/intern_disabled/DieingParent.cpp @@ -0,0 +1,21 @@ +#include "DieingParent.h" +#include "jttoolkit.h" +#include "Global.h" + +DieingParent::DieingParent(JPoint t){ + for(int i=0;i<5;i++)rnd.push_back(randomFloat()); + copyFrom(t); +} + +DieingParent::~DieingParent(){ + +} + +void DieingParent::step(){ + lerpSelfTo(JPoint(0,0,0),0.4); +} + +void DieingParent::draw(int counter,JPoint end){ + +} + diff --git a/intern_disabled/DieingParent.h b/intern_disabled/DieingParent.h new file mode 100755 index 0000000..546adb6 --- /dev/null +++ b/intern_disabled/DieingParent.h @@ -0,0 +1,30 @@ +#ifndef _DieingParent_H_ +#define _DieingParent_H_ + + +#include "JPoint.h" +#include "TreeNode.h" +#include + +using namespace std; + +class TreeNode; + +class DieingParent : public JPoint{ + public: + + + + vector rnd; + DieingParent(JPoint t); + ~DieingParent(); + + void step(); + void draw(int counter,JPoint end); + +}; + + + +#endif + diff --git a/intern_disabled/Edie.cpp b/intern_disabled/Edie.cpp new file mode 100755 index 0000000..cde0a97 --- /dev/null +++ b/intern_disabled/Edie.cpp @@ -0,0 +1,28 @@ +#include "Edie.h" +#include "jttoolkit.h" +#include "Global.h" + +Edie::Edie(float xx,float yy,float zz):JPoint(xx,yy,zz){ + +} + +Edie::Edie(){ + for(int i=0;i<5;i++)rnd.push_back(randomFloat()); + +} + +Edie::~Edie(){ + +} + +void Edie::step(){ + +} + +void Edie::draw(){ + glPushMatrix(); + glTranslate(); + glRectf(-3,-3,3,3); + glPopMatrix(); +} + diff --git a/intern_disabled/Edie.h b/intern_disabled/Edie.h new file mode 100755 index 0000000..37d6b58 --- /dev/null +++ b/intern_disabled/Edie.h @@ -0,0 +1,24 @@ +#ifndef _Edie_H_ +#define _Edie_H_ + + +#include "JPoint.h" +#include + +using namespace std; + +class Edie : public JPoint{ + public: + vector rnd; + Edie(); + ~Edie(); + + void step(); + void draw(); + Edie(float xx,float yy,float zz); +}; + + + +#endif + diff --git a/intern_disabled/FXImg.cpp b/intern_disabled/FXImg.cpp new file mode 100755 index 0000000..c3c4262 --- /dev/null +++ b/intern_disabled/FXImg.cpp @@ -0,0 +1,183 @@ +#include "FXImg.h" +#include "gl_et_al.h" + +FXImg::FXImg(char*filename):JImage(filename){ + leftEatAwayPosition = 0; + + int rndcount = rows()*9; + + rnd = new float[rndcount]; + eaters = new float[rows()]; + + for(int i=0;irows()-22)r=20;//force top and bottoms to go fast. border thing. + a += r + insurance; + if(a>MaxRGB)a = MaxRGB; + c1.alphaQuantum(a); + pixels[ y *columns()+x] = c1; + } + } +} + + +void FXImg::stepLeftEatAway(){ + stepLeftEatAway(4); +} + +void FXImg::stepLeftEatAway(int chase){ + + for(int steps=0;steps<5;steps++){ + for(int y=0;yMaxRGB)a = MaxRGB; + + c1.alphaQuantum(a); + pixels[ y *columns()+x] = c1; + eaters[y] += rnd[y*2]*0.9+0.1; + } + } + } + + + //gradient chaser + for(int steps=0;steps<3;steps++){ + for(int y=0;yMaxRGB)a = MaxRGB; + c1.alphaQuantum(a); + pixels[ y *columns()+x] = c1; + } + } + } + leftEatAwayPosition++; + } + + + + +} + +void FXImg::killRandomPixel(){ + int x = (int)(columns()*randomFloat()); + int y = (int)(rows()*randomFloat()); + Color c(pixels[y*columns()+x]); + c.alphaQuantum(MaxRGB); + pixels[y*columns()+x] = c; +} + +void FXImg::drawAsQuadStrip(deque pts){ + glBindTexture(GL_TEXTURE_2D,textureID); + glBegin(GL_TRIANGLE_STRIP); + for(int i=0;itexX,pts[i]->texY); + glVertex2f(pts[i]->x,pts[i]->y); + } + glEnd(); +} + +void FXImg::drawQuadStripAsWireframe(deque pts){ + glBindTexture(GL_TEXTURE_2D,0); + glEnable(GL_LINE_SMOOTH); + glBegin(GL_LINES); + + //draw track spokes. + for(int i=0;ix,pts[i]->y); + } + + float steps = 128; + float inc = 1/steps; + + if(pts.size()>1){ + for(int i=1;ix + (pts[i*2+1]->x - pts[i*2]->x)*inc*j; + float py1 = pts[i*2]->y + (pts[i*2+1]->y - pts[i*2]->y)*inc*j; + float px2 = pts[i*2-2]->x + (pts[i*2-1]->x - pts[i*2-2]->x)*inc*j; + float py2 = pts[i*2-2]->y + (pts[i*2-1]->y - pts[i*2-2]->y)*inc*j; + glVertex2f(px1,py1); + glVertex2f(px2,py2); + } + } + } + + glEnd(); +} + + + +void FXImg::drawQuadStripAsHairs(deque pts,float start,float end){ + glBindTexture(GL_TEXTURE_2D,textureID); + //glEnable(GL_LINE_SMOOTH); + //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + //glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); + + float taper_to_fluff_ratio = 0.5; + // float crossoverScaler = 0.000008; + float crossoverScaler = 0.025; + float steps = rows()*2; + float inc = 1/steps; + + float ptss2 = pts.size()/2; + if(pts.size()>1){ + for(int j=0;j<=steps;j++){ + glBegin(GL_LINE_STRIP); + for(int i=0;i=start*ptss2 && ix + (pts[i*2+1]->x - pts[i*2]->x)*inc*steps*0.5; + float my1 = pts[i*2]->y + (pts[i*2+1]->y - pts[i*2]->y)*inc*steps*0.5; + + float px1 = pts[i*2]->x + (pts[i*2+1]->x - pts[i*2]->x)*inc*j; + float py1 = pts[i*2]->y + (pts[i*2+1]->y - pts[i*2]->y)*inc*j; + + float destScalar1 = crossoverScaler*pow(i,2);//*rnd[j*2+1]; + if(rnd[j*2+1]>taper_to_fluff_ratio)destScalar1 = -destScalar1; + else destScalar1 = fmin(0.5,destScalar1); + + px1 += (mx1 - px1)*destScalar1; + py1 += (my1 - py1)*destScalar1; + + float tx1 = pts[i*2]->texX + (pts[i*2+1]->texX - pts[i*2]->texX)*inc*j; + float ty1 = pts[i*2]->texY + (pts[i*2+1]->texY - pts[i*2]->texY)*inc*j; + + glTexCoord2f(tx1,ty1); glVertex2f(px1,py1); + } + } + glEnd(); + } + } +} diff --git a/intern_disabled/FXImg.h b/intern_disabled/FXImg.h new file mode 100755 index 0000000..d5ea7a0 --- /dev/null +++ b/intern_disabled/FXImg.h @@ -0,0 +1,30 @@ +#ifndef _FXImg_H_ +#define _FXImg_H_ + +#include "JImage.h" +#include "Point.h" +#include +#include +#include + +using namespace Magick; +using namespace std; + +class FXImg : public JImage{ + float *rnd; + float *eaters; + public: + int leftEatAwayPosition; + FXImg(char *filename); + ~FXImg(); + void killRandomPixel(); + void stepLeftEatAway(); + void stepLeftEatAway(int chase); + void drawAsQuadStrip(deque); + void drawQuadStripAsWireframe(deque); + void drawQuadStripAsHairs(deque,float start,float end); + void brushedSteelFade(); + void brushedSteelFade(float mag,int insurance); +}; + +#endif diff --git a/intern_disabled/FluxDiagram.cpp b/intern_disabled/FluxDiagram.cpp new file mode 100755 index 0000000..8739536 --- /dev/null +++ b/intern_disabled/FluxDiagram.cpp @@ -0,0 +1,36 @@ +#include "FluxDiagram.h" +#include "jttoolkit.h" +#include "Global.h" + +FluxDiagram::FluxDiagram(float position){ + pos = position; + nodes.push_back(new TreeNode(NULL,0)); +} + +FluxDiagram::~FluxDiagram(){ + +} + +void FluxDiagram::step(){ + //step all the treenodes + deque::iterator i; + for(i=nodes.begin();i!=nodes.end();i++){ + (*i)->step(); + } +} + + +void FluxDiagram::draw(){ + + glEnable(GL_LINE_SMOOTH); + glEnable(GL_BLEND); + glPushMatrix(); + glTranslatef(0,pos,-10); + //step all the treenodes + deque::iterator i; + for(i=nodes.begin();i!=nodes.end();i++){ + (*i)->draw(); + } + glPopMatrix(); +} + diff --git a/intern_disabled/FluxDiagram.h b/intern_disabled/FluxDiagram.h new file mode 100755 index 0000000..75b6ef1 --- /dev/null +++ b/intern_disabled/FluxDiagram.h @@ -0,0 +1,23 @@ +#ifndef _FluxDiagram_H_ +#define _FluxDiagram_H_ + + +#include "Satellite.h" +#include "TreeNode.h" + +class FluxDiagram : public Satellite{ + public: + float pos; + deque nodes; + FluxDiagram(float position); + ~FluxDiagram(); + + void step(); + void draw(); + +}; + + + +#endif + diff --git a/intern_disabled/GameGrid.cpp b/intern_disabled/GameGrid.cpp new file mode 100755 index 0000000..6b61c72 --- /dev/null +++ b/intern_disabled/GameGrid.cpp @@ -0,0 +1,145 @@ +#include "GameGrid.h" +#include "jttoolkit.h" +#include "Global.h" + + +GameGrid::GameGrid(float sld):Satellite(){ + steps = 7; + slide=sld; + boardHeight = 100; + for(int i=0;i<100;i++){ + rnd.push_back(randomFloat()); + } + clover.load("media/christianisms/clover.png"); + + Clover::phrases.push_back("If Joe throws the ball to Bill, Evan needs to run and block the second offensive man."); + Clover::phrases.push_back("Assuming Mr. Kim caught the pass on play #353, run 20 yards past the quarterback."); + Clover::phrases.push_back("Quarterback jumps over other quarterback then catch the ball."); + Clover::phrases.push_back("Throw the ball to the other player and run away."); + Clover::phrases.push_back("Block the receiving 45. Sneak past the offensive line and touch down gracefully."); + Clover::phrases.push_back("In play 238, the eagle crows when the lizard finds the sacred egg. No bluffing!"); + + createCloverList(); + populateSpots(); +} + + + +void GameGrid::createCloverList(){ + //make clover shape. + cloverList = glGenLists(1); + glNewList(cloverList,GL_COMPILE); + glColor4f(1,1,1,0.3); +#define DRAWBALL glutSolidSphere(0.13,6,6) + DRAWBALL; + + glPushMatrix(); + glTranslatef(0.35,0,0); + DRAWBALL; + glPopMatrix(); + + glPushMatrix(); + glTranslatef(-0.35,0,0); + DRAWBALL; + glPopMatrix(); + + glPushMatrix(); + glTranslatef(0,0.35,0); + DRAWBALL; + glPopMatrix(); + + glPushMatrix(); + glTranslatef(0,-0.35,0); + DRAWBALL; + glPopMatrix(); +#undef DRAWBALL + + glEndList(); +} + +void GameGrid::populateSpots(){ + //populate spots. + JRect f = Global::instance->field; + float incX = f.width() /steps; + float incY = boardHeight/steps; + + for(int yi=1;yi::iterator i=spots.begin() ; i!=spots.end() ; i++){ + (*i).step(); + } + + + //swap positions? + Clover c1 = spots[(int)(randomFloat()*spots.size())]; + Clover c2 = spots[(int)(randomFloat()*spots.size())]; + c1.dest.swap(c2.dest); + + + //reset everyone? + if(randomFloat()>0.999){ + for(deque::iterator i=spots.begin() ; i!=spots.end() ; i++){ + (*i).softReset(); + } + } + + +} + + + +void GameGrid::draw(){ + + /* + //make canvas + glColor4f(1,1,1,0.05); + glBegin(GL_POLYGON); + glVertex3f( Global::field.x2 , 0 , 0 ); + glVertex3f( Global::field.x1 , 0 , 0 ); + glVertex3f( Global::field.x1 , 0 , boardHeight ); + glVertex3f( Global::field.x2 , 0 , boardHeight ); + glEnd(); + */ + + //draw rects. + + + //draw the clovers + for(deque::iterator i=spots.begin() ; i!=spots.end() ; i++){ + (*i).draw(cloverList); + } + + //connect the clovers based on random vals. + + glColor4f(1,0.5,0,0.2); + glBegin(GL_LINES); + for(int i=3;i<20;i++){ + Clover c1 = spots[rnd[i]*spots.size()]; + Clover c2 = spots[rnd[i-1]*spots.size()]; + Clover c3 = spots[rnd[i-2]*spots.size()]; + Clover c4 = spots[rnd[i-3]*spots.size()]; + bezier(c1,c2,c3,c4,100); + } + glEnd(); +} diff --git a/intern_disabled/GameGrid.h b/intern_disabled/GameGrid.h new file mode 100755 index 0000000..c64a6c6 --- /dev/null +++ b/intern_disabled/GameGrid.h @@ -0,0 +1,29 @@ +#ifndef _GameGrid_H_ +#define _GameGrid_H_ + +#include "Satellite.h" +#include "JImage.h" +#include "Clover.h" +#include + +class GameGrid : public Satellite{ + public: + vector rnd; + int steps; + float slide; + float boardHeight; + deque spots; + JImage clover; + int cloverList; + GameGrid(float sld); + ~GameGrid(); + void step(); + void draw(); + void populateSpots(); + void createCloverList(); +}; + + + +#endif + diff --git a/intern_disabled/Guy.cpp b/intern_disabled/Guy.cpp new file mode 100755 index 0000000..e3f2fb0 --- /dev/null +++ b/intern_disabled/Guy.cpp @@ -0,0 +1,68 @@ +#include "Guy.h" +#include "jttoolkit.h" +#include "Global.h" + +Guy::Guy(int glDisplayList,float x,float y,int teamID,int id_){ + model = glDisplayList; + pos.x = x; + pos.y = y; + team = teamID; + id=id_; + counter=0; + + for(int i=0;i<10;i++){ + rnd.push_back(randomFloat()); + } + + randomizeDirection(); + lag_theta = theta;//catch up now, cause it's the beginning. +} + +Guy::~Guy(){ +} + +void Guy::step(){ + lag_theta+=(theta-lag_theta)*0.2; + pos+=(dest-pos)*(0.02*rnd[1]); + if(!Global::instance->field.pointInside(pos)){ + //choose another direction. + randomizeDirection(); + } + + counter++; + + int modable = round(this->rnd[0]*100+1); + + if(counter % modable ==0){ + randomizeDirection(); + } + + +} + +void Guy::draw(){ + + float b = 1; + if(!team)b=0.3; + + glPushMatrix(); + pos.glTranslate(); + glScalef(6,6,6); + glRotatef(90+lag_theta*(180/PI),0,0,1); + glTranslatef(0,1,0); + + glColor4f(1,1,b,0.05); + + glCallList(model); + glPopMatrix(); + + //lense connectors. + Global::instance->lensePlane(pos,pos+JPoint(0,0,11),1,1,b,0.01); + +} + + +void Guy::randomizeDirection(){ + Global::instance->field.randomPoint(&dest); + theta = pos.thetaFrom(dest); +} diff --git a/intern_disabled/Guy.h b/intern_disabled/Guy.h new file mode 100755 index 0000000..7164da3 --- /dev/null +++ b/intern_disabled/Guy.h @@ -0,0 +1,31 @@ +#ifndef _Guy_H_ +#define _Guy_H_ + +#include "JPoint.h" +#include "vector" + +using namespace std; + +class Guy{ + public: + int team; + int counter; + vector rnd; + float theta; + float lag_theta; + JPoint pos; + JPoint dest; + int model; + int id; + Guy(int,float,float,int,int); + ~Guy(); + void draw(); + void step(); + void randomizeDirection(); + +}; + + + +#endif + diff --git a/intern_disabled/GuyConnectors.cpp b/intern_disabled/GuyConnectors.cpp new file mode 100755 index 0000000..e9e9021 --- /dev/null +++ b/intern_disabled/GuyConnectors.cpp @@ -0,0 +1,81 @@ +#include "GuyConnectors.h" +#include "jttoolkit.h" +#include "Global.h" + +GuyConnectors::GuyConnectors(){ + for(int i=0;iathletes->guys.size()*2;i++){ + rnd.push_back(randomFloat()); + } +} + +GuyConnectors::~GuyConnectors(){ + +} + +void GuyConnectors::step(){ + +} + +void GuyConnectors::draw(){ + + glEnable(GL_LINE_SMOOTH); + glTranslatef(0,0,5); + JoshFont *f = getFont(); + for( int i=0;iathletes->guys.size()-1;i++){ + Guy g1 = Global::instance->athletes->guys[i]; + Guy g2 = Global::instance->athletes->guys[i+1]; + JPoint elevate(0,0,g1.pos.distanceFrom(g2.pos)); + + int modulee = (int)round(rnd[i]*200+10); + int modResult = ticks() % modulee; + float a = fabs((modResult/(float)modulee) - 0.5) - 0.1; + glColor4f(1,1,0.5,a); + + bezier(g1.pos, + g1.pos+elevate, + g2.pos+elevate, + g2.pos, + 30); + + + glColor4f(1,1,0.5,a*0.03); + Global::instance->lenseBezier(g1.pos, + g1.pos+elevate, + g2.pos+elevate, + g2.pos, + 30 + ); + + + glColor4f(1,1,0.5,a); + bezier(g1.pos, + g1.pos, + g2.pos, + g2.pos, + 30); + + //draw label for parabola + glPushMatrix(); + JPoint labelPos = (elevate+g1.pos.lerpTo(g2.pos,0.5)); + labelPos.glTranslate(); + glRotatef(90,0,1,0); + glRotatef(180,0,0,1); + //glRotatef( 180 ,0,0,1); + glRotatef( g1.pos.thetaFrom(g2.pos)*(180/PI) , 1,0,0); + + char labelStr[64]; + sprintf(labelStr,"E=%f",labelPos.z); + glTranslatef(-10,0,-5); + f->drawString(labelStr,2,0); + glRotatef(90,0,0,1); + glRotatef(90,0,1,0); + sprintf(labelStr,"D=%f",labelPos.z*2); + f->drawString(labelStr,2,0); + glPopMatrix(); + } + + + + +} + diff --git a/intern_disabled/GuyConnectors.h b/intern_disabled/GuyConnectors.h new file mode 100755 index 0000000..cf04c1b --- /dev/null +++ b/intern_disabled/GuyConnectors.h @@ -0,0 +1,23 @@ +#ifndef _GuyConnectors_H_ +#define _GuyConnectors_H_ + + +#include "Satellite.h" +#include "Global.h" +#include + +class GuyConnectors : public Satellite{ + public: + vector rnd; + GuyConnectors(); + ~GuyConnectors(); + + void step(); + void draw(); + +}; + + + +#endif + diff --git a/intern_disabled/GuyPointer.cpp b/intern_disabled/GuyPointer.cpp new file mode 100755 index 0000000..98b739b --- /dev/null +++ b/intern_disabled/GuyPointer.cpp @@ -0,0 +1,31 @@ +#include "GuyPointer.h" +#include "Global.h" +#include "Athletes.h" +#include "Guy.h" +#include "jttoolkit.h" + + +GuyPointer::GuyPointer(){ + //this assumes all the guys exist before i do. cause i'm counting them. + int s = Global::instance->athletes->guys.size(); + for(int i=0;iathletes->guys[i])); + } +} + +GuyPointer::~GuyPointer(){ + +} + +void GuyPointer::step(){ + for( vector::iterator i=signs.begin();i!=signs.end();i++ ){ + (*i)->step(); + } + +} + +void GuyPointer::draw(){ + for( vector::iterator i=signs.begin();i!=signs.end();i++ ){ + (*i)->draw(); + } +} diff --git a/intern_disabled/GuyPointer.h b/intern_disabled/GuyPointer.h new file mode 100755 index 0000000..af67730 --- /dev/null +++ b/intern_disabled/GuyPointer.h @@ -0,0 +1,21 @@ +#ifndef _GuyPointer_H_ +#define _GuyPointer_H_ + +#include "Satellite.h" +#include +#include "StatSign.h" +#include "JImage.h" + +class GuyPointer : public Satellite{ + public: + vector signs; + GuyPointer(); + ~GuyPointer(); + void step(); + void draw(); +}; + + + +#endif + diff --git a/intern_disabled/JImageSequence.cpp b/intern_disabled/JImageSequence.cpp new file mode 100755 index 0000000..c4f7768 --- /dev/null +++ b/intern_disabled/JImageSequence.cpp @@ -0,0 +1,56 @@ +#include "JImageSequence.h" +#include "jttoolkit.h" +#include "Global.h" + +void JImageSequence::load(char *filestr_, int begin_, int end){ + filestr = new char[512]; + sprintf(filestr,"%s",filestr_); + begin=begin_; + //load frame 1. + char filename[512]; + sprintf(filename,filestr,begin); + frames.push_back(new JImage(filename)); + + + max = end-begin; + counter = 0; + frameNum = begin; +} + +JImageSequence::JImageSequence(char *filestr_, int begin, int end){ + load(filestr_,begin,end); +} + +JImageSequence::~JImageSequence(){ + delete filestr; + for(int i=0;idrawList(); +} + diff --git a/intern_disabled/JImageSequence.h b/intern_disabled/JImageSequence.h new file mode 100755 index 0000000..2f67662 --- /dev/null +++ b/intern_disabled/JImageSequence.h @@ -0,0 +1,30 @@ +#ifndef _JImageSequence_H_ +#define _JImageSequence_H_ + + +#include "JImage.h" +#include + +using namespace std; + +class JImageSequence { + public: + int frameNum; + int counter; + int max; + int begin; + char *filestr; + vector frames; + JImageSequence(char *filestr, int begin,int end); + JImageSequence(); + ~JImageSequence(); + void step(); + void stepBack(); + void draw(); + void load(char *filestr, int begin,int end); +}; + + + +#endif + diff --git a/intern_disabled/JRect.cpp b/intern_disabled/JRect.cpp new file mode 100755 index 0000000..bdfcd5b --- /dev/null +++ b/intern_disabled/JRect.cpp @@ -0,0 +1,46 @@ +#include "JRect.h" +#include "jttoolkit.h" + + + +void JRect::randomPoint(JPoint *out){ + out->x = randomFloat()*(x2-x1) + x1; + out->y = randomFloat()*(y2-y1) + y1; +} + +JRect::JRect(){ + +} + +JRect::~JRect(){ + +} + + +void JRect::initCorners(float x1_,float y1_,float x2_,float y2_){ + x1 = x1_; + y1 = y1_; + x2 = x2_; + y2 = y2_; + +} + + +void JRect::glRect(){ + glRectf(x1,y1,x2,y2); +} + +int JRect::pointInside(JPoint p){ + if(p.xx1 && p.yy1){ + return true; + }else return false; +} + + +float JRect::width(){ + return x2-x1; +} + +float JRect::height(){ + return y2-y1; +} diff --git a/intern_disabled/JRect.h b/intern_disabled/JRect.h new file mode 100755 index 0000000..bb304a2 --- /dev/null +++ b/intern_disabled/JRect.h @@ -0,0 +1,25 @@ +#ifndef _JRect_H_ +#define _JRect_H_ + +#include "JPoint.h" + +class JRect{ + public: + float x1; + float y1; + float x2; + float y2; + JRect(); + ~JRect(); + void initCorners(float x1,float y1,float x2,float y2); + void glRect(); + void randomPoint(JPoint *out); + int pointInside(JPoint p); + float width(); + float height(); +}; + + + +#endif + diff --git a/intern_disabled/NetTicket.cpp b/intern_disabled/NetTicket.cpp new file mode 100755 index 0000000..5793d1d --- /dev/null +++ b/intern_disabled/NetTicket.cpp @@ -0,0 +1,90 @@ +#include "NetTicket.h" + +NetTicket::NetTicket(char*theURL){ + if(!jtHTTPClient_started)jtHTTPClient_init();//start the shared engine if not started. + stringWriter = new Vector(); + data = new char[1];data[0]=0; + url = theURL; + status = -1; + progressMax = -1; + progress = -1; + jtHTTPClient_curlQueue->push((long)this); +} + +NetTicket::~NetTicket(){ + //jtHTTPClient_deleteMatch((long)this);//remove myself from the global queue in case I am in there. + //ok this is terrible, but if you delete it mid-download, it will cause the system to crash. + delete stringWriter; + delete [] data; +} + + +void jtHTTPClient_init(){ + jtHTTPClient_started = 1; + jtHTTPClient_curlQueue = new Vector(); + jtHTTPClient__curl = curl_easy_init(); + curl_easy_setopt(jtHTTPClient__curl,CURLOPT_NOPROGRESS,0); + curl_easy_setopt(jtHTTPClient__curl,CURLOPT_PROGRESSFUNCTION,jtHTTPClient_progress_callback); + curl_easy_setopt(jtHTTPClient__curl,CURLOPT_WRITEFUNCTION,jtHTTPClient_write_data); + pthread_create(&jtHTTPClient_myThread,NULL,jtHTTPClient_threadFunc,NULL); + + // scheduling parameters of target thread + +} + + +void jtHTTPClient_reset(){ + curl_easy_cleanup(jtHTTPClient__curl); + delete jtHTTPClient_curlQueue; + jtHTTPClient_init(); +} + + +size_t jtHTTPClient_write_data(void*buffer,size_t size,size_t nmemb,void *userp){ + char*b = (char*)buffer; + NetTicket *thisTicket = (NetTicket*)jtHTTPClient_curlQueue->get(0); + for(int i=0;istringWriter->push((long)b[i]); + if(i%20==0)sched_yield(); + } + return nmemb; +} + +char*jtHTTPClient_getData(NetTicket *ticket){ + return ticket->stringWriter->createString(); +} + +void *jtHTTPClient_threadFunc(void*stuff){ + while(true){ + //always sorting through for unattended tickets. + while(jtHTTPClient_curlQueue->count>0){ + NetTicket *thisTicket = (NetTicket*)jtHTTPClient_curlQueue->get(0); + + curl_easy_setopt(jtHTTPClient__curl,CURLOPT_URL,thisTicket->url); + int result = curl_easy_perform(jtHTTPClient__curl); + if(result==0){//fill data + delete thisTicket->data; + thisTicket->data = thisTicket->stringWriter->createStringSleepy(); + } + thisTicket->status = result; + jtHTTPClient_curlQueue->unshift(); + //curl_easy_cleanup(jtHTTPClient__curl); + //printf("threadfunc working\n",0); + sched_yield(); + } + sched_yield(); + } +} + +int jtHTTPClient_progress_callback(void *clientp, + double dltotal, + double dlnow, + double ultotal, + double ulnow) { + + //printf("%f %f %f %f\n",dltotal,dlnow,ultotal,ulnow); + NetTicket *thisTicket = (NetTicket*)jtHTTPClient_curlQueue->get(0); + thisTicket->progress = dlnow; + thisTicket->progressMax = dltotal; + return 0; +} diff --git a/intern_disabled/NetTicket.h b/intern_disabled/NetTicket.h new file mode 100755 index 0000000..e7a0ad1 --- /dev/null +++ b/intern_disabled/NetTicket.h @@ -0,0 +1,35 @@ +#ifndef _NETTICKET_H_ +#define _NETTICKET_H_ +#include "Vector.h" + +#ifdef WIN32 +#define SOCKET long +#endif + + +#include "curl/curl.h" +#include + +class NetTicket{ + public: + NetTicket(char*url); + ~NetTicket(); + char *url; + char *data; + int status; + float progressMax; + float progress; + Vector *stringWriter; +}; + +//global queuing system using curl +static Vector *jtHTTPClient_curlQueue; +static CURL*jtHTTPClient__curl; +static int jtHTTPClient_started = 0; +static pthread_t jtHTTPClient_myThread; +void jtHTTPClient_init(); +void jtHTTPClient_reset(); +int jtHTTPClient_progress_callback(void *clientp,double dltotal,double dlnow,double ultotal,double ulnow); +size_t jtHTTPClient_write_data(void*buffer,size_t size,size_t nmemb,void *userp); +void *jtHTTPClient_threadFunc(void*stuff); +#endif diff --git a/intern_disabled/NeuralHanger.cpp b/intern_disabled/NeuralHanger.cpp new file mode 100755 index 0000000..abca24a --- /dev/null +++ b/intern_disabled/NeuralHanger.cpp @@ -0,0 +1,64 @@ +#include "NeuralHanger.h" +#include "jttoolkit.h" +#include "Global.h" + +NeuralHanger::NeuralHanger():JPoint(0,0,0){ + for(int i=0;i<5;i++)rnd.push_back(randomFloat()); + counter=0; + radius = 0; + theta = 0; + destRadius = 0; + destTheta = 0; + lineWidth = 2; +} + +NeuralHanger::~NeuralHanger(){ + +} + +void NeuralHanger::step(){ + + counter++; + + radius += (destRadius-radius)*0.3; + theta += (destTheta-theta)*0.3; + + //sampling the color in the space. + JPoint p = offset + tip; + + ColorRGB backplatePixel; + ColorRGB screenPixel; + //backplate pixel color + backplatePixel = Global::instance->backplate.pixelColor(p.x,p.y); + + //current screen buffer pixel color + if(Global::instance->pixels!=NULL)screenPixel = Global::instance->pixels->pixelColor(p.x,p.y); + + if(p.x>0 && p.y>0 && p.x < width() && p.y < height()){ + if( screenPixel.red() < backplatePixel.red()/6+0 ){ + children.push_back(new NeuralHanger()); + children.back()->depth = depth+1; + children.back()->destRadius = destRadius + (randomFloat()-0.5)*depth*0.3; + children.back()->destTheta = destTheta + (randomFloat()-0.5)*1; + children.back()->theta = children.back()->destTheta;//start theta off on the right track. + children.back()->lineWidth = fabs(lineWidth+(randomFloat()-0.5)*3); + } + } + + + for(int i=0;istep(); +} + +void NeuralHanger::draw(JPoint external_offset){ + tip.copyFrom(JPoint(radius*cos(theta), + radius*sin(theta),0)); + + offset.copyFrom(external_offset); + glLineWidth((int)lineWidth); + glBegin(GL_LINES); + (offset).glVertex(); + (tip+offset).glVertex(); + glEnd(); + for(int i=0;idraw(offset+tip); +} + diff --git a/intern_disabled/NeuralHanger.h b/intern_disabled/NeuralHanger.h new file mode 100755 index 0000000..355d4f9 --- /dev/null +++ b/intern_disabled/NeuralHanger.h @@ -0,0 +1,42 @@ +#ifndef _NeuralHanger_H_ +#define _NeuralHanger_H_ + + +#include "JPoint.h" +#include + +using namespace std; + +class NeuralHanger : public JPoint{ + public: + + JPoint offset; + JPoint tip; + + float lineWidth; + + int counter; + int matureTime; + + float radius; + float destRadius; + + float theta; + float destTheta; + + int depth; + + vector rnd; + vector children; + NeuralHanger(); + ~NeuralHanger(); + + void step(); + void draw(JPoint offset); + +}; + + + +#endif + diff --git a/intern_disabled/OrniArrow1.cpp b/intern_disabled/OrniArrow1.cpp new file mode 100755 index 0000000..9ae8cb3 --- /dev/null +++ b/intern_disabled/OrniArrow1.cpp @@ -0,0 +1,33 @@ +#include "OrniArrow1.h" +#include "jttoolkit.h" +#include "Global.h" + +OrniArrow1::OrniArrow1(){ + for(int i=0;i<5;i++)rnd.push_back(randomFloat()); +} + +OrniArrow1::~OrniArrow1(){ + +} + +void OrniArrow1::step(){ + +} + +void OrniArrow1::draw(int counter,JPoint end){ + glPushMatrix(); + glColor4f(1,1,1,0.3); + end.glTranslate(); + float sc = counter*0.4; + glRotatef(rnd[4]*360,0,0,1); + glBegin(GL_TRIANGLES); + glVertex3f(-0.8*sc,0,0); + glVertex3f(0,0,0.5*sc); + glVertex3f(0,0,1*sc); + glVertex3f(0.8*sc,0,0); + glVertex3f(0,0,0.5*sc); + glVertex3f(0,0,1*sc); + glEnd(); + glPopMatrix(); +} + diff --git a/intern_disabled/OrniArrow1.h b/intern_disabled/OrniArrow1.h new file mode 100755 index 0000000..49ddf63 --- /dev/null +++ b/intern_disabled/OrniArrow1.h @@ -0,0 +1,24 @@ +#ifndef _OrniArrow1_H_ +#define _OrniArrow1_H_ + +#include "TreeOrniment.h" +#include +#include "JPoint.h" + +using namespace std; + +class OrniArrow1 : public TreeOrniment{ + public: + vector rnd; + OrniArrow1(); + ~OrniArrow1(); + + void step(); + void draw(int counter,JPoint end); + +}; + + + +#endif + diff --git a/intern_disabled/OrniBubbleRing1.cpp b/intern_disabled/OrniBubbleRing1.cpp new file mode 100755 index 0000000..0d02b1a --- /dev/null +++ b/intern_disabled/OrniBubbleRing1.cpp @@ -0,0 +1,36 @@ +#include "OrniBubbleRing1.h" +#include "jttoolkit.h" +#include "Global.h" + +OrniBubbleRing1::OrniBubbleRing1(){ + for(int i=0;i<6;i++)rnd.push_back(randomFloat()); +} + +OrniBubbleRing1::~OrniBubbleRing1(){ + +} + +void OrniBubbleRing1::step(){ + +} + +void OrniBubbleRing1::draw(int counter,JPoint end){ + //draw circular bubble blowing thing + glPushMatrix(); + glLineWidth(10); + glColor4f(1,1,1,0.3); + end.glTranslate(); + float sc = counter*1; + glRotatef(rnd[4]*360 + (ticks()*( rnd[5]-0.5 )*20),0,0,1); + float steps = 60; + float inc = (PI*2)/steps; + glBegin(GL_LINES); + for(int i=0;i + +using namespace std; + +class OrniBubbleRing1 : public TreeOrniment{ + public: + vector rnd; + OrniBubbleRing1(); + ~OrniBubbleRing1(); + + void step(); + void draw(int counter,JPoint end); + +}; + + + +#endif + diff --git a/intern_disabled/OrniBubbleRing2.cpp b/intern_disabled/OrniBubbleRing2.cpp new file mode 100755 index 0000000..ecc7986 --- /dev/null +++ b/intern_disabled/OrniBubbleRing2.cpp @@ -0,0 +1,35 @@ +#include "OrniBubbleRing2.h" +#include "jttoolkit.h" +#include "Global.h" + +OrniBubbleRing2::OrniBubbleRing2(){ + for(int i=0;i<6;i++)rnd.push_back(randomFloat()); + +} + +OrniBubbleRing2::~OrniBubbleRing2(){ + +} + +void OrniBubbleRing2::step(){ + +} + +void OrniBubbleRing2::draw(int counter,JPoint end){ + + glPushMatrix(); + glColor4f(1,1,1,0.1); + glLineWidth(2); + end.glTranslate(); + float sc = counter*0.3; + glRotatef(rnd[4]*360 + (ticks()*( rnd[5]-0.5 )*20),0,0,1); + + glScalef(sc,sc,sc); + glRotatef(90,1,0,0); + glRotatef(90,0,1,0); + Global::instance->bubblering_model->outlineFaces(); + glLineWidth(1); + glPopMatrix(); + +} + diff --git a/intern_disabled/OrniBubbleRing2.h b/intern_disabled/OrniBubbleRing2.h new file mode 100755 index 0000000..8d50774 --- /dev/null +++ b/intern_disabled/OrniBubbleRing2.h @@ -0,0 +1,24 @@ +#ifndef _OrniBubbleRing2_H_ +#define _OrniBubbleRing2_H_ + + +#include "TreeOrniment.h" +#include + +using namespace std; + +class OrniBubbleRing2 : public TreeOrniment{ + public: + vector rnd; + OrniBubbleRing2(); + ~OrniBubbleRing2(); + + void step(); + void draw(int counter,JPoint end); + +}; + + + +#endif + diff --git a/intern_disabled/OrniTriangle1.cpp b/intern_disabled/OrniTriangle1.cpp new file mode 100755 index 0000000..31d21a0 --- /dev/null +++ b/intern_disabled/OrniTriangle1.cpp @@ -0,0 +1,41 @@ +#include "OrniTriangle1.h" +#include "jttoolkit.h" +#include "Global.h" + +OrniTriangle1::OrniTriangle1(){ + for(int i=0;i<6;i++)rnd.push_back(randomFloat()); + +} + +OrniTriangle1::~OrniTriangle1(){ + +} + +void OrniTriangle1::step(){ + +} + +void OrniTriangle1::draw(int counter,JPoint end){ + //draw upside down triangle thing + glPushMatrix(); + glColor4f(1,1,0.1,0.1); + glLineWidth(1); + end.glTranslate(); + float sc = counter*0.8; + glRotatef(rnd[4]*360 + (ticks()*( rnd[5]-0.5 )*20),0,0,1); + + //glBegin(GL_LINE_LOOP); + //glVertex3f(0, 0, 0); + //glVertex3f(0, 5*sc,10*sc); + //glVertex3f(0,-5*sc,10*sc); + //glEnd(); + + glScalef(sc,sc,sc); + glRotatef(90,1,0,0); + glRotatef(90,0,1,0); + Global::instance->triangle_gem_model->outlineFaces(); + glLineWidth(1); + glPopMatrix(); + +} + diff --git a/intern_disabled/OrniTriangle1.h b/intern_disabled/OrniTriangle1.h new file mode 100755 index 0000000..20899f4 --- /dev/null +++ b/intern_disabled/OrniTriangle1.h @@ -0,0 +1,24 @@ +#ifndef _OrniTriangle1_H_ +#define _OrniTriangle1_H_ + + +#include "TreeOrniment.h" +#include + +using namespace std; + +class OrniTriangle1 : public TreeOrniment{ + public: + vector rnd; + OrniTriangle1(); + ~OrniTriangle1(); + + void step(); + void draw(int counter,JPoint end); + +}; + + + +#endif + diff --git a/intern_disabled/Raster2Vector.cpp b/intern_disabled/Raster2Vector.cpp new file mode 100755 index 0000000..3ca9736 --- /dev/null +++ b/intern_disabled/Raster2Vector.cpp @@ -0,0 +1,300 @@ +#include "Raster2Vector.h" + + +/* + Rastor to Vector convertion object by Josh Nimoy, April 2002, jtnimoy@ucla.edu + */ + +Raster2Vector::~Raster2Vector(){ + delete [] vectors; + delete [] paths; + delete [] bits; + delete [] reg; +} + +Raster2Vector::Raster2Vector(int width, int height){ + this->picW = width; + this->picH = height; + this->vectors = new VECTOR[picW*picH * 4]; + this->paths = new unsigned int[picW*picH*256]; + this->bits = new unsigned char[picW*picH]; + this->reg = new PointReg[(picW+1)*(picH+1)]; +} + +//################################################################################################ + +void Raster2Vector::generateVectors(){ + this->vCount = 0; + //printf("converting to edges to vectors\n",NULL); + //create vectors from the bitmap data, creating square-sides only if a border + + + //clear the registry + for(int i=0;i<(picW+1)*(picH+1);i++)reg[i].state=0; + + //generate + for(int y=0;y0){ + if(bits[y*picW+(x-1)]==255)newVector(x,y,x,y+1); + }else newVector(x,y,x,y+1); + //XX + //34 + if(y0){ + if(bits[picW*(y-1)+x]==255)newVector(x+1,y,x,y); + }else newVector(x+1,y,x,y); + } + } + } + + //printf("chaining...\n",NULL); + //chain them together + pathCount=0; + for(int i=0;istate){ + case 0: + // ah, a pioneer. + thisReg->waitingPt = &vectors[vCount].p1; + break; + case 1: + //there was a lover waiting! + vectors[vCount].p1.state = 1; + thisReg->waitingPt->state = 1; + break; + case 2: + //no threesomes allowed - get your own partner! + thisReg->waitingPt = &vectors[vCount].p1; + thisReg->waitingPt->state = 1; + vectors[vCount].p1.x+=bendFactor; + vectors[vCount].p1.y+=bendFactor; + break; + case 3: + //there was a mutant lover waiting! + vectors[vCount].p1.x+=bendFactor; + vectors[vCount].p1.y+=bendFactor; + vectors[vCount].p1.state = 1; + break; + default: + printf("%i exception!\n",thisReg->state); + } + thisReg->state++; + + + //switch gears for p2 + + thisReg = ®[int(vectors[vCount].p2.y)*(picW)+int(vectors[vCount].p2.x)]; + + + //printf("%i p2 %f\t%f\t%f\t%i\n",vCount,vectors[vCount].p2.x,vectors[vCount].p2.y,vectors[vCount].p2.y*picW+vectors[vCount].p2.x,int(vectors[vCount].p2.y)*picW+int(vectors[vCount].p2.x)); + + switch(thisReg->state){ + case 0: + // ah, a pioneer. + thisReg->waitingPt = &vectors[vCount].p2; + break; + case 1: + //there was a lover waiting! + vectors[vCount].p2.state = 1; + thisReg->waitingPt->state = 1; + break; + case 2: + //no threesomes allowed - get your own partner! + thisReg->waitingPt = &vectors[vCount].p2; + thisReg->waitingPt->state = 1; + vectors[vCount].p2.x+=bendFactor; + vectors[vCount].p2.y+=bendFactor; + break; + case 3: + //there was a mutant lover waiting! + vectors[vCount].p2.x+=bendFactor; + vectors[vCount].p2.y+=bendFactor; + vectors[vCount].p2.state = 1; + break; + default: + printf("%i exception!\n",thisReg->state); + } + thisReg->state++; + +} diff --git a/intern_disabled/Raster2Vector.h b/intern_disabled/Raster2Vector.h new file mode 100755 index 0000000..551ff97 --- /dev/null +++ b/intern_disabled/Raster2Vector.h @@ -0,0 +1,66 @@ +#ifndef RASTER2VECTOR +#define RASTER2VECTOR + + +#include + +/* + Rastor to Vector convertion object by Josh Nimoy, April 2002, jtnimoy@ucla.edu + */ + + +struct FLOATPOINT{ + float x; + float y; + int state; +}; +////////////////////////////////// + + +#define EQUALPOINTS(p1,p2) ((p1.x==p2.x)&&(p1.y==p2.y)) + +struct VECTOR{ + FLOATPOINT p1; + FLOATPOINT p2; + int state; +}; +////////////////////////////////// + + +struct PointReg{ + unsigned char state; + FLOATPOINT *waitingPt; +}; + +///////////////////////////////// +class Raster2Vector{ +public: + + int vCount; + int picW; + int picH; + + unsigned char *bits; + + VECTOR *vectors; + unsigned int *paths; + int pathCount; + + void generateVectors(); ////this will do the actual convertion. + + PointReg *reg; + + Raster2Vector(int width, int height); + ~Raster2Vector(); + /////////////////////////////// + bool equalVectors(int v1,int v2); + void newVector(float x,float y,float xx,float yy); + void newVector(int x,int y,int xx,int yy); + void bendDuplicates(); + void bendDuplicates2(); +}; + + +////////////////////////////////// +#endif + diff --git a/intern_disabled/Satellite.cpp b/intern_disabled/Satellite.cpp new file mode 100755 index 0000000..50d828a --- /dev/null +++ b/intern_disabled/Satellite.cpp @@ -0,0 +1,18 @@ +#include "Satellite.h" + +Satellite::Satellite(){ + +} + +Satellite::~Satellite(){ + +} + +void Satellite::step(){ + +} + +void Satellite::draw(){ + +} + diff --git a/intern_disabled/Satellite.h b/intern_disabled/Satellite.h new file mode 100755 index 0000000..1c12b63 --- /dev/null +++ b/intern_disabled/Satellite.h @@ -0,0 +1,17 @@ +#ifndef _Satellite_H_ +#define _Satellite_H_ + + + +class Satellite{ + public: + Satellite(); + ~Satellite(); + virtual void step();//step time, with no drawing routines. + virtual void draw();//render yoself, without incrementing any of the animation stuff. +}; + + + +#endif + diff --git a/intern_disabled/ShotProfile.cpp b/intern_disabled/ShotProfile.cpp new file mode 100755 index 0000000..ad56d5b --- /dev/null +++ b/intern_disabled/ShotProfile.cpp @@ -0,0 +1,62 @@ +#include "ShotProfile.h" +#include "jttoolkit.h" +#include "Global.h" +#include "gl_et_al.h" + +void ShotProfile::nudge(float x,float y,float z){ + offsetX+=x; + offsetY+=y; + offsetZ+=z; + + +} + +void ShotProfile::glTranslate(){ + glTranslatef( offsetX+translateX+forceX*counter , + offsetY+translateY+forceY*counter , + offsetZ+translateZ+forceZ*counter ); +} + +void ShotProfile::reset(){ + counter=0; + offsetX=0; + offsetY=0; + offsetZ=0; +} + +void ShotProfile::step(){ + counter++; +} + +ShotProfile::ShotProfile(int vis, + float tx,float ty,float tz, + float fx,float fy,float fz, + float ws,float tmy,float tmx,float langle + ){ + translateX = tx; + translateY = ty; + translateZ = tz; + + forceX = fx; + forceY = fy; + forceZ = fz; + + gameVisible=vis; + + tumbleX = tmx; + tumbleY = tmy; + + lenseAngle = langle; + + worldScale = ws; + reset(); +} + +ShotProfile::~ShotProfile(){ + +} + + +void ShotProfile::perspective(){ + viewPerspective(lenseAngle); +} diff --git a/intern_disabled/ShotProfile.h b/intern_disabled/ShotProfile.h new file mode 100755 index 0000000..cfe13fa --- /dev/null +++ b/intern_disabled/ShotProfile.h @@ -0,0 +1,40 @@ +#ifndef _ShotProfile_H_ +#define _ShotProfile_H_ + +class ShotProfile { + private: + float translateX; + float translateY; + float translateZ; + float offsetX; + float offsetY; + float offsetZ; + float forceX; + float forceY; + float forceZ; + float lenseAngle; + public: + float tumbleY; + float tumbleX; + int gameVisible; + float worldScale; + int counter; + void reset(); + void step(); + void glTranslate(); + void perspective(); + void nudge(float x,float y,float z); + + ShotProfile(int vis, + float tx,float ty,float tz, + float fx,float fy,float fz, + float ws,float tmy,float tmx, + float lenseAngle_); + ~ShotProfile(); + +}; + + + +#endif + diff --git a/intern_disabled/StatSign.cpp b/intern_disabled/StatSign.cpp new file mode 100755 index 0000000..f67fb05 --- /dev/null +++ b/intern_disabled/StatSign.cpp @@ -0,0 +1,108 @@ +#include "StatSign.h" +#include "jttoolkit.h" +#include "Global.h" + +StatSign::StatSign(Guy *g){ + guy=g; + counter=0; + for(int i=0;i<2;i++){ + rnd.push_back(randomFloat()); + } + state=0; + char fname[256]; + sprintf(fname,"media/cardfaces/%02i.png",g->id); + face = new JImage(fname); +} + +StatSign::~StatSign(){ + delete face; +} + +void StatSign::step(){ + + if(state==1)counter++; + if(state==2)counter--; + + if(counter>10)counter=10; + if(counter<0)counter=0; + + float ratio = 0.995; + if(state==1)ratio = 0.9; + if(randomFloat()>ratio && (counter==10 || counter==0)){ + float r= randomFloat(); + if(r>0.5){ + state = 2; + }else{ + state = 1; + } + + } +} + +void StatSign::draw(){ + + + float globalscale = fmin(1,counter*0.1); + + Guy g =(*guy); + glColor4f(1,1,1,0.3); + glPushMatrix(); + + glRotatef((1-globalscale)*90,0,0,1); + + //draw arrow + glPushMatrix(); + (g.pos+JPoint(0,0,12*globalscale)).glTranslate(); + + glRotatef(Global::instance->tumbleY+90,1,0,0);//auto-orient , billboard, lookAtCamera + glScalef(globalscale,globalscale,globalscale); + glBegin(GL_POLYGON); + glVertex3f(0,0,0); + glVertex3f(0,-1,2); + glVertex3f(0,0,1); + glVertex3f(0,1,2); + glEnd(); + + glPopMatrix(); + + glBegin(GL_LINE_STRIP); + (g.pos+JPoint(0,0,12*globalscale)).glVertex(); + (g.pos+JPoint(0,0,25*globalscale)).glVertex(); + JPoint jutOut = g.pos+JPoint(0,0,25*globalscale); + jutOut -= (JPoint(0,0,0)-jutOut)*(0.5 * globalscale); + jutOut.glVertex(); + glEnd(); + + (jutOut-JPoint(12*globalscale,0,-2)).glTranslate(); + glScalef(globalscale,globalscale,globalscale); + glRotatef(90,1,0,0); + + //light milky background filler + glColor4f(1,1,0.5,0.1); + roundedRect(GL_POLYGON,-12,-10, 12,10, 1,5); + + + //draw the photo + glPushMatrix(); + glTranslatef(-1.25,8,0); + glScalef(16,16,0); + glRotatef(180,0,0,1); + glColor4f(1,1,1,0.5); + face->drawList(); + glPopMatrix(); + + //layout outlines + glColor4f(1,1,1,0.3); + roundedRect(GL_LINE_LOOP,-12,-10, 12,10, 1,5); + roundedRect(GL_LINE_LOOP,-10,-8, -1 , 8, 0.5,5); + + //some little white filled doodaads to populate the layout. + float textscaler = fmin(1,counter*0.1); + glRectf(-1, 3 , 5*textscaler , 4 ); + glRectf(-1, 2 , 4*textscaler , 2.5); + glRectf(-1, 4 , -4*textscaler , 5.5); + glRectf(-1, -1 , -5*textscaler , -2 ); + + glPopMatrix(); +} + diff --git a/intern_disabled/StatSign.h b/intern_disabled/StatSign.h new file mode 100755 index 0000000..2df8bfd --- /dev/null +++ b/intern_disabled/StatSign.h @@ -0,0 +1,28 @@ +#ifndef _StatSign_H_ +#define _StatSign_H_ + + +#include "Satellite.h" +#include "Guy.h" +#include "JImage.h" +#include + +using namespace std; + +class StatSign : public Satellite{ + public: + JImage *face; + Guy *guy; + StatSign(Guy *g); + ~StatSign(); + void step(); + void draw(); + int counter; + vector rnd; + int state; +}; + + + +#endif + diff --git a/intern_disabled/TheBall.cpp b/intern_disabled/TheBall.cpp new file mode 100755 index 0000000..c2e7351 --- /dev/null +++ b/intern_disabled/TheBall.cpp @@ -0,0 +1,93 @@ +#include "TheBall.h" +#include "gl_et_al.h" +#include "jttoolkit.h" +#include "Global.h" + +float TheBall::FRICTION = 1; +float TheBall::GRAVITY = -0.4; + +TheBall::TheBall(){ + + x = 0; + y = 0; + z = 0; + forceX=4; + forceY=3; + forceZ=4; + + radius = 1; +} + +TheBall::~TheBall(){ + +} + + +void TheBall::step(){ + float leap = 5; + + //apply forces + x += forceX; + y += forceY; + z += forceZ; + + //apply friction + forceX *= FRICTION; + forceY *= FRICTION; + forceZ *= FRICTION; + + forceZ += GRAVITY; + + //collide with the field boundaries and ground. + if(z<0){ + z=0; + forceZ=-forceZ*0.5;//grass friction + } + + if(xfield.x1){ + x=Global::instance->field.x1; + forceX = -forceX; + forceZ = 3;//kick it. + } + + if(x>Global::instance->field.x2){ + x=Global::instance->field.x2; + forceX = -forceX; + forceZ = 3;//kick it. + } + + if(yfield.y1){ + y=Global::instance->field.y1; + forceY = -forceY; + forceZ = 3;//kick it. + } + + if(y>Global::instance->field.y2){ + y=Global::instance->field.y2; + forceY = -forceY; + forceZ = 3;//kick it. + } + + + + +} + +void TheBall::draw(){ + + //draw the ball + glPushMatrix(); + glColor4f(0.3,0.1,0.05,0.9); + glTranslatef(x,y,z); + glutSolidSphere(radius,30,30); + glPopMatrix(); + + + //connect to lense + JPoint p1(x,y,z-radius); + JPoint p2(x,y,z+radius); + + glBindTexture(GL_TEXTURE_2D,0); + Global::instance->lensePlane(p1,p2, + 0.3,0.1,0.05,0.1); +} diff --git a/intern_disabled/TheBall.h b/intern_disabled/TheBall.h new file mode 100755 index 0000000..8705c1c --- /dev/null +++ b/intern_disabled/TheBall.h @@ -0,0 +1,31 @@ +#ifndef _TheBall_H_ +#define _TheBall_H_ + +#include "Satellite.h" + +class TheBall : public Satellite{ + public: + static float FRICTION; + static float GRAVITY; + float x; + float y; + float z; + + float forceX; + float forceY; + float forceZ; + + float radius; + + TheBall(); + ~TheBall(); + + void step(); + void draw(); + +}; + + + +#endif + diff --git a/intern_disabled/TreeNode.cpp b/intern_disabled/TreeNode.cpp new file mode 100755 index 0000000..81c3e69 --- /dev/null +++ b/intern_disabled/TreeNode.cpp @@ -0,0 +1,99 @@ +#include "TreeNode.h" +#include "jttoolkit.h" +#include "Global.h" + +TreeNode::TreeNode(int d,float xx,float yy,float zz,float rad,float th,float lw):JPoint(xx,yy,zz){ + lineWidth=lw; + depth = d; + theta = th; + radius = rad; + for(int i=0;i<5;i++)rnd.push_back(randomFloat()); + + + destOrigin.copyFrom(*this); + + + dest.x = radius*cos(theta); + dest.y = radius*sin(theta); + dest.z = 0; + + dieingParent = 0; + +} + +TreeNode::~TreeNode(){ + +} + +void TreeNode::step(){ + tip.lerpSelfTo(dest,0.2); + lerpSelfTo(destOrigin,0.2); + //have a baby? + + ColorRGB c = Global::instance->backplate.pixelColor((*this+dest).x,(*this+dest).y); + ColorRGB c2; + if(Global::instance->pixels!=NULL){ + c2 = Global::instance->pixels->pixelColor((*this+dest).x,(*this+dest).y); + } + float bright = (c.red() + c.green() + c.blue())/3; + float bright2 = (c2.red() + c2.green() + c2.blue())/3; + + if( ( randomFloat()>0.9 && children.size() < 4 && (( (bright > 0.5 || ticks() > 200) && bright2 < 0.1) || depth < 3) ) ){ + + float newTheta; + if(depth>4){ + newTheta = theta +(randomFloat()-0.5)*1; + }else{ + newTheta = theta +(randomFloat()-0.6)*1.1; + } + + children.push_back(new TreeNode(depth+1, //depth, necessary to pass this + 1 + tip.x,tip.y,tip.z, //position (will be constantly updated anyway + radius+(randomFloat()-0.5)*10, //radius + newTheta, //theta + lineWidth+(randomFloat()-0.5)*2 //line width + ) + ); + } + + for(int i=0;icopyFrom(*this+tip); + children[i]->destOrigin.copyFrom(*this+tip); + children[i]->step(); + } + + + if(dieingParent!=0){ + dieingParent->step(); + } + + +} + +void TreeNode::draw(){ + glColor4f(1,1,1,1); + glLineWidth((int)round(lineWidth)); + glBegin(GL_LINES); + glVertex(); + if(children.size()==0){ + glColor4f(1,1,1,0.0); + } + (*this+tip).glVertex(); + glEnd(); + + for(int i=0;idraw(); + } + + + if(dieingParent!=0){ + glBegin(GL_LINES); + glColor4f(1,1,1,1); + this->glVertex(); + glColor4f(1,1,1,0); + (*this+*dieingParent).glVertex(); + glEnd(); + } + +} + diff --git a/intern_disabled/TreeNode.h b/intern_disabled/TreeNode.h new file mode 100755 index 0000000..ac61b0c --- /dev/null +++ b/intern_disabled/TreeNode.h @@ -0,0 +1,37 @@ +#ifndef _TreeNode_H_ +#define _TreeNode_H_ + + +#include "JPoint.h" +#include "DieingParent.h" +#include + +using namespace std; + +class DieingParent; + +class TreeNode:public JPoint{ + public: + + float lineWidth; + int depth; + DieingParent *dieingParent; + JPoint tip; + JPoint dest; + JPoint destOrigin; + float theta; + float radius; + vector rnd; + vector children; + TreeNode(int,float,float,float,float,float,float); + ~TreeNode(); + + void step(); + void draw(); + +}; + + + +#endif + diff --git a/intern_disabled/TreeOrniment.cpp b/intern_disabled/TreeOrniment.cpp new file mode 100755 index 0000000..caa2774 --- /dev/null +++ b/intern_disabled/TreeOrniment.cpp @@ -0,0 +1,39 @@ +#include "TreeOrniment.h" +#include "jttoolkit.h" +#include "Global.h" + +TreeOrniment::TreeOrniment(){ + +} + +TreeOrniment::~TreeOrniment(){ + +} + +void TreeOrniment::step(){ + +} + +void TreeOrniment::draw(int counter,JPoint end){ + +} + + +/* + if(rnd[6]>0 && rnd[6] < 0.25){ + //draw pointing arrow + + + }else if(rnd[6]>0.25 && rnd[6] < 0.50 ){ + + + }else if(rnd[6]>0.50 && rnd[6] < 0.75 ){ + + + }else{ + + + //draw upside down triangle thing + + } +*/ diff --git a/intern_disabled/TreeOrniment.h b/intern_disabled/TreeOrniment.h new file mode 100755 index 0000000..fef04b2 --- /dev/null +++ b/intern_disabled/TreeOrniment.h @@ -0,0 +1,20 @@ +#ifndef _TreeOrniment_H_ +#define _TreeOrniment_H_ + +#include "gl_et_al.h" +#include "JPoint.h" + +class TreeOrniment { + public: + + TreeOrniment(); + ~TreeOrniment(); + virtual void step(); + virtual void draw(int counter,JPoint end); + +}; + + + +#endif + diff --git a/intern_disabled/equationlayouts.h b/intern_disabled/equationlayouts.h new file mode 100755 index 0000000..a7cac2d --- /dev/null +++ b/intern_disabled/equationlayouts.h @@ -0,0 +1,157 @@ +int data1_count = 8; +float data1[] = { + 124.000000,136.000000,77,115,SwappingEquation::LETTER, + 129.000000,130.000000,106,135,SwappingEquation::LETTER, + 127.000000,130.000000,154,113,SwappingEquation::LETTER, + 128.000000,130.000000,154,127,SwappingEquation::LETTER, + 124.000000,130.000000,254,85,SwappingEquation::LETTER, + 126.000000,130.000000,259,118,SwappingEquation::DIV, + 123.000000,130.000000,255,158,SwappingEquation::IGNOREME, + 128.000000,130.000000,290,156,SwappingEquation::LETTER +}; +int data2_count = 7; +float data2[] = { + 126.000000,135.000000,79,114,SwappingEquation::LETTER, + 130.000000,131.000000,106,136,SwappingEquation::LETTER, + 127.000000,128.000000,154,108,SwappingEquation::LETTER, + 129.000000,128.000000,156,124,SwappingEquation::LETTER, + 125.000000,127.000000,209,82,SwappingEquation::LETTER, + 126.000000,128.000000,212,116,SwappingEquation::LETTER, + 128.000000,128.000000,213,155,SwappingEquation::LETTER +}; +int data3_count = 9; +float data3[] = { + 119.000000,123.000000,70,135,SwappingEquation::LBRACKET, + 125.000000,132.000000,113,142,SwappingEquation::LETTER, + 130.000000,130.000000,176,142,SwappingEquation::LETTER, + 130.000000,128.000000,174,154,SwappingEquation::LETTER, + 115.000000,122.000000,254,131,SwappingEquation::IGNOREME, + 137.000000,123.000000,300,101,SwappingEquation::LETTER, + 131.000000,128.000000,297,147,SwappingEquation::LETTER, + 137.000000,131.000000,297,189,SwappingEquation::LETTER, + 141.000000,131.000000,369,143,SwappingEquation::RBRACKET +}; +int data4_count = 9; +float data4[] = { + 119.000000,129.000000,70,141,SwappingEquation::LBRACKET, + 125.000000,134.000000,114,145,SwappingEquation::LETTER, + 129.000000,131.000000,176,142,SwappingEquation::LETTER, + 129.000000,132.000000,174,158,SwappingEquation::LETTER, + 117.000000,121.000000,257,129,SwappingEquation::IGNOREME, + 128.000000,129.000000,303,106,SwappingEquation::LETTER, + 129.000000,130.000000,296,149,SwappingEquation::LETTER, + 134.000000,132.000000,292,193,SwappingEquation::LETTER, + 142.000000,130.000000,369,142,SwappingEquation::RBRACKET +}; +int data5_count = 11; +float data5[] = { + 117.000000,125.000000,67,138,SwappingEquation::LBRACKET, + 136.000000,128.000000,134,144,SwappingEquation::LETTER, + 127.000000,129.000000,152,180,SwappingEquation::LETTER, + 127.000000,129.000000,203,139,SwappingEquation::LETTER, + 130.000000,129.000000,205,156,SwappingEquation::LETTER, + 128.000000,129.000000,272,138,SwappingEquation::LETTER, + 127.000000,129.000000,293,179,SwappingEquation::LETTER, + 128.000000,128.000000,364,146,SwappingEquation::LETTER, + 128.000000,129.000000,444,137,SwappingEquation::LETTER, + 129.000000,131.000000,464,184,SwappingEquation::LETTER, + 139.000000,128.000000,504,140,SwappingEquation::RBRACKET +}; +int data6_count = 9; +float data6[] = { + 126.000000,133.000000,78,143,SwappingEquation::LETTER, + 127.000000,130.000000,109,165,SwappingEquation::LETTER, + 118.000000,131.000000,145,143,SwappingEquation::LBRACKET, + 128.000000,128.000000,194,148,SwappingEquation::LETTER, + 128.000000,130.000000,221,164,SwappingEquation::LETTER, + 128.000000,130.000000,267,149,SwappingEquation::LETTER, + 128.000000,130.000000,325,150,SwappingEquation::LETTER, + 128.000000,130.000000,354,165,SwappingEquation::LETTER, + 137.000000,131.000000,396,144,SwappingEquation::RBRACKET +}; +int data7_count = 8; +float data7[] = { + 130.000000,127.000000,69,146,SwappingEquation::LBRACKET, + 127.000000,127.000000,98,147,SwappingEquation::LETTER, + 129.000000,133.000000,127,168,SwappingEquation::LETTER, + 128.000000,130.000000,169,151,SwappingEquation::LETTER, + 128.000000,130.000000,229,150,SwappingEquation::LETTER, + 128.000000,130.000000,256,165,SwappingEquation::LETTER, + 128.000000,129.000000,273,148,SwappingEquation::RBRACKET, + 128.000000,134.000000,297,103,SwappingEquation::LETTER +}; +int data8_count = 10; +float data8[] = { + 128.000000,131.000000,93,150,SwappingEquation::DIV, + 120.000000,131.000000,93,142,SwappingEquation::LBRACKET, + 112.000000,130.000000,136,139,SwappingEquation::LETTER, + 126.000000,131.000000,208,139,SwappingEquation::LETTER, + 127.000000,130.000000,258,157,SwappingEquation::LETTER, + 128.000000,129.000000,302,147,SwappingEquation::DIV, + 128.000000,130.000000,366,139,SwappingEquation::LETTER, + 127.000000,130.000000,423,138,SwappingEquation::LETTER, + 136.000000,131.000000,486,141,SwappingEquation::LETTER, + 133.000000,131.000000,488,149,SwappingEquation::RBRACKET +}; + + + + + + + +/* + int data0_count = 26; + float data0[] = { + 47.000000, 63.000000, 178, 170, SwappingEquation::LETTER, + 46.000000, 70.000000, 174, 214, SwappingEquation::DIV, + 26.000000, 72.000000, 155, 260, SwappingEquation::LETTER, + 60.000000, 78.000000, 190, 266, SwappingEquation::LETTER, + 53.000000, 65.000000, 241, 214, SwappingEquation::LBRACKET, + 62.000000, 49.000000, 287, 202, SwappingEquation::LETTER, + 57.000000, 60.000000, 325, 212, SwappingEquation::LBRACKET, + 60.000000, 63.000000, 362, 215, SwappingEquation::LETTER, + 73.000000, 62.000000, 399, 213, SwappingEquation::RBRACKET, + 69.000000, 65.000000, 428, 214, SwappingEquation::RBRACKET, + 62.000000, 65.000000, 478, 216, SwappingEquation::IGNOREME, + 57.000000, 59.000000, 578, 165, SwappingEquation::LETTER, + 63.000000, 67.000000, 575, 213, SwappingEquation::DIV, + 66.000000, 69.000000, 554, 262, SwappingEquation::LETTER, + 58.000000, 70.000000, 593, 263, SwappingEquation::LETTER, + 56.000000, 69.000000, 640, 216, SwappingEquation::LBRACKET, + 64.000000, 54.000000, 681, 205, SwappingEquation::LETTER, + 55.000000, 64.000000, 719, 212, SwappingEquation::LBRACKET, + 66.000000, 63.000000, 755, 214, SwappingEquation::LETTER, + 77.000000, 62.000000, 798, 213, SwappingEquation::RBRACKET, + 72.000000, 63.000000, 821, 211, SwappingEquation::RBRACKET, + 59.000000, 57.000000, 865, 162, SwappingEquation::LETTER, + 76.000000, 59.000000, 904, 165, SwappingEquation::LETTER, + 76.000000, 66.000000, 889, 212, SwappingEquation::DIV, + 59.000000, 75.000000, 866, 262, SwappingEquation::LETTER, + 82.000000, 73.000000, 901, 265, SwappingEquation::LETTER + }; + + + int data1_count = 7; + float data1[] = { + 128.000000, 126.000000, 184, 239, SwappingEquation::LETTER, + 136.000000, 127.000000, 270, 112, SwappingEquation::LETTER, + 128.000000, 130.000000, 223, 117, SwappingEquation::LETTER, + 127.000000, 130.000000, 181, 168, SwappingEquation::LETTER, + 117.000000, 128.000000, 94, 112, SwappingEquation::LETTER, + 130.000000, 131.000000, 149, 114, SwappingEquation::LETTER, + 128.000000, 129.000000, 184, 114, SwappingEquation::LETTER + }; + + int data2_count = 7; + float data2[] = { + 130.000000,134.000000,114,93,SwappingEquation::LETTER, + 127.000000,132.000000,202,87,SwappingEquation::LETTER, + 126.000000,128.000000,108,195,SwappingEquation::LETTER, + 128.000000,128.000000,156,133,SwappingEquation::LETTER, + 128.000000,129.000000,154,195,SwappingEquation::LETTER, + 128.000000,130.000000,153,84,SwappingEquation::LETTER, + 128.000000,133.000000,204,203,SwappingEquation::LETTER + }; + +*/ diff --git a/intern_disabled/gl2ps.c b/intern_disabled/gl2ps.c new file mode 100755 index 0000000..f5909db --- /dev/null +++ b/intern_disabled/gl2ps.c @@ -0,0 +1,2298 @@ +/* + * GL2PS, an OpenGL to PostScript Printing Library + * Copyright (C) 1999-2003 Christophe Geuzaine + * + * $Id: gl2ps.c,v 1.1.1.1 2004/01/09 21:54:34 administrator Exp $ + * + * E-mail: geuz@geuz.org + * URL: http://www.geuz.org/gl2ps/ + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Contributor(s): + * Michael Sweet + * Marc Ume + * Jean-Francois Remacle + * Bart Kaptein + * Quy Nguyen-Dai + * Sam Buss + * Shane Hill + * Romain Boman + * Rouben Rostamian + * Diego Santa Cruz + * Shahzad Muzaffar + * Lassi Tuura + * Guy Barrand + */ + + +#if defined(__DARWIN__) + #include +#else + #include +#endif + + +#include +#include +#include +#include "gl2ps.h" + +/* The gl2ps context. gl2ps is not thread safe (we should create a + local GL2PScontext during gl2psBeginPage) */ + +GL2PScontext *gl2ps = NULL; + +/* Some 'system' utility routines */ + +void gl2psMsg(GLint level, char *fmt, ...){ + va_list args; + + if(!(gl2ps->options & GL2PS_SILENT)){ + switch(level){ + case GL2PS_INFO : fprintf(stderr, "GL2PS info: "); break; + case GL2PS_WARNING : fprintf(stderr, "GL2PS warning: "); break; + case GL2PS_ERROR : fprintf(stderr, "GL2PS error: "); break; + } + va_start(args, fmt); + vfprintf(stderr, fmt, args); + va_end(args); + fprintf(stderr, "\n"); + } + /* if(level == GL2PS_ERROR) exit(1); */ +} + +void *gl2psMalloc(size_t size){ + void *ptr; + + if(!size) return(NULL); + ptr = malloc(size); + if(!ptr){ + gl2psMsg(GL2PS_ERROR, "Couldn't allocate requested memory"); + exit(1); + } + return(ptr); +} + +void *gl2psRealloc(void *ptr, size_t size){ + if(!size) return(NULL); + ptr = realloc(ptr, size); + if(!ptr){ + gl2psMsg(GL2PS_ERROR, "Couldn't reallocate requested memory"); + exit(1); + } + return(ptr); +} + +void gl2psFree(void *ptr){ + if(!ptr) return; + free(ptr); +} + +/* The list handling routines */ + +void gl2psListRealloc(GL2PSlist *list, GLint n){ + if(n <= 0) return; + if(!list->array){ + list->nmax = ((n - 1) / list->incr + 1) * list->incr; + list->array = (char *)gl2psMalloc(list->nmax * list->size); + } + else{ + if(n > list->nmax){ + list->nmax = ((n - 1) / list->incr + 1) * list->incr; + list->array = (char *)gl2psRealloc(list->array, + list->nmax * list->size); + } + } +} + +GL2PSlist *gl2psListCreate(GLint n, GLint incr, GLint size){ + GL2PSlist *list; + + if(n < 0) n = 0; + if(incr <= 0) incr = 1; + list = (GL2PSlist *)gl2psMalloc(sizeof(GL2PSlist)); + list->nmax = 0; + list->incr = incr; + list->size = size; + list->n = 0; + list->array = NULL; + gl2psListRealloc(list, n); + return(list); +} + +void gl2psListReset(GL2PSlist *list){ + list->n = 0; +} + +void gl2psListDelete(GL2PSlist *list){ + gl2psFree(list->array); + gl2psFree(list); +} + +void gl2psListAdd(GL2PSlist *list, void *data){ + list->n++; + gl2psListRealloc(list, list->n); + memcpy(&list->array[(list->n - 1) * list->size], data, list->size); +} + +GLint gl2psListNbr(GL2PSlist *list){ + return(list->n); +} + +void *gl2psListPointer(GL2PSlist *list, GLint index){ + if((index < 0) || (index >= list->n)){ + gl2psMsg(GL2PS_ERROR, "Wrong list index in gl2psListPointer"); + return(&list->array[0]); + } + return(&list->array[index * list->size]); +} + +void gl2psListSort(GL2PSlist *list, + int (*fcmp)(const void *a, const void *b)){ + qsort(list->array, list->n, list->size, fcmp); +} + +void gl2psListAction(GL2PSlist *list, + void (*action)(void *data, void *dummy)){ + GLint i, dummy; + + for(i = 0; i < gl2psListNbr(list); i++){ + (*action)(gl2psListPointer(list, i), &dummy); + } +} + +void gl2psListActionInverse(GL2PSlist *list, + void (*action)(void *data, void *dummy)){ + GLint i, dummy; + + for(i = gl2psListNbr(list); i > 0; i--){ + (*action)(gl2psListPointer(list, i-1), &dummy); + } +} + +/* The 3D sorting routines */ + +GLfloat gl2psComparePointPlane(GL2PSxyz point, GL2PSplane plane){ + return(plane[0] * point[0] + + plane[1] * point[1] + + plane[2] * point[2] + + plane[3]); +} + +GLfloat gl2psPsca(GLfloat *a, GLfloat *b){ + return(a[0]*b[0] + a[1]*b[1] + a[2]*b[2]); +} + +void gl2psPvec(GLfloat *a, GLfloat *b, GLfloat *c){ + c[0] = a[1]*b[2] - a[2]*b[1]; + c[1] = a[2]*b[0] - a[0]*b[2]; + c[2] = a[0]*b[1] - a[1]*b[0]; +} + +GLfloat gl2psNorm(GLfloat *a){ + return sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]); +} + +void gl2psGetNormal(GLfloat *a, GLfloat *b, GLfloat *c){ + GLfloat norm; + + gl2psPvec(a, b, c); + if(!GL2PS_ZERO(norm = gl2psNorm(c))){ + c[0] = c[0] / norm; + c[1] = c[1] / norm; + c[2] = c[2] / norm; + } + else{ + /* FIXME: the plane is still wrong, despite our tests in + gl2psGetPlane... Let's return a dummy value for now (this is a + hack: we should do more tests in GetPlane) */ + c[0] = c[1] = 0.; + c[2] = 1.; + } +} + +void gl2psGetPlane(GL2PSprimitive *prim, GL2PSplane plane){ + GL2PSxyz v = {0., 0., 0.}, w = {0., 0., 0.}; + + switch(prim->type){ + case GL2PS_TRIANGLE : + case GL2PS_QUADRANGLE : + v[0] = prim->verts[1].xyz[0] - prim->verts[0].xyz[0]; + v[1] = prim->verts[1].xyz[1] - prim->verts[0].xyz[1]; + v[2] = prim->verts[1].xyz[2] - prim->verts[0].xyz[2]; + w[0] = prim->verts[2].xyz[0] - prim->verts[0].xyz[0]; + w[1] = prim->verts[2].xyz[1] - prim->verts[0].xyz[1]; + w[2] = prim->verts[2].xyz[2] - prim->verts[0].xyz[2]; + if((GL2PS_ZERO(v[0]) && GL2PS_ZERO(v[1]) && GL2PS_ZERO(v[2])) || + (GL2PS_ZERO(w[0]) && GL2PS_ZERO(w[1]) && GL2PS_ZERO(w[2]))){ + plane[0] = plane[1] = 0.; + plane[2] = 1.; + plane[3] = -prim->verts[0].xyz[2]; + } + else{ + gl2psGetNormal(v, w, plane); + plane[3] = + - plane[0] * prim->verts[0].xyz[0] + - plane[1] * prim->verts[0].xyz[1] + - plane[2] * prim->verts[0].xyz[2]; + } + break; + case GL2PS_LINE : + v[0] = prim->verts[1].xyz[0] - prim->verts[0].xyz[0]; + v[1] = prim->verts[1].xyz[1] - prim->verts[0].xyz[1]; + v[2] = prim->verts[1].xyz[2] - prim->verts[0].xyz[2]; + if(GL2PS_ZERO(v[0]) && GL2PS_ZERO(v[1]) && GL2PS_ZERO(v[2])){ + plane[0] = plane[1] = 0.; + plane[2] = 1.; + plane[3] = -prim->verts[0].xyz[2]; + } + else{ + if(GL2PS_ZERO(v[0])) w[0] = 1.; + else if(GL2PS_ZERO(v[1])) w[1] = 1.; + else w[2] = 1.; + gl2psGetNormal(v, w, plane); + plane[3] = + - plane[0] * prim->verts[0].xyz[0] + - plane[1] * prim->verts[0].xyz[1] + - plane[2] * prim->verts[0].xyz[2]; + } + break; + case GL2PS_POINT : + case GL2PS_PIXMAP : + case GL2PS_TEXT : + plane[0] = plane[1] = 0.; + plane[2] = 1.; + plane[3] = -prim->verts[0].xyz[2]; + break; + default : + gl2psMsg(GL2PS_ERROR, "Unknown primitive type in BSP tree"); + plane[0] = plane[1] = plane[3] = 0.; + plane[2] = 1.; + break; + } +} + +void gl2psCutEdge(GL2PSvertex *a, GL2PSvertex *b, GL2PSplane plane, + GL2PSvertex *c){ + GL2PSxyz v; + GLfloat sect; + + v[0] = b->xyz[0] - a->xyz[0]; + v[1] = b->xyz[1] - a->xyz[1]; + v[2] = b->xyz[2] - a->xyz[2]; + sect = - gl2psComparePointPlane(a->xyz, plane) / gl2psPsca(plane, v); + + c->xyz[0] = a->xyz[0] + v[0] * sect; + c->xyz[1] = a->xyz[1] + v[1] * sect; + c->xyz[2] = a->xyz[2] + v[2] * sect; + + c->rgba[0] = (1.-sect) * a->rgba[0] + sect * b->rgba[0]; + c->rgba[1] = (1.-sect) * a->rgba[1] + sect * b->rgba[1]; + c->rgba[2] = (1.-sect) * a->rgba[2] + sect * b->rgba[2]; + c->rgba[3] = (1.-sect) * a->rgba[3] + sect * b->rgba[3]; +} + +void gl2psCreateSplitPrimitive(GL2PSprimitive *parent, GL2PSplane plane, + GL2PSprimitive *child, GLshort numverts, + GLshort *index0, GLshort *index1){ + GLshort i; + + if(numverts > 4){ + gl2psMsg(GL2PS_WARNING, "%d vertices in polygon", numverts); + numverts = 4; + } + + switch(numverts){ + case 1 : child->type = GL2PS_POINT; break; + case 2 : child->type = GL2PS_LINE; break; + case 3 : child->type = GL2PS_TRIANGLE; break; + case 4 : child->type = GL2PS_QUADRANGLE; break; + } + child->boundary = 0; /* not done! */ + child->depth = parent->depth; /* should not be used in this case */ + child->culled = parent->culled; + child->dash = parent->dash; + child->width = parent->width; + child->numverts = numverts; + child->verts = (GL2PSvertex *)gl2psMalloc(numverts * sizeof(GL2PSvertex)); + + for(i = 0; i < numverts; i++){ + if(index1[i] < 0){ + child->verts[i] = parent->verts[index0[i]]; + } + else{ + gl2psCutEdge(&parent->verts[index0[i]], &parent->verts[index1[i]], + plane, &child->verts[i]); + } + } +} + +void gl2psAddIndex(GLshort *index0, GLshort *index1, GLshort *nb, + GLshort i, GLshort j){ + GLint k; + + for(k = 0; k < *nb; k++){ + if((index0[k] == i && index1[k] == j) || + (index1[k] == i && index0[k] == j)) return; + } + index0[*nb] = i; + index1[*nb] = j; + (*nb)++; +} + +GLshort gl2psGetIndex(GLshort i, GLshort num){ + return(i < num-1) ? i+1 : 0; +} + +GLint gl2psTestSplitPrimitive(GL2PSprimitive *prim, GL2PSplane plane){ + GLint type = GL2PS_COINCIDENT; + GLshort i, j; + GLfloat d[5]; + + for(i = 0; i < prim->numverts; i++){ + d[i] = gl2psComparePointPlane(prim->verts[i].xyz, plane); + } + + if(prim->numverts < 2){ + return 0; + } + else{ + for(i = 0; i < prim->numverts; i++){ + j = gl2psGetIndex(i, prim->numverts); + if(d[j] > GL2PS_EPSILON){ + if(type == GL2PS_COINCIDENT) type = GL2PS_IN_BACK_OF; + else if(type != GL2PS_IN_BACK_OF) return 1; + if(d[i] < -GL2PS_EPSILON) return 1; + } + else if(d[j] < -GL2PS_EPSILON){ + if(type == GL2PS_COINCIDENT) type = GL2PS_IN_FRONT_OF; + else if(type != GL2PS_IN_FRONT_OF) return 1; + if(d[i] > GL2PS_EPSILON) return 1; + } + } + } + return 0; +} + +GLint gl2psSplitPrimitive(GL2PSprimitive *prim, GL2PSplane plane, + GL2PSprimitive **front, GL2PSprimitive **back){ + GLshort i, j, in=0, out=0, in0[5], in1[5], out0[5], out1[5]; + GLint type; + GLfloat d[5]; + + type = GL2PS_COINCIDENT; + + for(i = 0; i < prim->numverts; i++){ + d[i] = gl2psComparePointPlane(prim->verts[i].xyz, plane); + } + + switch(prim->type){ + case GL2PS_POINT : + if(d[0] > GL2PS_EPSILON) type = GL2PS_IN_BACK_OF; + else if(d[0] < -GL2PS_EPSILON) type = GL2PS_IN_FRONT_OF; + else type = GL2PS_COINCIDENT; + break; + default : + for(i = 0; i < prim->numverts; i++){ + j = gl2psGetIndex(i, prim->numverts); + if(d[j] > GL2PS_EPSILON){ + if(type == GL2PS_COINCIDENT) type = GL2PS_IN_BACK_OF; + else if(type != GL2PS_IN_BACK_OF) type = GL2PS_SPANNING; + if(d[i] < -GL2PS_EPSILON){ + gl2psAddIndex(in0, in1, &in, i, j); + gl2psAddIndex(out0, out1, &out, i, j); + type = GL2PS_SPANNING; + } + gl2psAddIndex(out0, out1, &out, j, -1); + } + else if(d[j] < -GL2PS_EPSILON){ + if(type == GL2PS_COINCIDENT) type = GL2PS_IN_FRONT_OF; + else if(type != GL2PS_IN_FRONT_OF) type = GL2PS_SPANNING; + if(d[i] > GL2PS_EPSILON){ + gl2psAddIndex(in0, in1, &in, i, j); + gl2psAddIndex(out0, out1, &out, i, j); + type = GL2PS_SPANNING; + } + gl2psAddIndex(in0, in1, &in, j, -1); + } + else{ + gl2psAddIndex(in0, in1, &in, j, -1); + gl2psAddIndex(out0, out1, &out, j, -1); + } + } + break; + } + + if(type == GL2PS_SPANNING){ + *back = (GL2PSprimitive*)gl2psMalloc(sizeof(GL2PSprimitive)); + *front = (GL2PSprimitive*)gl2psMalloc(sizeof(GL2PSprimitive)); + gl2psCreateSplitPrimitive(prim, plane, *back, out, out0, out1); + gl2psCreateSplitPrimitive(prim, plane, *front, in, in0, in1); + } + + return type; +} + +void gl2psDivideQuad(GL2PSprimitive *quad, + GL2PSprimitive **t1, GL2PSprimitive **t2){ + *t1 = (GL2PSprimitive*)gl2psMalloc(sizeof(GL2PSprimitive)); + *t2 = (GL2PSprimitive*)gl2psMalloc(sizeof(GL2PSprimitive)); + (*t1)->type = (*t2)->type = GL2PS_TRIANGLE; + (*t1)->numverts = (*t2)->numverts = 3; + (*t1)->depth = (*t2)->depth = quad->depth; + (*t1)->culled = (*t2)->culled = quad->culled; + (*t1)->dash = (*t2)->dash = quad->dash; + (*t1)->width = (*t2)->width = quad->width; + (*t1)->verts = (GL2PSvertex *)gl2psMalloc(3 * sizeof(GL2PSvertex)); + (*t2)->verts = (GL2PSvertex *)gl2psMalloc(3 * sizeof(GL2PSvertex)); + (*t1)->verts[0] = quad->verts[0]; + (*t1)->verts[1] = quad->verts[1]; + (*t1)->verts[2] = quad->verts[2]; + (*t1)->boundary = ((quad->boundary & 1) ? 1 : 0) | ((quad->boundary & 2) ? 2 : 0); + (*t2)->verts[0] = quad->verts[0]; + (*t2)->verts[1] = quad->verts[2]; + (*t2)->verts[2] = quad->verts[3]; + (*t1)->boundary = ((quad->boundary & 4) ? 2 : 0) | ((quad->boundary & 4) ? 2 : 0); +} + +int gl2psCompareDepth(const void *a, const void *b){ + GL2PSprimitive *q, *w; + GLfloat diff; + + q = *(GL2PSprimitive**)a; + w = *(GL2PSprimitive**)b; + diff = q->depth - w->depth; + if(diff > 0.){ + return 1; + } + else if(diff < 0.){ + return -1; + } + else{ + return 0; + } +} + +int gl2psTrianglesFirst(const void *a, const void *b){ + GL2PSprimitive *q, *w; + + q = *(GL2PSprimitive**)a; + w = *(GL2PSprimitive**)b; + return(q->type < w->type ? 1 : -1); +} + +GLint gl2psFindRoot(GL2PSlist *primitives, GL2PSprimitive **root){ + GLint i, j, count, best = 1000000, index = 0; + GL2PSprimitive *prim1, *prim2; + GL2PSplane plane; + GLint maxp; + + if(gl2ps->options & GL2PS_BEST_ROOT){ + *root = *(GL2PSprimitive**)gl2psListPointer(primitives, 0); + maxp = gl2psListNbr(primitives); + if(maxp > gl2ps->maxbestroot){ + maxp = gl2ps->maxbestroot; + } + for(i = 0; i < maxp; i++){ + prim1 = *(GL2PSprimitive**)gl2psListPointer(primitives, i); + gl2psGetPlane(prim1, plane); + count = 0; + for(j = 0; j < gl2psListNbr(primitives); j++){ + if(j != i){ + prim2 = *(GL2PSprimitive**)gl2psListPointer(primitives, j); + count += gl2psTestSplitPrimitive(prim2, plane); + } + if(count > best) break; + } + if(count < best){ + best = count; + index = i; + *root = prim1; + if(!count) return index; + } + } + /* if(index) gl2psMsg(GL2PS_INFO, "GL2PS_BEST_ROOT was worth it: %d", index); */ + return index; + } + else{ + *root = *(GL2PSprimitive**)gl2psListPointer(primitives, 0); + return 0; + } +} + +void gl2psFreePrimitive(void *a, void *b){ + GL2PSprimitive *q; + + q = *(GL2PSprimitive**)a; + gl2psFree(q->verts); + if(q->type == GL2PS_TEXT){ + gl2psFree(q->text->str); + gl2psFree(q->text->fontname); + gl2psFree(q->text); + } + if(q->type == GL2PS_PIXMAP){ + gl2psFree(q->image->pixels); + gl2psFree(q->image); + } + gl2psFree(q); +} + +void gl2psAddPrimitiveInList(GL2PSprimitive *prim, GL2PSlist *list){ + GL2PSprimitive *t1, *t2; + + if(prim->type != GL2PS_QUADRANGLE){ + gl2psListAdd(list, &prim); + } + else{ + gl2psDivideQuad(prim, &t1, &t2); + gl2psListAdd(list, &t1); + gl2psListAdd(list, &t2); + gl2psFreePrimitive(&prim, NULL); + } + +} + +void gl2psFreeBspTree(GL2PSbsptree **tree){ + if(*tree){ + if((*tree)->back) gl2psFreeBspTree(&(*tree)->back); + if((*tree)->primitives){ + gl2psListAction((*tree)->primitives, gl2psFreePrimitive); + gl2psListDelete((*tree)->primitives); + } + if((*tree)->front) gl2psFreeBspTree(&(*tree)->front); + gl2psFree(*tree); + *tree = NULL; + } +} + +GLboolean gl2psGreater(GLfloat f1, GLfloat f2){ + if(f1 > f2) return 1; + else return 0; +} + +GLboolean gl2psLess(GLfloat f1, GLfloat f2){ + if(f1 < f2) return 1; + else return 0; +} + +void gl2psBuildBspTree(GL2PSbsptree *tree, GL2PSlist *primitives){ + GL2PSprimitive *prim, *frontprim, *backprim; + GL2PSlist *frontlist, *backlist; + GLint i, index; + + tree->front = NULL; + tree->back = NULL; + tree->primitives = gl2psListCreate(1, 2, sizeof(GL2PSprimitive*)); + index = gl2psFindRoot(primitives, &prim); + gl2psGetPlane(prim, tree->plane); + gl2psAddPrimitiveInList(prim, tree->primitives); + + frontlist = gl2psListCreate(1, 2, sizeof(GL2PSprimitive*)); + backlist = gl2psListCreate(1, 2, sizeof(GL2PSprimitive*)); + + for(i = 0; i < gl2psListNbr(primitives); i++){ + if(i != index){ + prim = *(GL2PSprimitive**)gl2psListPointer(primitives,i); + switch(gl2psSplitPrimitive(prim, tree->plane, &frontprim, &backprim)){ + case GL2PS_COINCIDENT: + gl2psAddPrimitiveInList(prim, tree->primitives); + break; + case GL2PS_IN_BACK_OF: + gl2psAddPrimitiveInList(prim, backlist); + break; + case GL2PS_IN_FRONT_OF: + gl2psAddPrimitiveInList(prim, frontlist); + break; + case GL2PS_SPANNING: + gl2psAddPrimitiveInList(backprim, backlist); + gl2psAddPrimitiveInList(frontprim, frontlist); + gl2psFreePrimitive(&prim, NULL); + break; + } + } + } + + if(gl2psListNbr(tree->primitives)){ + gl2psListSort(tree->primitives, gl2psTrianglesFirst); + } + + if(gl2psListNbr(frontlist)){ + gl2psListSort(frontlist, gl2psTrianglesFirst); + tree->front = (GL2PSbsptree*)gl2psMalloc(sizeof(GL2PSbsptree)); + gl2psBuildBspTree(tree->front, frontlist); + } + else{ + gl2psListDelete(frontlist); + } + + if(gl2psListNbr(backlist)){ + gl2psListSort(backlist, gl2psTrianglesFirst); + tree->back = (GL2PSbsptree*)gl2psMalloc(sizeof(GL2PSbsptree)); + gl2psBuildBspTree(tree->back, backlist); + } + else{ + gl2psListDelete(backlist); + } + + gl2psListDelete(primitives); +} + +void gl2psTraverseBspTree(GL2PSbsptree *tree, GL2PSxyz eye, GLfloat epsilon, + GLboolean (*compare)(GLfloat f1, GLfloat f2), + void (*action)(void *data, void *dummy)){ + GLfloat result; + + if(!tree) return; + + result = gl2psComparePointPlane(eye, tree->plane); + + if(compare(result, epsilon)){ + gl2psTraverseBspTree(tree->back, eye, epsilon, compare, action); + gl2psListAction(tree->primitives, action); + gl2psTraverseBspTree(tree->front, eye, epsilon, compare, action); + } + else if(compare(-epsilon, result)){ + gl2psTraverseBspTree(tree->front, eye, epsilon, compare, action); + gl2psListAction(tree->primitives, action); + gl2psTraverseBspTree(tree->back, eye, epsilon, compare, action); + } + else{ + gl2psTraverseBspTree(tree->front, eye, epsilon, compare, action); + gl2psTraverseBspTree(tree->back, eye, epsilon, compare, action); + } +} + +/* The 2D sorting routines (for occlusion culling) */ + +GLint gl2psGetPlaneFromPoints(GL2PSxyz a, GL2PSxyz b, GL2PSplane plane){ + GLfloat n; + + plane[0] = b[1] - a[1]; + plane[1] = a[0] - b[0]; + n = sqrt(plane[0]*plane[0] + plane[1]*plane[1]); + plane[2]=0.; + if(n != 0.){ + plane[0] /= n; + plane[1] /= n; + plane[3] = -plane[0]*a[0]-plane[1]*a[1]; + return 1; + } + else{ + plane[0] = -1.0; + plane[1] = 0.; + plane[3] = a[0]; + return 0; + } +} + +void gl2psFreeBspImageTree(GL2PSbsptree2d **tree){ + if(*tree){ + if((*tree)->back) gl2psFreeBspImageTree(&(*tree)->back); + if((*tree)->front) gl2psFreeBspImageTree(&(*tree)->front); + gl2psFree(*tree); + *tree = NULL; + } +} + +GLint gl2psCheckPoint(GL2PSxyz point, GL2PSplane plane){ + GLfloat pt_dis; + + pt_dis = gl2psComparePointPlane(point, plane); + if(pt_dis > GL2PS_EPSILON) return GL2PS_POINT_INFRONT; + else if(pt_dis < -GL2PS_EPSILON) return GL2PS_POINT_BACK; + else return GL2PS_POINT_COINCIDENT; +} + +void gl2psAddPlanesInBspTreeImage(GL2PSprimitive *prim, + GL2PSbsptree2d **tree){ + GLint ret = 0; + GLint i; + GLint offset = 0; + GL2PSbsptree2d *head = NULL, *cur = NULL; + + if((*tree == NULL) && (prim->numverts > 2)){ + head = (GL2PSbsptree2d*)gl2psMalloc(sizeof(GL2PSbsptree2d)); + for(i = 0; i < prim->numverts-1; i++){ + if(!gl2psGetPlaneFromPoints(prim->verts[i].xyz, + prim->verts[i+1].xyz, + head->plane)){ + if(prim->numverts-i > 3){ + offset++; + } + else{ + gl2psFree(head); + return; + } + } + else{ + break; + } + } + head->back = NULL; + head->front = NULL; + for(i = 2+offset; i < prim->numverts; i++){ + ret = gl2psCheckPoint(prim->verts[i].xyz, head->plane); + if(ret != GL2PS_POINT_COINCIDENT) break; + } + switch(ret){ + case GL2PS_POINT_INFRONT : + cur = head; + for(i = 1+offset; i < prim->numverts-1; i++){ + if(cur->front == NULL){ + cur->front = (GL2PSbsptree2d*)gl2psMalloc(sizeof(GL2PSbsptree2d)); + } + if(gl2psGetPlaneFromPoints(prim->verts[i].xyz, + prim->verts[i+1].xyz, + cur->front->plane)){ + cur = cur->front; + cur->front = NULL; + cur->back = NULL; + } + } + if(cur->front == NULL){ + cur->front = (GL2PSbsptree2d*)gl2psMalloc(sizeof(GL2PSbsptree2d)); + } + if(gl2psGetPlaneFromPoints(prim->verts[i].xyz, + prim->verts[offset].xyz, + cur->front->plane)){ + cur->front->front = NULL; + cur->front->back = NULL; + } + else{ + gl2psFree(cur->front); + cur->front = NULL; + } + break; + case GL2PS_POINT_BACK : + for(i = 0; i < 4; i++){ + head->plane[i] = -head->plane[i]; + } + cur = head; + for(i = 1+offset; i < prim->numverts-1; i++){ + if(cur->front == NULL){ + cur->front = (GL2PSbsptree2d*)gl2psMalloc(sizeof(GL2PSbsptree2d)); + } + if(gl2psGetPlaneFromPoints(prim->verts[i+1].xyz, + prim->verts[i].xyz, + cur->front->plane)){ + cur = cur->front; + cur->front = NULL; + cur->back = NULL; + } + } + if(cur->front == NULL){ + cur->front = (GL2PSbsptree2d*)gl2psMalloc(sizeof(GL2PSbsptree2d)); + } + if(gl2psGetPlaneFromPoints(prim->verts[offset].xyz, + prim->verts[i].xyz, + cur->front->plane)){ + cur->front->front = NULL; + cur->front->back = NULL; + } + else{ + gl2psFree(cur->front); + cur->front = NULL; + } + break; + default: + gl2psFree(head); + return; + } + (*tree) = head; + } +} + +GLint gl2psCheckPrimitive(GL2PSprimitive *prim, GL2PSplane plane){ + GLint i; + GLint pos; + + pos = gl2psCheckPoint(prim->verts[0].xyz, plane); + for(i = 1; i < prim->numverts; i++){ + pos |= gl2psCheckPoint(prim->verts[i].xyz, plane); + if(pos == (GL2PS_POINT_INFRONT | GL2PS_POINT_BACK)) return GL2PS_SPANNING; + } + if(pos & GL2PS_POINT_INFRONT) return GL2PS_IN_FRONT_OF; + else if(pos & GL2PS_POINT_BACK) return GL2PS_IN_BACK_OF; + else return GL2PS_COINCIDENT; +} + +GL2PSprimitive* gl2psCreateSplitPrimitive2D(GL2PSprimitive *parent, + GLshort numverts, + GL2PSvertex *vertx){ + GLint i; + GL2PSprimitive *child = (GL2PSprimitive*)gl2psMalloc(sizeof(GL2PSprimitive)); + + switch(numverts){ + case 1 : child->type = GL2PS_POINT; break; + case 2 : child->type = GL2PS_LINE; break; + case 3 : child->type = GL2PS_TRIANGLE; break; + case 4 : child->type = GL2PS_QUADRANGLE; break; + } + child->boundary = 0; /* not done! */ + child->depth = parent->depth; + child->culled = parent->culled; + child->dash = parent->dash; + child->width = parent->width; + child->numverts = numverts; + child->verts = (GL2PSvertex *)gl2psMalloc(numverts * sizeof(GL2PSvertex)); + for(i = 0; i < numverts; i++){ + child->verts[i] = vertx[i]; + } + return child; +} + +void gl2psSplitPrimitive2D(GL2PSprimitive *prim, + GL2PSplane plane, + GL2PSprimitive **front, + GL2PSprimitive **back){ + + /* cur will hold the position of the current vertex + prev will hold the position of the previous vertex + prev0 will hold the position of the vertex number 0 + v1 and v2 represent the current and previous vertices, respectively + flag is set if the current vertex should be checked against the plane */ + GLint cur = -1, prev = -1, i, v1 = 0, v2 = 0, flag = 1, prev0 = -1; + + /* list of vertices that will go in front and back primitive */ + GL2PSvertex *front_list = NULL, *back_list = NULL; + + /* number of vertices in front and back list */ + GLint front_count = 0, back_count = 0; + + for(i = 0; i <= prim->numverts; i++){ + v1 = i; + if(v1 == prim->numverts){ + if(prim->numverts < 3) break; + v1 = 0; + v2 = prim->numverts-1; + cur = prev0; + } + else if(flag){ + cur = gl2psCheckPoint(prim->verts[v1].xyz, plane); + if(i == 0){ + prev0 = cur; + } + } + if(((prev == -1) || (prev == cur) || (prev == 0) || (cur == 0)) && + (i < prim->numverts)){ + if(cur == GL2PS_POINT_INFRONT){ + front_count++; + front_list = (GL2PSvertex*)gl2psRealloc(front_list, + sizeof(GL2PSvertex)*front_count); + front_list[front_count-1] = prim->verts[v1]; + } + else if(cur == GL2PS_POINT_BACK){ + back_count++; + back_list = (GL2PSvertex*)gl2psRealloc(back_list, + sizeof(GL2PSvertex)*back_count); + back_list[back_count-1] = prim->verts[v1]; + } + else{ + front_count++; + front_list = (GL2PSvertex*)gl2psRealloc(front_list, + sizeof(GL2PSvertex)*front_count); + front_list[front_count-1] = prim->verts[v1]; + back_count++; + back_list = (GL2PSvertex*)gl2psRealloc(back_list, + sizeof(GL2PSvertex)*back_count); + back_list[back_count-1] = prim->verts[v1]; + } + flag = 1; + } + else if((prev != cur) && (cur != 0) && (prev != 0)){ + if(v1 != 0){ + v2 = v1-1; + i--; + } + front_count++; + front_list = (GL2PSvertex*)gl2psRealloc(front_list, + sizeof(GL2PSvertex)*front_count); + gl2psCutEdge(&prim->verts[v2], + &prim->verts[v1], + plane, + &front_list[front_count-1]); + back_count++; + back_list = (GL2PSvertex*)gl2psRealloc(back_list, + sizeof(GL2PSvertex)*back_count); + back_list[back_count-1] = front_list[front_count-1]; + flag = 0; + } + prev = cur; + } + *front = gl2psCreateSplitPrimitive2D(prim, front_count, front_list); + *back = gl2psCreateSplitPrimitive2D(prim, back_count, back_list); + gl2psFree(front_list); + gl2psFree(back_list); +} + +GLint gl2psAddInBspImageTree(GL2PSprimitive *prim, GL2PSbsptree2d **tree){ + GLint ret = 0; + GL2PSprimitive *frontprim = NULL, *backprim = NULL; + + /* FIXME: until we consider the actual extent of text strings and + pixmaps, never cull them. Otherwise the whole string/pixmap gets + culled as soon as the reference point is hidden */ + if(prim->type == GL2PS_PIXMAP || prim->type == GL2PS_TEXT){ + return 1; + } + + if(*tree == NULL){ + gl2psAddPlanesInBspTreeImage(prim, tree); + return 1; + } + else{ + switch(gl2psCheckPrimitive(prim, (*tree)->plane)){ + case GL2PS_IN_BACK_OF: return gl2psAddInBspImageTree(prim, &(*tree)->back); + case GL2PS_IN_FRONT_OF: + if((*tree)->front != NULL) return gl2psAddInBspImageTree(prim, &(*tree)->front); + else return 0; + case GL2PS_SPANNING: + gl2psSplitPrimitive2D(prim, (*tree)->plane, &frontprim, &backprim); + ret = gl2psAddInBspImageTree(backprim, &(*tree)->back); + if((*tree)->front != NULL){ + if(gl2psAddInBspImageTree(frontprim, &(*tree)->front)){ + ret = 1; + } + } + gl2psFree(frontprim->verts); + gl2psFree(frontprim); + gl2psFree(backprim->verts); + gl2psFree(backprim); + return ret; + case GL2PS_COINCIDENT: + if(prim->numverts < 3) return 1; + else return 0; + } + } + return 0; +} + +void gl2psAddInImageTree(void *a, void *b){ + GL2PSprimitive *prim = *(GL2PSprimitive **)a; + + if(!gl2psAddInBspImageTree(prim, &gl2ps->imagetree)){ + prim->culled = 1; + } +} + +/* Boundary contruction */ + +void gl2psAddBoundaryInList(GL2PSprimitive *prim, GL2PSlist *list){ + GL2PSprimitive *b; + GLshort i; + GL2PSxyz c; + + c[0] = c[1] = c[2] = 0.; + for(i = 0; i < prim->numverts; i++){ + c[0] += prim->verts[i].xyz[0]; + c[1] += prim->verts[i].xyz[1]; + } + c[0] /= prim->numverts; + c[1] /= prim->numverts; + + for(i = 0; i < prim->numverts; i++){ + if(prim->boundary & (GLint)pow(2., i)){ + b = (GL2PSprimitive*)gl2psMalloc(sizeof(GL2PSprimitive)); + b->type = GL2PS_LINE; + b->dash = prim->dash; + b->depth = prim->depth; /* FIXME: this is wrong */ + b->culled = prim->culled; + b->width = prim->width; + b->boundary = 0; + b->numverts = 2; + b->verts = (GL2PSvertex *)gl2psMalloc(2 * sizeof(GL2PSvertex)); + +#if 0 /* FIXME: need to work on boundary offset... */ + v[0] = c[0] - prim->verts[i].xyz[0]; + v[1] = c[1] - prim->verts[i].xyz[1]; + v[2] = 0.; + norm = gl2psNorm(v); + v[0] /= norm; + v[1] /= norm; + b->verts[0].xyz[0] = prim->verts[i].xyz[0] +0.1*v[0]; + b->verts[0].xyz[1] = prim->verts[i].xyz[1] +0.1*v[1]; + b->verts[0].xyz[2] = prim->verts[i].xyz[2]; + v[0] = c[0] - prim->verts[gl2psGetIndex(i, prim->numverts)].xyz[0]; + v[1] = c[1] - prim->verts[gl2psGetIndex(i, prim->numverts)].xyz[1]; + norm = gl2psNorm(v); + v[0] /= norm; + v[1] /= norm; + b->verts[1].xyz[0] = prim->verts[gl2psGetIndex(i, prim->numverts)].xyz[0] +0.1*v[0]; + b->verts[1].xyz[1] = prim->verts[gl2psGetIndex(i, prim->numverts)].xyz[1] +0.1*v[1]; + b->verts[1].xyz[2] = prim->verts[gl2psGetIndex(i, prim->numverts)].xyz[2]; +#else + b->verts[0].xyz[0] = prim->verts[i].xyz[0]; + b->verts[0].xyz[1] = prim->verts[i].xyz[1]; + b->verts[0].xyz[2] = prim->verts[i].xyz[2]; + b->verts[1].xyz[0] = prim->verts[gl2psGetIndex(i, prim->numverts)].xyz[0]; + b->verts[1].xyz[1] = prim->verts[gl2psGetIndex(i, prim->numverts)].xyz[1]; + b->verts[1].xyz[2] = prim->verts[gl2psGetIndex(i, prim->numverts)].xyz[2]; +#endif + + b->verts[0].rgba[0] = 0.; + b->verts[0].rgba[1] = 0.; + b->verts[0].rgba[2] = 0.; + b->verts[0].rgba[3] = 0.; + b->verts[1].rgba[0] = 0.; + b->verts[1].rgba[1] = 0.; + b->verts[1].rgba[2] = 0.; + b->verts[1].rgba[3] = 0.; + gl2psListAdd(list, &b); + } + } + +} + +void gl2psBuildPolygonBoundary(GL2PSbsptree *tree){ + GLint i, n; + GL2PSprimitive *prim; + + if(!tree) return; + gl2psBuildPolygonBoundary(tree->back); + n = gl2psListNbr(tree->primitives); + for(i = 0; i < n; i++){ + prim = *(GL2PSprimitive**)gl2psListPointer(tree->primitives, i); + if(prim->boundary) gl2psAddBoundaryInList(prim, tree->primitives); + } + gl2psBuildPolygonBoundary(tree->front); +} + +/* The feedback buffer parser */ + +void gl2psAddPolyPrimitive(GLshort type, GLshort numverts, + GL2PSvertex *verts, GLint offset, + char dash, GLfloat width, + char boundary){ + GLshort i; + GLfloat factor, units, area, dZ, dZdX, dZdY, maxdZ; + GL2PSprimitive *prim; + + prim = (GL2PSprimitive *)gl2psMalloc(sizeof(GL2PSprimitive)); + prim->type = type; + prim->numverts = numverts; + prim->verts = (GL2PSvertex *)gl2psMalloc(numverts * sizeof(GL2PSvertex)); + memcpy(prim->verts, verts, numverts * sizeof(GL2PSvertex)); + prim->boundary = boundary; + prim->dash = dash; + prim->width = width; + prim->culled = 0; + + if(gl2ps->options & GL2PS_SIMPLE_LINE_OFFSET){ + + if(type == GL2PS_LINE){ + if(gl2ps->sort == GL2PS_SIMPLE_SORT){ + prim->verts[0].xyz[2] -= GL2PS_SIMPLE_OFFSET_LARGE; + prim->verts[1].xyz[2] -= GL2PS_SIMPLE_OFFSET_LARGE; + } + else{ + prim->verts[0].xyz[2] -= GL2PS_SIMPLE_OFFSET; + prim->verts[1].xyz[2] -= GL2PS_SIMPLE_OFFSET; + } + } + + } + else if(offset && type == GL2PS_TRIANGLE){ + + /* FIXME: this needs some more work... */ + + if(gl2ps->sort == GL2PS_SIMPLE_SORT){ + factor = gl2ps->offset[0]; + units = gl2ps->offset[1]; + } + else{ + factor = gl2ps->offset[0] / 800.; + units = gl2ps->offset[1] / 800.; + } + + area = + (prim->verts[1].xyz[0] - prim->verts[0].xyz[0]) * + (prim->verts[2].xyz[1] - prim->verts[1].xyz[1]) - + (prim->verts[2].xyz[0] - prim->verts[1].xyz[0]) * + (prim->verts[1].xyz[1] - prim->verts[0].xyz[1]); + dZdX = + (prim->verts[2].xyz[1] - prim->verts[1].xyz[1]) * + (prim->verts[1].xyz[2] - prim->verts[0].xyz[2]) - + (prim->verts[1].xyz[1] - prim->verts[0].xyz[1]) * + (prim->verts[2].xyz[2] - prim->verts[1].xyz[2]) / area; + dZdY = + (prim->verts[1].xyz[0] - prim->verts[0].xyz[0]) * + (prim->verts[2].xyz[2] - prim->verts[1].xyz[2]) - + (prim->verts[2].xyz[0] - prim->verts[1].xyz[0]) * + (prim->verts[1].xyz[2] - prim->verts[0].xyz[2]) / area; + + maxdZ = sqrt(dZdX*dZdX + dZdY*dZdY); + + dZ = factor * maxdZ + units; + + prim->verts[0].xyz[2] += dZ; + prim->verts[1].xyz[2] += dZ; + prim->verts[2].xyz[2] += dZ; + } + + prim->depth = 0.; + if(gl2ps->sort == GL2PS_SIMPLE_SORT){ + for(i = 0; i < numverts; i++){ + prim->depth += prim->verts[i].xyz[2]; + } + prim->depth /= (GLfloat)numverts; + } + + gl2psListAdd(gl2ps->primitives, &prim); +} + +GLint gl2psGetVertex(GL2PSvertex *v, GLfloat *p){ + GLint i; + + v->xyz[0] = p[0]; + v->xyz[1] = p[1]; + v->xyz[2] = GL2PS_DEPTH_FACT * p[2]; + + if(gl2ps->colormode == GL_COLOR_INDEX && gl2ps->colorsize > 0){ + i = (GLint)(p[3] + 0.5); + v->rgba[0] = gl2ps->colormap[i][0]; + v->rgba[1] = gl2ps->colormap[i][1]; + v->rgba[2] = gl2ps->colormap[i][2]; + v->rgba[3] = gl2ps->colormap[i][3]; + return 4; + } + else{ + v->rgba[0] = p[3]; + v->rgba[1] = p[4]; + v->rgba[2] = p[5]; + v->rgba[3] = p[6]; + return 7; + } +} + +GLint gl2psParseFeedbackBuffer(void){ + char flag, dash = 0; + GLshort boundary; + GLint i, used, count, v, vtot, offset = 0; + GLfloat lwidth = 1., psize = 1.; + GLfloat *current; + GL2PSvertex vertices[3]; + + used = glRenderMode(GL_RENDER); + + if(used < 0){ + gl2psMsg(GL2PS_INFO, "OpenGL feedback buffer overflow"); + return GL2PS_OVERFLOW; + } + + if(used == 0){ + /* gl2psMsg(GL2PS_INFO, "Empty feedback buffer"); */ + return GL2PS_NO_FEEDBACK; + } + + current = gl2ps->feedback; + boundary = gl2ps->boundary = 0; + + while(used > 0){ + + if(boundary) gl2ps->boundary = 1; + + switch((GLint)*current){ + case GL_POINT_TOKEN : + current ++; + used --; + i = gl2psGetVertex(&vertices[0], current); + current += i; + used -= i; + gl2psAddPolyPrimitive(GL2PS_POINT, 1, vertices, 0, dash, psize, 0); + break; + case GL_LINE_TOKEN : + case GL_LINE_RESET_TOKEN : + current ++; + used --; + i = gl2psGetVertex(&vertices[0], current); + current += i; + used -= i; + i = gl2psGetVertex(&vertices[1], current); + current += i; + used -= i; + gl2psAddPolyPrimitive(GL2PS_LINE, 2, vertices, 0, dash, lwidth, 0); + break; + case GL_POLYGON_TOKEN : + count = (GLint)current[1]; + current += 2; + used -= 2; + v = vtot = 0; + while(count > 0 && used > 0){ + i = gl2psGetVertex(&vertices[v], current); + current += i; + used -= i; + count --; + vtot++; + if(v == 2){ + if(boundary){ + if(!count && vtot == 2) flag = 1|2|4; + else if(!count) flag = 2|4; + else if(vtot == 2) flag = 1|2; + else flag = 2; + } + else + flag = 0; + gl2psAddPolyPrimitive(GL2PS_TRIANGLE, 3, vertices, + offset, dash, 1, flag); + vertices[1] = vertices[2]; + } + else + v ++; + } + break; + case GL_BITMAP_TOKEN : + case GL_DRAW_PIXEL_TOKEN : + case GL_COPY_PIXEL_TOKEN : + current ++; + used --; + i = gl2psGetVertex(&vertices[0], current); + current += i; + used -= i; + break; + case GL_PASS_THROUGH_TOKEN : + switch((GLint)current[1]){ + case GL2PS_BEGIN_POLYGON_OFFSET_FILL : offset = 1; break; + case GL2PS_END_POLYGON_OFFSET_FILL : offset = 0; break; + case GL2PS_BEGIN_POLYGON_BOUNDARY : boundary = 1; break; + case GL2PS_END_POLYGON_BOUNDARY : boundary = 0; break; + case GL2PS_BEGIN_LINE_STIPPLE : dash = 4; break; + case GL2PS_END_LINE_STIPPLE : dash = 0; break; + case GL2PS_SET_POINT_SIZE : + current += 2; + used -= 2; + psize = current[1]; + break; + case GL2PS_SET_LINE_WIDTH : + current += 2; + used -= 2; + lwidth = current[1]; + break; + } + current += 2; + used -= 2; + break; + default : + gl2psMsg(GL2PS_WARNING, "Unknown token in buffer"); + current ++; + used --; + break; + } + } + + return GL2PS_SUCCESS; +} + +GLboolean gl2psSameColor(GL2PSrgba rgba1, GL2PSrgba rgba2){ + return !(rgba1[0] != rgba2[0] || + rgba1[1] != rgba2[1] || + rgba1[2] != rgba2[2]); +} + +GLboolean gl2psVertsSameColor(const GL2PSprimitive *prim){ + int i; + + for(i = 1; i < prim->numverts; i++){ + if(!gl2psSameColor(prim->verts[0].rgba, prim->verts[i].rgba)){ + return 0; + } + } + return 1; +} + +/* The PostScript routines. Other (vector) image formats should be + easy to generate by creating the three corresponding routines + (gl2psPrintXXXHeader, gl2psPrintXXXPrimitive, gl2psPrintXXXFooter, + gl2psPrintXXXBeginViewport and gl2psPrintXXXEndViewport) for the + new format. */ + +void gl2psWriteByte(FILE *stream, unsigned char byte){ + unsigned char h = byte / 16; + unsigned char l = byte % 16; + fprintf(stream, "%x%x", h, l); +} + +int gl2psGetRGB(GLfloat *pixels, GLsizei width, GLsizei height, GLuint x, GLuint y, + GLfloat *red, GLfloat *green, GLfloat *blue){ + /* OpenGL image is from down to up, PS image is up to down */ + GLfloat *pimag; + pimag = pixels + 3 * (width * (height - 1 - y) + x); + *red = *pimag; pimag++; + *green = *pimag; pimag++; + *blue = *pimag; pimag++; + return 1; +} + +void gl2psPrintPostScriptPixmap(GLfloat x, GLfloat y, GLsizei width, GLsizei height, + GLenum format, GLenum type, GLfloat *pixels, + FILE *stream){ + typedef unsigned char Uchar; + int status = 1, nbhex, nbyte2, nbyte4, nbyte8; + GLsizei row, col, col_max; + float dr, dg, db, fgrey; + Uchar red, green, blue, b, grey; + /* FIXME: this has to be generalized... */ + int shade = 0; + int nbit = 4; + + if((width <= 0) || (height <= 0)) return; + + /* Msg(INFO, "gl2psPrintPostScriptPixmap: x %g y %g w %d h %d", x, y, width, height); */ + + fprintf(stream, "gsave\n"); + fprintf(stream, "%.2f %.2f translate\n", x, y); + fprintf(stream, "%d %d scale\n", width, height); + + if(shade != 0){ /* grey */ + fprintf(stream, "/picstr %d string def\n", width); + fprintf(stream, "%d %d %d\n", width, height, 8); + fprintf(stream, "[ %d 0 0 -%d 0 %d ]\n", width, height, height); + fprintf(stream, "{ currentfile picstr readhexstring pop }\n"); + fprintf(stream, "image\n"); + for(row = 0; row < height; row++){ + for(col = 0; col < width; col++){ + status = gl2psGetRGB(pixels, width, height, + col, row, &dr, &dg, &db) == 0 ? 0 : status; + fgrey = (0.30 * dr + 0.59 * dg + 0.11 * db); + grey = (Uchar)(255. * fgrey); + gl2psWriteByte(stream, grey); + } + fprintf(stream, "\n"); + } + nbhex = width * height * 2; + fprintf(stream, "%%%% nbhex digit :%d\n", nbhex); + } + else if(nbit == 2){ + nbyte2 = (width * 3)/4; + nbyte2 /=3; + nbyte2 *=3; + col_max = (nbyte2 * 4)/3; + /* 2 bit for r and g and b */ + /* rgbs following each other */ + fprintf(stream, "/rgbstr %d string def\n", nbyte2); + fprintf(stream, "%d %d %d\n", col_max, height, 2); + fprintf(stream, "[ %d 0 0 -%d 0 %d ]\n", col_max, height, height); + fprintf(stream, "{ currentfile rgbstr readhexstring pop }\n" ); + fprintf(stream, "false 3\n" ); + fprintf(stream, "colorimage\n" ); + for(row = 0; row < height; row++){ + for(col = 0; col < col_max; col+=4){ + status = gl2psGetRGB(pixels, width, height, + col, row, &dr, &dg, &db) == 0 ? 0 : status; + red = (Uchar)(3. * dr); + green = (Uchar)(3. * dg); + blue = (Uchar)(3. * db); + b = red; + b = (b<<2)+green; + b = (b<<2)+blue; + status = gl2psGetRGB(pixels, width, height, + col+1, row, &dr, &dg, &db) == 0 ? 0 : status; + red = (Uchar)(3. * dr); + green = (Uchar)(3. * dg); + blue = (Uchar)(3. * db); + b = (b<<2)+red; + gl2psWriteByte(stream, b); + + b = green; + b = (b<<2)+blue; + status = gl2psGetRGB(pixels, width, height, + col+2, row, &dr, &dg, &db) == 0 ? 0 : status; + red = (Uchar)(3. * dr); + green = (Uchar)(3. * dg); + blue = (Uchar)(3. * db); + b = (b<<2)+red; + b = (b<<2)+green; + gl2psWriteByte(stream, b); + + b = blue; + status = gl2psGetRGB(pixels,width,height, + col+3, row, &dr, &dg, &db) == 0 ? 0 : status; + red = (Uchar)(3. * dr); + green = (Uchar)(3. * dg); + blue = (Uchar)(3. * db); + b = (b<<2)+red; + b = (b<<2)+green; + b = (b<<2)+blue; + gl2psWriteByte(stream, b); + } + fprintf(stream, "\n"); + } + } + else if(nbit == 4){ + nbyte4 = (width * 3)/2; + nbyte4 /=3; + nbyte4 *=3; + col_max = (nbyte4 * 2)/3; + /* 4 bit for r and g and b */ + /* rgbs following each other */ + fprintf(stream, "/rgbstr %d string def\n", nbyte4); + fprintf(stream, "%d %d %d\n", col_max, height,4); + fprintf(stream, "[ %d 0 0 -%d 0 %d ]\n", col_max, height, height); + fprintf(stream, "{ currentfile rgbstr readhexstring pop }\n"); + fprintf(stream, "false 3\n"); + fprintf(stream, "colorimage\n"); + for(row = 0; row < height; row++){ + for(col = 0; col < col_max; col+=2){ + status = gl2psGetRGB(pixels, width, height, + col, row, &dr, &dg, &db) == 0 ? 0 : status; + red = (Uchar)(15. * dr); + green = (Uchar)(15. * dg); + fprintf(stream, "%x%x", red, green); + blue = (Uchar)(15. * db); + + status = gl2psGetRGB(pixels, width, height, + col+1, row, &dr, &dg, &db) == 0 ? 0 : status; + red = (Uchar)(15. * dr); + fprintf(stream,"%x%x",blue,red); + green = (Uchar)(15. * dg); + blue = (Uchar)(15. * db); + fprintf(stream, "%x%x", green, blue); + } + fprintf(stream, "\n"); + } + } + else{ + nbyte8 = width * 3; + /* 8 bit for r and g and b */ + fprintf(stream, "/rgbstr %d string def\n", nbyte8); + fprintf(stream, "%d %d %d\n", width, height, 8); + fprintf(stream, "[ %d 0 0 -%d 0 %d ]\n", width, height, height); + fprintf(stream, "{ currentfile rgbstr readhexstring pop }\n"); + fprintf(stream, "false 3\n"); + fprintf(stream, "colorimage\n"); + for(row = 0; row < height; row++){ + for(col = 0; col < width; col++){ + status = gl2psGetRGB(pixels, width, height, + col, row, &dr, &dg, &db) == 0 ? 0 : status; + red = (Uchar)(255. * dr); + gl2psWriteByte(stream, red); + green = (Uchar)(255. * dg); + gl2psWriteByte(stream, green); + blue = (Uchar)(255. * db); + gl2psWriteByte(stream, blue); + } + fprintf(stream, "\n"); + } + } + + if(status == 0){ + gl2psMsg(GL2PS_ERROR, "Problem to retrieve some pixel rgb"); + } + fprintf(stream, "grestore\n"); +} + +void gl2psPrintPostScriptHeader(void){ + GLint index; + GLfloat rgba[4]; + time_t now; + + time(&now); + + if(gl2ps->format == GL2PS_PS){ + fprintf(gl2ps->stream, "%%!PS-Adobe-3.0\n"); + } + else{ + fprintf(gl2ps->stream, "%%!PS-Adobe-3.0 EPSF-3.0\n"); + } + + fprintf(gl2ps->stream, + "%%%%Title: %s\n" + "%%%%Creator: GL2PS %d.%d.%d, an OpenGL to PostScript Printing Library\n" + "%%%%For: %s\n" + "%%%%CreationDate: %s" + "%%%%LanguageLevel: 3\n" + "%%%%DocumentData: Clean7Bit\n" + "%%%%Pages: 1\n", + gl2ps->title, GL2PS_MAJOR_VERSION, GL2PS_MINOR_VERSION, GL2PS_PATCH_VERSION, + gl2ps->producer, ctime(&now)); + + if(gl2ps->format == GL2PS_PS){ + fprintf(gl2ps->stream, + "%%%%Orientation: %s\n" + "%%%%DocumentMedia: Default %d %d 0 () ()\n", + (gl2ps->options & GL2PS_LANDSCAPE) ? "Landscape" : "Portrait", + (gl2ps->options & GL2PS_LANDSCAPE) ? gl2ps->viewport[3] : gl2ps->viewport[2], + (gl2ps->options & GL2PS_LANDSCAPE) ? gl2ps->viewport[2] : gl2ps->viewport[3]); + } + + fprintf(gl2ps->stream, + "%%%%BoundingBox: %d %d %d %d\n" + "%%%%Copyright: GNU LGPL (C) 1999-2003 Christophe Geuzaine \n" + "%%%%EndComments\n", + (gl2ps->options & GL2PS_LANDSCAPE) ? gl2ps->viewport[1] : gl2ps->viewport[0], + (gl2ps->options & GL2PS_LANDSCAPE) ? gl2ps->viewport[0] : gl2ps->viewport[1], + (gl2ps->options & GL2PS_LANDSCAPE) ? gl2ps->viewport[3] : gl2ps->viewport[2], + (gl2ps->options & GL2PS_LANDSCAPE) ? gl2ps->viewport[2] : gl2ps->viewport[3]); + + /* RGB color: r g b C (replace C by G in output to change from rgb to gray) + Grayscale: r g b G + Font choose: size fontname FC + String primitive: (string) x y size fontname S + Point primitive: x y size P + Line width: width W + Flat-shaded line: x2 y2 x1 y1 L + Smooth-shaded line: x2 y2 r2 g2 b2 x1 y1 r1 g1 b1 SL + Flat-shaded triangle: x3 y3 x2 y2 x1 y1 T + Smooth-shaded triangle: x3 y3 r3 g3 b3 x2 y2 r2 g2 b2 x1 y1 r1 g1 b1 ST */ + + fprintf(gl2ps->stream, + "%%%%BeginProlog\n" + "/gl2psdict 64 dict def gl2psdict begin\n" + "1 setlinecap 1 setlinejoin\n" + "/tryPS3shading %s def %% set to false to force subdivision\n" + "/rThreshold %g def %% red component subdivision threshold\n" + "/gThreshold %g def %% green component subdivision threshold\n" + "/bThreshold %g def %% blue component subdivision threshold\n" + "/BD { bind def } bind def\n" + "/C { setrgbcolor } BD\n" + "/G { 0.082 mul exch 0.6094 mul add exch 0.3086 mul add neg 1.0 add setgray } BD\n" + "/W { setlinewidth } BD\n" + "/FC { findfont exch scalefont setfont } BD\n" + "/S { FC moveto show } BD\n" + "/P { newpath 0.0 360.0 arc closepath fill } BD\n" + "/L { newpath moveto lineto stroke } BD\n" + "/SL { C moveto C lineto stroke } BD\n" + "/T { newpath moveto lineto lineto closepath fill } BD\n", + (gl2ps->options & GL2PS_NO_PS3_SHADING) ? "false" : "true", + gl2ps->threshold[0], gl2ps->threshold[1], gl2ps->threshold[2]); + + /* Smooth-shaded triangle with PostScript level 3 shfill operator: + x3 y3 r3 g3 b3 x2 y2 r2 g2 b2 x1 y1 r1 g1 b1 STshfill */ + + fprintf(gl2ps->stream, + "/STshfill {\n" + " /b1 exch def /g1 exch def /r1 exch def /y1 exch def /x1 exch def\n" + " /b2 exch def /g2 exch def /r2 exch def /y2 exch def /x2 exch def\n" + " /b3 exch def /g3 exch def /r3 exch def /y3 exch def /x3 exch def\n" + " gsave << /ShadingType 4 /ColorSpace [/DeviceRGB]\n" + " /DataSource [ 0 x1 y1 r1 g1 b1 0 x2 y2 r2 g2 b2 0 x3 y3 r3 g3 b3 ] >>\n" + " shfill grestore } BD\n"); + + /* Flat-shaded triangle with middle color: + x3 y3 r3 g3 b3 x2 y2 r2 g2 b2 x1 y1 r1 g1 b1 Tm */ + + fprintf(gl2ps->stream, + /* stack : x3 y3 r3 g3 b3 x2 y2 r2 g2 b2 x1 y1 r1 g1 b1 */ + "/Tm { 3 -1 roll 8 -1 roll 13 -1 roll add add 3 div\n" /* r = (r1+r2+r3)/3 */ + /* stack : x3 y3 g3 b3 x2 y2 g2 b2 x1 y1 g1 b1 r */ + " 3 -1 roll 7 -1 roll 11 -1 roll add add 3 div\n" /* g = (g1+g2+g3)/3 */ + /* stack : x3 y3 b3 x2 y2 b2 x1 y1 b1 r g b */ + " 3 -1 roll 6 -1 roll 9 -1 roll add add 3 div" /* b = (b1+b2+b3)/3 */ + /* stack : x3 y3 x2 y2 x1 y1 r g b */ + " C T } BD\n"); + + /* Split triangle in four sub-triangles (at sides middle points) and call the + STnoshfill procedure on each, interpolating the colors in RGB space: + x3 y3 r3 g3 b3 x2 y2 r2 g2 b2 x1 y1 r1 g1 b1 STsplit + (in procedure comments key: (Vi) = xi yi ri gi bi) */ + + fprintf(gl2ps->stream, + "/STsplit {\n" + " 4 index 15 index add 0.5 mul\n" /* x13 = (x1+x3)/2 */ + " 4 index 15 index add 0.5 mul\n" /* y13 = (y1+y3)/2 */ + " 4 index 15 index add 0.5 mul\n" /* r13 = (r1+r3)/2 */ + " 4 index 15 index add 0.5 mul\n" /* g13 = (g1+g3)/2 */ + " 4 index 15 index add 0.5 mul\n" /* b13 = (b1+b3)/2 */ + " 5 copy 5 copy 25 15 roll\n" + /* stack : (V3) (V13) (V13) (V13) (V2) (V1) */ + " 9 index 30 index add 0.5 mul\n" /* x23 = (x2+x3)/2 */ + " 9 index 30 index add 0.5 mul\n" /* y23 = (y2+y3)/2 */ + " 9 index 30 index add 0.5 mul\n" /* r23 = (r2+r3)/2 */ + " 9 index 30 index add 0.5 mul\n" /* g23 = (g2+g3)/2 */ + " 9 index 30 index add 0.5 mul\n" /* b23 = (b2+b3)/2 */ + " 5 copy 5 copy 35 5 roll 25 5 roll 15 5 roll\n" + /* stack : (V3) (V13) (V23) (V13) (V23) (V13) (V23) (V2) (V1) */ + " 4 index 10 index add 0.5 mul\n" /* x12 = (x1+x2)/2 */ + " 4 index 10 index add 0.5 mul\n" /* y12 = (y1+y2)/2 */ + " 4 index 10 index add 0.5 mul\n" /* r12 = (r1+r2)/2 */ + " 4 index 10 index add 0.5 mul\n" /* g12 = (g1+g2)/2 */ + " 4 index 10 index add 0.5 mul\n" /* b12 = (b1+b2)/2 */ + " 5 copy 5 copy 40 5 roll 25 5 roll 15 5 roll 25 5 roll\n" + /* stack : (V3) (V13) (V23) (V13) (V12) (V23) (V13) (V1) (V12) (V23) (V12) (V2) */ + " STnoshfill STnoshfill STnoshfill STnoshfill } BD\n"); + + /* Gouraud shaded triangle using recursive subdivision until the difference + between corner colors does not exceed the thresholds: + x3 y3 r3 g3 b3 x2 y2 r2 g2 b2 x1 y1 r1 g1 b1 STnoshfill */ + + fprintf(gl2ps->stream, + "/STnoshfill {\n" + " 2 index 8 index sub abs rThreshold gt\n" /* |r1-r2|>rth */ + " { STsplit }\n" + " { 1 index 7 index sub abs gThreshold gt\n" /* |g1-g2|>gth */ + " { STsplit }\n" + " { dup 6 index sub abs bThreshold gt\n" /* |b1-b2|>bth */ + " { STsplit }\n" + " { 2 index 13 index sub abs rThreshold gt\n" /* |r1-r3|>rht */ + " { STsplit }\n" + " { 1 index 12 index sub abs gThreshold gt\n" /* |g1-g3|>gth */ + " { STsplit }\n" + " { dup 11 index sub abs bThreshold gt\n" /* |b1-b3|>bth */ + " { STsplit }\n" + " { 7 index 13 index sub abs rThreshold gt\n" /* |r2-r3|>rht */ + " { STsplit }\n" + " { 6 index 12 index sub abs gThreshold gt\n" /* |g2-g3|>gth */ + " { STsplit }\n" + " { 5 index 11 index sub abs bThreshold gt\n" /* |b2-b3|>bth */ + " { STsplit }\n" + " { Tm }\n" /* all colors sufficiently similar */ + " ifelse }\n" + " ifelse }\n" + " ifelse }\n" + " ifelse }\n" + " ifelse }\n" + " ifelse }\n" + " ifelse }\n" + " ifelse }\n" + " ifelse } BD\n"); + + fprintf(gl2ps->stream, + "tryPS3shading\n" + "{ /shfill where\n" + " { /ST { STshfill } BD }\n" + " { /ST { STnoshfill } BD }\n" + " ifelse }\n" + "{ /ST { STnoshfill } BD }\n" + "ifelse\n"); + + fprintf(gl2ps->stream, + "end\n" + "%%%%EndProlog\n" + "%%%%BeginSetup\n" + "/DeviceRGB setcolorspace\n" + "gl2psdict begin\n" + "%%%%EndSetup\n" + "%%%%Page: 1 1\n" + "%%%%BeginPageSetup\n"); + + if(gl2ps->options & GL2PS_LANDSCAPE){ + fprintf(gl2ps->stream, + "%d 0 translate 90 rotate\n", + gl2ps->viewport[3]); + } + + fprintf(gl2ps->stream, + "%%%%EndPageSetup\n" + "mark\n" + "gsave\n" + "1.0 1.0 scale\n"); + + if(gl2ps->options & GL2PS_DRAW_BACKGROUND){ + if(gl2ps->colormode == GL_RGBA || gl2ps->colorsize == 0){ + glGetFloatv(GL_COLOR_CLEAR_VALUE, rgba); + } + else{ + glGetIntegerv(GL_INDEX_CLEAR_VALUE, &index); + rgba[0] = gl2ps->colormap[index][0]; + rgba[1] = gl2ps->colormap[index][1]; + rgba[2] = gl2ps->colormap[index][2]; + rgba[3] = 0.; + } + fprintf(gl2ps->stream, + "%g %g %g C\n" + "newpath %d %d moveto %d %d lineto %d %d lineto %d %d lineto\n" + "closepath fill\n", + rgba[0], rgba[1], rgba[2], + gl2ps->viewport[0], gl2ps->viewport[1], gl2ps->viewport[2], + gl2ps->viewport[1], gl2ps->viewport[2], gl2ps->viewport[3], + gl2ps->viewport[0], gl2ps->viewport[3]); + } +} + +void gl2psPrintPostScriptColor(GL2PSrgba rgba){ + if(!gl2psSameColor(gl2ps->lastrgba, rgba)){ + gl2ps->lastrgba[0] = rgba[0]; + gl2ps->lastrgba[1] = rgba[1]; + gl2ps->lastrgba[2] = rgba[2]; + fprintf(gl2ps->stream, "%g %g %g C\n", rgba[0], rgba[1], rgba[2]); + } +} + +void gl2psResetPostScriptColor(void){ + gl2ps->lastrgba[0] = gl2ps->lastrgba[1] = gl2ps->lastrgba[2] = -1.; +} + +void gl2psPrintPostScriptPrimitive(void *a, void *b){ + GL2PSprimitive *prim; + + prim = *(GL2PSprimitive**)a; + + if((gl2ps->options & GL2PS_OCCLUSION_CULL) && prim->culled) return; + + switch(prim->type){ + case GL2PS_PIXMAP : + gl2psPrintPostScriptPixmap(prim->verts[0].xyz[0], prim->verts[0].xyz[1], + prim->image->width, prim->image->height, + prim->image->format, prim->image->type, + prim->image->pixels, gl2ps->stream); + break; + case GL2PS_TEXT : + gl2psPrintPostScriptColor(prim->verts[0].rgba); + fprintf(gl2ps->stream, "(%s) %g %g %d /%s S\n", + prim->text->str, prim->verts[0].xyz[0], prim->verts[0].xyz[1], + prim->text->fontsize, prim->text->fontname); + break; + case GL2PS_POINT : + gl2psPrintPostScriptColor(prim->verts[0].rgba); + fprintf(gl2ps->stream, "%f %f %f P\n", + prim->verts[0].xyz[0], prim->verts[0].xyz[1], 0.5*prim->width); + break; + case GL2PS_LINE : + if(gl2ps->lastlinewidth != prim->width){ + gl2ps->lastlinewidth = prim->width; + fprintf(gl2ps->stream, "%f W\n", gl2ps->lastlinewidth); + } + if(prim->dash){ + fprintf(gl2ps->stream, "[%d] 0 setdash\n", prim->dash); + } + if(!gl2psVertsSameColor(prim)){ + gl2psResetPostScriptColor(); + fprintf(gl2ps->stream, "%f %f %f %f %f %f %f %f %f %f SL\n", + prim->verts[1].xyz[0], prim->verts[1].xyz[1], + prim->verts[1].rgba[0], prim->verts[1].rgba[1], + prim->verts[1].rgba[2], prim->verts[0].xyz[0], + prim->verts[0].xyz[1], prim->verts[0].rgba[0], + prim->verts[0].rgba[1], prim->verts[0].rgba[2]); + } + else{ + gl2psPrintPostScriptColor(prim->verts[0].rgba); + fprintf(gl2ps->stream, "%f %f %f %f L\n", + prim->verts[1].xyz[0], prim->verts[1].xyz[1], + prim->verts[0].xyz[0], prim->verts[0].xyz[1]); + } + if(prim->dash){ + fprintf(gl2ps->stream, "[] 0 setdash\n"); + } + break; + case GL2PS_TRIANGLE : + if(!gl2psVertsSameColor(prim)){ + gl2psResetPostScriptColor(); + fprintf(gl2ps->stream, "%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f ST\n", + prim->verts[2].xyz[0], prim->verts[2].xyz[1], + prim->verts[2].rgba[0], prim->verts[2].rgba[1], + prim->verts[2].rgba[2], prim->verts[1].xyz[0], + prim->verts[1].xyz[1], prim->verts[1].rgba[0], + prim->verts[1].rgba[1], prim->verts[1].rgba[2], + prim->verts[0].xyz[0], prim->verts[0].xyz[1], + prim->verts[0].rgba[0], prim->verts[0].rgba[1], + prim->verts[0].rgba[2]); + } + else{ + gl2psPrintPostScriptColor(prim->verts[0].rgba); + fprintf(gl2ps->stream, "%f %f %f %f %f %f T\n", + prim->verts[2].xyz[0], prim->verts[2].xyz[1], + prim->verts[1].xyz[0], prim->verts[1].xyz[1], + prim->verts[0].xyz[0], prim->verts[0].xyz[1]); + } + break; + case GL2PS_QUADRANGLE : + gl2psMsg(GL2PS_WARNING, "There should not be any quad left to print"); + break; + default : + gl2psMsg(GL2PS_ERROR, "Unknown type of primitive to print"); + break; + } +} + +void gl2psPrintPostScriptFooter(void){ + fprintf(gl2ps->stream, + "grestore\n" + "showpage\n" + "cleartomark\n" + "%%%%PageTrailer\n" + "%%%%Trailer\n" + "end\n" + "%%%%EOF\n"); +} + +void gl2psPrintPostScriptBeginViewport(GLint viewport[4]){ + GLint index; + GLfloat rgba[4]; + int x = viewport[0], y = viewport[1], w = viewport[2], h = viewport[3]; + + glRenderMode(GL_FEEDBACK); + + fprintf(gl2ps->stream, + "gsave\n" + "1.0 1.0 scale\n"); + + if(gl2ps->options & GL2PS_DRAW_BACKGROUND){ + if(gl2ps->colormode == GL_RGBA || gl2ps->colorsize == 0){ + glGetFloatv(GL_COLOR_CLEAR_VALUE, rgba); + } + else{ + glGetIntegerv(GL_INDEX_CLEAR_VALUE, &index); + rgba[0] = gl2ps->colormap[index][0]; + rgba[1] = gl2ps->colormap[index][1]; + rgba[2] = gl2ps->colormap[index][2]; + rgba[3] = 0.; + } + fprintf(gl2ps->stream, + "%g %g %g C\n" + "newpath %d %d moveto %d %d lineto %d %d lineto %d %d lineto\n" + "closepath fill\n", + rgba[0], rgba[1], rgba[2], + x, y, x+w, y, x+w, y+h, x, y+h); + fprintf(gl2ps->stream, + "newpath %d %d moveto %d %d lineto %d %d lineto %d %d lineto\n" + "closepath clip\n", + x, y, x+w, y, x+w, y+h, x, y+h); + } + +} + +GLint gl2psPrintPostScriptEndViewport(void){ + GLint res; + GLint gl2psPrintPrimitives(void); + + res = gl2psPrintPrimitives(); + fprintf(gl2ps->stream, "grestore\n"); + return res; +} + +/* The LaTeX routines */ + +void gl2psPrintTeXHeader(void){ + char name[256]; + int i; + + if(gl2ps->filename && strlen(gl2ps->filename) < 256){ + for(i = strlen(gl2ps->filename)-1; i >= 0; i--){ + if(gl2ps->filename[i] == '.'){ + strncpy(name, gl2ps->filename, i); + name[i] = '\0'; + break; + } + } + if(i <= 0) strcpy(name, gl2ps->filename); + } + else{ + strcpy(name, "untitled"); + } + + fprintf(gl2ps->stream, + "\\setlength{\\unitlength}{1pt}\n" + "\\begin{picture}(0,0)\n" + "\\includegraphics{%s}\n" + "\\end{picture}%%\n" + "%s\\begin{picture}(%d,%d)(0,0)\n", + name, (gl2ps->options & GL2PS_LANDSCAPE) ? "\\rotatebox{90}{" : "", + gl2ps->viewport[2], gl2ps->viewport[3]); +} + +void gl2psPrintTeXPrimitive(void *a, void *b){ + GL2PSprimitive *prim; + + prim = *(GL2PSprimitive**)a; + + switch(prim->type){ + case GL2PS_TEXT : + fprintf(gl2ps->stream, "\\put(%g,%g){\\makebox(0,0)[lb]{%s}}\n", + prim->verts[0].xyz[0], prim->verts[0].xyz[1], prim->text->str); + break; + default : + break; + } +} + +void gl2psPrintTeXFooter(void){ + fprintf(gl2ps->stream, "\\end{picture}%s\n", + (gl2ps->options & GL2PS_LANDSCAPE) ? "}" : ""); +} + +void gl2psPrintTeXBeginViewport(GLint viewport[4]){ +} + +GLint gl2psPrintTeXEndViewport(void){ + return GL2PS_SUCCESS; +} + +/* The general primitive printing routine */ + +GLint gl2psPrintPrimitives(void){ + GL2PSbsptree *root; + GL2PSxyz eye = {0., 0., 100000.}; + GLint res = GL2PS_SUCCESS; + void (*pprim)(void *a, void *b) = 0; + + if(gl2ps->format == GL2PS_PS || gl2ps->format == GL2PS_EPS){ + res = gl2psParseFeedbackBuffer(); + } + + if(res != GL2PS_SUCCESS){ + return res; + } + + switch(gl2ps->format){ + case GL2PS_TEX : + pprim = gl2psPrintTeXPrimitive; + break; + case GL2PS_PS : + case GL2PS_EPS : + pprim = gl2psPrintPostScriptPrimitive; + break; + } + + switch(gl2ps->sort){ + case GL2PS_NO_SORT : + gl2psListAction(gl2ps->primitives, pprim); + gl2psListAction(gl2ps->primitives, gl2psFreePrimitive); + /* reset the primitive list, waiting for the next viewport */ + gl2psListReset(gl2ps->primitives); + break; + case GL2PS_SIMPLE_SORT : + gl2psListSort(gl2ps->primitives, gl2psCompareDepth); + if(gl2ps->options & GL2PS_OCCLUSION_CULL){ + gl2psListAction(gl2ps->primitives, gl2psAddInImageTree); + gl2psFreeBspImageTree(&gl2ps->imagetree); + } + gl2psListActionInverse(gl2ps->primitives, pprim); + gl2psListAction(gl2ps->primitives, gl2psFreePrimitive); + /* reset the primitive list, waiting for the next viewport */ + gl2psListReset(gl2ps->primitives); + break; + case GL2PS_BSP_SORT : + root = (GL2PSbsptree*)gl2psMalloc(sizeof(GL2PSbsptree)); + gl2psBuildBspTree(root, gl2ps->primitives); + if(gl2ps->boundary) gl2psBuildPolygonBoundary(root); + if(gl2ps->options & GL2PS_OCCLUSION_CULL){ + gl2psTraverseBspTree(root, eye, -(float)GL2PS_EPSILON, gl2psLess, + gl2psAddInImageTree); + gl2psFreeBspImageTree(&gl2ps->imagetree); + } + gl2psTraverseBspTree(root, eye, (float)GL2PS_EPSILON, gl2psGreater, + pprim); + gl2psFreeBspTree(&root); + /* reallocate the primitive list (it's been deleted by + gl2psBuildBspTree) in case there is another viewport */ + gl2ps->primitives = gl2psListCreate(500, 500, sizeof(GL2PSprimitive*)); + break; + default : + gl2psMsg(GL2PS_ERROR, "Unknown sorting algorithm: %d", gl2ps->sort); + res = GL2PS_ERROR; + break; + } + + fflush(gl2ps->stream); + + return res; +} + +/* The public routines */ + +GL2PSDLL_API GLint gl2psBeginPage(const char *title, const char *producer, + GLint viewport[4], GLint format, GLint sort, + GLint options, GLint colormode, + GLint colorsize, GL2PSrgba *colormap, + GLint nr, GLint ng, GLint nb, GLint buffersize, + FILE *stream, const char *filename){ + int i; + + gl2ps = (GL2PScontext*)gl2psMalloc(sizeof(GL2PScontext)); + gl2ps->maxbestroot = 10; + gl2ps->format = format; + gl2ps->title = title; + gl2ps->producer = producer; + gl2ps->filename = filename; + gl2ps->sort = sort; + gl2ps->options = options; + for(i = 0; i < 4; i++){ + gl2ps->viewport[i] = viewport[i]; + } + gl2ps->threshold[0] = nr ? 1./(GLfloat)nr : 0.032; + gl2ps->threshold[1] = ng ? 1./(GLfloat)ng : 0.017; + gl2ps->threshold[2] = nb ? 1./(GLfloat)nb : 0.05; + gl2ps->colormode = colormode; + gl2ps->buffersize = buffersize > 0 ? buffersize : 2048 * 2048; + for(i = 0; i < 4; i++){ + gl2ps->lastrgba[i] = -1.; + } + gl2ps->lastlinewidth = -1.; + gl2ps->imagetree = NULL; + + if(gl2ps->colormode == GL_RGBA){ + gl2ps->colorsize = 0; + gl2ps->colormap = NULL; + } + else if(gl2ps->colormode == GL_COLOR_INDEX){ + if(!colorsize || !colormap){ + gl2psMsg(GL2PS_ERROR, "Missing colormap for GL_COLOR_INDEX rendering"); + gl2psFree(gl2ps); + gl2ps = NULL; + return GL2PS_ERROR; + } + gl2ps->colorsize = colorsize; + gl2ps->colormap = (GL2PSrgba*)gl2psMalloc(gl2ps->colorsize * sizeof(GL2PSrgba)); + memcpy(gl2ps->colormap, colormap, gl2ps->colorsize * sizeof(GL2PSrgba)); + } + else{ + gl2psMsg(GL2PS_ERROR, "Unknown color mode in gl2psBeginPage"); + gl2psFree(gl2ps); + gl2ps = NULL; + return GL2PS_ERROR; + } + + if(!stream){ + gl2psMsg(GL2PS_ERROR, "Bad file pointer"); + gl2psFree(gl2ps); + gl2ps = NULL; + return GL2PS_ERROR; + } + else{ + gl2ps->stream = stream; + /* In case gl2psEndPage failed (e.g. due to a GL2PS_OVERFLOW) and + we didn't reopen the stream before calling gl2psBeginPage + again, we need to rewind the stream */ + rewind(gl2ps->stream); + } + + switch(gl2ps->format){ + case GL2PS_TEX : + gl2psPrintTeXHeader(); + break; + case GL2PS_PS : + case GL2PS_EPS : + gl2psPrintPostScriptHeader(); + break; + default : + gl2psMsg(GL2PS_ERROR, "Unknown output format: %d", gl2ps->format); + gl2psFree(gl2ps); + gl2ps = NULL; + return GL2PS_ERROR; + } + + gl2ps->primitives = gl2psListCreate(500, 500, sizeof(GL2PSprimitive*)); + gl2ps->feedback = (GLfloat*)gl2psMalloc(gl2ps->buffersize * sizeof(GLfloat)); + glFeedbackBuffer(gl2ps->buffersize, GL_3D_COLOR, gl2ps->feedback); + glRenderMode(GL_FEEDBACK); + + return GL2PS_SUCCESS; +} + +GL2PSDLL_API GLint gl2psEndPage(void){ + GLint res; + + if(!gl2ps) return GL2PS_UNINITIALIZED; + + res = gl2psPrintPrimitives(); + + /* print the footer even if gl2psPrintPrimitives didn't succeed, so + that we end up with a valid file */ + switch(gl2ps->format){ + case GL2PS_TEX : + gl2psPrintTeXFooter(); + break; + case GL2PS_PS : + case GL2PS_EPS : + gl2psPrintPostScriptFooter(); + break; + } + + fflush(gl2ps->stream); + + gl2psListDelete(gl2ps->primitives); + gl2psFree(gl2ps->colormap); + gl2psFree(gl2ps->feedback); + gl2psFree(gl2ps); + gl2ps = NULL; + + return res; +} + +GL2PSDLL_API GLint gl2psBeginViewport(GLint viewport[4]){ + if(!gl2ps) return GL2PS_UNINITIALIZED; + + switch(gl2ps->format){ + case GL2PS_EPS : + gl2psPrintPostScriptBeginViewport(viewport); + break; + default : + /* FIXME: handle other formats */ + break; + } + + return GL2PS_SUCCESS; +} + +GL2PSDLL_API GLint gl2psEndViewport(void){ + GLint res; + + if(!gl2ps) return GL2PS_UNINITIALIZED; + + switch(gl2ps->format){ + case GL2PS_EPS : + res = gl2psPrintPostScriptEndViewport(); + break; + default : + /* FIXME: handle other formats */ + res = GL2PS_SUCCESS; + break; + } + + return res; +} + +GL2PSDLL_API GLint gl2psText(const char *str, const char *fontname, GLshort fontsize){ + GLfloat pos[4]; + GL2PSprimitive *prim; + GLboolean valid; + + if(!gl2ps || !str) return GL2PS_UNINITIALIZED; + + if(gl2ps->options & GL2PS_NO_TEXT) return GL2PS_SUCCESS; + + glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &valid); + if(!valid) return GL2PS_SUCCESS; /* the primitive is culled */ + + glGetFloatv(GL_CURRENT_RASTER_POSITION, pos); + + prim = (GL2PSprimitive *)gl2psMalloc(sizeof(GL2PSprimitive)); + prim->type = GL2PS_TEXT; + prim->boundary = 0; + prim->numverts = 1; + prim->verts = (GL2PSvertex *)gl2psMalloc(sizeof(GL2PSvertex)); + prim->verts[0].xyz[0] = pos[0]; + prim->verts[0].xyz[1] = pos[1]; + prim->verts[0].xyz[2] = GL2PS_DEPTH_FACT * pos[2]; + prim->depth = pos[2]; + prim->culled = 0; + prim->dash = 0; + prim->width = 1; + glGetFloatv(GL_CURRENT_RASTER_COLOR, prim->verts[0].rgba); + prim->text = (GL2PSstring*)gl2psMalloc(sizeof(GL2PSstring)); + prim->text->str = (char*)gl2psMalloc((strlen(str)+1)*sizeof(char)); + strcpy(prim->text->str, str); + prim->text->fontname = (char*)gl2psMalloc((strlen(fontname)+1)*sizeof(char)); + strcpy(prim->text->fontname, fontname); + prim->text->fontsize = fontsize; + + gl2psListAdd(gl2ps->primitives, &prim); + + return GL2PS_SUCCESS; +} + +GL2PSDLL_API GLint gl2psDrawPixels(GLsizei width, GLsizei height, + GLint xorig, GLint yorig, + GLenum format, GLenum type, + const void *pixels){ + int size; + GLfloat pos[4]; + GL2PSprimitive *prim; + GLboolean valid; + + if(!gl2ps || !pixels) return GL2PS_UNINITIALIZED; + + if((width <= 0) || (height <= 0)) return GL2PS_ERROR; + + if(gl2ps->options & GL2PS_NO_PIXMAP) return GL2PS_SUCCESS; + + if(format != GL_RGB || type != GL_FLOAT){ + gl2psMsg(GL2PS_ERROR, "gl2psDrawPixels only implemented for GL_RGB, GL_FLOAT pixels"); + return GL2PS_ERROR; + } + + glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &valid); + if(!valid) return GL2PS_SUCCESS; /* the primitive is culled */ + + glGetFloatv(GL_CURRENT_RASTER_POSITION, pos); + + prim = (GL2PSprimitive *)gl2psMalloc(sizeof(GL2PSprimitive)); + prim->type = GL2PS_PIXMAP; + prim->boundary = 0; + prim->numverts = 1; + prim->verts = (GL2PSvertex *)gl2psMalloc(sizeof(GL2PSvertex)); + prim->verts[0].xyz[0] = pos[0] + xorig; + prim->verts[0].xyz[1] = pos[1] + yorig; + prim->verts[0].xyz[2] = GL2PS_DEPTH_FACT * pos[2]; + prim->depth = pos[2]; + prim->culled = 0; + prim->dash = 0; + prim->width = 1; + glGetFloatv(GL_CURRENT_RASTER_COLOR, prim->verts[0].rgba); + prim->image = (GL2PSimage*)gl2psMalloc(sizeof(GL2PSimage)); + prim->image->width = width; + prim->image->height = height; + prim->image->format = format; + prim->image->type = type; + size = height*width*3*sizeof(GLfloat); /* FIXME: handle other types/formats */ + prim->image->pixels = (GLfloat*)gl2psMalloc(size); + memcpy(prim->image->pixels, pixels, size); + + gl2psListAdd(gl2ps->primitives, &prim); + + return GL2PS_SUCCESS; +} + +GL2PSDLL_API GLint gl2psEnable(GLint mode){ + if(!gl2ps) return GL2PS_UNINITIALIZED; + + switch(mode){ + case GL2PS_POLYGON_OFFSET_FILL : + glPassThrough(GL2PS_BEGIN_POLYGON_OFFSET_FILL); + glGetFloatv(GL_POLYGON_OFFSET_FACTOR, &gl2ps->offset[0]); + glGetFloatv(GL_POLYGON_OFFSET_UNITS, &gl2ps->offset[1]); + break; + case GL2PS_POLYGON_BOUNDARY : + glPassThrough(GL2PS_BEGIN_POLYGON_BOUNDARY); + break; + case GL2PS_LINE_STIPPLE : + glPassThrough(GL2PS_BEGIN_LINE_STIPPLE); + break; + default : + gl2psMsg(GL2PS_WARNING, "Unknown mode in gl2psEnable: %d", mode); + return GL2PS_WARNING; + } + + return GL2PS_SUCCESS; +} + +GL2PSDLL_API GLint gl2psDisable(GLint mode){ + if(!gl2ps) return GL2PS_UNINITIALIZED; + + switch(mode){ + case GL2PS_POLYGON_OFFSET_FILL : + glPassThrough(GL2PS_END_POLYGON_OFFSET_FILL); + break; + case GL2PS_POLYGON_BOUNDARY : + glPassThrough(GL2PS_END_POLYGON_BOUNDARY); + break; + case GL2PS_LINE_STIPPLE : + glPassThrough(GL2PS_END_LINE_STIPPLE); + break; + default : + gl2psMsg(GL2PS_WARNING, "Unknown mode in gl2psDisable: %d", mode); + return GL2PS_WARNING; + } + + return GL2PS_SUCCESS; +} + +GL2PSDLL_API GLint gl2psPointSize(GLfloat value){ + if(!gl2ps) return GL2PS_UNINITIALIZED; + + glPassThrough(GL2PS_SET_POINT_SIZE); + glPassThrough(value); + + return GL2PS_SUCCESS; +} + +GL2PSDLL_API GLint gl2psLineWidth(GLfloat value){ + if(!gl2ps) return GL2PS_UNINITIALIZED; + + glPassThrough(GL2PS_SET_LINE_WIDTH); + glPassThrough(value); + + return GL2PS_SUCCESS; +} diff --git a/intern_disabled/gl2ps.h b/intern_disabled/gl2ps.h new file mode 100755 index 0000000..ed66da1 --- /dev/null +++ b/intern_disabled/gl2ps.h @@ -0,0 +1 @@ +/* * GL2PS, an OpenGL to PostScript Printing Library * Copyright (C) 1999-2003 Christophe Geuzaine * * $Id: gl2ps.h,v 1.1.1.1 2004/01/09 21:54:34 administrator Exp $ * * E-mail: geuz@geuz.org * URL: http://www.geuz.org/gl2ps/ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ #ifndef __GL2PS_H__ #define __GL2PS_H__ #include #include #include /* To generate a Windows dll, define GL2PSDLL at compile time */ #ifdef WIN32 # include # ifdef GL2PSDLL # ifdef GL2PSDLL_EXPORTS # define GL2PSDLL_API __declspec(dllexport) # else # define GL2PSDLL_API __declspec(dllimport) # endif # else # define GL2PSDLL_API # endif #else # define GL2PSDLL_API #endif #ifdef __APPLE__ # include #else # include #endif /* Version number */ #define GL2PS_MAJOR_VERSION 0 #define GL2PS_MINOR_VERSION 9 #define GL2PS_PATCH_VERSION 0 #define GL2PS_VERSION (GL2PS_MAJOR_VERSION + \ 0.01 * GL2PS_MINOR_VERSION + \ 0.0001 * GL2PS_PATCH_VERSION) /* Output file format */ #define GL2PS_PS 1 #define GL2PS_EPS 2 #define GL2PS_TEX 3 /* Sorting algorithms */ #define GL2PS_NO_SORT 1 #define GL2PS_SIMPLE_SORT 2 #define GL2PS_BSP_SORT 3 /* Options for gl2psBeginPage */ #define GL2PS_NONE 0 #define GL2PS_DRAW_BACKGROUND (1<<0) #define GL2PS_SIMPLE_LINE_OFFSET (1<<1) #define GL2PS_SILENT (1<<2) #define GL2PS_BEST_ROOT (1<<3) #define GL2PS_OCCLUSION_CULL (1<<4) #define GL2PS_NO_TEXT (1<<5) #define GL2PS_LANDSCAPE (1<<6) #define GL2PS_NO_PS3_SHADING (1<<7) #define GL2PS_NO_PIXMAP (1<<8) /* Arguments for gl2psEnable/gl2psDisable */ #define GL2PS_POLYGON_OFFSET_FILL 1 #define GL2PS_POLYGON_BOUNDARY 2 #define GL2PS_LINE_STIPPLE 3 /* Magic numbers */ #define GL2PS_EPSILON 5.e-3 #define GL2PS_DEPTH_FACT 1000.0 #define GL2PS_SIMPLE_OFFSET 0.05 #define GL2PS_SIMPLE_OFFSET_LARGE 1.0 #define GL2PS_ZERO(arg) (fabs(arg)<1.e-20) /* Message levels and error codes */ #define GL2PS_SUCCESS 0 #define GL2PS_INFO 1 #define GL2PS_WARNING 2 #define GL2PS_ERROR 3 #define GL2PS_NO_FEEDBACK 4 #define GL2PS_OVERFLOW 5 #define GL2PS_UNINITIALIZED 6 /* Primitive types */ #define GL2PS_TEXT 1 #define GL2PS_POINT 2 #define GL2PS_LINE 3 #define GL2PS_QUADRANGLE 4 #define GL2PS_TRIANGLE 5 #define GL2PS_PIXMAP 6 /* BSP tree primitive comparison */ #define GL2PS_COINCIDENT 1 #define GL2PS_IN_FRONT_OF 2 #define GL2PS_IN_BACK_OF 3 #define GL2PS_SPANNING 4 /* 2D BSP tree primitive comparison */ #define GL2PS_POINT_COINCIDENT 0 #define GL2PS_POINT_INFRONT 1 #define GL2PS_POINT_BACK 2 /* Pass through options */ #define GL2PS_BEGIN_POLYGON_OFFSET_FILL 1 #define GL2PS_END_POLYGON_OFFSET_FILL 2 #define GL2PS_BEGIN_POLYGON_BOUNDARY 3 #define GL2PS_END_POLYGON_BOUNDARY 4 #define GL2PS_BEGIN_LINE_STIPPLE 5 #define GL2PS_END_LINE_STIPPLE 6 #define GL2PS_SET_POINT_SIZE 7 #define GL2PS_SET_LINE_WIDTH 8 typedef GLfloat GL2PSrgba[4]; typedef GLfloat GL2PSxyz[3]; typedef GLfloat GL2PSplane[4]; typedef struct _GL2PSbsptree2d GL2PSbsptree2d; struct _GL2PSbsptree2d { GL2PSplane plane; GL2PSbsptree2d *front, *back; }; typedef struct { GLint nmax, size, incr, n; char *array; } GL2PSlist; typedef struct _GL2PSbsptree GL2PSbsptree; struct _GL2PSbsptree { GL2PSplane plane; GL2PSlist *primitives; GL2PSbsptree *front, *back; }; typedef struct { GL2PSxyz xyz; GL2PSrgba rgba; } GL2PSvertex; typedef struct { GLshort fontsize; char *str, *fontname; } GL2PSstring; typedef struct { GLsizei width, height; GLenum format, type; GLfloat *pixels; } GL2PSimage; typedef struct { GLshort type, numverts; char boundary, dash, culled; GLfloat width, depth; GL2PSvertex *verts; GL2PSstring *text; GL2PSimage *image; } GL2PSprimitive; typedef struct { GLint format, sort, options, colorsize, colormode, buffersize, maxbestroot; const char *title, *producer, *filename; GLboolean boundary; GLfloat *feedback, offset[2]; GLint viewport[4]; GL2PSrgba *colormap, lastrgba, threshold; float lastlinewidth; GL2PSlist *primitives; GL2PSbsptree2d *imagetree; FILE *stream; } GL2PScontext; /* public functions */ #ifdef __cplusplus extern "C" { #endif GL2PSDLL_API GLint gl2psBeginPage(const char *title, const char *producer, GLint viewport[4], GLint format, GLint sort, GLint options, GLint colormode, GLint colorsize, GL2PSrgba *colormap, GLint nr, GLint ng, GLint nb, GLint buffersize, FILE *stream, const char *filename); GL2PSDLL_API GLint gl2psEndPage(void); GL2PSDLL_API GLint gl2psBeginViewport(GLint viewport[4]); GL2PSDLL_API GLint gl2psEndViewport(void); GL2PSDLL_API GLint gl2psText(const char *str, const char *fontname, GLshort fontsize); GL2PSDLL_API GLint gl2psDrawPixels(GLsizei width, GLsizei height, GLint xorig, GLint yorig, GLenum format, GLenum type, const void *pixels); GL2PSDLL_API GLint gl2psEnable(GLint mode); GL2PSDLL_API GLint gl2psDisable(GLint mode); GL2PSDLL_API GLint gl2psPointSize(GLfloat value); GL2PSDLL_API GLint gl2psLineWidth(GLfloat value); #ifdef __cplusplus }; #endif #endif /* __GL2PS_H__ */ \ No newline at end of file diff --git a/intern_disabled/obj.cpp b/intern_disabled/obj.cpp new file mode 100755 index 0000000..f975df6 --- /dev/null +++ b/intern_disabled/obj.cpp @@ -0,0 +1,330 @@ +/** + +OBJ import by jtnimoy + +*/ + + +#include "obj.h" +using namespace obj4gl; + +#include + + + +Vertex OBJ::getVertex(int i){ + if(ivertices.resize(this->vertices.size()+1);//allocate 1 new in the vector. + + f >> this->vertices[vcx].x; + f >> this->vertices[vcx].y; + f >> this->vertices[vcx].z; + + char t[256]; + //f.getline(t,256); + ignoreRestOfLine(&f); + vcx++; + }else if(!strcmp(tok,"#")){ + //comment + char t[32]; + //f.getline(t,32,'\n'); + ignoreRestOfLine(&f); + + }else if(!strcmp(tok,"usemap")){ + //comment + char t[32]; + //f.getline(t,32,'\n'); + ignoreRestOfLine(&f); + + }else if(!strcmp(tok,"o")){ + //name -- don't care (for now) + char t[256]; + //f.getline(t,256); + ignoreRestOfLine(&f); + }else if(!strcmp(tok,"vt")){ + char t[32]; + f.getline(t,32,' '); + float x = strtod(t,NULL); + //f.getline(t,32); + ignoreRestOfLine(&f); + float y = strtod(t,NULL); + //printf("textureVertex(%s,%s)\n",x,y); + + }else if(!strcmp(tok,"vn")){ + this->normals.resize(this->normals.size()+1);//allocate the new one. + f >> this->normals[normalCount].x; + f >> this->normals[normalCount].y; + f >> this->normals[normalCount].z; + normalCount++; + ignoreRestOfLine(&f); + }else if(!strcmp(tok,"g")){ + char x[32]; + //f.getline(x,32); + ignoreRestOfLine(&f); + //printf("group name(%s)\n",x); + }else if(!strcmp(tok,"s")){ + char x[32]; + //f.getline(x,32); + ignoreRestOfLine(&f); + //printf("shadingGroup(%s)\n",x); + }else if(!strcmp(tok,"usemtl")){ + char x[256]; + //f.getline(x,256); + ignoreRestOfLine(&f); + //printf("useMaterial(%s)\n",x); + + }else if(!strcmp(tok,"mtllib")){ + char x[256]; + //f.getline(x,256); + ignoreRestOfLine(&f); + //printf("useMaterial(%s)\n",x); + + + }else if(!strcmp(tok,"f") || !strcmp(tok,"fo")){ + char x[256]; + + int strlen_x; + this->faces.resize(this->faces.size()+1); + + /** + get the number of vertices in this face and store it in the face struct. + */ + int oldpos = f.tellg(); //push file ptr + f.getline(x,256,'\n'); + strlen_x=strlen(x); + this->faces[fcx].count = 1; + for(int i=0;ifaces[fcx].count++; + } + f.seekg(oldpos);//pop file ptr + + + + /** + get the number of forward slashes per line in order to categorise. + + */ + oldpos = f.tellg(); //push file ptr + f.getline(x,256,'\n'); + strlen_x=strlen(x); + this->faces[fcx].type = 1; + for(int i=0;ifaces[fcx].type++; + else if(x[i]==' '||x[i]=='\t')break;//only count the first one. + } + f.seekg(oldpos);//pop file ptr + + /** + validate vertex size to make sure this is a type of face-spec we know how to parse + which is only 2, 3, and 4 + */ + if(this->faces[fcx].count>4 ){ + printf("OBJ Unrecognized face vertex.count: %i. skipping rest of line.\n",this->faces[fcx].count); + ignoreRestOfLine(&f); + continue; + } + + + + /** + validate vertex.type - the data-depth. ie. how many numbers per chunk. + */ + if(this->faces[fcx].type!=3 && this->faces[fcx].type!=2 && this->faces[fcx].type!=1 ){ + printf("OBJ Unrecognized face vertex.type: %i. skipping rest of line.\n",this->faces[fcx].type); + ignoreRestOfLine(&f); + continue; + } + + + + /** + loop through and collect the appropriate data into the arrays. + */ + for(int thisVertexID=0;thisVertexIDfaces[fcx].count;thisVertexID++){ + if(this->faces[fcx].count>=thisVertexID+1){ + + //depending on the syntax of the face vertex chunk, parse accordingly + if(this->faces[fcx].type==3){ + // %i/%i/%i + f.getline(x,256,'/'); + this->faces[fcx].v[thisVertexID] = strtol(x,NULL,10); + f.getline(x,256,'/'); + this->faces[fcx].t[thisVertexID] = strtol(x,NULL,10);//collect the texture coord + if(this->faces[fcx].count==thisVertexID+1)f.getline(x,256);//this works because if the count is zero, + else f.getline(x,256,' '); + this->faces[fcx].n[thisVertexID] = strtol(x,NULL,10);//collect the normal + }else if(this->faces[fcx].type==2){ + // %i/%i + f.getline(x,256,'/'); + this->faces[fcx].v[thisVertexID] = strtol(x,NULL,10);//collect the texture coord + if(this->faces[fcx].count==thisVertexID+1)f.getline(x,256);//this works because if the count is zero, + else f.getline(x,256,' '); + this->faces[fcx].t[thisVertexID] = strtol(x,NULL,10);//collect the normal + }else if(this->faces[fcx].type==1){ + // %i + if(this->faces[fcx].count==thisVertexID+1)f.getline(x,256);//this works because if the count is zero, + else f.getline(x,256,' '); + this->faces[fcx].v[thisVertexID] = strtol(x,NULL,10);//collect the normal + } + + } + + } + faceCount++; + fcx++; + + }else if(strlen(tok)==0){ + }else{ + if(tok[0]!='#'){ + printf("OBJ Unrecognized Command: \"%s\"\n",tok); + } + ignoreRestOfLine(&f); + + } + } + f.close(); + + vertexCount = vcx; + +} + +OBJ::~OBJ(){ + //delete [] vertices; + //delete [] faces; +} + + +void OBJ::renderFace(int i){ + + /** + draw the verts + */ + // printf("%i\n",-1); + for(int ii=0;ii=ii+1){ + // printf("%i\n",1); + //todo: glTexCoord2f(...,...); + + if(faces[i].type>2){ + glNormal3f(normals[faces[i].n[ii]-1].x, + normals[faces[i].n[ii]-1].y, + normals[faces[i].n[ii]-1].z); + } + //printf("%i\n",2); + glVertex3f(vertices[faces[i].v[ii]-1].x, + vertices[faces[i].v[ii]-1].y, + vertices[faces[i].v[ii]-1].z); + //printf("%i\n",3); + } + //printf("%i\n",4); + } + //printf("%i\n",5); +} + + +void OBJ::fillFaces(){ + glEnable(GL_RESCALE_NORMAL); + for(int i=0;igetline(buff,256); + //ok, now skip empty lines as well. + if(f->peek()=='\n')ignoreRestOfLine(f); +} diff --git a/intern_disabled/obj.h b/intern_disabled/obj.h new file mode 100755 index 0000000..ff48e32 --- /dev/null +++ b/intern_disabled/obj.h @@ -0,0 +1,95 @@ +/** + +OBJ import by jtnimoy + +last updated 1-aug-06 + +still needs to be implemented: + - texture coordinates + - faces with vertex counts greater than 255. + - dynamically allocate arrays instead of hard coding a max value. but use standard STL vectors. + - some of the objs folder demos come out crooked. is this a vertex ordering thing, or a 1 vs. 0 thing? + +references: + http://orion.math.iastate.edu/burkardt/data/obj/obj_format.txt + + +*/ + +#ifndef _OBJ4GL_H_ +#define _OBJ4GL_H_ + +#include +#include +using namespace std; + +namespace obj4gl{ + + /** + holds the information for a single face. + */ + struct Face{ + /** + number of v,n,t token-phrases seperated by space. + */ + int count; + + /** + could be "%i/%i/%i" or "%i/%i" or number, and possibly "%i" + */ + int type; + + /** + vertices contained in the face + */ + long v[4]; + + /** + normals of that vertex (optional - see ::type) + */ + long n[4]; + + /** + texture coord of that vertex (optional - see ::type) + */ + long t[4]; + + }; + + struct Vertex{ + float x; + float y; + float z; + }; + + class OBJ{ + public: + + OBJ(char file[]); + OBJ(); + + ~OBJ(); + + int vertexCount; + int faceCount; + int normalCount; + + vector faces; + vector vertices; + vector normals; + + void open(char[]); + + void outlineFaces(); + void fillFaces(); + void pointVertices(); + Vertex getVertex(int i); + + private: + void renderFace(int i); + void ignoreRestOfLine(ifstream *f); + }; + +}; + +#endif diff --git a/intern_disabled/quadstretch.cpp b/intern_disabled/quadstretch.cpp new file mode 100755 index 0000000..2e69a83 --- /dev/null +++ b/intern_disabled/quadstretch.cpp @@ -0,0 +1,263 @@ +#include "quadstretch.h" + +void intersect_lines2(float x0,float y0,float x1,float y1,float x2,float y2,float x3,float y3,float &xi,float &yi){ + //THANK YOU PETE CONOLLY + float infinity_approx = 999999999999999999999.0f; + float a1=0.0; + float b1=0.0; + float c1=0.0; // constants of linear equations + float a2=0.0; + float b2=0.0; + float c2=0.0; + float det_inv=0.0; // the inverse of the determinant of the coefficient + float m1=0.0; + float m2=0.0; // the slopes of each line + + if(x1!=x0)m1=(y1-y0)/(x1-x0); + else m1 = infinity_approx; + + if(x3!=x2)m2=(y3-y2)/(x3-x2); + else m2 = infinity_approx; + a1=m1; + a2=m2; + b1=-1; + b2=-1; + c1=(y0-m1*x0); + c2=(y2-m2*x2); + // compute the inverse of the determinate + det_inv = 1/(a1*b2 - a2*b1); + // use Kramers rule to compute xi and yi + xi=((b1*c2 - b2*c1)*det_inv); + yi=((a2*c1 - a1*c2)*det_inv); +} + + +void quadStretch2(float x,float y,float l,float t,float w,float h,float *q,float &newx,float &newy){ + /* + --x & y are the original point + -- l & t are left and top of original rect + -- w & h are width and height of original rect + --q is an array of 4 points describing the new quad. + + --1. strip it down to floats between 0 and 1 + -- so we know where it is, relative to the boundaries. + */ + float xF = (x-l)/w; + float yF = (y-t)/h; + //2. generate "vertical" + + float interpTop[2]; + float interpBottom[2]; + float interpLeft[2]; + float interpRight[2]; + + interpolatePoints2( q[0*2+0],q[0*2+1], + q[1*2+0],q[1*2+1],xF, + interpTop[0],interpTop[1]); + + interpolatePoints2( q[3*2+0],q[3*2+1], + q[2*2+0],q[2*2+1],xF, + interpBottom[0],interpBottom[1]); + + //3. generate "horizontal" + interpolatePoints2( q[0*2+0],q[0*2+1], + q[3*2+0],q[3*2+1],yF, + interpLeft[0],interpLeft[1]); + + interpolatePoints2(q[1*2+0],q[1*2+1], + q[2*2+0],q[2*2+1],yF, + interpRight[0],interpRight[1]); + + intersect_lines2( interpTop[0], interpTop[1], + interpBottom[0], interpBottom[1], + interpLeft[0], interpLeft[1], + interpRight[0], interpRight[1], + newx,newy); +} + + +void interpolatePoints2(float x1,float y1,float x2,float y2,float i,float &x,float &y){ + //i is a float between 0 and 1 + x=x1+(x2-x1)*i; + y=y1+(y2-y1)*i; +} + + +void interpolatePoints(float x1,float y1, + float x2,float y2,float i,float *ret){ + // --i is a float between 0 and 1 + ret[0] = x1 + (x2-x1)*i; + ret[1] = y1 + (y2-y1)*i; +} + +//----------------------------------------------------------------------------- +void intersect_lines(float x0,float y0,float x1, + float y1,float x2,float y2, + float x3,float y3,float *ret){ + // --THANK YOU PETE CONOLLY +#define infinity_approx 999999999999999999999.0 + float a1=0.0; + float b1=0.0; + float c1=0.0; // constants of linear equations + float a2=0.0; + float b2=0.0; + float c2=0.0; + float det_inv=0.0; // the inverse of the determinant of the coefficient + float m1=0.0; + float m2=0.0; // the slopes of each line + if (x1 != x0) { + m1 = (y1-y0)/(x1-x0); + } else { + m1 = infinity_approx; + } + if (x3 != x2) { + m2 = (y3-y2)/(x3-x2); + } else { + m2 = infinity_approx; + } + a1 = m1; + a2 = m2; + b1 = -1; + b2 = -1; + c1 = (y0-m1*x0); + c2 = (y2-m2*x2); + // compute the inverse of the determinate + det_inv = 1/(a1*b2 - a2*b1); + // use Kramers rule to compute xi and yi + float xi=((b1*c2 - b2*c1)*det_inv); + float yi=((a2*c1 - a1*c2)*det_inv); + ret[0] = xi; + ret[1] = yi; +} + +//----------------------------------------------------------------------------- + +void quadstretch(float x,float y,float l,float t, + float w,float h,float *qx,float *qy,float *ret){ + + /* + --x & y are the original point + -- l & t are left and top of original rect + -- w & h are width and height of original rect + --qx and qy are arrays of 4 points describing the new quad. + + --1. strip it down to floats between 0 and 1 + -- so we know where it is, relative to the boundaries. + */ + + float xF = (x-l)/float(w); + float yF = (y-t)/float(h); + // 2. generate "vertical" + float interpTop[2]; + interpolatePoints(qx[0],qy[0],qx[1],qy[1],xF,interpTop); + + float interpBottom[2]; + interpolatePoints(qx[3],qy[3],qx[2],qy[2],xF,interpBottom); + //3. generate "horizontal" + float interpLeft[2]; + interpolatePoints(qx[0],qy[0],qx[3],qy[3],yF,interpLeft); + + float interpRight[2]; + interpolatePoints(qx[1],qy[1],qx[2],qy[2],yF,interpRight); + + intersect_lines(interpTop [0], interpTop[1], + interpBottom[0],interpBottom[1], + interpLeft [0], interpLeft[1], + interpRight [0], interpRight[1],ret); +} + +//----------------------------------------------------------------------------- + +#define CMPPNTS(a,b,c,d) ((a==c)&&(b==d)) + +int intersectLineSegs(float x1,float y1, + float x2,float y2, + float x3,float y3, + float x4,float y4){ + float ix=0; + float iy=0; + float m1=0; + float m2=0; + float b1=0; + float b2=0; + // this code was taken from virtual origami icm final from itp + // dumbed down only to return true or false, instead of a + // full geometric relationships report. + + // warning: Z not implemented + + if(CMPPNTS(x1,y1,x3,y3)||CMPPNTS(x1,y1,x4,y4)|| + CMPPNTS(x2,y2,x3,y3)||CMPPNTS(x2,y2,x4,y4)){ + //any vertexes have a straight match? + return true; + } + + //vertical check + if(x1==x2){//vertical solutions + m2 = (y3 - y4)/(x3 - x4); + b2 = y3 - m2 * x3; + ix = x1; + iy = m2*x1 + b2; + + }else if(x3==x4){//vertical solutions + m1 = (y1 - y2)/(x1 - x2); + b1 = y1 - m1 * x1; + ix = x3; + iy = m1*x3 + b1; + + }else{//otherwise, do it like you would + // slopes + m1 = (y1 - y2)/(x1 - x2); + m2 = (y3 - y4)/(x3 - x4); + + if(m1==m2){ + //ir.parallel = true; + //return ir; + return false; + } + // y-intercepts + b1 = y1 - m1 * x1; + b2 = y3 - m2 * x3; + + ix = (b1-b2)/(m2-m1); + iy = m1*ix + b1; + } + + //and finally, check to see if it is within both segments. + //first, the Xs + + if(x1>x2){ + if(ix > x1 || ix < x2)return false;//ir.outside = true; + }else{ + if(ix < x1 || ix > x2)return false;//ir.outside = true; + } + + if(x3>x4){ + if(ix > x3 || ix < x4)return false;//ir.outside = true; + }else{ + if(ix < x3 || ix > x4)return false;//ir.outside = true; + } + + //then the Y's + + if(y1>y2){ + if(iy > y1 || iy < y2)return false;//ir.outside = true; + }else{ + if(iy < y1 || iy > y2)return false;//ir.outside = true; + } + + if(y3>y4){ + if(iy > y3 || iy < y4)return false;//ir.outside = true; + }else{ + if(iy < y3 || iy > y4)return false;//ir.outside = true; + } + + // if(ir.outside){ + // return false; + //return ir; + // }else{ + //ir.ok = true; + return true; + //return ir; + //} +} diff --git a/intern_disabled/server_internals.c b/intern_disabled/server_internals.c new file mode 100755 index 0000000..be7f88c --- /dev/null +++ b/intern_disabled/server_internals.c @@ -0,0 +1,112 @@ +/* + * server_internals.c + * meant to be compiled on g++ on win32 and os x + * this is the backend for server.cpp + */ + +#include "server_internals.h" + +//------------------------------------------------------------------------------ +void _tcpserver_messageCallbackFunc(void(*message_callbackfuncname)(int,int,int)){ + _tcpserver_message_callbackfunc = message_callbackfuncname; +} + +//------------------------------------------------------------------------------ +void _tcpserver_close(){ + close(_tcpserver_socket);//this will also send EOFs to all the threads. + _tcpserver_socket = -1; +} +//------------------------------------------------------------------------------ +void *_tcpserver_serverListening(void *args){ + int ret; + //listen out the port. + + while(1){ + //printf("debug %i\r\n",_tcpserver_socket); + sched_yield(); + listen(_tcpserver_socket,0); + if(_tcpserver_socket!=-1){ + pthread_t tid; + if ((_tcpserver_pendingSocket = get_client_socket(_tcpserver_socket)) == -1){ + printf("error getting network client. %i\n",_tcpserver_pendingSocket); + return 0; + } else { //success + ret = pthread_create(&tid, NULL,_tcpserver_clienthandler, NULL); //create a new thread + } + + } else { + printf("there was an error\n",0); + break; + } + } +} +//------------------------------------------------------------------------------ +int _tcpserver_listen(int port){ + + if((_tcpserver_socket = make_listen_socket(port)) == -1){ + printf("error making socket\n",0); + return -1; + } + pthread_t tid; + pthread_create(&tid, NULL,_tcpserver_serverListening, NULL); //create a new thread + return _tcpserver_socket; +} +//------------------------------------------------------------------------------ +void *_tcpserver_clienthandler(void *args){ + int mySock = _tcpserver_pendingSocket;//take a snapshot. + int ret; + FILE *fp = fdopen(mySock, "r"); + _tcpserver_message_callbackfunc( _TCPSERVER_MESSAGE_CLIENT_CONNECTED,_tcpserver_pendingSocket,0 ); + //get some input + int c; + while ((c = fgetc(fp)) != EOF ) { + sched_yield(); + _tcpserver_message_callbackfunc( _TCPSERVER_MESSAGE_CLIENT_RECEIVED_BYTE,mySock,c ); + } + + fclose(fp); + close(mySock); + + _tcpserver_message_callbackfunc( _TCPSERVER_MESSAGE_CLIENT_DISCONNECTED,mySock,0 ); + + return 0; +} + +//------------------------------------------------------------------------------ + +int get_client_socket( int listen_socket) { + struct sockaddr_in sin; + int sock; + socklen_t sin_len; + memset(&sin, 0, sizeof( sin)); + sin_len = sizeof( sin); + sock = accept( listen_socket, (struct sockaddr *) &sin, &sin_len); + return sock; +} + +//------------------------------------------------------------------------------ + +int make_listen_socket( int port) { + struct sockaddr_in sin; + int sock; + sock = socket( AF_INET, SOCK_STREAM, 0); + if (sock < 0){ + printf("network error:socket could not be created. (port:%i)\n",port); + return -1; + } + memset(& sin, 0, sizeof( sin)); + sin.sin_family = AF_INET; + sin.sin_addr.s_addr = htonl( INADDR_ANY); + sin.sin_port = htons( port); + if (bind( sock, (struct sockaddr*) &sin, sizeof( sin)) < 0){ + printf("network error:socket could not be bound. (port:%i) Do you have permissions?\n",port); + return -1; + } + return sock; + +} +//------------------------------------------------------------------------------ +int _tcpserver_getSocket(){ + return _tcpserver_socket; +} + diff --git a/intern_disabled/server_internals.h b/intern_disabled/server_internals.h new file mode 100755 index 0000000..0a000da --- /dev/null +++ b/intern_disabled/server_internals.h @@ -0,0 +1,42 @@ +#ifndef _SERVER_INTERNALS_H_ +#define _SERVER_INTERNALS_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int _tcpserver_socket=-1;//main socket +static int _tcpserver_pendingSocket=-1; + +static void(*_tcpserver_message_callbackfunc)(int,int,int); + +#define _TCPSERVER_MESSAGE_CLIENT_CONNECTED 0 +#define _TCPSERVER_MESSAGE_CLIENT_DISCONNECTED 1 +#define _TCPSERVER_MESSAGE_CLIENT_RECEIVED_BYTE 2 + +void _server_callback(int arg1,int arg2,int arg3); +void server_close(); +void server_init(int port); +void server_sendAll(char *data,int length); +int server_valid();//returns true only if the server is ready and listening. +int server_clientcount(); + +//------------------------------------------------------------------------------ + +void _tcpserver_messageCallbackFunc(void(*message_callbackfuncname)(int,int,int)); +int make_listen_socket( int port) ; +int get_client_socket( int listen_socket) ; +void *_tcpserver_clienthandler(void *args); +void *_tcpserver_serverListening(void *args); +int _tcpserver_listen(int port); +void _tcpserver_close(); +int _tcpserver_getSocket(); +#endif diff --git a/intern_disabled/server_internals2.cpp b/intern_disabled/server_internals2.cpp new file mode 100755 index 0000000..a34afeb --- /dev/null +++ b/intern_disabled/server_internals2.cpp @@ -0,0 +1,88 @@ +#include "server_internals.h" +#include "Vector.h" + +static Vector *_server_clients=0; + +//------------------------------------------------------------------------------ + +int server_valid(){ + //printf("%i\r\n",_tcpserver_getSocket()); + return (_tcpserver_getSocket()!=-1);//zero if not valid. +} + +int server_clientcount(){ + if(_server_clients!=0){ + return _server_clients->count; + } else { + return 0; + } +} + +void _server_callback(int arg1,int arg2,int arg3){ + + switch(arg1){ + case _TCPSERVER_MESSAGE_CLIENT_CONNECTED: + //printf("new client %i\n",arg2); + _server_clients->push(arg2); + break; + case _TCPSERVER_MESSAGE_CLIENT_DISCONNECTED: + //printf("bye client %i\n",arg2); + _server_clients->deleteMatch(arg2); + break; + case _TCPSERVER_MESSAGE_CLIENT_RECEIVED_BYTE: + if(arg3=='\n'){ + //printf("received %i %i '\\n'\n",arg2,arg3,arg3); + } else if(arg3=='\r'){ + //printf("received %i %i '\\r'\n",arg2,arg3,arg3); + } else { + //printf("received %i %i '%c'\n",arg2,arg3,arg3); + } + + // here is a demonstration of a simple broadcast server. it echos all messages to everyone. + //char thebyte; + //thebyte = (char)arg3; + //server_sendAll(&thebyte,1);// here is where i relay any messages to the other clients. + // + + break; + default: + printf("error: invalid _tcpserver internal callback message: %i\n",arg1);//wtfh?! + } +} + +void server_close(){ + if(_server_clients!=0){ + delete _server_clients; + } + if(_tcpserver_socket!=-1){ + _tcpserver_close(); + } +} + +void server_init(int port){ + _server_clients = new Vector(); + _tcpserver_messageCallbackFunc(_server_callback); + _tcpserver_listen(port); +} + + +void server_sendAll(char *data,int length){ + for(int i=0;i<_server_clients->count;i++){ + int thisClient = _server_clients->get(i); + send(thisClient,data,length,0); + } +} + +/* this is an example program that uses this API + +int main(){ + server_init(667); + while(1){ + //server_sendAll("hi there\n",strlen("hi there\n")); + sched_yield();//don't care what i do here. + } + server_close(); + return 0; +} + +*/ diff --git a/script/Info.plist.template.xml b/script/Info.plist.template.xml new file mode 100755 index 0000000..acd5fe1 --- /dev/null +++ b/script/Info.plist.template.xml @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + %%PROJNAME%% + CFBundleGetInfoString + no description (yet) + CFBundleIconFile + appIcon + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + %%PROJNAME%% + CFBundlePackageType + APPL + CFBundleSignature + ???? + CSResourcesFileMapped + + + diff --git a/script/appIt b/script/appIt new file mode 100755 index 0000000..45252b9 --- /dev/null +++ b/script/appIt @@ -0,0 +1,33 @@ +#!/usr/bin/python + +import sys + +chmod = 0755 + +if(len(sys.argv)==1): + print "help goes here" +else: #make it + import os + projname = sys.argv[1] + try: + os.mkdir(projname+".app",chmod) + os.mkdir(projname+".app/Contents",chmod) + os.mkdir(projname+".app/Contents/MacOS",chmod) + os.mkdir(projname+".app/Contents/Resources",chmod) + os.mkdir(projname+".app/Contents/Resources/renders",chmod) + except(OSError):#who cares if it already exists + pass + + os.system("cp -r ./media ./" + projname + ".app/Contents/Resources") + os.system("cp ./"+projname+" ./" + projname + ".app/Contents/MacOS/" + projname) + os.system("cp ./media/appIcon.icns ./" + projname + ".app/Contents/Resources/appIcon.icns") + #Info.plist + plist = open("script/Info.plist.template.xml","r") + plist = plist.read() + import string + plist = string.split(plist,"%%PROJNAME%%") + plist = string.join(plist,projname) + + a = open("./" + projname + ".app/Contents/Info.plist","w") + a.write(plist) + a.close() diff --git a/script/bundle_depends.py b/script/bundle_depends.py new file mode 100755 index 0000000..50cddf5 --- /dev/null +++ b/script/bundle_depends.py @@ -0,0 +1,77 @@ +#!/usr/bin/python +# +# this will analyse a given binary and bundle all depends from /opt/local/lib +# +import sys,os,string + +queue = [] + +class OtoolResult(object): + """docstring""" + + fullPath = "" + moduleName = "" + path = "" + updatable = "" + + def __init__(self,s,u): + """docstring""" + self.extract(s) + self.updatable = u + def extract(self,s): + """docstring""" + self.fullPath = string.split(s[1:],' ')[0] + self.moduleName = string.split(self.fullPath,'/')[-1] + self.path = string.join(string.split(self.fullPath,'/')[:-1],'/') + + def __str__(self): + return "OtoolResult{\n\tfullpath=" + self.fullPath + "\n\tmoduleName=" + self.moduleName + "\n\tpath=" + self.path + "\n}\n" + + def getDestDir(self): + return (string.join(string.split(sys.argv[1],"/")[:-1],"/")) + + + def previousExists(self): + """determines whether or not we should copy the file into that dir""" + lss = os.listdir(self.getDestDir()) + retval = 0 + for i in lss: + if(i==self.moduleName): + retval = 1 + break + return retval + + def bundlePathMatch(self,p): + if(self.path == p): + if(not self.previousExists()): + global queue + os.system("cp " + self.path + "/" + self.moduleName + " " + self.getDestDir()) + #todo - call install_name_tool with -id flag to update the lib's ID. + os.system("install_name_tool -id @executable_path/" + self.moduleName + " " + self.getDestDir() + "/" + self.moduleName) + print "\tbundled " + self.moduleName + queue += [self.getDestDir() + "/" + self.moduleName] #add this to the end of the list + os.system("install_name_tool -change " + self.fullPath + " " + "@executable_path/" + self.moduleName + " " + self.updatable) + +# argument validation +if(len(sys.argv) < 2): + print "\n\nexample: bundle_depends.py ../programme.app/Contents/MacOS/programme\n\n" + + +def bundle_depends(filename): + p = os.popen("otool -L "+filename,'r') + p = string.split(p.read(),'\n') + + p = p[1:-1] #format otool output by trimming 1 from left and right + + for i in p: + otr = OtoolResult(i,filename) + otr.bundlePathMatch(thisPath) + + +thisPath = "/opt/local/lib" +queue += [sys.argv[1]] + +while(len(queue)>0): + print("Updating " + queue[0]) + bundle_depends(queue[0]) #deal with the first one + queue = queue[1:] #chop off the first one diff --git a/script/cpptemplate.cpp b/script/cpptemplate.cpp new file mode 100755 index 0000000..293ec4e --- /dev/null +++ b/script/cpptemplate.cpp @@ -0,0 +1,21 @@ +#include ".h" +#include "jttoolkit.h" +#include "Global.h" + +::(){ + for(int i=0;i<5;i++)rnd.push_back(randomFloat()); + +} + +::~(){ + +} + +void ::step(){ + +} + +void ::draw(int counter,JPoint end){ + +} + diff --git a/script/create b/script/create new file mode 100755 index 0000000..08e5b8b --- /dev/null +++ b/script/create @@ -0,0 +1,37 @@ +#!/usr/bin/python + +# +# this script will generate a new C++ class in its own file, inside +# the intern directory. +# + +import string +import sys +import os + +f = open(sys.path[0] + "/cpptemplate.cpp","r") +cpptemplate = f.read() +f.close() + +f = open(sys.path[0] + "/headertemplate.h","r") +headertemplate = f.read() +f.close() + +def replace(str,newname): + s = string.split(str,"") + return string.join(s,newname) + +if(len(sys.argv)<2): + print "creates a new object in jttoolkit intern and adds it to the makefile.\nexample: ./create.py JTClassName" +else: + full=sys.argv[1] + print "making object \""+full+".cpp\"" + name = full + #execfile("./generate") + out=open(sys.path[0] + "/../intern/"+full+".cpp","a") + out.write(replace(cpptemplate,name)) + out.close() + out=open(sys.path[0] + "/../intern/"+name+".h","a") + out.write(replace(headertemplate,name)) + out.close() + diff --git a/script/findReplace.py b/script/findReplace.py new file mode 100755 index 0000000..b137276 --- /dev/null +++ b/script/findReplace.py @@ -0,0 +1,10 @@ +#!/usr/bin/python +import string,sys + +a = open(sys.argv[1],"rb") +a=a.read() +a=string.split(a,sys.argv[2]) +a=string.join(a,sys.argv[3]) +b=open(sys.argv[1],"wb") +b.write(a) +b.close() diff --git a/script/generate b/script/generate new file mode 100755 index 0000000..ba387b9 --- /dev/null +++ b/script/generate @@ -0,0 +1,29 @@ +#!/usr/bin/python +import string +infile = open("../script/list.txt","r") +objs = string.split(infile.read()) +out = open("objectsbuild_generated.mk","w") +for i in objs: + if(i!=''): + n = string.split(i,'.')[0] #chop off the .cpp or .c + out.write("build/"+n+".o: intern/"+i+"\n\tcd build; g++ $(OFLAGS) ../intern/"+i+"\n\n") +out.close() + +out = open("objectslist_generated.mk","w") +out.write("OBJECTS="); +for i in objs: + if(i!=''): + n = string.split(i,'.')[0] #chop off the .cpp or .c + out.write(n+".o ") +out.write("\n\n") +out.close() + + +out = open("objectslistbuild_generated.mk","w") +out.write("OBJECTSBUILD="); +for i in objs: + if(i!=''): + n = string.split(i,'.')[0] #chop off the .cpp or .c + out.write("build/"+n+".o ") +out.write("\n\n") +out.close() diff --git a/script/headertemplate.h b/script/headertemplate.h new file mode 100755 index 0000000..2650e46 --- /dev/null +++ b/script/headertemplate.h @@ -0,0 +1,24 @@ +#ifndef __H_ +#define __H_ + + +#include "TreeOrniment.h" +#include + +using namespace std; + +class : public TreeOrniment{ + public: + vector rnd; + (); + ~(); + + void step(); + void draw(int counter,JPoint end); + +}; + + + +#endif + diff --git a/script/objectsbuild_generated.mk b/script/objectsbuild_generated.mk new file mode 100755 index 0000000..9f21081 --- /dev/null +++ b/script/objectsbuild_generated.mk @@ -0,0 +1,72 @@ +build/jttoolkit.o: intern/jttoolkit.cpp + cd build; g++ $(OFLAGS) ../intern/jttoolkit.cpp + +build/project.o: intern/project.cpp + cd build; g++ $(OFLAGS) ../intern/project.cpp + +build/JoshFont.o: intern/JoshFont.cpp + cd build; g++ $(OFLAGS) ../intern/JoshFont.cpp + +build/quadstretch.o: intern/quadstretch.cpp + cd build; g++ $(OFLAGS) ../intern/quadstretch.cpp + +build/obj.o: intern/obj.cpp + cd build; g++ $(OFLAGS) ../intern/obj.cpp + +build/Global.o: intern/Global.cpp + cd build; g++ $(OFLAGS) ../intern/Global.cpp + +build/JRect.o: intern/JRect.cpp + cd build; g++ $(OFLAGS) ../intern/JRect.cpp + +build/Satellite.o: intern/Satellite.cpp + cd build; g++ $(OFLAGS) ../intern/Satellite.cpp + +build/TheBall.o: intern/TheBall.cpp + cd build; g++ $(OFLAGS) ../intern/TheBall.cpp + +build/BallPointer.o: intern/BallPointer.cpp + cd build; g++ $(OFLAGS) ../intern/BallPointer.cpp + +build/BallPathTracer.o: intern/BallPathTracer.cpp + cd build; g++ $(OFLAGS) ../intern/BallPathTracer.cpp + +build/JPoint.o: intern/JPoint.cpp + cd build; g++ $(OFLAGS) ../intern/JPoint.cpp + +build/Athletes.o: intern/Athletes.cpp + cd build; g++ $(OFLAGS) ../intern/Athletes.cpp + +build/Guy.o: intern/Guy.cpp + cd build; g++ $(OFLAGS) ../intern/Guy.cpp + +build/GameGrid.o: intern/GameGrid.cpp + cd build; g++ $(OFLAGS) ../intern/GameGrid.cpp + +build/JImage.o: intern/JImage.cpp + cd build; g++ $(OFLAGS) ../intern/JImage.cpp + +build/Clover.o: intern/Clover.cpp + cd build; g++ $(OFLAGS) ../intern/Clover.cpp + +build/GuyPointer.o: intern/GuyPointer.cpp + cd build; g++ $(OFLAGS) ../intern/GuyPointer.cpp + +build/StatSign.o: intern/StatSign.cpp + cd build; g++ $(OFLAGS) ../intern/StatSign.cpp + +build/GuyConnectors.o: intern/GuyConnectors.cpp + cd build; g++ $(OFLAGS) ../intern/GuyConnectors.cpp + +build/JImageSequence.o: intern/JImageSequence.cpp + cd build; g++ $(OFLAGS) ../intern/JImageSequence.cpp + +build/ShotProfile.o: intern/ShotProfile.cpp + cd build; g++ $(OFLAGS) ../intern/ShotProfile.cpp + +build/FluxDiagram.o: intern/FluxDiagram.cpp + cd build; g++ $(OFLAGS) ../intern/FluxDiagram.cpp + +build/TreeNode.o: intern/TreeNode.cpp + cd build; g++ $(OFLAGS) ../intern/TreeNode.cpp + diff --git a/script/objectslist_generated.mk b/script/objectslist_generated.mk new file mode 100755 index 0000000..8c959e0 --- /dev/null +++ b/script/objectslist_generated.mk @@ -0,0 +1,2 @@ +OBJECTS=jttoolkit.o project.o JoshFont.o quadstretch.o obj.o Global.o JRect.o Satellite.o TheBall.o BallPointer.o BallPathTracer.o JPoint.o Athletes.o Guy.o GameGrid.o JImage.o Clover.o GuyPointer.o StatSign.o GuyConnectors.o JImageSequence.o ShotProfile.o FluxDiagram.o TreeNode.o + diff --git a/script/objectslistbuild_generated.mk b/script/objectslistbuild_generated.mk new file mode 100755 index 0000000..8e566fc --- /dev/null +++ b/script/objectslistbuild_generated.mk @@ -0,0 +1,2 @@ +OBJECTSBUILD=build/jttoolkit.o build/project.o build/JoshFont.o build/quadstretch.o build/obj.o build/Global.o build/JRect.o build/Satellite.o build/TheBall.o build/BallPointer.o build/BallPathTracer.o build/JPoint.o build/Athletes.o build/Guy.o build/GameGrid.o build/JImage.o build/Clover.o build/GuyPointer.o build/StatSign.o build/GuyConnectors.o build/JImageSequence.o build/ShotProfile.o build/FluxDiagram.o build/TreeNode.o + -- 2.34.1