+ default:
+ case Q3DEFORM_PROJECTIONSHADOW:
+ case Q3DEFORM_TEXT0:
+ case Q3DEFORM_TEXT1:
+ case Q3DEFORM_TEXT2:
+ case Q3DEFORM_TEXT3:
+ case Q3DEFORM_TEXT4:
+ case Q3DEFORM_TEXT5:
+ case Q3DEFORM_TEXT6:
+ case Q3DEFORM_TEXT7:
+ case Q3DEFORM_NONE:
+ break;
+ case Q3DEFORM_AUTOSPRITE:
+ Matrix4x4_Transform3x3(&rsurface.inversematrix, r_view.forward, newforward);
+ Matrix4x4_Transform3x3(&rsurface.inversematrix, r_view.right, newright);
+ Matrix4x4_Transform3x3(&rsurface.inversematrix, r_view.up, newup);
+ VectorNormalize(newforward);
+ VectorNormalize(newright);
+ VectorNormalize(newup);
+ // make deformed versions of only the model vertices used by the specified surfaces
+ for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
+ {
+ const msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+ // a single autosprite surface can contain multiple sprites...
+ for (j = 0;j < surface->num_vertices - 3;j += 4)
+ {
+ VectorClear(center);
+ for (i = 0;i < 4;i++)
+ VectorAdd(center, (rsurface.vertex3f + 3 * surface->num_firstvertex) + (j+i) * 3, center);
+ VectorScale(center, 0.25f, center);
+ VectorCopy((rsurface.normal3f + 3 * surface->num_firstvertex) + j*3, forward);
+ VectorCopy((rsurface.svector3f + 3 * surface->num_firstvertex) + j*3, right);
+ VectorCopy((rsurface.tvector3f + 3 * surface->num_firstvertex) + j*3, up);
+ for (i = 0;i < 4;i++)
+ {
+ VectorSubtract((rsurface.vertex3f + 3 * surface->num_firstvertex) + (j+i)*3, center, v);
+ VectorMAMAMAM(1, center, DotProduct(forward, v), newforward, DotProduct(right, v), newright, DotProduct(up, v), newup, rsurface.array_deformedvertex3f + (surface->num_firstvertex+i+j) * 3);
+ }
+ }
+ Mod_BuildNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, rsurface.vertex3f, rsurface.modelelement3i + surface->num_firsttriangle * 3, rsurface.array_deformednormal3f, r_smoothnormals_areaweighting.integer);
+ Mod_BuildTextureVectorsFromNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, rsurface.vertex3f, rsurface.modeltexcoordtexture2f, rsurface.array_deformednormal3f, rsurface.modelelement3i + surface->num_firsttriangle * 3, rsurface.array_deformedsvector3f, rsurface.array_deformedtvector3f, r_smoothnormals_areaweighting.integer);
+ }
+ rsurface.vertex3f = rsurface.array_deformedvertex3f;
+ rsurface.vertex3f_bufferobject = 0;
+ rsurface.vertex3f_bufferoffset = 0;
+ rsurface.svector3f = rsurface.array_deformedsvector3f;
+ rsurface.svector3f_bufferobject = 0;
+ rsurface.svector3f_bufferoffset = 0;
+ rsurface.tvector3f = rsurface.array_deformedtvector3f;
+ rsurface.tvector3f_bufferobject = 0;
+ rsurface.tvector3f_bufferoffset = 0;
+ rsurface.normal3f = rsurface.array_deformednormal3f;
+ rsurface.normal3f_bufferobject = 0;
+ rsurface.normal3f_bufferoffset = 0;
+ break;
+ case Q3DEFORM_AUTOSPRITE2:
+ Matrix4x4_Transform3x3(&rsurface.inversematrix, r_view.forward, newforward);
+ Matrix4x4_Transform3x3(&rsurface.inversematrix, r_view.right, newright);
+ Matrix4x4_Transform3x3(&rsurface.inversematrix, r_view.up, newup);
+ VectorNormalize(newforward);
+ VectorNormalize(newright);
+ VectorNormalize(newup);
+ // make deformed versions of only the model vertices used by the specified surfaces
+ for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
+ {
+ const msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+ const float *v1, *v2;
+ float f, l;
+ struct
+ {
+ float length2;
+ int quadedge;
+ }
+ shortest[2];
+ // a single autosprite surface can contain multiple sprites...
+ for (j = 0;j < surface->num_vertices - 3;j += 4)
+ {
+ VectorClear(center);
+ for (i = 0;i < 4;i++)
+ VectorAdd(center, (rsurface.vertex3f + 3 * surface->num_firstvertex) + (j+i) * 3, center);
+ VectorScale(center, 0.25f, center);
+ shortest[0].quadedge = shortest[1].quadedge = 0;
+ shortest[0].length2 = shortest[1].length2 = 0;
+ // find the two shortest edges, then use them to define the
+ // axis vectors for rotating around the central axis
+ for (i = 0;i < 6;i++)
+ {
+ v1 = rsurface.vertex3f + 3 * (surface->num_firstvertex + quadedges[i][0]);
+ v2 = rsurface.vertex3f + 3 * (surface->num_firstvertex + quadedges[i][1]);
+ l = VectorDistance2(v1, v2);
+ if (shortest[0].length2 > l || i == 0)
+ {
+ shortest[1] = shortest[0];
+ shortest[0].length2 = l;
+ shortest[0].quadedge = i;
+ }
+ else if (shortest[1].length2 > l || i == 1)
+ {
+ shortest[1].length2 = l;
+ shortest[1].quadedge = i;
+ }
+ }
+ // this calculates the midpoints *2 (not bothering to average) of the two shortest edges, and subtracts one from the other to get the up vector
+ for (i = 0;i < 3;i++)
+ {
+ right[i] = rsurface.vertex3f[3 * (surface->num_firstvertex + quadedges[shortest[1].quadedge][1]) + i]
+ + rsurface.vertex3f[3 * (surface->num_firstvertex + quadedges[shortest[1].quadedge][0]) + i];
+ up[i] = rsurface.vertex3f[3 * (surface->num_firstvertex + quadedges[shortest[1].quadedge][0]) + i]
+ + rsurface.vertex3f[3 * (surface->num_firstvertex + quadedges[shortest[1].quadedge][1]) + i]
+ - rsurface.vertex3f[3 * (surface->num_firstvertex + quadedges[shortest[0].quadedge][0]) + i]
+ - rsurface.vertex3f[3 * (surface->num_firstvertex + quadedges[shortest[0].quadedge][1]) + i];
+ }
+ // calculate a forward vector to use instead of the original plane normal (this is how we get a new right vector)
+ VectorSubtract(rsurface.modelorg, center, forward);
+ CrossProduct(up, forward, newright);
+ // normalize the vectors involved
+ VectorNormalize(right);
+ VectorNormalize(newright);
+ // rotate the quad around the up axis vector, this is made
+ // especially easy by the fact we know the quad is flat,
+ // so we only have to subtract the center position and
+ // measure distance along the right vector, and then
+ // multiply that by the newright vector and add back the
+ // center position
+ // we also need to subtract the old position to undo the
+ // displacement from the center, which we do with a
+ // DotProduct, the subtraction/addition of center is also
+ // optimized into DotProducts here
+ l = DotProduct(newright, center) - DotProduct(right, center);
+ for (i = 0;i < 4;i++)
+ {
+ v1 = rsurface.vertex3f + 3 * (surface->num_firstvertex + j + i);
+ f = DotProduct(right, v1) - DotProduct(newright, v1) + l;
+ VectorMA(v1, f, newright, rsurface.array_deformedvertex3f + (surface->num_firstvertex+i+j) * 3);
+ }
+ }
+ Mod_BuildNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, rsurface.vertex3f, rsurface.modelelement3i + surface->num_firsttriangle * 3, rsurface.array_deformednormal3f, r_smoothnormals_areaweighting.integer);
+ Mod_BuildTextureVectorsFromNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, rsurface.vertex3f, rsurface.modeltexcoordtexture2f, rsurface.array_deformednormal3f, rsurface.modelelement3i + surface->num_firsttriangle * 3, rsurface.array_deformedsvector3f, rsurface.array_deformedtvector3f, r_smoothnormals_areaweighting.integer);
+ }
+ rsurface.vertex3f = rsurface.array_deformedvertex3f;
+ rsurface.vertex3f_bufferobject = 0;
+ rsurface.vertex3f_bufferoffset = 0;
+ rsurface.svector3f = rsurface.array_deformedsvector3f;
+ rsurface.svector3f_bufferobject = 0;
+ rsurface.svector3f_bufferoffset = 0;
+ rsurface.tvector3f = rsurface.array_deformedtvector3f;
+ rsurface.tvector3f_bufferobject = 0;
+ rsurface.tvector3f_bufferoffset = 0;
+ rsurface.normal3f = rsurface.array_deformednormal3f;
+ rsurface.normal3f_bufferobject = 0;
+ rsurface.normal3f_bufferoffset = 0;
+ break;
+ case Q3DEFORM_NORMAL:
+ // deform the normals to make reflections wavey
+ for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)