| Assignment 2: Texture Warper |
|---|
| What It Does: |
|
This program sets an even grid of triangles over an image,
and warps each point outward from the point of the mouse.
The entire image is globally scaled, translated, and rotated. Users can press L (less)
and B (bigger) to change the resolution of the grid, creating a smoother (albeit slower)
effect. Space cycles from one image to the next. Six coloured lights swirl continuously
around the image. |
| How It Does What It Does: |
|
Using barycentric coordinates,
this program finds texture and colour coordinates for each pixel on the screen,
multiplying them to get the final colour.
When the program starts (or you resize the texture-grid)
it creates a grid of vertices, each with texture coordinates
evenly distributed across the image, and colour (0.5, 0.5, 0.5). Each iteration, it re-calculates offsets dependent on the position of the mouse. To get a mouse-image translation, the program creates an inverse matrix for each GL_Transform, Rotate and Scale, and multiples these in the opposite order, to create an inverse matrix that maps screen position to image position. It then stores the mouse position and loops through each vertex in the image grid, calculating its offset. The formula used is: float strength = cosf(dist * (M_PI/2.0f) / threshold); where dist is the distance (in un-transformed coords) from the mouse to the vertex (x, y), and threshold is scaled so that the “bubble” will appear the same size despite global scaling. Each vertex is translated strength/10 units directly away from the mouse. A similar formula is applied to the lights, adding lightcols[i]*((strength+1)/2) to the vertex's lighting, and maxing each colour at 1.0f. |