News:

Function Finder  Find all the functions within source code files

Main Menu

Z Depth Perspective For Sprites

Started by kevin, October 20, 2010, 03:06:54 PM

Previous topic - Next topic

kevin

 Z Depth Perspective For Sprites

  Here's a simpler variation of the classic 'CustomSceneDepth' example you'll find the example pack under Demos.  It shows how you can project 3D space (none rotated) into 2D screen coordinates.   From there it's just matter of scaling our media to fit the required size.  In this version I've used a sprite, but you can use Polygons (TexturedQuads), Shapes, Images. whatever..  


  Requires PlayBasic V1.64L

PlayBASIC Code: [Select]
   Setfps 60

Size=256
Img=NewfXimage(size,size)
RenderPhongImage img,size/2,size/2,$ff0000,256,2


ProjectionX#=400
ProjectionY#=400

; objects Width and Height and depth in the scene
ObjectWidth=size
ObjectHeight=size
ObjectDepth=5000

; use a spritge to represent this object on screen
Spr=NewSprite(0,0,img)
SpriteDrawMode Spr,2
AutoCenterSpriteHandle spr,true

Do
; Clear the screen
Cls

; project the obejcts screenwidth and height at this depth
ScreenWidth#=(ObjectWidth*ProjectionX#)/ObjectDepth
ScreenHeight#=(ObjectHeight*ProjectionY#)/ObjectDepth

ScaleX#=ScreenWidth#/GetImageWidth(img)
ScaleY#=ScreenHeight#/GetImageHeight(img)
positionsprite spr,GetScreenWidth()/2,GetScreenHeight()/2
ScaleSpriteXY spr,scaleX#,scaley#
SpriteTint Spr, rgbdepthcue($ffffff,0,Objectdepth,500,2500)
drawsprite Spr

ObjectDepth=wrapvalue(ObjectDepth-10,50,2500)

Sync
loop





Related To:

  2.5D Rugby Source
  Manual Projection/Scene Perspective
  Mip Mapped Image Zoomer