]> git.xonotic.org Git - xonotic/darkplaces.git/blob - transform.c
you can now (try to) play in maps you don't have, and models you don't have are shown...
[xonotic/darkplaces.git] / transform.c
1
2 #include "quakedef.h"
3
4 vec_t softwaretransform_rotatematrix[3][4];
5 vec_t softwaretransform_matrix[3][4];
6 vec_t softwaretransform_invmatrix[3][4];
7 int softwaretransform_complexity;
8
9 vec_t softwaretransform_identitymatrix[3][4] =
10 {
11         {1, 0, 0, 0},
12         {0, 1, 0, 0},
13         {0, 0, 1, 0}
14 };
15
16 void softwaretransformidentity(void)
17 {
18         memcpy(softwaretransform_rotatematrix, softwaretransform_identitymatrix, sizeof(vec_t[3][4]));
19         memcpy(softwaretransform_matrix      , softwaretransform_identitymatrix, sizeof(vec_t[3][4]));
20         memcpy(softwaretransform_invmatrix   , softwaretransform_identitymatrix, sizeof(vec_t[3][4]));
21         softwaretransform_complexity = 0;
22 }
23
24 void softwaretransformset (vec3_t origin, vec3_t angles, vec_t scale)
25 {
26         float invscale;
27         invscale = 1.0f / scale;
28         if (scale == 0)
29                 Host_Error("softwaretransformset: 0 scale\n");
30
31         AngleMatrix(angles, origin, softwaretransform_rotatematrix);
32
33         softwaretransform_matrix[0][0] = softwaretransform_rotatematrix[0][0] * scale;
34         softwaretransform_matrix[0][1] = softwaretransform_rotatematrix[0][1] * scale;
35         softwaretransform_matrix[0][2] = softwaretransform_rotatematrix[0][2] * scale;
36         softwaretransform_matrix[1][0] = softwaretransform_rotatematrix[1][0] * scale;
37         softwaretransform_matrix[1][1] = softwaretransform_rotatematrix[1][1] * scale;
38         softwaretransform_matrix[1][2] = softwaretransform_rotatematrix[1][2] * scale;
39         softwaretransform_matrix[2][0] = softwaretransform_rotatematrix[2][0] * scale;
40         softwaretransform_matrix[2][1] = softwaretransform_rotatematrix[2][1] * scale;
41         softwaretransform_matrix[2][2] = softwaretransform_rotatematrix[2][2] * scale;
42         softwaretransform_matrix[0][3] = softwaretransform_rotatematrix[0][3];
43         softwaretransform_matrix[1][3] = softwaretransform_rotatematrix[1][3];
44         softwaretransform_matrix[2][3] = softwaretransform_rotatematrix[2][3];
45
46         softwaretransform_invmatrix[0][0] = softwaretransform_rotatematrix[0][0] * invscale;
47         softwaretransform_invmatrix[0][1] = softwaretransform_rotatematrix[1][0] * invscale;
48         softwaretransform_invmatrix[0][2] = softwaretransform_rotatematrix[2][0] * invscale;
49         softwaretransform_invmatrix[1][0] = softwaretransform_rotatematrix[0][1] * invscale;
50         softwaretransform_invmatrix[1][1] = softwaretransform_rotatematrix[1][1] * invscale;
51         softwaretransform_invmatrix[1][2] = softwaretransform_rotatematrix[2][1] * invscale;
52         softwaretransform_invmatrix[2][0] = softwaretransform_rotatematrix[0][2] * invscale;
53         softwaretransform_invmatrix[2][1] = softwaretransform_rotatematrix[1][2] * invscale;
54         softwaretransform_invmatrix[2][2] = softwaretransform_rotatematrix[2][2] * invscale;
55         softwaretransform_invmatrix[0][3] = softwaretransform_rotatematrix[0][3];
56         softwaretransform_invmatrix[1][3] = softwaretransform_rotatematrix[1][3];
57         softwaretransform_invmatrix[2][3] = softwaretransform_rotatematrix[2][3];
58
59         // choose transform mode
60         if (softwaretransform_matrix[0][0] != 1 || softwaretransform_matrix[0][1] != 0 || softwaretransform_matrix[0][2] != 0
61          || softwaretransform_matrix[1][0] != 0 || softwaretransform_matrix[1][1] != 1 || softwaretransform_matrix[1][2] != 0
62          || softwaretransform_matrix[2][0] != 0 || softwaretransform_matrix[2][1] != 0 || softwaretransform_matrix[2][2] != 1)
63                 softwaretransform_complexity = 2;
64         else if (softwaretransform_matrix[0][3] != 0 || softwaretransform_matrix[1][3] != 0 || softwaretransform_matrix[2][3] != 0)
65                 softwaretransform_complexity = 1;
66         else
67                 softwaretransform_complexity = 0;
68 }
69
70 void softwaretransformforentity (entity_render_t *r)
71 {
72         vec3_t angles;
73         if (r->model->type == mod_brush)
74         {
75                 angles[0] = r->angles[0];
76                 angles[1] = r->angles[1];
77                 angles[2] = r->angles[2];
78                 softwaretransformset(r->origin, angles, r->scale);
79         }
80         else
81         {
82                 angles[0] = -r->angles[0];
83                 angles[1] = r->angles[1];
84                 angles[2] = r->angles[2];
85                 softwaretransformset(r->origin, angles, r->scale);
86         }
87 }
88