BRender Technical Reference Manual:3 Functions (Structured Reference):Miscellaneous
Next|Prev|Up
Input Device Support
BrMatrix34RollingBall()

# Miscellaneous

## Input Device Support

BRender has little support for 3D specific input devices, however, the following function may be useful in simulating a 3D input device using a 2D input device such as a mouse.

## `BrMatrix34RollingBall()`

Description:
This function generates a matrix which provides an intuitive way of controlling the rotation of 3D objects with a mouse or other 2D pointing device. The mouse may be thought of as controlling a horizontal flat surface resting on top of a fixed sphere. As the surface is moved in any direction (but not rotated), so the sphere will rotate.

Declaration:
`void BrMatrix34RollingBall(br_matrix34* mat, int dx, int dy, int radius)`

Arguments:
`br_matrix34 * mat`

A pointer to the destination matrix.

`int dx,dy`

The amount the `top surface' has moved in each direction.

`int radius`

The radius of the imaginary ball.

Effects:
This function calculates the tangent vector (`dx`,`dy`) to the sphere of radius `radius`. in 3D, and uses this to determine the axis of rotation normal to this tangent at the centre of the sphere, and the angle subtended by the tangent vector. From this, a transform matrix is created, describing the rotation.

Remarks:
The function is expected to be used with frequent samples of movements made with the 2D manipulator, i.e. a movement of 10cm in one go will produce a smaller rotation (no greater than 180xb0 ) whereas the same movement sampled at 100 intervals will cumulatively produce a larger rotation (possibly several revolutions). This is unlikely to be a problem in practice.

Note that using the 2D manipulator to describe small circles can rotate the 3D object about its vertical axis.

Example:
```int mouse_x,mouse_y;
br_matrix34 mat;
...
BrMatrix34RollingBall(&mat,-mouse_x,mouse_y,500);
```
The book Graphics Gems III, edited by David Kirk, ISBN 0-12-409670-0, Ch.2, Pt.3, `The Rolling Ball', Andrew J. Hanson, p51.

Generated with
CERN WebMaker