home *** CD-ROM | disk | FTP | other *** search
/ Virtual Reality Homebrewer's Handbook / vr.iso / vr386 / body.c < prev    next >
C/C++ Source or Header  |  1996-03-19  |  3KB  |  119 lines

  1. /* Handles body/head/manipulator mappings */
  2.  
  3. /* Written by Dave Stampe, 4/1/94 */
  4.  
  5.  
  6. /*
  7.  This code is part of the VR-386 project, created by Dave Stampe.
  8.  VR-386 is a desendent of REND386, created by Dave Stampe and
  9.  Bernie Roehl.  Almost all the code has been rewritten by Dave
  10.  Stampre for VR-386.
  11.  
  12.  Copyright (c) 1994 by Dave Stampe:
  13.  May be freely used to write software for release into the public domain
  14.  or for educational use; all commercial endeavours MUST contact Dave Stampe
  15.  (dstampe@psych.toronto.edu) for permission to incorporate any part of
  16.  this software or source code into their products!  Usually there is no
  17.  charge for under 50-100 items for low-cost or shareware products, and terms
  18.  are reasonable.  Any royalties are used for development, so equipment is
  19.  often acceptable payment.
  20.  
  21.  ATTRIBUTION:  If you use any part of this source code or the libraries
  22.  in your projects, you must give attribution to VR-386 and Dave Stampe,
  23.  and any other authors in your documentation, source code, and at startup
  24.  of your program.  Let's keep the freeware ball rolling!
  25.  
  26.  DEVELOPMENT: VR-386 is a effort to develop the process started by
  27.  REND386, improving programmer access by rewriting the code and supplying
  28.  a standard API.  If you write improvements, add new functions rather
  29.  than rewriting current functions.  This will make it possible to
  30.  include you improved code in the next API release.  YOU can help advance
  31.  VR-386.  Comments on the API are welcome.
  32.  
  33.  CONTACT: dstampe@psych.toronto.edu
  34. */
  35.  
  36. #include <stdio.h>
  37. #include <stdlib.h>    /* atexit() */
  38. #include <dos.h>
  39.  
  40. #include "pointer.h"
  41. #include "vr_api.h"
  42. #include "intmath.h"
  43. #include "splits.h"
  44. #include "pcdevice.h"
  45. #include "segment.h"
  46.  
  47.  
  48.  
  49. OBJECT *body_seg = NULL;  /* body-in-world base segment */
  50. OBJECT *head_seg = NULL;  /* head-on-body segment */
  51. OBJECT *wrist_seg = NULL; /* wrist-on-body segment */
  52.  
  53. extern PDRIVER *head_device;
  54.  
  55.  
  56. /* do BEFORE loading, initializing devices */
  57. // creates default camera, etc.
  58.  
  59.  
  60. void init_body_links() /* setup body-glove-head system */
  61. {
  62.  extern int use_ht;
  63.  
  64.  if(!body_seg) body_seg = new_seg(NULL);  // same as invisible object
  65.  if(!head_seg) head_seg = new_seg(NULL);
  66.  attach_object(head_seg, body_seg,0);
  67.  if(!wrist_seg) wrist_seg = new_seg(NULL);
  68.  attach_object(wrist_seg, body_seg,0);
  69.  
  70.  abs_rot_segment(head_seg, 0*65536L, 0*65536L, 0, RYXZ);
  71.  
  72.  set_object_pose(body_seg,body_pose);
  73.  update_object(body_seg);
  74.  attach_camera(current_camera, head_seg);
  75. }
  76.  
  77.  
  78. /* sequence: update cursor/glove, read head tracker, */
  79. /* body_centric_map(), manipulate object, and render */
  80.  
  81. OBJECT *body_vehicle_object = NULL;
  82.  
  83. void update_body_links()
  84. {
  85.   set_object_pose(body_seg,body_pose);
  86.   if (!body_vehicle_object) update_object(body_seg);
  87.   else update_object(body_vehicle_object);
  88. }
  89.  
  90.  
  91. void disconnect_body()
  92. {
  93.   MATRIX m;
  94.  
  95.   update_body_links();    // make current
  96.  
  97.   if(body_vehicle_object) detach_object (body_seg,1);
  98.   get_object_matrix_pose(body_seg, body_pose);
  99.   body_vehicle_object = NULL;
  100. }
  101.  
  102.  
  103. void connect_body(OBJECT *s)
  104. {
  105.  MATRIX m;
  106.  POSE p;
  107.  
  108.   update_body_links();    // make current
  109.  
  110.  if(body_vehicle_object)
  111.       disconnect_body();
  112.  if(!s) return;
  113.  
  114.  attach_object(body_seg, s, 1);
  115.  get_object_matrix_pose(body_seg, body_pose);
  116.  
  117.  body_vehicle_object = s;
  118. }
  119.