Advertisement
Guest User

Perl OpenHMD Module (Alpha): examples/simple

a guest
Nov 24th, 2014
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.42 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. use OpenHMD qw(:CONSTANTS);
  7.  
  8. main();
  9.  
  10. sub main {
  11.     my $openhmd = OpenHMD -> new;
  12.  
  13.     my $context = $openhmd -> ohmd_ctx_create;
  14.  
  15.     my $device_count = $openhmd -> ohmd_ctx_probe ($context);
  16.     printf "Device count: %i\n", $device_count;
  17.  
  18.     foreach my $index (0 .. $device_count - 1) {
  19.         printf "Device #%i:\n",     $index;
  20.         printf "\tVendor: \t%s\n",   $openhmd -> ohmd_list_gets ($context, $index, $OHMD_VENDOR);
  21.         printf "\tProduct:\t%s\n",  $openhmd -> ohmd_list_gets ($context, $index, $OHMD_PRODUCT);
  22.         printf "\tPath:   \t%s\n",     $openhmd -> ohmd_list_gets ($context, $index, $OHMD_PATH);
  23.         print "\n";
  24.     }
  25.  
  26.     my $device = $openhmd -> ohmd_list_open_device ($context, 0);
  27.  
  28.     printf "Resolution:\t%i x %i\n",
  29.         $openhmd -> ohmd_device_geti ($device, $OHMD_SCREEN_HORIZONTAL_RESOLUTION   ),
  30.         $openhmd -> ohmd_device_geti ($device, $OHMD_SCREEN_VERTICAL_RESOLUTION     ),
  31.     ;
  32.     print "\n";
  33.  
  34.     printf "Horizontal Size:        \t%f\n", $openhmd -> ohmd_device_getf ($device, $OHMD_SCREEN_HORIZONTAL_SIZE);
  35.     printf "Vertical Size:          \t%f\n", $openhmd -> ohmd_device_getf ($device, $OHMD_SCREEN_VERTICAL_SIZE);
  36.     printf "Lens Separation:        \t%f\n", $openhmd -> ohmd_device_getf ($device, $OHMD_LENS_HORIZONTAL_SEPARATION);
  37.     printf "Lens Vertical Centre:   \t%f\n", $openhmd -> ohmd_device_getf ($device, $OHMD_LENS_VERTICAL_POSITION);
  38.     printf "Left Eye FOV:           \t%f\n", $openhmd -> ohmd_device_getf ($device, $OHMD_LEFT_EYE_FOV);
  39.     printf "Right Eye FOV:          \t%f\n", $openhmd -> ohmd_device_getf ($device, $OHMD_RIGHT_EYE_FOV);
  40.     printf "Left Eye Asepect:       \t%f\n", $openhmd -> ohmd_device_getf ($device, $OHMD_LEFT_EYE_ASPECT_RATIO);
  41.     printf "Right Eye Aspect:       \t%f\n", $openhmd -> ohmd_device_getf ($device, $OHMD_RIGHT_EYE_ASPECT_RATIO);
  42.     printf "Distortion K:           \t%s\n", join (', ', ($openhmd -> ohmd_device_getf ($device, $OHMD_DISTORTION_K))[0 .. 5]);
  43.     printf "IPD:                    \t%f\n", $openhmd -> ohmd_device_getf ($device, $OHMD_EYE_IPD);
  44.  
  45.     print 'Sleeping for 5 seconds..', "\n";
  46.     sleep 5;
  47.  
  48.     foreach my $iteration (0 .. 1000) {
  49.         $openhmd -> ohmd_ctx_update ($context);
  50.         printf "%f %f %f %f\n", $openhmd -> ohmd_device_getf ($device, $OHMD_ROTATION_QUAT);
  51.         select (undef, undef, undef, 0.01);
  52.     }
  53.  
  54.     $openhmd -> ohmd_ctx_destroy ($context);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement