File: trackball.ads

package info (click to toggle)
libgtkada2 2.8.1-6lenny3
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 13,496 kB
  • ctags: 3,886
  • sloc: ada: 103,189; ansic: 45,411; perl: 5,500; sh: 2,812; makefile: 1,169; xml: 19
file content (35 lines) | stat: -rw-r--r-- 1,523 bytes parent folder | download | duplicates (11)
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

--  virtual trackball implementation

package Trackball is

   type Quaternion is array (0 .. 3) of Float;
   type Matrix is array (0 .. 3, 0 .. 3) of aliased Float;
   type Vector is array (0 .. 2) of Float;

   procedure Trackball (Q : out Quaternion;
                        P1x, P1y, P2x, P2y : Float);
   --  Pass the x and y coordinates of the last and current positions of
   --  the mouse, scaled so they are from (-1.0 ... 1.0).
   --  The resulting rotation is returned as a quaternion rotation in the
   --  first paramater.

   procedure Add_Quats (Q1, Q2 : Quaternion;
                        Dest   : out Quaternion);
   --  Given two quaternions, add them together to get a third quaternion.
   --  Adding quaternions to get a compound rotation is analagous to adding
   --  translations to get a compound translation.  When incrementally adding
   --  rotations, the first argument here should be the new rotation, the
   --  second and third the total rotation (which will be over-written with
   --  the resulting new total rotation).

   procedure Build_Rotmatrix (M : out Matrix; Q : Quaternion);
   --  A useful function, builds a rotation matrix in Matrix based on given
   --  quaternion.

   procedure Axis_To_Quat (A : Vector; Phi : Float; Q : out Quaternion);
   --  This function computes a quaternion based on an axis (defined by the
   --  given vector) and an angle about which to rotate.  The angle is
   --  expressed in radians.  The result is put into the third argument.

end Trackball;