00001 /*************************************************************************** 00002 *cr 00003 *cr (C) Copyright 1995-2019 The Board of Trustees of the 00004 *cr University of Illinois 00005 *cr All Rights Reserved 00006 *cr 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * RCS INFORMATION: 00011 * 00012 * $RCSfile: DisplayRocker.C,v $ 00013 * $Author: johns $ $Locker: $ $State: Exp $ 00014 * $Revision: 1.9 $ $Date: 2019/01/17 21:20:59 $ 00015 * 00016 *************************************************************************** 00017 * DESCRIPTION: 00018 * 00019 ***************************************************************************/ 00020 00021 #include "DisplayRocker.h" 00022 00023 DisplayRocker::DisplayRocker(Displayable *d) 00024 : Displayable(d) { 00025 Rocking = rockOnce = FALSE; 00026 rockSteps = currRockStep = 0; 00027 rockAmount = 0.0; 00028 rockAxis = 'y'; 00029 } 00030 00032 00033 // 'rock' the scene, by moving it through a given arc (possibly just a 00034 // continuous circle), with a specified number of steps. 00035 // There are two ways: 00036 // a) doOnce == TRUE: the rocking is done once, from a --> b 00037 // b) doOnce == FALSE: the rocking is done until told to stop, 00038 // from (a+b)/2 --> b --> a --> b ..... 00039 // Note that if steps < 0, the rocking is continuous, that is no ending point 00040 // is specified so the rotation is continually in one direction. In this 00041 // case doOnce means nothing, and is automatically used as if it were FALSE. 00042 void DisplayRocker::start_rocking(float a, char ax, int steps, int doOnce) { 00043 // set rocking parameters 00044 Rocking = TRUE; 00045 rockSteps = steps; // if < 0, continuous 00046 rockAmount = a; 00047 rockAxis = ((ax >= 'x' && ax <= 'z') ? ax : 'y'); 00048 00049 // when currRockStep == rockSteps, flip rockAmount or stop 00050 rockOnce = (doOnce && steps >= 0); 00051 currRockStep = (rockOnce ? 0 : (int)( ((float)steps)/2.0 )); 00052 } 00053 00054 void DisplayRocker::prepare() { 00055 if (Rocking) { 00056 parent->add_rot(rockAmount, rockAxis); 00057 if (rockSteps >= 0 && ++currRockStep >= rockSteps) { 00058 currRockStep = 0; 00059 rockAmount *= -1.0; // reverse direction of rocking 00060 if (rockOnce) 00061 stop_rocking(); // rocked once; now quit 00062 } 00063 } 00064 } 00065