Blitz3D+ Command Reference

SpriteViewMode sprite,view_mode

Parameters

sprite - sprite handle
view_mode - how the sprite orients itself:
1: camera-aligned (default) - takes the camera orientation completely, so it faces the camera and rolls with it
2: free - keeps whatever orientation you give it
3: camera-facing - turns to look along the camera view direction, but keeps its own roll
4: upright - turns to face the camera about the up axis only, staying upright

Description

Sets how a sprite turns to face the camera.

Mode 1 is the default and the one to use for particles: the sprite adopts the camera orientation outright, so it is always square-on to the screen no matter how the camera pitches or rolls. Smoke, sparks, explosions and glows all want this.

Mode 2 turns the behaviour off entirely - the sprite keeps whatever orientation you gave it, like a flat piece of paper hung in the world. That makes it useful for decals, signs and floor markings. Because it is a single flat quad it is only visible from the front, so add EntityFX sprite,16 to disable backface culling if the player can walk behind it.

Mode 3 turns the sprite to look along the camera view direction while keeping its own roll, so a sprite you have deliberately rotated stays rotated as the camera moves around it.

Mode 4 is the classic billboard: the sprite turns about the up axis to face the camera, but never tips over. This is what trees, bushes, spectators, torches and lamp posts want - things that should always be seen from the side, and would look wrong lying flat when the camera looks down at them from above.

See also: CreateSprite, LoadSprite, HandleSprite, RotateSprite, EntityFX.

Example

; SpriteViewMode Example
; ----------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

; The camera hangs from a pivot so it can orbit the sprite
pivot=CreatePivot()
PositionEntity pivot,0,1,0

camera=CreateCamera(pivot)
PositionEntity camera,0,0,10

light=CreateLight()
RotateEntity light,90,0,0

; A reflective floor helps show the camera moving
plane=CreatePlane()
EntityTexture plane,LoadTexture("media/Chorme-2.BMP")

sprite=LoadSprite("media/b3dlogo.jpg")
PositionEntity sprite,0,1,0

pitch=-15
yaw=180
roll=0
view_mode=1
view_mode_info$=" (fixed)"

While Not KeyDown(1)

    ; Cursor keys orbit the camera, A and S roll it
    If KeyDown(208) And pitch<0 Then pitch=pitch+1
    If KeyDown(200) And pitch>-89 Then pitch=pitch-1
    If KeyDown(205) Then yaw=yaw+1
    If KeyDown(203) Then yaw=yaw-1
    If KeyDown(30) Then roll=roll+1
    If KeyDown(31) Then roll=roll-1

    ; Choose a sprite view mode with keys 1-4
    If KeyHit(2) Then view_mode=1 : view_mode_info$=" (fixed: always faces camera)"
    If KeyHit(3) Then view_mode=2 : view_mode_info$=" (free: independent of camera)"
    If KeyHit(4) Then view_mode=3 : view_mode_info$=" (upright1: faces camera, rolls with it)"
    If KeyHit(5) Then view_mode=4 : view_mode_info$=" (upright2: billboard, stays upright)"

    ; Apply the view mode to the sprite
    SpriteViewMode sprite,view_mode

    RotateEntity pivot,pitch,yaw,0
    PointEntity camera,sprite,roll

    RenderWorld

    Text 0,0,"Cursor keys: orbit camera   A/S: roll camera   1-4: view mode   Esc: exit"
    Text 0,20,"SpriteViewMode sprite,"+view_mode+view_mode_info$

    Flip

Wend

End

Index