Home My Page Projects Code Snippets Project Openings 3D graphics for Standard ML
Summary Activity SCM

SCM Repository

[sml3d] View of /trunk/sml3d/src/openal/listener.sml
ViewVC logotype

View of /trunk/sml3d/src/openal/listener.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 882 - (download) (annotate)
Sat May 8 17:16:05 2010 UTC (9 years, 5 months ago) by jhr
File size: 1652 byte(s)
  Added Listener module to OpenAL implementation
(* listener.sml
 *
 * COPYRIGHT (c) 2010 John Reppy (http://cs.uchicago.edu/~jhr)
 * All rights reserved.
 *
 * A listener represents the location and orientation of the
 * 'user' in 3D-space.
 *
 * Properties include: -
 *
 * Gain         AL_GAIN         ALfloat
 * Position     AL_POSITION     ALfloat[3]
 * Velocity     AL_VELOCITY     ALfloat[3]
 * Orientation  AL_ORIENTATION  ALfloat[6] (Forward then Up vectors)
 *)

structure Listener =
  struct
    local
      open ALTypes
      open ALConsts
      open ALFuncs
    in

  (* gain of listener for current context *)
    fun gain () = let
	  val f = ref 0.0
	  in
	    alGetListenerf (AL_GAIN, f);
	    !f
	  end
    fun setGain f = alListenerf (AL_GAIN, f)

  (* float-vector properties *)
    local
      fun get tag () = let
	    val arr = Array.array(3, 0.0)
	    in
	      alGetListenerfv (tag, arr);
	      {x = Array.sub(arr, 0), y = Array.sub(arr, 1), z = Array.sub(arr, 2)}
	    end
      fun set tag {x, y, z} = alListener3f (tag, x, y, z)
    in
    val position = get AL_POSITION
    val setPosition = set AL_POSITION
    val velocity = get AL_VELOCITY
    val setVelocity = set AL_VELOCITY
    end

  (* listener orientation *)
    fun orientation () = let
	  val arr = Array.array(6, 0.0)
	  fun get i = Array.sub(arr, i)
	  in
	    alGetListenerfv (AL_ORIENTATION, arr);
	    { dir = {x = get 0, y = get 1, z = get 2}, up = {x = get 3, y = get 4, z = get 5} }
	  end

    fun setOrientation {dir={x=dx, y=dy, z=dz}, up={x=ux, y=uy, z=uz}} = let
	  val vec = Vector.fromList [dx, dy, dz, ux, uy, uz]
	  in
	    alListenerfv (AL_ORIENTATION, vec)
	  end

    end (* local *)
  end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0