hi all,
it is a demonstration of shifting texture (not scrolling).
original post:
http://forum.thegamecreators.com/?m=forum_view&t=63506&b=1
Challenge one:
lock cli
Rem Project: ShadowPlaneIdea
Rem Created: 24/10/2005 18:14:11
rem Technique: use collision polygon data
rem to construct shadow meshes under a single
rem object casting a shadow, then apply a
rem shadow texture then modify the UV data
rem with clamp so it only appears under the
rem origin object. The mesh only needs refreshing
rem if the origin object moves to include/exclude
rem meshes, otherwise just the UV data is changed
rem synchro
set window on
sync on
` *=---------------------------------------------------------------------=*
`
`Init FUNCTIONS for vertexdata manipulation
dim sf_currentmemblockmesh(0)
`
` *=---------------------------------------------------------------------=*
rem shadow texture
cls rgb(0,0,0)
ink rgb(64,64,64),0
box 3,3,13,13
blur bitmap 0,2
get image 1,0,0,16,16
ink rgb(255,255,255),0
rem Create the scene mesh
gosub _make_scene
rem view
sync rate 60 : autocam off
position camera 10,0,-30 : point camera 10,0,0
do
`
rem prompt
set cursor 0,16
print "L E E S C H A L L E N G E"
print
if chall=0
print "This program uses a constructed mesh, a shadow texture and UV manipulation"
print "commands to create a shadow using the X# and Y# values (mouse position)."
print
print "LEFT MOUSE BUTTON resizes the shadow dynamically"
print "Press SPACE to view the challenge"
if spacekey()=1 then chall=1 : gosub _make_scene
endif
if chall=1
print "I want to use this technique even if the individual polygons have been"
print "rotated and are of non-uniform size and shape (as shown below)."
print "The challenge is to only change the UV calculations code, leaving the"
print "rest of the program as it stands. Polygon data in, new UV data out."
endif
`
rem get origin pos
remstart
334 pixels pour 5 tiles, donc 1 tiles=67 pixels, et donc 1/2 tiles=33 pixels
centre du premier tile= 187,240
5 tiles de largeur '5' = 25 de largeur totale
334/25=13.36
154=187-33
207=240-33
remend
x#=(mousex()-154)/13.36
y#=(207-mousey())/13.36
`
rem tweak shadow size
if mouseclick()=1 then size#=2 else size#=1
`
rem For all polygons
for m=0 to lmmax-1
`
rem which poly
mo=m*4
`
rem get poly start corner
x1#=get vertexdata position x(mo+1)
y1#=get vertexdata position y(mo+1)
x2#=get vertexdata position x(mo+2)
y2#=get vertexdata position y(mo+2)
`
rem get size of polygon plate (works for 2D U=X and V=Y)
dimx#=abs(x2#-x1#) : dimy#=abs(y2#-y1#)
`
rem relative difference between poly-start-corner and origin position
relx#=x1#-x# : rely#=y#-y1#
`
rem work out shift in UV based on origin pos and shadow size
shiftx#=(relx#/dimx#)*size#
shifty#=(rely#/dimy#)*size#
`
rem work out the UV for this polygon given location of x# and y#
u1#=0 : v1#=0 : u2#=size# : v2#=size#
u1#=(u1#+shiftx#)
u2#=(u2#+shiftx#)
v1#=(v1#+shifty#)
v2#=(v2#+shifty#)
`
rem update the UV of this poly
set vertexdata uv(mo+0,u1#,v2#)
set vertexdata uv(mo+1,u2#,v2#)
set vertexdata uv(mo+2,u1#,v1#)
set vertexdata uv(mo+3,u2#,v1#)
`
rem Next polygon
next m
`
`refresh mesh
change mesh from memblock 1,100
change mesh 1,0,1
`
rem update screen
sync
`
rem End loop
loop
end
rem This makes the mesh and textures it
_make_scene:
`plain info:
` VERTEX ORDER:
` 0,3,1
` 3,0,2
`
` 2---3
` | /|
` | / |
` |/ |
` 0---1
`
`
` TEXTURE COORDINATE :
` 0,0---1,0
` | |
` 0,1---1,1
`
`
`SCENE MESH:
` object 11:
` 9 10 11 12
`0 5 6 7 8
` 1 2 3 4
if object exist(11)=1 then delete object 11
make object plain 11,5,5
rotate limb 11,0,0,0,0
make mesh from object 11,11
delete object 11
make object 11,11,0
lm=1
for h=-1 to 1
for x=1 to 4
add limb 11,lm,11
if chall=0
offset limb 11,lm,x*5,h*5,0
else
rem The challenge is the code can rotate the polygons within the mesh, and the
rem technique still works by adjusting the UV data to take account of polygon
rem orientation, size and shape.
offset limb 11,lm,x*6,h*7,0
rotate limb 11,lm,0,0,rnd(359)
scale limb 11,lm,100+(lm*10),100-(lm*5),100+(rnd(5)*10)
endif
inc lm
next x
next h
lmmax=lm
delete mesh 11
position object 11,0,0,0
`SET OBJECT Numéro d'Objet, solide, opaque, face cachée, filtrage, lumière, brouillard, ambiance
set object 11, 0, 1, 0, 1, 0, 1, 1
`object 1(shadow):
rem collect meshes
if object exist(1)=1 then delete object 1
rotate limb 11,0,0,0,0
make mesh from object 1,11
make object 1,1,0
`we will need the mesh number 1 later, so we do not delete
rotate object 1,0,0,0
position object 1,0,0,-0.01
set object texture 1,2,0
`SET OBJECT Numéro d'Objet, solide, opaque, face cachée, filtrage, lumière, brouillard, ambiance
set object 1, 1, 0, 0, 1, 1, 1, 1
rem apply shape texture to mesh for shadow
texture object 1,1
rem create memblock object, for vertex manipulation
if memblock exist(100) then delete memblock 100
make memblock from mesh 100,1
set current memblockmesh(100)
return
end
`FUNCTIONS ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function set current memblockmesh(mem)
sf_currentmemblockmesh(0)=mem
endfunction
function GET VERTEXDATA POSITION X(vertex_number)
mem=sf_currentmemblockmesh(0)
offset=32
result#=memblock float(mem,offset+(12*vertex_number))
endfunction result#
function GET VERTEXDATA POSITION Y(vertex_number)
mem=sf_currentmemblockmesh(0)
offset=36
result#=memblock float(mem,offset+(12*vertex_number))
endfunction result#
function SET VERTEXDATA UV(vertex_number, U#, V#)
mem=sf_currentmemblockmesh(0)
offsetU=memblock dword(mem,28)
offsetV=memblock dword(mem,28)+4
write memblock float mem,offsetU+(8*vertex_number),U#
write memblock float mem,offsetV+(8*vertex_number),V#
endfunction
Now, I will try to convert the challenge number two, it will be more complicated!
EDIT : fixed an error that reversed the texture data + add comment(plain structure)
@+
DirectX 9.0c (February 2010)/ DBClassic v1.20