News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Grassy Feild Depth trick

Started by Draco9898, July 17, 2005, 08:48:19 AM

Previous topic - Next topic

Draco9898

Here's an interesting trick I tried to make, basically I'm trying to make a Mode-7 type of thing, but it's hard seeing as how quads have no real depth and there's not a way to scroll the texture inside the quads using UV's (At least when I tried the texture got all stetchy, heh), So I cheated and scrolled the image itself...(Makes it REEEAL slow of course, but that's OK)
I wanted to make it so the Quads were rended in a way to where you could just manipulate the points to make it look like to had depth AND it was moving towards you AND was rotating, but ummm yeah the math fries my brain...
Part of the problem with trying to draw say, a level map for a racing game (Super mario Kart style) to a quad is the map would be a really big texture AND you'd need to convert it every loop X_X


I wanted to make something like this:
(login required)

Media-less Version:
PlayBASIC Code: [Select]
Global ScreenW#=512: Global ScreenH#=384
OpenScreen ScreenW#,ScreenH#,16,2
SetFPS 60

`Landscape Grass Image
Dim GrassImg(1): GrassImg(1)=GetFreeImage()
CreateImage GrassImg(1),128,128: RenderToImage GrassImg(1)
For X=1 To 128
For Y=1 To 128
DotC X,Y,RGB(0,Rnd(255)+1, 0)
Next Y
Next X
RenderToScreen
PrepareFXImage GrassImg(1)
`Create Landscape using Quads
YQuads=6
Type tQuads
x1,y1,x2,y2,x3,y3,x4,y4
EndType
Dim Quads(7*YQuads) As tQuads
For X=1 To 7
For Y=1 To YQuads
NQ=NQ+1
AddX#=(120*(X-1)): AddY#=7: AddY2#=12+((Y*3)*Y)
If Y=1
Quads(NQ).x1=0+AddX#: Quads(NQ).y1=120
Quads(NQ).x2=120+AddX#: Quads(NQ).y2=120
Quads(NQ).x3=120+AddX#: Quads(NQ).y3=120+AddY#
Quads(NQ).x4=0+AddX#: Quads(NQ).y4=120+AddY#
Else
Quads(NQ).x1=0+AddX#: Quads(NQ).y1=Quads(NQ-1).y4
Quads(NQ).x2=120+AddX#: Quads(NQ).y2=Quads(NQ-1).y3
Quads(NQ).x3=120+AddX#: Quads(NQ).y3=Quads(NQ).y2+AddY2#
Quads(NQ).x4=0+AddX#: Quads(NQ).y4=Quads(NQ).y1+AddY2#
EndIf
Next Y
Next X


Do
Cls RGB(108, 159, 221)
Text 10,10,FPS()
LockBuffer
; create variables to hold the UV coords for out texture mapper
; U1/v1 = top left cord on texture
u1=0: v1=0
; U2/v2 = top left cord On texture
u2=128: v2=0
; U3/v3 = top left cord On texture
u3=128: v3=128
; U4/v4 = top left cord On texture
u4=0: v4=128
ScrollImage GrassImg(1),0,2
PrepareFXImage GrassImg(1)
DrawImage GrassImg(1),122,10,1
For X=1 To (7*YQuads)
TextureQuad GrassImg(1),Quads(X).x1,Quads(X).y1,u1,v1,Quads(X).x2,Quads(X).y2,u2,v2,Quads(X).x3,Quads(X).y3,u3,v3,Quads(X).x4,Quads(X).y4,u4,v4
Next X
UnLockBuffer


Sync
Loop





Needs texture Version:
PlayBASIC Code: [Select]
Global ScreenW#=512: Global ScreenH#=384
OpenScreen ScreenW#,ScreenH#,16,2
SetFPS 60

`Landscape Grass Image
Dim GrassImg(1): GrassImg(1)=GetFreeImage()
LoadImage "Grass1.png",GrassImg(1): PrepareFXImage GrassImg(1)
`Create Landscape using Quads
YQuads=6
Type tQuads
x1,y1,x2,y2,x3,y3,x4,y4
EndType
Dim Quads(7*YQuads) As tQuads
For X=1 To 7
For Y=1 To YQuads
NQ=NQ+1
AddX#=(120*(X-1)): AddY#=7: AddY2#=12+((Y*3)*Y)
If Y=1
Quads(NQ).x1=0+AddX#: Quads(NQ).y1=120
Quads(NQ).x2=120+AddX#: Quads(NQ).y2=120
Quads(NQ).x3=120+AddX#: Quads(NQ).y3=120+AddY#
Quads(NQ).x4=0+AddX#: Quads(NQ).y4=120+AddY#
Else
Quads(NQ).x1=0+AddX#: Quads(NQ).y1=Quads(NQ-1).y4
Quads(NQ).x2=120+AddX#: Quads(NQ).y2=Quads(NQ-1).y3
Quads(NQ).x3=120+AddX#: Quads(NQ).y3=Quads(NQ).y2+AddY2#
Quads(NQ).x4=0+AddX#: Quads(NQ).y4=Quads(NQ).y1+AddY2#
EndIf
Next Y
Next X


Do
Cls RGB(108, 159, 221)
Text 10,10,FPS()
LockBuffer
; create variables to hold the UV coords for out texture mapper
; U1/v1 = top left cord on texture
u1=0: v1=0
; U2/v2 = top left cord On texture
u2=128: v2=0
; U3/v3 = top left cord On texture
u3=128: v3=128
; U4/v4 = top left cord On texture
u4=0: v4=128
ScrollImage GrassImg(1),0,2
PrepareFXImage GrassImg(1)
DrawImage GrassImg(1),122,10,1
For X=1 To (7*YQuads)
TextureQuad GrassImg(1),Quads(X).x1,Quads(X).y1,u1,v1,Quads(X).x2,Quads(X).y2,u2,v2,Quads(X).x3,Quads(X).y3,u3,v3,Quads(X).x4,Quads(X).y4,u4,v4
Next X
UnLockBuffer


Sync
Loop



And you need my texture here:
DualCore Intel Core 2 processor @ 2.3 ghz, Geforce 8600 GT (latest forceware drivers), 2 gigs of ram, WIN XP home edition sp2, FireFox 2.

"You'll no doubt be horrified to discover that PlayBasic is a Programming Language." -Kevin

kevin

#1
rather than scroll the texture, build a pre-mirroed version then UV map it.


To do a Mode7 effect, you should use TextureStrip and project the floor coords accordingly.    



PlayBASIC Code: [Select]
Circle 15,15,16,1
Getimage 1,0,0,31,31
i=ExpandImage(1)
drawimage i,100,100,0
sync
waitkey




Function ExpandImage(ThisImage)
OldSurface=GetSurface()
W=getImageWidth(ThisImage)
H=getimageheight(ThisImage)
NewImage=GetFreeImage()
CreateImage NewImage,w*2,h*2
RenderToImage NewIMage
DrawImage ThisImage,0,0,0
DrawImage ThisImage,w,0,0
DrawImage ThisImage,0,h,0
DrawImage ThisImage,w,h,0
RendertoIMage OldSurface
EndFunction NewImage






Draco9898

#2
Oh yummy, thanks Kevin  :)

But one thing is it seems how large TextureStrip is on the screen depends on the image size and I can't figure out a way to transform it to give it depth and fill almost the entire screen from the left side to the right side... :huh: I tried using a huge image, but the framerate goes down the hole (As one might expect...)

I'm trying to do a world map type of thing like on final fantasy 5 or 6..or any of those old SNES RPGS where they just draw the maps tiles on the screen as a mode 7 effect and make it appear to have depth...
DualCore Intel Core 2 processor @ 2.3 ghz, Geforce 8600 GT (latest forceware drivers), 2 gigs of ram, WIN XP home edition sp2, FireFox 2.

"You'll no doubt be horrified to discover that PlayBasic is a Programming Language." -Kevin