BRL-CAD
knob.c
Go to the documentation of this file.
1 /* K N O B . C
2  * BRL-CAD
3  *
4  * Copyright (c) 1988-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @file libdm/knob.c
21  *
22  * Utilities for dealing with knobs.
23  *
24  */
25 
26 #include "common.h"
27 
28 #include "tcl.h"
29 #include "vmath.h"
30 #include "dm.h"
31 
32 #ifdef IR_KNOBS
33 
34 /*
35  * Because the dials are so sensitive, setting them exactly to
36  * zero is very difficult. This function can be used to extend the
37  * location of "zero" into "the dead zone".
38  */
39 
40 int
41 dm_limit(int i)
42 {
43  if ( i > NOISE )
44  return i-NOISE;
45  if ( i < -NOISE )
46  return i+NOISE;
47  return 0;
48 }
49 
50 /*
51  * This function reverses the effects of dm_limit.
52  */
53 int
54 dm_unlimit(int i)
55 {
56  if ( i > 0 )
57  return i + NOISE;
58  if ( i < 0 )
59  return i - NOISE;
60  return 0;
61 }
62 
63 /*
64  * Wrap the given value "f" to a new value in the range (-1.0, 1.0).
65  */
66 fastf_t
68 {
69  int i;
70  fastf_t tmp_f;
71 
72  /* This way makes no assumption about the size of f */
73  if (f > 1.0) {
74  tmp_f = (f - 1.0) / 2.0;
75  i = tmp_f;
76  tmp_f = (tmp_f - i) * 2.0;
77 
78  if (tmp_f == 0)
79  return 1.0;
80  else
81  return -1.0 + tmp_f;
82  }
83 
84  if (f < -1.0) {
85  tmp_f = (f + 1.0) / 2.0;
86  i = tmp_f;
87  tmp_f = (tmp_f - i) * 2.0;
88 
89  if (tmp_f == 0)
90  return -1.0;
91  else
92  return 1.0 + tmp_f;
93  }
94 
95  return f;
96 }
97 #endif
98 
99 /*
100  * Local Variables:
101  * mode: C
102  * tab-width: 8
103  * indent-tabs-mode: t
104  * c-file-style: "stroustrup"
105  * End:
106  * ex: shiftwidth=4 tabstop=8
107  */
int dm_limit(int i)
Header file for the BRL-CAD common definitions.
fastf_t dm_wrap(fastf_t f)
int dm_unlimit(int i)
double fastf_t
Definition: defines.h:300