File: rotate.h

package info (click to toggle)
python-visual 3.2.9-4.1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 2,796 kB
  • ctags: 2,664
  • sloc: cpp: 11,958; sh: 8,185; python: 3,709; ansic: 480; makefile: 311
file content (52 lines) | stat: -rw-r--r-- 1,409 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef VISUAL_ROTATE_H
#define VISUAL_ROTATE_H

#include <boost/python/tuple.hpp>
#include <boost/python/dict.hpp>
#include <boost/python/extract.hpp>
#include <boost/python/raw_function.hpp>

namespace visual {

/* Unfortunately the signatures of the functions primitive.rotate( "angle", "axis")
 * and primitive.rotate( "angle", "origin") are identical to Boost.Python.  To 
 * differentiate them, I am using this raw function to interpret the arguments.
 * Ick.
 */
template <typename Prim>
boost::python::object
py_rotate( boost::python::tuple args, boost::python::dict kwargs)
{
	using boost::python::extract;
	
	Prim* This = extract<Prim*>( args[0]);
	
	if (!kwargs.has_key("angle")) {
		// This exception is more useful than the keyerror exception below.
		throw std::invalid_argument( 
			"primitive.rotate(): angle of rotation must be specified.");
	}
	
	double angle = extract<double>(kwargs["angle"]);
	
	// The rotation axis, which defaults to the body axis.
	vector r_axis;
	if (kwargs.has_key("axis"))
		r_axis = vector(kwargs["axis"]);
	else
		r_axis = This->get_axis();
	
	// The rotation origin, which defaults to the body position.
	vector origin;
	if (kwargs.has_key("origin"))
		origin = vector(kwargs["origin"]);
	else
		origin = This->get_pos();
	
	This->py_rotate( angle, r_axis, origin);
	return boost::python::object();
}
	
} // !namespace visual

#endif // !defined VISUAL_ROTATE_H