MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / ComputeObjectSurfaceRes

Function ComputeObjectSurfaceRes

editor/editor_object_lighting.cpp:34–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32#include "mem.h"
33
34void ComputeObjectSurfaceRes(rad_surface *surf, object *obj, int subnum, int facenum) {
35 int i;
36 float left = 1.1f, right = -1, top = 1.1f, bottom = -1;
37 lightmap_object_face *lfp = &obj->lm_object.lightmap_faces[subnum][facenum];
38 int lw = lmi_w(lfp->lmi_handle);
39 int lh = lmi_h(lfp->lmi_handle);
40
41 for (i = 0; i < lfp->num_verts; i++) {
42 if (lfp->u2[i] < left)
43 left = lfp->u2[i];
44 if (lfp->u2[i] > right)
45 right = lfp->u2[i];
46 if (lfp->v2[i] < top)
47 top = lfp->v2[i];
48 if (lfp->v2[i] > bottom)
49 bottom = lfp->v2[i];
50 }
51
52 float left_result = (left * lw) + .0001;
53 float right_result = (right * lw) + .0001;
54 float top_result = (top * lh) + .0001;
55 float bottom_result = (bottom * lh) + .0001;
56
57 surf->x1 = floor(left_result);
58 surf->x2 = floor(right_result);
59
60 surf->y1 = floor(top_result);
61 surf->y2 = floor(bottom_result);
62
63 surf->xresolution = (surf->x2 - surf->x1);
64 surf->yresolution = (surf->y2 - surf->y1);
65
66 // Adjust for a accuracy errors
67 if (((right_result) - (float)surf->x2) > .005)
68 surf->xresolution++;
69
70 if (((bottom_result) - (float)surf->y2) > .005)
71 surf->yresolution++;
72
73 if (((top_result) - (float)surf->y1) > .99)
74 surf->y1++;
75
76 if (((left_result) - (float)surf->x1) > .99)
77 surf->x1++;
78}
79
80void ApplyLightmapToObjectSurface(object *obj, int subnum, int facenum, rad_surface *sp) {
81 lightmap_object_face *fp = &obj->lm_object.lightmap_faces[subnum][facenum];

Calls 2

lmi_wFunction · 0.85
lmi_hFunction · 0.85

Tested by

no test coverage detected