summaryrefslogtreecommitdiffhomepage
path: root/SixenseSDK/include/sixense_utils/laser_pointer.hpp
blob: d845ae97e040590d0bdd552e858b207156077830 (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
 *
 * SIXENSE CONFIDENTIAL
 *
 * Copyright (C) 2011 Sixense Entertainment Inc.
 * All Rights Reserved
 *
 */

#ifndef SIXENSE_PORT_UTILS_LASER_POINTER_HPP
#define SIXENSE_PORT_UTILS_LASER_POINTER_HPP

#pragma warning(push)
#pragma warning( disable:4251 )

#include "sixense_utils/export.hpp"
#include "sixense_utils/interfaces.hpp"

#include "sixense_math.hpp"

using sixenseMath::Vector2;
using sixenseMath::Vector3;
using sixenseMath::Matrix3;

namespace sixenseUtils {

	// LaserPointer computes a ray that shoots from the controller and intersects with the screen. 
	class SIXENSE_UTILS_EXPORT LaserPointer {

	public:
		LaserPointer();

		void setScreenSize( Vector2 width_and_height_in_mm );
		void setScreenCenterOffsetFromBase( Vector3 offset_in_mm );

		Vector2 getScreenSize();
		Vector3 getScreenCenterOffsetFromBase();

		Vector2 getIntersection( Vector3 position, Matrix3 rotation );

	private:
		Vector2 _width_and_height_in_mm;
		Vector3 _offset_in_mm;

	};


	// This class can be used to compute the required parameters for the LaserPointer by having the user aim the controller at the
	// corners of the screen.
	class SIXENSE_UTILS_EXPORT LaserPointerCalib {
	public:

		LaserPointerCalib() { _has_computed = false; }

		// Calibrate using 4 ray casts, bottom left and top right from 2 distinct positions in space
		bool compute( 
			Vector3 bottom_left_ray_from_point_A, 
			Vector3 top_right_ray_from_point_A, 
			Vector3 bottom_left_ray_from_point_B, 
			Vector3 top_right_ray_from_point_B );

		// Calibrate using 2 ray casts plus the screen size, bottom left and top right
		bool compute(
			float screen_width_in_mm, float screen_aspect, 
			Vector3 bottom_left_ray_from_point_A, 
			Vector3 top_right_ray_from_point_A );

		bool hasComputed() { return _has_computed; }
		Vector2 getScrenSize();
		Vector3 setScreenCenterOffsetFromBase();

	private:
		bool _has_computed;
		Vector2 _width_and_height_in_mm;
		Vector3 _offset_in_mm;
	};
};

#pragma warning(pop)

#endif