added 3dengfx into the repo, probably not the correct version for this
[summerhack] / src / 3dengfx / src / gfx / controller.hpp
1 /*
2 This file is part of the graphics core library.
3
4 Copyright (c) 2004, 2005 John Tsiombikas <nuclear@siggraph.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 /* motion controllers (part of the animation system)
22  *
23  * Author: John Tsiombikas 2004
24  */
25
26 #ifndef _CONTROLLER_HPP_
27 #define _CONTROLLER_HPP_
28
29 #include "curves.hpp"
30 #include "timeline.hpp"
31
32 enum ControllerClass {CTRL_CURVE, CTRL_SIN, CTRL_COS, CTRL_LIN};
33
34 enum {
35         CTRL_X          = 1,    // 0001
36         CTRL_Y          = 2,    // 0010
37         CTRL_Z          = 4,    // 0100
38         CTRL_XY         = 3,    // 0011
39         CTRL_YZ         = 6,    // 0110
40         CTRL_XZ         = 5,    // 0101
41         CTRL_XYZ        = 7             // 0111
42 };
43         
44
45 class MotionController {
46 private:
47         Curve *curve;
48
49         // parameters for the sinusoidal controller
50         scalar_t freq, ampl, phase;
51         scalar_t (*freq_func)(scalar_t);
52         scalar_t (*ampl_func)(scalar_t);
53
54         // parameters for the linear controller
55         Vector3 orig, slope;
56         
57         unsigned long start_time, end_time;
58         
59         TimelineMode time_mode;
60         ControllerClass ctrl_type;
61         unsigned int axis_flags;
62         
63 public:
64         MotionController(ControllerClass ctype = CTRL_CURVE, TimelineMode mode = TIME_CLAMP);
65         MotionController(Curve *curve, unsigned long start, unsigned long end, TimelineMode mode = TIME_CLAMP);
66         
67         void set_curve(Curve *curve);
68         void set_sin_func(scalar_t freq, scalar_t ampl, scalar_t phase = 0.0f);
69         void set_sin_func(scalar_t (*freq_func)(scalar_t), scalar_t(*ampl_func)(scalar_t));
70         
71         void set_origin(scalar_t orig);
72         void set_origin(const Vector3 &orig_vec);
73         void set_slope(scalar_t slope);
74         void set_slope(const Vector3 &slope_vec);
75         
76         void set_timing(unsigned long start, unsigned long end);
77         void set_timeline_mode(TimelineMode tmode);
78         void set_controller_type(ControllerClass ctype);
79         void set_control_axis(unsigned int axis_flags);
80         
81         Curve *get_curve();
82         unsigned long get_start_time() const;
83         unsigned long get_end_time() const;
84         TimelineMode get_timeline_mode() const;
85         unsigned int get_control_axis() const;
86         
87         Vector3 operator ()(unsigned long time) const;
88 };
89         
90
91 #endif  // _CONTROLLER_HPP_