Challenge:
Version:
Bumpmapped Waves
Winner?:
No
Code Snippet:
sync on sync rate 0 color backdrop 0 backdrop on randomize timer() `Wave settings #constant WAVE_HEIGHT 4.0 null = make vector3(1) null = make vector3(2) set vector3 2, 1.0, 1.0, 1.0 #constant wS 128 make memblock 1, 12 + (wS * wS * 4) write memblock dword 1, 0, wS write memblock dword 1, 4, wS write memblock dword 1, 8, 32 make object plain 1, 5, 5 setMemblockData(1) make image from memblock 1, 1 make memblock 2, 12 + (32 * 32 * 4) write memblock dword 2, 0, 32 write memblock dword 2, 4, 32 write memblock dword 2, 8, 32 for i = 12 to (32*32*4) step 4 : write memblock dword 2, i, rgb(128, 128, 255 - rnd(64)) : next i make image from memblock 2, 2 delete memblock 2 texture object 1, 2 position object 1, 0, 0, 0 point object 1, 0, 1, 0 set ambient light 50 a# = 160.0 d# = 17.5 positionCamera(a#, d#) t_a# = 160.0 t_d# = 7.5 bm = 1 set bump mapping on 1, 1 frameTime# = 1.0 startTime = timer() do frameTime# = (frameTime# * 0.8) + ((timer() - startTime) * 0.2) startTime = timer() text 0, 0, "angle: " + str$(a#) mX = mousemovex() mY = mousemovey() mZ = mousemovez() c = 0 if mX <> 0 then inc t_a#, mX * frameTime# * 0.1 : c = 1 if mY <> 0 then inc t_d#, mY * frameTime# * 0.01 : c = 1 a# = curvevalue(t_a#, a#, 500.0 / frameTime#) d# = curvevalue(t_d#, d#, 500.0 / frameTime#) positionCamera(a#, d#) setMemblockData(1) make image from memblock 1, 1 sync loop function positionCamera(a#, d#) position camera d# * sin(a#), d#, d# * cos(a#) point camera 0, 0, 0 d# = d# * 5.0 set point light 0, 20,20,20 endfunction function setMemblockData(mb) t# = timer() * -0.360 `text 200, 10, "T: " + str$(t#) for x = 0 to wS-1 hX# = x - (wS * 0.5) for z = 0 to wS-1 hZ# = z - (wS * 0.5) createNormal(1, heightFunction(hX#, hZ#, t#), heightFunction(hX#, hZ#-1, t#), heightFunction(hX#+1, hZ#, t#), heightFunction(hX#, hZ#+1, t#), heightFunction(hX#-1, hZ#, t#)) normalize vector3 1, 1 add vector3 1, 1, 2 multiply vector3 1, 127 write memblock dword 1, 12 + (x + (z * wS)) * 4, rgb(x vector3(1), y vector3(1), z vector3(1)) next z next x endfunction function heightFunction(x#, z#, t#) h# = 1.0 * sin(32 * sqrt(x#*x# + z#*z#) + t#) endfunction h# function createNormal(v, hMiddle#, hUp#, hRight#, hDown#, hLeft#) set vector3 v, hLeft#-hRight#, 1.0, hUp#-hDown# endfunction