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

Function FindPointUV

Descent3/room.cpp:1027–1061  ·  view source on GitHub ↗

Finds the uv coords of a given point on a room:face. Fills in u & v. Parameters: u,v - pointers to variables to be filled in pnt - the point we're checking rp - pointer to the room that pnt is in fp - pointer to the face that pnt is on

Source from the content-addressed store, hash-verified

1025// rp - pointer to the room that pnt is in
1026// fp - pointer to the face that pnt is on
1027void FindPointUV(float *u, float *v, const vector *pnt, const room *rp, const face *fp) {
1028 int roomnum = ROOMNUM(rp);
1029 int ii, jj;
1030 vector vec0, vec1;
1031 float *p1, *checkp, *v0, *v1;
1032 float k0, k1;
1033 int t;
1034
1035 // Make sure we have a valid room
1036 ASSERT((roomnum >= 0) && (roomnum <= Highest_room_index));
1037
1038 // Find what plane to project this wall onto to make it a 2d case
1039 GetIJ(&fp->normal, &ii, &jj);
1040
1041 // Compute delta vectors
1042 vec0 = rp->verts[fp->face_verts[0]] - rp->verts[fp->face_verts[1]]; // vec from 1 -> 0
1043 vec1 = rp->verts[fp->face_verts[2]] - rp->verts[fp->face_verts[1]]; // vec from 1 -> 0
1044
1045 // Get pointers to referece our vectors as arrays of floats
1046 p1 = (float *)&rp->verts[fp->face_verts[1]];
1047 v0 = (float *)&vec0;
1048 v1 = (float *)&vec1;
1049 checkp = (float *)pnt;
1050
1051 // Compute our clipping values along i & j axes
1052 k1 = -(cross(checkp, v0) + cross(v0, p1)) / cross(v0, v1);
1053 t = (fabs(v0[ii]) > fabs(v0[jj])) ? ii : jj;
1054 k0 = ((-k1 * v1[t]) + checkp[t] - p1[t]) / v0[t];
1055
1056 // Compute u & v values
1057 *u = fp->face_uvls[1].u + (k0 * (fp->face_uvls[0].u - fp->face_uvls[1].u)) +
1058 (k1 * (fp->face_uvls[2].u - fp->face_uvls[1].u));
1059 *v = fp->face_uvls[1].v + (k0 * (fp->face_uvls[0].v - fp->face_uvls[1].v)) +
1060 (k1 * (fp->face_uvls[2].v - fp->face_uvls[1].v));
1061}
1062
1063// Check if a particular point on a wall is a transparent pixel
1064// Parameters: pnt - the point we're checking

Callers 1

CheckTransparentPointFunction · 0.85

Calls 1

GetIJFunction · 0.85

Tested by

no test coverage detected