Fuze Arena Logo
  • Forum
  • Creations
    Catalogue Showcase
  • Help

reflect()

Purpose

Find the reflection of a vector

Description

Find the reflection of a vector when it hits a surface

Syntax

result = reflect( incident, normal )

Arguments

result The resulting reflection vector { x, y, z, w }

incident incident vector { x, y, z, w }

normal normal vector orthoganal to the surface { x, y, z, w }

Example

radians( true )
image = loadImage( "Untied Games/Enemy small top C", false )
ship = createSprite( )
setSpriteImage( ship, image )
lastpos = { gwidth() / 2, gheight() / 2 }
setSpriteLocation( ship, lastpos )
setSpriteScale( ship, { 3, 3 } )
size = getSpriteSize( ship )
speed = { 400, 300 }

loop
    clear()
    c = controls( 0 )
    curpos = getSpriteLocation( ship )
    refx = 0
    refy = 0
    if curpos.x < size.x / 2 then
        refx = 1
    endIf
    if curpos.y < size.y / 2 then
        refy = 1
    endIf
    if curpos.x > gwidth() - size.x / 2 then
        refx = -1
    endIf
    if curpos.y > gheight() - size.y / 2 then
        refy = -1
    endIf
    speed = reflect( speed, { refx, refy } )
    setSpriteSpeed( ship, speed )
    if curpos != lastpos then
        setSpriteRotation( ship, -pi / 2 + atan2( curpos.y - lastpos.y, curpos.x - lastpos.x ) )
        lastpos = curpos
    endIf
    updateSprites()
    drawSprites()
    update()
repeat

Associated Commands

cross(), dot(), length(), normalize(), refract()

logo

©2019 FUZE Technologies Ltd. FUZE is a registered trademark of FUZE Technologies Ltd. All rights reserved.

Useful links

  • Fuze Main Site
  • Fuze Arena on Twitter
  • Fuze Arena on Youtube
  • Download Buyer

Contact Information

  • FUZE Technologies Ltd
    15 Clearfields Farm
    Wotton Underwood
    Aylesbury, Buckinghamshire
    ​England, HP18 0RS

  • +44 (0) 1844 239 432

  • contact@fuze.co.uk

© Copyright FUZE Technologies Ltd. All rights reserved.