# A Pneumatically-Actuated Mouse for Delivering Multimodal Haptic Feedback
## 5 Haptic Rendering
### Texture Rendering  
In the current paper, haptic texture rendering is achieved by using the high frequency vibrations generated through the haptic mouse. Air is pumped into and extracted from the stretchable layer at a high frequency (as compared to static pressure) and a user in contact with the haptic mouse can perceive the high frequency actuation. Various textures can be rendered by varying the frequency and amplitude of the rendered vibrations. In real life scenarios, every texture is a combination of multiple frequencies having different amplitudes. For the purpose of simplicity and as a proof of concept, in the current paper, every texture consists of a single predetermined frequency and amplitude. The overall process of rendering is provided in Algorithm 2. Further details about the texture rendering algorithm are provided in the following subsection. ```
1:Input: Collision point in current and previous frame
2:Step 1: Ray casting
3: Get mouse pointer position of current frame
4: Cast a ray
5:Step 2: Collision Detection
6:if Ray collides with any object then
7: Determine the object
8:endif
9:Step 3: Distance between the object and camera position
10: Get collision coordinates and camera coordinates
11: Calculate distance between camera and object (x and z coordinates only)
12:Step 4: Convert height into valve opening duration (ms)
13:for Current frame and previous frame do
14: Calculate change in volume
15: Calculate opening duration based on volume
16:endfor
17:Step 5: Valve operation
18:if Height of current frame is greater than previous frame then
19: Open positive valve equal to the difference of duration
20:endif
21:if Height of current frame is lesser than previous frame then
22: Open negative valve equal to the difference of duration
23:endif
24:Finish
```  
**Algorithm 2** Geometry rendering. Algorithm 3  
A virtual texture is displayed on a computer screen, and every time the mouse pointer comes in contact (or slides over it) with the displayed texture, the user experiences high frequency vibration feedback. The frequency of this vibration is directly dependent on the frequency of the given texture. The haptic textures are modeled based on a grid approach. This is a position-based rendering algorithm used to deliver appropriate feedback each time the mouse pointer crosses the grid. A virtual grid-like structure is overlaid on each virtual texture. The frequency of the texture dictates the grid spacing; the higher the frequency of the texture, the closer the grid lines are situated and vice versa. A virtual texture is generated in a specific area of the computer screen. The algorithm is continuously listening for a collision event in this area. When a mouse pointer crosses this area, a collision event is triggered. The length of the pointer slide is calculated based on its history (difference between last position and current position). Haptic feedback is generated for each grid point that is crossed during this length. ```
1:Input: Mouse pointer position
2:Step 1: Interaction Area
3: Determine whether mouse pointer is in pre-determined confined location
4: Determine whether the surface is textured surface
5:Step 2: Determination of Grid Number
6:if Mouse pointer velocity is high then
7: Determine number of grid points between the current and previous pointer position
8:endif
9:Step 3: Rendering Feedback
10:if Surface = Texture surface then
11:for Every point of grid do
12: Create a thread
13: Actuate according to the created thread
14:endfor
15:endif
16:Finish
```  
**Algorithm 2** Texture rendering. In certain cases a user might slide the mouse pointer across a texture grid at a high velocity. The pointer can pass through several grid points in a short duration of time. The graphical rendering algorithm may miss some of the intermediate crossings, and record fewer collisions. This can occur because haptic rendering is carried out at significantly higher refresh rates than graphical rendering.