News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Strip Scene Support

Started by kevin, August 02, 2005, 01:10:14 AM

Previous topic - Next topic

kevin

This demo is just hacked together from some other examples.  The main difference is that this version is Z buffered through the camera/scene.  This means that objects (well strips now) can be drawn in any order and the camera will sort scene for the user.

 Supports Gouraud & Textured Strips

kevin

#1
PlayBASIC Code: [Select]
   Constant RopeEdges=3
Dim WaveRippleAngle#(3)

Type RopeVerts
X1#,X2#, rgb1,rgb2
endtype

Dim RopeSegs(Ropeedges) as Ropeverts

createcamera 1
cameraclscolour 1,rgb(60,20,10)


Do
CaptureToscene
ClsScene

CircleRing()

capturedepth 500
DrawRope()

capturedepth 500
Sinus()


drawcamera 1


Sync
loop


Function CircleRing()
Static Baseangle#

; get the Screen width and height
sw=getScreenWidth()
sh=getScreenHeight()

; Draw a group of depth sorted circles, these circles will rotate
; and be drawn in order to the viewer
Number_Of_Circles=30
For lp=0 to Number_Of_Circles
; Calc angle and positon to draw this cricle at
angle#=wrapangle(baseangle#,(lp*(360/Number_of_Circles)))
X=Cos(angle#)*300
y=sin(angle#)*150
Z=500+(Sin(angle#)*300)
pr=(170*128)/Z
; Set the Current Depth.
Capturedepth Z

; Draw this filled circle (which will be capture to the scene buffer)
circlec (sw/2)+X,(getscreenheight()/3)-y,pr,1,rgbfade($ff8f8f,16384/z)

next

; Change and wrap the BaseAngle variable to a value between 0 and 360
BaseAngle#=wrapangle(BaseAngle#,1)
EndFunction





Function DrawRope()
radius=75
ScreenHeight=GetScreenHeight()

basex=GetScreenwidth()/2

WaveAngle#= WaveRippleAngle#(1)
WaveAngle2#= WaveRippleAngle#(2)
WaveAngle3#= WaveRippleAngle#(3)

WaveRippleAngle#(1)=wrapangle(WaveAngle#,0.7)
WaveRippleAngle#(2)=wrapangle(WaveAngle2#,1.2)
WaveRippleAngle#(3)=wrapangle(WaveAngle3#,2.1)

r=175
g=40
b=30

EdgeAngleStep#=360.0/(RopeEdges)

BaseZ=500


Segments=0
static BaseAngle#
For lp=0 To RopeEdges
Angle#=BaseAngle#+(EdgeAngleStep#*lp)
Angle2#=Angle#+EdgeAngleStep#

X1#=Cosradius(angle#,Radius)
X2#=CosRadius(angle2#,Radius)
Z1#=basez+SinRadius(angle#,Radius)
Z2#=basez+SinRadius(angle2#,Radius)

Px1#=((X1#*500)/z1#)
Px2#=((X2#*500)/z2#)

If pX1#<pX2#
R1=(R*400)/z1#
G1=(G*400)/z1#
B1=(B*400)/z1#

R2=(R*400)/z2#
G2=(G*400)/z2#
B2=(B*400)/z2#

RopeSegs(Segments).x1=px1#
RopeSegs(Segments).x2=px2#
RopeSegs(Segments).rgb1=rgb(r1,g1,b1)
RopeSegs(Segments).rgb2=rgb(r2,g2,b2)
inc segments
EndIf
Next

dec segments

For ThisScanLine=0 To ScreenHeight-1
Xoffset=basex+Sinradius(wAVEangle#,50)
Xoffset=Xoffset+cosradius(wAVEangle2#+wAVEangle#,80)
Xoffset=Xoffset+cosradius(wAVEangle3#,90)

For lp=0 to Segments
x1=Xoffset+RopeSegs(lp).x1
x2=Xoffset+RopeSegs(lp).x2
if x1<x2
GouraudStripH x1,RopeSegs(lp).rgb1,x2,RopeSegs(lp).rgb2,ThisScanline
endif
next
waveangle#= waveangle#+0.5
waveangle2#= waveangle2#+0.15
waveangle3#= waveangle3#+0.73
Next

inc BaseAngle#
EndFunction






Login required to view complete source code