İletileri Göster

Bu özellik size üyenin attığı tüm iletileri gösterme olanağı sağlayacaktır . Not sadece size izin verilen bölümlerdeki iletilerini görebilirsiniz


Konular - spaztica

Sayfa: 1 ... 14 15 [16] 17
226
coding / Exe Yapısı
« : 27.04.2004 05:53:23 »
http://www.xbdev.net/fileformats/pe/pe.php adresinde file header'lar, exe yapısı ve PE üzerine güzel bir yazı var; özellikle 4k ve 256byte gibi çalışmalar yapanlar için fikir verebilir sanırım.

227
geyik / Lamer Cenneti
« : 24.04.2004 00:40:24 »
http://www.tomshardware.com.tr/game/20040421/index.html

lamer partisi; aslında bi bomba çakmak lazım tepesine ya, neyse. :)

228
coding / Pi
« : 21.04.2004 22:18:35 »
virgülden sonrak 10bin hane; kime lazım olursa artık...

Kod: [Seç]
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940513200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892354201995611212902196086403441815981362977477130996051870721134999999837297804995105973173281609631859502445945534690830264252230825334468503526193118817101000313783875288658753320838142061717766914730359825349042875546873115956286388235378759375195778185778053217122680661300192787661119590921642019893809525720106548586327886593615338182796823030195203530185296899577362259941389124972177528347913151557485724245415069595082953311686172785588907509838175463746493931925506040092770167113900984882401285836160356370766010471018194295559619894676783744944825537977472684710404753464620804668425906949129331367702898915210475216205696602405803815019351125338243003558764024749647326391419927260426992279678235478163600934172164121992458631503028618297455570674983850549458858692699569092721079750930295532116534498720275596023648066549911988183479775356636980742654252786255181841757467289097777279380008164706001614524919217321721477235014144197356854816136115735255213347574184946843852332390739414333454776241686251898356948556209921922218427255025425688767179049460165346680498862723279178608578438382796797668145410095388378636095068006422512520511739298489608412848862694560424196528502221066118630674427862203919494504712371378696095636437191728746776465757396241389086583264599581339047802759009946576407895126946839835259570982582262052248940772671947826848260147699090264013639443745530506820349625245174939965143142980919065925093722169646151570985838741059788595977297549893016175392846813826868386894277415599185592524595395943104997252468084598727364469584865383673622262609912460805124388439045124413654976278079771569143599770012961608944169486855584840635342207222582848864815845602850601684273945226746767889525213852254995466672782398645659611635488623057745649803559363456817432411251507606947945109659609402522887971089314566913686722874894056010150330861792868092087476091782493858900971490967598526136554978189312978482168299894872265880485756401427047755513237964145152374623436454285844479526586782105114135473573952311342716610213596953623144295248493718711014576540359027993440374200731057853906219838744780847848968332144571386875194350643021845319104848100537061468067491927819119793995206141966342875444064374512371819217999839101591956181467514269123974894090718649423196156794520809514655022523160388193014209376213785595663893778708303906979207734672218256259966150142150306803844773454920260541466592520149744285073251866600213243408819071048633173464965145390579626856100550810665879699816357473638405257145910289706414011097120628043903975951567715770042033786993600723055876317635942187312514712053292819182618612586732157919841484882916447060957527069572209175671167229109816909152801735067127485832228718352093539657251210835791513698820914442100675103346711031412671113699086585163983150197016515116851714376576183515565088490998985998238734552833163550764791853589322618548963213293308985706420467525907091548141654985946163718027098199430992448895757128289059232332609729971208443357326548938239119325974636673058360414281388303203824903758985243744170291327656180937734440307074692112019130203303801976211011004492932151608424448596376698389522868478312355265821314495768572624334418930396864262434107732269780280731891544110104468232527162010526522721116603966655730925471105578537634668206531098965269186205647693125705863566201855810072936065987648611791045334885034611365768675324944166803962657978771855608455296541266540853061434443185867697514566140680070023787765913440171274947042056223053899456131407112700040785473326993908145466464588079727082668306343285878569830523580893306575740679545716377525420211495576158140025012622859413021647155097925923099079654737612551765675135751782966645477917450112996148903046399471329621073404375189573596145890193897131117904297828564750320319869151402870808599048010941214722131794764777262241425485454033215718530614228813758504306332175182979866223717215916077166925474873898665494945011465406284336639379003976926567214638530673609657120918076383271664162748888007869256029022847210403172118608204190004229661711963779213375751149595015660496318629472654736425230817703675159067350235072835405670403867435136222247715891504953098444893330963408780769325993978054193414473774418426312986080998886874132604721569516239658645730216315981931951673538129741677294786724229246543668009806769282382806899640048243540370141631496589794092432378969070697794223625082216889573837986230015937764716512289357860158816175578297352334460428151262720373431465319777741603199066554187639792933441952154134189948544473456738316249934191318148092777710386387734317720754565453220777092120190516609628049092636019759882816133231666365286193266863360627356763035447762803504507772355471058595487027908143562401451718062464362679456127531813407833033625423278394497538243720583531147711992606381334677687969597030983391307710987040859133746414428227726346594704745878477872019277152807317679077071572134447306057007334924369311383504931631284042512192565179806941135280131470130478164378851852909285452011658393419656213491434159562586586557055269049652098580338507224264829397285847831630577775606888764462482468579260395352773480304802900587607582510474709164396136267604492562742042083208566119062545433721315359584506877246029016187667952406163425225771954291629919306455377991403734043287526288896399587947572917464263574552540790914513571113694109119393251910760208252026187985318877058429725916778131496990090192116971737278476847268608490033770242429165130050051683233643503895170298939223345172201381280696501178440874519601212285993716231301711444846409038906449544400619869075485160263275052983491874078668088183385102283345085048608250393021332197155184306354550076682829493041377655279397517546139539846833936383047461199665385815384205685338621867252334028308711232827892125077126294632295639898989358211674562701021835646220134967151881909730381198004973407239610368540664319395097901906996395524530054505806855019567302292191393391856803449039820595510022635353619204199474553859381023439554495977837790237421617271117236434354394782218185286240851400666044332588856986705431547069657474585503323233421073015459405165537906866273337995851156257843229882737231989875714159578111963583300594087306812160287649628674460477464915995054973742562690104903778198683593814657412680492564879855614537234786733039046883834363465537949864192705638729317487233208376011230299113679386270894387993620162951541337142489283072201269014754668476535761647737946752004907571555278196536213239264061601363581559074220202031872776052772190055614842555187925303435139844253223415762336106425063904975008656271095359194658975141310348227693062474353632569160781547818115284366795706110861533150445212747392454494542368288606134084148637767009612071512491404302725386076482363414334623518975766452164137679690314950191085759844239198629164219399490723623464684411739403265918404437805133389452574239950829659122850855582157250310712570126683024029295252201187267675622041542051618416348475651699981161410100299607838690929160302884002691041407928862150784245167090870006992821206604183718065355672525325675328612910424877618258297651579598470356222629348600341587229805349896502262917487882027342092222453398562647669149055628425039127577102840279980663658254889264880254566101729670266407655904290994568150652653053718294127033693137851786090407086671149655834343476933857817113864558736781230145876871266034891390956200993936103102916161528813843790990423174733639480457593149314052976347574811935670911013775172100803155902485309066920376719220332290943346768514221447737939375170344366199104033751117354719185504644902636551281622882446257591633303910722538374218214088350865739177150968288747826569959957449066175834413752239709683408005355984917541738188399944697486762655165827658483588453142775687900290951702835297163445621296404352311760066510124120065975585127617858382920419748442360800719304576189323492292796501987518721272675079812554709589045563579212210333466974992356302549478024901141952123828153091140790738602515227429958180724716259166854513331239480494707911915326734302824418604142636395480004480026704962482017928964766975831832713142517029692348896276684403232609275249603579964692565049368183609003238092934595889706953653494060340216654437558900456328822505452556405644824651518754711962184439658253375438856909411303150952617937800297412076651479394259029896959469955657612186561967337862362561252163208628692221032748892186543648022967807057656151446320469279068212073883778142335628236089632080682224680122482611771858963814091839036736722208883215137556003727983940041529700287830766709444745601345564172543709069793961225714298946715435784687886144458123145935719849225284716050492212424701412147805734551050080190869960330276347870810817545011930714122339086639383395294257869050764310063835198343893415961318543475464955697810382930971646514384070070736041123735998434522516105070270562352660127648483084076118301305279320542746286540360367453286510570658748822569815793678976697422057505968344086973502014102067235850200724522563265134105592401902742162484391403599895353945909440704691209140938700126456001623742880210927645793106579229552498872758461012648369998922569596881592056001016552563756

229
coding / Yalancıktan Griler...
« : 21.04.2004 06:44:28 »
http://r0k.us/graphics/pseudoGrey.html

buradaki teknikle normal bir 24 bit grafik için ekstradan 1786 gri seviyesi eklemek ve kullanmak mümkün oalbiliyormuş. c++ ile kod yapanların ilgisini çekebilir sanki. luma formülünün bir açığını mı ne kullanıyor anlamadığım kadarıyla...

230
tr scener discussion / Yeni Moderatör
« : 08.04.2004 14:17:09 »
5pritus arkadaşımız skate'in önerisi ile forum moderatörü olmuştur. başarılarının devamını dileriz. :)

231
demoscene / Tr'deki TÜm Demogrupları
« : 06.04.2004 20:29:13 »
tr'de var olmuş TÜM demogruplarını araştırıyorum; grup isimleri, üyeleri, hangi yıllarda var oldular, bulunabiliyorsa release'leri...

birileri yardımcı olabilirse çok sevinirim. :)

232
geyik / 360a Bir-ikiii
« : 06.04.2004 11:53:03 »

233
geyik / I Can
« : 06.04.2004 11:43:50 »
Bilkom yine yarışmasını duyurmuş; aramızda ilgilenen olabilir belki. Ödüller hiç de fena değil aslında. Olmadı, satar, düzgün bi PC'ye de yatırım yapabilirsiniz hani...

Özellikle aramızda müzikle uğraşanlar varsa bir göz atsın derim.
http://www.i-can.bilkom.com.tr

234
coding / Bumpmapping
« : 31.03.2004 07:01:35 »
Alıntı
To really do REAL 2d bump mapping one has to calculate normals for every
pixel in bump map (an image representing "heights" of pixels) and for each
pixel take dot product of light source and this normal (the normal of the
surface (ie. bumpy screen) is <0,0,-1>, ie. directly to the viewer, so it
doesn't affect bump mapping).

This, of course, is awfully slow. And it does not look that good either.

The answer is simple. If we know X and Y of normal, we can calculate it's Z
(as normals are unit vectors. So Z is simply 1-sqrt(X^2 + Y^2) ). Therefore,
we can calculate the lighting value for each X and Y and store it into a
map (which, normally is 256x256). This kind of a map is called enviroment map
(enviroment maps are used to simulate reflecting objects with simple mapping).

Here's some pseudocode to calculate enviroment map:

for (int y=0;y<256;y++)
for (int x=0;x<256;x++)
{
 float nX=(x-128)/128;
 float nY=(y-128)/128;
 float nZ=1-sqrt(nX*nX + nY*nY);
 if (nZ<0) nZ=0;
 enviromentmap
  • [y]=nZ*256; // 256 shades...

};

Of course you can use Phong illumination model as well...

So, by picking value at enviromentmap[normalx+128][normaly+128] (if normals are
in 9.7 fixed point format) we get the correct lighting info for lightsource at
<0,0,-infinity>. This, althought correct, is not what we want. We want light-
source to move and be infinitely close to the surface.

Normalx is simply difference of heights in neighbour pixel on X axis... ie.

normalx = bumpmap[x+1][y] - bumpmap[x-1][y]

and for normaly, we ofcourse do

normaly = bumpmap
  • [y+1] - bumpmap
  • [y-1]


And now, gals and guys, comes the damned easy part :)

We simply pick value from
enviromentmap[(normalx-(lightx-currentx))][(normalx-(lightx-currentx))].
Of course, you have to check that values are within range...

So, here's a simple pseudocode for 2d bump mapper:

for (int y=0;y<200;y++)
for (int x=0;x<320;x++)
{
 int nX=bumpmap[x+1][y]-bumpmap[x-1][y];
 int nY=bumpmap
  • [y+1]-bumpmap
  • [y-1];

 int lX=x-lightx;
 int lY=y-lighty;
 nX-=lX;
 nY-=lY;
 nX+=128;
 nY+=128;
 if (nX<0 || nX>255) nX=0;
 if (nY<0 || nY>255) nY=0;
 screen
  • [y]=enviromentmap[nX][nY];

};

Hope this helps you...

235
coding / Ateş Efekti
« : 31.03.2004 06:44:21 »
Alıntı
Introduction:
This is the first tutorial (of many I hope) on programming various 2d
and 3d effects. I am starting off with the standard fire effect. Often
enough, people who write tutorials start with stuff about mode 13h,
palettes, etc ... by I figure that there is already plenty enough stuff
out there on those topics.
Before you start reading, maybe you will want to download fire.zip from
my homepage (unless you already have) and look at it and the code. Just
so we know what we are talking about here ;) If you feel that the code
is somewhat obscure (I think it is ...) well then read on!

Part I: Generating a cool palette
The first thing your program will have to do, (after setting up video
mode and such) is to create a cool palette for the fire. This turns out
to be a crucial part of the effectiveness of the effect.
To look good, the palette must contain a smooth gradient of colors that
range from white to black, passing by reds, oranges, yellows and maybe
some blues for the top of the fire. As we will see later on, the order
of colors is important. The palette should look like this:
____________________
|Color 0 | Black |
| .   |   |
| .   |   |
| .   |   |
|Color n1 | Blue |
| .   |   |
| .   |   |
| .   |   |
|Color n2 | Red |
| .   |   |
|Color n3 | Orange|
| .   |   |
|Color n4 | Yellow|
| .   |   |
|Color 255 | White |
|__________|_______|
The higher the color index is, the 'hotter' the pixel is. So at the bottom
of the fire everything is white, then it gradually decreases to black.
The trick is to have smooth color runs between the various colors at indexes
0, n1, n2, ... so that the whole thing looks smooth. And the key to smooth
color runs is: LINEAR INTERPOLATION. Remember this one if you haven't already
its one of those things that you will often need in programming (especially
graphics programming). If you already know what this is and are comfortable
with it, just skip a paragraph or two. Its a realy simple formula and
has an incredible number of applications. Here it goes:

Value = Start_Value + t * (End_Value - Start_Value)
where t varies from 0 to 1

Wow, read that over once or twice ;) The parameter t specifies the
position of the value you want to get between Start_Value and End_Value as a
fraction. For example, consider the linear run of numbers:
0,5,10,15,20,25, ...., 100
It is said to be linear because the numbers progress by addition (+5 each
time). Now, what is the number right in the middle of the sequence ?
Easy, with our formula we just write:

Number_in_the_middle = 0 + 0.5 * (100 - 0)
          = 50
And that's the correct answer of course! (write the whole thing out if you're
not sure ;))

Back to palettes and smooth color runs. We know that between color index 0
and 10 for example we want to have a smooth run of colors that goes from
black to blue. All we have to do to get those colors in between is:
Color = Black + t * (Blue - Black)
and since we want to do this from color index 0 to 10: t=i/10 where i is
the index of the color to generate. Colors of course have red, green and blue
components so the real calulation is:

t = i / 10
Color.Red = Black.Red + t * (Blue.Red - Black.Red)
Color.Green = Black.Green + t * (Blue.Green - Black.Green)
Color.Blue = Black.Blue + t * (Blue.Blue - Black.Blue)

The following C code will do the job for you:

void make_gradient (byte start_index, byte red_s, byte green_s,
          byte blue_s, byte end_index, byte red_e,
          byte green_e, byte blue_e)
{
 //Produces smooth gradients from RGB_start to RGB_end
 //(on the variable's names s = start and e = end
 unsigned char index;
 unsigned char max = (end_index - start_index);

 float red_inc, green_inc, blue_inc;

 //Set the two starting values
 set_color(start_index, red_s, green_s, blue_s);
 set_color(end_index, red_e, green_e, blue_e);
 //Compute the RGB increments
 red_inc = (red_e - red_s) / ((float) (max));
 green_inc = (green_e - green_s) / ((float) (max));
 blue_inc = (blue_e - blue_s) / ((float) (max));
 //Set middle colors
 for (index = 1; index < max; index++)
  set_color((start_index + index), (red_s + red_inc * index),
                  (green_s + green_inc * index),
                  (blue_s + blue_inc * index));
}

I assume that you can write the set_color function on your own.
Making a good palette will take a little tweaking, but this function
will make things easier.

Part II: I want to see some flames!

Ok, ok, here it comes ... Lets see how this cool effects is done:
There are several steps to the algorithm:
a) Generate the bottom of the fire (to keep it going)
B) Scroll the fire up
c) Smooth the colors as they move up
d) Display to the screen
We will need at least two arrays the same size of the screen (320x200).
a) The bottom line is filled randomly at various places with white (color
255). Now you will need a random number generator to do this.
At the time I wrote the program, I had no clue as to how to do that, and I
figured it required very complex mathematics. It turns out that it doesn't.
However I didn't know that at the time and I found an alternate solution.
I pregenerated a few random 'bottom line' for the fire and simply copied
them to the bottom line of the fire buffer at run time. That's not the best
way though. Here is a small bit of inline assembly that will generate a
pseudo-random number between 0 and n - 1:
(n should be smaller that 255 even though the parameter is an int)

int seed;
int fast_rand(int n)
{
 asm mov ax, seed
 asm add ax, 1234
 asm xor al, ah
 asm rol ah, l
 asm add ax, 4321
 asm ror al, 1
 asm xor ah, al
 asm mov seed, ax
 asm xor dx, dx
 asm mov cx, n
 asm div cx         ;Divide by n
 asm mov al, ah       ;Save remainder (which ranges from 0 - (n-1))
 asm xor ah, ah
;Return value is in _AX
}

There is no real logic behind this, the idea is just to mess with the value
in the seed variable enough so that it look random. You might want to fool
with that function yourself to make it smaller or whatever. I think you get
the idea.

b/c)This part of the algorithm is what makes the fire realy go. Lets call
our first offscreen buffer, page1 and the other page2. The trick to scroll
upwards is to read pixel (x, y) from page1 and to display it at (x, y-1)
on page2. (Note that special care must be taken not to go beyond the memory
limit of the buffer).
But simple upward scrolling is not what we need. We need to decrease the
pixel color as well. And to do this correctly we must smooth the value that
is being scrolled up. Instead of reading the pixel (x,y), we read the pixels
AROUND (x,y) and put an AVERAGE of those into (x,y-1) on page2. Having a
palette organized linearly helps with this since we don't have to worry
about the rbg values of the colors, we can just average their indexes and
it will look good :)
In order to make the averaging process simpler, we take the 4 or 8
surrounding pixels and use a shift to divide the result.
Thus:
page2(x,y-1)=(page1(x-1,y-1) + page1(x,y-1) + page1(x+1,y-1)
       page1(x-1,y ) +  0    + page1(x+1,y )
       page1(x-1,y+1) + page1(x,y+1) + page1(x+1,y+1)) >> 3;


d)Now that page2 contains a smoothed and moved up page1, we can just copy
it to the screen with our favorite 'rep movsd' intruction and swap around
page1 and page2 so we can repeat the process again. And that's it! You should
have a burning fire on your screen!


Part III: Higher Grounds
- Ok, I got all that, but how can I make this even better ?
There are several variations on this theme. Lets see briefly in theory what
they are.
The first possibility, which I have implemented, is based on a program by
Frank Paxti that I found a while ago on Hornet.org (which is closed now
unfortunately :_( ). The idea is to work on a per-pixel basis. When you move
a pixel up, you randomly displace its x coordinate by -1, 0, or 1. You also
decrease its color randomly based on a decay value. The fire is kept running
by copying to the bottom line a few random colored pixels which are
smoothed (only the bottom line that is) so that the fire will spread left and
right. This really looks real good. I'm not posting the source I've written
to my homepage because its basically a C translation of what that other guy
had done in pascal/asm, mail me (darki@multimania.com) if you desperately
want to have a look at it or browse the ruins of Hornet.org and see if you
can find the original still there...

Other ideas for a better fire effect would be to distort the bitmap with an
image warping algorithm on top of the rest, I don't know if this would really
look good and I haven't tried to implement it. Its up to you to see ...
You might also try to code this effect with high/true color video modes
(15,16,24 and 32bit). It would probably require a color table to emulate the
palette hardware ...

236
coding / Lens Effect.
« : 31.03.2004 06:36:07 »
ingilizce bir yazı; ama kolay anlaşılabilir.



Alıntı
This is some info on how one could implement a lens.
You should also have the file lens.gif, which contains some pictures to
clarify this text.
The first part is some stuff in general, the real explanation of the lens
transformation is in the second part.


How to implement the transformation
-----------------------------------

The main idea is: I want to transform a fraction of a picture.
Consider the smallest square possible, that contains all pixels affected by the
transformation. That is the 'blue' part of the picture.
I'm considering a precalculated transformation, so the dimensions of the
blue square are know (and constant). Therefore, I also know the total amount of
pixels involved in the transformation. Lets say NPI is a constant, representing
the 'N'umber of 'P'ixels 'I'nvolved. (That is the number of 'blue' pixels)
My program then requires 3 arrays: ORG[NPI], TFM[NPI] and DEST[NPI].

I first copy all 'blue' pixels to the array, called ORG.
[ Suppose the blue square is 10 by 10 pixel, than ORG[0..9] contain the   ]
[ value of the pixels on the first line, ORG[10..11] contain the value of  ]
[ the pixels on the second line, and so on...                ]
So ORG is an array with the original values of the pixels. The copying-routine
depends on the resolution (and the video mode) I'm working in.

I now want to transform the 'blue' picture, that is: I want to transform
the array ORG. For each pixel, I'm gonna determine its new value, and store it
in DEST. To know what its new value is, I use the third array TFM. This array
is a constant, and can therefore by calculated in advance. (You'll see how that
is done for the lens in the second part of this text)

This array says for each pixel: the pixel at position i in the result, should
be the same as the pixel at position TFM in the original.
[ So the formula is DEST = ORG[TMF] for all elements from 0 till NPI-1. ]
The transformation is fast, and does not depend on the resolution/video-mode.

We now copy the array DEST to the blue rectangle on the image, and the
transformation is complete.


If the transformed region is to be connect to the position of the mouse,
then every time the mouse is moved you have to:
1. Copy the original (array ORG) back to the old position,
2. Get the 'blue' region at the new position in the array ORG,
3. Do the transformation from ORG to DEST,
4. Copy the transformed region (DEST) onto the picture.


[ Here are some simple transformations:                   ]
[ ( suppose the blue region has dimensions dX by dY, thus NPI = dX*dY )   ]
[                                      ]
[ for i:=0 to dX*dY-1 do                          ]
[   TFM:=i;                              ]
[ Defines no change at all !                        ]
[ (that is: the transformed picture is the same as the original)      ]
[                                      ]
[ for i:=0 to dX*dY-1 do                          ]
[   TMF:=(dX*dY-1) -i;                         ]
[ This flips the original round both axis (X and Y)             ]
[                                      ]
[ for i:=0 to dY-1 do                            ]
[   for j:=0 to dX-1 do                          ]
[     TFM[i*dX+j] := i*dX + dX-1 - j;                  ]
[ This flips the original round the X-axis only               ]
[                                      ]
[ const M=2;                                ]
[ for i:=0 to dY-1 do                            ]
[   for j:=0 to dX-1 do                          ]
[     TFM[i*dX+j] := (i div M)*dX + (j div M);             ]
[ This magnifies the upper left corner by a factor of M           ]

[ Mind you:                                 ]
[ if you do the copying directly on the screen, you'll get some flickering. ]
[ One way to avoid that is using a virtual screen.             ]
[ That means you use an array, say VirtScr, wich represents the real screen. ]
[ You then perform all action where the screen is involed (loading the image,]
[ getting ORG and writing DEST) on the VirtScr, and than copy that VirtScr ]
[ on the real screen. However, that has 2 disadvantages:          ]
[ 1. You'll use more memory (for the VirtScr)                ]
[ 2. The result will be slower (because you have to copy the VirtScr to the ]
[  real screen)                              ]


How to make the lens transformation
-----------------------------------

Okay. So now the question is how to make the transformation array for the lens.
Consider a sphere S, intersecting with a plane à. This defines a circle C in
the plane. Define Rc as the ray of the circle C, Rs as the ray of the sphere S,
and d as the distance from the centre of the sphere to the plane à.
We know then that:
              Rcı + dı = Rsı     (1)

If you want several lenses with the same radius, but different lens-strength,
then you must preserve the same value for Rc. If the size of the transformed
area is L by L pixels (the lens is circular, so the involved area is a square)
then Rc should be «L. The distance d determines the strength of the lens.
So, knowing Rc and d, we can determine Rs.

Suppose we're given L (so Rc = «L), we made a choice for d, and we calculated
the value of Rs. We now want to transform each pixel in the square (LxL).
We simply check all pixels [2 loops: one for the X-axis and one for the Y-axis]
We call the point we're transforming p. If p lies outside or on C, then the
point isn't transformed. That is: TFM(p)=p; if (x,y) are the coordinates of
p than TFM[x+y*L] := x+y*L.

If p lies within the C, then the point will be transformed:
the effect should be as if all points within the circle were projected from
the centre of the sphere onto the sphere. Hence, for a given point p,
we determine the point q (see picture). That point q is the projection of some
point i within the circle C, so from the point q, we draw a line to the centre
of the sphere, thus defining the point i, which is the intersection of that
line whith the plane. That is the transformation of the point p: TFM(p)=i,
because: if the point i was to be projected on the sphere, it would end up at
the point q. Since we're looking straight onto the plane, the points q and p
are the same. (that is: they end up at the same point on your screen).



When implementing, you can use some shortcuts:
Lets say L and d are given. Then Rc=«L;
Consider the origin of a rectangular system in the centre of the circle C.
The X-axis and the Y-axis are parrallel to the plane à, in such a way that
the square that is to be transformed, is defined as:

         [-Rc,Rc] x [-Rc,Rc]

The orientation of the Z-axis is such that the coordinates of the centre of the
sphere are (0,0,-d). The sphere is given by:

        xı + yı + (z+d)ı = Rsı         (2)

hence: [ (1) ]

        xı + yı + (z+d)ı = Rcı + dı       (3)

Consider the point P within the circle C. Thus, its coordinates are:

     (Px,Py,0)  and   Pxı + Pyı < Rcı    (4)


The coordinates of the point Q can be found through this system:

    | x = Px      Â- defines the line, parrallel to the Z-axis
    | y = Py      Ù through the point P.
    | xı + yı + (z+d)ı = Rcı + dı

We immediatly find Qx and Qy (Qx=Px; Qy=Py), and for Qz we find:

    Pxı + Pyı + Qzı + 2*d*Qz + dı = Rcı + dı

    Qzı + 2*d*Qz - Rcı + Pxı + Pyı = 0

    D = dı - (Pxı + Pyı - Rcı)           (5)

    since Rcı > Pxı + Pyı  [ (4) ], we find D>0, and

    Qz = 1 ñ ûD.

We find 2 solutions (the line intersects the sphere twice !), but consider
only the one with Qz>0. We find coordinates for Q:

    (Qx,Qy,Qz) ğ (Px,Py,1+ûD)     (6)

Finally, we find the coordinates of the point I through :
[ (Sx,Sy,Sz) are the coordinates of the centre of the sphere ]
[ (Sx,Sy,Sz) ğ (0,0,-d)                   ]

    |   ( z - Sz)
    | x = --------- * (Qx-Sx) + Sx    ¿
    |   (Qz - Sz)           Ã defines the line through
    |                   ³ the centre of the sphere
    |   ( z - Sz)           ³ and the point Q
    | y = --------- * (Qy-Sy) + Sy    Ù
    |   (Qz - Sz)
    |
    | z = 0               -- defines the plane à

We find:

         ( 0 - (-d) )
     Ix = ------------ * (Qx-0) + 0
         ( Qz - (-d))

         ( 0 - (-d) )
     Iy = ------------ * (Qy-0) + 0
         ( Qz - (-d))

     Iz = 0


hence:        d
     Ix = --------- Qx
         Qz + d

           d
     Iy = --------- Qy
         Qz + d

     Iz = 0


We know the coordinates of Q (they can be fully determined if the coordinates
of P are known), and we know d, so I can be calculated.
We could than say:

  TFM[ («L+Px) + («L+Py) * L ] := («L+Ix) + («L+Iy) * L;

( Remember: Px,Py,Ix and Iy all are î [-Rc,Rc] and Rc ğ «L )

Now, you can see (by just observing the drawing, or by checking the formulas)
that if we find

  TFM[ p( Px, Py) ] = i( Ix, Iy)

then also

  TFM[ p( Px,-Py) ] = i( Ix,-Iy)
  TFM[ p(-Px, Py) ] = i(-Ix, Iy)
  TFM[ p(-Px,-Py) ] = i(-Ix,-Iy)

so that the entire transformation can be defined be calculating ¬ of the
transformed area.


Joey/SD

237
flash actionscript / Flash+php Ile Chat Server Olayı
« : 25.03.2004 00:04:06 »
php rutin:

Kod: [Seç]
#!/usr/local/bin/php -q

<?php 

set_time_limit 
(0); 
ob_implicit_flush (); 

define ('SOCKET_READ'1024); 
define ('LISTEN_QUEUE'10); 
define ('PORT'9999); 
define ('MAX_CLIENTS'30); 
define ('MAX_ROOMS'4); 

//--------------------------------------------- 

function room_join ($room

global 
$client$count$room$rooms$room_position
if (!isset (
$rooms)) 
 { 
 for (
$room_build_count 0$room_build_count MAX_ROOMS$room_build_count++) 
  
$rooms [$room_build_count] = array (); 
 } 
$room_size count ($rooms [$room]); 
if (
$room_size 4
 { 
 
array_push ($rooms [$room], $count); 
 
$room_position [$count] = array ($room$room_size); 
 
socket_write ($client [$count], &quot;You have joined room &quot; . $room . &quot;.&quot; . chr (0)); 
 
socket_write ($client [$count], $room . &quot;#&quot; . ($room_size + 1) . chr (0)); 
 

else 
 
socket_write ($client [$count], &quot;Room &quot; . $room . &quotis currently full.&quot; . chr (0)); 


//--------------------------------------------- 

function room_exit () 

global 
$client$count$rooms$room_position
array_splice ($rooms [$room_position [$count] [0]], $room_position [$count] [1], 1); 
socket_write ($client [$count], &quot;You have left room &quot; . $room_position [$count] [0] . &quot;.&quot; . chr (0)); 
$room_position [$count] = null


//--------------------------------------------- 

function kill_server () 

global 
$listenfd$client
for (
$count 0$count MAX_CLIENTS$count++) 
 { 
 if (
$client [$count] != null
  { 
  
socket_write ($client [$count], &quot;Server disconnected!&quot; . chr (0)); 
  
socket_close ($client [$count]); 
  } 
 } 
socket_close ($listenfd); 
exit; 


//--------------------------------------------- 

function close_client ($count

global 
$client$usernames$remote_host$remote_port
if (isset (
$rooms)) 
 
room_exit (); 
for (
$broadcast_count 0$broadcast_count <= MAX_CLIENTS$broadcast_count++) 
 { 
 if (
$broadcast_count == $count
  
socket_write ($client [$count], &quot; <font color=&quot;#CC0000&quot;>You have disconnected.</font>&quot; . chr (0)); 
 
else if ($client [$broadcast_count] != null
  
socket_write ($client [$broadcast_count], &quot; <font color=&quot;#CC0000&quot;>&quot; . $usernames [$count] . &quot; has disconnected.</font>&quot; . chr (0)); 
 

socket_close ($client [$count]); 
$client [$count] = null
unset (
$remote_host [$count]); 
$client_still_connected false
for (
$count 0$count <= MAX_CLIENTS$count++) 
 { 
 if (
$client [$count] != null
  { 
  
$client_still_connected true
  break; 
  } 
 } 
if (
$client_still_connected == false
 
kill_server (); 


//--------------------------------------------- 

$listenfd socket_create (AF_INETSOCK_STREAM0); 
if (
$listenfd
 print &
quot;Listening on port &quot; . PORT . &quot;
&
quot;; 
else 
 { 
 
socket_write ($client [$count], &quot;Socket died!&quot; . chr (0)); 
 die (&
quot;Socket died!
&
quot;); 
 } 
socket_setopt ($listenfdSOL_SOCKETSO_REUSEADDR0); 
if (!
socket_bind ($listenfd, &quot;127.0.0.1&quot;, PORT)) 
 { 
 
socket_close ($listenfd); 
 die (&
quot;Could not bind!
&
quot;); 
 } 
socket_listen ($listenfdLISTEN_QUEUE); 
for (
$count 0$count MAX_CLIENTS$count++) 
 
$client [$count] = null
while (
1
 { 
 
$rfds [0] = $listenfd
  { 
  for (
$count 0$count <= MAX_CLIENTS$count++) 
   if (
$client [$count] != null
    
$rfds [$count 1] = $client [$count]; 
  } 
 
$nready socket_select ($rfds$null$nullnull); 
 if (
in_array ($listenfd$rfds)) 
  { 
  for (
$count 0$count <= MAX_CLIENTS$count++) 
   { 
   if (
$client [$count] == null
    { 
    
$client [$count] = socket_accept ($listenfd); 
    
socket_setopt ($client [$count], SOL_SOCKETSO_REUSEADDR0); 
    
socket_getpeername ($client [$count], $remote_host [$count], $remote_port [$count]); 
    if (
$count MAX_CLIENTS
     { 
     break; 
     } 
    } 
   if (
$count >= MAX_CLIENTS
    { 
    
close_client ($count); 
    break; 
    } 
   } 
  if (--
$nready <= 0
   continue; 
  } 
 for (
$count 0$count <= MAX_CLIENTS$count++) 
  { 
  if (
$client [$count] == null
   continue; 
  if (
in_array ($client [$count], $rfds)) 
   { 
   
$incoming_data trim (socket_read ($client [$count], SOCKET_READ)); 
   if (!
$incoming_data
    
close_client ($count); 
   else 
    { 
    if (
substr ($incoming_data01) == &quot;#&quot;) 
     

     
$call_function explode (&quot;#&quot;, $incoming_data); 
     
if ($call_function [1] == &quot;client_number&quot;) 
      
socket_write ($client [$count], $count chr (0)); 
     else if (
$call_function [1] == &quot;username&quot;) 
      { 
      
$usernames [$count] = $call_function [2]; 
      for (
$broadcast_count 0$broadcast_count <= MAX_CLIENTS$broadcast_count++) 
       { 
       if ((
$client [$broadcast_count] != null) && ($broadcast_count != $count)) 
        
socket_write ($client [$broadcast_count], &quot; <font color=&quot;#CC0000&quot;>&quot; . $usernames [$count] . &quot; has connected.</font>&quot; . chr (0)); 
       

      } 
     else if (
$call_function [1] == &quot;room_join&quot;) 
      { 
      
$room $call_function [2]; 
      
room_join ($room); 
      } 
     else if (
$call_function [1] == &quot;room_exit&quot;) 
      
room_exit (); 
     else if (
$call_function [1] == &quot;close_client&quot;) 
      
close_client ($count); 
     else if (
$call_function [1] == &quot;kill_server&quot;) 
      
kill_server (); 
     } 
    else 
     { 
     for (
$broadcast_count 0$broadcast_count <= MAX_CLIENTS$broadcast_count++) 
      { 
      if (
$broadcast_count == $count
       
socket_write ($client [$count], &quot;<font color=&quot;#999999&quot;>You said: &quot; . $incoming_data . chr (0)); 
      
else if ($client [$broadcast_count] != null
       
socket_write ($client [$broadcast_count], $usernames [$count] . &quot;: &quot; . $incoming_data chr (0)); 
      } 
     } 
    } 
   if (--
$nready <= 0
    break; 
   } 
  } 
 } 
?>


flash kısmı için de test_chat.fla dosyasını çekin.

238
php / Php Socket Server
« : 24.03.2004 23:33:07 »
Flash'da socket server kullananlar için PHP'de simple sockserver; PHP 4.1+ olmalı ve SafeMode kapalı olmalı. Script timeout'u da 0 yaparak script'in 30 saniyede timeout olmamasına dikkat edin. Script bir client'ın yazdığı herşeyi diğer client'lara echo eder; /quit ise server'ı sonlandırır.

Kod: [Seç]
#!/usr/local/bin/php -q
<?php
//setting this to 0 lets scriphang around for ever
set_time_limit(0);



// defaults...

define('MAXLINE'1024); // how much to read from a socket at a time
define('LISTENQ'5); // listening queue
define('PORT'10000); // the default port to run on
define('FD_SETSIZE'2); // file descriptor set size (max number of concurrent clients)...


// for kill the server

function killDaemon()
{
global 
$listenfd$client;
$msg = &quot;Daemon going down!
&
quot;;
for (
$i 0$i FD_SETSIZE$i++)
{
if (
$client[$i] != null)
{
socket_write($client[$i], $msgstrlen($msg));
socket_close($client[$i]);
}


}
print &
quot;Shutting down the daemon
&quot;;
socket_close($listenfd);
exit;
}


// whenever a client disconnects...

function closeClient($i)
{
global 
$client$remote_host$remote_port;

print &
quot;closing client[$i] ({$remote_host[$i]}:{$remote_port[$i]})
&
quot;;

socket_close($client[$i]);
$client[$i] = null;
unset(
$remote_host[$i]);


//check to see if anyone is still attached, this will shutdown the 
//remove down from here if you want to remove this option
serverremove if unwanted
$someoneconnected 
false;
for (
$i 0$i <= FD_SETSIZE$i++){
if(
$client[$i] != null){
$someoneconnected true;
break;
}
}

if(
$someoneconnected == false){
killDaemon();
}
//stop removing here, for the auto shutdown feature

}


// set up the file descriptors and sockets...

// $listenfd only listens for a connection, it doesn't handle anything
// but initial connections, after which the $client array takes over...

$listenfd socket_create(AF_INETSOCK_STREAM0);
if (
$listenfd)
print &
quot;Listening on port &quot; . PORT . &quot;
&
quot;;
else
die(&
quot;AIEE -- socket died!
&
quot;);

//set servers ip here, leave if using a local host
//socket_setopt($listenfd, SOL_SOCKET, SO_REUSEADDR, 1); - old

socket_setopt($listenfdSOL_SOCKETSO_REUSEADDR0); 
if (!
socket_bind($listenfd, &quot;0.0.0.0&quot;, PORT))
{
socket_close($listenfd);
die(&
quot;AIEE -- Couldn't bind!
&quot;);
}
socket_listen($listenfd, LISTENQ);


// set up our clients. After listenfd receives a connection,
// the connection is handed off to a $client[]. $maxi is the
// set to the highest client being used, which is somewhat
// unnecessary, but it saves us from checking each and every client
// if only, say, the first two are being used.


//for ($i = 0; $i < FD_SETSIZE; $i++) - old

//$client[$i] = null;

//allow spaces for extra users, that will be automatically closed
for ($i = 0; $i < LISTENQ; $i++)
$client[$i] = null;



// the main loop.

while(1)
{
$rfds[0] = $listenfd;

//for ($i = 0; $i < FD_SETSIZE; $i++) - old
{
for ($i = 0; $i <= FD_SETSIZE; $i++)
if ($client[$i] != null)
$rfds[$i + 1] = $client[$i];
}


// block indefinitely until we receive a connection...

$nready = socket_select($rfds, $null, $null, null);


// if we have a new connection, stick it in the $client array,

if (in_array($listenfd, $rfds))
{
print &quot;listenfd heard something, setting up new client
&quot;;

//for ($i = 0; $i < FD_SETSIZE; $i++) - old
for ($i = 0; $i <= FD_SETSIZE; $i++) //pick up the new spot
{
if ($client[$i] == null)
{
$client[$i] = socket_accept($listenfd);
//socket_setopt($client[$i], SOL_SOCKET, SO_REUSEADDR, 1); - old

socket_setopt($client[$i], SOL_SOCKET, SO_REUSEADDR, 0);
socket_getpeername($client[$i], $remote_host[$i], $remote_port[$i]);
print &quot;Accepted {$remote_host[$i]}:{$remote_port[$i]} as client[$i]
&quot;;

// continue the server if connection allowed else allow next step
if ($i < FD_SETSIZE)
{
break;
}

}

if ($i >= FD_SETSIZE)
{
//trigger_error(&quot;too many clients&quot;, E_USER_ERROR);
//exit;
//or close the new socket, 
closeClient($i);
break;// continue the server
}

}

if (--$nready <= 0)
continue;
}


// check the clients for incoming data.

for ($i = 0; $i <= FD_SETSIZE; $i++)
{
if ($client[$i] == null)
continue;

if (in_array($client[$i], $rfds))
{
$n = trim(socket_read($client[$i], MAXLINE));

if (!$n)
closeClient($i);
else
{
// if a client has sent some data, do one of these:

if ($n == &quot;/killme&quot;)
killDaemon();
else if ($n == &quot;/quit&quot;)
closeClient($i);
else
{
// print something on the server, then echo the incoming
// data to all of the clients in the $client array.
//$n is incoming data

print &quot;From {$remote_host[$i]}:{$remote_port[$i]},>client[$i]: $n
&quot;;
for ($j = 0; $j <= FD_SETSIZE; $j++)
{
if ($client[$j] != null)
socket_write($client[$j], &quot;From client[$i]: $n&quot;.chr(0));
//the chr(0) send the nul character required by flash
}
}
}

if (--$nready <= 0)
break;
}
}
}

?>


bu da Flash'dan sockservera teorik bağlantı yapısı:
xml.fla adresinde de çalışan bir örnek bulunuyor.  B)

Kod: [Seç]
on (release) {
_root.mysocket = new XMLSocket();


_root.mysocket.connect(_root.ip, _root.port);
//makes connections

_root.mysocket.onConnect = function(success) {
//on a result
if (success) {- if succedded
_root.status = "Connected";
} else {
_root.status = "Failed";
}
};

_root.mysocket.onClose = function(success) {
//when the connection is closed or lost
_root.status = "Closed";
};


_root.mysocket.onXML = xmlhandler;
//when data is received run this function
function xmlhandler(doc) {
_root.status = "data Recieved";
loadedvars = String(doc);
_root.datain+=loadedvars+" ";

}
}

239
flash actionscript / Flash<->php Data Takası
« : 24.03.2004 20:29:20 »
Flash'te ilk frame'e şu kod geliyor:

Kod: [Seç]
loader = new LoadVars();
loader.onLoad = function(success) {
        if(success){
                trace(&quot;loaded results&quot;);
                trace(loader.msg);
        }
};
sender = new LoadVars();
sender.page = &quot;3&quot;;
sender.sendAndLoad(&quot;http://127.0.0.1/decoded/pinpon.php&quot;,loader,POST);

PHP'de de karşılayacak kod (swf ile aynı domain altına pinpon.php ismiyle kaydedilmeli):
Kod: [Seç]
header('Expires: Jan 01, 2001 00:00 GMT');
header("Cache-control: no-cache");
header("Pragma: no-cache");
$page=$_POST["page"];
if($page=="3")echo("msg=got it...");
?>

tabii domain uygun girilmeli. swf'nin bulunduğu domain'de durmalı php de...

crossdomain için serverdaki php/asp kod gidip diğer domain'den bilgiyi çekebilir. ya da loadvars yerine loadxml fonkisyonu kullanılarak crossdomain xml dosyasında da aşağıdaki ek ile bu gerçekleştirilebilir:
Kod: [Seç]



 
 
 

240
geyik / Pixel Art
« : 23.03.2004 02:44:59 »

Sayfa: 1 ... 14 15 [16] 17