Perspective Sprites
The following pic's are an extension of the previous entity demos, but this time the sprites are rotating in 3D (XYZ) and being projected and rendered in perspective.
What Are Sprite Entities ?
load3Dimage "animal.jpg",1
load3Dimage "particle_white.bmp",2
CreateSprite 1
positionspritexyz 1,400,300,1000
SpriteDrawmode 1,2
SpriteImage 1,1
centerspritehandle 1
SpriteVertexQuantity 1,8
SpriteFaceQuantity 1,8
PokeSpriteVertex 1, 4, 200,0,0
PokeSpriteVertex 1, 5, 300,0,0
PokeSpriteVertex 1, 6, 300,300,0
PokeSpriteVertex 1, 7, 200,300,0
PokeSpriteFaceVerts 1,1,4
PokeSpriteface 1,1,0,4,0,0,$ffff00
PokeSpriteface 1,1,1,5,1,0,$ffff00
PokeSpriteface 1,1,2,6,1,1,$ffffff
PokeSpriteface 1,1,3,7,0,1,$ff00ff
max=1000
For lp=0 to max
me= MakeParticleSprite(2,rnd(800),rnd(600),rndrange(15,25))
positionspritexyz me,rndrange(-800,800),_
rndrange(-800,800),_
rndrange(200,5000)
facecount=facecount+getSpriteFaceQuantity(me)
next
;' SetFps 30
Do
Cls 200
For lp=1 to max
TurnspriteXYZ lp,0.1*(lp/100),0.2,0.15
angle2#=angle#+(lp*5)
SpriteAlphaLevel lp,cosnewvalue(0.5,angle2#,0.5)
z#=GetSpriteZ(lp)-1
if z#<200
z#=5000
endif
PositionspriteZ lp,z#
drawsprite lp
next
; DrawOrderedSprites
; drawallsprites
ink $ffffff
; Scalesprite 2,1+cos(angle#)
f=fps()
print f
angle#=angle#+1
print Screen3dstate()
print FaceCount
print FaceCount*f
Sync
loop
Function MakeParticleSprite(ThisIMage,Xpos#,Ypos#,points)
ThisSprite=NewSprite(Xpos#,Ypos#,ThisIMage)
SpriteDrawMode ThisSprite, 2+16
SpriteVertexQuantity thisSprite,(Points)*4
SpriteFaceQuantity thisSprite,(Points)
angleStep#=360.0/points
size=32
For lp=0 to points-1
angle#=wrapangle(angle#,anglestep#)
Radius#=100
SetVerts(ThisSprite,VertexOffset,Angle#,Radius#,Size,wrapangle(angle#,-45))
SetFace(ThisSprite,ThisFace,VertexOffset,RndRgb())
VertexOffset=VertexOffset+4
inc thisface
next
EndFUnction ThisSPrite
Psub SetVerts(ThisSprite,VertexOffset,Angle#,Radius,Size,Rotation)
CenterX#=CosNewValue(0,angle#,Radius)
CenterY#=SinNewValue(0,angle#,Radius)
For lp=0 to 3
X#=CosNewValue(CenterX#,Rotation,Size)
Y#=SinNewValue(CenterY#,Rotation,Size)
PokeSpriteVertex ThisSprite,VertexOffset+lp,X#,y#,z#
Rotation=wrapangle(Rotation,90)
next
EndPsub
Psub SetFace(ThisSprite,ThisFace,VertexOffset,ThisColour)
PokeSpriteFaceVerts ThisSprite,ThisFace,4
PokeSpriteface ThisSprite,ThisFace,0,VertexOffset+0,0,0,ThisColour
PokeSpriteface ThisSprite,ThisFace,1,VertexOffset+1,1,0,ThisColour
PokeSpriteface ThisSprite,ThisFace,2,VertexOffset+2,1,1,ThisColour
PokeSpriteface ThisSprite,ThisFace,3,VertexOffset+3,0,1,ThisColour
EndPsub
NOTE: I doubt this code will function the same in future versions (versions above PB1.68c) as the pespective calc's are currently hard coded into the mesh translation.